Bug 932698 - Hold a wakelock when we receive the powey key to wake up device. r=dhylands

This commit is contained in:
Viral Wang 2014-07-31 03:05:00 -04:00
Родитель f555dd078b
Коммит 12cb20a9ef
5 изменённых файлов: 63 добавлений и 0 удалений

Просмотреть файл

@ -68,6 +68,7 @@
#include "UeventPoller.h"
#include "nsIWritablePropertyBag2.h"
#include <algorithm>
#include "PowerWakeLock.h"
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
#define NsecPerMsec 1000000LL
@ -667,6 +668,7 @@ void
SetScreenEnabled(bool aEnabled)
{
GetGonkDisplay()->SetEnabled(aEnabled);
gPowerWakelock = nullptr;
sScreenEnabled = aEnabled;
}

Просмотреть файл

@ -0,0 +1,24 @@
/* -*- Mode: C++; tab-width: 40; 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 "PowerWakeLock.h"
#include <hardware_legacy/power.h>
const char* kPower_WAKE_LOCK_ID = "PowerKeyEvent";
namespace mozilla {
namespace hal_impl {
StaticRefPtr <PowerWakelock> gPowerWakelock;
PowerWakelock::PowerWakelock()
{
acquire_wake_lock(PARTIAL_WAKE_LOCK, kPower_WAKE_LOCK_ID);
}
PowerWakelock::~PowerWakelock()
{
release_wake_lock(kPower_WAKE_LOCK_ID);
}
} // hal_impl
} // mozilla

Просмотреть файл

@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 40; 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 __POWERWAKELOCK_H_
#define __POWERWAKELOCK_H_
#include "mozilla/StaticPtr.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace hal_impl {
class PowerWakelock
{
public:
NS_INLINE_DECL_REFCOUNTING(PowerWakelock);
PowerWakelock();
private:
~PowerWakelock();
};
extern StaticRefPtr <PowerWakelock> gPowerWakelock;
} // hal_impl
} // mozilla
#endif /* __POWERWAKELOCK_H_ */

Просмотреть файл

@ -51,6 +51,12 @@
#include <sys/limits.h>
#include <sha1.h>
#include "PowerWakeLock.h"
#include "mozilla/Hal.h"
using namespace mozilla;
using namespace mozilla::hal;
using namespace mozilla::hal_impl;
/* this macro is used to tell if "bit" is set in "array"
* it selects a byte from the array, and does a boolean AND
* operation with a byte that only has the relevant bit set.
@ -855,6 +861,10 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
event->type = iev.type;
event->code = iev.code;
event->value = iev.value;
if (event->code == KEY_POWER && event->value
&& !hal::GetScreenEnabled()) {
gPowerWakelock = new PowerWakelock();
}
event += 1;
capacity -= 1;
}

Просмотреть файл

@ -17,6 +17,7 @@
EXPORTS += [
'GonkPermission.h',
'OrientationObserver.h',
'PowerWakeLock.h',
]
DIRS += ['libdisplay', 'nativewindow']
@ -57,6 +58,7 @@ SOURCES += [
'nsWindow.cpp',
'OrientationObserver.cpp',
'ParentProcessController.cpp',
'PowerWakeLock.cpp',
'ProcessOrientation.cpp',
'WidgetTraceEvent.cpp'
]