mirror of
https://github.com/markusfisch/BinaryEye.git
synced 2024-09-20 20:03:06 +02:00
Run RenderScript.forceCompat() after RSRuntimeExc
Because there are more systems than just Lineage that need `RenderScript.forceCompat()`. To not hold back everyone else, the app now silently switches to `forceCompat()` once there was a RSRuntimeException. Thats's very crude because there may be other reasons for RSRuntimeException's *and* the app will still crash even if `forceCompat()` is the fix because `forceCompat()` must be called before every other RenderScript function. But that's probably the best I can do right now.
This commit is contained in:
parent
a36fd668a9
commit
307401087e
@ -10,6 +10,7 @@ import android.os.Bundle
|
||||
import android.os.Vibrator
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.Toolbar
|
||||
import android.support.v8.renderscript.RSRuntimeException
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
@ -441,6 +442,7 @@ class CameraActivity : AppCompatActivity() {
|
||||
): Result? {
|
||||
frameData ?: return null
|
||||
invert = invert xor true
|
||||
try {
|
||||
val pp = preprocessor ?: createPreprocessorAndMapping(
|
||||
frameWidth,
|
||||
frameHeight,
|
||||
@ -454,6 +456,13 @@ class CameraActivity : AppCompatActivity() {
|
||||
pp.outHeight,
|
||||
invert
|
||||
)
|
||||
} catch (e: RSRuntimeException) {
|
||||
prefs.forceCompat = true
|
||||
// now the only option is to let the app crash because
|
||||
// RenderScript.forceCompat() needs to be called before
|
||||
// RenderScript is initialized
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
private fun createPreprocessorAndMapping(
|
||||
|
@ -11,8 +11,10 @@ val prefs = Preferences()
|
||||
class BinaryEyeApp : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
prefs.init(this)
|
||||
|
||||
if (System.getProperty("os.version")?.contains(
|
||||
if (prefs.forceCompat ||
|
||||
System.getProperty("os.version")?.contains(
|
||||
"lineageos", true
|
||||
) == true
|
||||
) {
|
||||
@ -21,6 +23,5 @@ class BinaryEyeApp : Application() {
|
||||
}
|
||||
|
||||
db.open(this)
|
||||
prefs.init(this)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.markusfisch.android.binaryeye.preference
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.preference.PreferenceManager
|
||||
@ -57,6 +58,14 @@ class Preferences {
|
||||
setInt(INDEX_OF_LAST_SELECTED_FORMAT, value)
|
||||
field = value
|
||||
}
|
||||
var forceCompat: Boolean = false
|
||||
@SuppressLint("ApplySharedPref")
|
||||
set(value) {
|
||||
// since the app may be about to crash when forceCompat is set,
|
||||
// it's necessary to `commit()` this synchronously
|
||||
preferences.edit().putBoolean(FORCE_COMPAT, value).commit()
|
||||
field = value
|
||||
}
|
||||
|
||||
fun init(context: Context) {
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
@ -85,6 +94,7 @@ class Preferences {
|
||||
INDEX_OF_LAST_SELECTED_FORMAT,
|
||||
indexOfLastSelectedFormat
|
||||
)
|
||||
forceCompat = preferences.getBoolean(FORCE_COMPAT, forceCompat)
|
||||
}
|
||||
|
||||
private fun setBoolean(label: String, value: Boolean) {
|
||||
@ -116,5 +126,6 @@ class Preferences {
|
||||
const val SHOW_META_DATA = "show_meta_data"
|
||||
const val OPEN_WITH_URL = "open_with_url"
|
||||
const val INDEX_OF_LAST_SELECTED_FORMAT = "index_of_last_selected_format"
|
||||
const val FORCE_COMPAT = "force_compat"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user