зеркало из https://github.com/mozilla/gecko-dev.git
Bug 714358: System time change implementation, r=mounir
This commit is contained in:
Родитель
de8420fdc1
Коммит
9242ba9386
|
@ -8,5 +8,5 @@
|
|||
interface nsIDOMMozTimeManager : nsISupports
|
||||
{
|
||||
// jsval could be Date object or UTC seconds
|
||||
void set(in jsval time);
|
||||
[implicit_jscontext] void set(in jsval time);
|
||||
};
|
||||
|
|
21
hal/Hal.cpp
21
hal/Hal.cpp
|
@ -417,7 +417,28 @@ bool GetLight(LightType light, hal::LightConfiguration* aConfig)
|
|||
RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig));
|
||||
}
|
||||
|
||||
static ObserverList<SystemTimeChange> sSystemTimeObserver;
|
||||
|
||||
void
|
||||
RegisterSystemTimeChangeObserver(SystemTimeObserver *aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
sSystemTimeObserver.AddObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterSystemTimeChangeObserver(SystemTimeObserver *aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
sSystemTimeObserver.RemoveObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
NotifySystemTimeChange(const hal::SystemTimeChange& aReason)
|
||||
{
|
||||
sSystemTimeObserver.Broadcast(aReason);
|
||||
}
|
||||
|
||||
void
|
||||
AdjustSystemClock(int32_t aDeltaMilliseconds)
|
||||
{
|
||||
|
|
20
hal/Hal.h
20
hal/Hal.h
|
@ -50,6 +50,8 @@ class WindowIdentifier;
|
|||
extern PRLogModuleInfo *sHalLog;
|
||||
#define HAL_LOG(msg) PR_LOG(mozilla::hal::sHalLog, PR_LOG_DEBUG, msg)
|
||||
|
||||
typedef Observer<SystemTimeChange> SystemTimeObserver;
|
||||
|
||||
} // namespace hal
|
||||
|
||||
namespace MOZ_HAL_NAMESPACE {
|
||||
|
@ -249,6 +251,24 @@ void AdjustSystemClock(int32_t aDeltaMilliseconds);
|
|||
*/
|
||||
void SetTimezone(const nsCString& aTimezoneSpec);
|
||||
|
||||
/**
|
||||
* Register observer for system time changed notification.
|
||||
* @param aObserver The observer that should be added.
|
||||
*/
|
||||
void RegisterSystemTimeChangeObserver(hal::SystemTimeObserver *aObserver);
|
||||
|
||||
/**
|
||||
* Unregister the observer for system time changed.
|
||||
* @param aObserver The observer that should be removed.
|
||||
*/
|
||||
void UnregisterSystemTimeChangeObserver(hal::SystemTimeObserver *aObserver);
|
||||
|
||||
/**
|
||||
* Notify of a change in the system cloeck or time zone.
|
||||
* @param aReason
|
||||
*/
|
||||
void NotifySystemTimeChange(const hal::SystemTimeChange& aReason);
|
||||
|
||||
/**
|
||||
* Reboot the device.
|
||||
*/
|
||||
|
|
|
@ -71,6 +71,13 @@ enum WakeLockControl {
|
|||
WAKE_LOCK_ADD_ONE = 1,
|
||||
};
|
||||
|
||||
enum SystemTimeChange {
|
||||
SYS_TIME_CHANGE_UNKNOWN = -1,
|
||||
SYS_TIME_CHANGE_CLOCK,
|
||||
SYS_TIME_CHANGE_TZ,
|
||||
SYS_TIME_CHANGE_GUARD
|
||||
};
|
||||
|
||||
} // namespace hal
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -143,7 +150,16 @@ struct ParamTraits<mozilla::hal::ProcessPriority>:
|
|||
mozilla::hal::NUM_PROCESS_PRIORITY> {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* SystemTimeChange serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::hal::SystemTimeChange>
|
||||
: public EnumSerializer<mozilla::hal::SystemTimeChange,
|
||||
mozilla::hal::SYS_TIME_CHANGE_UNKNOWN,
|
||||
mozilla::hal::SYS_TIME_CHANGE_GUARD>
|
||||
{};
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_hal_Types_h
|
||||
|
|
|
@ -581,6 +581,10 @@ sys_clock_settime(clockid_t clk_id, const struct timespec *tp)
|
|||
void
|
||||
AdjustSystemClock(int32_t aDeltaMilliseconds)
|
||||
{
|
||||
if (aDeltaMilliseconds == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct timespec now;
|
||||
|
||||
// Preventing context switch before setting system clock
|
||||
|
@ -600,16 +604,34 @@ AdjustSystemClock(int32_t aDeltaMilliseconds)
|
|||
now.tv_sec -= 1;
|
||||
}
|
||||
// we need to have root privilege.
|
||||
sys_clock_settime(CLOCK_REALTIME, &now);
|
||||
if (sys_clock_settime(CLOCK_REALTIME, &now) != 0) {
|
||||
NS_ERROR("sys_clock_settime failed");
|
||||
return;
|
||||
}
|
||||
|
||||
hal::NotifySystemTimeChange(hal::SYS_TIME_CHANGE_CLOCK);
|
||||
}
|
||||
|
||||
bool
|
||||
IsSameTimeZone(const nsCString& aTimezoneSpec)
|
||||
{
|
||||
char timezone[32];
|
||||
property_get("persist.sys.timezone", timezone, "");
|
||||
return aTimezoneSpec.EqualsASCII(timezone);
|
||||
}
|
||||
|
||||
void
|
||||
SetTimezone(const nsCString& aTimezoneSpec)
|
||||
{
|
||||
if (IsSameTimeZone(aTimezoneSpec)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
hal::NotifySystemTimeChange(hal::SYS_TIME_CHANGE_TZ);
|
||||
}
|
||||
|
||||
// Nothing to do here. Gonk widgetry always listens for screen
|
||||
|
|
|
@ -24,6 +24,7 @@ using mozilla::hal::SwitchDevice;
|
|||
using mozilla::hal::ProcessPriority;
|
||||
using nsIntRect;
|
||||
using PRTime;
|
||||
using mozilla::hal::SystemTimeChange;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -86,6 +87,7 @@ child:
|
|||
NotifyWakeLockChange(WakeLockInformation aWakeLockInfo);
|
||||
NotifyScreenConfigurationChange(ScreenConfiguration aScreenOrientation);
|
||||
NotifySwitchChange(SwitchEvent aEvent);
|
||||
NotifySystemTimeChange(SystemTimeChange aReason);
|
||||
|
||||
parent:
|
||||
Vibrate(uint32_t[] pattern, uint64_t[] id, PBrowser browser);
|
||||
|
|
|
@ -583,6 +583,11 @@ public:
|
|||
hal::SetProcessPriority(aPid, aPriority);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Notify(const SystemTimeChange& aReason)
|
||||
{
|
||||
unused << SendNotifySystemTimeChange(aReason);
|
||||
}
|
||||
};
|
||||
|
||||
class HalChild : public PHalChild {
|
||||
|
@ -619,6 +624,12 @@ public:
|
|||
hal::NotifySwitchChange(aEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool
|
||||
RecvNotifySystemTimeChange(const SystemTimeChange& aReason) {
|
||||
hal::NotifySystemTimeChange(aReason);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче