Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / hal / android / AndroidHal.cpp
blobdf0eebdebe8badbf52ca825e4e6f8f517ca05928
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/. */
6 #include "Hal.h"
7 #include "HalImpl.h"
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;
19 namespace mozilla {
20 namespace hal_impl {
22 void
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
27 // signature.
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.)
32 bool allZero = true;
33 for (uint32_t i = 0; i < pattern.Length(); i++) {
34 if (pattern[i] != 0) {
35 allZero = false;
36 break;
40 if (allZero) {
41 hal_impl::CancelVibrate(WindowIdentifier());
42 return;
45 AndroidBridge* b = AndroidBridge::Bridge();
46 if (!b) {
47 return;
50 b->Vibrate(pattern);
53 void
54 CancelVibrate(const WindowIdentifier &)
56 // Ignore WindowIdentifier parameter.
58 mozilla::widget::android::GeckoAppShell::CancelVibrate();
61 void
62 EnableBatteryNotifications()
64 mozilla::widget::android::GeckoAppShell::EnableBatteryNotifications();
67 void
68 DisableBatteryNotifications()
70 mozilla::widget::android::GeckoAppShell::DisableBatteryNotifications();
73 void
74 GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
76 AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo);
79 void
80 EnableNetworkNotifications()
82 mozilla::widget::android::GeckoAppShell::EnableNetworkNotifications();
85 void
86 DisableNetworkNotifications()
88 mozilla::widget::android::GeckoAppShell::DisableNetworkNotifications();
91 void
92 GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
94 AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo);
97 void
98 EnableScreenConfigurationNotifications()
100 mozilla::widget::android::GeckoAppShell::EnableScreenOrientationNotifications();
103 void
104 DisableScreenConfigurationNotifications()
106 mozilla::widget::android::GeckoAppShell::DisableScreenOrientationNotifications();
109 void
110 GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
112 AndroidBridge* bridge = AndroidBridge::Bridge();
113 if (!bridge) {
114 return;
117 nsresult rv;
118 nsCOMPtr<nsIScreenManager> screenMgr =
119 do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
120 if (NS_FAILED(rv)) {
121 NS_ERROR("Can't find nsIScreenManager!");
122 return;
125 nsIntRect rect;
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);
140 bool
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);
153 return true;
154 default:
155 return false;
159 void
160 UnlockScreenOrientation()
162 mozilla::widget::android::GeckoAppShell::UnlockScreenOrientation();
165 } // hal_impl
166 } // mozilla