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