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