Skip to content

Commit

Permalink
Merge pull request #6411 from grzesiek2010/COLLECT-6410
Browse files Browse the repository at this point in the history
Don't require OpenGL 3.0
  • Loading branch information
lognaturel authored Sep 12, 2024
2 parents ab2857a + b49a95b commit 4dbe61e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions collect_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ the specific language governing permissions and limitations under the License.
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:glEsVersion="0x00030000"
android:required="false" />

<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -55,10 +55,11 @@ 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;
/*
* 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);
}

@Override public void showUnavailableMessage(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,8 +43,11 @@ 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) {
Expand Down

0 comments on commit 4dbe61e

Please sign in to comment.