Bug 791329 - Let GonkSwitch to know the status about headset or headphone from uevent. r=dhylands
authorMarco Chen <mchen@mozilla.com>
Tue, 25 Sep 2012 19:03:13 +0800
changeset 114320 e33be28f695067eafa533581c12eb7e9a7d6e962
parent 114319 1ebd4fc2448cc461e6f77bf50e7a73f84ebd54ba
child 114321 00141260d4e76c629136288861459c3b9aff476f
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs791329
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 791329 - Let GonkSwitch to know the status about headset or headphone from uevent. r=dhylands
hal/HalTypes.h
hal/gonk/GonkSwitch.cpp
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -47,16 +47,18 @@ enum SwitchDevice {
   SWITCH_USB,
   NUM_SWITCH_DEVICE
 };
 
 enum SwitchState {
   SWITCH_STATE_UNKNOWN = -1,
   SWITCH_STATE_ON,
   SWITCH_STATE_OFF,
+  SWITCH_STATE_HEADSET,          // Headphone with microphone
+  SWITCH_STATE_HEADPHONE,        // without microphone
   NUM_SWITCH_STATE
 };
 
 typedef Observer<SwitchEvent> SwitchObserver;
 
 enum ProcessPriority {
   PROCESS_PRIORITY_BACKGROUND,
   PROCESS_PRIORITY_FOREGROUND,
--- a/hal/gonk/GonkSwitch.cpp
+++ b/hal/gonk/GonkSwitch.cpp
@@ -33,43 +33,26 @@ using namespace mozilla::hal;
 
 #define SWITCH_HEADSET_DEVPATH "/devices/virtual/switch/h2w"
 #define SWITCH_USB_DEVPATH_GB  "/devices/virtual/switch/usb_configuration"
 #define SWITCH_USB_DEVPATH_ICS "/devices/virtual/android_usb/android0"
 
 namespace mozilla {
 namespace hal_impl {
 /**
- * The uevent for a headset on SGS2 insertion looks like:
- * 
- * change@/devices/virtual/switch/h2w
- *   ACTION=change
- *   DEVPATH=/devices/virtual/switch/h2w
- *   SUBSYSTEM=switch
- *   SWITCH_NAME=h2w
- *   SWITCH_STATE=2
- *   SEQNUM=2581
- * On Otoro, SWITCH_NAME could be Headset/No Device when plug/unplug.
- * change@/devices/virtual/switch/h2w
- *   ACTION=change
- *   DEVPATH=/devices/virtual/switch/h2w
- *   SUBSYSTEM=switch
- *   SWITCH_NAME=Headset
- *   SWITCH_STATE=1
- *   SEQNUM=1602
- * 
- * The uevent for usb on GB,
+ * The uevent for a usb on GB insertion looks like:
+ *
  *  change@/devices/virtual/switch/usb_configuration
  *    ACTION=change
  *    DEVPATH=/devices/virtual/switch/usb_configuration
  *    SUBSYSTEM=switch
  *    SWITCH_NAME=usb_configuration
  *    SWITCH_STATE=0
  *    SEQNUM=5038
- */ 
+ */
 class SwitchHandler : public RefCounted<SwitchHandler>
 {
 public:
   SwitchHandler(const char* aDevPath, SwitchDevice aDevice)
     : mDevPath(aDevPath),
       mState(SWITCH_STATE_UNKNOWN),
       mDevice(aDevice)
   {
@@ -179,16 +162,57 @@ protected:
 
   SwitchState ConvertState(const char* aState)
   {
     MOZ_ASSERT(aState);
     return strcmp(aState, "CONFIGURED") == 0 ? SWITCH_STATE_ON : SWITCH_STATE_OFF;
   }
 };
 
+/**
+ * The uevent delivered for the headset under ICS looks like,
+ *
+ * change@/devices/virtual/switch/h2w
+ *   ACTION=change
+ *   DEVPATH=/devices/virtual/switch/h2w
+ *   SUBSYSTEM=switch
+ *   SWITCH_NAME=h2w
+ *   SWITCH_STATE=2 // Headset with no mic
+ *   SEQNUM=2581
+ * On Otoro, SWITCH_NAME could be Headset/No Device when plug/unplug.
+ * change@/devices/virtual/switch/h2w
+ *   ACTION=change
+ *   DEVPATH=/devices/virtual/switch/h2w
+ *   SUBSYSTEM=switch
+ *   SWITCH_NAME=Headset
+ *   SWITCH_STATE=1 // Headset with mic
+ *   SEQNUM=1602
+ */
+class SwitchHandlerHeadphone: public SwitchHandler
+{
+public:
+  SwitchHandlerHeadphone(const char* aDevPath) :
+    SwitchHandler(aDevPath, SWITCH_HEADPHONES)
+  {
+    SwitchHandler::GetInitialState();
+  }
+
+  virtual ~SwitchHandlerHeadphone() { }
+
+protected:
+  SwitchState ConvertState(const char* aState)
+  {
+    MOZ_ASSERT(aState);
+
+    return aState[0] == '0' ? SWITCH_STATE_OFF :
+      (aState[0] == '1' ? SWITCH_STATE_HEADSET : SWITCH_STATE_HEADPHONE);
+  }
+};
+
+
 typedef nsTArray<RefPtr<SwitchHandler> > SwitchHandlerArray;
 
 class SwitchEventRunnable : public nsRunnable
 {
 public:
   SwitchEventRunnable(SwitchEvent& aEvent) : mEvent(aEvent)
   {
   }
@@ -280,20 +304,20 @@ private:
   };
 
   EventInfo mEventInfo[NUM_SWITCH_DEVICE];
   size_t mEnableCount;
   SwitchHandlerArray mHandler;
 
   void Init()
   {
-    mHandler.AppendElement(new SwitchHandler(SWITCH_HEADSET_DEVPATH, SWITCH_HEADPHONES));
+    mHandler.AppendElement(new SwitchHandlerHeadphone(SWITCH_HEADSET_DEVPATH));
     mHandler.AppendElement(new SwitchHandler(SWITCH_USB_DEVPATH_GB, SWITCH_USB));
     mHandler.AppendElement(new SwitchHandlerUsbIcs(SWITCH_USB_DEVPATH_ICS));
-    
+
     SwitchHandlerArray::index_type handlerIndex;
     SwitchHandlerArray::size_type numHandlers = mHandler.Length();
 
     for (handlerIndex = 0; handlerIndex < numHandlers; handlerIndex++) {
       SwitchState state = mHandler[handlerIndex]->GetState();
       if (state == SWITCH_STATE_UNKNOWN) {
         continue;
       }