Adding simple implementation of CallService for testing.
Updates some methods of the CallService API and adds very simple
implementations for isCompatibleWith(), call(), and disconnect().
TestCallServiceProvider now returns a single-item list including the single
ICallService implementation
depends on change: I27a8d14c5c63d3f6a70a290ffb39d9f623d40a60
Change-Id: I9b86c2a09c6c8e6d0ee306e5e26b2404fa60376d
diff --git a/src/com/android/telecomm/CallServiceFinder.java b/src/com/android/telecomm/CallServiceFinder.java
index 898877f..5d73dce 100644
--- a/src/com/android/telecomm/CallServiceFinder.java
+++ b/src/com/android/telecomm/CallServiceFinder.java
@@ -244,7 +244,7 @@
try {
provider.lookupCallServices(new ICallServiceLookupResponse.Stub() {
@Override
- public void onResult(List<IBinder> binderList) {
+ public void setCallServices(List<IBinder> binderList) {
List<ICallService> callServices = Lists.newArrayList();
for (IBinder binder : binderList) {
callServices.add(ICallService.Stub.asInterface(binder));
diff --git a/tests/src/com/android/telecomm/testcallservice/TestCallService.java b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
index 69e0db0..163fe35 100644
--- a/tests/src/com/android/telecomm/testcallservice/TestCallService.java
+++ b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
@@ -17,39 +17,91 @@
package com.android.telecomm.testcallservice;
import com.google.android.collect.Lists;
+import com.google.common.base.Preconditions;
+import java.util.Date;
+
+import android.os.RemoteException;
+import android.telecomm.CallInfo;
import android.telecomm.CallService;
import android.telecomm.ICallServiceAdapter;
+import android.text.TextUtils;
import android.util.Log;
/**
* Service which provides fake calls to test the ICallService interface.
*/
public class TestCallService extends CallService {
- /** Unique identifying tag used for logging. */
private static final String TAG = TestCallService.class.getSimpleName();
+ /**
+ * Adapter to call back into CallsManager.
+ */
+ private ICallServiceAdapter mCallsManagerAdapter;
+
/** {@inheritDoc} */
@Override
public void setCallServiceAdapter(ICallServiceAdapter callServiceAdapter) {
Log.i(TAG, "setCallServiceAdapter()");
+
+ mCallsManagerAdapter = callServiceAdapter;
}
- /** {@inheritDoc} */
+ /**
+ * Responds as compatible for all calls except those starting with the number 7 (arbitrarily
+ * chosen for testing purposes).
+ *
+ * {@inheritDoc}
+ */
@Override
- public void isCompatibleWith(String handle) {
- Log.i(TAG, "isCompatibleWith(" + handle + ")");
+ public void isCompatibleWith(String handle, String callId) {
+ Log.i(TAG, "isCompatibleWith(" + handle + ", " + callId + ")");
+ Preconditions.checkNotNull(handle);
+
+ // Is compatible if the handle doesn't start with 7.
+ boolean isCompatible = (handle.charAt(0) != '7');
+
+ try {
+ // Tell CallsManager whether this call service can place the call (is compatible).
+ // Returning positively on setCompatibleWith() doesn't guarantee that we will be chosen
+ // to place the call. If we *are* chosen then CallsManager will execute the call()
+ // method below.
+ mCallsManagerAdapter.setCompatibleWith(handle, callId, isCompatible);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to setCompatibleWith().", e);
+ }
}
- /** {@inheritDoc} */
+ /**
+ * Starts a call by calling into the adapter. For testing purposes this methods acts as if a
+ * call was successfully connected every time.
+ *
+ * {@inheritDoc}
+ */
@Override
- public void call(String handle) {
- Log.i(TAG, "call(" + handle + ")");
+ public void call(String handle, String callId) {
+ Log.i(TAG, "call(" + handle + ", " + callId + ")");
+
+ try {
+ // This creates a call within CallsManager starting at the DIALING state.
+ // TODO(santoscordon): When we define the call states, consider renaming newOutgoingCall
+ // to newDialingCall to match the states exactly and as an indication of the starting
+ // state for this new call. This depends on what the states are ultimately defined as.
+ mCallsManagerAdapter.newOutgoingCall(callId);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to create a newOutgoingCall().", e);
+ }
}
/** {@inheritDoc} */
@Override
public void disconnect(String callId) {
Log.i(TAG, "disconnect(" + callId + ")");
+
+ try {
+ mCallsManagerAdapter.setDisconnected(callId);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to setDisconnected().", e);
+ }
}
}
diff --git a/tests/src/com/android/telecomm/testcallservice/TestCallServiceProvider.java b/tests/src/com/android/telecomm/testcallservice/TestCallServiceProvider.java
index e83cd82..6e420f6 100644
--- a/tests/src/com/android/telecomm/testcallservice/TestCallServiceProvider.java
+++ b/tests/src/com/android/telecomm/testcallservice/TestCallServiceProvider.java
@@ -16,20 +16,33 @@
package com.android.telecomm.testcallservice;
+import android.os.IBinder;
+import android.os.RemoteException;
import android.telecomm.CallServiceProvider;
import android.telecomm.ICallServiceLookupResponse;
import android.util.Log;
+import com.google.common.collect.Lists;
+
+import java.util.List;
+
/**
* Service which provides fake calls to test the ICallService interface.
*/
public class TestCallServiceProvider extends CallServiceProvider {
- /** Unique identifying tag used for logging. */
private static final String TAG = TestCallServiceProvider.class.getSimpleName();
/** {@inheritDoc} */
@Override
public void lookupCallServices(ICallServiceLookupResponse response) {
Log.i(TAG, "lookupCallServices()");
+
+ try {
+ TestCallService callService = new TestCallService();
+ List<IBinder> callServiceList = Lists.newArrayList(callService.getBinder());
+ response.setCallServices(callServiceList);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to setCallServices().", e);
+ }
}
}