We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2739 - [Android] No support for SDL_DisableScreenSaver
Summary: [Android] No support for SDL_DisableScreenSaver
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: All Android (All)
: P2 normal
Assignee: Gabriel Jacobo
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-24 11:59 UTC by Martin Gerhardy
Modified: 2014-10-20 20:36 UTC (History)
3 users (show)

See Also:


Attachments
This implements SuspendScreenSaver support for android (16.06 KB, patch)
2014-09-25 06:12 UTC, Martin Gerhardy
Details | Diff
Updated patch (7.87 KB, patch)
2014-10-17 12:59 UTC, Martin Gerhardy
Details | Diff
Updated patch (7.87 KB, patch)
2014-10-17 13:01 UTC, Martin Gerhardy
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Gerhardy 2014-09-24 11:59:22 UTC
Another permission would be needed here.

<uses-permission android:name="android.permission.WAKE_LOCK" />

SDLActivity.java should call

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

enable screensaver would be:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Comment 1 Martin Gerhardy 2014-09-25 06:12:06 UTC
Created attachment 1880 [details]
This implements SuspendScreenSaver support for android

Attached a patch which implements the behaviour.
Comment 2 Philipp Wiesemann 2014-09-25 18:29:08 UTC
(In reply to Martin Gerhardy from comment #1)
> Created attachment 1880 [details]
> This implements SuspendScreenSaver support for android
> 
> Attached a patch which implements the behaviour.

Thank you for providing an implementation.

In this patch is a typo in SDL_androidvideo.c which causes a compile error ("Android_JNI_SuspendScreensaver" should be "Android_JNI_SuspendScreenSaver").

Also I think the WAKE_LOCK permission is not needed as no WakeLocks are used directly. [1][2]

[1] https://developer.android.com/training/scheduling/wakelock.html#screen
[2] http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_KEEP_SCREEN_ON
Comment 3 Martin Gerhardy 2014-09-26 08:07:46 UTC
oh cool - didn't know that. Should i change the patch according to this - or will you do the three changes before applying it?
Comment 4 Gabriel Jacobo 2014-10-16 11:57:13 UTC
I think this is ok, but the patch has a lot of idle changes (spaces for tabs?), can you clean that up so we can incorporate? Thanks!
Comment 5 Martin Gerhardy 2014-10-17 12:59:46 UTC
Created attachment 1901 [details]
Updated patch

removed wakelock permission,

removed most of the whitespace changes
Comment 6 Martin Gerhardy 2014-10-17 13:01:03 UTC
Created attachment 1902 [details]
Updated patch

fixed typo
Comment 7 Gabriel Jacobo 2014-10-20 13:11:51 UTC
Fixed, thanks! https://hg.libsdl.org/SDL/rev/c677ab1148c5
Comment 8 Sylvain 2014-10-20 17:37:00 UTC
Hi, I see some trouble with this change.
Lines might be not sync with trunk, it happens in the suspendScreenSaver() java function

I use ndk-r10c + API level 20


I/SDL     ( 2269): SDL_Android_Init()
I/SDL     ( 2269): SDL_Android_Init() finished!

E/ViewRootImpl( 2269): net.my.app.MainActivity : Only the original thread that created a view hierarchy can touch its views.

E/ViewRootImpl( 2269): java.lang.RuntimeException
E/ViewRootImpl( 2269): 	at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6363)
E/ViewRootImpl( 2269): 	at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:896)
E/ViewRootImpl( 2269): 	at android.view.View.requestLayout(View.java:16585)
E/ViewRootImpl( 2269): 	at android.view.View.setLayoutParams(View.java:10712)
E/ViewRootImpl( 2269): 	at android.view.WindowManagerGlobal.updateViewLayout(WindowManagerGlobal.java:291)
E/ViewRootImpl( 2269): 	at android.view.WindowManagerImpl.updateViewLayout(WindowManagerImpl.java:99)
E/ViewRootImpl( 2269): 	at android.app.Activity.onWindowAttributesChanged(Activity.java:2410)
E/ViewRootImpl( 2269): 	at android.view.Window.setFlags(Window.java:767)
E/ViewRootImpl( 2269): 	at android.view.Window.addFlags(Window.java:721)
E/ViewRootImpl( 2269): 	at org.libsdl.app.SDLActivity.suspendScreenSaver(SDLActivity.java:200)
E/ViewRootImpl( 2269): 	at org.libsdl.app.SDLActivity.nativeInit(Native Method)
E/ViewRootImpl( 2269): 	at org.libsdl.app.SDLMain.run(SDLActivity.java:830)
E/ViewRootImpl( 2269): 	at java.lang.Thread.run(Thread.java:864)





I/DEBUG   (  267): backtrace:
I/DEBUG   (  267):     #00  pc 00022cb0  /system/lib/libc.so (tgkill+12)
I/DEBUG   (  267):     #01  pc 00013cb5  /system/lib/libc.so (pthread_kill+48)
I/DEBUG   (  267):     #02  pc 00013ec9  /system/lib/libc.so (raise+10)
I/DEBUG   (  267):     #03  pc 00012a63  /system/lib/libc.so
I/DEBUG   (  267):     #04  pc 00022564  /system/lib/libc.so (abort+4)
I/DEBUG   (  267):     #05  pc 0004e423  /system/lib/libdvm.so (dvmAbort+110)
I/DEBUG   (  267):     #06  pc 000535bb  /system/lib/libdvm.so (dvmDecodeIndirectRef(Thread*, _jobject*)+290)
I/DEBUG   (  267):     #07  pc 00054cc9  /system/lib/libdvm.so
I/DEBUG   (  267):     #08  pc 000672ef  /system/lib/libandroid_runtime.so (android::android_view_Surface_getSurface(_JNIEnv*, _jobject*)+30)
I/DEBUG   (  267):     #09  pc 0006732f  /system/lib/libandroid_runtime.so (android::android_view_Surface_getNativeWindow(_JNIEnv*, _jobject*)+6)
I/DEBUG   (  267):     #10  pc 00009375  /system/lib/libandroid.so (ANativeWindow_fromSurface+10)
I/DEBUG   (  267):     #11  pc 0003e3e3  /data/app-lib/net.my.app-2/libSDL2.so (Android_JNI_GetNativeWindow+30)
I/DEBUG   (  267):     #12  pc 0008993f  /data/app-lib/net.my.app-2/libSDL2.so (Android_CreateWindow+118)
I/DEBUG   (  267):     #13  pc 00089095  /data/app-lib/net.my.app-2/libSDL2.so (SDL_CreateWindow_REAL+408)
I/DEBUG   (  267):     #14  pc 000480db  /data/app-lib/net.my.app-2/libSDL2.so (SDL_CreateWindow+18)
I/DEBUG   (  267):     #15  pc 00063d6b  /data/app-lib/net.my.app-2/libmain.so (SlWorld::SlWorld()+218)
I/DEBUG   (  267):     #16  pc 0004e0a3  /data/app-lib/net.my.app-2/libmain.so (SDL_main+26)
I/DEBUG   (  267):     #17  pc 0006a1f5  /data/app-lib/net.my.app-2/libmain.so (Java_org_libsdl_app_SDLActivity_nativeInit+204)
I/DEBUG   (  267):     #18  pc 00020a0c  /system/lib/libdvm.so (dvmPlatformInvoke+112)
I/DEBUG   (  267):     #19  pc 00057649  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+428)
I/DEBUG   (  267):     #20  pc 000597d1  /system/lib/libdvm.so (dvmResolveNativeMethod(unsigned int const*, JValue*, Method const*, Thread*)+272)
I/DEBUG   (  267):     #21  pc 00029ea0  /system/lib/libdvm.so
I/DEBUG   (  267):     #22  pc 000327a4  /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
I/DEBUG   (  267):     #23  pc 0002fcc0  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+232)
I/DEBUG   (  267):     #24  pc 0006d52d  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+336)
I/DEBUG   (  267):     #25  pc 0006d551  /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+20)
I/DEBUG   (  267):     #26  pc 0006079f  /system/lib/libdvm.so
I/DEBUG   (  267):     #27  pc 0000d300  /system/lib/libc.so (__thread_entry+72)
I/DEBUG   (  267):     #28  pc 0000d498  /system/lib/libc.so (pthread_create+240)
Comment 9 Philipp Wiesemann 2014-10-20 20:29:31 UTC
(In reply to Sylvain from comment #8)
> Hi, I see some trouble with this change.

The trouble should now be fixed:
https://hg.libsdl.org/SDL/rev/f9244b2a1511

The fault was that setting the Window flags indirectly affects the Views and Views must only be modified on the UI thread. The crash seems not to happen on all versions of Android so maybe what "addFlags()" indirectly causes is differently there. Or different with some AndroidManifest settings.
Comment 10 Sylvain 2014-10-20 20:36:33 UTC
Hi, 
Yes thanks, I confirm this is fixed !


By the way, I have always a rare ANR  in my android report console : 
"ANR Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50000010 }"
Could this be related to the screensaver ?
And/or, could disabling the screensaver solve this?