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

Commit a1329aeb authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Watch for NumberFormatExceptions in AlsaCardsParser and AlsaDevicesParser

Bug: 19082426
Change-Id: I130d4df290716339326a28d249217a8a04220176
parent ab75f637
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ public class AlsaCardsParser {
    private static final String TAG = "AlsaCardsParser";
    protected static final boolean DEBUG = true;

    private static final String kCardsFilePath = "/proc/asound/cards";

    private static LineTokenizer mTokenizer = new LineTokenizer(" :[]");

    private ArrayList<AlsaCardRecord> mCardRecords = new ArrayList<AlsaCardRecord>();
@@ -56,8 +58,14 @@ public class AlsaCardsParser {
                tokenIndex = mTokenizer.nextToken(line, tokenIndex);
                delimIndex = mTokenizer.nextDelimiter(line, tokenIndex);

                try {
                    // mCardNum
                    mCardNum = Integer.parseInt(line.substring(tokenIndex, delimIndex));
                } catch (NumberFormatException e) {
                    Slog.e(TAG, "Failed to parse line " + lineIndex + " of " + kCardsFilePath
                        + ": " + line.substring(tokenIndex, delimIndex));
                    return false;
                }

                // mField1
                tokenIndex = mTokenizer.nextToken(line, delimIndex);
@@ -93,8 +101,7 @@ public class AlsaCardsParser {
        }
        mCardRecords = new ArrayList<AlsaCardRecord>();

        final String cardsFilePath = "/proc/asound/cards";
        File cardsFile = new File(cardsFilePath);
        File cardsFile = new File(kCardsFilePath);
        try {
            FileReader reader = new FileReader(cardsFile);
            BufferedReader bufferedReader = new BufferedReader(reader);
+54 −47
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ public class AlsaDevicesParser {
    private static final String TAG = "AlsaDevicesParser";
    protected static final boolean DEBUG = false;

    private static final String kDevicesFilePath = "/proc/asound/devices";

    private static final int kIndex_CardDeviceField = 5;
    private static final int kStartIndex_CardNum = 6;
    private static final int kEndIndex_CardNum = 8; // one past
@@ -89,6 +91,7 @@ public class AlsaDevicesParser {
                }
                String token = line.substring(tokenOffset, delimOffset);

                try {
                    switch (tokenIndex) {
                    case kToken_LineNum:
                        // ignore
@@ -134,6 +137,11 @@ public class AlsaDevicesParser {
                        }
                        break;
                    } // switch (tokenIndex)
                } catch (NumberFormatException e) {
                    Slog.e(TAG, "Failed to parse token " + tokenIndex + " of " + kDevicesFilePath
                        + " token: " + token);
                    return false;
                }

                tokenIndex++;
            } // while (true)
@@ -245,8 +253,7 @@ public class AlsaDevicesParser {
    public void scan() {
        mDeviceRecords.clear();

        final String devicesFilePath = "/proc/asound/devices";
        File devicesFile = new File(devicesFilePath);
        File devicesFile = new File(kDevicesFilePath);
        try {
            FileReader reader = new FileReader(devicesFile);
            BufferedReader bufferedReader = new BufferedReader(reader);