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 "mozilla/dom/ScreenOrientation.h"
12 #include "nsIScreenManager.h"
13 #include "nsServiceManagerUtils.h"
15 using namespace mozilla::dom
;
16 using namespace mozilla::hal
;
17 using namespace mozilla::widget::android
;
23 Vibrate(const nsTArray
<uint32_t> &pattern
, const WindowIdentifier
&)
25 // Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate,
26 // hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same
29 // Strangely enough, the Android Java API seems to treat vibrate([0]) as a
30 // nop. But we want to treat vibrate([0]) like CancelVibrate! (Note that we
31 // also need to treat vibrate([]) as a call to CancelVibrate.)
33 for (uint32_t i
= 0; i
< pattern
.Length(); i
++) {
34 if (pattern
[i
] != 0) {
41 hal_impl::CancelVibrate(WindowIdentifier());
45 AndroidBridge
* b
= AndroidBridge::Bridge();
54 CancelVibrate(const WindowIdentifier
&)
56 // Ignore WindowIdentifier parameter.
58 mozilla::widget::android::GeckoAppShell::CancelVibrate();
62 EnableBatteryNotifications()
64 mozilla::widget::android::GeckoAppShell::EnableBatteryNotifications();
68 DisableBatteryNotifications()
70 mozilla::widget::android::GeckoAppShell::DisableBatteryNotifications();
74 GetCurrentBatteryInformation(hal::BatteryInformation
* aBatteryInfo
)
76 AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo
);
80 EnableNetworkNotifications()
82 mozilla::widget::android::GeckoAppShell::EnableNetworkNotifications();
86 DisableNetworkNotifications()
88 mozilla::widget::android::GeckoAppShell::DisableNetworkNotifications();
92 GetCurrentNetworkInformation(hal::NetworkInformation
* aNetworkInfo
)
94 AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo
);
98 EnableScreenConfigurationNotifications()
100 mozilla::widget::android::GeckoAppShell::EnableScreenOrientationNotifications();
104 DisableScreenConfigurationNotifications()
106 mozilla::widget::android::GeckoAppShell::DisableScreenOrientationNotifications();
110 GetCurrentScreenConfiguration(ScreenConfiguration
* aScreenConfiguration
)
112 AndroidBridge
* bridge
= AndroidBridge::Bridge();
118 nsCOMPtr
<nsIScreenManager
> screenMgr
=
119 do_GetService("@mozilla.org/gfx/screenmanager;1", &rv
);
121 NS_ERROR("Can't find nsIScreenManager!");
126 int32_t colorDepth
, pixelDepth
;
127 ScreenOrientation orientation
;
128 nsCOMPtr
<nsIScreen
> screen
;
130 screenMgr
->GetPrimaryScreen(getter_AddRefs(screen
));
131 screen
->GetRect(&rect
.x
, &rect
.y
, &rect
.width
, &rect
.height
);
132 screen
->GetColorDepth(&colorDepth
);
133 screen
->GetPixelDepth(&pixelDepth
);
134 orientation
= static_cast<ScreenOrientation
>(bridge
->GetScreenOrientation());
136 *aScreenConfiguration
=
137 hal::ScreenConfiguration(rect
, orientation
, colorDepth
, pixelDepth
);
141 LockScreenOrientation(const ScreenOrientation
& aOrientation
)
143 switch (aOrientation
) {
144 // The Android backend only supports these orientations.
145 case eScreenOrientation_PortraitPrimary
:
146 case eScreenOrientation_PortraitSecondary
:
147 case eScreenOrientation_PortraitPrimary
| eScreenOrientation_PortraitSecondary
:
148 case eScreenOrientation_LandscapePrimary
:
149 case eScreenOrientation_LandscapeSecondary
:
150 case eScreenOrientation_LandscapePrimary
| eScreenOrientation_LandscapeSecondary
:
151 case eScreenOrientation_Default
:
152 mozilla::widget::android::GeckoAppShell::LockScreenOrientation(aOrientation
);
160 UnlockScreenOrientation()
162 mozilla::widget::android::GeckoAppShell::UnlockScreenOrientation();