MidiManager API tweaks:

Rename MidiReceiver.onPost() to post()

Change MidiManager.DeviceCallback from an interface to a class

Change-Id: I939ba7a7d82e721b90a3d80252a88e7a650c9396
diff --git a/core/java/android/midi/MidiDeviceServer.java b/core/java/android/midi/MidiDeviceServer.java
index 7499934..4a1995f 100644
--- a/core/java/android/midi/MidiDeviceServer.java
+++ b/core/java/android/midi/MidiDeviceServer.java
@@ -254,12 +254,12 @@
         return new MidiReceiver() {
 
             @Override
-            public void onPost(byte[] msg, int offset, int count, long timestamp) throws IOException {
+            public void post(byte[] msg, int offset, int count, long timestamp) throws IOException {
                 ArrayList<MidiInputPort> receivers = mOutputPortReceivers[portNumberF];
                 synchronized (receivers) {
                     for (int i = 0; i < receivers.size(); i++) {
                         // FIXME catch errors and remove dead ones
-                        receivers.get(i).onPost(msg, offset, count, timestamp);
+                        receivers.get(i).post(msg, offset, count, timestamp);
                     }
                 }
             }
diff --git a/core/java/android/midi/MidiInputPort.java b/core/java/android/midi/MidiInputPort.java
index 51c47dd..735c68a 100644
--- a/core/java/android/midi/MidiInputPort.java
+++ b/core/java/android/midi/MidiInputPort.java
@@ -50,7 +50,7 @@
      * @param timestamp future time to post the message (based on
      *                  {@link java.lang.System#nanoTime}
      */
-    public void onPost(byte[] msg, int offset, int count, long timestamp) throws IOException {
+    public void post(byte[] msg, int offset, int count, long timestamp) throws IOException {
         assert(offset >= 0 && count >= 0 && offset + count <= msg.length);
 
         synchronized (mBuffer) {
diff --git a/core/java/android/midi/MidiManager.java b/core/java/android/midi/MidiManager.java
index 8aa8395..3a0b064 100644
--- a/core/java/android/midi/MidiManager.java
+++ b/core/java/android/midi/MidiManager.java
@@ -66,22 +66,24 @@
     }
 
     /**
-     * Callback interface used for clients to receive MIDI device added and removed notifications
+     * Callback class used for clients to receive MIDI device added and removed notifications
      */
-    public interface DeviceCallback {
+    public static class DeviceCallback {
         /**
          * Called to notify when a new MIDI device has been added
          *
          * @param device a {@link MidiDeviceInfo} for the newly added device
          */
-        void onDeviceAdded(MidiDeviceInfo device);
+        void onDeviceAdded(MidiDeviceInfo device) {
+        }
 
         /**
          * Called to notify when a MIDI device has been removed
          *
          * @param device a {@link MidiDeviceInfo} for the removed device
          */
-        void onDeviceRemoved(MidiDeviceInfo device);
+        void onDeviceRemoved(MidiDeviceInfo device) {
+        }
     }
 
     /**
diff --git a/core/java/android/midi/MidiOutputPort.java b/core/java/android/midi/MidiOutputPort.java
index 332b431..b9512fd 100644
--- a/core/java/android/midi/MidiOutputPort.java
+++ b/core/java/android/midi/MidiOutputPort.java
@@ -65,7 +65,7 @@
                         for (int i = 0; i < mReceivers.size(); i++) {
                             MidiReceiver receiver = mReceivers.get(i);
                             try {
-                                receiver.onPost(buffer, offset, size, timestamp);
+                                receiver.post(buffer, offset, size, timestamp);
                             } catch (IOException e) {
                                 Log.e(TAG, "post failed");
                                 deadReceivers.add(receiver);
diff --git a/core/java/android/midi/MidiReceiver.java b/core/java/android/midi/MidiReceiver.java
index fdfe51a..16c9bbb 100644
--- a/core/java/android/midi/MidiReceiver.java
+++ b/core/java/android/midi/MidiReceiver.java
@@ -32,7 +32,7 @@
      * The msg bytes should be copied by the receiver rather than retaining a reference
      * to this parameter.
      * Also, modifying the contents of the msg array parameter may result in other receivers
-     * in the same application receiving incorrect values in their onPost() method.
+     * in the same application receiving incorrect values in their post() method.
      *
      * @param msg a byte array containing the MIDI data
      * @param offset the offset of the first byte of the data in the byte array
@@ -40,5 +40,5 @@
      * @param timestamp the timestamp of the message (based on {@link java.lang.System#nanoTime}
      * @throws IOException
      */
-    public void onPost(byte[] msg, int offset, int count, long timestamp) throws IOException;
+    public void post(byte[] msg, int offset, int count, long timestamp) throws IOException;
 }
diff --git a/services/usb/java/com/android/server/usb/UsbMidiDevice.java b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
index 8d44905..396ed38 100644
--- a/services/usb/java/com/android/server/usb/UsbMidiDevice.java
+++ b/services/usb/java/com/android/server/usb/UsbMidiDevice.java
@@ -112,7 +112,7 @@
             MidiReceiver receiver = new MidiReceiver() {
 
                 @Override
-                public void onPost(byte[] data, int offset, int count, long timestamp)
+                public void post(byte[] data, int offset, int count, long timestamp)
                         throws IOException {
                     // FIXME - timestamps are ignored, future posting not supported yet.
                     mOutputStreams[portNumberF].write(data, offset, count);
@@ -137,7 +137,7 @@
                                 pfd.revents = 0;
 
                                 int count = mInputStreams[index].read(buffer);
-                                mOutputPortReceivers[index].onPost(buffer, 0, count,
+                                mOutputPortReceivers[index].post(buffer, 0, count,
                                         System.nanoTime());
                             } else if ((pfd.revents & (OsConstants.POLLERR
                                                         | OsConstants.POLLHUP)) != 0) {