Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d6f1eae authored by Robert Wu's avatar Robert Wu Committed by Automerger Merge Worker
Browse files

Merge "USB MIDI: Null check for mUsbMidiPacketConverter" into tm-dev am: 0559661c

parents c41ad84e 0559661c
Loading
Loading
Loading
Loading
+60 −40
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ public final class UsbDirectMidiDevice implements Closeable {
    private static final int BULK_TRANSFER_TIMEOUT_MILLISECONDS = 10;

    // Arbitrary number for timeout when closing a thread
    private static final int THREAD_JOIN_TIMEOUT_MILLISECONDS = 50;
    private static final int THREAD_JOIN_TIMEOUT_MILLISECONDS = 200;

    private ArrayList<UsbDeviceConnection> mUsbDeviceConnections;
    private ArrayList<ArrayList<UsbEndpoint>> mInputUsbEndpoints;
@@ -370,6 +370,10 @@ public final class UsbDirectMidiDevice implements Closeable {
                                        convertedArray = swapEndiannessPerWord(inputBuffer,
                                                bytesRead);
                                    } else {
                                        if (mUsbMidiPacketConverter == null) {
                                            Log.w(TAG, "mUsbMidiPacketConverter is null");
                                            break;
                                        }
                                        convertedArray =
                                                mUsbMidiPacketConverter.usbMidiToRawMidi(
                                                         inputBuffer, bytesRead);
@@ -379,12 +383,20 @@ public final class UsbDirectMidiDevice implements Closeable {
                                        logByteArray("Input after conversion ", convertedArray,
                                                0, convertedArray.length);
                                    }

                                    if ((outputReceivers == null)
                                            || (outputReceivers[portFinal] == null)) {
                                        Log.w(TAG, "outputReceivers is null");
                                        break;
                                    }
                                    outputReceivers[portFinal].send(convertedArray, 0,
                                            convertedArray.length, timestamp);
                                }
                            }
                        } catch (IOException e) {
                            Log.d(TAG, "reader thread exiting");
                        } catch (NullPointerException e) {
                            Log.e(TAG, "input thread: ", e);
                        } finally {
                            request.close();
                        }
@@ -414,6 +426,7 @@ public final class UsbDirectMidiDevice implements Closeable {
                Thread newThread = new Thread("UsbDirectMidiDevice output thread " + portFinal) {
                    @Override
                    public void run() {
                        try {
                            while (true) {
                                if (Thread.currentThread().interrupted()) {
                                    Log.w(TAG, "output thread interrupted");
@@ -443,6 +456,10 @@ public final class UsbDirectMidiDevice implements Closeable {
                                    convertedArray = swapEndiannessPerWord(event.data,
                                            event.count);
                                } else {
                                    if (mUsbMidiPacketConverter == null) {
                                        Log.w(TAG, "mUsbMidiPacketConverter is null");
                                        break;
                                    }
                                    convertedArray =
                                            mUsbMidiPacketConverter.rawMidiToUsbMidi(
                                                     event.data, event.count, portFinal);
@@ -458,6 +475,9 @@ public final class UsbDirectMidiDevice implements Closeable {
                                        BULK_TRANSFER_TIMEOUT_MILLISECONDS);
                                eventSchedulerFinal.addEventToPool(event);
                            }
                        } catch (NullPointerException e) {
                            Log.e(TAG, "output thread: ", e);
                        }
                        Log.d(TAG, "output thread exit");
                    }
                };