hal/android/AndroidHal.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/hal/android/AndroidHal.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,167 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "Hal.h"
    1.10 +#include "HalImpl.h"
    1.11 +#include "WindowIdentifier.h"
    1.12 +#include "AndroidBridge.h"
    1.13 +#include "mozilla/dom/network/Constants.h"
    1.14 +#include "mozilla/dom/ScreenOrientation.h"
    1.15 +#include "nsIScreenManager.h"
    1.16 +#include "nsServiceManagerUtils.h"
    1.17 +
    1.18 +using namespace mozilla::dom;
    1.19 +using namespace mozilla::hal;
    1.20 +using namespace mozilla::widget::android;
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace hal_impl {
    1.24 +
    1.25 +void
    1.26 +Vibrate(const nsTArray<uint32_t> &pattern, const WindowIdentifier &)
    1.27 +{
    1.28 +  // Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate,
    1.29 +  // hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same
    1.30 +  // signature.
    1.31 +
    1.32 +  // Strangely enough, the Android Java API seems to treat vibrate([0]) as a
    1.33 +  // nop.  But we want to treat vibrate([0]) like CancelVibrate!  (Note that we
    1.34 +  // also need to treat vibrate([]) as a call to CancelVibrate.)
    1.35 +  bool allZero = true;
    1.36 +  for (uint32_t i = 0; i < pattern.Length(); i++) {
    1.37 +    if (pattern[i] != 0) {
    1.38 +      allZero = false;
    1.39 +      break;
    1.40 +    }
    1.41 +  }
    1.42 +
    1.43 +  if (allZero) {
    1.44 +    hal_impl::CancelVibrate(WindowIdentifier());
    1.45 +    return;
    1.46 +  }
    1.47 +
    1.48 +  AndroidBridge* b = AndroidBridge::Bridge();
    1.49 +  if (!b) {
    1.50 +    return;
    1.51 +  }
    1.52 +
    1.53 +  b->Vibrate(pattern);
    1.54 +}
    1.55 +
    1.56 +void
    1.57 +CancelVibrate(const WindowIdentifier &)
    1.58 +{
    1.59 +  // Ignore WindowIdentifier parameter.
    1.60 +
    1.61 +  mozilla::widget::android::GeckoAppShell::CancelVibrate();
    1.62 +}
    1.63 +
    1.64 +void
    1.65 +EnableBatteryNotifications()
    1.66 +{
    1.67 +  mozilla::widget::android::GeckoAppShell::EnableBatteryNotifications();
    1.68 +}
    1.69 +
    1.70 +void
    1.71 +DisableBatteryNotifications()
    1.72 +{
    1.73 +  mozilla::widget::android::GeckoAppShell::DisableBatteryNotifications();
    1.74 +}
    1.75 +
    1.76 +void
    1.77 +GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
    1.78 +{
    1.79 +  AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo);
    1.80 +}
    1.81 +
    1.82 +void
    1.83 +EnableNetworkNotifications()
    1.84 +{
    1.85 +  mozilla::widget::android::GeckoAppShell::EnableNetworkNotifications();
    1.86 +}
    1.87 +
    1.88 +void
    1.89 +DisableNetworkNotifications()
    1.90 +{
    1.91 +  mozilla::widget::android::GeckoAppShell::DisableNetworkNotifications();
    1.92 +}
    1.93 +
    1.94 +void
    1.95 +GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
    1.96 +{
    1.97 +  AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo);
    1.98 +}
    1.99 +
   1.100 +void
   1.101 +EnableScreenConfigurationNotifications()
   1.102 +{
   1.103 +  mozilla::widget::android::GeckoAppShell::EnableScreenOrientationNotifications();
   1.104 +}
   1.105 +
   1.106 +void
   1.107 +DisableScreenConfigurationNotifications()
   1.108 +{
   1.109 +  mozilla::widget::android::GeckoAppShell::DisableScreenOrientationNotifications();
   1.110 +}
   1.111 +
   1.112 +void
   1.113 +GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
   1.114 +{
   1.115 +  AndroidBridge* bridge = AndroidBridge::Bridge();
   1.116 +  if (!bridge) {
   1.117 +    return;
   1.118 +  }
   1.119 +
   1.120 +  nsresult rv;
   1.121 +  nsCOMPtr<nsIScreenManager> screenMgr =
   1.122 +    do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
   1.123 +  if (NS_FAILED(rv)) {
   1.124 +    NS_ERROR("Can't find nsIScreenManager!");
   1.125 +    return;
   1.126 +  }
   1.127 +
   1.128 +  nsIntRect rect;
   1.129 +  int32_t colorDepth, pixelDepth;
   1.130 +  ScreenOrientation orientation;
   1.131 +  nsCOMPtr<nsIScreen> screen;
   1.132 +
   1.133 +  screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
   1.134 +  screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
   1.135 +  screen->GetColorDepth(&colorDepth);
   1.136 +  screen->GetPixelDepth(&pixelDepth);
   1.137 +  orientation = static_cast<ScreenOrientation>(bridge->GetScreenOrientation());
   1.138 +
   1.139 +  *aScreenConfiguration =
   1.140 +    hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth);
   1.141 +}
   1.142 +
   1.143 +bool
   1.144 +LockScreenOrientation(const ScreenOrientation& aOrientation)
   1.145 +{
   1.146 +  switch (aOrientation) {
   1.147 +    // The Android backend only supports these orientations.
   1.148 +    case eScreenOrientation_PortraitPrimary:
   1.149 +    case eScreenOrientation_PortraitSecondary:
   1.150 +    case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary:
   1.151 +    case eScreenOrientation_LandscapePrimary:
   1.152 +    case eScreenOrientation_LandscapeSecondary:
   1.153 +    case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary:
   1.154 +    case eScreenOrientation_Default:
   1.155 +      mozilla::widget::android::GeckoAppShell::LockScreenOrientation(aOrientation);
   1.156 +      return true;
   1.157 +    default:
   1.158 +      return false;
   1.159 +  }
   1.160 +}
   1.161 +
   1.162 +void
   1.163 +UnlockScreenOrientation()
   1.164 +{
   1.165 +  mozilla::widget::android::GeckoAppShell::UnlockScreenOrientation();
   1.166 +}
   1.167 +
   1.168 +} // hal_impl
   1.169 +} // mozilla
   1.170 +

mercurial