Autotest audio_helper: Check jack status from input device.

Add a function to check jack status for ARM device, on which
audio jacks are not exposed to amixer control.
Note that current implementation only gets the jack status
at when an InputDevice object initialized.

BUG=chromium-os:36035
TEST=Manual run desktop_AudioFeedback test, when audio loopback dongle
is plugged or unplugged can see corresponding log.

Change-Id: Ifd62e9d196b87d535a2df0d187c7359d43dd96ff
Reviewed-on: https://gerrit.chromium.org/gerrit/37519
Commit-Ready: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
diff --git a/client/cros/audio/audio_helper.py b/client/cros/audio/audio_helper.py
index 0afa70f..4a604d6 100644
--- a/client/cros/audio/audio_helper.py
+++ b/client/cros/audio/audio_helper.py
@@ -9,7 +9,10 @@
 import tempfile
 import threading
 
+from glob import glob
+
 from autotest_lib.client.bin import utils
+from autotest_lib.client.bin.input.input_device import *
 from autotest_lib.client.common_lib import error
 
 LD_LIBRARY_PATH = 'LD_LIBRARY_PATH'
@@ -105,9 +108,9 @@
         utils.system('/usr/bin/cras_test_client --mute 0')
         utils.system('amixer -c 0 contents')
 
-    def get_jack_status(self, jack_reg_exp):
+    def get_mixer_jack_status(self, jack_reg_exp):
         '''
-        Gets the jack status.
+        Gets the mixer jack status.
 
         Args:
             jack_reg_exp: The regular expression to match jack control name.
@@ -123,7 +126,9 @@
             if m:
                 numid = m.group(1)
                 break
-        if numid is not None:
+
+        # Proceed only when matched numid is not empty.
+        if numid:
             output = utils.system_output('amixer -c0 cget numid=%s' % numid)
             for line in output.split('\n'):
                 if _JACK_VALUE_ON_RE.match(line):
@@ -133,10 +138,34 @@
             return None
 
     def get_hp_jack_status(self):
-        return self.get_jack_status(_HP_JACK_CONTROL_RE)
+        status = self.get_mixer_jack_status(_HP_JACK_CONTROL_RE)
+        if status is not None:
+            return status
+
+        # When headphone jack is not found in amixer, lookup input devices
+        # instead.
+        #
+        # TODO(hychao): Check hp/mic jack status dynamically from evdev. And
+        # possibly replace the existing check using amixer.
+        for evdev in glob('/dev/input/event*'):
+            device = InputDevice(evdev)
+            if device.is_hp_jack():
+                return device.get_headphone_insert()
+        else:
+            return None
 
     def get_mic_jack_status(self):
-        return self.get_jack_status(_MIC_JACK_CONTROL_RE)
+        status = self.get_mixer_jack_status(_MIC_JACK_CONTROL_RE)
+        if status is not None:
+            return status
+
+        # When mic jack is not found in amixer, lookup input devices instead.
+        for evdev in glob('/dev/input/event*'):
+            device = InputDevice(evdev)
+            if device.is_mic_jack():
+                return device.get_microphone_insert()
+        else:
+            return None
 
     def check_loopback_dongle(self):
         '''