MidiService: Add GuardedBy Annotation to USB MIDI

As a follow-up to ag/16835029, adding GuardedBy annotation
to new USB specific classes. This should help with identifying
potential races

Bug: 219763493
Test: Tested on MIDI 2.0 keyboard
Change-Id: I3d77db0d741cca8f79a759d2dcc99e8254b0298c
diff --git a/services/midi/java/com/android/server/midi/MidiService.java b/services/midi/java/com/android/server/midi/MidiService.java
index 2d082e1..bce5256 100644
--- a/services/midi/java/com/android/server/midi/MidiService.java
+++ b/services/midi/java/com/android/server/midi/MidiService.java
@@ -50,6 +50,7 @@
 import android.util.EventLog;
 import android.util.Log;
 
+import com.android.internal.annotations.GuardedBy;
 import com.android.internal.content.PackageMonitor;
 import com.android.internal.util.DumpUtils;
 import com.android.internal.util.IndentingPrintWriter;
@@ -136,10 +137,12 @@
     private final Object mUsbMidiLock = new Object();
 
     // Number of times a USB MIDI 1.0 device has opened, based on the device name.
+    @GuardedBy("mUsbMidiLock")
     private final HashMap<String, Integer> mUsbMidiLegacyDeviceOpenCount =
             new HashMap<String, Integer>();
 
     // Whether a USB MIDI device has opened, based on the device name.
+    @GuardedBy("mUsbMidiLock")
     private final HashSet<String> mUsbMidiUniversalDeviceInUse = new HashSet<String>();
 
     // UID of BluetoothMidiService
@@ -1247,7 +1250,7 @@
         pw.decreaseIndent();
     }
 
-    // hold mUsbMidiLock before calling this
+    @GuardedBy("mUsbMidiLock")
     private boolean isUsbMidiDeviceInUseLocked(MidiDeviceInfo info) {
         String name = info.getProperties().getString(MidiDeviceInfo.PROPERTY_NAME);
         if (name.length() < MIDI_LEGACY_STRING.length()) {
@@ -1266,7 +1269,7 @@
         return false;
     }
 
-    // hold mUsbMidiLock before calling this
+    @GuardedBy("mUsbMidiLock")
     void addUsbMidiDeviceLocked(MidiDeviceInfo info) {
         String name = info.getProperties().getString(MidiDeviceInfo.PROPERTY_NAME);
         if (name.length() < MIDI_LEGACY_STRING.length()) {
@@ -1283,7 +1286,7 @@
         }
     }
 
-    // hold mUsbMidiLock before calling this
+    @GuardedBy("mUsbMidiLock")
     void removeUsbMidiDeviceLocked(MidiDeviceInfo info) {
         String name = info.getProperties().getString(MidiDeviceInfo.PROPERTY_NAME);
         if (name.length() < MIDI_LEGACY_STRING.length()) {