michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "Hal.h" michael@0: #include "HalImpl.h" michael@0: #include "WindowIdentifier.h" michael@0: #include "AndroidBridge.h" michael@0: #include "mozilla/dom/network/Constants.h" michael@0: #include "mozilla/dom/ScreenOrientation.h" michael@0: #include "nsIScreenManager.h" michael@0: #include "nsServiceManagerUtils.h" michael@0: michael@0: using namespace mozilla::dom; michael@0: using namespace mozilla::hal; michael@0: using namespace mozilla::widget::android; michael@0: michael@0: namespace mozilla { michael@0: namespace hal_impl { michael@0: michael@0: void michael@0: Vibrate(const nsTArray &pattern, const WindowIdentifier &) michael@0: { michael@0: // Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate, michael@0: // hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same michael@0: // signature. michael@0: michael@0: // Strangely enough, the Android Java API seems to treat vibrate([0]) as a michael@0: // nop. But we want to treat vibrate([0]) like CancelVibrate! (Note that we michael@0: // also need to treat vibrate([]) as a call to CancelVibrate.) michael@0: bool allZero = true; michael@0: for (uint32_t i = 0; i < pattern.Length(); i++) { michael@0: if (pattern[i] != 0) { michael@0: allZero = false; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (allZero) { michael@0: hal_impl::CancelVibrate(WindowIdentifier()); michael@0: return; michael@0: } michael@0: michael@0: AndroidBridge* b = AndroidBridge::Bridge(); michael@0: if (!b) { michael@0: return; michael@0: } michael@0: michael@0: b->Vibrate(pattern); michael@0: } michael@0: michael@0: void michael@0: CancelVibrate(const WindowIdentifier &) michael@0: { michael@0: // Ignore WindowIdentifier parameter. michael@0: michael@0: mozilla::widget::android::GeckoAppShell::CancelVibrate(); michael@0: } michael@0: michael@0: void michael@0: EnableBatteryNotifications() michael@0: { michael@0: mozilla::widget::android::GeckoAppShell::EnableBatteryNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableBatteryNotifications() michael@0: { michael@0: mozilla::widget::android::GeckoAppShell::DisableBatteryNotifications(); michael@0: } michael@0: michael@0: void michael@0: GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo) michael@0: { michael@0: AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo); michael@0: } michael@0: michael@0: void michael@0: EnableNetworkNotifications() michael@0: { michael@0: mozilla::widget::android::GeckoAppShell::EnableNetworkNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableNetworkNotifications() michael@0: { michael@0: mozilla::widget::android::GeckoAppShell::DisableNetworkNotifications(); michael@0: } michael@0: michael@0: void michael@0: GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo) michael@0: { michael@0: AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo); michael@0: } michael@0: michael@0: void michael@0: EnableScreenConfigurationNotifications() michael@0: { michael@0: mozilla::widget::android::GeckoAppShell::EnableScreenOrientationNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableScreenConfigurationNotifications() michael@0: { michael@0: mozilla::widget::android::GeckoAppShell::DisableScreenOrientationNotifications(); michael@0: } michael@0: michael@0: void michael@0: GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) michael@0: { michael@0: AndroidBridge* bridge = AndroidBridge::Bridge(); michael@0: if (!bridge) { michael@0: return; michael@0: } michael@0: michael@0: nsresult rv; michael@0: nsCOMPtr screenMgr = michael@0: do_GetService("@mozilla.org/gfx/screenmanager;1", &rv); michael@0: if (NS_FAILED(rv)) { michael@0: NS_ERROR("Can't find nsIScreenManager!"); michael@0: return; michael@0: } michael@0: michael@0: nsIntRect rect; michael@0: int32_t colorDepth, pixelDepth; michael@0: ScreenOrientation orientation; michael@0: nsCOMPtr screen; michael@0: michael@0: screenMgr->GetPrimaryScreen(getter_AddRefs(screen)); michael@0: screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height); michael@0: screen->GetColorDepth(&colorDepth); michael@0: screen->GetPixelDepth(&pixelDepth); michael@0: orientation = static_cast(bridge->GetScreenOrientation()); michael@0: michael@0: *aScreenConfiguration = michael@0: hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth); michael@0: } michael@0: michael@0: bool michael@0: LockScreenOrientation(const ScreenOrientation& aOrientation) michael@0: { michael@0: switch (aOrientation) { michael@0: // The Android backend only supports these orientations. michael@0: case eScreenOrientation_PortraitPrimary: michael@0: case eScreenOrientation_PortraitSecondary: michael@0: case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary: michael@0: case eScreenOrientation_LandscapePrimary: michael@0: case eScreenOrientation_LandscapeSecondary: michael@0: case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary: michael@0: case eScreenOrientation_Default: michael@0: mozilla::widget::android::GeckoAppShell::LockScreenOrientation(aOrientation); michael@0: return true; michael@0: default: michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: void michael@0: UnlockScreenOrientation() michael@0: { michael@0: mozilla::widget::android::GeckoAppShell::UnlockScreenOrientation(); michael@0: } michael@0: michael@0: } // hal_impl michael@0: } // mozilla michael@0: