From 407f42b4e919479e98f38dda19b9373bab57626d Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Thu, 12 Sep 2024 09:31:42 +0200 Subject: [PATCH 1/3] Make OpenGL 3.0 not required --- collect_app/src/main/AndroidManifest.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/collect_app/src/main/AndroidManifest.xml b/collect_app/src/main/AndroidManifest.xml index 00cb93ce1cd..1a50a0ccfe4 100644 --- a/collect_app/src/main/AndroidManifest.xml +++ b/collect_app/src/main/AndroidManifest.xml @@ -26,6 +26,9 @@ the specific language governing permissions and limitations under the License. + From a1ceea57fbdbcac9020f8d8fc7d244945c0662e1 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Thu, 12 Sep 2024 16:00:09 +0200 Subject: [PATCH 2/3] Implemented OpenGLVersionChecker --- .../system/OpenGLVersionChecker.kt | 28 +++++++++++++++++++ .../googlemaps/GoogleMapConfigurator.java | 5 ++-- .../collect/mapbox/MapboxMapConfigurator.java | 6 ++-- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 androidshared/src/main/java/org/odk/collect/androidshared/system/OpenGLVersionChecker.kt diff --git a/androidshared/src/main/java/org/odk/collect/androidshared/system/OpenGLVersionChecker.kt b/androidshared/src/main/java/org/odk/collect/androidshared/system/OpenGLVersionChecker.kt new file mode 100644 index 00000000000..99ddbc053f0 --- /dev/null +++ b/androidshared/src/main/java/org/odk/collect/androidshared/system/OpenGLVersionChecker.kt @@ -0,0 +1,28 @@ +package org.odk.collect.androidshared.system + +import android.app.ActivityManager +import android.content.Context + +/** + * Checks if the device supports the given OpenGL ES version. + * + * Note: This approach may not be 100% reliable because `reqGlEsVersion` indicates + * the highest version of OpenGL ES that the device's hardware is guaranteed to support + * at runtime. However, it might not always reflect the actual version available. + * + * For a more reliable method, refer to https://developer.android.com/develop/ui/views/graphics/opengl/about-opengl#version-check. + * This recommended approach is more complex to implement but offers better accuracy. + */ +object OpenGLVersionChecker { + @JvmStatic + fun isOpenGLv2Supported(context: Context): Boolean { + return (context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) + .deviceConfigurationInfo.reqGlEsVersion >= 0x20000 + } + + @JvmStatic + fun isOpenGLv3Supported(context: Context): Boolean { + return (context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager) + .deviceConfigurationInfo.reqGlEsVersion >= 0x30000 + } +} diff --git a/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java b/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java index 9e4b76999dc..5d82aa1e715 100644 --- a/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java +++ b/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java @@ -4,7 +4,6 @@ import static org.odk.collect.androidshared.ui.PrefUtils.getInt; import static kotlin.collections.SetsKt.setOf; -import android.app.ActivityManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -14,6 +13,7 @@ import com.google.android.gms.maps.GoogleMap; +import org.odk.collect.androidshared.system.OpenGLVersionChecker; import org.odk.collect.androidshared.system.PlayServicesChecker; import org.odk.collect.androidshared.ui.ToastUtils; import org.odk.collect.maps.MapConfigurator; @@ -57,8 +57,7 @@ private static boolean isGooglePlayServicesAvailable(Context context) { private static boolean isGoogleMapsSdkAvailable(Context context) { // The Google Maps SDK for Android requires OpenGL ES version 2. // See https://developers.google.com/maps/documentation/android-sdk/config - return ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) - .getDeviceConfigurationInfo().reqGlEsVersion >= 0x20000; + return OpenGLVersionChecker.isOpenGLv2Supported(context); } @Override public void showUnavailableMessage(Context context) { diff --git a/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java b/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java index 2a173ec51e7..635d6b8f690 100644 --- a/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java +++ b/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java @@ -10,6 +10,7 @@ import com.mapbox.maps.Style; +import org.odk.collect.androidshared.system.OpenGLVersionChecker; import org.odk.collect.androidshared.ui.PrefUtils; import org.odk.collect.androidshared.ui.ToastUtils; import org.odk.collect.maps.MapConfigurator; @@ -42,8 +43,9 @@ public MapboxMapConfigurator() { } @Override public boolean isAvailable(Context context) { - // If the app builds that means mapbox is available - return true; + // The Mapbox SDK for Android requires OpenGL ES version 3. + // See https://github.com/mapbox/mapbox-maps-android/blob/main/CHANGELOG.md#1100-november-29-2023 + return OpenGLVersionChecker.isOpenGLv3Supported(context); } @Override public void showUnavailableMessage(Context context) { From b49a95bd327c318f87c50dc6ad5e2fcf9b945da1 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Thu, 12 Sep 2024 16:02:44 +0200 Subject: [PATCH 3/3] Improved comments --- .../org/odk/collect/googlemaps/GoogleMapConfigurator.java | 6 ++++-- .../java/org/odk/collect/mapbox/MapboxMapConfigurator.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java b/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java index 5d82aa1e715..882a0967295 100644 --- a/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java +++ b/google-maps/src/main/java/org/odk/collect/googlemaps/GoogleMapConfigurator.java @@ -55,8 +55,10 @@ private static boolean isGooglePlayServicesAvailable(Context context) { } private static boolean isGoogleMapsSdkAvailable(Context context) { - // The Google Maps SDK for Android requires OpenGL ES version 2. - // See https://developers.google.com/maps/documentation/android-sdk/config + /* + * The Google Maps SDK for Android requires OpenGL ES version 2. + * See: https://developers.google.com/maps/documentation/android-sdk/config + */ return OpenGLVersionChecker.isOpenGLv2Supported(context); } diff --git a/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java b/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java index 635d6b8f690..aa757526ee0 100644 --- a/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java +++ b/mapbox/src/main/java/org/odk/collect/mapbox/MapboxMapConfigurator.java @@ -43,8 +43,10 @@ public MapboxMapConfigurator() { } @Override public boolean isAvailable(Context context) { - // The Mapbox SDK for Android requires OpenGL ES version 3. - // See https://github.com/mapbox/mapbox-maps-android/blob/main/CHANGELOG.md#1100-november-29-2023 + /* + * The Mapbox SDK for Android requires OpenGL ES version 3. + * See: https://github.com/mapbox/mapbox-maps-android/blob/main/CHANGELOG.md#1100-november-29-2023 + */ return OpenGLVersionChecker.isOpenGLv3Supported(context); }