2011-12-20 11:31:53 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et ft=cpp : */
|
2012-07-20 02:10:44 -07:00
|
|
|
/* Copyright 2012 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-05-08 14:36:07 -07:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2012-07-06 03:42:10 -07:00
|
|
|
#include <linux/android_alarm.h>
|
2012-05-08 14:36:07 -07:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/syscall.h>
|
2012-08-04 22:09:39 -07:00
|
|
|
#include <sys/resource.h>
|
2012-05-08 14:36:07 -07:00
|
|
|
#include <time.h>
|
2012-10-31 10:29:14 -07:00
|
|
|
#include <asm/page.h>
|
2012-05-08 14:36:07 -07:00
|
|
|
|
2012-12-14 15:58:45 -08:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-05-08 14:36:07 -07:00
|
|
|
#include "android/log.h"
|
|
|
|
#include "cutils/properties.h"
|
|
|
|
#include "hardware/hardware.h"
|
|
|
|
#include "hardware/lights.h"
|
2011-12-20 11:31:53 -08:00
|
|
|
#include "hardware_legacy/uevent.h"
|
2012-05-08 14:36:07 -07:00
|
|
|
#include "hardware_legacy/vibrator.h"
|
2012-05-09 14:30:22 -07:00
|
|
|
#include "hardware_legacy/power.h"
|
2013-05-07 20:58:22 -07:00
|
|
|
#include "libdisplay/GonkDisplay.h"
|
2012-05-08 14:36:07 -07:00
|
|
|
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
|
2011-12-20 11:31:53 -08:00
|
|
|
#include "Hal.h"
|
2011-12-23 21:03:55 -08:00
|
|
|
#include "HalImpl.h"
|
2011-12-20 11:31:53 -08:00
|
|
|
#include "mozilla/dom/battery/Constants.h"
|
|
|
|
#include "mozilla/FileUtils.h"
|
2011-12-21 17:58:29 -08:00
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "mozilla/Services.h"
|
2012-08-29 08:32:56 -07:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-08-04 22:09:39 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-05-08 14:36:07 -07:00
|
|
|
#include "nsAlgorithm.h"
|
2012-08-04 22:09:39 -07:00
|
|
|
#include "nsPrintfCString.h"
|
2011-12-21 17:58:29 -08:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
2012-10-04 02:28:34 -07:00
|
|
|
#include "nsIRecoveryService.h"
|
2012-05-08 14:36:07 -07:00
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsScreenManagerGonk.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIThread.h"
|
2012-04-11 00:59:00 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-04-20 04:43:25 -07:00
|
|
|
#include "OrientationObserver.h"
|
2012-04-11 00:59:00 -07:00
|
|
|
#include "UeventPoller.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2012-02-17 02:44:00 -08:00
|
|
|
|
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
|
2012-09-27 23:38:50 -07:00
|
|
|
#define NsecPerMsec 1000000LL
|
2012-02-17 02:44:00 -08:00
|
|
|
#define NsecPerSec 1000000000
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
// The header linux/oom.h is not available in bionic libc. We
|
|
|
|
// redefine some of its constants here.
|
|
|
|
|
|
|
|
#ifndef OOM_DISABLE
|
|
|
|
#define OOM_DISABLE (-17)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef OOM_ADJUST_MIN
|
|
|
|
#define OOM_ADJUST_MIN (-16)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef OOM_ADJUST_MAX
|
|
|
|
#define OOM_ADJUST_MAX 15
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef OOM_SCORE_ADJ_MIN
|
|
|
|
#define OOM_SCORE_ADJ_MIN (-1000)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef OOM_SCORE_ADJ_MAX
|
|
|
|
#define OOM_SCORE_ADJ_MAX 1000
|
|
|
|
#endif
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-10-21 20:10:05 -07:00
|
|
|
#ifndef BATTERY_CHARGING_ARGB
|
|
|
|
#define BATTERY_CHARGING_ARGB 0x00FF0000
|
|
|
|
#endif
|
|
|
|
#ifndef BATTERY_FULL_ARGB
|
|
|
|
#define BATTERY_FULL_ARGB 0x0000FF00
|
|
|
|
#endif
|
|
|
|
|
2012-08-04 22:09:39 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::hal;
|
2011-12-20 11:31:53 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace hal_impl {
|
|
|
|
|
2011-12-21 17:58:29 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This runnable runs for the lifetime of the program, once started. It's
|
|
|
|
* responsible for "playing" vibration patterns.
|
|
|
|
*/
|
|
|
|
class VibratorRunnable
|
|
|
|
: public nsIRunnable
|
|
|
|
, public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VibratorRunnable()
|
|
|
|
: mMonitor("VibratorRunnable")
|
|
|
|
, mIndex(0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
|
|
|
if (!os) {
|
|
|
|
NS_WARNING("Could not get observer service!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-19 23:34:07 -07:00
|
|
|
os->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2012-09-14 11:52:07 -07:00
|
|
|
}
|
2012-09-19 23:34:07 -07:00
|
|
|
|
2011-12-21 17:58:29 -08:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
// Run on the main thread, not the vibrator thread.
|
2012-05-25 00:18:30 -07:00
|
|
|
void Vibrate(const nsTArray<uint32_t> &pattern);
|
2011-12-21 17:58:29 -08:00
|
|
|
void CancelVibrate();
|
|
|
|
|
2012-09-19 23:34:07 -07:00
|
|
|
static bool ShuttingDown() { return sShuttingDown; }
|
|
|
|
|
2011-12-21 17:58:29 -08:00
|
|
|
private:
|
|
|
|
Monitor mMonitor;
|
|
|
|
|
|
|
|
// The currently-playing pattern.
|
2012-05-25 00:18:30 -07:00
|
|
|
nsTArray<uint32_t> mPattern;
|
2011-12-21 17:58:29 -08:00
|
|
|
|
|
|
|
// The index we're at in the currently-playing pattern. If mIndex >=
|
|
|
|
// mPattern.Length(), then we're not currently playing anything.
|
2012-05-25 00:18:30 -07:00
|
|
|
uint32_t mIndex;
|
2011-12-21 17:58:29 -08:00
|
|
|
|
|
|
|
// Set to true in our shutdown observer. When this is true, we kill the
|
|
|
|
// vibrator thread.
|
2012-09-19 23:34:07 -07:00
|
|
|
static bool sShuttingDown;
|
2011-12-21 17:58:29 -08:00
|
|
|
};
|
|
|
|
|
2012-09-19 13:55:10 -07:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(VibratorRunnable, nsIRunnable, nsIObserver);
|
2011-12-21 17:58:29 -08:00
|
|
|
|
2012-09-19 23:34:07 -07:00
|
|
|
bool VibratorRunnable::sShuttingDown = false;
|
|
|
|
|
2013-04-23 08:30:25 -07:00
|
|
|
static StaticRefPtr<VibratorRunnable> sVibratorRunnable;
|
2012-09-19 23:34:07 -07:00
|
|
|
|
2011-12-21 17:58:29 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
VibratorRunnable::Run()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
// We currently assume that mMonitor.Wait(X) waits for X milliseconds. But in
|
|
|
|
// reality, the kernel might not switch to this thread for some time after the
|
|
|
|
// wait expires. So there's potential for some inaccuracy here.
|
|
|
|
//
|
|
|
|
// This doesn't worry me too much. Note that we don't even start vibrating
|
|
|
|
// immediately when VibratorRunnable::Vibrate is called -- we go through a
|
|
|
|
// condvar onto another thread. Better just to be chill about small errors in
|
|
|
|
// the timing here.
|
|
|
|
|
2012-09-19 23:34:07 -07:00
|
|
|
while (!sShuttingDown) {
|
2011-12-21 17:58:29 -08:00
|
|
|
if (mIndex < mPattern.Length()) {
|
2012-05-25 00:18:30 -07:00
|
|
|
uint32_t duration = mPattern[mIndex];
|
2011-12-21 17:58:29 -08:00
|
|
|
if (mIndex % 2 == 0) {
|
|
|
|
vibrator_on(duration);
|
|
|
|
}
|
|
|
|
mIndex++;
|
|
|
|
mMonitor.Wait(PR_MillisecondsToInterval(duration));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mMonitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
2012-09-19 23:34:07 -07:00
|
|
|
sVibratorRunnable = NULL;
|
2011-12-21 17:58:29 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VibratorRunnable::Observe(nsISupports *subject, const char *topic,
|
|
|
|
const PRUnichar *data)
|
|
|
|
{
|
2011-12-21 17:58:29 -08:00
|
|
|
MOZ_ASSERT(strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
|
2011-12-21 17:58:29 -08:00
|
|
|
MonitorAutoLock lock(mMonitor);
|
2012-09-19 23:34:07 -07:00
|
|
|
sShuttingDown = true;
|
2011-12-21 17:58:29 -08:00
|
|
|
mMonitor.Notify();
|
2012-09-19 23:34:07 -07:00
|
|
|
|
2011-12-21 17:58:29 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-25 00:18:30 -07:00
|
|
|
VibratorRunnable::Vibrate(const nsTArray<uint32_t> &pattern)
|
2011-12-21 17:58:29 -08:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mPattern = pattern;
|
|
|
|
mIndex = 0;
|
|
|
|
mMonitor.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VibratorRunnable::CancelVibrate()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mPattern.Clear();
|
|
|
|
mPattern.AppendElement(0);
|
|
|
|
mIndex = 0;
|
|
|
|
mMonitor.Notify();
|
|
|
|
}
|
|
|
|
|
2011-12-20 11:31:53 -08:00
|
|
|
void
|
2011-12-21 17:58:29 -08:00
|
|
|
EnsureVibratorThreadInitialized()
|
|
|
|
{
|
|
|
|
if (sVibratorRunnable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-19 23:34:07 -07:00
|
|
|
sVibratorRunnable = new VibratorRunnable();
|
2011-12-21 17:58:29 -08:00
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
NS_NewThread(getter_AddRefs(thread), sVibratorRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
2011-12-20 11:31:53 -08:00
|
|
|
|
|
|
|
void
|
2012-05-25 00:18:30 -07:00
|
|
|
Vibrate(const nsTArray<uint32_t> &pattern, const hal::WindowIdentifier &)
|
2011-12-21 17:58:29 -08:00
|
|
|
{
|
2012-09-19 23:34:07 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (VibratorRunnable::ShuttingDown()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-21 17:58:29 -08:00
|
|
|
EnsureVibratorThreadInitialized();
|
|
|
|
sVibratorRunnable->Vibrate(pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CancelVibrate(const hal::WindowIdentifier &)
|
|
|
|
{
|
2012-09-19 23:34:07 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (VibratorRunnable::ShuttingDown()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-21 17:58:29 -08:00
|
|
|
EnsureVibratorThreadInitialized();
|
|
|
|
sVibratorRunnable->CancelVibrate();
|
|
|
|
}
|
2011-12-20 11:31:53 -08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class BatteryUpdater : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
hal::BatteryInformation info;
|
|
|
|
hal_impl::GetCurrentBatteryInformation(&info);
|
2012-10-21 20:10:05 -07:00
|
|
|
|
|
|
|
// Control the battery indicator (led light) here using BatteryInformation
|
|
|
|
// we just retrieved.
|
|
|
|
uint32_t color = 0; // Format: 0x00rrggbb.
|
|
|
|
if (info.charging() && (info.level() == 1)) {
|
|
|
|
// Charging and battery full.
|
|
|
|
color = BATTERY_FULL_ARGB;
|
|
|
|
} else if (info.charging() && (info.level() < 1)) {
|
|
|
|
// Charging but not full.
|
|
|
|
color = BATTERY_CHARGING_ARGB;
|
|
|
|
} // else turn off battery indicator.
|
|
|
|
|
|
|
|
hal::LightConfiguration aConfig(hal::eHalLightID_Battery,
|
|
|
|
hal::eHalLightMode_User,
|
|
|
|
hal::eHalLightFlash_None,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
color);
|
|
|
|
hal_impl::SetLight(hal::eHalLightID_Battery, aConfig);
|
|
|
|
|
2011-12-20 11:31:53 -08:00
|
|
|
hal::NotifyBatteryChange(info);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-11 00:59:00 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
class BatteryObserver : public IUeventObserver,
|
|
|
|
public RefCounted<BatteryObserver>
|
|
|
|
{
|
2011-12-20 11:31:53 -08:00
|
|
|
public:
|
2012-04-11 00:59:00 -07:00
|
|
|
BatteryObserver()
|
|
|
|
:mUpdater(new BatteryUpdater())
|
2011-12-20 11:31:53 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-11 00:59:00 -07:00
|
|
|
virtual void Notify(const NetlinkEvent &aEvent)
|
2011-12-20 11:31:53 -08:00
|
|
|
{
|
2012-04-11 00:59:00 -07:00
|
|
|
// 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.
|
|
|
|
NS_DispatchToMainThread(mUpdater);
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<BatteryUpdater> mUpdater;
|
|
|
|
};
|
|
|
|
|
2012-04-11 00:59:00 -07:00
|
|
|
// sBatteryObserver is owned by the IO thread. Only the IO thread may
|
|
|
|
// create or destroy it.
|
2012-08-29 08:32:56 -07:00
|
|
|
static StaticRefPtr<BatteryObserver> sBatteryObserver;
|
2012-04-11 00:59:00 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
RegisterBatteryObserverIOThread()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
MOZ_ASSERT(!sBatteryObserver);
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-04-11 00:59:00 -07:00
|
|
|
sBatteryObserver = new BatteryObserver();
|
|
|
|
RegisterUeventListener(sBatteryObserver);
|
|
|
|
}
|
2011-12-20 11:31:53 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
EnableBatteryNotifications()
|
|
|
|
{
|
2012-04-11 00:59:00 -07:00
|
|
|
XRE_GetIOMessageLoop()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableFunction(RegisterBatteryObserverIOThread));
|
|
|
|
}
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-04-11 00:59:00 -07:00
|
|
|
static void
|
|
|
|
UnregisterBatteryObserverIOThread()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
|
|
|
|
MOZ_ASSERT(sBatteryObserver);
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-04-11 00:59:00 -07:00
|
|
|
UnregisterUeventListener(sBatteryObserver);
|
|
|
|
sBatteryObserver = NULL;
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableBatteryNotifications()
|
|
|
|
{
|
2012-04-11 00:59:00 -07:00
|
|
|
XRE_GetIOMessageLoop()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableFunction(UnregisterBatteryObserverIOThread));
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 11:18:46 -08:00
|
|
|
static bool
|
|
|
|
GetCurrentBatteryCharge(int* aCharge)
|
|
|
|
{
|
|
|
|
bool success = ReadSysFile("/sys/class/power_supply/battery/capacity",
|
|
|
|
aCharge);
|
|
|
|
if (!success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if ((*aCharge < 0) || (*aCharge > 100)) {
|
2013-03-27 08:19:09 -07:00
|
|
|
HAL_LOG(("charge level contains unknown value: %d", *aCharge));
|
2012-11-29 11:18:46 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (*aCharge >= 0) && (*aCharge <= 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetCurrentBatteryCharging(int* aCharging)
|
2011-12-20 11:31:53 -08:00
|
|
|
{
|
2012-02-15 10:10:15 -08:00
|
|
|
static const int BATTERY_NOT_CHARGING = 0;
|
|
|
|
static const int BATTERY_CHARGING_USB = 1;
|
|
|
|
static const int BATTERY_CHARGING_AC = 2;
|
|
|
|
|
2012-11-29 11:18:46 -08:00
|
|
|
// Generic device support
|
|
|
|
|
|
|
|
int chargingSrc;
|
|
|
|
bool success =
|
|
|
|
ReadSysFile("/sys/class/power_supply/battery/charging_source", &chargingSrc);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (chargingSrc != BATTERY_NOT_CHARGING &&
|
|
|
|
chargingSrc != BATTERY_CHARGING_USB &&
|
|
|
|
chargingSrc != BATTERY_CHARGING_AC) {
|
|
|
|
HAL_LOG(("charging_source contained unknown value: %d", chargingSrc));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*aCharging = (chargingSrc == BATTERY_CHARGING_USB ||
|
|
|
|
chargingSrc == BATTERY_CHARGING_AC);
|
|
|
|
return true;
|
2011-12-21 17:58:29 -08:00
|
|
|
}
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-11-29 11:18:46 -08:00
|
|
|
// Otoro device support
|
|
|
|
|
|
|
|
char chargingSrcString[16];
|
|
|
|
|
|
|
|
success = ReadSysFile("/sys/class/power_supply/battery/status",
|
2013-03-27 08:19:09 -07:00
|
|
|
chargingSrcString, sizeof(chargingSrcString));
|
2012-11-29 11:18:46 -08:00
|
|
|
if (success) {
|
2013-03-27 08:19:09 -07:00
|
|
|
*aCharging = strcmp(chargingSrcString, "Charging") == 0 ||
|
|
|
|
strcmp(chargingSrcString, "Full") == 0;
|
2012-11-29 11:18:46 -08:00
|
|
|
return true;
|
2012-02-16 14:40:43 -08:00
|
|
|
}
|
|
|
|
|
2012-11-29 11:18:46 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
|
|
|
|
{
|
|
|
|
int charge;
|
|
|
|
|
|
|
|
if (GetCurrentBatteryCharge(&charge)) {
|
|
|
|
aBatteryInfo->level() = (double)charge / 100.0;
|
|
|
|
} else {
|
|
|
|
aBatteryInfo->level() = dom::battery::kDefaultLevel;
|
2011-12-21 17:58:29 -08:00
|
|
|
}
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-11-29 11:18:46 -08:00
|
|
|
int charging;
|
|
|
|
|
|
|
|
if (GetCurrentBatteryCharging(&charging)) {
|
|
|
|
aBatteryInfo->charging() = charging;
|
|
|
|
} else {
|
|
|
|
aBatteryInfo->charging() = true;
|
2012-02-15 10:10:15 -08:00
|
|
|
}
|
|
|
|
|
2013-07-10 06:47:30 -07:00
|
|
|
if (!aBatteryInfo->charging() || (aBatteryInfo->level() < 1.0)) {
|
2012-11-29 11:18:46 -08:00
|
|
|
aBatteryInfo->remainingTime() = dom::battery::kUnknownRemainingTime;
|
|
|
|
} else {
|
|
|
|
aBatteryInfo->remainingTime() = dom::battery::kDefaultRemainingTime;
|
|
|
|
}
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RAII class to help us remember to close file descriptors.
|
|
|
|
*/
|
2012-04-16 15:35:33 -07:00
|
|
|
const char *wakeLockFilename = "/sys/power/wake_lock";
|
|
|
|
const char *wakeUnlockFilename = "/sys/power/wake_unlock";
|
2011-12-20 11:31:53 -08:00
|
|
|
|
|
|
|
template<ssize_t n>
|
|
|
|
bool ReadFromFile(const char *filename, char (&buf)[n])
|
|
|
|
{
|
|
|
|
int fd = open(filename, O_RDONLY);
|
|
|
|
ScopedClose autoClose(fd);
|
|
|
|
if (fd < 0) {
|
|
|
|
HAL_LOG(("Unable to open file %s.", filename));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t numRead = read(fd, buf, n);
|
|
|
|
if (numRead < 0) {
|
|
|
|
HAL_LOG(("Error reading from file %s.", filename));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
buf[std::min(numRead, n - 1)] = '\0';
|
2011-12-20 11:31:53 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
bool WriteToFile(const char *filename, const char *toWrite)
|
2011-12-20 11:31:53 -08:00
|
|
|
{
|
|
|
|
int fd = open(filename, O_WRONLY);
|
|
|
|
ScopedClose autoClose(fd);
|
|
|
|
if (fd < 0) {
|
|
|
|
HAL_LOG(("Unable to open file %s.", filename));
|
2012-09-14 11:52:07 -07:00
|
|
|
return false;
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (write(fd, toWrite, strlen(toWrite)) < 0) {
|
|
|
|
HAL_LOG(("Unable to write to file %s.", filename));
|
2012-09-14 11:52:07 -07:00
|
|
|
return false;
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
2012-09-14 11:52:07 -07:00
|
|
|
|
|
|
|
return true;
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We can write to screenEnabledFilename to enable/disable the screen, but when
|
|
|
|
// we read, we always get "mem"! So we have to keep track ourselves whether
|
|
|
|
// the screen is on or not.
|
|
|
|
bool sScreenEnabled = true;
|
|
|
|
|
2012-04-16 15:35:33 -07:00
|
|
|
// 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;
|
|
|
|
|
2013-05-02 03:33:58 -07:00
|
|
|
// Some CPU wake locks may be acquired internally in HAL. We use a counter to
|
|
|
|
// keep track of these needs. Note we have to hold |sInternalLockCpuMonitor|
|
|
|
|
// when reading or writing this variable to ensure thread-safe.
|
|
|
|
int32_t sInternalLockCpuCount = 0;
|
|
|
|
|
2011-12-20 11:31:53 -08:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetScreenEnabled()
|
|
|
|
{
|
|
|
|
return sScreenEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetScreenEnabled(bool enabled)
|
|
|
|
{
|
2013-05-07 20:58:22 -07:00
|
|
|
GetGonkDisplay()->SetEnabled(enabled);
|
2011-12-20 11:31:53 -08:00
|
|
|
sScreenEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
GetScreenBrightness()
|
|
|
|
{
|
2012-02-01 22:09:00 -08:00
|
|
|
hal::LightConfiguration aConfig;
|
|
|
|
hal::LightType light = hal::eHalLightID_Backlight;
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-02-01 22:09:00 -08:00
|
|
|
hal::GetLight(light, &aConfig);
|
|
|
|
// backlight is brightness only, so using one of the RGB elements as value.
|
|
|
|
int brightness = aConfig.color() & 0xFF;
|
|
|
|
return brightness / 255.0;
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetScreenBrightness(double brightness)
|
|
|
|
{
|
|
|
|
// Don't use De Morgan's law to push the ! into this expression; we want to
|
|
|
|
// catch NaN too.
|
|
|
|
if (!(0 <= brightness && brightness <= 1)) {
|
|
|
|
HAL_LOG(("SetScreenBrightness: Dropping illegal brightness %f.",
|
|
|
|
brightness));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-01 22:09:00 -08:00
|
|
|
// Convert the value in [0, 1] to an int between 0 and 255 and convert to a color
|
|
|
|
// note that the high byte is FF, corresponding to the alpha channel.
|
2011-12-20 11:31:53 -08:00
|
|
|
int val = static_cast<int>(round(brightness * 255));
|
2012-02-01 22:09:00 -08:00
|
|
|
uint32_t color = (0xff<<24) + (val<<16) + (val<<8) + val;
|
|
|
|
|
|
|
|
hal::LightConfiguration aConfig;
|
|
|
|
aConfig.mode() = hal::eHalLightMode_User;
|
|
|
|
aConfig.flash() = hal::eHalLightFlash_None;
|
|
|
|
aConfig.flashOnMS() = aConfig.flashOffMS() = 0;
|
|
|
|
aConfig.color() = color;
|
|
|
|
hal::SetLight(hal::eHalLightID_Backlight, aConfig);
|
2012-02-14 19:24:00 -08:00
|
|
|
hal::SetLight(hal::eHalLightID_Buttons, aConfig);
|
2012-02-01 22:09:00 -08:00
|
|
|
}
|
|
|
|
|
2013-05-02 03:33:58 -07:00
|
|
|
static Monitor* sInternalLockCpuMonitor = nullptr;
|
|
|
|
|
|
|
|
static void
|
|
|
|
UpdateCpuSleepState()
|
|
|
|
{
|
|
|
|
sInternalLockCpuMonitor->AssertCurrentThreadOwns();
|
|
|
|
bool allowed = sCpuSleepAllowed && !sInternalLockCpuCount;
|
|
|
|
WriteToFile(allowed ? wakeUnlockFilename : wakeLockFilename, "gecko");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InternalLockCpu() {
|
|
|
|
MonitorAutoLock monitor(*sInternalLockCpuMonitor);
|
|
|
|
++sInternalLockCpuCount;
|
|
|
|
UpdateCpuSleepState();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
InternalUnlockCpu() {
|
|
|
|
MonitorAutoLock monitor(*sInternalLockCpuMonitor);
|
|
|
|
--sInternalLockCpuCount;
|
|
|
|
UpdateCpuSleepState();
|
|
|
|
}
|
|
|
|
|
2012-04-16 15:35:33 -07:00
|
|
|
bool
|
|
|
|
GetCpuSleepAllowed()
|
|
|
|
{
|
|
|
|
return sCpuSleepAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetCpuSleepAllowed(bool aAllowed)
|
|
|
|
{
|
2013-05-02 03:33:58 -07:00
|
|
|
MonitorAutoLock monitor(*sInternalLockCpuMonitor);
|
2012-04-16 15:35:33 -07:00
|
|
|
sCpuSleepAllowed = aAllowed;
|
2013-05-02 03:33:58 -07:00
|
|
|
UpdateCpuSleepState();
|
2012-04-16 15:35:33 -07:00
|
|
|
}
|
|
|
|
|
2012-02-01 22:09:00 -08:00
|
|
|
static light_device_t* sLights[hal::eHalLightID_Count]; // will be initialized to NULL
|
|
|
|
|
|
|
|
light_device_t* GetDevice(hw_module_t* module, char const* name)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
hw_device_t* device;
|
|
|
|
err = module->methods->open(module, name, &device);
|
|
|
|
if (err == 0) {
|
|
|
|
return (light_device_t*)device;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InitLights()
|
|
|
|
{
|
|
|
|
// assume that if backlight is NULL, nothing has been set yet
|
|
|
|
// if this is not true, the initialization will occur everytime a light is read or set!
|
|
|
|
if (!sLights[hal::eHalLightID_Backlight]) {
|
|
|
|
int err;
|
|
|
|
hw_module_t* module;
|
|
|
|
|
|
|
|
err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
|
|
|
|
if (err == 0) {
|
|
|
|
sLights[hal::eHalLightID_Backlight]
|
|
|
|
= GetDevice(module, LIGHT_ID_BACKLIGHT);
|
|
|
|
sLights[hal::eHalLightID_Keyboard]
|
|
|
|
= GetDevice(module, LIGHT_ID_KEYBOARD);
|
|
|
|
sLights[hal::eHalLightID_Buttons]
|
|
|
|
= GetDevice(module, LIGHT_ID_BUTTONS);
|
|
|
|
sLights[hal::eHalLightID_Battery]
|
|
|
|
= GetDevice(module, LIGHT_ID_BATTERY);
|
|
|
|
sLights[hal::eHalLightID_Notifications]
|
|
|
|
= GetDevice(module, LIGHT_ID_NOTIFICATIONS);
|
|
|
|
sLights[hal::eHalLightID_Attention]
|
|
|
|
= GetDevice(module, LIGHT_ID_ATTENTION);
|
|
|
|
sLights[hal::eHalLightID_Bluetooth]
|
|
|
|
= GetDevice(module, LIGHT_ID_BLUETOOTH);
|
|
|
|
sLights[hal::eHalLightID_Wifi]
|
|
|
|
= GetDevice(module, LIGHT_ID_WIFI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The state last set for the lights until liblights supports
|
|
|
|
* getting the light state.
|
|
|
|
*/
|
|
|
|
static light_state_t sStoredLightState[hal::eHalLightID_Count];
|
2011-12-20 11:31:53 -08:00
|
|
|
|
2012-02-01 22:09:00 -08:00
|
|
|
bool
|
|
|
|
SetLight(hal::LightType light, const hal::LightConfiguration& aConfig)
|
|
|
|
{
|
|
|
|
light_state_t state;
|
|
|
|
|
|
|
|
InitLights();
|
|
|
|
|
|
|
|
if (light < 0 || light >= hal::eHalLightID_Count || sLights[light] == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&state, 0, sizeof(light_state_t));
|
|
|
|
state.color = aConfig.color();
|
|
|
|
state.flashMode = aConfig.flash();
|
|
|
|
state.flashOnMS = aConfig.flashOnMS();
|
|
|
|
state.flashOffMS = aConfig.flashOffMS();
|
|
|
|
state.brightnessMode = aConfig.mode();
|
|
|
|
|
|
|
|
sLights[light]->set_light(sLights[light], &state);
|
|
|
|
sStoredLightState[light] = state;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
|
|
|
|
{
|
|
|
|
light_state_t state;
|
|
|
|
|
|
|
|
#ifdef HAVEGETLIGHT
|
|
|
|
InitLights();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (light < 0 || light >= hal::eHalLightID_Count || sLights[light] == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&state, 0, sizeof(light_state_t));
|
|
|
|
|
|
|
|
#ifdef HAVEGETLIGHT
|
|
|
|
sLights[light]->get_light(sLights[light], &state);
|
|
|
|
#else
|
|
|
|
state = sStoredLightState[light];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aConfig->light() = light;
|
|
|
|
aConfig->color() = state.color;
|
|
|
|
aConfig->flash() = hal::FlashMode(state.flashMode);
|
|
|
|
aConfig->flashOnMS() = state.flashOnMS;
|
|
|
|
aConfig->flashOffMS() = state.flashOffMS;
|
|
|
|
aConfig->mode() = hal::LightMode(state.brightnessMode);
|
|
|
|
|
|
|
|
return true;
|
2011-12-20 11:31:53 -08:00
|
|
|
}
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
void
|
2012-09-25 20:51:29 -07:00
|
|
|
AdjustSystemClock(int64_t aDeltaMilliseconds)
|
2012-02-17 02:44:00 -08:00
|
|
|
{
|
2012-09-27 23:38:50 -07:00
|
|
|
int fd;
|
|
|
|
struct timespec now;
|
|
|
|
|
2012-09-10 23:40:00 -07:00
|
|
|
if (aDeltaMilliseconds == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-14 11:52:07 -07:00
|
|
|
|
|
|
|
// Preventing context switch before setting system clock
|
2012-02-17 02:44:00 -08:00
|
|
|
sched_yield();
|
|
|
|
clock_gettime(CLOCK_REALTIME, &now);
|
2012-09-27 23:38:50 -07:00
|
|
|
now.tv_sec += (time_t)(aDeltaMilliseconds / 1000LL);
|
|
|
|
now.tv_nsec += (long)((aDeltaMilliseconds % 1000LL) * NsecPerMsec);
|
|
|
|
if (now.tv_nsec >= NsecPerSec) {
|
2012-02-17 02:44:00 -08:00
|
|
|
now.tv_sec += 1;
|
|
|
|
now.tv_nsec -= NsecPerSec;
|
|
|
|
}
|
|
|
|
|
2012-09-27 23:38:50 -07:00
|
|
|
if (now.tv_nsec < 0) {
|
2012-02-17 02:44:00 -08:00
|
|
|
now.tv_nsec += NsecPerSec;
|
2012-09-14 11:52:07 -07:00
|
|
|
now.tv_sec -= 1;
|
2012-02-17 02:44:00 -08:00
|
|
|
}
|
2012-09-27 23:38:50 -07:00
|
|
|
|
|
|
|
do {
|
|
|
|
fd = open("/dev/alarm", O_RDWR);
|
|
|
|
} while (fd == -1 && errno == EINTR);
|
|
|
|
ScopedClose autoClose(fd);
|
|
|
|
if (fd < 0) {
|
|
|
|
HAL_LOG(("Failed to open /dev/alarm: %s", strerror(errno)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, ANDROID_ALARM_SET_RTC, &now) < 0) {
|
|
|
|
HAL_LOG(("ANDROID_ALARM_SET_RTC failed: %s", strerror(errno)));
|
2012-09-10 23:40:00 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-09-14 11:52:07 -07:00
|
|
|
|
2012-10-23 00:15:43 -07:00
|
|
|
hal::NotifySystemClockChange(aDeltaMilliseconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t
|
|
|
|
GetTimezoneOffset()
|
|
|
|
{
|
|
|
|
PRExplodedTime prTime;
|
|
|
|
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &prTime);
|
|
|
|
|
|
|
|
// Daylight saving time (DST) will be taken into account.
|
|
|
|
int32_t offset = prTime.tm_params.tp_gmt_offset;
|
|
|
|
offset += prTime.tm_params.tp_dst_offset;
|
|
|
|
|
|
|
|
// Returns the timezone offset relative to UTC in minutes.
|
|
|
|
return -(offset / 60);
|
2012-02-17 02:44:00 -08:00
|
|
|
}
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
void
|
2012-02-17 02:44:00 -08:00
|
|
|
SetTimezone(const nsCString& aTimezoneSpec)
|
2012-09-10 23:40:00 -07:00
|
|
|
{
|
|
|
|
if (aTimezoneSpec.Equals(GetTimezone())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-23 00:15:43 -07:00
|
|
|
int32_t oldTimezoneOffsetMinutes = GetTimezoneOffset();
|
2012-02-17 02:44:00 -08:00
|
|
|
property_set("persist.sys.timezone", aTimezoneSpec.get());
|
2013-05-02 03:33:58 -07:00
|
|
|
// This function is automatically called by the other time conversion
|
2012-09-14 11:52:07 -07:00
|
|
|
// functions that depend on the timezone. To be safe, we call it manually.
|
2012-02-17 02:44:00 -08:00
|
|
|
tzset();
|
2012-10-23 00:15:43 -07:00
|
|
|
int32_t newTimezoneOffsetMinutes = GetTimezoneOffset();
|
|
|
|
hal::NotifySystemTimezoneChange(
|
|
|
|
hal::SystemTimezoneChangeInformation(
|
|
|
|
oldTimezoneOffsetMinutes, newTimezoneOffsetMinutes));
|
2012-02-17 02:44:00 -08:00
|
|
|
}
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
nsCString
|
2012-08-23 02:00:00 -07:00
|
|
|
GetTimezone()
|
|
|
|
{
|
|
|
|
char timezone[32];
|
|
|
|
property_get("persist.sys.timezone", timezone, "");
|
|
|
|
return nsCString(timezone);
|
|
|
|
}
|
|
|
|
|
2012-09-23 10:00:32 -07:00
|
|
|
void
|
2012-10-23 00:15:43 -07:00
|
|
|
EnableSystemClockChangeNotifications()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableSystemClockChangeNotifications()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EnableSystemTimezoneChangeNotifications()
|
2012-09-23 10:00:32 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-10-23 00:15:43 -07:00
|
|
|
DisableSystemTimezoneChangeNotifications()
|
2012-09-23 10:00:32 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-08 14:36:07 -07:00
|
|
|
// Nothing to do here. Gonk widgetry always listens for screen
|
|
|
|
// orientation changes.
|
|
|
|
void
|
|
|
|
EnableScreenConfigurationNotifications()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableScreenConfigurationNotifications()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration)
|
|
|
|
{
|
|
|
|
*aScreenConfiguration = nsScreenGonk::GetConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
|
|
|
|
{
|
2012-04-20 04:43:25 -07:00
|
|
|
return OrientationObserver::GetInstance()->LockScreenOrientation(aOrientation);
|
2012-05-08 14:36:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UnlockScreenOrientation()
|
|
|
|
{
|
2012-04-20 04:43:25 -07:00
|
|
|
OrientationObserver::GetInstance()->UnlockScreenOrientation();
|
2012-05-08 14:36:07 -07:00
|
|
|
}
|
|
|
|
|
2013-05-02 03:33:58 -07:00
|
|
|
// This thread will wait for the alarm firing by a blocking IO.
|
2012-07-06 03:42:10 -07:00
|
|
|
static pthread_t sAlarmFireWatcherThread;
|
|
|
|
|
2013-05-02 03:33:58 -07:00
|
|
|
// If |sAlarmData| is non-null, it's owned by the alarm-watcher thread.
|
|
|
|
struct AlarmData {
|
2012-07-06 03:42:10 -07:00
|
|
|
public:
|
2013-05-02 03:33:58 -07:00
|
|
|
AlarmData(int aFd) : mFd(aFd),
|
|
|
|
mGeneration(sNextGeneration++),
|
|
|
|
mShuttingDown(false) {}
|
2012-07-06 03:42:10 -07:00
|
|
|
ScopedClose mFd;
|
|
|
|
int mGeneration;
|
|
|
|
bool mShuttingDown;
|
|
|
|
|
|
|
|
static int sNextGeneration;
|
|
|
|
|
2013-05-02 03:33:58 -07:00
|
|
|
};
|
2012-07-06 03:42:10 -07:00
|
|
|
|
|
|
|
int AlarmData::sNextGeneration = 0;
|
|
|
|
|
|
|
|
AlarmData* sAlarmData = NULL;
|
|
|
|
|
|
|
|
class AlarmFiredEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
AlarmFiredEvent(int aGeneration) : mGeneration(aGeneration) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
// Guard against spurious notifications caused by an alarm firing
|
|
|
|
// concurrently with it being disabled.
|
2013-05-02 03:33:58 -07:00
|
|
|
if (sAlarmData && !sAlarmData->mShuttingDown &&
|
|
|
|
mGeneration == sAlarmData->mGeneration) {
|
2012-07-06 03:42:10 -07:00
|
|
|
hal::NotifyAlarmFired();
|
|
|
|
}
|
2013-05-02 03:33:58 -07:00
|
|
|
// The fired alarm event has been delivered to the observer (if needed);
|
|
|
|
// we can now release a CPU wake lock.
|
|
|
|
InternalUnlockCpu();
|
2012-07-06 03:42:10 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int mGeneration;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Runs on alarm-watcher thread.
|
2012-09-14 11:52:07 -07:00
|
|
|
static void
|
2012-07-06 03:42:10 -07:00
|
|
|
DestroyAlarmData(void* aData)
|
|
|
|
{
|
|
|
|
AlarmData* alarmData = static_cast<AlarmData*>(aData);
|
|
|
|
delete alarmData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Runs on alarm-watcher thread.
|
|
|
|
void ShutDownAlarm(int aSigno)
|
|
|
|
{
|
2012-07-26 09:15:26 -07:00
|
|
|
if (aSigno == SIGUSR1) {
|
2012-07-06 03:42:10 -07:00
|
|
|
sAlarmData->mShuttingDown = true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
static void*
|
2012-07-06 03:42:10 -07:00
|
|
|
WaitForAlarm(void* aData)
|
|
|
|
{
|
|
|
|
pthread_cleanup_push(DestroyAlarmData, aData);
|
|
|
|
|
|
|
|
AlarmData* alarmData = static_cast<AlarmData*>(aData);
|
|
|
|
|
|
|
|
while (!alarmData->mShuttingDown) {
|
|
|
|
int alarmTypeFlags = 0;
|
|
|
|
|
|
|
|
// ALARM_WAIT apparently will block even if an alarm hasn't been
|
|
|
|
// programmed, although this behavior doesn't seem to be
|
|
|
|
// documented. We rely on that here to avoid spinning the CPU
|
|
|
|
// while awaiting an alarm to be programmed.
|
|
|
|
do {
|
|
|
|
alarmTypeFlags = ioctl(alarmData->mFd, ANDROID_ALARM_WAIT);
|
2013-05-02 03:33:58 -07:00
|
|
|
} while (alarmTypeFlags < 0 && errno == EINTR &&
|
|
|
|
!alarmData->mShuttingDown);
|
|
|
|
|
|
|
|
if (!alarmData->mShuttingDown && alarmTypeFlags >= 0 &&
|
|
|
|
(alarmTypeFlags & ANDROID_ALARM_RTC_WAKEUP_MASK)) {
|
|
|
|
// To make sure the observer can get the alarm firing notification
|
|
|
|
// *on time* (the system won't sleep during the process in any way),
|
|
|
|
// we need to acquire a CPU wake lock before firing the alarm event.
|
|
|
|
InternalLockCpu();
|
|
|
|
nsRefPtr<AlarmFiredEvent> event =
|
|
|
|
new AlarmFiredEvent(alarmData->mGeneration);
|
|
|
|
NS_DispatchToMainThread(event);
|
2012-07-06 03:42:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_cleanup_pop(1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
EnableAlarm()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!sAlarmData);
|
|
|
|
|
|
|
|
int alarmFd = open("/dev/alarm", O_RDWR);
|
|
|
|
if (alarmFd < 0) {
|
|
|
|
HAL_LOG(("Failed to open alarm device: %s.", strerror(errno)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoPtr<AlarmData> alarmData(new AlarmData(alarmFd));
|
|
|
|
|
|
|
|
struct sigaction actions;
|
|
|
|
memset(&actions, 0, sizeof(actions));
|
|
|
|
sigemptyset(&actions.sa_mask);
|
|
|
|
actions.sa_flags = 0;
|
|
|
|
actions.sa_handler = ShutDownAlarm;
|
2012-07-26 09:15:26 -07:00
|
|
|
if (sigaction(SIGUSR1, &actions, NULL)) {
|
|
|
|
HAL_LOG(("Failed to set SIGUSR1 signal for alarm-watcher thread."));
|
2012-07-06 03:42:10 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
|
2013-05-02 03:33:58 -07:00
|
|
|
// Initialize the monitor for internally locking CPU to ensure thread-safe
|
|
|
|
// before running the alarm-watcher thread.
|
|
|
|
sInternalLockCpuMonitor = new Monitor("sInternalLockCpuMonitor");
|
|
|
|
int status = pthread_create(&sAlarmFireWatcherThread, &attr, WaitForAlarm,
|
|
|
|
alarmData.get());
|
2012-07-06 03:42:10 -07:00
|
|
|
if (status) {
|
|
|
|
alarmData = NULL;
|
2013-05-02 03:33:58 -07:00
|
|
|
delete sInternalLockCpuMonitor;
|
|
|
|
HAL_LOG(("Failed to create alarm-watcher thread. Status: %d.", status));
|
2012-07-06 03:42:10 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_attr_destroy(&attr);
|
|
|
|
|
|
|
|
// The thread owns this now. We only hold a pointer.
|
|
|
|
sAlarmData = alarmData.forget();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableAlarm()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sAlarmData);
|
|
|
|
|
|
|
|
// NB: this must happen-before the thread cancellation.
|
|
|
|
sAlarmData = NULL;
|
|
|
|
|
|
|
|
// The cancel will interrupt the thread and destroy it, freeing the
|
|
|
|
// data pointed at by sAlarmData.
|
2012-07-26 09:15:26 -07:00
|
|
|
DebugOnly<int> err = pthread_kill(sAlarmFireWatcherThread, SIGUSR1);
|
2012-07-06 03:42:10 -07:00
|
|
|
MOZ_ASSERT(!err);
|
2013-05-02 03:33:58 -07:00
|
|
|
|
|
|
|
delete sInternalLockCpuMonitor;
|
2012-07-06 03:42:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
|
2012-07-06 03:42:10 -07:00
|
|
|
{
|
|
|
|
if (!sAlarmData) {
|
|
|
|
HAL_LOG(("We should have enabled the alarm."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = aSeconds;
|
|
|
|
ts.tv_nsec = aNanoseconds;
|
|
|
|
|
2013-05-02 03:33:58 -07:00
|
|
|
// Currently we only support RTC wakeup alarm type.
|
|
|
|
const int result = ioctl(sAlarmData->mFd,
|
|
|
|
ANDROID_ALARM_SET(ANDROID_ALARM_RTC_WAKEUP), &ts);
|
2012-07-06 03:42:10 -07:00
|
|
|
|
|
|
|
if (result < 0) {
|
|
|
|
HAL_LOG(("Unable to set alarm: %s.", strerror(errno)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
static int
|
2012-10-31 10:29:14 -07:00
|
|
|
OomAdjOfOomScoreAdj(int aOomScoreAdj)
|
2012-09-14 11:52:07 -07:00
|
|
|
{
|
|
|
|
// Convert OOM adjustment from the domain of /proc/<pid>/oom_score_adj
|
2012-10-31 10:29:14 -07:00
|
|
|
// to the domain of /proc/<pid>/oom_adj.
|
2012-09-14 11:52:07 -07:00
|
|
|
|
|
|
|
int adj;
|
|
|
|
|
|
|
|
if (aOomScoreAdj < 0) {
|
|
|
|
adj = (OOM_DISABLE * aOomScoreAdj) / OOM_SCORE_ADJ_MIN;
|
|
|
|
} else {
|
|
|
|
adj = (OOM_ADJUST_MAX * aOomScoreAdj) / OOM_SCORE_ADJ_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return adj;
|
|
|
|
}
|
|
|
|
|
2012-10-31 10:29:14 -07:00
|
|
|
static void
|
|
|
|
EnsureKernelLowMemKillerParamsSet()
|
|
|
|
{
|
|
|
|
static bool kernelLowMemKillerParamsSet;
|
|
|
|
if (kernelLowMemKillerParamsSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
kernelLowMemKillerParamsSet = true;
|
|
|
|
|
|
|
|
HAL_LOG(("Setting kernel's low-mem killer parameters."));
|
|
|
|
|
|
|
|
// Set /sys/module/lowmemorykiller/parameters/{adj,minfree,notify_trigger}
|
|
|
|
// according to our prefs. These files let us tune when the kernel kills
|
|
|
|
// processes when we're low on memory, and when it notifies us that we're
|
|
|
|
// running low on available memory.
|
|
|
|
//
|
|
|
|
// adj and minfree are both comma-separated lists of integers. If adj="A,B"
|
|
|
|
// and minfree="X,Y", then the kernel will kill processes with oom_adj
|
|
|
|
// A or higher once we have fewer than X pages of memory free, and will kill
|
|
|
|
// processes with oom_adj B or higher once we have fewer than Y pages of
|
|
|
|
// memory free.
|
|
|
|
//
|
|
|
|
// notify_trigger is a single integer. If we set notify_trigger=Z, then
|
|
|
|
// we'll get notified when there are fewer than Z pages of memory free. (See
|
|
|
|
// GonkMemoryPressureMonitoring.cpp.)
|
|
|
|
|
|
|
|
// Build the adj and minfree strings.
|
|
|
|
nsAutoCString adjParams;
|
|
|
|
nsAutoCString minfreeParams;
|
|
|
|
|
2013-06-28 21:14:02 -07:00
|
|
|
int32_t lowerBoundOfNextOomScoreAdj = OOM_SCORE_ADJ_MIN - 1;
|
|
|
|
int32_t lowerBoundOfNextKillUnderMB = 0;
|
|
|
|
|
|
|
|
for (int i = NUM_PROCESS_PRIORITY - 1; i >= 0; i--) {
|
2013-02-14 12:41:30 -08:00
|
|
|
// The system doesn't function correctly if we're missing these prefs, so
|
|
|
|
// crash loudly.
|
|
|
|
|
2013-05-09 13:27:06 -07:00
|
|
|
ProcessPriority priority = static_cast<ProcessPriority>(i);
|
|
|
|
|
2012-10-31 10:29:14 -07:00
|
|
|
int32_t oomScoreAdj;
|
2013-05-09 13:27:06 -07:00
|
|
|
if (!NS_SUCCEEDED(Preferences::GetInt(
|
|
|
|
nsPrintfCString("hal.processPriorityManager.gonk.%s.OomScoreAdjust",
|
|
|
|
ProcessPriorityToString(priority)).get(),
|
|
|
|
&oomScoreAdj))) {
|
2013-02-14 12:41:30 -08:00
|
|
|
MOZ_CRASH();
|
2012-10-31 10:29:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t killUnderMB;
|
2013-05-09 13:27:06 -07:00
|
|
|
if (!NS_SUCCEEDED(Preferences::GetInt(
|
|
|
|
nsPrintfCString("hal.processPriorityManager.gonk.%s.KillUnderMB",
|
|
|
|
ProcessPriorityToString(priority)).get(),
|
|
|
|
&killUnderMB))) {
|
2013-02-14 12:41:30 -08:00
|
|
|
MOZ_CRASH();
|
2012-10-31 10:29:14 -07:00
|
|
|
}
|
|
|
|
|
2013-06-28 21:14:02 -07:00
|
|
|
// The LMK in kernel silently malfunctions if we assign the parameters
|
|
|
|
// in non-increasing order, so we add this assertion here. See bug 887192.
|
|
|
|
MOZ_ASSERT(oomScoreAdj > lowerBoundOfNextOomScoreAdj);
|
|
|
|
MOZ_ASSERT(killUnderMB > lowerBoundOfNextKillUnderMB);
|
|
|
|
|
2012-10-31 10:29:14 -07:00
|
|
|
// adj is in oom_adj units.
|
|
|
|
adjParams.AppendPrintf("%d,", OomAdjOfOomScoreAdj(oomScoreAdj));
|
|
|
|
|
|
|
|
// minfree is in pages.
|
|
|
|
minfreeParams.AppendPrintf("%d,", killUnderMB * 1024 * 1024 / PAGE_SIZE);
|
2013-06-28 21:14:02 -07:00
|
|
|
|
|
|
|
lowerBoundOfNextOomScoreAdj = oomScoreAdj;
|
|
|
|
lowerBoundOfNextKillUnderMB = killUnderMB;
|
2012-10-31 10:29:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Strip off trailing commas.
|
|
|
|
adjParams.Cut(adjParams.Length() - 1, 1);
|
|
|
|
minfreeParams.Cut(minfreeParams.Length() - 1, 1);
|
|
|
|
if (!adjParams.IsEmpty() && !minfreeParams.IsEmpty()) {
|
|
|
|
WriteToFile("/sys/module/lowmemorykiller/parameters/adj", adjParams.get());
|
|
|
|
WriteToFile("/sys/module/lowmemorykiller/parameters/minfree", minfreeParams.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the low-memory-notification threshold.
|
|
|
|
int32_t lowMemNotifyThresholdMB;
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(
|
|
|
|
"hal.processPriorityManager.gonk.notifyLowMemUnderMB",
|
|
|
|
&lowMemNotifyThresholdMB))) {
|
|
|
|
|
|
|
|
// notify_trigger is in pages.
|
|
|
|
WriteToFile("/sys/module/lowmemorykiller/parameters/notify_trigger",
|
|
|
|
nsPrintfCString("%d", lowMemNotifyThresholdMB * 1024 * 1024 / PAGE_SIZE).get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:27 -07:00
|
|
|
static void
|
|
|
|
SetNiceForPid(int aPid, int aNice)
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
int origProcPriority = getpriority(PRIO_PROCESS, aPid);
|
|
|
|
if (errno) {
|
|
|
|
LOG("Unable to get nice for pid=%d; error %d. SetNiceForPid bailing.",
|
|
|
|
aPid, errno);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rv = setpriority(PRIO_PROCESS, aPid, aNice);
|
|
|
|
if (rv) {
|
|
|
|
LOG("Unable to set nice for pid=%d; error %d. SetNiceForPid bailing.",
|
|
|
|
aPid, errno);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// On Linux, setpriority(aPid) modifies the priority only of the main
|
|
|
|
// thread of that process. We have to modify the priorities of all of the
|
|
|
|
// process's threads as well, so iterate over all the threads and increase
|
|
|
|
// each of their priorites by aNice - origProcPriority (and also ensure that
|
|
|
|
// none of the tasks has a lower priority than the main thread).
|
|
|
|
//
|
|
|
|
// This is horribly racy.
|
|
|
|
|
|
|
|
DIR* tasksDir = opendir(nsPrintfCString("/proc/%d/task/", aPid).get());
|
|
|
|
if (!tasksDir) {
|
|
|
|
LOG("Unable to open /proc/%d/task. SetNiceForPid bailing.", aPid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Be careful not to leak tasksDir; after this point, we must call closedir().
|
|
|
|
|
|
|
|
while (struct dirent* de = readdir(tasksDir)) {
|
|
|
|
char* endptr = nullptr;
|
|
|
|
long tidlong = strtol(de->d_name, &endptr, /* base */ 10);
|
|
|
|
if (*endptr || tidlong < 0 || tidlong > INT32_MAX || tidlong == aPid) {
|
|
|
|
// if dp->d_name was not an integer, was negative (?!) or too large, or
|
|
|
|
// was the same as aPid, we're not interested.
|
|
|
|
//
|
|
|
|
// (The |tidlong == aPid| check is very important; without it, we'll
|
|
|
|
// renice aPid twice, and the second renice will be relative to the
|
|
|
|
// priority set by the first renice.)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tid = static_cast<int>(tidlong);
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
// Get and set the task's new priority.
|
|
|
|
int origtaskpriority = getpriority(PRIO_PROCESS, tid);
|
|
|
|
if (errno) {
|
|
|
|
LOG("Unable to get nice for tid=%d (pid=%d); error %d. This isn't "
|
|
|
|
"necessarily a problem; it could be a benign race condition.",
|
|
|
|
tid, aPid, errno);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int newtaskpriority =
|
2013-06-05 04:55:01 -07:00
|
|
|
std::max(origtaskpriority - origProcPriority + aNice, aNice);
|
2013-04-25 17:53:27 -07:00
|
|
|
rv = setpriority(PRIO_PROCESS, tid, newtaskpriority);
|
|
|
|
|
|
|
|
if (rv) {
|
|
|
|
LOG("Unable to set nice for tid=%d (pid=%d); error %d. This isn't "
|
|
|
|
"necessarily a problem; it could be a benign race condition.",
|
|
|
|
tid, aPid, errno);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG("Changed nice for pid %d from %d to %d.",
|
|
|
|
aPid, origProcPriority, aNice);
|
|
|
|
|
|
|
|
closedir(tasksDir);
|
|
|
|
}
|
|
|
|
|
2012-08-04 22:09:39 -07:00
|
|
|
void
|
2013-05-09 13:27:06 -07:00
|
|
|
SetProcessPriority(int aPid,
|
|
|
|
ProcessPriority aPriority,
|
|
|
|
ProcessCPUPriority aCPUPriority)
|
2012-08-04 22:09:39 -07:00
|
|
|
{
|
2013-05-09 13:27:06 -07:00
|
|
|
HAL_LOG(("SetProcessPriority(pid=%d, priority=%d, cpuPriority=%d)",
|
|
|
|
aPid, aPriority, aCPUPriority));
|
2012-08-04 22:09:39 -07:00
|
|
|
|
2012-10-31 10:29:14 -07:00
|
|
|
// If this is the first time SetProcessPriority was called, set the kernel's
|
|
|
|
// OOM parameters according to our prefs.
|
|
|
|
//
|
|
|
|
// We could/should do this on startup instead of waiting for the first
|
|
|
|
// SetProcessPriorityCall. But in practice, the master process needs to set
|
|
|
|
// its priority early in the game, so we can reasonably rely on
|
|
|
|
// SetProcessPriority being called early in startup.
|
|
|
|
EnsureKernelLowMemKillerParamsSet();
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
int32_t oomScoreAdj = 0;
|
2012-08-04 22:09:39 -07:00
|
|
|
nsresult rv = Preferences::GetInt(nsPrintfCString(
|
2013-05-09 13:27:06 -07:00
|
|
|
"hal.processPriorityManager.gonk.%s.OomScoreAdjust",
|
|
|
|
ProcessPriorityToString(aPriority)).get(), &oomScoreAdj);
|
2012-09-14 11:52:07 -07:00
|
|
|
|
2012-08-04 22:09:39 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-09-14 11:52:07 -07:00
|
|
|
int clampedOomScoreAdj = clamped<int>(oomScoreAdj, OOM_SCORE_ADJ_MIN,
|
|
|
|
OOM_SCORE_ADJ_MAX);
|
|
|
|
if(clampedOomScoreAdj != oomScoreAdj) {
|
|
|
|
HAL_LOG(("Clamping OOM adjustment for pid %d to %d",
|
|
|
|
aPid, clampedOomScoreAdj));
|
|
|
|
} else {
|
|
|
|
HAL_LOG(("Setting OOM adjustment for pid %d to %d",
|
|
|
|
aPid, clampedOomScoreAdj));
|
|
|
|
}
|
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
// We try the newer interface first, and fall back to the older interface
|
|
|
|
// on failure.
|
2012-09-14 11:52:07 -07:00
|
|
|
|
2012-09-14 11:52:07 -07:00
|
|
|
if (!WriteToFile(nsPrintfCString("/proc/%d/oom_score_adj", aPid).get(),
|
|
|
|
nsPrintfCString("%d", clampedOomScoreAdj).get()))
|
|
|
|
{
|
2012-10-31 10:29:14 -07:00
|
|
|
int oomAdj = OomAdjOfOomScoreAdj(clampedOomScoreAdj);
|
2012-09-14 11:52:07 -07:00
|
|
|
|
|
|
|
WriteToFile(nsPrintfCString("/proc/%d/oom_adj", aPid).get(),
|
|
|
|
nsPrintfCString("%d", oomAdj).get());
|
|
|
|
}
|
2013-05-09 13:27:06 -07:00
|
|
|
} else {
|
|
|
|
LOG("Unable to read oom_score_adj pref for priority %s; "
|
|
|
|
"are the prefs messed up?",
|
|
|
|
ProcessPriorityToString(aPriority));
|
|
|
|
MOZ_ASSERT(false);
|
2012-08-04 22:09:39 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nice = 0;
|
2012-08-04 22:09:39 -07:00
|
|
|
|
2013-05-09 13:27:06 -07:00
|
|
|
if (aCPUPriority == PROCESS_CPU_PRIORITY_NORMAL) {
|
|
|
|
rv = Preferences::GetInt(
|
|
|
|
nsPrintfCString("hal.processPriorityManager.gonk.%s.Nice",
|
|
|
|
ProcessPriorityToString(aPriority)).get(),
|
|
|
|
&nice);
|
|
|
|
} else if (aCPUPriority == PROCESS_CPU_PRIORITY_LOW) {
|
|
|
|
rv = Preferences::GetInt("hal.processPriorityManager.gonk.LowCPUNice",
|
|
|
|
&nice);
|
|
|
|
} else {
|
|
|
|
LOG("Unable to read niceness pref for priority %s; "
|
|
|
|
"are the prefs messed up?",
|
|
|
|
ProcessPriorityToString(aPriority));
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
LOG("Setting nice for pid %d to %d", aPid, nice);
|
2013-04-25 17:53:27 -07:00
|
|
|
SetNiceForPid(aPid, nice);
|
2012-08-04 22:09:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-04 02:28:34 -07:00
|
|
|
void
|
|
|
|
FactoryReset()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRecoveryService> recoveryService =
|
|
|
|
do_GetService("@mozilla.org/recovery-service;1");
|
|
|
|
if (!recoveryService) {
|
|
|
|
NS_WARNING("Could not get recovery service!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
recoveryService->FactoryReset();
|
|
|
|
}
|
|
|
|
|
2011-12-20 11:31:53 -08:00
|
|
|
} // hal_impl
|
|
|
|
} // mozilla
|