Bug 895665 - Gonk support for dev input audio jack events. r=mwu

This commit is contained in:
Michael Vines 2013-07-29 21:27:48 -07:00
parent 93a8c607cd
commit 3027d516ff

View File

@ -52,6 +52,7 @@
#include "libui/EventHub.h" #include "libui/EventHub.h"
#include "libui/InputReader.h" #include "libui/InputReader.h"
#include "libui/InputDispatcher.h" #include "libui/InputDispatcher.h"
#include "cutils/properties.h"
#include "GeckoProfiler.h" #include "GeckoProfiler.h"
@ -78,6 +79,9 @@ bool gDrawRequest = false;
static nsAppShell *gAppShell = NULL; static nsAppShell *gAppShell = NULL;
static int epollfd = 0; static int epollfd = 0;
static int signalfds[2] = {0}; static int signalfds[2] = {0};
static bool sDevInputAudioJack;
static int32_t sHeadphoneState;
static int32_t sMicrophoneState;
NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver) NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver)
@ -245,6 +249,41 @@ maybeSendKeyEvent(int keyCode, bool pressed, uint64_t timeMs)
} }
} }
class SwitchEventRunnable : public nsRunnable {
public:
SwitchEventRunnable(hal::SwitchEvent& aEvent) : mEvent(aEvent)
{}
NS_IMETHOD Run()
{
hal::NotifySwitchChange(mEvent);
return NS_OK;
}
private:
hal::SwitchEvent mEvent;
};
static void
updateHeadphoneSwitch()
{
hal::SwitchEvent event;
switch (sHeadphoneState) {
case AKEY_STATE_UP:
event.status() = hal::SWITCH_STATE_OFF;
break;
case AKEY_STATE_DOWN:
event.status() = sMicrophoneState == AKEY_STATE_DOWN ?
hal::SWITCH_STATE_HEADPHONE : hal::SWITCH_STATE_HEADSET;
break;
default:
return;
}
event.device() = hal::SWITCH_HEADPHONES;
NS_DispatchToMainThread(new SwitchEventRunnable(event));
}
class GeckoPointerController : public PointerControllerInterface { class GeckoPointerController : public PointerControllerInterface {
float mX; float mX;
float mY; float mY;
@ -553,6 +592,19 @@ GeckoInputDispatcher::notifyMotion(const NotifyMotionArgs* args)
void GeckoInputDispatcher::notifySwitch(const NotifySwitchArgs* args) void GeckoInputDispatcher::notifySwitch(const NotifySwitchArgs* args)
{ {
if (!sDevInputAudioJack)
return;
switch (args->switchCode) {
case SW_HEADPHONE_INSERT:
sHeadphoneState = args->switchValue;
updateHeadphoneSwitch();
break;
case SW_MICROPHONE_INSERT:
sMicrophoneState = args->switchValue;
updateHeadphoneSwitch();
break;
}
} }
void GeckoInputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) void GeckoInputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args)
@ -661,6 +713,12 @@ nsAppShell::Observe(nsISupports* aSubject,
return nsBaseAppShell::Observe(aSubject, aTopic, aData); return nsBaseAppShell::Observe(aSubject, aTopic, aData);
} }
if (sDevInputAudioJack) {
sHeadphoneState = mReader->getSwitchState(-1, AINPUT_SOURCE_SWITCH, SW_HEADPHONE_INSERT);
sMicrophoneState = mReader->getSwitchState(-1, AINPUT_SOURCE_SWITCH, SW_MICROPHONE_INSERT);
updateHeadphoneSwitch();
}
mEnableDraw = true; mEnableDraw = true;
NotifyEvent(); NotifyEvent();
return NS_OK; return NS_OK;
@ -680,6 +738,12 @@ nsAppShell::Exit()
void void
nsAppShell::InitInputDevices() nsAppShell::InitInputDevices()
{ {
char value[PROPERTY_VALUE_MAX];
property_get("ro.moz.devinputjack", value, "0");
sDevInputAudioJack = !strcmp(value, "1");
sHeadphoneState = AKEY_STATE_UNKNOWN;
sMicrophoneState = AKEY_STATE_UNKNOWN;
mEventHub = new EventHub(); mEventHub = new EventHub();
mReaderPolicy = new GeckoInputReaderPolicy(); mReaderPolicy = new GeckoInputReaderPolicy();
mReaderPolicy->setDisplayInfo(); mReaderPolicy->setDisplayInfo();