Search in sources :

Example 6 with UsbPortStatus

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

the class ShadowUsbManagerTest method setPortRoles_sinkHost_shouldSetPortStatus.

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

Example 7 with UsbPortStatus

use of android.hardware.usb.UsbPortStatus in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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 8 with UsbPortStatus

use of android.hardware.usb.UsbPortStatus in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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)

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