Bug 717150: Support adjust system clock and set timezone APIs in hal layer r=cjones.

This commit is contained in:
Vincent Chang 2012-02-17 02:44:00 -08:00
parent 187b1c29ab
commit fc5a31fa0f
7 changed files with 135 additions and 1 deletions

View File

@ -323,6 +323,21 @@ bool GetLight(LightType light, hal::LightConfiguration* aConfig)
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig));
}
void
AdjustSystemClock(int32_t aDeltaMilliseconds)
{
AssertMainThread();
PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds));
}
void
SetTimezone(const nsCString& aTimezoneSpec)
{
AssertMainThread();
PROXY_IF_SANDBOXED(SetTimezone(aTimezoneSpec));
}
void
EnableSensorNotifications(SensorType aSensor) {
AssertMainThread();

View File

@ -217,6 +217,19 @@ void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
*/
void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
/**
* Adjusting system clock.
* @param aDeltaMilliseconds The difference compared with current system clock.
*/
void AdjustSystemClock(int32_t aDeltaMilliseconds);
/**
* Set timezone
* @param aTimezoneSpec The definition can be found in
* http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
*/
void SetTimezone(const nsCString& aTimezoneSpec);
/**
* Reboot the device.
*/

View File

@ -105,7 +105,7 @@ CPPSRCS += \
endif
ifneq (gonk,$(MOZ_WIDGET_TOOLKIT)) #{
CPPSRCS += FallbackLights.cpp
CPPSRCS += FallbackLights.cpp FallbackTime.cpp
endif #}
include $(topsrcdir)/config/config.mk

View File

@ -0,0 +1,22 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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"
namespace mozilla {
namespace hal_impl {
void
AdjustSystemClock(int32_t aDeltaMilliseconds)
{}
void
SetTimezone(const nsCString& aTimezoneSpec)
{}
} // namespace hal_impl
} // namespace mozilla

View File

@ -26,7 +26,16 @@
#include <math.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <sys/syscall.h>
#include <cutils/properties.h>
#include "mozilla/dom/network/Constants.h"
#include <android/log.h>
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
#define NsecPerMsec 1000000
#define NsecPerSec 1000000000
using mozilla::hal::WindowIdentifier;
@ -510,6 +519,52 @@ GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
return true;
}
/**
* clock_settime() is not exposed through bionic.
* we define the new function to set system time.
* The result is the same as using clock_settime() system call.
*/
static int
sys_clock_settime(clockid_t clk_id, const struct timespec *tp)
{
return syscall(__NR_clock_settime, clk_id, tp);
}
void
AdjustSystemClock(int32_t aDeltaMilliseconds)
{
struct timespec now;
// Preventing context switch before setting system clock
sched_yield();
clock_gettime(CLOCK_REALTIME, &now);
now.tv_sec += aDeltaMilliseconds/1000;
now.tv_nsec += (aDeltaMilliseconds%1000)*NsecPerMsec;
if (now.tv_nsec >= NsecPerSec)
{
now.tv_sec += 1;
now.tv_nsec -= NsecPerSec;
}
if (now.tv_nsec < 0)
{
now.tv_nsec += NsecPerSec;
now.tv_sec -= 1;
}
// we need to have root privilege.
sys_clock_settime(CLOCK_REALTIME, &now);
}
void
SetTimezone(const nsCString& aTimezoneSpec)
{
property_set("persist.sys.timezone", aTimezoneSpec.get());
// this function is automatically called by the other time conversion
// functions that depend on the timezone. To be safe, we call it manually.
tzset();
}
void
EnableNetworkNotifications()
{}

View File

@ -109,6 +109,9 @@ parent:
sync GetScreenBrightness() returns (double brightness);
SetScreenBrightness(double brightness);
AdjustSystemClock(int32 aDeltaMilliseconds);
SetTimezone(nsCString aTimezoneSpec);
sync SetLight(LightType light, LightConfiguration aConfig)
returns (bool status);

View File

@ -135,6 +135,18 @@ GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
return status;
}
void
AdjustSystemClock(int32_t aDeltaMilliseconds)
{
Hal()->SendAdjustSystemClock(aDeltaMilliseconds);
}
void
SetTimezone(const nsCString& aTimezoneSpec)
{
Hal()->SendSetTimezone(nsCString(aTimezoneSpec));
}
void
Reboot()
{
@ -288,6 +300,20 @@ public:
return true;
}
NS_OVERRIDE virtual bool
RecvAdjustSystemClock(const int32_t &aDeltaMilliseconds)
{
hal::AdjustSystemClock(aDeltaMilliseconds);
return true;
}
NS_OVERRIDE virtual bool
RecvSetTimezone(const nsCString& aTimezoneSpec)
{
hal::SetTimezone(aTimezoneSpec);
return true;
}
NS_OVERRIDE virtual bool
RecvReboot()
{