rkkr / simple-keyboard

Apache License 2.0
1.1k stars 219 forks source link

Rare glitch where empty background fills entire screen #272

Open digitalheir opened 3 years ago

digitalheir commented 3 years ago

Screenshot_20210425-000719

I've had it occur a couple of times that the keyboard opens and does not seem to inflate the actual keyboard or something, the entire screen is filled with the background color. The issue is not terrible, because I can just dismiss the keyboard and open it again. Do you have any idea what might cause it?

rkkr commented 3 years ago

When app is reinstalled/upgraded the first click in the text field doesn't open it. But there is nothing of the sorts of keyboard background being drawn. So I doubt that it's the same thing. Also second click in the text field always opens it.

Some more hints would be needed how to reproduce it or a logcat.

rkkr commented 3 years ago

Also is it only one app that this happens in? I don't see any fields for text input in the screenshot.

digitalheir commented 3 years ago

When app is reinstalled/upgraded the first click in the text field doesn't open it.

I think this is different. The keyboard is open: the Android 10 system UI for closing the keyboard appears on the bottom left and right and the light grey color matches the keyboard white style

is it only one app

The app doesn't seem to matter. You don't see a text input because the keyboard layout obscures everything. It happens only when the keyboard loads the first time (I guess when onCreateInputView performs), but only sometimes and seemingly randomly so it's kind of difficult to reproduce and isolate.

I'm guessing the Android system gives rkr.simplekeyboard.inputmethod.latin.InputView very weird container params, maybe extremely tall, causing the entire screen to be filled.

I think I should add log the layout measurements so I can replay the parameters whenever this happens again.

rkkr commented 3 years ago

Height of the keyboard is controlled by the keyboard itself. There's something more interesting than that happening.

It happens only when the keyboard loads the first time

First time after what? Restart? Update? Force Close? If it's the first cold start then this could be the same issue, with the only difference being that instead of no View being shown in my side, it shows a blank full screen one in your side.

digitalheir commented 3 years ago

I've just had the non-opening thing you were talking about occur. It feels like it occurs under the same condition, but indeed it is different because the keyboard is not loaded at all (and then does show up with a second tap in the text field). My initial report was about the case where the keyboard is loaded but somehow incorrectly.

Height of the keyboard is controlled by the keyboard itself. There's something more interesting than that happening.

I see the main layout has layout_height="wrap_content". So I guess something inside the KeyboardView would report screen-filling size.. It's so odd.

First time after what?

I think when the keyboard process starts, it never seems to happen when the keyboard is dismissed and reappears (except if it was replaced by another keyboard for so long that I expect the system to have cleared SimpleKeyboard from memory; because there is always a lag before the keyboard opens in this case where the system need to initialize all resources)

digitalheir commented 3 years ago

Just some speculation: this issue is maybe device-specific or specific to Android 10+. I know the Android team is working on IME visibility measurements (WindowInsets API). I have tried to use the keyboard for a day on Xiaomi A1 with Android 9, and this issue never occurred. On Fairphone 3 with Android 10 it regularly occurs.

It could also be a Fairphone-specific bug. I've had seemingly phone-specific glitches occur in other apps before, but none so severe.

I also found the updateSoftInputWindowLayoutParameters method gives me some control. Here the system-provided input area / window for the IME is manipulated. I've tried to set the window height param to LayoutParams.WRAP CONTENT instead of MATCH_PARENT. The keyboard then always renders correctly on first glance, but the preview popup is clipped on top, so not a solution. I'm a bit out of my depth here...

digitalheir commented 3 years ago

I've opened the Layout Inspector to see what was going on with the views. Indeed, the background I see is filled by KeyboardView (with height param WRAP_CONTENT!!)

I've tried to log the onMeasure params, and I guess this is the problem:

2021-04-29 11:38:18.130 KB: setMeasuredDimension(1080, 667)
2021-04-29 11:38:18.178 KB: setMeasuredDimension(1080, 667)
2021-04-29 11:38:18.462 KB: super.onMeasure(width=MeasureSpec(1073742904; mode=EXACTLY, size=1080), height=MeasureSpec(-2147481704; mode=AT_MOST, size=1944))
2021-04-29 11:38:18.486 KB: super.onMeasure(width=MeasureSpec(1073742904; mode=EXACTLY, size=1080), height=MeasureSpec(-2147481704; mode=AT_MOST, size=1944))

with breakpoints, I was able to verify that the second case produces this glitch. Super is called if KeyboardView.keyboard is null. (Oddly, it is not null before..? Will try to trace this later to see why it becomes null)

We read in KeyboardView.java:

    // Main keyboard
    // TODO: Consider having a dummy keyboard object to make this @NonNull
    private Keyboard mKeyboard;

Maybe a good idea to ensure it is never null!

rkkr commented 3 years ago

Tested locally and mKeyboard is never null. Not even when it doesn't start the first time after update.

Fixing this problem might require splitting Main and Popup Views. Now they share the same layout and view, even thou they work totally differently. But first you'll have to find where this comes from. Won't be the first time when issue is caused by a bug in OS.

digitalheir commented 3 years ago

It really looks like it. The only idea I have now is that the keyboard object is garbage collected erroneously: I could not find a place where it was assigned null. It makes little sense.

Won't be the first time when issue is caused by a bug in OS.

Specifically FairphoneOS is known to be quite buggy all-round. For a taste:

https://forum.fairphone.com/t/known-bugs-problems-with-android-10/64330

Since the glitch did not occur on my other phone, and I can live with it happening sometimes, maybe we should park this issue until someone else encounters it.

llyando commented 3 years ago

I have encountered this issue from time to time. I am using v6.21.2 v5.4 of the app on Android 11. Nothing more to add that hasn't already been mentioned previously.

Edit: put in wrong version.

rkkr commented 3 years ago

There's no such version: https://github.com/rkkr/simple-keyboard/releases

llyando commented 3 years ago

Ah, apologies. I was looking at the simple gallery app version. Updated my prior comment to reflect correct version, 5.4.