Skip to content

RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.

OpenFreeMap map: start on OpenGL on phones without Vulkan

CIS-C03f4f46115e7b
diff --git a/app/src/main/java/com/rfsentinel/app/ui/MapSafety.kt b/app/src/main/java/com/rfsentinel/app/ui/MapSafety.kt
index ab759a9..950c97e 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/MapSafety.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/MapSafety.kt
@@ -1,6 +1,7 @@
package com.rfsentinel.app.ui
import android.content.Context
+import android.content.pm.PackageManager
import com.rfsentinel.app.util.Prefs
import org.maplibre.android.RenderingEngine
@@ -53,8 +54,15 @@ internal object MapSafety {
/** The OpenFreeMap map has been told to use OpenGL, not Vulkan. */
fun openGl(context: Context): Boolean = sp(context).getBoolean(OPENGL, false)
- /** The renderer MapLibre must use, or null to let it choose (Vulkan where the phone has it, else OpenGL). */
- fun renderer(context: Context): RenderingEngine.Type? = if (openGl(context)) RenderingEngine.Type.OPENGL else null
+ /**
+ * The renderer MapLibre must use, or null to let it choose (Vulkan). A phone without Vulkan gets OpenGL from the
+ * start: MapLibre does not fall back by itself, it throws "No Vulkan compatible GPU found" and the app closes once.
+ */
+ fun renderer(context: Context): RenderingEngine.Type? =
+ if (openGl(context) || !hasVulkan(context)) RenderingEngine.Type.OPENGL else null
+
+ private fun hasVulkan(context: Context): Boolean =
+ context.packageManager.hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_LEVEL)
/**
* If the last start-up never finished: forgets the mark and counts it. The first time for the OpenFreeMap map
diff --git a/app/src/test/java/com/rfsentinel/app/ui/MapSafetyTest.kt b/app/src/test/java/com/rfsentinel/app/ui/MapSafetyTest.kt
index 672af25..0d1656f 100644
--- a/app/src/test/java/com/rfsentinel/app/ui/MapSafetyTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/ui/MapSafetyTest.kt
@@ -2,6 +2,7 @@ package com.rfsentinel.app.ui
import android.app.Application
import android.content.Context
+import android.content.pm.PackageManager
import androidx.test.core.app.ApplicationProvider
import com.rfsentinel.app.util.Prefs
import org.junit.Assert.assertEquals
@@ -13,6 +14,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.maplibre.android.RenderingEngine
import org.robolectric.RobolectricTestRunner
+import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
/**
@@ -30,6 +32,16 @@ class MapSafetyTest {
ctx.getSharedPreferences("map_safety", Context.MODE_PRIVATE).edit().clear().commit()
MapSafety.live = false
Prefs.setViewPanes(ctx, setOf("map", "list"))
+ vulkan(true)
+ }
+
+ private fun vulkan(has: Boolean) = shadowOf(ctx.packageManager).setSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_LEVEL, has)
+
+ @Test
+ fun aPhoneWithoutVulkanStartsOnOpenGl() {
+ vulkan(false)
+ assertEquals("no crash first: MapLibre would not fall back by itself", RenderingEngine.Type.OPENGL, MapSafety.renderer(ctx))
+ assertEquals(MapSafety.Recovery.NONE, MapSafety.recover(ctx))
}
/** The app starts again after dying: nothing is live in the new process. */