Search in sources :

Example 1 with ConnectionRequest

use of android.telecom.ConnectionRequest in project robolectric by robolectric.

the class ShadowTelecomManager method buildConnectionRequestForIncomingCall.

private static ConnectionRequest buildConnectionRequestForIncomingCall(IncomingCallRecord call) {
    PhoneAccountHandle phoneAccount = verifyNotNull(call.phoneAccount);
    Bundle extras = verifyNotNull(call.extras);
    Uri address = extras.getParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS);
    int videoState = extras.getInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_AUDIO_ONLY);
    return new ConnectionRequest(phoneAccount, address, new Bundle(extras), videoState);
}
Also used : ConnectionRequest(android.telecom.ConnectionRequest) PhoneAccountHandle(android.telecom.PhoneAccountHandle) Bundle(android.os.Bundle) Uri(android.net.Uri)

Example 2 with ConnectionRequest

use of android.telecom.ConnectionRequest in project robolectric by robolectric.

the class ShadowTelecomManager method allowOutgoingCall.

/**
 * Allows an {@link OutgoingCallRecord} created via {@link TelecomManager#placeCall}.
 *
 * <p>Specifically, this method sets up the relevant {@link ConnectionService} and returns the
 * result of {@link ConnectionService#onCreateOutgoingConnection}.
 */
@TargetApi(M)
@Nullable
public Connection allowOutgoingCall(OutgoingCallRecord call) {
    if (call.isHandled) {
        throw new IllegalStateException("Call has already been allowed or denied.");
    }
    call.isHandled = true;
    PhoneAccountHandle phoneAccount = verifyNotNull(call.phoneAccount);
    ConnectionRequest request = buildConnectionRequestForOutgoingCall(call);
    ConnectionService service = setupConnectionService(phoneAccount);
    return service.onCreateOutgoingConnection(phoneAccount, request);
}
Also used : ConnectionService(android.telecom.ConnectionService) ConnectionRequest(android.telecom.ConnectionRequest) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TargetApi(android.annotation.TargetApi) Nullable(androidx.annotation.Nullable)

Example 3 with ConnectionRequest

use of android.telecom.ConnectionRequest in project robolectric by robolectric.

the class ShadowTelecomManager method denyIncomingCall.

/**
 * Denies an {@link IncomingCallRecord} created via {@link TelecomManager#addNewIncomingCall}.
 *
 * <p>Specifically, this method sets up the relevant {@link ConnectionService} and calls {@link
 * ConnectionService#onCreateIncomingConnectionFailed}.
 */
@TargetApi(O)
public void denyIncomingCall(IncomingCallRecord call) {
    if (call.isHandled) {
        throw new IllegalStateException("Call has already been allowed or denied.");
    }
    call.isHandled = true;
    PhoneAccountHandle phoneAccount = verifyNotNull(call.phoneAccount);
    ConnectionRequest request = buildConnectionRequestForIncomingCall(call);
    ConnectionService service = setupConnectionService(phoneAccount);
    service.onCreateIncomingConnectionFailed(phoneAccount, request);
}
Also used : ConnectionService(android.telecom.ConnectionService) ConnectionRequest(android.telecom.ConnectionRequest) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TargetApi(android.annotation.TargetApi)

Example 4 with ConnectionRequest

use of android.telecom.ConnectionRequest in project robolectric by robolectric.

the class ShadowTelecomManager method denyOutgoingCall.

/**
 * Denies an {@link OutgoingCallRecord} created via {@link TelecomManager#placeCall}.
 *
 * <p>Specifically, this method sets up the relevant {@link ConnectionService} and calls {@link
 * ConnectionService#onCreateOutgoingConnectionFailed}.
 */
@TargetApi(O)
public void denyOutgoingCall(OutgoingCallRecord call) {
    if (call.isHandled) {
        throw new IllegalStateException("Call has already been allowed or denied.");
    }
    call.isHandled = true;
    PhoneAccountHandle phoneAccount = verifyNotNull(call.phoneAccount);
    ConnectionRequest request = buildConnectionRequestForOutgoingCall(call);
    ConnectionService service = setupConnectionService(phoneAccount);
    service.onCreateOutgoingConnectionFailed(phoneAccount, request);
}
Also used : ConnectionService(android.telecom.ConnectionService) ConnectionRequest(android.telecom.ConnectionRequest) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TargetApi(android.annotation.TargetApi)

Example 5 with ConnectionRequest

use of android.telecom.ConnectionRequest in project robolectric by robolectric.

the class ShadowTelecomManagerTest method testAllowNewIncomingCall.

@Test
public void testAllowNewIncomingCall() {
    shadowOf(telecomService).setCallRequestMode(CallRequestMode.ALLOW_ALL);
    Uri address = Uri.parse("tel:+1-201-555-0123");
    PhoneAccountHandle phoneAccount = createHandle("id");
    Bundle extras = new Bundle();
    extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, address);
    extras.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
    extras.putString("TEST_EXTRA_KEY", "TEST_EXTRA_VALUE");
    telecomService.addNewIncomingCall(createHandle("id"), extras);
    ArgumentCaptor<ConnectionRequest> requestCaptor = ArgumentCaptor.forClass(ConnectionRequest.class);
    verify(connectionServiceListener).onCreateIncomingConnection(eq(phoneAccount), requestCaptor.capture());
    verifyNoMoreInteractions(connectionServiceListener);
    ConnectionRequest request = requestCaptor.getValue();
    assertThat(request.getAccountHandle()).isEqualTo(phoneAccount);
    assertThat(request.getExtras().getString("TEST_EXTRA_KEY")).isEqualTo("TEST_EXTRA_VALUE");
    assertThat(request.getAddress()).isEqualTo(address);
    assertThat(request.getVideoState()).isEqualTo(VideoProfile.STATE_BIDIRECTIONAL);
}
Also used : ConnectionRequest(android.telecom.ConnectionRequest) PhoneAccountHandle(android.telecom.PhoneAccountHandle) Bundle(android.os.Bundle) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

ConnectionRequest (android.telecom.ConnectionRequest)10 PhoneAccountHandle (android.telecom.PhoneAccountHandle)10 Uri (android.net.Uri)6 Bundle (android.os.Bundle)6 TargetApi (android.annotation.TargetApi)4 ConnectionService (android.telecom.ConnectionService)4 Test (org.junit.Test)4 Config (org.robolectric.annotation.Config)3 Nullable (androidx.annotation.Nullable)2