Back out entire dd28759eba7b push (bug 739913 and bug 742226) due to OSX 10.7 and b2g bustage. r=shouldausedtry

This commit is contained in:
Ryan VanderMeulen 2012-04-12 20:00:57 -04:00
parent d3faf91314
commit 0f578d67d8
15 changed files with 41 additions and 427 deletions

View File

@ -318,10 +318,6 @@ var shell = {
navigator.mozPower.screenEnabled = true;
}
}
if (topic == "cpu") {
navigator.mozPower.cpuSleepAllowed = (state != "locked-foreground" &&
state != "locked-background");
}
}
let idleTimeout = Services.prefs.getIntPref("power.screen.timeout");

View File

@ -236,27 +236,6 @@ PowerManager::SetScreenBrightness(double aBrightness)
return NS_OK;
}
NS_IMETHODIMP
PowerManager::GetCpuSleepAllowed(bool *aEnabled)
{
if (!CheckPermission()) {
*aEnabled = true;
return NS_OK;
}
*aEnabled = hal::GetCpuSleepAllowed();
return NS_OK;
}
NS_IMETHODIMP
PowerManager::SetCpuSleepAllowed(bool aEnabled)
{
NS_ENSURE_TRUE(CheckPermission(), NS_ERROR_DOM_SECURITY_ERR);
hal::SetCpuSleepAllowed(aEnabled);
return NS_OK;
}
} // power
} // dom
} // mozilla

View File

@ -42,7 +42,7 @@ interface nsIDOMMozWakeLockListener;
/**
* This interface implements navigator.mozPower
*/
[scriptable, uuid(256a3287-f528-45b5-9ba8-2b3650c056e6)]
[scriptable, uuid(4586bed1-cf78-4436-b503-88277d645b68)]
interface nsIDOMMozPowerManager : nsISupports
{
void powerOff();
@ -96,11 +96,4 @@ interface nsIDOMMozPowerManager : nsISupports
* @throw NS_ERROR_INVALID_ARG if brightness is not in the range [0, 1].
*/
attribute double screenBrightness;
/**
* Is it possible that the device's CPU will sleep after the screen is
* disabled? Setting this attribute to false will prevent the device
* entering suspend state.
*/
attribute boolean cpuSleepAllowed;
};

View File

@ -363,22 +363,6 @@ void SetScreenEnabled(bool enabled)
PROXY_IF_SANDBOXED(SetScreenEnabled(enabled));
}
bool GetCpuSleepAllowed()
{
// Generally for interfaces that are accessible by normal web content
// we should cache the result and be notified on state changes, like
// what the battery API does. But since this is only used by
// privileged interface, the synchronous getter is OK here.
AssertMainThread();
RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed());
}
void SetCpuSleepAllowed(bool enabled)
{
AssertMainThread();
PROXY_IF_SANDBOXED(SetCpuSleepAllowed(enabled));
}
double GetScreenBrightness()
{
AssertMainThread();

View File

@ -148,17 +148,6 @@ double GetScreenBrightness();
*/
void SetScreenBrightness(double brightness);
/**
* Determine whether the device is allowed to sleep.
*/
bool GetCpuSleepAllowed();
/**
* Set whether the device is allowed to suspend automatically after
* the screen is disabled.
*/
void SetCpuSleepAllowed(bool enabled);
/**
* Set the value of a light to a particular color, with a specific flash pattern.
* light specifices which light. See Hal.idl for the list of constants

View File

@ -84,7 +84,6 @@ CPPSRCS += \
GonkHal.cpp \
Power.cpp \
GonkSensor.cpp \
UeventPoller.cpp \
$(NULL)
else ifeq (Linux,$(OS_TARGET))
CPPSRCS += \

View File

@ -141,16 +141,6 @@ void
SetScreenBrightness(double brightness)
{}
bool
GetCpuSleepAllowed()
{
return true;
}
void
SetCpuSleepAllowed(bool enabled)
{}
void
EnableNetworkNotifications()
{

View File

@ -4,7 +4,6 @@
* 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 "base/message_loop.h"
#include "hardware_legacy/uevent.h"
#include "Hal.h"
#include "HalImpl.h"
@ -20,11 +19,9 @@
#include "nsIThread.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsXULAppAPI.h"
#include "hardware/lights.h"
#include "hardware/hardware.h"
#include "hardware_legacy/vibrator.h"
#include "UeventPoller.h"
#include <stdio.h>
#include <math.h>
#include <fcntl.h>
@ -199,74 +196,70 @@ public:
}
};
} // anonymous namespace
class BatteryObserver : public IUeventObserver,
public RefCounted<BatteryObserver>
{
class UEventWatcher : public nsRunnable {
public:
BatteryObserver()
:mUpdater(new BatteryUpdater())
UEventWatcher()
: mUpdater(new BatteryUpdater())
, mRunning(false)
{
}
virtual void Notify(const NetlinkEvent &aEvent)
NS_IMETHOD Run()
{
// this will run on IO thread
NetlinkEvent *event = const_cast<NetlinkEvent*>(&aEvent);
const char *subsystem = event->getSubsystem();
// e.g. DEVPATH=/devices/platform/sec-battery/power_supply/battery
const char *devpath = event->findParam("DEVPATH");
if (strcmp(subsystem, "power_supply") == 0 &&
strstr(devpath, "battery")) {
// aEvent will be valid only in this method.
while (mRunning) {
char buf[1024];
int count = uevent_next_event(buf, sizeof(buf) - 1);
if (!count) {
NS_WARNING("uevent_next_event() returned 0!");
continue;
}
buf[sizeof(buf) - 1] = 0;
if (strstr(buf, "battery"))
NS_DispatchToMainThread(mUpdater);
}
return NS_OK;
}
bool mRunning;
private:
nsRefPtr<BatteryUpdater> mUpdater;
};
// sBatteryObserver is owned by the IO thread. Only the IO thread may
// create or destroy it.
static BatteryObserver *sBatteryObserver = NULL;
} // anonymous namespace
static void
RegisterBatteryObserverIOThread()
{
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
MOZ_ASSERT(!sBatteryObserver);
sBatteryObserver = new BatteryObserver();
RegisterUeventListener(sBatteryObserver);
}
static bool sUEventInitialized = false;
static UEventWatcher *sWatcher = NULL;
static nsIThread *sWatcherThread = NULL;
void
EnableBatteryNotifications()
{
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE,
NewRunnableFunction(RegisterBatteryObserverIOThread));
}
if (!sUEventInitialized)
sUEventInitialized = uevent_init();
if (!sUEventInitialized) {
NS_WARNING("uevent_init() failed!");
return;
}
static void
UnregisterBatteryObserverIOThread()
{
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
MOZ_ASSERT(sBatteryObserver);
if (!sWatcher)
sWatcher = new UEventWatcher();
NS_ADDREF(sWatcher);
UnregisterUeventListener(sBatteryObserver);
delete sBatteryObserver;
sBatteryObserver = NULL;
sWatcher->mRunning = true;
nsresult rv = NS_NewThread(&sWatcherThread, sWatcher);
if (NS_FAILED(rv))
NS_WARNING("Failed to get new thread for uevent watching");
}
void
DisableBatteryNotifications()
{
XRE_GetIOMessageLoop()->PostTask(
FROM_HERE,
NewRunnableFunction(UnregisterBatteryObserverIOThread));
sWatcher->mRunning = false;
sWatcherThread->Shutdown();
NS_IF_RELEASE(sWatcherThread);
delete sWatcher;
}
void
@ -329,8 +322,6 @@ namespace {
* RAII class to help us remember to close file descriptors.
*/
const char *screenEnabledFilename = "/sys/power/state";
const char *wakeLockFilename = "/sys/power/wake_lock";
const char *wakeUnlockFilename = "/sys/power/wake_unlock";
template<ssize_t n>
bool ReadFromFile(const char *filename, char (&buf)[n])
@ -372,12 +363,6 @@ void WriteToFile(const char *filename, const char *toWrite)
// the screen is on or not.
bool sScreenEnabled = true;
// We can read wakeLockFilename to find out whether the cpu wake lock
// is already acquired, but reading and parsing it is a lot more work
// than tracking it ourselves, and it won't be accurate anyway (kernel
// internal wake locks aren't counted here.)
bool sCpuSleepAllowed = true;
} // anonymous namespace
bool
@ -430,19 +415,6 @@ SetScreenBrightness(double brightness)
hal::SetLight(hal::eHalLightID_Buttons, aConfig);
}
bool
GetCpuSleepAllowed()
{
return sCpuSleepAllowed;
}
void
SetCpuSleepAllowed(bool aAllowed)
{
WriteToFile(aAllowed ? wakeUnlockFilename : wakeLockFilename, "gecko");
sCpuSleepAllowed = aAllowed;
}
static light_device_t* sLights[hal::eHalLightID_Count]; // will be initialized to NULL
light_device_t* GetDevice(hw_module_t* module, char const* name)

View File

@ -1,198 +0,0 @@
/* -*- 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 <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <signal.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <linux/types.h>
#include <linux/netlink.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "base/message_loop.h"
#include "mozilla/FileUtils.h"
#include "nsAutoPtr.h"
#include "nsThreadUtils.h"
#include "nsXULAppAPI.h"
#include "UeventPoller.h"
namespace mozilla {
namespace hal_impl {
static void ShutdownUevent();
class NetlinkPoller : public MessageLoopForIO::Watcher
{
public:
NetlinkPoller() : mSocket(-1),
mIOLoop(MessageLoopForIO::current())
{
}
virtual ~NetlinkPoller() {}
bool OpenSocket();
virtual void OnFileCanReadWithoutBlocking(int fd);
// no writing to the netlink socket
virtual void OnFileCanWriteWithoutBlocking(int fd)
{
MOZ_NOT_REACHED("Must not write to netlink socket");
}
MessageLoopForIO *GetIOLoop () const { return mIOLoop; }
void RegisterObserver(IUeventObserver *aObserver)
{
mUeventObserverList.AddObserver(aObserver);
}
void UnregisterObserver(IUeventObserver *aObserver)
{
mUeventObserverList.RemoveObserver(aObserver);
if (mUeventObserverList.Length() == 0)
ShutdownUevent(); // this will destroy self
}
private:
ScopedClose mSocket;
MessageLoopForIO* mIOLoop;
MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
NetlinkEvent mNetlinkEvent;
const static int kBuffsize = 64 * 1024;
uint8_t mBuffer [kBuffsize];
typedef ObserverList<NetlinkEvent> UeventObserverList;
UeventObserverList mUeventObserverList;
};
bool
NetlinkPoller::OpenSocket()
{
mSocket.mFd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
if (mSocket.mFd < 0)
return false;
int sz = kBuffsize;
if (setsockopt(mSocket.mFd, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz)) < 0)
return false;
// add FD_CLOEXEC flag
int flags = fcntl(mSocket.mFd, F_GETFD);
if (flags == -1) {
return false;
}
flags |= FD_CLOEXEC;
if (fcntl(mSocket.mFd, F_SETFD, flags) == -1)
return false;
// set non-blocking
if (fcntl(mSocket.mFd, F_SETFL, O_NONBLOCK) == -1)
return false;
struct sockaddr_nl saddr;
bzero(&saddr, sizeof(saddr));
saddr.nl_family = AF_NETLINK;
saddr.nl_groups = 1;
saddr.nl_pid = getpid();
if (bind(mSocket.mFd, (struct sockaddr *)&saddr, sizeof(saddr)) == -1)
return false;
if (!mIOLoop->WatchFileDescriptor(mSocket.mFd,
true,
MessageLoopForIO::WATCH_READ,
&mReadWatcher,
this)) {
return false;
}
return true;
}
static nsAutoPtr<NetlinkPoller> sPoller;
class UeventInitTask : public Task
{
virtual void Run()
{
if (!sPoller) {
return;
}
if (sPoller->OpenSocket()) {
return;
}
sPoller->GetIOLoop()->PostDelayedTask(FROM_HERE, new UeventInitTask(), 1000);
}
};
void
NetlinkPoller::OnFileCanReadWithoutBlocking(int fd)
{
MOZ_ASSERT(fd == mSocket.mFd);
while (true) {
int ret = read(fd, mBuffer, kBuffsize);
if (ret == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return;
}
if (errno == EINTR) {
continue;
}
}
if (ret <= 0) {
// fatal error on netlink socket which should not happen
_exit(1);
}
mNetlinkEvent.decode(reinterpret_cast<char*>(mBuffer), ret);
mUeventObserverList.Broadcast(mNetlinkEvent);
}
}
static void
InitializeUevent()
{
MOZ_ASSERT(!sPoller);
sPoller = new NetlinkPoller();
sPoller->GetIOLoop()->PostTask(FROM_HERE, new UeventInitTask());
}
static void
ShutdownUevent()
{
sPoller = NULL;
}
void
RegisterUeventListener(IUeventObserver *aObserver)
{
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
if (!sPoller)
InitializeUevent();
sPoller->RegisterObserver(aObserver);
}
void
UnregisterUeventListener(IUeventObserver *aObserver)
{
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
sPoller->UnregisterObserver(aObserver);
}
} // hal_impl
} // mozilla

View File

@ -1,38 +0,0 @@
/* -*- 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/. */
#ifndef _mozilla_uevent_poller_h_
#define _mozilla_uevent_poller_h_
#include <sysutils/NetlinkEvent.h>
#include "mozilla/Observer.h"
class NetlinkEvent;
namespace mozilla {
namespace hal_impl {
typedef mozilla::Observer<NetlinkEvent> IUeventObserver;
/**
* Register for uevent notification. Note that the method should run on the
* <b> IO Thread </b>
* @aObserver the observer to be added. The observer's Notify() is only called
* on the <b> IO Thread </b>
*/
void RegisterUeventListener(IUeventObserver *aObserver);
/**
* Unregister for uevent notification. Note that the method should run on the
* <b> IO Thread </b>
* @aObserver the observer to be removed
*/
void UnregisterUeventListener(IUeventObserver *aObserver);
}
}
#endif

View File

@ -91,16 +91,6 @@ void
SetScreenBrightness(double brightness)
{}
bool
GetCpuSleepAllowed()
{
return true;
}
void
SetCpuSleepAllowed(bool enabled)
{}
void
EnableNetworkNotifications()
{}

View File

@ -120,9 +120,6 @@ parent:
sync GetScreenEnabled() returns (bool enabled);
SetScreenEnabled(bool enabled);
sync GetCpuSleepAllowed() returns (bool enabled);
SetCpuSleepAllowed(bool enabled);
sync GetScreenBrightness() returns (double brightness);
SetScreenBrightness(double brightness);

View File

@ -138,20 +138,6 @@ SetScreenEnabled(bool enabled)
Hal()->SendSetScreenEnabled(enabled);
}
bool
GetCpuSleepAllowed()
{
bool enabled = false;
Hal()->SendGetCpuSleepAllowed(&enabled);
return enabled;
}
void
SetCpuSleepAllowed(bool enabled)
{
Hal()->SendSetCpuSleepAllowed(enabled);
}
double
GetScreenBrightness()
{
@ -381,20 +367,6 @@ public:
return true;
}
NS_OVERRIDE virtual bool
RecvGetCpuSleepAllowed(bool *enabled)
{
*enabled = hal::GetCpuSleepAllowed();
return true;
}
NS_OVERRIDE virtual bool
RecvSetCpuSleepAllowed(const bool &enabled)
{
hal::SetCpuSleepAllowed(enabled);
return true;
}
NS_OVERRIDE virtual bool
RecvGetScreenBrightness(double *brightness)
{

View File

@ -69,16 +69,6 @@ void
SetScreenBrightness(double brightness)
{}
bool
GetCpuSleepAllowed()
{
return true;
}
void
SetCpuSleepAllowed(bool enabled)
{}
void
EnableNetworkNotifications()
{}

View File

@ -395,7 +395,6 @@ OS_LIBS += \
-lhardware \
-lutils \
-lcutils \
-lsysutils \
-lcamera_client \
-lbinder \
-lsensorservice \