Search in sources :

Example 1 with UsbPortStatus

use of android.hardware.usb.UsbPortStatus in project robolectric by robolectric.

the class ShadowUsbManagerTest method setPortRoles_sinkHost_shouldSetPortStatus_Q.

@Test
@Config(minSdk = Q)
public void setPortRoles_sinkHost_shouldSetPortStatus_Q() {
    shadowOf(usbManager).addPort("port1");
    List<UsbPort> usbPorts = getUsbPorts();
    _usbManager_().setPortRoles(usbPorts.get(0), UsbPortStatus.POWER_ROLE_SINK, UsbPortStatus.DATA_ROLE_HOST);
    UsbPortStatus usbPortStatus = _usbManager_().getPortStatus(usbPorts.get(0));
    assertThat(usbPortStatus.getCurrentPowerRole()).isEqualTo(UsbPortStatus.POWER_ROLE_SINK);
    assertThat(usbPortStatus.getCurrentDataRole()).isEqualTo(UsbPortStatus.DATA_ROLE_HOST);
}
Also used : UsbPortStatus(android.hardware.usb.UsbPortStatus) UsbPort(android.hardware.usb.UsbPort) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 2 with UsbPortStatus

use of android.hardware.usb.UsbPortStatus in project robolectric by robolectric.

the class ShadowUsbManager method setPortRoles.

@Implementation(minSdk = M)
@HiddenApi
protected void setPortRoles(/* UsbPort */
Object port, /* int */
Object powerRole, /* int */
Object dataRole) {
    UsbPortStatus status = usbPortStatuses.get(port);
    usbPortStatuses.put((UsbPort) port, (UsbPortStatus) createUsbPortStatus(status.getCurrentMode(), (int) powerRole, (int) dataRole, status.getSupportedRoleCombinations()));
    RuntimeEnvironment.getApplication().sendBroadcast(new Intent(UsbManager.ACTION_USB_PORT_CHANGED));
}
Also used : UsbPortStatus(android.hardware.usb.UsbPortStatus) Intent(android.content.Intent) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 3 with UsbPortStatus

use of android.hardware.usb.UsbPortStatus in project android_packages_apps_Settings by omnirom.

the class UsbBackend method updatePorts.

private void updatePorts() {
    mPort = null;
    mPortStatus = null;
    List<UsbPort> ports = mUsbManager.getPorts();
    // For now look for a connected port, in the future we should identify port in the
    // notification and pick based on that.
    final int N = ports.size();
    for (int i = 0; i < N; i++) {
        UsbPortStatus status = ports.get(i).getStatus();
        if (status.isConnected()) {
            mPort = ports.get(i);
            mPortStatus = status;
            break;
        }
    }
}
Also used : UsbPortStatus(android.hardware.usb.UsbPortStatus) UsbPort(android.hardware.usb.UsbPort)

Example 4 with UsbPortStatus

use of android.hardware.usb.UsbPortStatus in project android_packages_apps_Settings by omnirom.

the class UsbConnectionBroadcastReceiverTest method onReceive_usbPortStatus_invokeCallback.

@Test
public void onReceive_usbPortStatus_invokeCallback() {
    final Intent intent = new Intent();
    intent.setAction(UsbManager.ACTION_USB_PORT_CHANGED);
    final UsbPortStatus status = new UsbPortStatus(0, POWER_ROLE_SINK, DATA_ROLE_DEVICE, 0, CONTAMINANT_PROTECTION_NONE, CONTAMINANT_DETECTION_NOT_SUPPORTED);
    intent.putExtra(UsbManager.EXTRA_PORT_STATUS, status);
    mReceiver.onReceive(mContext, intent);
    verify(mListener).onUsbConnectionChanged(false, /* connected */
    UsbManager.FUNCTION_NONE, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
}
Also used : UsbPortStatus(android.hardware.usb.UsbPortStatus) Intent(android.content.Intent) Test(org.junit.Test)

Example 5 with UsbPortStatus

use of android.hardware.usb.UsbPortStatus in project robolectric by robolectric.

the class ShadowUsbManagerTest method getPortStatus_shouldReturnStatusForCorrespondingPort.

@Test
@Config(minSdk = Q)
public void getPortStatus_shouldReturnStatusForCorrespondingPort() {
    shadowOf(usbManager).addPort("port1");
    shadowOf(usbManager).addPort("port2");
    shadowOf(usbManager).addPort("port3", UsbPortStatus.MODE_DUAL, UsbPortStatus.POWER_ROLE_SINK, UsbPortStatus.DATA_ROLE_DEVICE, /*statusSupportedRoleCombinations=*/
    0);
    UsbPortStatus portStatus = (UsbPortStatus) shadowOf(usbManager).getPortStatus("port3");
    assertThat(portStatus.getCurrentMode()).isEqualTo(UsbPortStatus.MODE_DUAL);
    assertThat(portStatus.getCurrentPowerRole()).isEqualTo(UsbPortStatus.POWER_ROLE_SINK);
    assertThat(portStatus.getCurrentDataRole()).isEqualTo(UsbPortStatus.DATA_ROLE_DEVICE);
    assertThat(portStatus.getSupportedRoleCombinations()).isEqualTo(0);
}
Also used : UsbPortStatus(android.hardware.usb.UsbPortStatus) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

UsbPortStatus (android.hardware.usb.UsbPortStatus)8 Test (org.junit.Test)5 UsbPort (android.hardware.usb.UsbPort)4 Intent (android.content.Intent)3 Config (org.robolectric.annotation.Config)3 HiddenApi (org.robolectric.annotation.HiddenApi)1 Implementation (org.robolectric.annotation.Implementation)1