@@ -177,25 +177,8 @@ internal class SimpleVideoEncoder(
177177 }
178178
179179 fun encode (image : Bitmap ) {
180- /* *
181- * it seems that Xiaomi devices have problems with hardware canvas, so we have to use lockCanvas
182- * instead https://stackoverflow.com/a/73520742
183- * ---
184- * Same for Motorola devices.
185- * ---
186- * As for the Spreadtrum/Unisoc chipset, it can be spread across various devices, so we have to
187- * check the SOC_MANUFACTURER property, as the manufacturer name might have changed.
188- * https://github.com/getsentry/sentry-android-gradle-plugin/issues/861#issuecomment-2867021256
189- */
190180 val canvas =
191- if (
192- Build .MANUFACTURER .contains(" xiaomi" , ignoreCase = true ) ||
193- Build .MANUFACTURER .contains(" motorola" , ignoreCase = true ) ||
194- SystemProperties .get(SystemProperties .Property .SOC_MANUFACTURER )
195- .equals(" spreadtrum" , ignoreCase = true ) ||
196- SystemProperties .get(SystemProperties .Property .SOC_MANUFACTURER )
197- .equals(" unisoc" , ignoreCase = true )
198- ) {
181+ if (shouldUseSoftwareCanvas()) {
199182 surface?.lockCanvas(null )
200183 } else {
201184 surface?.lockHardwareCanvas()
@@ -338,6 +321,34 @@ internal class SimpleVideoEncoder(
338321 }
339322}
340323
324+ /* *
325+ * Whether frames should be drawn onto the encoder's input surface with a software canvas
326+ * ([Surface.lockCanvas]) instead of a hardware one ([Surface.lockHardwareCanvas]).
327+ *
328+ * It seems that Xiaomi devices have problems with hardware canvas, so we have to use lockCanvas
329+ * instead https://stackoverflow.com/a/73520742
330+ * ---
331+ * Same for Motorola devices.
332+ * ---
333+ * As for the Spreadtrum/Unisoc chipset, it can be spread across various devices, so we have to
334+ * check the SOC_MANUFACTURER property, as the manufacturer name might have changed.
335+ * https://github.com/getsentry/sentry-android-gradle-plugin/issues/861#issuecomment-2867021256
336+ * ---
337+ * On the Android Emulator (goldfish/ranchu), a hardware canvas makes hwui own an EGL window surface
338+ * on the input surface. The emulator's EGL driver keeps a dequeued buffer on it and cancels that
339+ * buffer when the surface is destroyed, which can crash natively in eglDestroySurface once the
340+ * encoder has been torn down. https://github.com/getsentry/sentry-java/issues/6279
341+ */
342+ internal fun shouldUseSoftwareCanvas (): Boolean =
343+ Build .MANUFACTURER .contains(" xiaomi" , ignoreCase = true ) ||
344+ Build .MANUFACTURER .contains(" motorola" , ignoreCase = true ) ||
345+ SystemProperties .get(SystemProperties .Property .SOC_MANUFACTURER )
346+ .equals(" spreadtrum" , ignoreCase = true ) ||
347+ SystemProperties .get(SystemProperties .Property .SOC_MANUFACTURER )
348+ .equals(" unisoc" , ignoreCase = true ) ||
349+ Build .HARDWARE .contains(" goldfish" , ignoreCase = true ) ||
350+ Build .HARDWARE .contains(" ranchu" , ignoreCase = true )
351+
341352@SuppressLint(" UseRequiresApi" )
342353@TargetApi(24 )
343354internal data class MuxerConfig (
0 commit comments