diff --git a/src/corelib/global/qoperatingsystemversion.cpp b/src/corelib/global/qoperatingsystemversion.cpp index a89cfa88d2..bb29a6b1a0 100644 --- a/src/corelib/global/qoperatingsystemversion.cpp +++ b/src/corelib/global/qoperatingsystemversion.cpp @@ -15,6 +15,7 @@ #include #ifdef Q_OS_ANDROID +#include #include #endif @@ -179,11 +180,13 @@ QOperatingSystemVersionBase QOperatingSystemVersionBase::current_impl() { 9, 0 }, // API level 28 { 10, 0 }, // API level 29 { 11, 0 }, // API level 30 + { 12, 0 }, // API level 31 + { 12, 0 }, // API level 32 + { 13, 0 }, // API level 33 }; // This will give us at least the first 2 version components - const size_t versionIdx = size_t(QJniObject::getStaticField( - "android/os/Build$VERSION", "SDK_INT")) - 1; + const size_t versionIdx = QtAndroidPrivate::androidSdkVersion() - 1; if (versionIdx < sizeof(versions) / sizeof(versions[0])) { version.m_major = versions[versionIdx].major; version.m_minor = versions[versionIdx].minor; @@ -657,6 +660,32 @@ const QOperatingSystemVersion QOperatingSystemVersion::Android10 = const QOperatingSystemVersion QOperatingSystemVersion::Android11 = QOperatingSystemVersion(QOperatingSystemVersion::Android, 11, 0); +/*! + \variable QOperatingSystemVersion::Android12 + \brief a version corresponding to Android 12 (version 12.0, API level 31). + \since 6.5 + */ +const QOperatingSystemVersion QOperatingSystemVersion::Android12 = + QOperatingSystemVersion(QOperatingSystemVersion::Android, 12, 0); + +/*! + \variable QOperatingSystemVersion::Android12L + \brief a version corresponding to Android 12L (version 12.0, API level 32). + \since 6.5 + */ +const QOperatingSystemVersion QOperatingSystemVersion::Android12L = + QOperatingSystemVersion(QOperatingSystemVersion::Android, 12, 0); + +/*! + \variable QOperatingSystemVersion::Android13 + \brief a version corresponding to Android 13 (version 13.0, API level 33). + \since 6.5 + */ +const QOperatingSystemVersion QOperatingSystemVersion::Android13 = + QOperatingSystemVersion(QOperatingSystemVersion::Android, 13, 0); + + + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const QOperatingSystemVersion &ov) { diff --git a/src/corelib/global/qoperatingsystemversion.h b/src/corelib/global/qoperatingsystemversion.h index 5fcc3411de..d6fee2980c 100644 --- a/src/corelib/global/qoperatingsystemversion.h +++ b/src/corelib/global/qoperatingsystemversion.h @@ -152,6 +152,9 @@ public: static const QOperatingSystemVersion AndroidPie; static const QOperatingSystemVersion Android10; static const QOperatingSystemVersion Android11; + static const QOperatingSystemVersion Android12; + static const QOperatingSystemVersion Android12L; + static const QOperatingSystemVersion Android13; #else static constexpr QOperatingSystemVersionBase Windows7 { QOperatingSystemVersionBase::Windows, 6, 1 }; static constexpr QOperatingSystemVersionBase Windows8 { QOperatingSystemVersionBase::Windows, 6, 2 }; @@ -186,6 +189,9 @@ public: static constexpr QOperatingSystemVersionBase AndroidPie { QOperatingSystemVersionBase::Android, 9, 0 }; static constexpr QOperatingSystemVersionBase Android10 { QOperatingSystemVersionBase::Android, 10, 0 }; static constexpr QOperatingSystemVersionBase Android11 { QOperatingSystemVersionBase::Android, 11, 0 }; + static constexpr QOperatingSystemVersionBase Android12 { QOperatingSystemVersionBase::Android, 12, 0 }; + static constexpr QOperatingSystemVersionBase Android12L { QOperatingSystemVersionBase::Android, 12, 0 }; + static constexpr QOperatingSystemVersionBase Android13 { QOperatingSystemVersionBase::Android, 13, 0 }; #endif // New (static constexpr) entries go here, only cherry-pick as far back as 6.3 (QTBUG-97808): static constexpr QOperatingSystemVersionBase Windows10_1809 { QOperatingSystemVersionBase::Windows, 10, 0, 17763 }; // RS5 diff --git a/src/corelib/global/qsysinfo.cpp b/src/corelib/global/qsysinfo.cpp index 6e9f8a0eea..a06a85b641 100644 --- a/src/corelib/global/qsysinfo.cpp +++ b/src/corelib/global/qsysinfo.cpp @@ -16,6 +16,7 @@ #endif #ifdef Q_OS_ANDROID +#include #include #endif @@ -408,65 +409,65 @@ static bool findUnixOsVersion(QUnixOSVersion &v) #ifdef Q_OS_ANDROID static const char *osVer_helper(QOperatingSystemVersion) { -/* Data: - - - -Cupcake -Donut -Eclair -Eclair -Eclair -Froyo -Gingerbread -Gingerbread -Honeycomb -Honeycomb -Honeycomb -Ice Cream Sandwich -Ice Cream Sandwich -Jelly Bean -Jelly Bean -Jelly Bean -KitKat -KitKat -Lollipop -Lollipop -Marshmallow -Nougat -Nougat -Oreo -*/ - static const char versions_string[] = - "\0" - "Cupcake\0" - "Donut\0" - "Eclair\0" - "Froyo\0" - "Gingerbread\0" - "Honeycomb\0" - "Ice Cream Sandwich\0" - "Jelly Bean\0" - "KitKat\0" - "Lollipop\0" - "Marshmallow\0" - "Nougat\0" - "Oreo\0" - "\0"; - - static const int versions_indices[] = { - 0, 0, 0, 1, 9, 15, 15, 15, - 22, 28, 28, 40, 40, 40, 50, 50, - 69, 69, 69, 80, 80, 87, 87, 96, - 108, 108, 115, -1 - }; - - static const int versions_count = (sizeof versions_indices) / (sizeof versions_indices[0]); - // https://source.android.com/source/build-numbers.html // https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels - const int sdk_int = QJniObject::getStaticField("android/os/Build$VERSION", "SDK_INT"); - return &versions_string[versions_indices[qBound(0, sdk_int, versions_count - 1)]]; + const int sdk_int = QtAndroidPrivate::androidSdkVersion(); + switch (sdk_int) { + case 3: + return "Cupcake"; + case 4: + return "Donut"; + case 5: + case 6: + case 7: + return "Eclair"; + case 8: + return "Froyo"; + case 9: + case 10: + return "Gingerbread"; + case 11: + case 12: + case 13: + return "Honeycomb"; + case 14: + case 15: + return "Ice Cream Sandwich"; + case 16: + case 17: + case 18: + return "Jelly Bean"; + case 19: + case 20: + return "KitKat"; + case 21: + case 22: + return "Lollipop"; + case 23: + return "Marshmallow"; + case 24: + case 25: + return "Nougat"; + case 26: + case 27: + return "Oreo"; + case 28: + return "Pie"; + case 29: + return "10"; + case 30: + return "11"; + case 31: + return "12"; + case 32: + return "12L"; + case 33: + return "13"; + default: + break; + } + + return ""; } #endif