diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-06-15 11:35:00 +0200 |
---|---|---|
committer | MÃ¥rten Nordheim <marten.nordheim@qt.io> | 2018-06-22 13:06:14 +0000 |
commit | 4fa8dfee5dd31433d22fdb449c1783e256931c8f (patch) | |
tree | 703220d63d2b3bbcafdbf8375167b1ebdd140097 /src/corelib/tools/qtimezoneprivate_android.cpp | |
parent | 4361c0ee846fb5574a05534186a01779a5e0bb82 (diff) |
Leave m_id clear if the JNI didn't give us a time-zone
QTimeZonePrivate::isValid() just checks m_id is non-empty; so we have
to leave m_id clear if we don't get a valid time-zone back when we ask
the JNI for one. Unfortunately, JNI gives us a "valid" default zone
if it doesn't recognize the given name; so check the known names of
this zone (or of zones with its offset); if the given ianaId isn't one
of them, assume this is a bogus zone.
Task-number: QTBUG-68842
Change-Id: I6245db18c59c4261ed5fcd4d948dd773365ce61d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qtimezoneprivate_android.cpp')
-rw-r--r-- | src/corelib/tools/qtimezoneprivate_android.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/corelib/tools/qtimezoneprivate_android.cpp b/src/corelib/tools/qtimezoneprivate_android.cpp index c3f8c3e0d9..b60093617f 100644 --- a/src/corelib/tools/qtimezoneprivate_android.cpp +++ b/src/corelib/tools/qtimezoneprivate_android.cpp @@ -82,7 +82,24 @@ void QAndroidTimeZonePrivate::init(const QByteArray &ianaId) QJNIObjectPrivate jo_ianaId = QJNIObjectPrivate::fromString( QString::fromUtf8(ianaId) ); androidTimeZone = QJNIObjectPrivate::callStaticObjectMethod( "java.util.TimeZone", "getTimeZone", "(Ljava/lang/String;)Ljava/util/TimeZone;", static_cast<jstring>(jo_ianaId.object()) ); - if (ianaId.isEmpty()) + // Painfully, JNI gives us back a default zone object if it doesn't + // recognize the name; so check for whether ianaId is a recognized name of + // the zone object we got and ignore the zone if not. + bool found = false; + // Try checking ianaId against getID(), getDisplayName(): + QJNIObjectPrivate jname = androidTimeZone.callObjectMethod("getID", "()Ljava/lang/String;"); + found = (jname.toString().toUtf8() == ianaId); + for (int style = 1; !found && style-- > 0;) { + for (int dst = 1; !found && dst-- > 0;) { + jname = androidTimeZone.callObjectMethod("getDisplayName", "(ZI;)Ljava/lang/String;", + bool(dst), style); + found = (jname.toString().toUtf8() == ianaId); + } + } + + if (!found) + m_id.clear(); + else if (ianaId.isEmpty()) m_id = systemTimeZoneId(); else m_id = ianaId; |