Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Keep Screen On" not working as expected on Android #67034

Closed
ehsanngp opened this issue Oct 7, 2022 · 8 comments · Fixed by #68786
Closed

"Keep Screen On" not working as expected on Android #67034

ehsanngp opened this issue Oct 7, 2022 · 8 comments · Fixed by #68786

Comments

@ehsanngp
Copy link

ehsanngp commented Oct 7, 2022

Godot version

4.0 Beta 2

System information

Ubuntu 16.04

Issue description

Keep Screen On option in Project Settings > Display > Window has no effect on exported Android builds. The issue was present from the first Alpha release of Godot 4.0 that I tested (4.0 Alpha 6)

Steps to reproduce

  1. Create a mobile project, got to Project Settings > Display > Window. Check Keep Screen On option.
  2. Export and run the project on Android device.
  3. The screen turns off after default screen timeout of Android.

Minimal reproduction project

No response

@Calinou
Copy link
Member

Calinou commented Oct 7, 2022

Keep Screen On is supposed to be implemented on Android: #18683

Does it work in 3.5? Also, which device did you test this on (and which Android version is it running)?

@Calinou Calinou changed the title [Android] 'Keep Screen On' not working as expected. "Keep Screen On" not working as expected on Android Oct 7, 2022
@ehsanngp
Copy link
Author

ehsanngp commented Oct 7, 2022

Have not tested it on Godot 3.5, but was working on 3.2 (not sure about version, but it was diffidently working in some prev version).
I have tested this particular bug on Android 10 & 11, both on Xiaomi Mi A3.

I can test on other devices too, but as far as I have searched by grep, I could not find any known implementation of "Keep Screen On" not on XML nor Java part of compiled templates, so my best guess is that there should be basically absent from generated code somehow.

@RendersJens
Copy link

Hi, I have the same issue, Android 11 on Samsung galaxy tab A8, Godot 4 beta 4 running on Ubuntu 22.04.

@Calinou
Copy link
Member

Calinou commented Nov 16, 2022

Relevant source code:

public void setKeepScreenOn(final boolean p_enabled) {
runOnUiThread(() -> {
if (p_enabled) {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}

setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));

I wonder why "True" has an uppercase "T" here…

@Calinou Calinou added this to the 4.0 milestone Nov 16, 2022
@ehsanngp
Copy link
Author

ehsanngp commented Nov 17, 2022

Relevant source code:

public void setKeepScreenOn(final boolean p_enabled) {
runOnUiThread(() -> {
if (p_enabled) {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}

setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));

I wonder why "True" has an uppercase "T" here…

That should be the root cause ...

@akien-mga
Copy link
Member

akien-mga commented Nov 17, 2022

setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));

I wonder why "True" has an uppercase "T" here…

Seems like getGlobal() in Java always returns a string and not a Variant, so it depends on the Variant to String conversion.

JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path) {
        String js = jstring_to_string(path, env);

        return env->NewStringUTF(GLOBAL_GET(js).operator String().utf8().get_data());
}

We used the print booleans as True and False, and this changed in Godot 4.0, so this code is now broken.

It's pretty brittle to rely on such String conversion, but I imagine it's not easy / worth the effort to reimplement a Variant equivalent in Java just for this.

@RendersJens
Copy link

We used the print booleans as True and False, and this changed in Godot 4.0, so this code is now broken.

It's pretty brittle to rely on such String conversion, but I imagine it's not easy / worth the effort to reimplement a Variant equivalent in Java just for this.

Ah so since Godot 4.0, the string representation of bools has changed? This kind of bug could quickly be avoided by replacing the hard coded "True" with the similar conversion of the Godot bool true to string then, e.g. another output of getGlobal?

@akien-mga
Copy link
Member

akien-mga commented Nov 17, 2022

Yes just changing "True" to "true" in the code Calinou linked should be sufficient. If you can test it, then feel free to make a PR with that fix.

And checking the only other use of getGlobal, I found the reason for #68048 too, I'll make a PR to fix both.
Edit: may have found the reason, still need to look into it more.
Edit 2: Yeah the problem is not about parsing the setting, this works fine. It fails actually initializing OpenGL.

anvilfolk pushed a commit to anvilfolk/godot that referenced this issue Dec 1, 2022
Boolean stringification changed in Godot 4.0.

Fixes godotengine#67034.

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
rohanrhu pushed a commit to rohanrhu/godot that referenced this issue Dec 19, 2022
Boolean stringification changed in Godot 4.0.

Fixes godotengine#67034.

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
rohanrhu pushed a commit to rohanrhu/godot that referenced this issue Dec 28, 2022
Boolean stringification changed in Godot 4.0.

Fixes godotengine#67034.

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
rohanrhu pushed a commit to rohanrhu/godot that referenced this issue Dec 28, 2022
Boolean stringification changed in Godot 4.0.

Fixes godotengine#67034.

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
Streq pushed a commit to Streq/godot that referenced this issue Feb 9, 2023
Boolean stringification changed in Godot 4.0.

Fixes godotengine#67034.

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants