Bug 964154 - To Detect Whether Headset Event is Came from Input Dev or /sys Node in Runtime Not by Property. r=dhylands

This commit is contained in:
Kershaw Chang 2014-07-01 19:52:00 +02:00
parent 702ff05ae0
commit 928904ed0c
6 changed files with 47 additions and 11 deletions

View File

@ -1239,5 +1239,11 @@ GetTotalSystemMemoryLevel()
return hal_impl::GetTotalSystemMemoryLevel();
}
bool IsHeadphoneEventFromInputDev()
{
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(IsHeadphoneEventFromInputDev(), false);
}
} // namespace hal
} // namespace mozilla

View File

@ -616,6 +616,11 @@ uint32_t GetTotalSystemMemory();
*/
uint32_t GetTotalSystemMemoryLevel();
/**
* Determine whether the headphone switch event is from input device
*/
bool IsHeadphoneEventFromInputDev();
} // namespace MOZ_HAL_NAMESPACE
} // namespace mozilla

View File

@ -30,5 +30,10 @@ NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
{
}
bool IsHeadphoneEventFromInputDev()
{
return false;
}
} // namespace hal_impl
} // namespace mozilla

View File

@ -17,7 +17,6 @@
#include <android/log.h>
#include <fcntl.h>
#include <sysutils/NetlinkEvent.h>
#include <cutils/properties.h>
#include "base/message_loop.h"
@ -240,7 +239,9 @@ class SwitchEventObserver MOZ_FINAL : public IUeventObserver
public:
NS_INLINE_DECL_REFCOUNTING(SwitchEventObserver)
SwitchEventObserver() : mEnableCount(0)
SwitchEventObserver()
: mEnableCount(0),
mHeadphonesFromInputDev(false)
{
Init();
}
@ -309,6 +310,12 @@ public:
NS_DispatchToMainThread(new SwitchEventRunnable(info.mEvent));
}
}
bool GetHeadphonesFromInputDev()
{
return mHeadphonesFromInputDev;
}
private:
class EventInfo
{
@ -325,15 +332,18 @@ private:
EventInfo mEventInfo[NUM_SWITCH_DEVICE];
size_t mEnableCount;
SwitchHandlerArray mHandler;
bool mHeadphonesFromInputDev;
void Init()
{
char value[PROPERTY_VALUE_MAX];
property_get("ro.moz.devinputjack", value, "0");
bool headphonesFromInputDev = !strcmp(value, "1");
RefPtr<SwitchHandlerHeadphone> switchHeadPhone =
new SwitchHandlerHeadphone(SWITCH_HEADSET_DEVPATH);
if (!headphonesFromInputDev) {
mHandler.AppendElement(new SwitchHandlerHeadphone(SWITCH_HEADSET_DEVPATH));
// If the initial state is unknown, it means the headphone event is from input dev
mHeadphonesFromInputDev = switchHeadPhone->GetState() == SWITCH_STATE_UNKNOWN ? true : false;
if (!mHeadphonesFromInputDev) {
mHandler.AppendElement(switchHeadPhone);
} else {
// If headphone status will be notified from input dev then initialize
// status to "off" and wait for event notification.
@ -458,5 +468,12 @@ void NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
FROM_HERE,
NewRunnableFunction(NotifySwitchStateIOThread, aDevice, aState));
}
bool IsHeadphoneEventFromInputDev()
{
InitializeResourceIfNeed();
return sSwitchObserver->GetHeadphonesFromInputDev();
}
} // hal_impl
} //mozilla

View File

@ -443,6 +443,12 @@ StopDiskSpaceWatcher()
NS_RUNTIMEABORT("StopDiskSpaceWatcher() can't be called from sandboxed contexts.");
}
bool IsHeadphoneEventFromInputDev()
{
NS_RUNTIMEABORT("IsHeadphoneEventFromInputDev() cannot be called from sandboxed contexts.");
return false;
}
class HalParent : public PHalParent
, public BatteryObserver
, public NetworkObserver

View File

@ -62,7 +62,6 @@
#include "libui/EventHub.h"
#include "libui/InputReader.h"
#include "libui/InputDispatcher.h"
#include "cutils/properties.h"
#ifdef MOZ_NUWA_PROCESS
#include "ipc/Nuwa.h"
@ -1052,9 +1051,7 @@ nsAppShell::Exit()
void
nsAppShell::InitInputDevices()
{
char value[PROPERTY_VALUE_MAX];
property_get("ro.moz.devinputjack", value, "0");
sDevInputAudioJack = !strcmp(value, "1");
sDevInputAudioJack = hal::IsHeadphoneEventFromInputDev();
sHeadphoneState = AKEY_STATE_UNKNOWN;
sMicrophoneState = AKEY_STATE_UNKNOWN;