From 9d12773b51eb409ae0424e162957da87c033cbfa Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Fri, 2 Mar 2018 15:45:51 -0800 Subject: API Documentation and Constant cleanup. 1. Update handover API docs for clarity. 2. Added an unknown value per API review comments. 3. Renamed HANDOVER_FAILURE_DEST_USER_REJECTED to HANDOVER_FAILURE_USER_REJECTED 3. Removed the HANDOVER_FAILURE_DEST_INVALID_PERM constant since it isn't used (methods which deal with permissions throw security exceptions). Test: Make doc and verify documentation. Change-Id: Id21d6b4c83d5c773ab38d78eb6b1886a1ac4dadf Fixes: 73751004 Fixes: 73750515 Fixes: 73750817 --- api/current.txt | 8 +- telecomm/java/android/telecom/Call.java | 137 +++++++++++++++++---- .../java/android/telecom/ConnectionService.java | 98 +++++++++++++-- telecomm/java/android/telecom/TelecomManager.java | 24 +++- telecomm/java/android/telecom/VideoProfile.java | 1 + 5 files changed, 227 insertions(+), 41 deletions(-) diff --git a/api/current.txt b/api/current.txt index 77d261e5830e..705a0d3fc71f 100644 --- a/api/current.txt +++ b/api/current.txt @@ -39196,10 +39196,10 @@ package android.telecom { method public void onStateChanged(android.telecom.Call, int); method public void onVideoCallChanged(android.telecom.Call, android.telecom.InCallService.VideoCall); field public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1; // 0x1 - field public static final int HANDOVER_FAILURE_DEST_INVALID_PERM = 3; // 0x3 - field public static final int HANDOVER_FAILURE_DEST_NOT_SUPPORTED = 2; // 0x2 - field public static final int HANDOVER_FAILURE_DEST_USER_REJECTED = 4; // 0x4 - field public static final int HANDOVER_FAILURE_ONGOING_EMERG_CALL = 5; // 0x5 + field public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2; // 0x2 + field public static final int HANDOVER_FAILURE_ONGOING_EMERG_CALL = 4; // 0x4 + field public static final int HANDOVER_FAILURE_UNKNOWN = 5; // 0x5 + field public static final int HANDOVER_FAILURE_USER_REJECTED = 3; // 0x3 } public static class Call.Details { diff --git a/telecomm/java/android/telecom/Call.java b/telecomm/java/android/telecom/Call.java index 2341f03d2ec5..e82bd9902268 100644 --- a/telecomm/java/android/telecom/Call.java +++ b/telecomm/java/android/telecom/Call.java @@ -873,42 +873,76 @@ public final class Call { /** * @hide */ - @IntDef({HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_DEST_NOT_SUPPORTED, - HANDOVER_FAILURE_DEST_INVALID_PERM, HANDOVER_FAILURE_DEST_USER_REJECTED, - HANDOVER_FAILURE_ONGOING_EMERG_CALL}) + @IntDef(prefix = { "HANDOVER_" }, + value = {HANDOVER_FAILURE_DEST_APP_REJECTED, HANDOVER_FAILURE_NOT_SUPPORTED, + HANDOVER_FAILURE_USER_REJECTED, HANDOVER_FAILURE_ONGOING_EMERG_CALL, + HANDOVER_FAILURE_UNKNOWN}) @Retention(RetentionPolicy.SOURCE) public @interface HandoverFailureErrors {} /** * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the app - * to handover the call rejects handover. + * to handover the call to rejects the handover request. + *

+ * Will be returned when {@link Call#handoverTo(PhoneAccountHandle, int, Bundle)} is called + * and the destination {@link PhoneAccountHandle}'s {@link ConnectionService} returns a + * {@code null} {@link Connection} from + * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle, + * ConnectionRequest)}. + *

+ * For more information on call handovers, see + * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}. */ public static final int HANDOVER_FAILURE_DEST_APP_REJECTED = 1; /** - * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there is - * an error associated with unsupported handover. - */ - public static final int HANDOVER_FAILURE_DEST_NOT_SUPPORTED = 2; - - /** - * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there - * are some permission errors associated with APIs doing handover. + * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover + * is initiated but the source or destination app does not support handover. + *

+ * Will be returned when a handover is requested via + * {@link #handoverTo(PhoneAccountHandle, int, Bundle)} and the destination + * {@link PhoneAccountHandle} does not declare + * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. May also be returned when a handover is + * requested at the {@link PhoneAccountHandle} for the current call (i.e. the source call's + * {@link Details#getAccountHandle()}) does not declare + * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. + *

+ * For more information on call handovers, see + * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}. */ - public static final int HANDOVER_FAILURE_DEST_INVALID_PERM = 3; + public static final int HANDOVER_FAILURE_NOT_SUPPORTED = 2; /** - * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when user - * rejects handover. + * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when the remote + * user rejects the handover request. + *

+ * For more information on call handovers, see + * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}. */ - public static final int HANDOVER_FAILURE_DEST_USER_REJECTED = 4; + public static final int HANDOVER_FAILURE_USER_REJECTED = 3; /** * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when there * is ongoing emergency call. + *

+ * This error code is returned when {@link #handoverTo(PhoneAccountHandle, int, Bundle)} is + * called on an emergency call, or if any other call is an emergency call. + *

+ * Handovers are not permitted while there are ongoing emergency calls. + *

+ * For more information on call handovers, see + * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}. */ - public static final int HANDOVER_FAILURE_ONGOING_EMERG_CALL = 5; + public static final int HANDOVER_FAILURE_ONGOING_EMERG_CALL = 4; + /** + * Handover failure reason returned via {@link #onHandoverFailed(Call, int)} when a handover + * fails for an unknown reason. + *

+ * For more information on call handovers, see + * {@link #handoverTo(PhoneAccountHandle, int, Bundle)}. + */ + public static final int HANDOVER_FAILURE_UNKNOWN = 5; /** * Invoked when the state of this {@code Call} has changed. See {@link #getState()}. @@ -1049,6 +1083,10 @@ public final class Call { /** * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount} * has completed successfully. + *

+ * For a full discussion of the handover process and the APIs involved, see + * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}. + * * @param call The call which had initiated handover. */ public void onHandoverComplete(Call call) {} @@ -1056,8 +1094,12 @@ public final class Call { /** * Invoked when Call handover from one {@link PhoneAccount} to other {@link PhoneAccount} * has failed. + *

+ * For a full discussion of the handover process and the APIs involved, see + * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}. + * * @param call The call which had initiated handover. - * @param failureReason Error reason for failure + * @param failureReason Error reason for failure. */ public void onHandoverFailed(Call call, @HandoverFailureErrors int failureReason) {} } @@ -1237,7 +1279,7 @@ public final class Call { * Instructs this {@link #STATE_RINGING} {@code Call} to answer. * @param videoState The video state in which to answer the call. */ - public void answer(int videoState) { + public void answer(@VideoProfile.VideoState int videoState) { mInCallAdapter.answerCall(mTelecomCallId, videoState); } @@ -1451,16 +1493,65 @@ public final class Call { * by {@code toHandle}. The videoState specified indicates the desired video state after the * handover. *

- * A handover request is initiated by the user from one app to indicate a desire - * to handover a call to another. + * A call handover is the process where an ongoing call is transferred from one app (i.e. + * {@link ConnectionService} to another app. The user could, for example, choose to continue a + * mobile network call in a video calling app. The mobile network call via the Telephony stack + * is referred to as the source of the handover, and the video calling app is referred to as the + * destination. + *

+ * When considering a handover scenario the device this method is called on is considered the + * initiating device (since the user initiates the handover from this device), and the + * other device is considered the receiving device. + *

+ * When this method is called on the initiating device, the Telecom framework will bind + * to the {@link ConnectionService} defined by the {@code toHandle} {@link PhoneAccountHandle} + * and invoke + * {@link ConnectionService#onCreateOutgoingHandoverConnection(PhoneAccountHandle, + * ConnectionRequest)} to inform the destination app that a request has been made to handover a + * call to it. The app returns an instance of {@link Connection} to represent the handover call + * At this point the app should display UI to indicate to the user that a call + * handover is in process. + *

+ * The destination app is responsible for communicating the handover request from the + * initiating device to the receiving device. + *

+ * When the app on the receiving device receives the handover request, it calls + * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to continue the handover + * process from the initiating device to the receiving device. At this point + * the destination app on the receiving device should show UI to allow the user to + * choose whether they want to continue their call in the destination app. + *

+ * When the destination app on the receiving device calls + * {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)}, Telecom will bind to its + * {@link ConnectionService} and call + * {@link ConnectionService#onCreateIncomingHandoverConnection(PhoneAccountHandle, + * ConnectionRequest)} to inform it of the handover request. The app returns an instance of + * {@link Connection} to represent the handover call. + *

+ * If the user of the receiving device accepts the handover, the app calls + * {@link Connection#setActive()} to complete the handover process; Telecom will disconnect the + * original call. If the user rejects the handover, the app calls + * {@link Connection#setDisconnected(DisconnectCause)} and specifies a {@link DisconnectCause} + * of {@link DisconnectCause#CANCELED} to indicate that the handover has been cancelled. + *

+ * Telecom will only allow handovers from {@link PhoneAccount}s which declare + * {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. Similarly, the {@link PhoneAccount} + * specified by {@code toHandle} must declare {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_TO}. + *

+ * Errors in the handover process are reported to the {@link InCallService} via + * {@link Callback#onHandoverFailed(Call, int)}. Errors in the handover process are reported to + * the involved {@link ConnectionService}s via + * {@link ConnectionService#onHandoverFailed(ConnectionRequest, int)}. * * @param toHandle {@link PhoneAccountHandle} of the {@link ConnectionService} to handover * this call to. - * @param videoState Indicates the video state desired after the handover. + * @param videoState Indicates the video state desired after the handover (see the + * {@code STATE_*} constants defined in {@link VideoProfile}). * @param extras Bundle containing extra information to be passed to the * {@link ConnectionService} */ - public void handoverTo(PhoneAccountHandle toHandle, int videoState, Bundle extras) { + public void handoverTo(PhoneAccountHandle toHandle, @VideoProfile.VideoState int videoState, + Bundle extras) { mInCallAdapter.handoverTo(mTelecomCallId, toHandle, videoState, extras); } diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java index 2ea7e65eeec7..09e7f709fa99 100644 --- a/telecomm/java/android/telecom/ConnectionService.java +++ b/telecomm/java/android/telecom/ConnectionService.java @@ -2219,12 +2219,50 @@ public abstract class ConnectionService extends Service { } /** - * Called by Telecom on the initiating side of the handover to create an instance of a - * handover connection. + * Called by Telecom to request that a {@link ConnectionService} creates an instance of an + * outgoing handover {@link Connection}. + *

+ * A call handover is the process where an ongoing call is transferred from one app (i.e. + * {@link ConnectionService} to another app. The user could, for example, choose to continue a + * mobile network call in a video calling app. The mobile network call via the Telephony stack + * is referred to as the source of the handover, and the video calling app is referred to as the + * destination. + *

+ * When considering a handover scenario the initiating device is where a user initiated + * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo( + * PhoneAccountHandle, int, Bundle)}, and the other device is considered the receiving + * device. + *

+ * This method is called on the destination {@link ConnectionService} on initiating + * device when the user initiates a handover request from one app to another. The user request + * originates in the {@link InCallService} via + * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}. + *

+ * For a full discussion of the handover process and the APIs involved, see + * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}. + *

+ * Implementations of this method should return an instance of {@link Connection} which + * represents the handover. If your app does not wish to accept a handover to it at this time, + * you can return {@code null}. The code below shows an example of how this is done. + *

+     * {@code
+     * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
+     *     fromPhoneAccountHandle, ConnectionRequest request) {
+     *   if (!isHandoverAvailable()) {
+     *       return null;
+     *   }
+     *   MyConnection connection = new MyConnection();
+     *   connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
+     *   connection.setVideoState(request.getVideoState());
+     *   return connection;
+     * }
+     * }
+     * 
+ * * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the * ConnectionService which needs to handover the call. - * @param request Details about the call which needs to be handover. - * @return Connection object corresponding to the handover call. + * @param request Details about the call to handover. + * @return {@link Connection} instance corresponding to the handover call. */ public Connection onCreateOutgoingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle, ConnectionRequest request) { @@ -2232,12 +2270,46 @@ public abstract class ConnectionService extends Service { } /** - * Called by Telecom on the receiving side of the handover to request the - * {@link ConnectionService} to create an instance of a handover connection. + * Called by Telecom to request that a {@link ConnectionService} creates an instance of an + * incoming handover {@link Connection}. + *

+ * A call handover is the process where an ongoing call is transferred from one app (i.e. + * {@link ConnectionService} to another app. The user could, for example, choose to continue a + * mobile network call in a video calling app. The mobile network call via the Telephony stack + * is referred to as the source of the handover, and the video calling app is referred to as the + * destination. + *

+ * When considering a handover scenario the initiating device is where a user initiated + * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo( + * PhoneAccountHandle, int, Bundle)}, and the other device is considered the receiving + * device. + *

+ * This method is called on the destination app on the receiving device when the + * destination app calls {@link TelecomManager#acceptHandover(Uri, int, PhoneAccountHandle)} to + * accept an incoming handover from the initiating device. + *

+ * For a full discussion of the handover process and the APIs involved, see + * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}. + *

+ * Implementations of this method should return an instance of {@link Connection} which + * represents the handover. The code below shows an example of how this is done. + *

+     * {@code
+     * public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle
+     *     fromPhoneAccountHandle, ConnectionRequest request) {
+     *   // Given that your app requested to accept the handover, you should not return null here.
+     *   MyConnection connection = new MyConnection();
+     *   connection.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
+     *   connection.setVideoState(request.getVideoState());
+     *   return connection;
+     * }
+     * }
+     * 
+ * * @param fromPhoneAccountHandle {@link PhoneAccountHandle} associated with the * ConnectionService which needs to handover the call. * @param request Details about the call which needs to be handover. - * @return {@link Connection} object corresponding to the handover call. + * @return {@link Connection} instance corresponding to the handover call. */ public Connection onCreateIncomingHandoverConnection(PhoneAccountHandle fromPhoneAccountHandle, ConnectionRequest request) { @@ -2247,11 +2319,15 @@ public abstract class ConnectionService extends Service { /** * Called by Telecom in response to a {@code TelecomManager#acceptHandover()} * invocation which failed. - * @param request Details about the call which needs to be handover. - * @param error Reason for handover failure as defined in - * {@link android.telecom.Call.Callback#HANDOVER_FAILURE_DEST_INVALID_PERM} + *

+ * For a full discussion of the handover process and the APIs involved, see + * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)} + * + * @param request Details about the call which failed to handover. + * @param error Reason for handover failure. Will be one of the */ - public void onHandoverFailed(ConnectionRequest request, int error) { + public void onHandoverFailed(ConnectionRequest request, + @Call.Callback.HandoverFailureErrors int error) { return; } diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index 7e897453ab59..fe29f3a1ced2 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -1786,8 +1786,25 @@ public class TelecomManager { } /** - * Called from the recipient side of a handover to indicate a desire to accept the handover - * of an ongoing call to another {@link ConnectionService} identified by + * Called by an app to indicate that it wishes to accept the handover of an ongoing call to a + * {@link PhoneAccountHandle} it defines. + *

+ * A call handover is the process where an ongoing call is transferred from one app (i.e. + * {@link ConnectionService} to another app. The user could, for example, choose to continue a + * mobile network call in a video calling app. The mobile network call via the Telephony stack + * is referred to as the source of the handover, and the video calling app is referred to as the + * destination. + *

+ * When considering a handover scenario the initiating device is where a user initiated + * the handover process (e.g. by calling {@link android.telecom.Call#handoverTo( + * PhoneAccountHandle, int, Bundle)}, and the other device is considered the receiving + * device. + *

+ * For a full discussion of the handover process and the APIs involved, see + * {@link android.telecom.Call#handoverTo(PhoneAccountHandle, int, Bundle)}. + *

+ * This method is called from the receiving side of a handover to indicate a desire to + * accept the handover of an ongoing call to another {@link ConnectionService} identified by * {@link PhoneAccountHandle} destAcct. For managed {@link ConnectionService}s, the specified * {@link PhoneAccountHandle} must have been registered with {@link #registerPhoneAccount} and * the user must have enabled the corresponding {@link PhoneAccount}. This can be checked using @@ -1811,7 +1828,8 @@ public class TelecomManager { * @param videoState Video state after the handover. * @param destAcct The {@link PhoneAccountHandle} registered to the calling package. */ - public void acceptHandover(Uri srcAddr, int videoState, PhoneAccountHandle destAcct) { + public void acceptHandover(Uri srcAddr, @VideoProfile.VideoState int videoState, + PhoneAccountHandle destAcct) { try { if (isServiceConnected()) { getTelecomService().acceptHandover(srcAddr, videoState, destAcct); diff --git a/telecomm/java/android/telecom/VideoProfile.java b/telecomm/java/android/telecom/VideoProfile.java index e0e3a085315a..90ed36f19dbf 100644 --- a/telecomm/java/android/telecom/VideoProfile.java +++ b/telecomm/java/android/telecom/VideoProfile.java @@ -62,6 +62,7 @@ public class VideoProfile implements Parcelable { @Retention(RetentionPolicy.SOURCE) @IntDef( flag = true, + prefix = { "STATE_" }, value = {STATE_AUDIO_ONLY, STATE_TX_ENABLED, STATE_RX_ENABLED, STATE_BIDIRECTIONAL, STATE_PAUSED}) public @interface VideoState {} -- cgit v1.2.3-59-g8ed1b