summaryrefslogtreecommitdiffstats
path: root/core/java/android/alsa/AlsaCardsParser.java
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2015-01-21 11:11:14 -0800
committerMike Lockwood <lockwood@google.com>2015-01-21 11:11:14 -0800
commita1329aebe7ef21f18826d495b0df7fdbec1ae096 (patch)
tree7b91954cd172ea8ba41ca720f850a79512e7c19e /core/java/android/alsa/AlsaCardsParser.java
parentab75f637878ce3237e675cf3e1a5a43c3c009b09 (diff)
downloadframeworks_base-a1329aebe7ef21f18826d495b0df7fdbec1ae096.zip
frameworks_base-a1329aebe7ef21f18826d495b0df7fdbec1ae096.tar.gz
frameworks_base-a1329aebe7ef21f18826d495b0df7fdbec1ae096.tar.bz2
Watch for NumberFormatExceptions in AlsaCardsParser and AlsaDevicesParser
Bug: 19082426 Change-Id: I130d4df290716339326a28d249217a8a04220176
Diffstat (limited to 'core/java/android/alsa/AlsaCardsParser.java')
-rw-r--r--core/java/android/alsa/AlsaCardsParser.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/core/java/android/alsa/AlsaCardsParser.java b/core/java/android/alsa/AlsaCardsParser.java
index 8f9c56c..2c7d502 100644
--- a/core/java/android/alsa/AlsaCardsParser.java
+++ b/core/java/android/alsa/AlsaCardsParser.java
@@ -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);
- // mCardNum
- mCardNum = Integer.parseInt(line.substring(tokenIndex, delimIndex));
+ 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);