Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index 8b6c8e9..20920c9 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -187,6 +187,13 @@ public class SDLActivity extends Activity {
return super.dispatchKeyEvent(event);
}
+ public static void suspendScreenSaver(boolean suspend) {
+ if (suspend)
+ mSingleton.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ else
+ mSingleton.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ }
+
/** Called by onPause or surfaceDestroyed. Even if surfaceDestroyed
* is the first to be called, mIsSurfaceReady should still be set
* to 'true' during the call to onPause (in a usual scenario).
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index cf282f4..a998499 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -77,6 +77,7 @@ static jmethodID midAudioWriteShortBuffer;
static jmethodID midAudioWriteByteBuffer;
static jmethodID midAudioQuit;
static jmethodID midPollInputDevices;
+static jmethodID midSuspendScreenSaver;
/* Accelerometer data storage */
static float fLastAccelerometer[3];
@@ -131,6 +132,8 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
"audioQuit", "()V");
midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
"pollInputDevices", "()V");
+ midSuspendScreenSaver = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
+ "suspendScreenSaver", "(Z)V");
bHasNewData = false;
@@ -444,7 +447,13 @@ static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder)
static SDL_bool LocalReferenceHolder_IsActive()
{
- return s_active > 0;
+ return s_active > 0;
+}
+
+void Android_JNI_SuspendScreenSaver(SDL_bool suspend)
+{
+ JNIEnv *env = Android_JNI_GetEnv();
+ (*env)->CallStaticObjectMethod(env, mActivityClass, midSuspendScreenSaver, suspend);
}
ANativeWindow* Android_JNI_GetNativeWindow(void)
diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h
index 1294cd9..051958a 100644
--- a/src/core/android/SDL_android.h
+++ b/src/core/android/SDL_android.h
@@ -68,6 +68,8 @@ int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seco
/* Joystick support */
void Android_JNI_PollInputDevices();
+/* Video */
+void Android_JNI_SuspendScreenSaver(SDL_bool suspend);
/* Touch support */
int Android_JNI_GetTouchDeviceIds(int **ids);
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index 0ff6717..05c0753 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -76,6 +76,12 @@ Android_Available(void)
}
static void
+Android_SuspendScreenSaver(_THIS)
+{
+ Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
+}
+
+static void
Android_DeleteDevice(SDL_VideoDevice * device)
{
SDL_free(device);
@@ -126,6 +132,9 @@ Android_CreateDevice(int devindex)
device->GL_SwapWindow = Android_GLES_SwapWindow;
device->GL_DeleteContext = Android_GLES_DeleteContext;
+ /* Screensaver */
+ device->SuspendScreenSaver = Android_SuspendScreenSaver;
+
/* Text input */
device->StartTextInput = Android_StartTextInput;
device->StopTextInput = Android_StopTextInput;