hal/android/AndroidHal.cpp
author Mike Hommey <mh+mozilla@glandium.org>
Thu, 24 Mar 2016 18:55:05 +0900
changeset 328798 bd956b7718c96998ed80143b0f77a7f0a1f87281
parent 292316 a6c8af1c08d4d2de320596c5040183d30914af79
child 346045 684888aeee810cbf3ab28acdd4edb8e92d6cbc59
permissions -rw-r--r--
Bug 1259381 - Don't add --with-ccache in mozconfigs doing --disable-compile-environment or --enable-artifact-builds. r=chmanchester While moving the ccache flag, we're going to make it disappear when the compiler environment is not enabled, so adding --with-ccache will fail.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "Hal.h"
#include "HalImpl.h"
#include "WindowIdentifier.h"
#include "AndroidBridge.h"
#include "mozilla/dom/network/Constants.h"
#include "mozilla/dom/ScreenOrientation.h"
#include "nsIScreenManager.h"
#include "nsServiceManagerUtils.h"

using namespace mozilla::dom;
using namespace mozilla::hal;

namespace mozilla {
namespace hal_impl {

void
Vibrate(const nsTArray<uint32_t> &pattern, const WindowIdentifier &)
{
  // Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate,
  // hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same
  // signature.

  // Strangely enough, the Android Java API seems to treat vibrate([0]) as a
  // nop.  But we want to treat vibrate([0]) like CancelVibrate!  (Note that we
  // also need to treat vibrate([]) as a call to CancelVibrate.)
  bool allZero = true;
  for (uint32_t i = 0; i < pattern.Length(); i++) {
    if (pattern[i] != 0) {
      allZero = false;
      break;
    }
  }

  if (allZero) {
    hal_impl::CancelVibrate(WindowIdentifier());
    return;
  }

  AndroidBridge* b = AndroidBridge::Bridge();
  if (!b) {
    return;
  }

  b->Vibrate(pattern);
}

void
CancelVibrate(const WindowIdentifier &)
{
  // Ignore WindowIdentifier parameter.

  mozilla::widget::GeckoAppShell::CancelVibrate();
}

void
EnableBatteryNotifications()
{
  mozilla::widget::GeckoAppShell::EnableBatteryNotifications();
}

void
DisableBatteryNotifications()
{
  mozilla::widget::GeckoAppShell::DisableBatteryNotifications();
}

void
GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
{
  AndroidBridge::Bridge()->GetCurrentBatteryInformation(aBatteryInfo);
}

void
EnableNetworkNotifications()
{
  mozilla::widget::GeckoAppShell::EnableNetworkNotifications();
}

void
DisableNetworkNotifications()
{
  mozilla::widget::GeckoAppShell::DisableNetworkNotifications();
}

void
GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
{
  AndroidBridge::Bridge()->GetCurrentNetworkInformation(aNetworkInfo);
}

void
EnableScreenConfigurationNotifications()
{
  mozilla::widget::GeckoAppShell::EnableScreenOrientationNotifications();
}

void
DisableScreenConfigurationNotifications()
{
  mozilla::widget::GeckoAppShell::DisableScreenOrientationNotifications();
}

void
GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
{
  AndroidBridge* bridge = AndroidBridge::Bridge();
  if (!bridge) {
    return;
  }

  nsresult rv;
  nsCOMPtr<nsIScreenManager> screenMgr =
    do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
  if (NS_FAILED(rv)) {
    NS_ERROR("Can't find nsIScreenManager!");
    return;
  }

  nsIntRect rect;
  int32_t colorDepth, pixelDepth;
  int16_t angle;
  ScreenOrientationInternal orientation;
  nsCOMPtr<nsIScreen> screen;

  screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
  screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
  screen->GetColorDepth(&colorDepth);
  screen->GetPixelDepth(&pixelDepth);
  orientation = static_cast<ScreenOrientationInternal>(bridge->GetScreenOrientation());
  angle = bridge->GetScreenAngle();

  *aScreenConfiguration =
    hal::ScreenConfiguration(rect, orientation, angle, colorDepth, pixelDepth);
}

bool
LockScreenOrientation(const ScreenOrientationInternal& aOrientation)
{
  // Force the default orientation to be portrait-primary.
  ScreenOrientationInternal orientation =
    aOrientation == eScreenOrientation_Default ? eScreenOrientation_PortraitPrimary
                                               : aOrientation;

  switch (orientation) {
    // The Android backend only supports these orientations.
    case eScreenOrientation_PortraitPrimary:
    case eScreenOrientation_PortraitSecondary:
    case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary:
    case eScreenOrientation_LandscapePrimary:
    case eScreenOrientation_LandscapeSecondary:
    case eScreenOrientation_LandscapePrimary | eScreenOrientation_LandscapeSecondary:
    case eScreenOrientation_Default:
      mozilla::widget::GeckoAppShell::LockScreenOrientation(orientation);
      return true;
    default:
      return false;
  }
}

void
UnlockScreenOrientation()
{
  mozilla::widget::GeckoAppShell::UnlockScreenOrientation();
}

} // hal_impl
} // mozilla