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