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-05-09 01:36:07 +04:00
|
|
|
#include "nsIScreenManager.h"
|
2018-08-29 23:54:56 +03:00
|
|
|
#include "nsPIDOMWindow.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
|
|
|
|
2016-07-21 20:49:04 +03:00
|
|
|
namespace java = mozilla::java;
|
|
|
|
|
2011-11-02 19:28:26 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace hal_impl {
|
|
|
|
|
2012-05-25 11:18:30 +04:00
|
|
|
void 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.
|
|
|
|
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoAppShell::CancelVibrate();
|
2011-09-30 11:00:48 +04:00
|
|
|
}
|
2011-11-02 19:28:26 +04:00
|
|
|
|
|
|
|
void EnableBatteryNotifications() {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoAppShell::EnableBatteryNotifications();
|
2011-11-02 19:35:11 +04:00
|
|
|
}
|
2011-11-02 19:28:26 +04:00
|
|
|
|
|
|
|
void DisableBatteryNotifications() {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::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() {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoAppShell::EnableNetworkNotifications();
|
2012-01-16 18:01:07 +04:00
|
|
|
}
|
2012-01-16 17:39:57 +04:00
|
|
|
|
|
|
|
void DisableNetworkNotifications() {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::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-05-09 01:36:07 +04:00
|
|
|
void EnableScreenConfigurationNotifications() {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoAppShell::EnableScreenOrientationNotifications();
|
2012-03-20 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
void DisableScreenConfigurationNotifications() {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoAppShell::DisableScreenOrientationNotifications();
|
2012-03-20 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
void 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;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t colorDepth, pixelDepth;
|
2015-08-19 00:55:15 +03:00
|
|
|
int16_t angle;
|
2019-05-16 23:31:13 +03:00
|
|
|
hal::ScreenOrientation orientation;
|
2012-05-09 01:36:07 +04:00
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
|
2018-01-10 19:17:58 +03:00
|
|
|
int32_t rectX, rectY, rectWidth, rectHeight;
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
2018-09-07 17:47:51 +03:00
|
|
|
|
2018-01-10 19:17:58 +03:00
|
|
|
screen->GetRect(&rectX, &rectY, &rectWidth, &rectHeight);
|
2012-05-09 01:36:07 +04:00
|
|
|
screen->GetColorDepth(&colorDepth);
|
|
|
|
screen->GetPixelDepth(&pixelDepth);
|
2019-05-16 23:31:13 +03:00
|
|
|
orientation =
|
2019-05-25 20:46:15 +03:00
|
|
|
static_cast<hal::ScreenOrientation>(bridge->GetScreenOrientation());
|
2015-08-19 00:55:15 +03:00
|
|
|
angle = bridge->GetScreenAngle();
|
2012-05-09 01:36:07 +04:00
|
|
|
|
|
|
|
*aScreenConfiguration =
|
2018-01-10 19:17:58 +03:00
|
|
|
hal::ScreenConfiguration(nsIntRect(rectX, rectY, rectWidth, rectHeight),
|
|
|
|
orientation, angle, colorDepth, pixelDepth);
|
2012-03-20 17:09:45 +04:00
|
|
|
}
|
|
|
|
|
2019-05-16 23:31:13 +03:00
|
|
|
bool LockScreenOrientation(const hal::ScreenOrientation& aOrientation) {
|
2015-08-25 23:42:24 +03:00
|
|
|
// Force the default orientation to be portrait-primary.
|
2019-05-16 23:31:13 +03:00
|
|
|
hal::ScreenOrientation orientation =
|
|
|
|
aOrientation == eScreenOrientation_Default
|
|
|
|
? eScreenOrientation_PortraitPrimary
|
|
|
|
: aOrientation;
|
2015-08-25 23:42:24 +03:00
|
|
|
|
|
|
|
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:
|
2016-07-21 20:49:04 +03:00
|
|
|
java::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() {
|
2016-07-21 20:49:04 +03:00
|
|
|
java::GeckoAppShell::UnlockScreenOrientation();
|
2012-03-29 23:43:16 +04:00
|
|
|
}
|
|
|
|
|
2011-11-02 19:28:26 +04:00
|
|
|
} // namespace hal_impl
|
|
|
|
} // namespace mozilla
|