Merge "Use the new incoming call confirmation APIs." into master-nova-dev

This commit is contained in:
Santos Cordon 2014-02-19 04:36:22 +00:00 committed by Android (Google) Code Review
commit cfcc2f7d82
3 changed files with 89 additions and 11 deletions

View File

@ -20,9 +20,13 @@ import android.os.Handler;
import android.os.Looper;
import android.telecomm.CallInfo;
import android.telecomm.ICallServiceAdapter;
import android.util.Log;
import com.google.android.collect.Sets;
import com.google.common.base.Strings;
import java.util.Set;
/**
* Used by call services in order to update state and control calls while the call service is bound
* to Telecomm. Each call service is given its own instance for the lifetime of the binding between
@ -34,6 +38,7 @@ import com.google.common.base.Strings;
* TODO(santoscordon): Do we need Binder.clear/restoreCallingIdentity() in the service methods?
*/
public final class CallServiceAdapter extends ICallServiceAdapter.Stub {
private static final String TAG = CallServiceAdapter.class.getSimpleName();
private final CallsManager mCallsManager;
@ -42,6 +47,14 @@ public final class CallServiceAdapter extends ICallServiceAdapter.Stub {
/** Used to run code (e.g. messages, Runnables) on the main (UI) thread. */
private final Handler mHandler = new Handler(Looper.getMainLooper());
/** The list of unconfirmed incoming call IDs. Contains only IDs for incoming calls which are
* pending confirmation from the call service. Entries are added by the call service when a
* confirmation request is sent and removed when the confirmation is received or it times out.
* See {@link IncomingCallsManager} for more information about the incoming sequence and its
* timeouts.
*/
private final Set<String> mUnconfirmedIncomingCallIds = Sets.newHashSet();
/**
* Persists the specified parameters.
*/
@ -50,21 +63,24 @@ public final class CallServiceAdapter extends ICallServiceAdapter.Stub {
mOutgoingCallsManager = outgoingCallsManager;
}
/** {@inheritDoc} */
@Override public void getNextCallId() {
// TODO(santoscordon): needs response object.
}
/** {@inheritDoc} */
@Override public void setCompatibleWith(String callId, boolean isCompatible) {
// TODO(santoscordon): fill in.
}
/**
* {@inheritDoc}
*/
@Override public void handleIncomingCall(CallInfo callInfo) {
// TODO(santoscordon): fill in.
/** {@inheritDoc} */
@Override public void handleConfirmedIncomingCall(final CallInfo callInfo) {
checkValidCallId(callInfo.getId());
mHandler.post(new Runnable() {
@Override public void run() {
if (mUnconfirmedIncomingCallIds.remove(callInfo.getId())) {
// TODO(santoscordon): Uncomment when ready.
// mIncomingCallsManager.handleSuccessfulIncomingCall(callInfo);
} else {
Log.wtf(TAG, "Call service confirming unknown incoming call " + callInfo);
}
}
});
}
/** {@inheritDoc} */
@ -127,6 +143,25 @@ public final class CallServiceAdapter extends ICallServiceAdapter.Stub {
});
}
/**
* Adds a call ID to the list of unconfirmed incoming call IDs. Only calls with call IDs in the
* list will be handled by {@link #handleConfirmedIncomingCall}.
*
* @param callId The ID of the call.
*/
void addUnconfirmedIncomingCallId(String callId) {
mUnconfirmedIncomingCallIds.add(callId);
}
/**
* Removed a call ID from the list of unconfirmed incoming call IDs.
*
* @param callId The ID of the call.
*/
void removeUnconfirmedIncomingCallId(String callId) {
mUnconfirmedIncomingCallIds.remove(callId);
}
/**
* Throws an IllegalArgumentException if the specified call ID is invalid.
*
@ -134,7 +169,7 @@ public final class CallServiceAdapter extends ICallServiceAdapter.Stub {
*/
private void checkValidCallId(String callId) {
if (Strings.isNullOrEmpty(callId)) {
throw new IllegalArgumentException();
throw new IllegalArgumentException("Invalid call ID.");
}
}
}

View File

@ -121,6 +121,32 @@ public class CallServiceWrapper extends ServiceBinder<ICallService> {
}
}
/** See {@link ICallService#confirmIncomingCall}. */
public void confirmIncomingCall(String callId, String callToken) {
try {
if (mServiceInterface == null) {
Log.wtf(TAG, "confirmIncomingCall() invoked while service in unbound.");
} else {
mAdapter.addUnconfirmedIncomingCallId(callId);
mServiceInterface.confirmIncomingCall(callId, callToken);
}
} catch (RemoteException e) {
Log.e(TAG, "Failed to confirmIncomingCall for call " + callId, e);
mAdapter.removeUnconfirmedIncomingCallId(callId);
}
}
/**
* Cancels the an incoming call confirmation for the specified call ID.
* TODO(santoscordon): This method should be called by IncomingCallManager when the incoming
* call confirmation has failed.
*
* @param callId The ID of the call.
*/
void cancelIncomingCall(String callId) {
mAdapter.removeUnconfirmedIncomingCallId(callId);
}
/** {@inheritDoc} */
@Override protected void setServiceInterface(IBinder binder) {
mServiceInterface = ICallService.Stub.asInterface(binder);

View File

@ -31,6 +31,7 @@ import android.media.MediaPlayer;
import android.os.RemoteException;
import android.telecomm.CallInfo;
import android.telecomm.CallService;
import android.telecomm.CallState;
import android.telecomm.ICallServiceAdapter;
import android.text.TextUtils;
import android.util.Log;
@ -141,6 +142,22 @@ public class TestCallService extends CallService {
}
}
/** {@inheritDoc} */
@Override
public void confirmIncomingCall(String callId, String callToken) {
Log.i(TAG, "confirmIncomingCall(" + callId + ", " + callToken + ")");
// Use dummy number for testing incoming calls.
String handle = "5551234";
CallInfo callInfo = new CallInfo(callId, CallState.RINGING, handle);
try {
mCallsManagerAdapter.handleConfirmedIncomingCall(callInfo);
} catch (RemoteException e) {
Log.e(TAG, "Failed to handleConfirmedIncomingCall().", e);
}
}
/** {@inheritDoc} */
@Override
public boolean onUnbind(Intent intent) {