2011-11-02 08:28:26 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 08:28:26 -07:00
|
|
|
|
|
|
|
#include "Hal.h"
|
2011-12-17 13:04:51 -08:00
|
|
|
#include "HalImpl.h"
|
2011-12-17 13:04:26 -08:00
|
|
|
#include "WindowIdentifier.h"
|
2011-11-02 08:35:11 -07:00
|
|
|
#include "AndroidBridge.h"
|
2012-01-16 05:39:57 -08:00
|
|
|
#include "mozilla/dom/network/Constants.h"
|
2012-03-20 06:09:45 -07:00
|
|
|
#include "mozilla/dom/ScreenOrientation.h"
|
2012-05-08 14:36:07 -07:00
|
|
|
#include "nsIScreenManager.h"
|
2013-09-10 13:56:05 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2011-11-02 08:28:26 -07:00
|
|
|
|
2012-05-08 14:36:07 -07:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::hal;
|
2011-09-30 00:00:48 -07:00
|
|
|
|
2011-11-02 08:28:26 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace hal_impl {
|
|
|
|
|
|
|
|
void
|
2012-05-25 00:18:30 -07:00
|
|
|
Vibrate(const nsTArray<uint32_t> &pattern, const WindowIdentifier &)
|
2011-09-30 00:00:48 -07: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-10 13:26:36 -08: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 00:18:30 -07:00
|
|
|
for (uint32_t i = 0; i < pattern.Length(); i++) {
|
2011-11-10 13:26:36 -08:00
|
|
|
if (pattern[i] != 0) {
|
|
|
|
allZero = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allZero) {
|
|
|
|
hal_impl::CancelVibrate(WindowIdentifier());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-30 00:00:48 -07:00
|
|
|
AndroidBridge* b = AndroidBridge::Bridge();
|
|
|
|
if (!b) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:26:36 -08:00
|
|
|
b->Vibrate(pattern);
|
2011-09-30 00:00:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CancelVibrate(const WindowIdentifier &)
|
|
|
|
{
|
|
|
|
// Ignore WindowIdentifier parameter.
|
|
|
|
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* b = AndroidBridge::Bridge();
|
|
|
|
if (b)
|
|
|
|
b->CancelVibrate();
|
2011-09-30 00:00:48 -07:00
|
|
|
}
|
2011-11-02 08:28:26 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
EnableBatteryNotifications()
|
2011-11-02 08:35:11 -07:00
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->EnableBatteryNotifications();
|
2011-11-02 08:35:11 -07:00
|
|
|
}
|
2011-11-02 08:28:26 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
DisableBatteryNotifications()
|
2011-11-02 08:35:11 -07:00
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->DisableBatteryNotifications();
|
2011-11-02 08:35:11 -07:00
|
|
|
}
|
2011-11-02 08:28:26 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
|
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->GetCurrentBatteryInformation(aBatteryInfo);
|
2011-11-02 08:28:26 -07:00
|
|
|
}
|
|
|
|
|
2012-01-16 05:39:57 -08:00
|
|
|
void
|
|
|
|
EnableNetworkNotifications()
|
2012-01-16 06:01:07 -08:00
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->EnableNetworkNotifications();
|
2012-01-16 06:01:07 -08:00
|
|
|
}
|
2012-01-16 05:39:57 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
DisableNetworkNotifications()
|
2012-01-16 06:01:07 -08:00
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->DisableNetworkNotifications();
|
2012-01-16 06:01:07 -08:00
|
|
|
}
|
2012-01-16 05:39:57 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
|
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->GetCurrentNetworkInformation(aNetworkInfo);
|
2012-01-16 05:39:57 -08:00
|
|
|
}
|
|
|
|
|
2012-03-20 06:09:45 -07:00
|
|
|
void
|
2012-05-08 14:36:07 -07:00
|
|
|
EnableScreenConfigurationNotifications()
|
2012-03-20 06:09:45 -07:00
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->EnableScreenOrientationNotifications();
|
2012-03-20 06:09:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-08 14:36:07 -07:00
|
|
|
DisableScreenConfigurationNotifications()
|
2012-03-20 06:09:45 -07:00
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->DisableScreenOrientationNotifications();
|
2012-03-20 06:09:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-08 14:36:07 -07:00
|
|
|
GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
|
2012-03-20 06:09:45 -07:00
|
|
|
{
|
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-08 14:36:07 -07: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 08:56:38 -07:00
|
|
|
int32_t colorDepth, pixelDepth;
|
2012-05-08 14:36:07 -07:00
|
|
|
ScreenOrientation orientation;
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
|
|
|
|
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
|
|
|
|
screen->GetColorDepth(&colorDepth);
|
|
|
|
screen->GetPixelDepth(&pixelDepth);
|
|
|
|
orientation = static_cast<ScreenOrientation>(bridge->GetScreenOrientation());
|
|
|
|
|
|
|
|
*aScreenConfiguration =
|
|
|
|
hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth);
|
2012-03-20 06:09:45 -07:00
|
|
|
}
|
|
|
|
|
2012-03-29 12:43:16 -07:00
|
|
|
bool
|
2012-05-08 14:36:07 -07:00
|
|
|
LockScreenOrientation(const ScreenOrientation& aOrientation)
|
2012-03-29 12:43:16 -07:00
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-11 03:57:20 -07:00
|
|
|
switch (aOrientation) {
|
|
|
|
// The Android backend only supports these orientations.
|
|
|
|
case eScreenOrientation_PortraitPrimary:
|
|
|
|
case eScreenOrientation_PortraitSecondary:
|
2012-09-19 09:28:16 -07:00
|
|
|
case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary:
|
2012-09-11 03:57:20 -07:00
|
|
|
case eScreenOrientation_LandscapePrimary:
|
|
|
|
case eScreenOrientation_LandscapeSecondary:
|
2012-09-19 09:28:16 -07:00
|
|
|
case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary:
|
2013-09-30 07:40:41 -07:00
|
|
|
case eScreenOrientation_Default:
|
2013-11-19 07:56:09 -08:00
|
|
|
bridge->LockScreenOrientation(aOrientation);
|
2012-09-11 03:57:20 -07:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-29 12:43:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnlockScreenOrientation()
|
|
|
|
{
|
2013-11-19 07:56:09 -08:00
|
|
|
AndroidBridge* bridge = AndroidBridge::Bridge();
|
|
|
|
if (!bridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge->UnlockScreenOrientation();
|
2012-03-29 12:43:16 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 08:28:26 -07:00
|
|
|
} // hal_impl
|
|
|
|
} // mozilla
|
|
|
|
|