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>
This commit is contained in:
Edward Welbourne 2018-06-15 11:35:00 +02:00 committed by Mårten Nordheim
parent 4361c0ee84
commit 4fa8dfee5d

View File

@ -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;