Android: Avoid deadlock in Qt.inputMethod.visible

A blocking isSoftwareKeyboardVisible() is a deadlock
waiting to happen: when the android input method performs
blocking metacalls from the android thread to the GUI
thread all the time, we cannot block the GUI thread
waiting for the android thread.

Task-number: QTBUG-40750
Change-Id: I2490897b0f65e0d92214907e239b10b372d949dd
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
Paul Olav Tvete 2014-09-01 13:27:23 +02:00
parent f6c36917f1
commit b9a7cedb6e
3 changed files with 4 additions and 36 deletions

View File

@ -361,11 +361,6 @@ public class QtActivityDelegate
});
}
public boolean isSoftwareKeyboardVisible()
{
return m_keyboardIsVisible;
}
String getAppIconSize(Activity a)
{
int size = a.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);

View File

@ -397,25 +397,6 @@ public class QtNative
});
}
private static boolean isSoftwareKeyboardVisible()
{
final Semaphore semaphore = new Semaphore(0);
final Boolean[] ret = {false};
runAction(new Runnable() {
@Override
public void run() {
ret[0] = m_activityDelegate.isSoftwareKeyboardVisible();
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
e.printStackTrace();
}
return ret[0];
}
private static void setFullScreen(final boolean fullScreen)
{
runAction(new Runnable() {

View File

@ -59,10 +59,10 @@ namespace QtAndroidInput
static jmethodID m_showSoftwareKeyboardMethodID = 0;
static jmethodID m_resetSoftwareKeyboardMethodID = 0;
static jmethodID m_hideSoftwareKeyboardMethodID = 0;
static jmethodID m_isSoftwareKeyboardVisibleMethodID = 0;
static jmethodID m_updateSelectionMethodID = 0;
static bool m_ignoreMouseEvents = false;
static bool m_softwareKeyboardVisible = false;
static QList<QWindowSystemInterface::TouchPoint> m_touchPoints;
@ -125,15 +125,7 @@ namespace QtAndroidInput
bool isSoftwareKeyboardVisible()
{
AttachedJNIEnv env;
if (!env.jniEnv)
return false;
bool visibility = env.jniEnv->CallStaticBooleanMethod(applicationClass(), m_isSoftwareKeyboardVisibleMethodID);
#ifdef QT_DEBUG_ANDROID_IM_PROTOCOL
qDebug() << "@@@ ISSOFTWAREKEYBOARDVISIBLE" << visibility;
#endif
return visibility;
return m_softwareKeyboardVisible;
}
@ -714,8 +706,9 @@ namespace QtAndroidInput
false);
}
static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean /*visibility*/)
static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean visibility)
{
m_softwareKeyboardVisible = visibility;
QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext();
if (inputContext && qGuiApp)
inputContext->emitInputPanelVisibleChanged();
@ -756,7 +749,6 @@ namespace QtAndroidInput
GET_AND_CHECK_STATIC_METHOD(m_showSoftwareKeyboardMethodID, appClass, "showSoftwareKeyboard", "(IIIII)V");
GET_AND_CHECK_STATIC_METHOD(m_resetSoftwareKeyboardMethodID, appClass, "resetSoftwareKeyboard", "()V");
GET_AND_CHECK_STATIC_METHOD(m_hideSoftwareKeyboardMethodID, appClass, "hideSoftwareKeyboard", "()V");
GET_AND_CHECK_STATIC_METHOD(m_isSoftwareKeyboardVisibleMethodID, appClass, "isSoftwareKeyboardVisible", "()Z");
GET_AND_CHECK_STATIC_METHOD(m_updateSelectionMethodID, appClass, "updateSelection", "(IIII)V");
return true;
}