author | Kershaw Chang <kechang@mozilla.com> |
Tue, 01 Jul 2014 19:52:00 +0200 | |
changeset 191889 | bd0703d4cd88067e4cf300932b4e25a013ab6667 |
parent 191888 | 03d0a5fd13cf1e72d5755a6af6997bc5833497cb |
child 191890 | e71a17dfed283edbf39e5c2af287742bb6ae6c87 |
push id | 45685 |
push user | cbook@mozilla.com |
push date | Wed, 02 Jul 2014 13:09:48 +0000 |
treeherder | mozilla-inbound@60133a85f8ae [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | dhylands |
bugs | 964154 |
milestone | 33.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
|
--- a/hal/Hal.cpp +++ b/hal/Hal.cpp @@ -1234,10 +1234,16 @@ GetTotalSystemMemory() } uint32_t GetTotalSystemMemoryLevel() { return hal_impl::GetTotalSystemMemoryLevel(); } +bool IsHeadphoneEventFromInputDev() +{ + AssertMainThread(); + RETURN_PROXY_IF_SANDBOXED(IsHeadphoneEventFromInputDev(), false); +} + } // namespace hal } // namespace mozilla
--- a/hal/Hal.h +++ b/hal/Hal.h @@ -611,16 +611,21 @@ uint32_t GetTotalSystemMemory(); /** * Get the level of total system memory on device in MiB. * (round the value up to the next power of two) * * Returns 0 if we are unable to determine this information from /proc/meminfo. */ uint32_t GetTotalSystemMemoryLevel(); +/** + * Determine whether the headphone switch event is from input device + */ +bool IsHeadphoneEventFromInputDev(); + } // namespace MOZ_HAL_NAMESPACE } // namespace mozilla #ifdef MOZ_DEFINED_HAL_NAMESPACE # undef MOZ_DEFINED_HAL_NAMESPACE # undef MOZ_HAL_NAMESPACE #endif
--- a/hal/fallback/FallbackSwitch.cpp +++ b/hal/fallback/FallbackSwitch.cpp @@ -25,10 +25,15 @@ GetCurrentSwitchState(SwitchDevice aDevi return SWITCH_STATE_UNKNOWN; } void NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState) { } +bool IsHeadphoneEventFromInputDev() +{ + return false; +} + } // namespace hal_impl } // namespace mozilla
--- a/hal/gonk/GonkSwitch.cpp +++ b/hal/gonk/GonkSwitch.cpp @@ -12,17 +12,16 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <android/log.h> #include <fcntl.h> #include <sysutils/NetlinkEvent.h> -#include <cutils/properties.h> #include "base/message_loop.h" #include "Hal.h" #include "mozilla/FileUtils.h" #include "mozilla/RefPtr.h" #include "mozilla/Monitor.h" #include "nsPrintfCString.h" @@ -235,17 +234,19 @@ class SwitchEventObserver MOZ_FINAL : pu { ~SwitchEventObserver() { mHandler.Clear(); } public: NS_INLINE_DECL_REFCOUNTING(SwitchEventObserver) - SwitchEventObserver() : mEnableCount(0) + SwitchEventObserver() + : mEnableCount(0), + mHeadphonesFromInputDev(false) { Init(); } int GetEnableCount() { return mEnableCount; } @@ -304,41 +305,50 @@ public: void NotifyAnEvent(SwitchDevice aDevice) { EventInfo& info = mEventInfo[aDevice]; if (info.mEvent.status() != SWITCH_STATE_UNKNOWN) { NS_DispatchToMainThread(new SwitchEventRunnable(info.mEvent)); } } + + bool GetHeadphonesFromInputDev() + { + return mHeadphonesFromInputDev; + } + private: class EventInfo { public: EventInfo() : mEnabled(false) { mEvent.status() = SWITCH_STATE_UNKNOWN; mEvent.device() = SWITCH_DEVICE_UNKNOWN; } SwitchEvent mEvent; bool mEnabled; }; 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. mEventInfo[SWITCH_HEADPHONES].mEvent.device() = SWITCH_HEADPHONES; mEventInfo[SWITCH_HEADPHONES].mEvent.status() = SWITCH_STATE_OFF; } mHandler.AppendElement(new SwitchHandler(SWITCH_USB_DEVPATH_GB, SWITCH_USB)); mHandler.AppendElement(new SwitchHandlerUsbIcs(SWITCH_USB_DEVPATH_ICS)); @@ -453,10 +463,17 @@ NotifySwitchStateIOThread(SwitchDevice a void NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState) { InitializeResourceIfNeed(); XRE_GetIOMessageLoop()->PostTask( FROM_HERE, NewRunnableFunction(NotifySwitchStateIOThread, aDevice, aState)); } + +bool IsHeadphoneEventFromInputDev() +{ + InitializeResourceIfNeed(); + return sSwitchObserver->GetHeadphonesFromInputDev(); +} + } // hal_impl } //mozilla
--- a/hal/sandbox/SandboxHal.cpp +++ b/hal/sandbox/SandboxHal.cpp @@ -438,16 +438,22 @@ StartDiskSpaceWatcher() } void 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 , public ISensorObserver , public WakeLockObserver , public ScreenConfigurationObserver , public SwitchObserver , public SystemClockChangeObserver
--- a/widget/gonk/nsAppShell.cpp +++ b/widget/gonk/nsAppShell.cpp @@ -57,17 +57,16 @@ #include "nsWindow.h" #include "OrientationObserver.h" #include "GonkMemoryPressureMonitoring.h" #include "android/log.h" #include "libui/EventHub.h" #include "libui/InputReader.h" #include "libui/InputDispatcher.h" -#include "cutils/properties.h" #ifdef MOZ_NUWA_PROCESS #include "ipc/Nuwa.h" #endif #include "mozilla/Preferences.h" #include "GeckoProfiler.h" @@ -1047,19 +1046,17 @@ nsAppShell::Exit() obsServ->RemoveObserver(this, "network-connection-state-changed"); } return nsBaseAppShell::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; mEventHub = new EventHub(); mReaderPolicy = new GeckoInputReaderPolicy(); mReaderPolicy->setDisplayInfo(); mDispatcher = new GeckoInputDispatcher(mEventHub);