ConnectionService API has only one completed callback (1/3)

Refactor ConnectionService API so it has only one "completed"
callback, and connection state and failure codes indicates what
happened. Previous design where we had separate callbacks for failure,
cancellation and success was error prone because it was easy to forget
to implement one of them.

Bug: 16993846
Bug: 17070939

Change-Id: I84bf5d041cf78193ccf80db201b08db3b7014830
This commit is contained in:
Ihab Awad
2014-08-18 09:23:25 -07:00
parent ccc8c29af1
commit 6107bab041
9 changed files with 117 additions and 266 deletions

View File

@@ -48,7 +48,7 @@ final class RemoteConnectionService {
private final IConnectionServiceAdapter mServantDelegate = new IConnectionServiceAdapter() {
@Override
public void handleCreateConnectionSuccessful(
public void handleCreateConnectionComplete(
String id,
ConnectionRequest request,
ParcelableConnection parcel) {
@@ -56,6 +56,7 @@ final class RemoteConnectionService {
findConnectionForAction(id, "handleCreateConnectionSuccessful");
if (connection != NULL_CONNECTION && mPendingConnections.contains(connection)) {
mPendingConnections.remove(connection);
// Unconditionally initialize the connection ...
connection.setState(parcel.getState());
connection.setCallCapabilities(parcel.getCapabilities());
connection.setHandle(
@@ -64,28 +65,14 @@ final class RemoteConnectionService {
parcel.getCallerDisplayName(),
parcel.getCallerDisplayNamePresentation());
// TODO: Do we need to support video providers for remote connections?
if (connection.getState() == Connection.STATE_DISCONNECTED) {
// ... then, if it was created in a disconnected state, that indicates
// failure on the providing end, so immediately mark it destroyed
connection.setDestroyed();
}
}
}
@Override
public void handleCreateConnectionFailed(
String id,
ConnectionRequest request,
int errorCode,
String errorMessage) {
// TODO: How do we propagate the failure codes?
findConnectionForAction(id, "handleCreateConnectionFailed")
.setDestroyed();
}
@Override
public void handleCreateConnectionCancelled(
String id,
ConnectionRequest request) {
findConnectionForAction(id, "handleCreateConnectionCancelled")
.setDestroyed();
}
@Override
public void setActive(String callId) {
findConnectionForAction(callId, "setActive")