|
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/. */ |
|
5 |
|
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" |
|
14 |
|
15 using namespace mozilla::dom; |
|
16 using namespace mozilla::hal; |
|
17 using namespace mozilla::widget::android; |
|
18 |
|
19 namespace mozilla { |
|
20 namespace hal_impl { |
|
21 |
|
22 void |
|
23 Vibrate(const nsTArray<uint32_t> &pattern, const WindowIdentifier &) |
|
24 { |
|
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. |
|
28 |
|
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; |
|
37 } |
|
38 } |
|
39 |
|
40 if (allZero) { |
|
41 hal_impl::CancelVibrate(WindowIdentifier()); |
|
42 return; |
|
43 } |
|
44 |
|
45 AndroidBridge* b = AndroidBridge::Bridge(); |
|
46 if (!b) { |
|
47 return; |
|
48 } |
|
49 |
|
50 b->Vibrate(pattern); |
|
51 } |
|
52 |
|
53 void |
|
54 CancelVibrate(const WindowIdentifier &) |
|
55 { |
|
56 // Ignore WindowIdentifier parameter. |
|
57 |
|
58 mozilla::widget::android::GeckoAppShell::CancelVibrate(); |
|
59 } |
|
60 |
|
61 void |
|
62 EnableBatteryNotifications() |
|
63 { |
|
64 mozilla::widget::android::GeckoAppShell::EnableBatteryNotifications(); |
|
65 } |
|
66 |
|
67 void |
|
68 DisableBatteryNotifications() |
|
69 { |
|
70 mozilla::widget::android::GeckoAppShell::DisableBatteryNotifications(); |
|
71 } |
|
72 |
|
73 void |
|
74 GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo) |
|
75 { |
|
76 AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo); |
|
77 } |
|
78 |
|
79 void |
|
80 EnableNetworkNotifications() |
|
81 { |
|
82 mozilla::widget::android::GeckoAppShell::EnableNetworkNotifications(); |
|
83 } |
|
84 |
|
85 void |
|
86 DisableNetworkNotifications() |
|
87 { |
|
88 mozilla::widget::android::GeckoAppShell::DisableNetworkNotifications(); |
|
89 } |
|
90 |
|
91 void |
|
92 GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo) |
|
93 { |
|
94 AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo); |
|
95 } |
|
96 |
|
97 void |
|
98 EnableScreenConfigurationNotifications() |
|
99 { |
|
100 mozilla::widget::android::GeckoAppShell::EnableScreenOrientationNotifications(); |
|
101 } |
|
102 |
|
103 void |
|
104 DisableScreenConfigurationNotifications() |
|
105 { |
|
106 mozilla::widget::android::GeckoAppShell::DisableScreenOrientationNotifications(); |
|
107 } |
|
108 |
|
109 void |
|
110 GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) |
|
111 { |
|
112 AndroidBridge* bridge = AndroidBridge::Bridge(); |
|
113 if (!bridge) { |
|
114 return; |
|
115 } |
|
116 |
|
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; |
|
123 } |
|
124 |
|
125 nsIntRect rect; |
|
126 int32_t colorDepth, pixelDepth; |
|
127 ScreenOrientation orientation; |
|
128 nsCOMPtr<nsIScreen> screen; |
|
129 |
|
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()); |
|
135 |
|
136 *aScreenConfiguration = |
|
137 hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth); |
|
138 } |
|
139 |
|
140 bool |
|
141 LockScreenOrientation(const ScreenOrientation& aOrientation) |
|
142 { |
|
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; |
|
156 } |
|
157 } |
|
158 |
|
159 void |
|
160 UnlockScreenOrientation() |
|
161 { |
|
162 mozilla::widget::android::GeckoAppShell::UnlockScreenOrientation(); |
|
163 } |
|
164 |
|
165 } // hal_impl |
|
166 } // mozilla |
|
167 |