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);
}
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));
}
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;
}
}
}
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);
}
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);
}
Aggregations