Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 1 | /* |
| 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 Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 18 | |
Hall Liu | a98f58b | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Tyler Gunn | 2ac4010 | 2014-08-18 16:23:10 -0700 | [diff] [blame] | 20 | import android.annotation.SdkConstant; |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 22 | import android.app.Service; |
Hall Liu | a98f58b | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 23 | import android.bluetooth.BluetoothDevice; |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 24 | import android.content.Intent; |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 25 | import android.hardware.camera2.CameraManager; |
Yorke Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 26 | import android.net.Uri; |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 27 | import android.os.Bundle; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 28 | import android.os.Handler; |
| 29 | import android.os.IBinder; |
| 30 | import android.os.Looper; |
| 31 | import android.os.Message; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 32 | import android.view.Surface; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 33 | |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 34 | import com.android.internal.os.SomeArgs; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 35 | import com.android.internal.telecom.IInCallAdapter; |
| 36 | import com.android.internal.telecom.IInCallService; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 37 | |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 38 | import java.lang.String; |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 39 | import java.util.Collections; |
| 40 | import java.util.List; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 41 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 42 | /** |
| 43 | * This service is implemented by any app that wishes to provide the user-interface for managing |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 44 | * phone calls. Telecom binds to this service while there exists a live (active or incoming) call, |
Santos Cordon | f2600eb | 2015-06-22 15:02:20 -0700 | [diff] [blame] | 45 | * 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 Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 54 | * <service android:name="your.package.YourInCallServiceImplementation" |
Sailesh Nepal | 78f3ba6 | 2015-12-28 16:20:56 -0800 | [diff] [blame] | 55 | * android:permission="android.permission.BIND_INCALL_SERVICE"> |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 56 | * <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 Cordon | f2600eb | 2015-06-22 15:02:20 -0700 | [diff] [blame] | 61 | * } |
| 62 | * </pre> |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 63 | */ |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 64 | public abstract class InCallService extends Service { |
Tyler Gunn | 2ac4010 | 2014-08-18 16:23:10 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * The {@link Intent} that must be declared as handled by the service. |
| 68 | */ |
| 69 | @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 70 | public static final String SERVICE_INTERFACE = "android.telecom.InCallService"; |
Tyler Gunn | 2ac4010 | 2014-08-18 16:23:10 -0700 | [diff] [blame] | 71 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 72 | private static final int MSG_SET_IN_CALL_ADAPTER = 1; |
| 73 | private static final int MSG_ADD_CALL = 2; |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 74 | private static final int MSG_UPDATE_CALL = 3; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 75 | private static final int MSG_SET_POST_DIAL_WAIT = 4; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 76 | private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 5; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 77 | private static final int MSG_BRING_TO_FOREGROUND = 6; |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 78 | private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7; |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 79 | private static final int MSG_SILENCE_RINGER = 8; |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 80 | private static final int MSG_ON_CONNECTION_EVENT = 9; |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 81 | private static final int MSG_ON_RTT_UPGRADE_REQUEST = 10; |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 82 | private static final int MSG_ON_RTT_INITIATION_FAILURE = 11; |
Sanket Padawe | e29a266 | 2017-12-01 13:59:27 -0800 | [diff] [blame] | 83 | private static final int MSG_ON_HANDOVER_FAILED = 12; |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 84 | private static final int MSG_ON_HANDOVER_COMPLETE = 13; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 85 | |
| 86 | /** Default Handler used to consolidate binder method calls onto a single thread. */ |
| 87 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 88 | @Override |
| 89 | public void handleMessage(Message msg) { |
Jay Shrauner | 5e6162d | 2014-09-22 20:47:45 -0700 | [diff] [blame] | 90 | if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) { |
| 91 | return; |
| 92 | } |
| 93 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 94 | switch (msg.what) { |
| 95 | case MSG_SET_IN_CALL_ADAPTER: |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 96 | String callingPackage = getApplicationContext().getOpPackageName(); |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 97 | mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj), callingPackage, |
| 98 | getApplicationContext().getApplicationInfo().targetSdkVersion); |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 99 | mPhone.addListener(mPhoneListener); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 100 | onPhoneCreated(mPhone); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 101 | break; |
| 102 | case MSG_ADD_CALL: |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 103 | mPhone.internalAddCall((ParcelableCall) msg.obj); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 104 | break; |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 105 | case MSG_UPDATE_CALL: |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 106 | mPhone.internalUpdateCall((ParcelableCall) msg.obj); |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 107 | break; |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 108 | case MSG_SET_POST_DIAL_WAIT: { |
| 109 | SomeArgs args = (SomeArgs) msg.obj; |
| 110 | try { |
| 111 | String callId = (String) args.arg1; |
| 112 | String remaining = (String) args.arg2; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 113 | mPhone.internalSetPostDialWait(callId, remaining); |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 114 | } finally { |
| 115 | args.recycle(); |
| 116 | } |
| 117 | break; |
| 118 | } |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 119 | case MSG_ON_CALL_AUDIO_STATE_CHANGED: |
| 120 | mPhone.internalCallAudioStateChanged((CallAudioState) msg.obj); |
Sailesh Nepal | b632e5b | 2014-04-03 12:54:33 -0700 | [diff] [blame] | 121 | break; |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 122 | case MSG_BRING_TO_FOREGROUND: |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 123 | mPhone.internalBringToForeground(msg.arg1 == 1); |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 124 | break; |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 125 | case MSG_ON_CAN_ADD_CALL_CHANGED: |
| 126 | mPhone.internalSetCanAddCall(msg.arg1 == 1); |
| 127 | break; |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 128 | case MSG_SILENCE_RINGER: |
| 129 | mPhone.internalSilenceRinger(); |
| 130 | break; |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 131 | case MSG_ON_CONNECTION_EVENT: { |
| 132 | SomeArgs args = (SomeArgs) msg.obj; |
| 133 | try { |
| 134 | String callId = (String) args.arg1; |
| 135 | String event = (String) args.arg2; |
| 136 | Bundle extras = (Bundle) args.arg3; |
| 137 | mPhone.internalOnConnectionEvent(callId, event, extras); |
| 138 | } finally { |
| 139 | args.recycle(); |
| 140 | } |
| 141 | break; |
| 142 | } |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 143 | case MSG_ON_RTT_UPGRADE_REQUEST: { |
| 144 | String callId = (String) msg.obj; |
| 145 | int requestId = msg.arg1; |
| 146 | mPhone.internalOnRttUpgradeRequest(callId, requestId); |
| 147 | break; |
| 148 | } |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 149 | case MSG_ON_RTT_INITIATION_FAILURE: { |
| 150 | String callId = (String) msg.obj; |
| 151 | int reason = msg.arg1; |
| 152 | mPhone.internalOnRttInitiationFailure(callId, reason); |
| 153 | break; |
| 154 | } |
Sanket Padawe | e29a266 | 2017-12-01 13:59:27 -0800 | [diff] [blame] | 155 | case MSG_ON_HANDOVER_FAILED: { |
| 156 | String callId = (String) msg.obj; |
| 157 | int error = msg.arg1; |
| 158 | mPhone.internalOnHandoverFailed(callId, error); |
| 159 | break; |
| 160 | } |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 161 | case MSG_ON_HANDOVER_COMPLETE: { |
| 162 | String callId = (String) msg.obj; |
| 163 | mPhone.internalOnHandoverComplete(callId); |
| 164 | break; |
| 165 | } |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 166 | default: |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | /** Manages the binder calls so that the implementor does not need to deal with it. */ |
| 173 | private final class InCallServiceBinder extends IInCallService.Stub { |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 174 | @Override |
| 175 | public void setInCallAdapter(IInCallAdapter inCallAdapter) { |
| 176 | mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget(); |
| 177 | } |
| 178 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 179 | @Override |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 180 | public void addCall(ParcelableCall call) { |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 181 | mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget(); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 184 | @Override |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 185 | public void updateCall(ParcelableCall call) { |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 186 | mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget(); |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void setPostDial(String callId, String remaining) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 191 | // TODO: Unused |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void setPostDialWait(String callId, String remaining) { |
| 196 | SomeArgs args = SomeArgs.obtain(); |
| 197 | args.arg1 = callId; |
| 198 | args.arg2 = remaining; |
| 199 | mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget(); |
| 200 | } |
Sailesh Nepal | b632e5b | 2014-04-03 12:54:33 -0700 | [diff] [blame] | 201 | |
| 202 | @Override |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 203 | public void onCallAudioStateChanged(CallAudioState callAudioState) { |
| 204 | mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, callAudioState).sendToTarget(); |
Sailesh Nepal | b632e5b | 2014-04-03 12:54:33 -0700 | [diff] [blame] | 205 | } |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 206 | |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 207 | @Override |
| 208 | public void bringToForeground(boolean showDialpad) { |
| 209 | mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget(); |
| 210 | } |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 211 | |
| 212 | @Override |
| 213 | public void onCanAddCallChanged(boolean canAddCall) { |
| 214 | mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0) |
| 215 | .sendToTarget(); |
| 216 | } |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 217 | |
| 218 | @Override |
| 219 | public void silenceRinger() { |
| 220 | mHandler.obtainMessage(MSG_SILENCE_RINGER).sendToTarget(); |
| 221 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 222 | |
| 223 | @Override |
| 224 | public void onConnectionEvent(String callId, String event, Bundle extras) { |
| 225 | SomeArgs args = SomeArgs.obtain(); |
| 226 | args.arg1 = callId; |
| 227 | args.arg2 = event; |
| 228 | args.arg3 = extras; |
| 229 | mHandler.obtainMessage(MSG_ON_CONNECTION_EVENT, args).sendToTarget(); |
| 230 | } |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 231 | |
| 232 | @Override |
| 233 | public void onRttUpgradeRequest(String callId, int id) { |
| 234 | mHandler.obtainMessage(MSG_ON_RTT_UPGRADE_REQUEST, id, 0, callId).sendToTarget(); |
| 235 | } |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 236 | |
| 237 | @Override |
| 238 | public void onRttInitiationFailure(String callId, int reason) { |
| 239 | mHandler.obtainMessage(MSG_ON_RTT_INITIATION_FAILURE, reason, 0, callId).sendToTarget(); |
| 240 | } |
Sanket Padawe | e29a266 | 2017-12-01 13:59:27 -0800 | [diff] [blame] | 241 | |
| 242 | @Override |
| 243 | public void onHandoverFailed(String callId, int error) { |
| 244 | mHandler.obtainMessage(MSG_ON_HANDOVER_FAILED, error, 0, callId).sendToTarget(); |
| 245 | } |
Tyler Gunn | 79bc1ec | 2018-01-22 15:17:54 -0800 | [diff] [blame] | 246 | |
| 247 | @Override |
| 248 | public void onHandoverComplete(String callId) { |
| 249 | mHandler.obtainMessage(MSG_ON_HANDOVER_COMPLETE, callId).sendToTarget(); |
| 250 | } |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 253 | private Phone.Listener mPhoneListener = new Phone.Listener() { |
| 254 | /** ${inheritDoc} */ |
| 255 | @Override |
| 256 | public void onAudioStateChanged(Phone phone, AudioState audioState) { |
| 257 | InCallService.this.onAudioStateChanged(audioState); |
| 258 | } |
| 259 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 260 | public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) { |
| 261 | InCallService.this.onCallAudioStateChanged(callAudioState); |
| 262 | }; |
| 263 | |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 264 | /** ${inheritDoc} */ |
| 265 | @Override |
| 266 | public void onBringToForeground(Phone phone, boolean showDialpad) { |
| 267 | InCallService.this.onBringToForeground(showDialpad); |
| 268 | } |
| 269 | |
| 270 | /** ${inheritDoc} */ |
| 271 | @Override |
| 272 | public void onCallAdded(Phone phone, Call call) { |
| 273 | InCallService.this.onCallAdded(call); |
| 274 | } |
| 275 | |
| 276 | /** ${inheritDoc} */ |
| 277 | @Override |
| 278 | public void onCallRemoved(Phone phone, Call call) { |
| 279 | InCallService.this.onCallRemoved(call); |
| 280 | } |
| 281 | |
| 282 | /** ${inheritDoc} */ |
| 283 | @Override |
| 284 | public void onCanAddCallChanged(Phone phone, boolean canAddCall) { |
| 285 | InCallService.this.onCanAddCallChanged(canAddCall); |
| 286 | } |
| 287 | |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 288 | /** ${inheritDoc} */ |
| 289 | @Override |
| 290 | public void onSilenceRinger(Phone phone) { |
| 291 | InCallService.this.onSilenceRinger(); |
| 292 | } |
| 293 | |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 296 | private Phone mPhone; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 297 | |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 298 | public InCallService() { |
| 299 | } |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 300 | |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 301 | @Override |
| 302 | public IBinder onBind(Intent intent) { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 303 | return new InCallServiceBinder(); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 306 | @Override |
| 307 | public boolean onUnbind(Intent intent) { |
Santos Cordon | 619b3c0 | 2014-09-02 17:13:45 -0700 | [diff] [blame] | 308 | if (mPhone != null) { |
| 309 | Phone oldPhone = mPhone; |
| 310 | mPhone = null; |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 311 | |
Santos Cordon | 619b3c0 | 2014-09-02 17:13:45 -0700 | [diff] [blame] | 312 | oldPhone.destroy(); |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 313 | // destroy sets all the calls to disconnected if any live ones still exist. Therefore, |
| 314 | // it is important to remove the Listener *after* the call to destroy so that |
| 315 | // InCallService.on* callbacks are appropriately called. |
| 316 | oldPhone.removeListener(mPhoneListener); |
| 317 | |
Santos Cordon | 619b3c0 | 2014-09-02 17:13:45 -0700 | [diff] [blame] | 318 | onPhoneDestroyed(oldPhone); |
| 319 | } |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 320 | |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 321 | return false; |
| 322 | } |
| 323 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 324 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 325 | * Obtain the {@code Phone} associated with this {@code InCallService}. |
| 326 | * |
| 327 | * @return The {@code Phone} object associated with this {@code InCallService}, or {@code null} |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 328 | * if the {@code InCallService} is not in a state where it has an associated |
| 329 | * {@code Phone}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 330 | * @hide |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 331 | * @deprecated Use direct methods on InCallService instead of {@link Phone}. |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 332 | */ |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 333 | @SystemApi |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 334 | @Deprecated |
| 335 | public Phone getPhone() { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 336 | return mPhone; |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /** |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 340 | * Obtains the current list of {@code Call}s to be displayed by this in-call service. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 341 | * |
| 342 | * @return A list of the relevant {@code Call}s. |
| 343 | */ |
| 344 | public final List<Call> getCalls() { |
| 345 | return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls(); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Returns if the device can support additional calls. |
| 350 | * |
| 351 | * @return Whether the phone supports adding more calls. |
| 352 | */ |
| 353 | public final boolean canAddCall() { |
| 354 | return mPhone == null ? false : mPhone.canAddCall(); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Obtains the current phone call audio state. |
| 359 | * |
| 360 | * @return An object encapsulating the audio state. Returns null if the service is not |
| 361 | * fully initialized. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 362 | * @deprecated Use {@link #getCallAudioState()} instead. |
| 363 | * @hide |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 364 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 365 | @Deprecated |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 366 | public final AudioState getAudioState() { |
| 367 | return mPhone == null ? null : mPhone.getAudioState(); |
| 368 | } |
| 369 | |
| 370 | /** |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 371 | * Obtains the current phone call audio state. |
| 372 | * |
| 373 | * @return An object encapsulating the audio state. Returns null if the service is not |
| 374 | * fully initialized. |
| 375 | */ |
| 376 | public final CallAudioState getCallAudioState() { |
| 377 | return mPhone == null ? null : mPhone.getCallAudioState(); |
| 378 | } |
| 379 | |
| 380 | /** |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 381 | * Sets the microphone mute state. When this request is honored, there will be change to |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 382 | * the {@link #getCallAudioState()}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 383 | * |
| 384 | * @param state {@code true} if the microphone should be muted; {@code false} otherwise. |
| 385 | */ |
| 386 | public final void setMuted(boolean state) { |
| 387 | if (mPhone != null) { |
| 388 | mPhone.setMuted(state); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 394 | * be change to the {@link #getCallAudioState()}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 395 | * |
| 396 | * @param route The audio route to use. |
| 397 | */ |
| 398 | public final void setAudioRoute(int route) { |
| 399 | if (mPhone != null) { |
| 400 | mPhone.setAudioRoute(route); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /** |
Hall Liu | a98f58b | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 405 | * Request audio routing to a specific bluetooth device. Calling this method may result in |
| 406 | * the device routing audio to a different bluetooth device than the one specified if the |
| 407 | * bluetooth stack is unable to route audio to the requested device. |
| 408 | * A list of available devices can be obtained via |
| 409 | * {@link CallAudioState#getSupportedBluetoothDevices()} |
| 410 | * |
| 411 | * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by |
| 412 | * {@link BluetoothDevice#getAddress()}. |
| 413 | */ |
| 414 | public final void requestBluetoothAudio(@NonNull String bluetoothAddress) { |
| 415 | if (mPhone != null) { |
| 416 | mPhone.requestBluetoothAudio(bluetoothAddress); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 421 | * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience |
| 422 | * to start displaying in-call information to the user. Each instance of {@code InCallService} |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 423 | * will have only one {@code Phone}, and this method will be called exactly once in the lifetime |
| 424 | * of the {@code InCallService}. |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 425 | * |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 426 | * @param phone The {@code Phone} object associated with this {@code InCallService}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 427 | * @hide |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 428 | * @deprecated Use direct methods on InCallService instead of {@link Phone}. |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 429 | */ |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 430 | @SystemApi |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 431 | @Deprecated |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 432 | public void onPhoneCreated(Phone phone) { |
| 433 | } |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 434 | |
| 435 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 436 | * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience |
| 437 | * to stop displaying in-call information to the user. This method will be called exactly once |
| 438 | * in the lifetime of the {@code InCallService}, and it will always be called after a previous |
| 439 | * call to {@link #onPhoneCreated(Phone)}. |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 440 | * |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 441 | * @param phone The {@code Phone} object associated with this {@code InCallService}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 442 | * @hide |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 443 | * @deprecated Use direct methods on InCallService instead of {@link Phone}. |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 444 | */ |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 445 | @SystemApi |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 446 | @Deprecated |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 447 | public void onPhoneDestroyed(Phone phone) { |
| 448 | } |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 449 | |
| 450 | /** |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 451 | * Called when the audio state changes. |
| 452 | * |
| 453 | * @param audioState The new {@link AudioState}. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 454 | * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState) instead}. |
| 455 | * @hide |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 456 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 457 | @Deprecated |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 458 | public void onAudioStateChanged(AudioState audioState) { |
| 459 | } |
| 460 | |
| 461 | /** |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 462 | * Called when the audio state changes. |
| 463 | * |
| 464 | * @param audioState The new {@link CallAudioState}. |
| 465 | */ |
| 466 | public void onCallAudioStateChanged(CallAudioState audioState) { |
| 467 | } |
| 468 | |
| 469 | /** |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 470 | * Called to bring the in-call screen to the foreground. The in-call experience should |
| 471 | * respond immediately by coming to the foreground to inform the user of the state of |
| 472 | * ongoing {@code Call}s. |
| 473 | * |
| 474 | * @param showDialpad If true, put up the dialpad when the screen is shown. |
| 475 | */ |
| 476 | public void onBringToForeground(boolean showDialpad) { |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Called when a {@code Call} has been added to this in-call session. The in-call user |
| 481 | * experience should add necessary state listeners to the specified {@code Call} and |
| 482 | * immediately start to show the user information about the existence |
| 483 | * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will |
| 484 | * include this {@code Call}. |
| 485 | * |
| 486 | * @param call A newly added {@code Call}. |
| 487 | */ |
| 488 | public void onCallAdded(Call call) { |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Called when a {@code Call} has been removed from this in-call session. The in-call user |
| 493 | * experience should remove any state listeners from the specified {@code Call} and |
| 494 | * immediately stop displaying any information about this {@code Call}. |
| 495 | * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}. |
| 496 | * |
| 497 | * @param call A newly removed {@code Call}. |
| 498 | */ |
| 499 | public void onCallRemoved(Call call) { |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Called when the ability to add more calls changes. If the phone cannot |
| 504 | * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it |
| 505 | * is set to {@code true}. This can be used to control the visibility of UI to add more calls. |
| 506 | * |
| 507 | * @param canAddCall Indicates whether an additional call can be added. |
| 508 | */ |
| 509 | public void onCanAddCallChanged(boolean canAddCall) { |
| 510 | } |
| 511 | |
| 512 | /** |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 513 | * Called to silence the ringer if a ringing call exists. |
| 514 | */ |
| 515 | public void onSilenceRinger() { |
| 516 | } |
| 517 | |
| 518 | /** |
Tyler Gunn | 06f3fa6 | 2016-08-25 09:26:15 -0700 | [diff] [blame] | 519 | * Unused; to handle connection events issued by a {@link ConnectionService}, implement the |
| 520 | * {@link android.telecom.Call.Callback#onConnectionEvent(Call, String, Bundle)} callback. |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 521 | * <p> |
| 522 | * See {@link Connection#sendConnectionEvent(String, Bundle)}. |
| 523 | * |
| 524 | * @param call The call the event is associated with. |
| 525 | * @param event The event. |
| 526 | * @param extras Any associated extras. |
| 527 | */ |
| 528 | public void onConnectionEvent(Call call, String event, Bundle extras) { |
| 529 | } |
| 530 | |
| 531 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 532 | * Used to issue commands to the {@link Connection.VideoProvider} associated with a |
| 533 | * {@link Call}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 534 | */ |
| 535 | public static abstract class VideoCall { |
| 536 | |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 537 | /** @hide */ |
| 538 | public abstract void destroy(); |
| 539 | |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 540 | /** |
Andrew Lee | 7c9ee2b | 2015-04-16 15:26:08 -0700 | [diff] [blame] | 541 | * Registers a callback to receive commands and state changes for video calls. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 542 | * |
Andrew Lee | 7c9ee2b | 2015-04-16 15:26:08 -0700 | [diff] [blame] | 543 | * @param callback The video call callback. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 544 | */ |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 545 | public abstract void registerCallback(VideoCall.Callback callback); |
| 546 | |
| 547 | /** |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 548 | * Registers a callback to receive commands and state changes for video calls. |
| 549 | * |
| 550 | * @param callback The video call callback. |
| 551 | * @param handler A handler which commands and status changes will be delivered to. |
| 552 | */ |
| 553 | public abstract void registerCallback(VideoCall.Callback callback, Handler handler); |
| 554 | |
| 555 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 556 | * Clears the video call callback set via {@link #registerCallback}. |
Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 557 | * |
| 558 | * @param callback The video call callback to clear. |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 559 | */ |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 560 | public abstract void unregisterCallback(VideoCall.Callback callback); |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 561 | |
| 562 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 563 | * Sets the camera to be used for the outgoing video. |
| 564 | * <p> |
| 565 | * Handled by {@link Connection.VideoProvider#onSetCamera(String)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 566 | * |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 567 | * @param cameraId The id of the camera (use ids as reported by |
| 568 | * {@link CameraManager#getCameraIdList()}). |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 569 | */ |
| 570 | public abstract void setCamera(String cameraId); |
| 571 | |
| 572 | /** |
| 573 | * Sets the surface to be used for displaying a preview of what the user's camera is |
| 574 | * currently capturing. When video transmission is enabled, this is the video signal which |
| 575 | * is sent to the remote device. |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 576 | * <p> |
| 577 | * Handled by {@link Connection.VideoProvider#onSetPreviewSurface(Surface)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 578 | * |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 579 | * @param surface The {@link Surface}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 580 | */ |
| 581 | public abstract void setPreviewSurface(Surface surface); |
| 582 | |
| 583 | /** |
| 584 | * Sets the surface to be used for displaying the video received from the remote device. |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 585 | * <p> |
| 586 | * Handled by {@link Connection.VideoProvider#onSetDisplaySurface(Surface)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 587 | * |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 588 | * @param surface The {@link Surface}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 589 | */ |
| 590 | public abstract void setDisplaySurface(Surface surface); |
| 591 | |
| 592 | /** |
| 593 | * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of |
| 594 | * the device is 0 degrees. |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 595 | * <p> |
| 596 | * Handled by {@link Connection.VideoProvider#onSetDeviceOrientation(int)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 597 | * |
| 598 | * @param rotation The device orientation, in degrees. |
| 599 | */ |
| 600 | public abstract void setDeviceOrientation(int rotation); |
| 601 | |
| 602 | /** |
| 603 | * Sets camera zoom ratio. |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 604 | * <p> |
| 605 | * Handled by {@link Connection.VideoProvider#onSetZoom(float)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 606 | * |
| 607 | * @param value The camera zoom ratio. |
| 608 | */ |
| 609 | public abstract void setZoom(float value); |
| 610 | |
| 611 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 612 | * Issues a request to modify the properties of the current video session. |
| 613 | * <p> |
| 614 | * Example scenarios include: requesting an audio-only call to be upgraded to a |
| 615 | * bi-directional video call, turning on or off the user's camera, sending a pause signal |
| 616 | * when the {@link InCallService} is no longer the foreground application. |
| 617 | * <p> |
| 618 | * Handled by |
| 619 | * {@link Connection.VideoProvider#onSendSessionModifyRequest(VideoProfile, VideoProfile)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 620 | * |
| 621 | * @param requestProfile The requested call video properties. |
| 622 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 623 | public abstract void sendSessionModifyRequest(VideoProfile requestProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 624 | |
| 625 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 626 | * Provides a response to a request to change the current call video session |
| 627 | * properties. This should be called in response to a request the {@link InCallService} has |
| 628 | * received via {@link VideoCall.Callback#onSessionModifyRequestReceived}. |
| 629 | * <p> |
| 630 | * Handled by |
| 631 | * {@link Connection.VideoProvider#onSendSessionModifyResponse(VideoProfile)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 632 | * |
| 633 | * @param responseProfile The response call video properties. |
| 634 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 635 | public abstract void sendSessionModifyResponse(VideoProfile responseProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 636 | |
| 637 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 638 | * Issues a request to the {@link Connection.VideoProvider} to retrieve the capabilities |
| 639 | * of the current camera. The current camera is selected using |
| 640 | * {@link VideoCall#setCamera(String)}. |
| 641 | * <p> |
| 642 | * Camera capabilities are reported to the caller via |
| 643 | * {@link VideoCall.Callback#onCameraCapabilitiesChanged(VideoProfile.CameraCapabilities)}. |
| 644 | * <p> |
| 645 | * Handled by {@link Connection.VideoProvider#onRequestCameraCapabilities()}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 646 | */ |
| 647 | public abstract void requestCameraCapabilities(); |
| 648 | |
| 649 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 650 | * Issues a request to the {@link Connection.VideoProvider} to retrieve the cumulative data |
| 651 | * usage for the video component of the current call (in bytes). Data usage is reported |
| 652 | * to the caller via {@link VideoCall.Callback#onCallDataUsageChanged}. |
| 653 | * <p> |
| 654 | * Handled by {@link Connection.VideoProvider#onRequestConnectionDataUsage()}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 655 | */ |
| 656 | public abstract void requestCallDataUsage(); |
| 657 | |
| 658 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 659 | * Provides the {@link Connection.VideoProvider} with the {@link Uri} of an image to be |
| 660 | * displayed to the peer device when the video signal is paused. |
| 661 | * <p> |
| 662 | * Handled by {@link Connection.VideoProvider#onSetPauseImage(Uri)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 663 | * |
| 664 | * @param uri URI of image to display. |
| 665 | */ |
Yorke Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 666 | public abstract void setPauseImage(Uri uri); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 667 | |
| 668 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 669 | * The {@link InCallService} extends this class to provide a means of receiving callbacks |
Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 670 | * from the {@link Connection.VideoProvider}. |
| 671 | * <p> |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 672 | * When the {@link InCallService} receives the |
| 673 | * {@link Call.Callback#onVideoCallChanged(Call, VideoCall)} callback, it should create an |
| 674 | * instance its {@link VideoCall.Callback} implementation and set it on the |
| 675 | * {@link VideoCall} using {@link VideoCall#registerCallback(Callback)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 676 | */ |
Andrew Lee | da80c87 | 2015-04-15 14:09:50 -0700 | [diff] [blame] | 677 | public static abstract class Callback { |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 678 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 679 | * Called when the {@link Connection.VideoProvider} receives a session modification |
Tyler Gunn | 295f5d7 | 2015-06-04 11:08:54 -0700 | [diff] [blame] | 680 | * request from the peer device. |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 681 | * <p> |
| 682 | * The {@link InCallService} may potentially prompt the user to confirm whether they |
| 683 | * wish to accept the request, or decide to automatically accept the request. In either |
| 684 | * case the {@link InCallService} should call |
| 685 | * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} to indicate the video |
| 686 | * profile agreed upon. |
| 687 | * <p> |
| 688 | * Callback originates from |
| 689 | * {@link Connection.VideoProvider#receiveSessionModifyRequest(VideoProfile)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 690 | * |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 691 | * @param videoProfile The requested video profile. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 692 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 693 | public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 694 | |
| 695 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 696 | * Called when the {@link Connection.VideoProvider} receives a response to a session |
| 697 | * modification request previously sent to the peer device. |
| 698 | * <p> |
| 699 | * The new video state should not be considered active by the {@link InCallService} |
| 700 | * until the {@link Call} video state changes (the |
| 701 | * {@link Call.Callback#onDetailsChanged(Call, Call.Details)} callback is triggered |
| 702 | * when the video state changes). |
| 703 | * <p> |
| 704 | * Callback originates from |
| 705 | * {@link Connection.VideoProvider#receiveSessionModifyResponse(int, VideoProfile, |
| 706 | * VideoProfile)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 707 | * |
| 708 | * @param status Status of the session modify request. Valid values are |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 709 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS}, |
| 710 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL}, |
| 711 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID}, |
| 712 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT}, |
| 713 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}. |
| 714 | * @param requestedProfile The original request which was sent to the peer device. |
| 715 | * @param responseProfile The actual profile changes made by the peer device. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 716 | */ |
| 717 | public abstract void onSessionModifyResponseReceived(int status, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 718 | VideoProfile requestedProfile, VideoProfile responseProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 719 | |
| 720 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 721 | * Handles events related to the current video session which the {@link InCallService} |
| 722 | * may wish to handle. These are separate from requested changes to the session due to |
| 723 | * the underlying protocol or connection. |
| 724 | * <p> |
| 725 | * Callback originates from |
| 726 | * {@link Connection.VideoProvider#handleCallSessionEvent(int)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 727 | * |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 728 | * @param event The event. Valid values are: |
| 729 | * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE}, |
| 730 | * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME}, |
| 731 | * {@link Connection.VideoProvider#SESSION_EVENT_TX_START}, |
| 732 | * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP}, |
| 733 | * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE}, |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 734 | * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY}, |
| 735 | * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_PERMISSION_ERROR}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 736 | */ |
| 737 | public abstract void onCallSessionEvent(int event); |
| 738 | |
| 739 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 740 | * Handles a change to the video dimensions from the peer device. This could happen if, |
| 741 | * for example, the peer changes orientation of their device, or switches cameras. |
| 742 | * <p> |
| 743 | * Callback originates from |
| 744 | * {@link Connection.VideoProvider#changePeerDimensions(int, int)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 745 | * |
| 746 | * @param width The updated peer video width. |
| 747 | * @param height The updated peer video height. |
| 748 | */ |
| 749 | public abstract void onPeerDimensionsChanged(int width, int height); |
| 750 | |
| 751 | /** |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 752 | * Handles a change to the video quality. |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 753 | * <p> |
| 754 | * Callback originates from {@link Connection.VideoProvider#changeVideoQuality(int)}. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 755 | * |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 756 | * @param videoQuality The updated peer video quality. Valid values: |
| 757 | * {@link VideoProfile#QUALITY_HIGH}, |
| 758 | * {@link VideoProfile#QUALITY_MEDIUM}, |
| 759 | * {@link VideoProfile#QUALITY_LOW}, |
| 760 | * {@link VideoProfile#QUALITY_DEFAULT}. |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 761 | */ |
| 762 | public abstract void onVideoQualityChanged(int videoQuality); |
| 763 | |
| 764 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 765 | * Handles an update to the total data used for the current video session. |
| 766 | * <p> |
| 767 | * Used by the {@link Connection.VideoProvider} in response to |
| 768 | * {@link VideoCall#requestCallDataUsage()}. May also be called periodically by the |
| 769 | * {@link Connection.VideoProvider}. |
| 770 | * <p> |
| 771 | * Callback originates from {@link Connection.VideoProvider#setCallDataUsage(long)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 772 | * |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 773 | * @param dataUsage The updated data usage (in bytes). |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 774 | */ |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 775 | public abstract void onCallDataUsageChanged(long dataUsage); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 776 | |
| 777 | /** |
Tyler Gunn | b702ef8 | 2015-05-29 11:51:53 -0700 | [diff] [blame] | 778 | * Handles a change in the capabilities of the currently selected camera. |
| 779 | * <p> |
| 780 | * Used by the {@link Connection.VideoProvider} in response to |
| 781 | * {@link VideoCall#requestCameraCapabilities()}. The {@link Connection.VideoProvider} |
| 782 | * may also report the camera capabilities after a call to |
| 783 | * {@link VideoCall#setCamera(String)}. |
| 784 | * <p> |
| 785 | * Callback originates from |
| 786 | * {@link Connection.VideoProvider#changeCameraCapabilities( |
| 787 | * VideoProfile.CameraCapabilities)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 788 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 789 | * @param cameraCapabilities The changed camera capabilities. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 790 | */ |
Yorke Lee | 400470f | 2015-05-12 13:31:25 -0700 | [diff] [blame] | 791 | public abstract void onCameraCapabilitiesChanged( |
| 792 | VideoProfile.CameraCapabilities cameraCapabilities); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 793 | } |
| 794 | } |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 795 | } |