Search in sources :

Example 6 with ConnectionRequest

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

the class ShadowTelecomManagerTest method testAllowPlaceCall.

@Test
@Config(minSdk = M)
public void testAllowPlaceCall() {
    shadowOf(telecomService).setCallRequestMode(CallRequestMode.ALLOW_ALL);
    Uri address = Uri.parse("tel:+1-201-555-0123");
    PhoneAccountHandle phoneAccount = createHandle("id");
    Bundle outgoingCallExtras = new Bundle();
    outgoingCallExtras.putString("TEST_EXTRA_KEY", "TEST_EXTRA_VALUE");
    Bundle extras = new Bundle();
    extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccount);
    extras.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
    extras.putBundle(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, outgoingCallExtras);
    telecomService.placeCall(address, extras);
    ArgumentCaptor<ConnectionRequest> requestCaptor = ArgumentCaptor.forClass(ConnectionRequest.class);
    verify(connectionServiceListener).onCreateOutgoingConnection(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) Config(org.robolectric.annotation.Config)

Example 7 with ConnectionRequest

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

the class ShadowTelecomManagerTest method testDenyNewIncomingCall.

@Test
@Config(minSdk = O)
public void testDenyNewIncomingCall() {
    shadowOf(telecomService).setCallRequestMode(CallRequestMode.DENY_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).onCreateIncomingConnectionFailed(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) Config(org.robolectric.annotation.Config)

Example 8 with ConnectionRequest

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

the class ShadowTelecomManagerTest method testDenyPlaceCall.

@Test
@Config(minSdk = O)
public void testDenyPlaceCall() {
    shadowOf(telecomService).setCallRequestMode(CallRequestMode.DENY_ALL);
    Uri address = Uri.parse("tel:+1-201-555-0123");
    PhoneAccountHandle phoneAccount = createHandle("id");
    Bundle outgoingCallExtras = new Bundle();
    outgoingCallExtras.putString("TEST_EXTRA_KEY", "TEST_EXTRA_VALUE");
    Bundle extras = new Bundle();
    extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccount);
    extras.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
    extras.putBundle(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, outgoingCallExtras);
    telecomService.placeCall(address, extras);
    ArgumentCaptor<ConnectionRequest> requestCaptor = ArgumentCaptor.forClass(ConnectionRequest.class);
    verify(connectionServiceListener).onCreateOutgoingConnectionFailed(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) Config(org.robolectric.annotation.Config)

Example 9 with ConnectionRequest

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

the class ShadowTelecomManager method allowIncomingCall.

/**
 * Allows an {@link IncomingCallRecord} created via {@link TelecomManager#addNewIncomingCall}.
 *
 * <p>Specifically, this method sets up the relevant {@link ConnectionService} and returns the
 * result of {@link ConnectionService#onCreateIncomingConnection}.
 */
@TargetApi(M)
@Nullable
public Connection allowIncomingCall(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);
    return service.onCreateIncomingConnection(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 10 with ConnectionRequest

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

the class ShadowTelecomManager method buildConnectionRequestForOutgoingCall.

private static ConnectionRequest buildConnectionRequestForOutgoingCall(OutgoingCallRecord call) {
    PhoneAccountHandle phoneAccount = verifyNotNull(call.phoneAccount);
    Uri address = verifyNotNull(call.address);
    Bundle extras = verifyNotNull(call.extras);
    Bundle outgoingCallExtras = extras.getBundle(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS);
    int videoState = extras.getInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_AUDIO_ONLY);
    return new ConnectionRequest(phoneAccount, address, outgoingCallExtras == null ? null : new Bundle(outgoingCallExtras), videoState);
}
Also used : ConnectionRequest(android.telecom.ConnectionRequest) PhoneAccountHandle(android.telecom.PhoneAccountHandle) Bundle(android.os.Bundle) Uri(android.net.Uri)

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