From f10676ded275fc422bac1d89523e97e5273d6e37 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 21 Dec 2010 14:34:29 -0800 Subject: [PATCH] Bug 616664 - Android code for keeping the screen on. r=mwu a=blocking-fennec --- embedding/android/GeckoAppShell.java | 10 +++++++++- widget/src/android/AndroidBridge.cpp | 8 ++++++++ widget/src/android/AndroidBridge.h | 3 +++ widget/src/android/Makefile.in | 1 + widget/src/android/nsScreenManagerAndroid.cpp | 11 ++++++++++- widget/src/android/nsScreenManagerAndroid.h | 11 ++++++++--- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index 857a44ab5a3..f9a8883fc44 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -1,4 +1,4 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -638,4 +638,12 @@ class GeckoAppShell GeckoApp.mAppContext.mProgressDialog = null; } } + + public static void setKeepScreenOn(final boolean on) { + GeckoApp.mAppContext.runOnUiThread(new Runnable() { + public void run() { + GeckoApp.surfaceView.setKeepScreenOn(on); + } + }); + } } diff --git a/widget/src/android/AndroidBridge.cpp b/widget/src/android/AndroidBridge.cpp index 7425592f1ba..d848fb4a941 100644 --- a/widget/src/android/AndroidBridge.cpp +++ b/widget/src/android/AndroidBridge.cpp @@ -122,6 +122,7 @@ AndroidBridge::Init(JNIEnv *jEnv, jShowInputMethodPicker = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showInputMethodPicker", "()V"); jHideProgressDialog = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "hideProgressDialog", "()V"); jPerformHapticFeedback = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "performHapticFeedback", "(Z)V"); + jSetKeepScreenOn = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setKeepScreenOn", "(Z)V"); jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext")); jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10")); @@ -639,6 +640,13 @@ AndroidBridge::GetStaticStringField(const char *className, const char *fieldName return true; } +void +AndroidBridge::SetKeepScreenOn(bool on) +{ + JNI()->CallStaticVoidMethod(sBridge->mGeckoAppShellClass, + sBridge->jSetKeepScreenOn, on); +} + // Available for places elsewhere in the code to link to. PRBool mozilla_AndroidBridge_SetMainThread(void *thr) diff --git a/widget/src/android/AndroidBridge.h b/widget/src/android/AndroidBridge.h index b1a219e9afb..7a460aa0615 100644 --- a/widget/src/android/AndroidBridge.h +++ b/widget/src/android/AndroidBridge.h @@ -211,6 +211,8 @@ public: bool GetStaticStringField(const char *classID, const char *field, nsAString &result); + void SetKeepScreenOn(bool on); + protected: static AndroidBridge *sBridge; @@ -259,6 +261,7 @@ protected: jmethodID jShowInputMethodPicker; jmethodID jHideProgressDialog; jmethodID jPerformHapticFeedback; + jmethodID jSetKeepScreenOn; // stuff we need for CallEglCreateWindowSurface jclass jEGLSurfaceImplClass; diff --git a/widget/src/android/Makefile.in b/widget/src/android/Makefile.in index 37179f96d70..107056ce7d5 100644 --- a/widget/src/android/Makefile.in +++ b/widget/src/android/Makefile.in @@ -100,6 +100,7 @@ DEFINES += -D_IMPL_NS_WIDGET LOCAL_INCLUDES += \ -I$(topsrcdir)/widget/src/xpwidgets \ + -I$(topsrcdir)/widget/src/shared \ -I$(topsrcdir)/dom/system/android \ -I$(srcdir) \ $(NULL) diff --git a/widget/src/android/nsScreenManagerAndroid.cpp b/widget/src/android/nsScreenManagerAndroid.cpp index 4a31b80ef44..ffa3615f9eb 100644 --- a/widget/src/android/nsScreenManagerAndroid.cpp +++ b/widget/src/android/nsScreenManagerAndroid.cpp @@ -38,8 +38,11 @@ #include "nsScreenManagerAndroid.h" #include "nsWindow.h" +#include "AndroidBridge.h" -NS_IMPL_ISUPPORTS1(nsScreenAndroid, nsIScreen) +using namespace mozilla; + +NS_IMPL_ISUPPORTS2(nsScreenAndroid, nsIScreen, nsIScreen_MOZILLA_2_0_BRANCH) nsScreenAndroid::nsScreenAndroid(void *nativeScreen) { @@ -88,6 +91,12 @@ nsScreenAndroid::GetColorDepth(PRInt32 *aColorDepth) return GetPixelDepth(aColorDepth); } +void +nsScreenAndroid::ApplyMinimumBrightness(PRUint32 aBrightness) +{ + AndroidBridge::Bridge()->SetKeepScreenOn(aBrightness == BRIGHTNESS_FULL); +} + NS_IMPL_ISUPPORTS1(nsScreenManagerAndroid, nsIScreenManager) nsScreenManagerAndroid::nsScreenManagerAndroid() diff --git a/widget/src/android/nsScreenManagerAndroid.h b/widget/src/android/nsScreenManagerAndroid.h index c7fcc87b0c2..9907155cacc 100644 --- a/widget/src/android/nsScreenManagerAndroid.h +++ b/widget/src/android/nsScreenManagerAndroid.h @@ -43,16 +43,21 @@ #include "nsIScreenManager.h" #include "nsIScreen.h" +#include "WidgetUtils.h" -class nsScreenAndroid : - public nsIScreen +class nsScreenAndroid + : public nsIScreen + , public mozilla::widget::BrightnessLockingWidget { public: - nsScreenAndroid(void *platformScreen); + nsScreenAndroid(void *nativeScreen); ~nsScreenAndroid(); NS_DECL_ISUPPORTS NS_DECL_NSISCREEN + +protected: + void ApplyMinimumBrightness(PRUint32 aBrightness); }; class nsScreenManagerAndroid :