From 2cba33901bfc4cbd86334c2484e78b61f131dcf5 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 15 Mar 2016 12:03:41 +0100 Subject: [PATCH] Android: Support PasswordMaskDelay It is only set if the "Show passwords" option in Android's security settings is enabled, the value is not updated at runtime as this option isn't likely to be changed frequently, if at all. The value of 1.5s is hardcoded in Android's PasswordTransformationMethod. [ChangeLog][Android] Show password while typing is now supported Task-number: QTBUG-48948 Change-Id: I9209b68c8684b825be196e8d0afd37cb0e0d141d Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Jason Erb --- .../platforms/android/qandroidplatformintegration.cpp | 11 +++++++++++ .../platforms/android/qandroidplatformintegration.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index 80d7e31aa3..c0a2b2c578 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -80,6 +80,8 @@ Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::Pri Qt::ApplicationState QAndroidPlatformIntegration::m_defaultApplicationState = Qt::ApplicationActive; +bool QAndroidPlatformIntegration::m_showPasswordEnabled = false; + void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteArray &resource) { if (resource=="JavaVM") @@ -191,6 +193,12 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶ } QWindowSystemInterface::registerTouchDevice(m_touchDevice); } + + auto contentResolver = javaActivity.callObjectMethod("getContentResolver", "()Landroid/content/ContentResolver;"); + Q_ASSERT(contentResolver.isValid()); + m_showPasswordEnabled = QJNIObjectPrivate::callStaticMethod("android/provider/Settings$System", "getInt", + "(Landroid/content/ContentResolver;Ljava/lang/String;)I", contentResolver.object(), + QJNIObjectPrivate::getStaticObjectField("android/provider/Settings$System", "TEXT_SHOW_PASSWORD", "Ljava/lang/String;").object()) > 0; } QGuiApplicationPrivate::instance()->setApplicationState(m_defaultApplicationState); @@ -313,6 +321,9 @@ QPlatformServices *QAndroidPlatformIntegration::services() const QVariant QAndroidPlatformIntegration::styleHint(StyleHint hint) const { switch (hint) { + case PasswordMaskDelay: + // this number is from a hard-coded value in Android code (cf. PasswordTransformationMethod) + return m_showPasswordEnabled ? 1500 : 0; case ShowIsMaximized: return true; default: diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h index 1f06c23d0b..bda0bee9ad 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.h +++ b/src/plugins/platforms/android/qandroidplatformintegration.h @@ -143,6 +143,8 @@ private: static Qt::ApplicationState m_defaultApplicationState; + static bool m_showPasswordEnabled; + QPlatformFontDatabase *m_androidFDB; QAndroidPlatformNativeInterface *m_androidPlatformNativeInterface; QAndroidPlatformServices *m_androidPlatformServices;