audiod: Skip enumerating non-ADSP sound cards

Target crash is observed when a USB headset
is inserted while the target is rebooting.

The crash occurs as AudioDaemon polls on a list
which is corrupt.

Skip enumerating non-ADSP sound cards in AudioDaemon
and sndmonitor to avoid list corruption that fixes
the issue.

CRs-Fixed: 1090587
Change-Id: I0e527182bf4c40e34dbafe8ef3af5490a2bd5798
diff --git a/audiod/AudioDaemon.cpp b/audiod/AudioDaemon.cpp
index 2c9b5d0..1a40330 100644
--- a/audiod/AudioDaemon.cpp
+++ b/audiod/AudioDaemon.cpp
@@ -1,5 +1,5 @@
 /* AudioDaemon.cpp
-Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
+Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
@@ -69,7 +69,7 @@
     {
         FILE *fp;
         int fd;
-        char *ptr, *saveptr;
+        char *ptr, *saveptr, *card_id = NULL;
         char buffer[128];
         int line = 0;
         String8 path;
@@ -84,9 +84,21 @@
         sndcardFdPair.clear();
         memset(buffer, 0x0, sizeof(buffer));
         while ((fgets(buffer, sizeof(buffer), fp) != NULL)) {
-            if (line % 2)
+            if (line++ % 2)
                 continue;
             ptr = strtok_r(buffer, " [", &saveptr);
+            if (!ptr)
+                continue;
+
+            card_id = strtok_r(saveptr+1, "]", &saveptr);
+            if (!card_id)
+                continue;
+            //Only consider sound cards associated with ADSP
+            if ((strncasecmp(card_id, "msm", 3) != 0) &&
+                (strncasecmp(card_id, "apq", 3) != 0)) {
+                ALOGD("Skipping non-ADSP sound card %s", card_id);
+                continue;
+            }
             if (ptr) {
                 path = "/proc/asound/card";
                 path += ptr;
@@ -101,7 +113,6 @@
                     sndcardFdPair.push_back(std::make_pair(sndcard, fd));
                 }
             }
-            line++;
         }
 
         ALOGV("%s: %d sound cards detected", __func__, sndcardFdPair.size());