MidiService: Fix USB removeDeviceConnection
When MIDI USB devices are removed, removeUsbMidiDeviceLocked is not called at the correct places. This CL moves the check as a per Device basis. Whenever mDeviceConnections is removed per device, removeUsbMidiDeviceLocked should be called. Before, we were calling addUsbMidiDeviceLocked on a Device basis and removeUsbMidiDeviceLocked on a Client basis. This caused incorrect behavior. The consistent behavior with this CL allows MIDI 2.0 opens to work as expected. Bug: 231465285 Test: Tested MIDI 2.0 app with MIDI 2.0 device Test: Tested MIDI Keyboard with virtual device Test: Tested MIDI Keyboard with Bluetooth MIDI Test: Tested MIDI Keyboard with USB MIDI Change-Id: I68567fa54b1013c6dce357f77451fe11ae2140f9
This commit is contained in:
@@ -235,7 +235,7 @@ public class MidiService extends IMidiManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
// called from Device.close()
|
||||
// called from Device.closeLocked()
|
||||
public void removeDeviceConnection(DeviceConnection connection) {
|
||||
mDeviceConnections.remove(connection.getToken());
|
||||
if (mListeners.size() == 0 && mDeviceConnections.size() == 0) {
|
||||
@@ -291,12 +291,6 @@ public class MidiService extends IMidiManager.Stub {
|
||||
}
|
||||
|
||||
for (DeviceConnection connection : mDeviceConnections.values()) {
|
||||
if (connection.getDevice().getDeviceInfo().getType()
|
||||
== MidiDeviceInfo.TYPE_USB) {
|
||||
synchronized (mUsbMidiLock) {
|
||||
removeUsbMidiDeviceLocked(connection.getDevice().getDeviceInfo());
|
||||
}
|
||||
}
|
||||
connection.getDevice().removeDeviceConnection(connection);
|
||||
}
|
||||
}
|
||||
@@ -529,6 +523,13 @@ public class MidiService extends IMidiManager.Stub {
|
||||
synchronized (mDeviceConnections) {
|
||||
mDeviceConnections.remove(connection);
|
||||
|
||||
if (connection.getDevice().getDeviceInfo().getType()
|
||||
== MidiDeviceInfo.TYPE_USB) {
|
||||
synchronized (mUsbMidiLock) {
|
||||
removeUsbMidiDeviceLocked(connection.getDevice().getDeviceInfo());
|
||||
}
|
||||
}
|
||||
|
||||
if (mDeviceConnections.size() == 0 && mServiceConnection != null) {
|
||||
mContext.unbindService(mServiceConnection);
|
||||
mServiceConnection = null;
|
||||
@@ -547,6 +548,12 @@ public class MidiService extends IMidiManager.Stub {
|
||||
public void closeLocked() {
|
||||
synchronized (mDeviceConnections) {
|
||||
for (DeviceConnection connection : mDeviceConnections) {
|
||||
if (connection.getDevice().getDeviceInfo().getType()
|
||||
== MidiDeviceInfo.TYPE_USB) {
|
||||
synchronized (mUsbMidiLock) {
|
||||
removeUsbMidiDeviceLocked(connection.getDevice().getDeviceInfo());
|
||||
}
|
||||
}
|
||||
connection.getClient().removeDeviceConnection(connection);
|
||||
}
|
||||
mDeviceConnections.clear();
|
||||
@@ -1338,6 +1345,8 @@ public class MidiService extends IMidiManager.Stub {
|
||||
String deviceName = extractUsbDeviceName(name);
|
||||
String tagName = extractUsbDeviceTag(name);
|
||||
|
||||
Log.i(TAG, "Checking " + deviceName + " " + tagName);
|
||||
|
||||
// Only one MIDI 2.0 device can be used at once.
|
||||
// Multiple MIDI 1.0 devices can be used at once.
|
||||
if (mUsbMidiUniversalDeviceInUse.contains(deviceName)
|
||||
@@ -1357,6 +1366,8 @@ public class MidiService extends IMidiManager.Stub {
|
||||
String deviceName = extractUsbDeviceName(name);
|
||||
String tagName = extractUsbDeviceTag(name);
|
||||
|
||||
Log.i(TAG, "Adding " + deviceName + " " + tagName);
|
||||
|
||||
if ((tagName).equals(MIDI_UNIVERSAL_STRING)) {
|
||||
mUsbMidiUniversalDeviceInUse.add(deviceName);
|
||||
} else if ((tagName).equals(MIDI_LEGACY_STRING)) {
|
||||
@@ -1374,6 +1385,8 @@ public class MidiService extends IMidiManager.Stub {
|
||||
String deviceName = extractUsbDeviceName(name);
|
||||
String tagName = extractUsbDeviceTag(name);
|
||||
|
||||
Log.i(TAG, "Removing " + deviceName + " " + tagName);
|
||||
|
||||
if ((tagName).equals(MIDI_UNIVERSAL_STRING)) {
|
||||
mUsbMidiUniversalDeviceInUse.remove(deviceName);
|
||||
} else if ((tagName).equals(MIDI_LEGACY_STRING)) {
|
||||
|
||||
Reference in New Issue
Block a user