Loading media/java/android/media/midi/IMidiDeviceServer.aidl +2 −1 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,8 @@ interface IMidiDeviceServer void closeDevice(); void closeDevice(); // connects the input port pfd to the specified output port // connects the input port pfd to the specified output port void connectPorts(IBinder token, in ParcelFileDescriptor pfd, int outputPortNumber); // Returns the PID of the called process. int connectPorts(IBinder token, in ParcelFileDescriptor pfd, int outputPortNumber); MidiDeviceInfo getDeviceInfo(); MidiDeviceInfo getDeviceInfo(); void setDeviceInfo(in MidiDeviceInfo deviceInfo); void setDeviceInfo(in MidiDeviceInfo deviceInfo); Loading media/java/android/media/midi/MidiDevice.java +11 −3 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.media.midi; import android.os.Binder; import android.os.Binder; import android.os.IBinder; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.RemoteException; import android.util.Log; import android.util.Log; Loading Loading @@ -181,9 +182,16 @@ public final class MidiDevice implements Closeable { } } try { try { IBinder token = new Binder(); IBinder token = new Binder(); mDeviceServer.connectPorts(token, pfd, outputPortNumber); int calleePid = mDeviceServer.connectPorts(token, pfd, outputPortNumber); // If the service is a different Process then it will duplicate the pfd // and we can safely close this one. // But if the service is in the same Process then closing the pfd will // kill the connection. So don't do that. if (calleePid != Process.myPid()) { // close our copy of the file descriptor // close our copy of the file descriptor IoUtils.closeQuietly(pfd); IoUtils.closeQuietly(pfd); } return new MidiConnection(token, inputPort); return new MidiConnection(token, inputPort); } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "RemoteException in connectPorts"); Log.e(TAG, "RemoteException in connectPorts"); Loading media/java/android/media/midi/MidiDeviceServer.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -254,7 +254,7 @@ public final class MidiDeviceServer implements Closeable { } } @Override @Override public void connectPorts(IBinder token, ParcelFileDescriptor pfd, public int connectPorts(IBinder token, ParcelFileDescriptor pfd, int outputPortNumber) { int outputPortNumber) { MidiInputPort inputPort = new MidiInputPort(pfd, outputPortNumber); MidiInputPort inputPort = new MidiInputPort(pfd, outputPortNumber); MidiDispatcher dispatcher = mOutputPortDispatchers[outputPortNumber]; MidiDispatcher dispatcher = mOutputPortDispatchers[outputPortNumber]; Loading @@ -270,6 +270,7 @@ public final class MidiDeviceServer implements Closeable { synchronized (mPortClients) { synchronized (mPortClients) { mPortClients.put(token, client); mPortClients.put(token, client); } } return Process.myPid(); // for caller to detect same process ID } } @Override @Override Loading Loading
media/java/android/media/midi/IMidiDeviceServer.aidl +2 −1 Original line number Original line Diff line number Diff line Loading @@ -28,7 +28,8 @@ interface IMidiDeviceServer void closeDevice(); void closeDevice(); // connects the input port pfd to the specified output port // connects the input port pfd to the specified output port void connectPorts(IBinder token, in ParcelFileDescriptor pfd, int outputPortNumber); // Returns the PID of the called process. int connectPorts(IBinder token, in ParcelFileDescriptor pfd, int outputPortNumber); MidiDeviceInfo getDeviceInfo(); MidiDeviceInfo getDeviceInfo(); void setDeviceInfo(in MidiDeviceInfo deviceInfo); void setDeviceInfo(in MidiDeviceInfo deviceInfo); Loading
media/java/android/media/midi/MidiDevice.java +11 −3 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.media.midi; import android.os.Binder; import android.os.Binder; import android.os.IBinder; import android.os.IBinder; import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.RemoteException; import android.util.Log; import android.util.Log; Loading Loading @@ -181,9 +182,16 @@ public final class MidiDevice implements Closeable { } } try { try { IBinder token = new Binder(); IBinder token = new Binder(); mDeviceServer.connectPorts(token, pfd, outputPortNumber); int calleePid = mDeviceServer.connectPorts(token, pfd, outputPortNumber); // If the service is a different Process then it will duplicate the pfd // and we can safely close this one. // But if the service is in the same Process then closing the pfd will // kill the connection. So don't do that. if (calleePid != Process.myPid()) { // close our copy of the file descriptor // close our copy of the file descriptor IoUtils.closeQuietly(pfd); IoUtils.closeQuietly(pfd); } return new MidiConnection(token, inputPort); return new MidiConnection(token, inputPort); } catch (RemoteException e) { } catch (RemoteException e) { Log.e(TAG, "RemoteException in connectPorts"); Log.e(TAG, "RemoteException in connectPorts"); Loading
media/java/android/media/midi/MidiDeviceServer.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -254,7 +254,7 @@ public final class MidiDeviceServer implements Closeable { } } @Override @Override public void connectPorts(IBinder token, ParcelFileDescriptor pfd, public int connectPorts(IBinder token, ParcelFileDescriptor pfd, int outputPortNumber) { int outputPortNumber) { MidiInputPort inputPort = new MidiInputPort(pfd, outputPortNumber); MidiInputPort inputPort = new MidiInputPort(pfd, outputPortNumber); MidiDispatcher dispatcher = mOutputPortDispatchers[outputPortNumber]; MidiDispatcher dispatcher = mOutputPortDispatchers[outputPortNumber]; Loading @@ -270,6 +270,7 @@ public final class MidiDeviceServer implements Closeable { synchronized (mPortClients) { synchronized (mPortClients) { mPortClients.put(token, client); mPortClients.put(token, client); } } return Process.myPid(); // for caller to detect same process ID } } @Override @Override Loading