Loading core/java/android/midi/MidiDeviceServer.java +5 −8 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ public final class MidiDeviceServer implements Closeable { @Override public void onIOException() { synchronized (mOutputPortReceivers) { mOutputPortReceivers[getPortNumber()] = null; mOutputPortReceivers[getPortNumber()].clear(); } } } Loading Loading @@ -88,7 +88,6 @@ public final class MidiDeviceServer implements Closeable { } ParcelFileDescriptor result = null; MidiOutputPort newOutputPort = null; synchronized (mInputPortSenders) { if (mInputPortSenders[portNumber] != null) { Loading @@ -99,21 +98,19 @@ public final class MidiDeviceServer implements Closeable { try { ParcelFileDescriptor[] pair = ParcelFileDescriptor.createSocketPair( OsConstants.SOCK_SEQPACKET); newOutputPort = new ServerOutputPort(pair[0], portNumber); MidiOutputPort newOutputPort = new ServerOutputPort(pair[0], portNumber); mInputPortSenders[portNumber] = newOutputPort; result = pair[1]; } catch (IOException e) { Log.e(TAG, "unable to create ParcelFileDescriptors in openInputPort"); return null; } if (newOutputPort != null) { ArrayList<MidiReceiver> receivers = mInputPortReceivers[portNumber]; synchronized (receivers) { for (int i = 0; i < receivers.size(); i++) { newOutputPort.connect(receivers.get(i)); } } } catch (IOException e) { Log.e(TAG, "unable to create ParcelFileDescriptors in openInputPort"); return null; } } Loading core/java/android/midi/MidiOutputPort.java +4 −2 Original line number Diff line number Diff line Loading @@ -52,9 +52,11 @@ public class MidiOutputPort extends MidiPort implements MidiSender { while (true) { // read next event int count = mInputStream.read(buffer); if (count < MIN_PACKED_MESSAGE_SIZE || count > MAX_PACKED_MESSAGE_SIZE) { Log.e(TAG, "Number of bytes read out of range: " + count); if (count < 0) { break; } else if (count < MIN_PACKED_MESSAGE_SIZE || count > MAX_PACKED_MESSAGE_SIZE) { Log.e(TAG, "Number of bytes read out of range: " + count); continue; } int offset = getMessageOffset(buffer, count); Loading core/java/android/midi/MidiPort.java +4 −4 Original line number Diff line number Diff line Loading @@ -33,15 +33,15 @@ abstract public class MidiPort implements Closeable { /** * Minimum size of packed message as sent through our ParcelFileDescriptor * 8 bytes for timestamp, 1 byte for port number and 1 to 3 bytes for message * 8 bytes for timestamp and 1 to 3 bytes for message */ protected static final int MIN_PACKED_MESSAGE_SIZE = 10; protected static final int MIN_PACKED_MESSAGE_SIZE = 9; /** * Maximum size of packed message as sent through our ParcelFileDescriptor * 8 bytes for timestamp, 1 byte for port number and 1 to 3 bytes for message * 8 bytes for timestamp and 1 to 3 bytes for message */ protected static final int MAX_PACKED_MESSAGE_SIZE = 12; protected static final int MAX_PACKED_MESSAGE_SIZE = 11; /* package */ MidiPort(int portNumber) { Loading services/usb/java/com/android/server/usb/UsbMidiDevice.java +7 −2 Original line number Diff line number Diff line Loading @@ -133,7 +133,8 @@ public final class UsbMidiDevice implements Closeable { public void run() { byte[] buffer = new byte[3]; try { while (true) { boolean done = false; while (!done) { // look for a readable FileDescriptor for (int index = 0; index < mPollFDs.length; index++) { StructPollfd pfd = mPollFDs[index]; Loading @@ -141,7 +142,11 @@ public final class UsbMidiDevice implements Closeable { // clear readable flag pfd.revents = 0; int count = readMessage(buffer, index); mOutputPortReceivers[index].onPost(buffer, 0, count, System.nanoTime()); mOutputPortReceivers[index].onPost(buffer, 0, count, System.nanoTime()); } else if ((pfd.revents & (OsConstants.POLLERR | OsConstants.POLLHUP)) != 0) { done = true; } } Loading Loading
core/java/android/midi/MidiDeviceServer.java +5 −8 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ public final class MidiDeviceServer implements Closeable { @Override public void onIOException() { synchronized (mOutputPortReceivers) { mOutputPortReceivers[getPortNumber()] = null; mOutputPortReceivers[getPortNumber()].clear(); } } } Loading Loading @@ -88,7 +88,6 @@ public final class MidiDeviceServer implements Closeable { } ParcelFileDescriptor result = null; MidiOutputPort newOutputPort = null; synchronized (mInputPortSenders) { if (mInputPortSenders[portNumber] != null) { Loading @@ -99,21 +98,19 @@ public final class MidiDeviceServer implements Closeable { try { ParcelFileDescriptor[] pair = ParcelFileDescriptor.createSocketPair( OsConstants.SOCK_SEQPACKET); newOutputPort = new ServerOutputPort(pair[0], portNumber); MidiOutputPort newOutputPort = new ServerOutputPort(pair[0], portNumber); mInputPortSenders[portNumber] = newOutputPort; result = pair[1]; } catch (IOException e) { Log.e(TAG, "unable to create ParcelFileDescriptors in openInputPort"); return null; } if (newOutputPort != null) { ArrayList<MidiReceiver> receivers = mInputPortReceivers[portNumber]; synchronized (receivers) { for (int i = 0; i < receivers.size(); i++) { newOutputPort.connect(receivers.get(i)); } } } catch (IOException e) { Log.e(TAG, "unable to create ParcelFileDescriptors in openInputPort"); return null; } } Loading
core/java/android/midi/MidiOutputPort.java +4 −2 Original line number Diff line number Diff line Loading @@ -52,9 +52,11 @@ public class MidiOutputPort extends MidiPort implements MidiSender { while (true) { // read next event int count = mInputStream.read(buffer); if (count < MIN_PACKED_MESSAGE_SIZE || count > MAX_PACKED_MESSAGE_SIZE) { Log.e(TAG, "Number of bytes read out of range: " + count); if (count < 0) { break; } else if (count < MIN_PACKED_MESSAGE_SIZE || count > MAX_PACKED_MESSAGE_SIZE) { Log.e(TAG, "Number of bytes read out of range: " + count); continue; } int offset = getMessageOffset(buffer, count); Loading
core/java/android/midi/MidiPort.java +4 −4 Original line number Diff line number Diff line Loading @@ -33,15 +33,15 @@ abstract public class MidiPort implements Closeable { /** * Minimum size of packed message as sent through our ParcelFileDescriptor * 8 bytes for timestamp, 1 byte for port number and 1 to 3 bytes for message * 8 bytes for timestamp and 1 to 3 bytes for message */ protected static final int MIN_PACKED_MESSAGE_SIZE = 10; protected static final int MIN_PACKED_MESSAGE_SIZE = 9; /** * Maximum size of packed message as sent through our ParcelFileDescriptor * 8 bytes for timestamp, 1 byte for port number and 1 to 3 bytes for message * 8 bytes for timestamp and 1 to 3 bytes for message */ protected static final int MAX_PACKED_MESSAGE_SIZE = 12; protected static final int MAX_PACKED_MESSAGE_SIZE = 11; /* package */ MidiPort(int portNumber) { Loading
services/usb/java/com/android/server/usb/UsbMidiDevice.java +7 −2 Original line number Diff line number Diff line Loading @@ -133,7 +133,8 @@ public final class UsbMidiDevice implements Closeable { public void run() { byte[] buffer = new byte[3]; try { while (true) { boolean done = false; while (!done) { // look for a readable FileDescriptor for (int index = 0; index < mPollFDs.length; index++) { StructPollfd pfd = mPollFDs[index]; Loading @@ -141,7 +142,11 @@ public final class UsbMidiDevice implements Closeable { // clear readable flag pfd.revents = 0; int count = readMessage(buffer, index); mOutputPortReceivers[index].onPost(buffer, 0, count, System.nanoTime()); mOutputPortReceivers[index].onPost(buffer, 0, count, System.nanoTime()); } else if ((pfd.revents & (OsConstants.POLLERR | OsConstants.POLLHUP)) != 0) { done = true; } } Loading