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 | |
Tyler Gunn | 2ac4010 | 2014-08-18 16:23:10 -0700 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 21 | import android.app.Service; |
| 22 | import android.content.Intent; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 23 | import android.os.Handler; |
| 24 | import android.os.IBinder; |
| 25 | import android.os.Looper; |
| 26 | import android.os.Message; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 27 | import android.view.Surface; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 28 | |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 29 | import com.android.internal.os.SomeArgs; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 30 | import com.android.internal.telecom.IInCallAdapter; |
| 31 | import com.android.internal.telecom.IInCallService; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 32 | |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 33 | import java.lang.String; |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 34 | import java.util.Collections; |
| 35 | import java.util.List; |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 36 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 37 | /** |
| 38 | * 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] | 39 | * phone calls. Telecom binds to this service while there exists a live (active or incoming) call, |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 40 | * and uses it to notify the in-call app of any live and and recently disconnected calls. |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 41 | */ |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 42 | public abstract class InCallService extends Service { |
Tyler Gunn | 2ac4010 | 2014-08-18 16:23:10 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * The {@link Intent} that must be declared as handled by the service. |
| 46 | */ |
| 47 | @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 48 | public static final String SERVICE_INTERFACE = "android.telecom.InCallService"; |
Tyler Gunn | 2ac4010 | 2014-08-18 16:23:10 -0700 | [diff] [blame] | 49 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 50 | private static final int MSG_SET_IN_CALL_ADAPTER = 1; |
| 51 | private static final int MSG_ADD_CALL = 2; |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 52 | private static final int MSG_UPDATE_CALL = 3; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 53 | private static final int MSG_SET_POST_DIAL_WAIT = 4; |
| 54 | private static final int MSG_ON_AUDIO_STATE_CHANGED = 5; |
| 55 | private static final int MSG_BRING_TO_FOREGROUND = 6; |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 56 | private static final int MSG_ON_CAN_ADD_CALL_CHANGED = 7; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 57 | |
| 58 | /** Default Handler used to consolidate binder method calls onto a single thread. */ |
| 59 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 60 | @Override |
| 61 | public void handleMessage(Message msg) { |
Jay Shrauner | 5e6162d | 2014-09-22 20:47:45 -0700 | [diff] [blame] | 62 | if (mPhone == null && msg.what != MSG_SET_IN_CALL_ADAPTER) { |
| 63 | return; |
| 64 | } |
| 65 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 66 | switch (msg.what) { |
| 67 | case MSG_SET_IN_CALL_ADAPTER: |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 68 | mPhone = new Phone(new InCallAdapter((IInCallAdapter) msg.obj)); |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 69 | mPhone.addListener(mPhoneListener); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 70 | onPhoneCreated(mPhone); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 71 | break; |
| 72 | case MSG_ADD_CALL: |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 73 | mPhone.internalAddCall((ParcelableCall) msg.obj); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 74 | break; |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 75 | case MSG_UPDATE_CALL: |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 76 | mPhone.internalUpdateCall((ParcelableCall) msg.obj); |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 77 | break; |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 78 | case MSG_SET_POST_DIAL_WAIT: { |
| 79 | SomeArgs args = (SomeArgs) msg.obj; |
| 80 | try { |
| 81 | String callId = (String) args.arg1; |
| 82 | String remaining = (String) args.arg2; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 83 | mPhone.internalSetPostDialWait(callId, remaining); |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 84 | } finally { |
| 85 | args.recycle(); |
| 86 | } |
| 87 | break; |
| 88 | } |
Sailesh Nepal | 4cff392 | 2014-03-19 10:15:37 -0700 | [diff] [blame] | 89 | case MSG_ON_AUDIO_STATE_CHANGED: |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 90 | mPhone.internalAudioStateChanged((AudioState) msg.obj); |
Sailesh Nepal | b632e5b | 2014-04-03 12:54:33 -0700 | [diff] [blame] | 91 | break; |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 92 | case MSG_BRING_TO_FOREGROUND: |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 93 | mPhone.internalBringToForeground(msg.arg1 == 1); |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 94 | break; |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 95 | case MSG_ON_CAN_ADD_CALL_CHANGED: |
| 96 | mPhone.internalSetCanAddCall(msg.arg1 == 1); |
| 97 | break; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 98 | default: |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | /** Manages the binder calls so that the implementor does not need to deal with it. */ |
| 105 | private final class InCallServiceBinder extends IInCallService.Stub { |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 106 | @Override |
| 107 | public void setInCallAdapter(IInCallAdapter inCallAdapter) { |
| 108 | mHandler.obtainMessage(MSG_SET_IN_CALL_ADAPTER, inCallAdapter).sendToTarget(); |
| 109 | } |
| 110 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 111 | @Override |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 112 | public void addCall(ParcelableCall call) { |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 113 | mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget(); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 116 | @Override |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 117 | public void updateCall(ParcelableCall call) { |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 118 | mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget(); |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void setPostDial(String callId, String remaining) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 123 | // TODO: Unused |
Ihab Awad | 2f23664 | 2014-03-10 15:33:45 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void setPostDialWait(String callId, String remaining) { |
| 128 | SomeArgs args = SomeArgs.obtain(); |
| 129 | args.arg1 = callId; |
| 130 | args.arg2 = remaining; |
| 131 | mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget(); |
| 132 | } |
Sailesh Nepal | b632e5b | 2014-04-03 12:54:33 -0700 | [diff] [blame] | 133 | |
| 134 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 135 | public void onAudioStateChanged(AudioState audioState) { |
Sailesh Nepal | 6043793 | 2014-04-05 16:44:55 -0700 | [diff] [blame] | 136 | mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, audioState).sendToTarget(); |
Sailesh Nepal | b632e5b | 2014-04-03 12:54:33 -0700 | [diff] [blame] | 137 | } |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 138 | |
Santos Cordon | 3534ede | 2014-05-29 13:07:10 -0700 | [diff] [blame] | 139 | @Override |
| 140 | public void bringToForeground(boolean showDialpad) { |
| 141 | mHandler.obtainMessage(MSG_BRING_TO_FOREGROUND, showDialpad ? 1 : 0, 0).sendToTarget(); |
| 142 | } |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 143 | |
| 144 | @Override |
| 145 | public void onCanAddCallChanged(boolean canAddCall) { |
| 146 | mHandler.obtainMessage(MSG_ON_CAN_ADD_CALL_CHANGED, canAddCall ? 1 : 0, 0) |
| 147 | .sendToTarget(); |
| 148 | } |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 151 | private Phone.Listener mPhoneListener = new Phone.Listener() { |
| 152 | /** ${inheritDoc} */ |
| 153 | @Override |
| 154 | public void onAudioStateChanged(Phone phone, AudioState audioState) { |
| 155 | InCallService.this.onAudioStateChanged(audioState); |
| 156 | } |
| 157 | |
| 158 | /** ${inheritDoc} */ |
| 159 | @Override |
| 160 | public void onBringToForeground(Phone phone, boolean showDialpad) { |
| 161 | InCallService.this.onBringToForeground(showDialpad); |
| 162 | } |
| 163 | |
| 164 | /** ${inheritDoc} */ |
| 165 | @Override |
| 166 | public void onCallAdded(Phone phone, Call call) { |
| 167 | InCallService.this.onCallAdded(call); |
| 168 | } |
| 169 | |
| 170 | /** ${inheritDoc} */ |
| 171 | @Override |
| 172 | public void onCallRemoved(Phone phone, Call call) { |
| 173 | InCallService.this.onCallRemoved(call); |
| 174 | } |
| 175 | |
| 176 | /** ${inheritDoc} */ |
| 177 | @Override |
| 178 | public void onCanAddCallChanged(Phone phone, boolean canAddCall) { |
| 179 | InCallService.this.onCanAddCallChanged(canAddCall); |
| 180 | } |
| 181 | |
| 182 | }; |
| 183 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 184 | private Phone mPhone; |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 185 | |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 186 | public InCallService() { |
| 187 | } |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 188 | |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 189 | @Override |
| 190 | public IBinder onBind(Intent intent) { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 191 | return new InCallServiceBinder(); |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 194 | @Override |
| 195 | public boolean onUnbind(Intent intent) { |
Santos Cordon | 619b3c0 | 2014-09-02 17:13:45 -0700 | [diff] [blame] | 196 | if (mPhone != null) { |
| 197 | Phone oldPhone = mPhone; |
| 198 | mPhone = null; |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 199 | |
Santos Cordon | 619b3c0 | 2014-09-02 17:13:45 -0700 | [diff] [blame] | 200 | oldPhone.destroy(); |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 201 | // destroy sets all the calls to disconnected if any live ones still exist. Therefore, |
| 202 | // it is important to remove the Listener *after* the call to destroy so that |
| 203 | // InCallService.on* callbacks are appropriately called. |
| 204 | oldPhone.removeListener(mPhoneListener); |
| 205 | |
Santos Cordon | 619b3c0 | 2014-09-02 17:13:45 -0700 | [diff] [blame] | 206 | onPhoneDestroyed(oldPhone); |
| 207 | } |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 208 | |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 209 | return false; |
| 210 | } |
| 211 | |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 212 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 213 | * Obtain the {@code Phone} associated with this {@code InCallService}. |
| 214 | * |
| 215 | * @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] | 216 | * if the {@code InCallService} is not in a state where it has an associated |
| 217 | * {@code Phone}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 218 | * @hide |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 219 | */ |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 220 | @SystemApi |
Jay Shrauner | 164a0ac | 2015-04-14 18:16:10 -0700 | [diff] [blame] | 221 | public final Phone getPhone() { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 222 | return mPhone; |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /** |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 226 | * Obtains the current list of {@code Call}s to be displayed by this in-call experience. |
| 227 | * |
| 228 | * @return A list of the relevant {@code Call}s. |
| 229 | */ |
| 230 | public final List<Call> getCalls() { |
| 231 | return mPhone == null ? Collections.<Call>emptyList() : mPhone.getCalls(); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Returns if the device can support additional calls. |
| 236 | * |
| 237 | * @return Whether the phone supports adding more calls. |
| 238 | */ |
| 239 | public final boolean canAddCall() { |
| 240 | return mPhone == null ? false : mPhone.canAddCall(); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Obtains the current phone call audio state. |
| 245 | * |
| 246 | * @return An object encapsulating the audio state. Returns null if the service is not |
| 247 | * fully initialized. |
| 248 | */ |
| 249 | public final AudioState getAudioState() { |
| 250 | return mPhone == null ? null : mPhone.getAudioState(); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Sets the microphone mute state. When this request is honored, there will be change to |
| 255 | * the {@link #getAudioState()}. |
| 256 | * |
| 257 | * @param state {@code true} if the microphone should be muted; {@code false} otherwise. |
| 258 | */ |
| 259 | public final void setMuted(boolean state) { |
| 260 | if (mPhone != null) { |
| 261 | mPhone.setMuted(state); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will |
| 267 | * be change to the {@link #getAudioState()}. |
| 268 | * |
| 269 | * @param route The audio route to use. |
| 270 | */ |
| 271 | public final void setAudioRoute(int route) { |
| 272 | if (mPhone != null) { |
| 273 | mPhone.setAudioRoute(route); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 278 | * Invoked when the {@code Phone} has been created. This is a signal to the in-call experience |
| 279 | * 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] | 280 | * will have only one {@code Phone}, and this method will be called exactly once in the lifetime |
| 281 | * of the {@code InCallService}. |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 282 | * |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 283 | * @param phone The {@code Phone} object associated with this {@code InCallService}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 284 | * @hide |
Evan Charlton | 924748f | 2014-04-03 08:36:38 -0700 | [diff] [blame] | 285 | */ |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 286 | @SystemApi |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 287 | public void onPhoneCreated(Phone phone) { |
| 288 | } |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 289 | |
| 290 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 291 | * Invoked when a {@code Phone} has been destroyed. This is a signal to the in-call experience |
| 292 | * to stop displaying in-call information to the user. This method will be called exactly once |
| 293 | * in the lifetime of the {@code InCallService}, and it will always be called after a previous |
| 294 | * call to {@link #onPhoneCreated(Phone)}. |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 295 | * |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 296 | * @param phone The {@code Phone} object associated with this {@code InCallService}. |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 297 | * @hide |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 298 | */ |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 299 | @SystemApi |
Santos Cordon | 2f42b11 | 2014-07-19 13:19:37 -0700 | [diff] [blame] | 300 | public void onPhoneDestroyed(Phone phone) { |
| 301 | } |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 302 | |
| 303 | /** |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 304 | * Called when the audio state changes. |
| 305 | * |
| 306 | * @param audioState The new {@link AudioState}. |
| 307 | */ |
| 308 | public void onAudioStateChanged(AudioState audioState) { |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Called to bring the in-call screen to the foreground. The in-call experience should |
| 313 | * respond immediately by coming to the foreground to inform the user of the state of |
| 314 | * ongoing {@code Call}s. |
| 315 | * |
| 316 | * @param showDialpad If true, put up the dialpad when the screen is shown. |
| 317 | */ |
| 318 | public void onBringToForeground(boolean showDialpad) { |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Called when a {@code Call} has been added to this in-call session. The in-call user |
| 323 | * experience should add necessary state listeners to the specified {@code Call} and |
| 324 | * immediately start to show the user information about the existence |
| 325 | * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will |
| 326 | * include this {@code Call}. |
| 327 | * |
| 328 | * @param call A newly added {@code Call}. |
| 329 | */ |
| 330 | public void onCallAdded(Call call) { |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Called when a {@code Call} has been removed from this in-call session. The in-call user |
| 335 | * experience should remove any state listeners from the specified {@code Call} and |
| 336 | * immediately stop displaying any information about this {@code Call}. |
| 337 | * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}. |
| 338 | * |
| 339 | * @param call A newly removed {@code Call}. |
| 340 | */ |
| 341 | public void onCallRemoved(Call call) { |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Called when the ability to add more calls changes. If the phone cannot |
| 346 | * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it |
| 347 | * is set to {@code true}. This can be used to control the visibility of UI to add more calls. |
| 348 | * |
| 349 | * @param canAddCall Indicates whether an additional call can be added. |
| 350 | */ |
| 351 | public void onCanAddCallChanged(boolean canAddCall) { |
| 352 | } |
| 353 | |
| 354 | /** |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 355 | * Class to invoke functionality related to video calls. |
| 356 | */ |
| 357 | public static abstract class VideoCall { |
| 358 | |
| 359 | /** |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 360 | * Sets a listener to invoke callback methods in the InCallUI after performing video |
| 361 | * telephony actions. |
| 362 | * |
| 363 | * @param videoCallListener The call video client. |
| 364 | */ |
| 365 | public abstract void setVideoCallListener(VideoCall.Listener videoCallListener); |
| 366 | |
| 367 | /** |
| 368 | * Sets the camera to be used for video recording in a video call. |
| 369 | * |
| 370 | * @param cameraId The id of the camera. |
| 371 | */ |
| 372 | public abstract void setCamera(String cameraId); |
| 373 | |
| 374 | /** |
| 375 | * Sets the surface to be used for displaying a preview of what the user's camera is |
| 376 | * currently capturing. When video transmission is enabled, this is the video signal which |
| 377 | * is sent to the remote device. |
| 378 | * |
| 379 | * @param surface The surface. |
| 380 | */ |
| 381 | public abstract void setPreviewSurface(Surface surface); |
| 382 | |
| 383 | /** |
| 384 | * Sets the surface to be used for displaying the video received from the remote device. |
| 385 | * |
| 386 | * @param surface The surface. |
| 387 | */ |
| 388 | public abstract void setDisplaySurface(Surface surface); |
| 389 | |
| 390 | /** |
| 391 | * Sets the device orientation, in degrees. Assumes that a standard portrait orientation of |
| 392 | * the device is 0 degrees. |
| 393 | * |
| 394 | * @param rotation The device orientation, in degrees. |
| 395 | */ |
| 396 | public abstract void setDeviceOrientation(int rotation); |
| 397 | |
| 398 | /** |
| 399 | * Sets camera zoom ratio. |
| 400 | * |
| 401 | * @param value The camera zoom ratio. |
| 402 | */ |
| 403 | public abstract void setZoom(float value); |
| 404 | |
| 405 | /** |
| 406 | * Issues a request to modify the properties of the current session. The request is sent to |
| 407 | * the remote device where it it handled by |
| 408 | * {@link VideoCall.Listener#onSessionModifyRequestReceived}. |
| 409 | * Some examples of session modification requests: upgrade call from audio to video, |
| 410 | * downgrade call from video to audio, pause video. |
| 411 | * |
| 412 | * @param requestProfile The requested call video properties. |
| 413 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 414 | public abstract void sendSessionModifyRequest(VideoProfile requestProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 415 | |
| 416 | /** |
| 417 | * Provides a response to a request to change the current call session video |
| 418 | * properties. |
| 419 | * This is in response to a request the InCall UI has received via |
| 420 | * {@link VideoCall.Listener#onSessionModifyRequestReceived}. |
| 421 | * The response is handled on the remove device by |
| 422 | * {@link VideoCall.Listener#onSessionModifyResponseReceived}. |
| 423 | * |
| 424 | * @param responseProfile The response call video properties. |
| 425 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 426 | public abstract void sendSessionModifyResponse(VideoProfile responseProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * Issues a request to the video provider to retrieve the camera capabilities. |
| 430 | * Camera capabilities are reported back to the caller via |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 431 | * {@link VideoCall.Listener#onCameraCapabilitiesChanged(CameraCapabilities)}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 432 | */ |
| 433 | public abstract void requestCameraCapabilities(); |
| 434 | |
| 435 | /** |
| 436 | * Issues a request to the video telephony framework to retrieve the cumulative data usage for |
| 437 | * the current call. Data usage is reported back to the caller via |
| 438 | * {@link VideoCall.Listener#onCallDataUsageChanged}. |
| 439 | */ |
| 440 | public abstract void requestCallDataUsage(); |
| 441 | |
| 442 | /** |
| 443 | * Provides the video telephony framework with the URI of an image to be displayed to remote |
| 444 | * devices when the video signal is paused. |
| 445 | * |
| 446 | * @param uri URI of image to display. |
| 447 | */ |
| 448 | public abstract void setPauseImage(String uri); |
| 449 | |
| 450 | /** |
| 451 | * Listener class which invokes callbacks after video call actions occur. |
| 452 | */ |
| 453 | public static abstract class Listener { |
| 454 | /** |
| 455 | * Called when a session modification request is received from the remote device. |
Andrew Lee | 1418576 | 2014-07-25 09:41:56 -0700 | [diff] [blame] | 456 | * The remote request is sent via |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 457 | * {@link Connection.VideoProvider#onSendSessionModifyRequest}. The InCall UI |
Andrew Lee | 1418576 | 2014-07-25 09:41:56 -0700 | [diff] [blame] | 458 | * is responsible for potentially prompting the user whether they wish to accept the new |
| 459 | * call profile (e.g. prompt user if they wish to accept an upgrade from an audio to a |
| 460 | * video call) and should call |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 461 | * {@link Connection.VideoProvider#onSendSessionModifyResponse} to indicate |
Andrew Lee | 1418576 | 2014-07-25 09:41:56 -0700 | [diff] [blame] | 462 | * the video settings the user has agreed to. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 463 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 464 | * @param videoProfile The requested video call profile. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 465 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 466 | public abstract void onSessionModifyRequestReceived(VideoProfile videoProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 467 | |
| 468 | /** |
| 469 | * Called when a response to a session modification request is received from the remote |
| 470 | * device. The remote InCall UI sends the response using |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 471 | * {@link Connection.VideoProvider#onSendSessionModifyResponse}. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 472 | * |
| 473 | * @param status Status of the session modify request. Valid values are |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 474 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS}, |
| 475 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL}, |
| 476 | * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID} |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 477 | * @param requestedProfile The original request which was sent to the remote device. |
| 478 | * @param responseProfile The actual profile changes made by the remote device. |
| 479 | */ |
| 480 | public abstract void onSessionModifyResponseReceived(int status, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 481 | VideoProfile requestedProfile, VideoProfile responseProfile); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 482 | |
| 483 | /** |
| 484 | * Handles events related to the current session which the client may wish to handle. |
| 485 | * These are separate from requested changes to the session due to the underlying |
| 486 | * protocol or connection. |
| 487 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 488 | * Valid values are: |
| 489 | * {@link Connection.VideoProvider#SESSION_EVENT_RX_PAUSE}, |
| 490 | * {@link Connection.VideoProvider#SESSION_EVENT_RX_RESUME}, |
| 491 | * {@link Connection.VideoProvider#SESSION_EVENT_TX_START}, |
| 492 | * {@link Connection.VideoProvider#SESSION_EVENT_TX_STOP}, |
| 493 | * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_FAILURE}, |
| 494 | * {@link Connection.VideoProvider#SESSION_EVENT_CAMERA_READY} |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 495 | * |
| 496 | * @param event The event. |
| 497 | */ |
| 498 | public abstract void onCallSessionEvent(int event); |
| 499 | |
| 500 | /** |
| 501 | * Handles a change to the video dimensions from the remote caller (peer). This could |
| 502 | * happen if, for example, the peer changes orientation of their device. |
| 503 | * |
| 504 | * @param width The updated peer video width. |
| 505 | * @param height The updated peer video height. |
| 506 | */ |
| 507 | public abstract void onPeerDimensionsChanged(int width, int height); |
| 508 | |
| 509 | /** |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 510 | * Handles a change to the video quality. |
| 511 | * |
| 512 | * @param videoQuality The updated peer video quality. |
| 513 | */ |
| 514 | public abstract void onVideoQualityChanged(int videoQuality); |
| 515 | |
| 516 | /** |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 517 | * Handles an update to the total data used for the current session. |
| 518 | * |
| 519 | * @param dataUsage The updated data usage. |
| 520 | */ |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 521 | public abstract void onCallDataUsageChanged(long dataUsage); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * Handles a change in camera capabilities. |
| 525 | * |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 526 | * @param cameraCapabilities The changed camera capabilities. |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 527 | */ |
Santos Cordon | a249281 | 2015-04-15 11:05:16 -0700 | [diff] [blame] | 528 | public abstract void onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities); |
Andrew Lee | 50aca23 | 2014-07-22 16:41:54 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
Sailesh Nepal | ab5d282 | 2014-03-08 18:01:06 -0800 | [diff] [blame] | 531 | } |