1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "WindowIdentifier.h"
9 #include "AndroidBridge.h"
10 #include "mozilla/dom/network/Constants.h"
11 #include "nsIScreenManager.h"
12 #include "nsPIDOMWindow.h"
13 #include "nsServiceManagerUtils.h"
15 using namespace mozilla::dom
;
16 using namespace mozilla::hal
;
18 namespace java
= mozilla::java
;
23 void Vibrate(const nsTArray
<uint32_t>& pattern
, const WindowIdentifier
&) {
24 // Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate,
25 // hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same
28 // Strangely enough, the Android Java API seems to treat vibrate([0]) as a
29 // nop. But we want to treat vibrate([0]) like CancelVibrate! (Note that we
30 // also need to treat vibrate([]) as a call to CancelVibrate.)
32 for (uint32_t i
= 0; i
< pattern
.Length(); i
++) {
33 if (pattern
[i
] != 0) {
40 hal_impl::CancelVibrate(WindowIdentifier());
44 AndroidBridge
* b
= AndroidBridge::Bridge();
52 void CancelVibrate(const WindowIdentifier
&) {
53 // Ignore WindowIdentifier parameter.
55 java::GeckoAppShell::CancelVibrate();
58 void EnableBatteryNotifications() {
59 java::GeckoAppShell::EnableBatteryNotifications();
62 void DisableBatteryNotifications() {
63 java::GeckoAppShell::DisableBatteryNotifications();
66 void GetCurrentBatteryInformation(hal::BatteryInformation
* aBatteryInfo
) {
67 AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo
);
70 void EnableNetworkNotifications() {
71 java::GeckoAppShell::EnableNetworkNotifications();
74 void DisableNetworkNotifications() {
75 java::GeckoAppShell::DisableNetworkNotifications();
78 void GetCurrentNetworkInformation(hal::NetworkInformation
* aNetworkInfo
) {
79 AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo
);
82 void EnableScreenConfigurationNotifications() {
83 java::GeckoAppShell::EnableScreenOrientationNotifications();
86 void DisableScreenConfigurationNotifications() {
87 java::GeckoAppShell::DisableScreenOrientationNotifications();
90 void GetCurrentScreenConfiguration(ScreenConfiguration
* aScreenConfiguration
) {
91 AndroidBridge
* bridge
= AndroidBridge::Bridge();
97 nsCOMPtr
<nsIScreenManager
> screenMgr
=
98 do_GetService("@mozilla.org/gfx/screenmanager;1", &rv
);
100 NS_ERROR("Can't find nsIScreenManager!");
104 int32_t colorDepth
, pixelDepth
;
106 ScreenOrientation orientation
;
107 nsCOMPtr
<nsIScreen
> screen
;
109 int32_t rectX
, rectY
, rectWidth
, rectHeight
;
111 screenMgr
->GetPrimaryScreen(getter_AddRefs(screen
));
113 screen
->GetRect(&rectX
, &rectY
, &rectWidth
, &rectHeight
);
114 screen
->GetColorDepth(&colorDepth
);
115 screen
->GetPixelDepth(&pixelDepth
);
116 orientation
= static_cast<ScreenOrientation
>(bridge
->GetScreenOrientation());
117 angle
= bridge
->GetScreenAngle();
119 *aScreenConfiguration
=
120 hal::ScreenConfiguration(nsIntRect(rectX
, rectY
, rectWidth
, rectHeight
),
121 orientation
, angle
, colorDepth
, pixelDepth
);
124 bool LockScreenOrientation(const ScreenOrientation
& aOrientation
) {
125 // Force the default orientation to be portrait-primary.
126 ScreenOrientation orientation
= aOrientation
== eScreenOrientation_Default
127 ? eScreenOrientation_PortraitPrimary
130 switch (orientation
) {
131 // The Android backend only supports these orientations.
132 case eScreenOrientation_PortraitPrimary
:
133 case eScreenOrientation_PortraitSecondary
:
134 case eScreenOrientation_PortraitPrimary
|
135 eScreenOrientation_PortraitSecondary
:
136 case eScreenOrientation_LandscapePrimary
:
137 case eScreenOrientation_LandscapeSecondary
:
138 case eScreenOrientation_LandscapePrimary
|
139 eScreenOrientation_LandscapeSecondary
:
140 case eScreenOrientation_Default
:
141 java::GeckoAppShell::LockScreenOrientation(orientation
);
148 void UnlockScreenOrientation() {
149 java::GeckoAppShell::UnlockScreenOrientation();
152 } // namespace hal_impl
153 } // namespace mozilla