-
Notifications
You must be signed in to change notification settings - Fork 82
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
[w.i.p.] isWifiEnabled and isFullscreen use JNI:callBooleanMethod #73
[w.i.p.] isWifiEnabled and isFullscreen use JNI:callBooleanMethod #73
Conversation
That code change didn't help:
"android.lua" line 1050:
Is that the reason why nobody used callBooleanMethod before? :( Does any one know how what's wrong here? |
assets/android.lua
Outdated
@@ -1360,7 +1360,7 @@ local function run(android_app_state) | |||
end | |||
android.isFullscreen = function() | |||
return JNI:context(android.app.activity.vm, function(JNI) | |||
local fullscreen = JNI:callIntMethod( | |||
local fullscreen = JNI:callBooleanMethod( | |||
android.app.activity.clazz, | |||
"isFullscreen", | |||
"()Z" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be something like B then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean "()B" instead "()Z" ?
It's completely unreadable for me where it came from and what it does mean :(
If it caught my change the result is the same:
10-23 21:31:42.706 4577 4593 E luajit-launcher: Failed to run script: [string "android.lua"]:1050: 'struct JNINativeInterface' has no member named 'callBooleanMethod'
10-23 21:31:42.712 4577 4593 V threaded_app: android_app_destroy!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have overlooked doc for that. If there's such?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pardon, B is byte and Z is boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just "Z" or "()Z" or "Z()"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, please link directly to the line. It's clearer. :-) You should change it to a capital C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On line 1050.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just "Z" or "()Z" or "Z()"?
No it's good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my earlier brevity; I was on my phone in a slight hurry but I wanted to give you something useful to work with in case you were still looking at it.
Anyway, it should be fine if you fix it to an uppercase C on the line you mentioned.
android-luajit-launcher/assets/android.lua
Line 1050 in bd88561
return self.env[0].callBooleanMethod(self.env, object, methodID, ...) |
I apologize if I was confusing, but it's this line: android-luajit-launcher/assets/android.lua Line 1050 in bd88561
That has to be changed to The other line is the line I mentioned, not the one you mentioned. ;-) |
I did a quick test and something still seems not ok:
at least on 686 emulator (android 5.1) It doesn't throw any expection, but return is missing. There's a workaround to use int as @Frenzie is it time to try workaround? Or do you have any ideas what else might be wrong? |
same result for isFullscreen:
|
I suspect you'll need to cast this Presumably it'll give you these values android-luajit-launcher/assets/android.lua Lines 772 to 773 in bd88561
There's a to_string. android-luajit-launcher/assets/android.lua Lines 1099 to 1104 in bd88561
We'd probably have to add to_bool. So you could fix it up properly if you want to. (I don't particularly feel like looking at that for the moment.) But I think it's fine if you just keep the typo correction on CallBooleanMethod for the moment and use the int workaround for now. It doesn't look too horrible. :-) |
Changed to This can mean there's an issue in Java implementation, but it was just done excalty as on some recipes on internet (or issue with emulator?). Maybe it's again Java code has to be wrapped with something? Any way if it's java issue then we would be able to uncommit ab96312 |
Oh, I thought you meant you'd already tested the int method. For wifi I would only trust results from a real device, although I would probably expect it to always return I don't have a working Android knowledge or anything. I only know various things that go into Android (such as XML and Java). But from browsing around the docs real quick it could be that you should use different methods for Android <4.4 and Android 4.4+. API 16https://developer.android.com/training/system-ui/immersive.html API 1https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN Basically like this (should've checked our own code before checking the docs) except get instead of set android-luajit-launcher/src/org/koreader/launcher/MainActivity.java Lines 45 to 61 in ab96312
|
I checked it using 5.1 emulator which is api 22 so should work. I checked setFullscreen and setWifiEnabled, it was working fine. Must have overlooked the isWifiEnabled and isFulscreen. Sorry. BTW as far as I remember the setFullscreenLayout was after my full screen commit. It seems to be the same issue. In android.lua or MainActivity.java. At least I can see now no difference between isCharging is Fullscreen and isWiFienabled... |
Okay, but we want to keep things working on API 9 and up unless there's a really good reason not to. Doesn't your own Android reader come with Android API <16? ;-)
It was structured differently but it was there from the first time the Java layer was added in cb6deb8 (with a slight mistake fixed in 655bf22). |
public boolean isFullscreen() { | ||
return (getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; | ||
public int isFullscreen() { | ||
return ((getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) ? 1: 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be &&
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
& is a Java low level (bit) comparison as far as I remember from couple years back, Java trainings. It's almost not used in plain Java. Never had a chance to see it in real code.
But did seen it in android.
Also if this was the issue it should return at least false.
I'll double check if it's not the case..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, it's bitwise AND to extract the flag. Makes sense, although it seems more like a C kind of thing than something you'd expect to see in Java.
This was a problem with x86 emulator. Works on ARM. Please merge. I'll push new PR for API 11 Fullscreen |
It's fine if it doesn't work but does it also not crash? :-P |
emulator x86 = doesn't crash, doesn't work :( arm = doesn't crash, works;) |
I meant API-wise, sorry for the confusion. Edit: well, I suppose I meant both arch and API. I'll look into setting up some Android unit tests to prevent regressions (we currently only test if it builds) but I'm not entirely sure how yet. Part of the problem is that it'll take 20 minutes or more, so they can't quite be made part of the regular CI. Maybe something involving a Gitlab mirror… |
* Also fix callBoolean method typo
in response to koreader/koreader#3396 (review)
Commit from phone.
needs testing