blob: fa12756cc52b867d92ffac08112d0e39fb8d4571 [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
Gabriel Pealb95f1692014-08-19 14:24:18 -070019import android.annotation.SystemApi;
Tyler Gunn2ac40102014-08-18 16:23:10 -070020import android.annotation.SdkConstant;
Santos Cordon2f42b112014-07-19 13:19:37 -070021import android.app.Service;
22import android.content.Intent;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080023import android.os.Handler;
24import android.os.IBinder;
25import android.os.Looper;
26import android.os.Message;
Andrew Lee50aca232014-07-22 16:41:54 -070027import android.view.Surface;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080028
Ihab Awad2f236642014-03-10 15:33:45 -070029import com.android.internal.os.SomeArgs;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070030import com.android.internal.telecom.IInCallAdapter;
31import com.android.internal.telecom.IInCallService;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080032
Andrew Lee50aca232014-07-22 16:41:54 -070033import java.lang.String;
34
Sailesh Nepalab5d2822014-03-08 18:01:06 -080035/**
36 * This service is implemented by any app that wishes to provide the user-interface for managing
Tyler Gunnef9f6f92014-09-12 22:16:17 -070037 * phone calls. Telecom binds to this service while there exists a live (active or incoming) call,
Santos Cordon2f42b112014-07-19 13:19:37 -070038 * and uses it to notify the in-call app of any live and and recently disconnected calls.
Ihab Awadb19a0bc2014-08-07 19:46:01 -070039 *
40 * {@hide}
Sailesh Nepalab5d2822014-03-08 18:01:06 -080041 */
Gabriel Pealb95f1692014-08-19 14:24:18 -070042@SystemApi
Santos Cordon2f42b112014-07-19 13:19:37 -070043public abstract class InCallService extends Service {
Tyler Gunn2ac40102014-08-18 16:23:10 -070044
45 /**
46 * The {@link Intent} that must be declared as handled by the service.
47 */
48 @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION)
Tyler Gunnef9f6f92014-09-12 22:16:17 -070049 public static final String SERVICE_INTERFACE = "android.telecom.InCallService";
Tyler Gunn2ac40102014-08-18 16:23:10 -070050
Sailesh Nepalab5d2822014-03-08 18:01:06 -080051 private static final int MSG_SET_IN_CALL_ADAPTER = 1;
52 private static final int MSG_ADD_CALL = 2;
Sailesh Nepal60437932014-04-05 16:44:55 -070053 private static final int MSG_UPDATE_CALL = 3;
Ihab Awad5d0410f2014-07-30 10:07:40 -070054 private static final int MSG_SET_POST_DIAL_WAIT = 4;
55 private static final int MSG_ON_AUDIO_STATE_CHANGED = 5;
56 private static final int MSG_BRING_TO_FOREGROUND = 6;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080057
58 /** Default Handler used to consolidate binder method calls onto a single thread. */
59 private final Handler mHandler = new Handler(Looper.getMainLooper()) {
60 @Override
61 public void handleMessage(Message msg) {
62 switch (msg.what) {
63 case MSG_SET_IN_CALL_ADAPTER:
Ihab Awade63fadb2014-07-09 21:52:04 -070064 mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj));
65 onPhoneCreated(mPhone);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080066 break;
67 case MSG_ADD_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070068 mPhone.internalAddCall((ParcelableCall) msg.obj);
Sailesh Nepalab5d2822014-03-08 18:01:06 -080069 break;
Sailesh Nepal60437932014-04-05 16:44:55 -070070 case MSG_UPDATE_CALL:
Santos Cordon88b771d2014-07-19 13:10:40 -070071 mPhone.internalUpdateCall((ParcelableCall) msg.obj);
Ihab Awad2f236642014-03-10 15:33:45 -070072 break;
Ihab Awad2f236642014-03-10 15:33:45 -070073 case MSG_SET_POST_DIAL_WAIT: {
74 SomeArgs args = (SomeArgs) msg.obj;
75 try {
76 String callId = (String) args.arg1;
77 String remaining = (String) args.arg2;
Ihab Awade63fadb2014-07-09 21:52:04 -070078 mPhone.internalSetPostDialWait(callId, remaining);
Ihab Awad2f236642014-03-10 15:33:45 -070079 } finally {
80 args.recycle();
81 }
82 break;
83 }
Sailesh Nepal4cff3922014-03-19 10:15:37 -070084 case MSG_ON_AUDIO_STATE_CHANGED:
Ihab Awadb19a0bc2014-08-07 19:46:01 -070085 mPhone.internalAudioStateChanged((AudioState) msg.obj);
Sailesh Nepalb632e5b2014-04-03 12:54:33 -070086 break;
Santos Cordon3534ede2014-05-29 13:07:10 -070087 case MSG_BRING_TO_FOREGROUND:
Ihab Awade63fadb2014-07-09 21:52:04 -070088 mPhone.internalBringToForeground(msg.arg1 == 1);
Santos Cordon3534ede2014-05-29 13:07:10 -070089 break;
Sailesh Nepalab5d2822014-03-08 18:01:06 -080090 default:
91 break;
92 }
93 }
94 };
95
96 /** Manages the binder calls so that the implementor does not need to deal with it. */
97 private final class InCallServiceBinder extends IInCallService.Stub {
Sailesh Nepalab5d2822014-03-08 18:01:06 -080098 @Override
99 public void setInCallAdapter(IInCallAdapter inCallAdapter) {
100 mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget();
101 }
102
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800103 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700104 public void addCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700105 mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800106 }
107
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800108 @Override
Santos Cordon88b771d2014-07-19 13:10:40 -0700109 public void updateCall(ParcelableCall call) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700110 mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
Ihab Awad2f236642014-03-10 15:33:45 -0700111 }
112
113 @Override
114 public void setPostDial(String callId, String remaining) {
Ihab Awad5d0410f2014-07-30 10:07:40 -0700115 // TODO: Unused
Ihab Awad2f236642014-03-10 15:33:45 -0700116 }
117
118 @Override
119 public void setPostDialWait(String callId, String remaining) {
120 SomeArgs args = SomeArgs.obtain();
121 args.arg1 = callId;
122 args.arg2 = remaining;
123 mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
124 }
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700125
126 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700127 public void onAudioStateChanged(AudioState audioState) {
Sailesh Nepal60437932014-04-05 16:44:55 -0700128 mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, audioState).sendToTarget();
Sailesh Nepalb632e5b2014-04-03 12:54:33 -0700129 }
Santos Cordon3534ede2014-05-29 13:07:10 -0700130
Santos Cordon3534ede2014-05-29 13:07:10 -0700131 @Override
132 public void bringToForeground(boolean showDialpad) {
133 mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget();
134 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800135 }
136
Ihab Awade63fadb2014-07-09 21:52:04 -0700137 private Phone mPhone;
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800138
Santos Cordon2f42b112014-07-19 13:19:37 -0700139 public InCallService() {
140 }
Evan Charlton924748f2014-04-03 08:36:38 -0700141
Santos Cordon2f42b112014-07-19 13:19:37 -0700142 @Override
143 public IBinder onBind(Intent intent) {
Ihab Awade63fadb2014-07-09 21:52:04 -0700144 return new InCallServiceBinder();
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800145 }
146
Santos Cordonf30d7e92014-08-26 09:54:33 -0700147 @Override
148 public boolean onUnbind(Intent intent) {
Santos Cordon619b3c02014-09-02 17:13:45 -0700149 if (mPhone != null) {
150 Phone oldPhone = mPhone;
151 mPhone = null;
Santos Cordonf30d7e92014-08-26 09:54:33 -0700152
Santos Cordon619b3c02014-09-02 17:13:45 -0700153 oldPhone.destroy();
154 onPhoneDestroyed(oldPhone);
155 }
Santos Cordonf30d7e92014-08-26 09:54:33 -0700156 return false;
157 }
158
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800159 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700160 * Obtain the {@code Phone} associated with this {@code InCallService}.
161 *
162 * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null}
Santos Cordon2f42b112014-07-19 13:19:37 -0700163 * if the {@code InCallService} is not in a state where it has an associated
164 * {@code Phone}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800165 */
Ihab Awade63fadb2014-07-09 21:52:04 -0700166 public Phone getPhone() {
167 return mPhone;
Evan Charlton924748f2014-04-03 08:36:38 -0700168 }
169
170 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700171 * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience
172 * to start displaying in-call information to the user. Each instance of {@code InCallService}
Santos Cordon2f42b112014-07-19 13:19:37 -0700173 * will have only one {@code Phone}, and this method will be called exactly once in the lifetime
174 * of the {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700175 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700176 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Evan Charlton924748f2014-04-03 08:36:38 -0700177 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700178 public void onPhoneCreated(Phone phone) {
179 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800180
181 /**
Ihab Awade63fadb2014-07-09 21:52:04 -0700182 * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience
183 * to stop displaying in-call information to the user. This method will be called exactly once
184 * in the lifetime of the {@code InCallService}, and it will always be called after a previous
185 * call to {@link #onPhoneCreated(Phone)}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800186 *
Ihab Awade63fadb2014-07-09 21:52:04 -0700187 * @param phone The {@code Phone} object associated with this {@code InCallService}.
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800188 */
Santos Cordon2f42b112014-07-19 13:19:37 -0700189 public void onPhoneDestroyed(Phone phone) {
190 }
Andrew Lee50aca232014-07-22 16:41:54 -0700191
192 /**
193 * Class to invoke functionality related to video calls.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700194 * @hide
Andrew Lee50aca232014-07-22 16:41:54 -0700195 */
196 public static abstract class VideoCall {
197
198 /**
Andrew Lee50aca232014-07-22 16:41:54 -0700199 * Sets a listener to invoke callback methods in the InCallUI after performing video
200 * telephony actions.
201 *
202 * @param videoCallListener The call video client.
203 */
204 public abstract void setVideoCallListener(VideoCall.Listener videoCallListener);
205
206 /**
207 * Sets the camera to be used for video recording in a video call.
208 *
209 * @param cameraId The id of the camera.
210 */
211 public abstract void setCamera(String cameraId);
212
213 /**
214 * Sets the surface to be used for displaying a preview of what the user's camera is
215 * currently capturing. When video transmission is enabled, this is the video signal which
216 * is sent to the remote device.
217 *
218 * @param surface The surface.
219 */
220 public abstract void setPreviewSurface(Surface surface);
221
222 /**
223 * Sets the surface to be used for displaying the video received from the remote device.
224 *
225 * @param surface The surface.
226 */
227 public abstract void setDisplaySurface(Surface surface);
228
229 /**
230 * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of
231 * the device is 0 degrees.
232 *
233 * @param rotation The device orientation, in degrees.
234 */
235 public abstract void setDeviceOrientation(int rotation);
236
237 /**
238 * Sets camera zoom ratio.
239 *
240 * @param value The camera zoom ratio.
241 */
242 public abstract void setZoom(float value);
243
244 /**
245 * Issues a request to modify the properties of the current session. The request is sent to
246 * the remote device where it it handled by
247 * {@link VideoCall.Listener#onSessionModifyRequestReceived}.
248 * Some examples of session modification requests: upgrade call from audio to video,
249 * downgrade call from video to audio, pause video.
250 *
251 * @param requestProfile The requested call video properties.
252 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700253 public abstract void sendSessionModifyRequest(VideoProfile requestProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700254
255 /**
256 * Provides a response to a request to change the current call session video
257 * properties.
258 * This is in response to a request the InCall UI has received via
259 * {@link VideoCall.Listener#onSessionModifyRequestReceived}.
260 * The response is handled on the remove device by
261 * {@link VideoCall.Listener#onSessionModifyResponseReceived}.
262 *
263 * @param responseProfile The response call video properties.
264 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700265 public abstract void sendSessionModifyResponse(VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700266
267 /**
268 * Issues a request to the video provider to retrieve the camera capabilities.
269 * Camera capabilities are reported back to the caller via
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700270 * {@link VideoCall.Listener#onCameraCapabilitiesChanged(CameraCapabilities)}.
Andrew Lee50aca232014-07-22 16:41:54 -0700271 */
272 public abstract void requestCameraCapabilities();
273
274 /**
275 * Issues a request to the video telephony framework to retrieve the cumulative data usage for
276 * the current call. Data usage is reported back to the caller via
277 * {@link VideoCall.Listener#onCallDataUsageChanged}.
278 */
279 public abstract void requestCallDataUsage();
280
281 /**
282 * Provides the video telephony framework with the URI of an image to be displayed to remote
283 * devices when the video signal is paused.
284 *
285 * @param uri URI of image to display.
286 */
287 public abstract void setPauseImage(String uri);
288
289 /**
290 * Listener class which invokes callbacks after video call actions occur.
Tyler Gunn75537ae2014-08-22 11:33:13 -0700291 * @hide
Andrew Lee50aca232014-07-22 16:41:54 -0700292 */
293 public static abstract class Listener {
294 /**
295 * Called when a session modification request is received from the remote device.
Andrew Lee14185762014-07-25 09:41:56 -0700296 * The remote request is sent via
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700297 * {@link Connection.VideoProvider#onSendSessionModifyRequest}. The InCall UI
Andrew Lee14185762014-07-25 09:41:56 -0700298 * is responsible for potentially prompting the user whether they wish to accept the new
299 * call profile (e.g. prompt user if they wish to accept an upgrade from an audio to a
300 * video call) and should call
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700301 * {@link Connection.VideoProvider#onSendSessionModifyResponse} to indicate
Andrew Lee14185762014-07-25 09:41:56 -0700302 * the video settings the user has agreed to.
Andrew Lee50aca232014-07-22 16:41:54 -0700303 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700304 * @param videoProfile The requested video call profile.
Andrew Lee50aca232014-07-22 16:41:54 -0700305 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700306 public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700307
308 /**
309 * Called when a response to a session modification request is received from the remote
310 * device. The remote InCall UI sends the response using
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700311 * {@link Connection.VideoProvider#onSendSessionModifyResponse}.
Andrew Lee50aca232014-07-22 16:41:54 -0700312 *
313 * @param status Status of the session modify request. Valid values are
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700314 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
315 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
316 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID}
Andrew Lee50aca232014-07-22 16:41:54 -0700317 * @param requestedProfile The original request which was sent to the remote device.
318 * @param responseProfile The actual profile changes made by the remote device.
319 */
320 public abstract void onSessionModifyResponseReceived(int status,
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700321 VideoProfile requestedProfile, VideoProfile responseProfile);
Andrew Lee50aca232014-07-22 16:41:54 -0700322
323 /**
324 * Handles events related to the current session which the client may wish to handle.
325 * These are separate from requested changes to the session due to the underlying
326 * protocol or connection.
327 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700328 * Valid values are:
329 * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE},
330 * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME},
331 * {@link Connection.VideoProvider#SESSION_EVENT_TX_START},
332 * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP},
333 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
334 * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY}
Andrew Lee50aca232014-07-22 16:41:54 -0700335 *
336 * @param event The event.
337 */
338 public abstract void onCallSessionEvent(int event);
339
340 /**
341 * Handles a change to the video dimensions from the remote caller (peer). This could
342 * happen if, for example, the peer changes orientation of their device.
343 *
344 * @param width The updated peer video width.
345 * @param height The updated peer video height.
346 */
347 public abstract void onPeerDimensionsChanged(int width, int height);
348
349 /**
350 * Handles an update to the total data used for the current session.
351 *
352 * @param dataUsage The updated data usage.
353 */
354 public abstract void onCallDataUsageChanged(int dataUsage);
355
356 /**
357 * Handles a change in camera capabilities.
358 *
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700359 * @param cameraCapabilities The changed camera capabilities.
Andrew Lee50aca232014-07-22 16:41:54 -0700360 */
361 public abstract void onCameraCapabilitiesChanged(
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700362 CameraCapabilities cameraCapabilities);
Andrew Lee50aca232014-07-22 16:41:54 -0700363 }
364 }
Sailesh Nepalab5d2822014-03-08 18:01:06 -0800365}