Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ee5800d authored by Roy Luo's avatar Roy Luo Committed by Android (Google) Code Review
Browse files

Merge "Add legacy fallback for midi device identification" into main

parents e8ce4cad 82bc2412
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -1027,28 +1027,36 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
            boolean enabled = (mCurrentFunctions & UsbManager.FUNCTION_MIDI) != 0;
            if (enabled != mMidiEnabled) {
                if (enabled) {
                    boolean midiDeviceFound = false;
                    if (android.hardware.usb.flags.Flags.enableUsbSysfsMidiIdentification()) {
                        try {
                            getMidiCardDevice();
                            midiDeviceFound = true;
                        } catch (FileNotFoundException e) {
                            Slog.e(TAG, "could not identify MIDI device", e);
                            enabled = false;
                            Slog.w(TAG, "could not identify MIDI device", e);
                        }
                    } else {
                    }
                    // For backward compatibility with older kernels without
                    // https://lore.kernel.org/r/20240307030922.3573161-1-royluo@google.com
                    if (!midiDeviceFound) {
                        Scanner scanner = null;
                        try {
                            scanner = new Scanner(new File(MIDI_ALSA_PATH));
                            mMidiCard = scanner.nextInt();
                            mMidiDevice = scanner.nextInt();
                            midiDeviceFound = true;
                        } catch (FileNotFoundException e) {
                            Slog.e(TAG, "could not open MIDI file", e);
                            enabled = false;
                        } finally {
                            if (scanner != null) {
                                scanner.close();
                            }
                        }
                    }
                    if (!midiDeviceFound) {
                        Slog.e(TAG, "Failed to enable MIDI function");
                        enabled = false;
                    }
                }
                mMidiEnabled = enabled;
            }