Mitigate Talkback crash

This commit is contained in:
Aleksandras Kostarevas 2024-07-13 04:47:07 +03:00
parent 593ac9e35e
commit df6efc760e

View File

@ -17,6 +17,7 @@
package org.futo.inputmethod.accessibility;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
@ -153,12 +154,29 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
@Override
protected void onPopulateNodeForVirtualView(int virtualViewId, @NonNull AccessibilityNodeInfoCompat node) {
Key k = getKeyOf(virtualViewId);
if(k == null) return;
if(k == null) {
// TODO: For some reason, sometimes this is null and crashes.
// Just set this to something to prevent crash
Log.e(TAG, "Invalid virtual view id " + virtualViewId);
node.setContentDescription("Unknown");
node.setBoundsInParent(new Rect(0, 0, 0, 0));
node.setFocusable(false);
node.setScreenReaderFocusable(false);
return;
}
node.setClassName(android.inputmethodservice.Keyboard.Key.class.getName());
String description = getKeyDescription(k);
if(description == null || description.isBlank()) {
Log.e(TAG, "Invalid key has blank description: " + k.toLongString());
description = "Unknown";
}
node.setContentDescription(description);
node.setBoundsInParent(k.getHitBox());