OSDN Git Service

Catch IO Exception in UsbDevicesParser and don't add failed devices.
authorPaul McLean <pmclean@google.com>
Thu, 5 Oct 2017 21:28:20 +0000 (15:28 -0600)
committerPaul McLean <pmclean@google.com>
Thu, 5 Oct 2017 21:28:20 +0000 (15:28 -0600)
Note: This is related to bug 66988327, but NOT a fix for it.

Bug: 66988327
Test: Manual
Change-Id: Ib9ccaa9634c7fc011f70513d5589870e9190418a

core/java/com/android/internal/alsa/AlsaDevicesParser.java
services/usb/java/com/android/server/usb/UsbAlsaManager.java

index 7cdd897..6e3d596 100644 (file)
@@ -258,7 +258,7 @@ public class AlsaDevicesParser {
         return line.charAt(kIndex_CardDeviceField) == '[';
     }
 
-    public void scan() {
+    public boolean scan() {
         mDeviceRecords.clear();
 
         File devicesFile = new File(kDevicesFilePath);
@@ -274,11 +274,13 @@ public class AlsaDevicesParser {
                 }
             }
             reader.close();
+            return true;
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }
+        return false;
     }
 
     //
index 68c1d5f..acc27be 100644 (file)
@@ -314,7 +314,11 @@ public final class UsbAlsaManager {
             return null;
         }
 
-        mDevicesParser.scan();
+        if (!mDevicesParser.scan()) {
+            Slog.e(TAG, "Error parsing ALSA devices file.");
+            return null;
+        }
+
         int device = mDevicesParser.getDefaultDeviceNum(card);
 
         boolean hasPlayback = mDevicesParser.hasPlaybackDevices(card);