Search in sources :

Example 1 with ConnectionService

use of android.telecom.ConnectionService 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 2 with ConnectionService

use of android.telecom.ConnectionService 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 3 with ConnectionService

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

the class ShadowTelecomManager method setupConnectionService.

private static ConnectionService setupConnectionService(PhoneAccountHandle phoneAccount) {
    ComponentName service = phoneAccount.getComponentName();
    Class<? extends ConnectionService> clazz;
    try {
        clazz = Class.forName(service.getClassName()).asSubclass(ConnectionService.class);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
    }
    return verifyNotNull(ServiceController.of(ReflectionHelpers.callConstructor(clazz), null).create().get());
}
Also used : ConnectionService(android.telecom.ConnectionService) ComponentName(android.content.ComponentName)

Example 4 with ConnectionService

use of android.telecom.ConnectionService 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 ConnectionService

use of android.telecom.ConnectionService 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)

Aggregations

ConnectionService (android.telecom.ConnectionService)5 TargetApi (android.annotation.TargetApi)4 ConnectionRequest (android.telecom.ConnectionRequest)4 PhoneAccountHandle (android.telecom.PhoneAccountHandle)4 Nullable (androidx.annotation.Nullable)2 ComponentName (android.content.ComponentName)1