/** * Adds a USB device into available USB devices map with permission value. If the USB device * already exists, updates the USB device with new permission value. */ public void addOrUpdateUsbDevice(UsbDevice usbDevice, boolean hasPermission) { Preconditions.checkNotNull(usbDevice); Preconditions.checkNotNull(usbDevice.getDeviceName()); usbDevices.put(usbDevice.getDeviceName(), usbDevice); if (hasPermission) { grantPermission(usbDevice); } else { revokePermission(usbDevice, RuntimeEnvironment.application.getPackageName()); } }
/** Removes a USB device from available USB devices map. */ public void removeUsbDevice(UsbDevice usbDevice) { Preconditions.checkNotNull(usbDevice); usbDevices.remove(usbDevice.getDeviceName()); revokePermission(usbDevice, RuntimeEnvironment.application.getPackageName()); }
public UsbDeviceAssert hasDeviceName(String name) { isNotNull(); String actualName = actual.getDeviceName(); assertThat(actualName) // .overridingErrorMessage("Expected device name <%s> but was <%s>.", name, actualName) // .isEqualTo(name); return this; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); usbManager = (UsbManager) ApplicationProvider.getApplicationContext().getSystemService(Context.USB_SERVICE); when(usbDevice1.getDeviceName()).thenReturn(DEVICE_NAME_1); when(usbDevice2.getDeviceName()).thenReturn(DEVICE_NAME_2); }
public OpenDevice openDevice(UsbDevice device) { UsbDeviceConnection connection = mUsbManager.openDevice(device); Log.i("USB","Device name="+device.getDeviceName()); int bus = getBusNumber(device.getDeviceName()); int address = getAddress(device.getDeviceName()); return new OpenDevice(device, connection, bus, address); }
/** * Retrieves an {@link android.mtp.MtpDevice} object for the USB device * with the given ID. * * @param id the ID of the USB device * @return the MtpDevice, or null if it does not exist */ public MtpDevice getDevice(int id) { synchronized (mDevices) { return mDevices.get(UsbDevice.getDeviceName(id)); } }
/** * Get the device name(linux device path) * * @return the device name(linux device path) */ @NonNull public String getDeviceAddress() { return usbDevice.getDeviceName(); }
@Override protected void onResume() { super.onResume(); Intent intent = getIntent(); if (intent != null) { Log.d("onResume", "intent: " + intent.toString()); if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) { UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (usbDevice != null) { Log.d("onResume", "USB device attached: name: " + usbDevice.getDeviceName());
@Override public String toString() { return String.format("<%s device_name=%s device_id=%s port_number=%s>", getClass().getSimpleName(), mDevice.getDeviceName(), mDevice.getDeviceId(), mPortNumber); }
@Override public String toString() { return String.format("<%s device_name=%s device_id=%s port_number=%s>", getClass().getSimpleName(), mDevice.getDeviceName(), mDevice.getDeviceId(), mPortNumber); }
public UsbDeviceAssert hasDeviceName(String name) { isNotNull(); String actualName = actual.getDeviceName(); assertThat(actualName) // .overridingErrorMessage("Expected device name <%s> but was <%s>.", name, actualName) // .isEqualTo(name); return this; }
/** Removes a USB device from available USB devices map. */ public void removeUsbDevice(UsbDevice usbDevice) { Preconditions.checkNotNull(usbDevice); usbDevices.remove(usbDevice.getDeviceName()); revokePermission(usbDevice, RuntimeEnvironment.application.getPackageName()); }
@Override public void onMidiSystemExclusive(@NonNull final MidiInputDevice sender, int cable, final byte[] systemExclusive) { midiInputEventHandler.sendMessage(Message.obtain(midiInputEventHandler, 0, "SystemExclusive from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", data:" + Arrays.toString(systemExclusive))); if (thruToggleButton != null && thruToggleButton.isChecked() && getMidiOutputDeviceFromSpinner() != null) { getMidiOutputDeviceFromSpinner().sendMidiSystemExclusive(cable, systemExclusive); midiOutputEventHandler.sendMessage(Message.obtain(midiOutputEventHandler, 0, "SystemExclusive from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", data:" + Arrays.toString(systemExclusive))); } }
@Override public void onMidiPitchWheel(@NonNull final MidiInputDevice sender, int cable, int channel, int amount) { midiInputEventHandler.sendMessage(Message.obtain(midiInputEventHandler, 0, "PitchWheel from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", channel: " + channel + ", amount: " + amount)); if (thruToggleButton != null && thruToggleButton.isChecked() && getMidiOutputDeviceFromSpinner() != null) { getMidiOutputDeviceFromSpinner().sendMidiPitchWheel(cable, channel, amount); midiOutputEventHandler.sendMessage(Message.obtain(midiOutputEventHandler, 0, "PitchWheel from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", channel: " + channel + ", amount: " + amount)); } }
@Override public void onMidiPolyphonicAftertouch(@NonNull final MidiInputDevice sender, int cable, int channel, int note, int pressure) { midiInputEventHandler.sendMessage(Message.obtain(midiInputEventHandler, 0, "PolyphonicAftertouch from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", channel: " + channel + ", note: " + note + ", pressure: " + pressure)); if (thruToggleButton != null && thruToggleButton.isChecked() && getMidiOutputDeviceFromSpinner() != null) { getMidiOutputDeviceFromSpinner().sendMidiPolyphonicAftertouch(cable, channel, note, pressure); midiOutputEventHandler.sendMessage(Message.obtain(midiOutputEventHandler, 0, "PolyphonicAftertouch from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", channel: " + channel + ", note: " + note + ", pressure: " + pressure)); } }
@Override public void onMidiMiscellaneousFunctionCodes(@NonNull final MidiInputDevice sender, int cable, int byte1, int byte2, int byte3) { midiInputEventHandler.sendMessage(Message.obtain(midiInputEventHandler, 0, "MiscellaneousFunctionCodes from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", byte1: " + byte1 + ", byte2: " + byte2 + ", byte3: " + byte3)); if (thruToggleButton != null && thruToggleButton.isChecked() && getMidiOutputDeviceFromSpinner() != null) { getMidiOutputDeviceFromSpinner().sendMidiMiscellaneousFunctionCodes(cable, byte1, byte2, byte3); midiOutputEventHandler.sendMessage(Message.obtain(midiOutputEventHandler, 0, "MiscellaneousFunctionCodes from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", byte1: " + byte1 + ", byte2: " + byte2 + ", byte3: " + byte3)); } }
@Override public void onMidiMiscellaneousFunctionCodes(@NonNull final MidiInputDevice sender, int cable, int byte1, int byte2, int byte3) { midiInputEventHandler.sendMessage(Message.obtain(midiInputEventHandler, 0, "MiscellaneousFunctionCodes from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", byte1: " + byte1 + ", byte2: " + byte2 + ", byte3: " + byte3)); if (thruToggleButton != null && thruToggleButton.isChecked() && getMidiOutputDeviceFromSpinner() != null) { getMidiOutputDeviceFromSpinner().sendMidiMiscellaneousFunctionCodes(cable, byte1, byte2, byte3); midiOutputEventHandler.sendMessage(Message.obtain(midiOutputEventHandler, 0, "MiscellaneousFunctionCodes from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", byte1: " + byte1 + ", byte2: " + byte2 + ", byte3: " + byte3)); } }
@Override public void onMidiControlChange(@NonNull final MidiInputDevice sender, int cable, int channel, int function, int value) { midiInputEventHandler.sendMessage(Message.obtain(midiInputEventHandler, 0, "ControlChange from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", channel: " + channel + ", function: " + function + ", value: " + value)); if (thruToggleButton != null && thruToggleButton.isChecked() && getMidiOutputDeviceFromSpinner() != null) { getMidiOutputDeviceFromSpinner().sendMidiControlChange(cable, channel, function, value); midiOutputEventHandler.sendMessage(Message.obtain(midiOutputEventHandler, 0, "ControlChange from: " + sender.getUsbDevice().getDeviceName() + ", cable: " + cable + ", channel: " + channel + ", function: " + function + ", value: " + value)); } }
public BitmapRegionDecoder run(JobContext jc) { byte[] bytes = mMtpContext.getMtpClient().getObject( UsbDevice.getDeviceName(mDeviceId), mObjectId, mObjectSize); return DecodeUtils.requestCreateBitmapRegionDecoder( jc, bytes, 0, bytes.length, false); } };
@Override public void onMidiOutputDeviceAttached(@NonNull final MidiOutputDevice midiOutputDevice) { if (connectedDevicesAdapter != null) { connectedDevicesAdapter.remove(midiOutputDevice.getUsbDevice()); connectedDevicesAdapter.add(midiOutputDevice.getUsbDevice()); connectedDevicesAdapter.notifyDataSetChanged(); } Toast.makeText(MIDIDriverMultipleSampleActivity.this, "USB MIDI Device " + midiOutputDevice.getUsbDevice().getDeviceName() + " has been attached.", Toast.LENGTH_LONG).show(); }