blob: 5d8f9f6d5a7bd3f5ee3e94ea267c24d24cd7e281 [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;
Hall Liub64ac4c2017-02-06 10:49:48 -080080 private static final int MSG_ON_RTT_INITIATION_FAILURE = 11;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080081
82 /** Default Handler used to consolidate binder method calls onto a single thread. */
83 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
84 @Override
85 public void handleMessage(Message msg) {
Jay Shrauner5e6162d2014-09-22 20:47:45 -070086 if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) {
87 return;
88 }
89
Sailesh Nepalab5d2822014-03-08 18:01:06 -080090 switch (msg.what) {
91 case MSG_SET_IN_CALL_ADAPTER:
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -080092 String callingPackage = getApplicationContext().getOpPackageName();
93 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage);
Santos Cordona2492812015-04-15 11:05:16 -070094 mPhone.addListener(mPhoneListener);
Ihab Awade63fadb2014-07-09 21:52:04 -070095 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080096 break;
97 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070098 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080099 break;
Sailesh Nepal60437932014-04-05 16:44:55 -0700100 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -0700101 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -0700102 break;
Ihab Awad2f236642014-03-10 15:33:45 -0700103 case MSG_SET_POST_DIAL_WAIT: {
104 SomeArgs args = (SomeArgs) msg.obj;
105 try {
106 String callId = (String) args.arg1;
107 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -0700108 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -0700109 } finally {
110 args.recycle();
111 }
112 break;
113 }
Yorke Lee4af59352015-05-13 14:14:54 -0700114 case MSG_ON_CALL_AUDIO_STATE_CHANGED:
115 mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700116 break;
Santos Cordon3534ede2014-05-29 13:07:10 -0700117 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -0700118 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -0700119 break;
Santos Cordon6c912b72014-11-07 16:05:09 -0800120 case MSG_ON_CAN_ADD_CALL_CHANGED:
121 mPhone.internalSetCanAddCall(msg.arg1 == 1);
122 break;
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800123 case MSG_SILENCE_RINGER:
124 mPhone.internalSilenceRinger();
125 break;
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700126 case MSG_ON_CONNECTION_EVENT: {
127 SomeArgs args = (SomeArgs) msg.obj;
128 try {
129 String callId = (String) args.arg1;
130 String event = (String) args.arg2;
131 Bundle extras = (Bundle) args.arg3;
132 mPhone.internalOnConnectionEvent(callId, event, extras);
133 } finally {
134 args.recycle();
135 }
136 break;
137 }
Hall Liu95d55872017-01-25 17:12:49 -0800138 case MSG_ON_RTT_UPGRADE_REQUEST: {
139 String callId = (String) msg.obj;
140 int requestId = msg.arg1;
141 mPhone.internalOnRttUpgradeRequest(callId, requestId);
142 break;
143 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800144 case MSG_ON_RTT_INITIATION_FAILURE: {
145 String callId = (String) msg.obj;
146 int reason = msg.arg1;
147 mPhone.internalOnRttInitiationFailure(callId, reason);
148 break;
149 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800150 default:
151 break;
152 }
153 }
154 };
155
156 /** Manages the binder calls so that the implementor does not need to deal with it. */
157 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800158 @Override
159 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
160 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
161 }
162
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800163 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700164 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700165 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800166 }
167
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800168 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700169 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700170 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700171 }
172
173 @Override
174 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700175 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700176 }
177
178 @Override
179 public void setPostDialWait(String callId, String remaining) {
180 SomeArgs args = SomeArgs.obtain();
181 args.arg1 = callId;
182 args.arg2 = remaining;
183 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
184 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700185
186 @Override
Yorke Lee4af59352015-05-13 14:14:54 -0700187 public void onCallAudioStateChanged(CallAudioState callAudioState) {
188 mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700189 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700190
Santos Cordon3534ede2014-05-29 13:07:10 -0700191 @Override
192 public void bringToForeground(boolean showDialpad) {
193 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
194 }
Santos Cordon6c912b72014-11-07 16:05:09 -0800195
196 @Override
197 public void onCanAddCallChanged(boolean canAddCall) {
198 mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0)
199 .sendToTarget();
200 }
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800201
202 @Override
203 public void silenceRinger() {
204 mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget();
205 }
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700206
207 @Override
208 public void onConnectionEvent(String callId, String event, Bundle extras) {
209 SomeArgs args = SomeArgs.obtain();
210 args.arg1 = callId;
211 args.arg2 = event;
212 args.arg3 = extras;
213 mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget();
214 }
Hall Liu95d55872017-01-25 17:12:49 -0800215
216 @Override
217 public void onRttUpgradeRequest(String callId, int id) {
218 mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget();
219 }
Hall Liub64ac4c2017-02-06 10:49:48 -0800220
221 @Override
222 public void onRttInitiationFailure(String callId, int reason) {
223 mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget();
224 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800225 }
226
Santos Cordona2492812015-04-15 11:05:16 -0700227 private Phone.Listener mPhoneListener = new Phone.Listener() {
228 /** ${inheritDoc} */
229 @Override
230 public void onAudioStateChanged(Phone phone, AudioState audioState) {
231 InCallService.this.onAudioStateChanged(audioState);
232 }
233
Yorke Lee4af59352015-05-13 14:14:54 -0700234 public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) {
235 InCallService.this.onCallAudioStateChanged(callAudioState);
236 };
237
Santos Cordona2492812015-04-15 11:05:16 -0700238 /** ${inheritDoc} */
239 @Override
240 public void onBringToForeground(Phone phone, boolean showDialpad) {
241 InCallService.this.onBringToForeground(showDialpad);
242 }
243
244 /** ${inheritDoc} */
245 @Override
246 public void onCallAdded(Phone phone, Call call) {
247 InCallService.this.onCallAdded(call);
248 }
249
250 /** ${inheritDoc} */
251 @Override
252 public void onCallRemoved(Phone phone, Call call) {
253 InCallService.this.onCallRemoved(call);
254 }
255
256 /** ${inheritDoc} */
257 @Override
258 public void onCanAddCallChanged(Phone phone, boolean canAddCall) {
259 InCallService.this.onCanAddCallChanged(canAddCall);
260 }
261
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800262 /** ${inheritDoc} */
263 @Override
264 public void onSilenceRinger(Phone phone) {
265 InCallService.this.onSilenceRinger();
266 }
267
Santos Cordona2492812015-04-15 11:05:16 -0700268 };
269
Ihab Awade63fadb2014-07-09 21:52:04 -0700270 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800271
Santos Cordon2f42b112014-07-19 13:19:37 -0700272 public InCallService() {
273 }
Evan Charlton924748f2014-04-03 08:36:38 -0700274
Santos Cordon2f42b112014-07-19 13:19:37 -0700275 @Override
276 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700277 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800278 }
279
Santos Cordonf30d7e92014-08-26 09:54:33 -0700280 @Override
281 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700282 if (mPhone != null) {
283 Phone oldPhone = mPhone;
284 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700285
Santos Cordon619b3c02014-09-02 17:13:45 -0700286 oldPhone.destroy();
Santos Cordona2492812015-04-15 11:05:16 -0700287 // destroy sets all the calls to disconnected if any live ones still exist. Therefore,
288 // it is important to remove the Listener *after* the call to destroy so that
289 // InCallService.on* callbacks are appropriately called.
290 oldPhone.removeListener(mPhoneListener);
291
Santos Cordon619b3c02014-09-02 17:13:45 -0700292 onPhoneDestroyed(oldPhone);
293 }
Santos Cordona2492812015-04-15 11:05:16 -0700294
Santos Cordonf30d7e92014-08-26 09:54:33 -0700295 return false;
296 }
297
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800298 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700299 * Obtain the {@code Phone} associated with this {@code InCallService}.
300 *
301 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700302 * if the {@code InCallService} is not in a state where it has an associated
303 * {@code Phone}.
Santos Cordona2492812015-04-15 11:05:16 -0700304 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700305 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800306 */
Santos Cordona2492812015-04-15 11:05:16 -0700307 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700308 @Deprecated
309 public Phone getPhone() {
Ihab Awade63fadb2014-07-09 21:52:04 -0700310 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700311 }
312
313 /**
Santos Cordon895d4b82015-06-25 16:41:48 -0700314 * Obtains the current list of {@code Call}s to be displayed by this in-call service.
Santos Cordona2492812015-04-15 11:05:16 -0700315 *
316 * @return A list of the relevant {@code Call}s.
317 */
318 public final List<Call> getCalls() {
319 return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls();
320 }
321
322 /**
323 * Returns if the device can support additional calls.
324 *
325 * @return Whether the phone supports adding more calls.
326 */
327 public final boolean canAddCall() {
328 return mPhone == null ? false : mPhone.canAddCall();
329 }
330
331 /**
332 * Obtains the current phone call audio state.
333 *
334 * @return An object encapsulating the audio state. Returns null if the service is not
335 * fully initialized.
Yorke Lee4af59352015-05-13 14:14:54 -0700336 * @deprecated Use {@link #getCallAudioState()} instead.
337 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700338 */
Yorke Lee4af59352015-05-13 14:14:54 -0700339 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700340 public final AudioState getAudioState() {
341 return mPhone == null ? null : mPhone.getAudioState();
342 }
343
344 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700345 * Obtains the current phone call audio state.
346 *
347 * @return An object encapsulating the audio state. Returns null if the service is not
348 * fully initialized.
349 */
350 public final CallAudioState getCallAudioState() {
351 return mPhone == null ? null : mPhone.getCallAudioState();
352 }
353
354 /**
Santos Cordona2492812015-04-15 11:05:16 -0700355 * Sets the microphone mute state. When this request is honored, there will be change to
Yorke Lee4af59352015-05-13 14:14:54 -0700356 * the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700357 *
358 * @param state {@code true} if the microphone should be muted; {@code false} otherwise.
359 */
360 public final void setMuted(boolean state) {
361 if (mPhone != null) {
362 mPhone.setMuted(state);
363 }
364 }
365
366 /**
367 * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will
Yorke Lee4af59352015-05-13 14:14:54 -0700368 * be change to the {@link #getCallAudioState()}.
Santos Cordona2492812015-04-15 11:05:16 -0700369 *
370 * @param route The audio route to use.
371 */
372 public final void setAudioRoute(int route) {
373 if (mPhone != null) {
374 mPhone.setAudioRoute(route);
375 }
376 }
377
378 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700379 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
380 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700381 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
382 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700383 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700384 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700385 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700386 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Evan Charlton924748f2014-04-03 08:36:38 -0700387 */
Santos Cordona2492812015-04-15 11:05:16 -0700388 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700389 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700390 public void onPhoneCreated(Phone phone) {
391 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800392
393 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700394 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
395 * to stop displaying in-call information to the user. This method will be called exactly once
396 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
397 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800398 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700399 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Santos Cordona2492812015-04-15 11:05:16 -0700400 * @hide
Santos Cordon29886d82015-04-16 15:34:07 -0700401 * @deprecated Use direct methods on InCallService instead of {@link Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800402 */
Santos Cordona2492812015-04-15 11:05:16 -0700403 @SystemApi
Santos Cordon29886d82015-04-16 15:34:07 -0700404 @Deprecated
Santos Cordon2f42b112014-07-19 13:19:37 -0700405 public void onPhoneDestroyed(Phone phone) {
406 }
Andrew Lee50aca232014-07-22 16:41:54 -0700407
408 /**
Santos Cordona2492812015-04-15 11:05:16 -0700409 * Called when the audio state changes.
410 *
411 * @param audioState The new {@link AudioState}.
Yorke Lee4af59352015-05-13 14:14:54 -0700412 * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}.
413 * @hide
Santos Cordona2492812015-04-15 11:05:16 -0700414 */
Yorke Lee4af59352015-05-13 14:14:54 -0700415 @Deprecated
Santos Cordona2492812015-04-15 11:05:16 -0700416 public void onAudioStateChanged(AudioState audioState) {
417 }
418
419 /**
Yorke Lee4af59352015-05-13 14:14:54 -0700420 * Called when the audio state changes.
421 *
422 * @param audioState The new {@link CallAudioState}.
423 */
424 public void onCallAudioStateChanged(CallAudioState audioState) {
425 }
426
427 /**
Santos Cordona2492812015-04-15 11:05:16 -0700428 * Called to bring the in-call screen to the foreground. The in-call experience should
429 * respond immediately by coming to the foreground to inform the user of the state of
430 * ongoing {@code Call}s.
431 *
432 * @param showDialpad If true, put up the dialpad when the screen is shown.
433 */
434 public void onBringToForeground(boolean showDialpad) {
435 }
436
437 /**
438 * Called when a {@code Call} has been added to this in-call session. The in-call user
439 * experience should add necessary state listeners to the specified {@code Call} and
440 * immediately start to show the user information about the existence
441 * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will
442 * include this {@code Call}.
443 *
444 * @param call A newly added {@code Call}.
445 */
446 public void onCallAdded(Call call) {
447 }
448
449 /**
450 * Called when a {@code Call} has been removed from this in-call session. The in-call user
451 * experience should remove any state listeners from the specified {@code Call} and
452 * immediately stop displaying any information about this {@code Call}.
453 * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}.
454 *
455 * @param call A newly removed {@code Call}.
456 */
457 public void onCallRemoved(Call call) {
458 }
459
460 /**
461 * Called when the ability to add more calls changes. If the phone cannot
462 * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it
463 * is set to {@code true}. This can be used to control the visibility of UI to add more calls.
464 *
465 * @param canAddCall Indicates whether an additional call can be added.
466 */
467 public void onCanAddCallChanged(boolean canAddCall) {
468 }
469
470 /**
Sailesh Nepal9c2618b2016-01-23 16:28:22 -0800471 * Called to silence the ringer if a ringing call exists.
472 */
473 public void onSilenceRinger() {
474 }
475
476 /**
Tyler Gunn06f3fa62016-08-25 09:26:15 -0700477 * Unused; to handle connection events issued by a {@link ConnectionService}, implement the
478 * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback.
Tyler Gunn876dbfb2016-03-14 15:18:07 -0700479 * <p>
480 * See {@link Connection#sendConnectionEvent(String, Bundle)}.
481 *
482 * @param call The call the event is associated with.
483 * @param event The event.
484 * @param extras Any associated extras.
485 */
486 public void onConnectionEvent(Call call, String event, Bundle extras) {
487 }
488
489 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700490 * Used to issue commands to the {@link Connection.VideoProvider} associated with a
491 * {@link Call}.
Andrew Lee50aca232014-07-22 16:41:54 -0700492 */
493 public static abstract class VideoCall {
494
Andrew Lee011728f2015-04-23 15:47:06 -0700495 /** @hide */
496 public abstract void destroy();
497
Andrew Lee50aca232014-07-22 16:41:54 -0700498 /**
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700499 * Registers a callback to receive commands and state changes for video calls.
Andrew Lee50aca232014-07-22 16:41:54 -0700500 *
Andrew Lee7c9ee2b2015-04-16 15:26:08 -0700501 * @param callback The video call callback.
Andrew Lee50aca232014-07-22 16:41:54 -0700502 */
Andrew Leeda80c872015-04-15 14:09:50 -0700503 public abstract void registerCallback(VideoCall.Callback callback);
504
505 /**
Andrew Lee011728f2015-04-23 15:47:06 -0700506 * Registers a callback to receive commands and state changes for video calls.
507 *
508 * @param callback The video call callback.
509 * @param handler A handler which commands and status changes will be delivered to.
510 */
511 public abstract void registerCallback(VideoCall.Callback callback, Handler handler);
512
513 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700514 * Clears the video call callback set via {@link #registerCallback}.
Tyler Gunn295f5d72015-06-04 11:08:54 -0700515 *
516 * @param callback The video call callback to clear.
Tyler Gunn75958422015-04-15 14:23:42 -0700517 */
Andrew Lee011728f2015-04-23 15:47:06 -0700518 public abstract void unregisterCallback(VideoCall.Callback callback);
Tyler Gunn75958422015-04-15 14:23:42 -0700519
520 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700521 * Sets the camera to be used for the outgoing video.
522 * <p>
523 * Handled by {@link Connection.VideoProvider#onSetCamera(String)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700524 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700525 * @param cameraId The id of the camera (use ids as reported by
526 * {@link CameraManager#getCameraIdList()}).
Andrew Lee50aca232014-07-22 16:41:54 -0700527 */
528 public abstract void setCamera(String cameraId);
529
530 /**
531 * Sets the surface to be used for displaying a preview of what the user's camera is
532 * currently capturing. When video transmission is enabled, this is the video signal which
533 * is sent to the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700534 * <p>
535 * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700536 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700537 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700538 */
539 public abstract void setPreviewSurface(Surface surface);
540
541 /**
542 * Sets the surface to be used for displaying the video received from the remote device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700543 * <p>
544 * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700545 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700546 * @param surface The {@link Surface}.
Andrew Lee50aca232014-07-22 16:41:54 -0700547 */
548 public abstract void setDisplaySurface(Surface surface);
549
550 /**
551 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
552 * the device is 0 degrees.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700553 * <p>
554 * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700555 *
556 * @param rotation The device orientation, in degrees.
557 */
558 public abstract void setDeviceOrientation(int rotation);
559
560 /**
561 * Sets camera zoom ratio.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700562 * <p>
563 * Handled by {@link Connection.VideoProvider#onSetZoom(float)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700564 *
565 * @param value The camera zoom ratio.
566 */
567 public abstract void setZoom(float value);
568
569 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700570 * Issues a request to modify the properties of the current video session.
571 * <p>
572 * Example scenarios include: requesting an audio-only call to be upgraded to a
573 * bi-directional video call, turning on or off the user's camera, sending a pause signal
574 * when the {@link InCallService} is no longer the foreground application.
575 * <p>
576 * Handled by
577 * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700578 *
579 * @param requestProfile The requested call video properties.
580 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700581 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700582
583 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700584 * Provides a response to a request to change the current call video session
585 * properties. This should be called in response to a request the {@link InCallService} has
586 * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}.
587 * <p>
588 * Handled by
589 * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700590 *
591 * @param responseProfile The response call video properties.
592 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700593 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700594
595 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700596 * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities
597 * of the current camera. The current camera is selected using
598 * {@link VideoCall#setCamera(String)}.
599 * <p>
600 * Camera capabilities are reported to the caller via
601 * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}.
602 * <p>
603 * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700604 */
605 public abstract void requestCameraCapabilities();
606
607 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700608 * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data
609 * usage for the video component of the current call (in bytes). Data usage is reported
610 * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}.
611 * <p>
612 * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}.
Andrew Lee50aca232014-07-22 16:41:54 -0700613 */
614 public abstract void requestCallDataUsage();
615
616 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700617 * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be
618 * displayed to the peer device when the video signal is paused.
619 * <p>
620 * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700621 *
622 * @param uri URI of image to display.
623 */
Yorke Lee32f24732015-05-12 16:18:03 -0700624 public abstract void setPauseImage(Uri uri);
Andrew Lee50aca232014-07-22 16:41:54 -0700625
626 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700627 * The {@link InCallService} extends this class to provide a means of receiving callbacks
Tyler Gunn295f5d72015-06-04 11:08:54 -0700628 * from the {@link Connection.VideoProvider}.
629 * <p>
Tyler Gunnb702ef82015-05-29 11:51:53 -0700630 * When the {@link InCallService} receives the
631 * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an
632 * instance its {@link VideoCall.Callback} implementation and set it on the
633 * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700634 */
Andrew Leeda80c872015-04-15 14:09:50 -0700635 public static abstract class Callback {
Andrew Lee50aca232014-07-22 16:41:54 -0700636 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700637 * Called when the {@link Connection.VideoProvider} receives a session modification
Tyler Gunn295f5d72015-06-04 11:08:54 -0700638 * request from the peer device.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700639 * <p>
640 * The {@link InCallService} may potentially prompt the user to confirm whether they
641 * wish to accept the request, or decide to automatically accept the request. In either
642 * case the {@link InCallService} should call
643 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video
644 * profile agreed upon.
645 * <p>
646 * Callback originates from
647 * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700648 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700649 * @param videoProfile The requested video profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700650 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700651 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700652
653 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700654 * Called when the {@link Connection.VideoProvider} receives a response to a session
655 * modification request previously sent to the peer device.
656 * <p>
657 * The new video state should not be considered active by the {@link InCallService}
658 * until the {@link Call} video state changes (the
659 * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered
660 * when the video state changes).
661 * <p>
662 * Callback originates from
663 * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile,
664 * VideoProfile)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700665 *
666 * @param status Status of the session modify request. Valid values are
Tyler Gunnb702ef82015-05-29 11:51:53 -0700667 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
668 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
669 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
670 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
671 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}.
672 * @param requestedProfile The original request which was sent to the peer device.
673 * @param responseProfile The actual profile changes made by the peer device.
Andrew Lee50aca232014-07-22 16:41:54 -0700674 */
675 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700676 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700677
678 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700679 * Handles events related to the current video session which the {@link InCallService}
680 * may wish to handle. These are separate from requested changes to the session due to
681 * the underlying protocol or connection.
682 * <p>
683 * Callback originates from
684 * {@link Connection.VideoProvider#handleCallSessionEvent(int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700685 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700686 * @param event The event. Valid values are:
687 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
688 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
689 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
690 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
691 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
Tyler Gunnbf9c6fd2016-11-09 10:19:23 -0800692 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY},
693 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}.
Andrew Lee50aca232014-07-22 16:41:54 -0700694 */
695 public abstract void onCallSessionEvent(int event);
696
697 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700698 * Handles a change to the video dimensions from the peer device. This could happen if,
699 * for example, the peer changes orientation of their device, or switches cameras.
700 * <p>
701 * Callback originates from
702 * {@link Connection.VideoProvider#changePeerDimensions(int, int)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700703 *
704 * @param width The updated peer video width.
705 * @param height The updated peer video height.
706 */
707 public abstract void onPeerDimensionsChanged(int width, int height);
708
709 /**
Rekha Kumar07366812015-03-24 16:42:31 -0700710 * Handles a change to the video quality.
Tyler Gunnb702ef82015-05-29 11:51:53 -0700711 * <p>
712 * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}.
Rekha Kumar07366812015-03-24 16:42:31 -0700713 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700714 * @param videoQuality The updated peer video quality. Valid values:
715 * {@link VideoProfile#QUALITY_HIGH},
716 * {@link VideoProfile#QUALITY_MEDIUM},
717 * {@link VideoProfile#QUALITY_LOW},
718 * {@link VideoProfile#QUALITY_DEFAULT}.
Rekha Kumar07366812015-03-24 16:42:31 -0700719 */
720 public abstract void onVideoQualityChanged(int videoQuality);
721
722 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700723 * Handles an update to the total data used for the current video session.
724 * <p>
725 * Used by the {@link Connection.VideoProvider} in response to
726 * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the
727 * {@link Connection.VideoProvider}.
728 * <p>
729 * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700730 *
Tyler Gunnb702ef82015-05-29 11:51:53 -0700731 * @param dataUsage The updated data usage (in bytes).
Andrew Lee50aca232014-07-22 16:41:54 -0700732 */
Rekha Kumar07366812015-03-24 16:42:31 -0700733 public abstract void onCallDataUsageChanged(long dataUsage);
Andrew Lee50aca232014-07-22 16:41:54 -0700734
735 /**
Tyler Gunnb702ef82015-05-29 11:51:53 -0700736 * Handles a change in the capabilities of the currently selected camera.
737 * <p>
738 * Used by the {@link Connection.VideoProvider} in response to
739 * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider}
740 * may also report the camera capabilities after a call to
741 * {@link VideoCall#setCamera(String)}.
742 * <p>
743 * Callback originates from
744 * {@link Connection.VideoProvider#changeCameraCapabilities(
745 * VideoProfile.CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700746 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700747 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700748 */
Yorke Lee400470f2015-05-12 13:31:25 -0700749 public abstract void onCameraCapabilitiesChanged(
750 VideoProfile.CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700751 }
752 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800753}