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

Commit 613bc557 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Checking for errors opening/parsing ALSA "cards" file."

parents a88b7a97 fd47f403
Loading
Loading
Loading
Loading
+29 −3
Original line number Diff line number Diff line
@@ -37,6 +37,12 @@ public class AlsaCardsParser {

    private ArrayList<AlsaCardRecord> mCardRecords = new ArrayList<AlsaCardRecord>();

    public static final int SCANSTATUS_NOTSCANNED = -1;
    public static final int SCANSTATUS_SUCCESS = 0;
    public static final int SCANSTATUS_FAIL = 1;
    public static final int SCANSTATUS_EMPTY = 2;
    private int mScanStatus = SCANSTATUS_NOTSCANNED;

    public class AlsaCardRecord {
        private static final String TAG = "AlsaCardRecord";
        private static final String kUsbCardKeyStr = "at usb-";
@@ -104,10 +110,11 @@ public class AlsaCardsParser {

    public AlsaCardsParser() {}

    public void scan() {
    public int scan() {
        if (DEBUG) {
            Slog.i(TAG, "AlsaCardsParser.scan()");
            Slog.i(TAG, "AlsaCardsParser.scan()....");
        }

        mCardRecords = new ArrayList<AlsaCardRecord>();

        File cardsFile = new File(kCardsFilePath);
@@ -134,11 +141,26 @@ public class AlsaCardsParser {
                mCardRecords.add(cardRecord);
            }
            reader.close();
            if (mCardRecords.size() > 0) {
                mScanStatus = SCANSTATUS_SUCCESS;
            } else {
                mScanStatus = SCANSTATUS_EMPTY;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            mScanStatus = SCANSTATUS_FAIL;
        } catch (IOException e) {
            e.printStackTrace();
            mScanStatus = SCANSTATUS_FAIL;
        }
        if (DEBUG) {
            Slog.i(TAG, "  status:" + mScanStatus);
        }
        return mScanStatus;
    }

    public int getScanStatus() {
        return mScanStatus;
    }

    public ArrayList<AlsaCardRecord> getScanRecords() {
@@ -182,7 +204,11 @@ public class AlsaCardsParser {
        }

        // get the new list of devices
        scan();
        if (scan() != SCANSTATUS_SUCCESS) {
            Slog.e(TAG, "Error scanning Alsa cards file.");
            return -1;
        }

        if (DEBUG) {
            LogDevices("Current Devices:", mCardRecords);
        }
+27 −3
Original line number Diff line number Diff line
@@ -46,6 +46,12 @@ public class AlsaDevicesParser {
    private boolean mHasPlaybackDevices = false;
    private boolean mHasMIDIDevices = false;

    public static final int SCANSTATUS_NOTSCANNED = -1;
    public static final int SCANSTATUS_SUCCESS = 0;
    public static final int SCANSTATUS_FAIL = 1;
    public static final int SCANSTATUS_EMPTY = 2;
    private int mScanStatus = SCANSTATUS_NOTSCANNED;

    public class AlsaDeviceRecord {
        public static final int kDeviceType_Unknown = -1;
        public static final int kDeviceType_Audio = 0;
@@ -258,7 +264,11 @@ public class AlsaDevicesParser {
        return line.charAt(kIndex_CardDeviceField) == '[';
    }

    public boolean scan() {
    public int scan() {
        if (DEBUG) {
            Slog.i(TAG, "AlsaDevicesParser.scan()....");
        }

        mDeviceRecords.clear();

        File devicesFile = new File(kDevicesFilePath);
@@ -274,13 +284,27 @@ public class AlsaDevicesParser {
                }
            }
            reader.close();
            return true;
            // success if we add at least 1 record
            if (mDeviceRecords.size() > 0) {
                mScanStatus = SCANSTATUS_SUCCESS;
            } else {
                mScanStatus = SCANSTATUS_EMPTY;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            mScanStatus = SCANSTATUS_FAIL;
        } catch (IOException e) {
            e.printStackTrace();
            mScanStatus = SCANSTATUS_FAIL;
        }
        return false;
        if (DEBUG) {
            Slog.i(TAG, "  status:" + mScanStatus);
        }
        return mScanStatus;
    }

    public int getScanStatus() {
        return mScanStatus;
    }

    //
+7 −2
Original line number Diff line number Diff line
@@ -132,7 +132,9 @@ public final class UsbAlsaManager {
        mHasMidiFeature = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MIDI);

        // initial scan
        mCardsParser.scan();
        if (mCardsParser.scan() != AlsaCardsParser.SCANSTATUS_SUCCESS) {
            Slog.e(TAG, "Error scanning ASLA cards file.");
        }
    }

    public void systemReady() {
@@ -314,7 +316,7 @@ public final class UsbAlsaManager {
            return null;
        }

        if (!mDevicesParser.scan()) {
        if (mDevicesParser.scan() != AlsaDevicesParser.SCANSTATUS_SUCCESS) {
            Slog.e(TAG, "Error parsing ALSA devices file.");
            return null;
        }
@@ -530,6 +532,9 @@ public final class UsbAlsaManager {
    //
    // called by UsbService.dump
    public void dump(IndentingPrintWriter pw) {
        pw.println("Parsers Scan Status:");
        pw.println("  Cards Parser: " + mCardsParser.getScanStatus());
        pw.println("  Devices Parser: " + mDevicesParser.getScanStatus());
        pw.println("USB Audio Devices:");
        for (UsbDevice device : mAudioDevices.keySet()) {
            pw.println("  " + device.getDeviceName() + ": " + mAudioDevices.get(device));
+2 −0
Original line number Diff line number Diff line
@@ -376,6 +376,8 @@ public class UsbHostManager {
                }
            }
        }

        mUsbAlsaManager.dump(pw);
    }

    private native void monitorUsbHostBus();