Loading media/java/android/media/midi/MidiManager.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -169,6 +169,13 @@ public final class MidiManager { /** /** * Registers a callback to receive notifications when MIDI devices are added and removed. * Registers a callback to receive notifications when MIDI devices are added and removed. * * * The {@link DeviceCallback#onDeviceStatusChanged} method will be called immediately * for any devices that have open ports. This allows applications to know which input * ports are already in use and, therefore, unavailable. * * Applications should call {@link #getDevices} before registering the callback * to get a list of devices already added. * * @param callback a {@link DeviceCallback} for MIDI device notifications * @param callback a {@link DeviceCallback} for MIDI device notifications * @param handler The {@link android.os.Handler Handler} that will be used for delivering the * @param handler The {@link android.os.Handler Handler} that will be used for delivering the * device notifications. If handler is null, then the thread used for the * device notifications. If handler is null, then the thread used for the Loading services/midi/java/com/android/server/midi/MidiService.java +21 −0 Original line number Original line Diff line number Diff line Loading @@ -575,6 +575,8 @@ public class MidiService extends IMidiManager.Stub { Client client = getClient(token); Client client = getClient(token); if (client == null) return; if (client == null) return; client.addListener(listener); client.addListener(listener); // Let listener know whether any ports are already busy. updateStickyDeviceStatus(client.mUid, listener); } } @Override @Override Loading @@ -584,6 +586,25 @@ public class MidiService extends IMidiManager.Stub { client.removeListener(listener); client.removeListener(listener); } } // Inform listener of the status of all known devices. private void updateStickyDeviceStatus(int uid, IMidiDeviceListener listener) { synchronized (mDevicesByInfo) { for (Device device : mDevicesByInfo.values()) { // ignore private devices that our client cannot access if (device.isUidAllowed(uid)) { try { MidiDeviceStatus status = device.getDeviceStatus(); if (status != null) { listener.onDeviceStatusChanged(status); } } catch (RemoteException e) { Log.e(TAG, "remote exception", e); } } } } } private static final MidiDeviceInfo[] EMPTY_DEVICE_INFO_ARRAY = new MidiDeviceInfo[0]; private static final MidiDeviceInfo[] EMPTY_DEVICE_INFO_ARRAY = new MidiDeviceInfo[0]; public MidiDeviceInfo[] getDevices() { public MidiDeviceInfo[] getDevices() { Loading Loading
media/java/android/media/midi/MidiManager.java +7 −0 Original line number Original line Diff line number Diff line Loading @@ -169,6 +169,13 @@ public final class MidiManager { /** /** * Registers a callback to receive notifications when MIDI devices are added and removed. * Registers a callback to receive notifications when MIDI devices are added and removed. * * * The {@link DeviceCallback#onDeviceStatusChanged} method will be called immediately * for any devices that have open ports. This allows applications to know which input * ports are already in use and, therefore, unavailable. * * Applications should call {@link #getDevices} before registering the callback * to get a list of devices already added. * * @param callback a {@link DeviceCallback} for MIDI device notifications * @param callback a {@link DeviceCallback} for MIDI device notifications * @param handler The {@link android.os.Handler Handler} that will be used for delivering the * @param handler The {@link android.os.Handler Handler} that will be used for delivering the * device notifications. If handler is null, then the thread used for the * device notifications. If handler is null, then the thread used for the Loading
services/midi/java/com/android/server/midi/MidiService.java +21 −0 Original line number Original line Diff line number Diff line Loading @@ -575,6 +575,8 @@ public class MidiService extends IMidiManager.Stub { Client client = getClient(token); Client client = getClient(token); if (client == null) return; if (client == null) return; client.addListener(listener); client.addListener(listener); // Let listener know whether any ports are already busy. updateStickyDeviceStatus(client.mUid, listener); } } @Override @Override Loading @@ -584,6 +586,25 @@ public class MidiService extends IMidiManager.Stub { client.removeListener(listener); client.removeListener(listener); } } // Inform listener of the status of all known devices. private void updateStickyDeviceStatus(int uid, IMidiDeviceListener listener) { synchronized (mDevicesByInfo) { for (Device device : mDevicesByInfo.values()) { // ignore private devices that our client cannot access if (device.isUidAllowed(uid)) { try { MidiDeviceStatus status = device.getDeviceStatus(); if (status != null) { listener.onDeviceStatusChanged(status); } } catch (RemoteException e) { Log.e(TAG, "remote exception", e); } } } } } private static final MidiDeviceInfo[] EMPTY_DEVICE_INFO_ARRAY = new MidiDeviceInfo[0]; private static final MidiDeviceInfo[] EMPTY_DEVICE_INFO_ARRAY = new MidiDeviceInfo[0]; public MidiDeviceInfo[] getDevices() { public MidiDeviceInfo[] getDevices() { Loading