2011-11-02 19:28:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-02 19:28:26 +04:00
|
|
|
|
|
|
|
#include "Hal.h"
|
2011-12-18 01:04:51 +04:00
|
|
|
#include "HalImpl.h"
|
2011-12-18 01:04:26 +04:00
|
|
|
#include "WindowIdentifier.h"
|
2011-11-02 19:35:11 +04:00
|
|
|
#include "AndroidBridge.h"
|
2012-01-16 17:39:57 +04:00
|
|
|
#include "mozilla/dom/network/Constants.h"
|
2012-03-20 17:09:45 +04:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
2012-05-09 01:36:07 +04:00
|
|
|
#include "nsIScreenManager.h"
|
2013-09-11 00:56:05 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2011-11-02 19:28:26 +04:00
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::hal;
|
2011-09-30 11:00:48 +04:00
|
|
|
|
2011-11-02 19:28:26 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace hal_impl {
|
|
|
|
|
|
|
|
void
|
2012-05-25 11:18:30 +04:00
|
|
|
Vibrate(const nsTArray<uint32_t> &pattern, const WindowIdentifier &)
|
2011-09-30 11:00:48 +04:00
|
|
|
{
|
|
|
|
// Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate,
|
|
|
|
// hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same
|
|
|
|
// signature.
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
// Strangely enough, the Android Java API seems to treat vibrate([0]) as a
|
|
|
|
// nop. But we want to treat vibrate([0]) like CancelVibrate! (Note that we
|
|
|
|
// also need to treat vibrate([]) as a call to CancelVibrate.)
|
|
|
|
bool allZero = true;
|
2012-05-25 11:18:30 +04:00
|
|
|
for (uint32_t i = 0; i < pattern.Length(); i++) {
|
2011-11-11 01:26:36 +04:00
|
|
|
if (pattern[i] != 0) {
|
|
|
|
allZero = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allZero) {
|
|
|
|
hal_impl::CancelVibrate(WindowIdentifier());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
AndroidBridge* b = AndroidBridge::Bridge();
|
|
|
|
if (!b) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-11 01:26:36 +04:00
|
|
|
b->Vibrate(pattern);
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CancelVibrate(const WindowIdentifier &)
|
|
|
|
{
|
|
|
|
// Ignore WindowIdentifier parameter.
|
|
|
|
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::CancelVibrate();
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
2011-11-02 19:28:26 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
EnableBatteryNotifications()
|
2011-11-02 19:35:11 +04:00
|
|
|
{
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::EnableBatteryNotifications();
|
2011-11-02 19:35:11 +04:00
|
|
|
}
|
2011-11-02 19:28:26 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
DisableBatteryNotifications()
|
2011-11-02 19:35:11 +04:00
|
|
|
{
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::DisableBatteryNotifications();
|
2011-11-02 19:35:11 +04:00
|
|
|
}
|
2011-11-02 19:28:26 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
|
|
|
|
{
|
2013-11-12 22:41:01 +04:00
|
|
|
AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo);
|
2011-11-02 19:28:26 +04:00
|
|
|
}
|
|
|
|
|
2012-01-16 17:39:57 +04:00
|
|
|
void
|
|
|
|
EnableNetworkNotifications()
|
2012-01-16 18:01:07 +04:00
|
|
|
{
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::EnableNetworkNotifications();
|
2012-01-16 18:01:07 +04:00
|
|
|
}
|
2012-01-16 17:39:57 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
DisableNetworkNotifications()
|
2012-01-16 18:01:07 +04:00
|
|
|
{
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::DisableNetworkNotifications();
|
2012-01-16 18:01:07 +04:00
|
|
|
}
|
2012-01-16 17:39:57 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
|
|
|
|
{
|
2013-11-12 22:41:01 +04:00
|
|
|
AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo);
|
2012-01-16 17:39:57 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 17:09:45 +04:00
|
|
|
void
|
2012-05-09 01:36:07 +04:00
|
|
|
EnableScreenConfigurationNotifications()
|
2012-03-20 17:09:45 +04:00
|
|
|
{
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::EnableScreenOrientationNotifications();
|
2012-03-20 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-09 01:36:07 +04:00
|
|
|
DisableScreenConfigurationNotifications()
|
2012-03-20 17:09:45 +04:00
|
|
|
{
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::DisableScreenOrientationNotifications();
|
2012-03-20 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-09 01:36:07 +04:00
|
|
|
GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
|
2012-03-20 17:09:45 +04:00
|
|
|
{
|
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIScreenManager> screenMgr =
|
|
|
|
do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Can't find nsIScreenManager!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect rect;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t colorDepth, pixelDepth;
|
2015-08-19 00:55:15 +03:00
|
|
|
int16_t angle;
|
2015-08-19 00:55:09 +03:00
|
|
|
ScreenOrientationInternal orientation;
|
2012-05-09 01:36:07 +04:00
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
|
|
|
|
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
|
|
|
|
screen->GetColorDepth(&colorDepth);
|
|
|
|
screen->GetPixelDepth(&pixelDepth);
|
2015-08-19 00:55:09 +03:00
|
|
|
orientation = static_cast<ScreenOrientationInternal>(bridge->GetScreenOrientation());
|
2015-08-19 00:55:15 +03:00
|
|
|
angle = bridge->GetScreenAngle();
|
2012-05-09 01:36:07 +04:00
|
|
|
|
|
|
|
*aScreenConfiguration =
|
2015-08-19 00:55:15 +03:00
|
|
|
hal::ScreenConfiguration(rect, orientation, angle, colorDepth, pixelDepth);
|
2012-03-20 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-29 23:43:16 +04:00
|
|
|
bool
|
2015-08-19 00:55:09 +03:00
|
|
|
LockScreenOrientation(const ScreenOrientationInternal& aOrientation)
|
2012-03-29 23:43:16 +04:00
|
|
|
{
|
2015-08-25 23:42:24 +03:00
|
|
|
// Force the default orientation to be portrait-primary.
|
|
|
|
ScreenOrientationInternal orientation =
|
|
|
|
aOrientation == eScreenOrientation_Default ? eScreenOrientation_PortraitPrimary
|
|
|
|
: aOrientation;
|
|
|
|
|
|
|
|
switch (orientation) {
|
2012-09-11 14:57:20 +04:00
|
|
|
// The Android backend only supports these orientations.
|
|
|
|
case eScreenOrientation_PortraitPrimary:
|
|
|
|
case eScreenOrientation_PortraitSecondary:
|
2012-09-19 20:28:16 +04:00
|
|
|
case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary:
|
2012-09-11 14:57:20 +04:00
|
|
|
case eScreenOrientation_LandscapePrimary:
|
|
|
|
case eScreenOrientation_LandscapeSecondary:
|
2012-09-19 20:28:16 +04:00
|
|
|
case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary:
|
2013-09-30 18:40:41 +04:00
|
|
|
case eScreenOrientation_Default:
|
2015-08-25 23:42:24 +03:00
|
|
|
mozilla::widget::GeckoAppShell::LockScreenOrientation(orientation);
|
2012-09-11 14:57:20 +04:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-29 23:43:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnlockScreenOrientation()
|
|
|
|
{
|
2015-01-10 03:33:57 +03:00
|
|
|
mozilla::widget::GeckoAppShell::UnlockScreenOrientation();
|
2012-03-29 23:43:16 +04:00
|
|
|
}
|
|
|
|
|
2011-11-02 19:28:26 +04:00
|
|
|
} // hal_impl
|
|
|
|
} // mozilla
|
|
|
|
|