Example usage for android.telecom ConnectionRequest ConnectionRequest

List of usage examples for android.telecom ConnectionRequest ConnectionRequest

Introduction

In this page you can find the example usage for android.telecom ConnectionRequest ConnectionRequest.

Prototype

public ConnectionRequest(PhoneAccountHandle accountHandle, Uri handle, Bundle extras, int videoState) 

Source Link

Usage

From source file:com.android.server.telecom.testapps.TestConnectionService.java

@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerAccount,
        final ConnectionRequest originalRequest) {

    final Uri handle = originalRequest.getAddress();
    String number = originalRequest.getAddress().getSchemeSpecificPart();
    log("call, number: " + number);

    // Crash on 555-DEAD to test call service crashing.
    if ("5550340".equals(number)) {
        throw new RuntimeException("Goodbye, cruel world.");
    }/*from w ww.  j  ava  2  s . c  o  m*/

    Bundle extras = originalRequest.getExtras();
    String gatewayPackage = extras.getString(TelecomManager.GATEWAY_PROVIDER_PACKAGE);
    Uri originalHandle = extras.getParcelable(TelecomManager.GATEWAY_ORIGINAL_ADDRESS);

    log("gateway package [" + gatewayPackage + "], original handle [" + originalHandle + "]");

    final TestConnection connection = new TestConnection(false /* isIncoming */);
    setAddress(connection, handle);

    // If the number starts with 555, then we handle it ourselves. If not, then we
    // use a remote connection service.
    // TODO: Have a special phone number to test the account-picker dialog flow.
    if (number != null && number.startsWith("555")) {
        // Normally we would use the original request as is, but for testing purposes, we are
        // adding ".." to the end of the number to follow its path more easily through the logs.
        final ConnectionRequest request = new ConnectionRequest(originalRequest.getAccountHandle(),
                Uri.fromParts(handle.getScheme(), handle.getSchemeSpecificPart() + "..", ""),
                originalRequest.getExtras(), originalRequest.getVideoState());
        connection.setVideoState(originalRequest.getVideoState());
        /// M: only VideoCall addVideoProvider @{
        if (originalRequest.getVideoState() == VideoProfile.STATE_BIDIRECTIONAL) {
            addVideoProvider(connection);
        }
        /// @}

        addCall(connection);
        connection.startOutgoing();

        for (Connection c : getAllConnections()) {
            c.setOnHold();
        }
    } else {
        log("Not a test number");
    }
    return connection;
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerAccount,
        final ConnectionRequest request) {
    PhoneAccountHandle accountHandle = request.getAccountHandle();
    ComponentName componentName = new ComponentName(this, TestConnectionService.class);

    if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) {
        final TestConnection connection = new TestConnection(true);
        // Get the stashed intent extra that determines if this is a video call or audio call.
        Bundle extras = request.getExtras();
        boolean isVideoCall = extras.getBoolean(EXTRA_IS_VIDEO_CALL);
        Uri providedHandle = extras.getParcelable(EXTRA_HANDLE);

        // Use dummy number for testing incoming calls.
        Uri address = providedHandle == null
                ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(isVideoCall), null)
                : providedHandle;/*from  w  w w.ja v a  2s .c o  m*/

        int videoState = isVideoCall ? VideoProfile.STATE_BIDIRECTIONAL : VideoProfile.STATE_AUDIO_ONLY;
        connection.setVideoState(videoState);
        setAddress(connection, address);

        addVideoProvider(connection);

        addCall(connection);

        ConnectionRequest newRequest = new ConnectionRequest(request.getAccountHandle(), address,
                request.getExtras(), videoState);
        connection.setVideoState(videoState);
        return connection;
    } else {
        return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR,
                "Invalid inputs: " + accountHandle + " " + componentName));
    }
}