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

Commit 10f1740c authored by Phil Burk's avatar Phil Burk Committed by android-build-merger
Browse files

Merge "MidiDevice: do not open ports on closed device" into nyc-dev

am: 2faac0d7

* commit '2faac0d7':
  MidiDevice: do not open ports on closed device

Change-Id: I6f98e504d682a5902dd29f5fa54023e7a8bc9814
parents fb91c831 2faac0d7
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public final class MidiDevice implements Closeable {
    private final IMidiManager mMidiManager;
    private final IBinder mClientToken;
    private final IBinder mDeviceToken;
    private boolean mIsDeviceClosed;

    private final CloseGuard mGuard = CloseGuard.get();

@@ -123,6 +124,9 @@ public final class MidiDevice implements Closeable {
     *         or null in case of failure.
     */
    public MidiInputPort openInputPort(int portNumber) {
        if (mIsDeviceClosed) {
            return null;
        }
        try {
            IBinder token = new Binder();
            ParcelFileDescriptor pfd = mDeviceServer.openInputPort(token, portNumber);
@@ -146,6 +150,9 @@ public final class MidiDevice implements Closeable {
     *         or null in case of failure.
     */
    public MidiOutputPort openOutputPort(int portNumber) {
        if (mIsDeviceClosed) {
            return null;
        }
        try {
            IBinder token = new Binder();
            ParcelFileDescriptor pfd = mDeviceServer.openOutputPort(token, portNumber);
@@ -175,6 +182,9 @@ public final class MidiDevice implements Closeable {
        if (outputPortNumber < 0 || outputPortNumber >= mDeviceInfo.getOutputPortCount()) {
            throw new IllegalArgumentException("outputPortNumber out of range");
        }
        if (mIsDeviceClosed) {
            return null;
        }

        ParcelFileDescriptor pfd = inputPort.claimFileDescriptor();
        if (pfd == null) {
@@ -202,7 +212,9 @@ public final class MidiDevice implements Closeable {
    @Override
    public void close() throws IOException {
        synchronized (mGuard) {
            if (!mIsDeviceClosed) {
                mGuard.close();
                mIsDeviceClosed = true;
                try {
                    mMidiManager.closeDevice(mClientToken, mDeviceToken);
                } catch (RemoteException e) {
@@ -210,6 +222,7 @@ public final class MidiDevice implements Closeable {
                }
            }
        }
    }

    @Override
    protected void finalize() throws Throwable {