use of android.hardware.usb.UsbPort 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);
}
use of android.hardware.usb.UsbPort in project robolectric by robolectric.
the class ShadowUsbManager method addPort.
/**
* Adds a USB port with given ID and {@link UsbPortStatus} parameters to UsbManager for Q+.
*/
@TargetApi(Build.VERSION_CODES.Q)
public void addPort(String portId, int statusCurrentMode, int statusCurrentPowerRole, int statusCurrentDataRole, int statusSupportedRoleCombinations) {
Preconditions.checkState(RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.Q);
UsbPort usbPort = (UsbPort) createUsbPort(realUsbManager, portId, statusCurrentMode);
usbPorts.put(portId, usbPort);
usbPortStatuses.put(usbPort, (UsbPortStatus) createUsbPortStatus(statusCurrentMode, statusCurrentPowerRole, statusCurrentDataRole, statusSupportedRoleCombinations));
}
use of android.hardware.usb.UsbPort 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;
}
}
}
use of android.hardware.usb.UsbPort 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);
}
use of android.hardware.usb.UsbPort in project robolectric by robolectric.
the class ShadowUsbManager method addPort.
/**
* Adds a USB port with given ID to UsbManager.
*/
public void addPort(String portId) {
if (RuntimeEnvironment.getApiLevel() >= Build.VERSION_CODES.Q) {
addPort(portId, UsbPortStatus.MODE_DUAL, UsbPortStatus.POWER_ROLE_SINK, UsbPortStatus.DATA_ROLE_DEVICE, 0);
return;
}
UsbPort usbPort = callConstructor(UsbPort.class, from(String.class, portId), from(int.class, getStaticField(UsbPort.class, "MODE_DUAL")));
usbPorts.put(portId, usbPort);
usbPortStatuses.put(usbPort, (UsbPortStatus) createUsbPortStatus(getStaticField(UsbPort.class, "MODE_DUAL"), getStaticField(UsbPort.class, "POWER_ROLE_SINK"), getStaticField(UsbPort.class, "DATA_ROLE_DEVICE"), 0));
}
Aggregations