Fix crash by disabling Flipper on API 22 and below (#7428)

* Disable Flipper on API 21 and below - only affects debug builds.

Due to a bug: https://github.com/facebook/flipper/issues/3572

* Add jonnyandrew to PR sign-off allowlist

Co-authored-by: Benoit Marty <benoit.marty@gmail.com>
This commit is contained in:
jonnyandrew 2022-10-21 17:36:31 +01:00 committed by GitHub
parent e003d01ec4
commit 31811bb7e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 20 deletions

1
changelog.d/7428.bugfix Normal file
View File

@ -0,0 +1 @@
Fix crash by disabling Flipper on Android API 22 and below - only affects debug version of the application.

View File

@ -81,6 +81,7 @@ const allowList = [
"Florian14",
"ganfra",
"jmartinesp",
"jonnyandrew",
"langleyd",
"MadLittleMods",
"manuroe",

View File

@ -17,6 +17,7 @@
package im.vector.app.flipper
import android.content.Context
import android.os.Build
import com.facebook.flipper.android.AndroidFlipperClient
import com.facebook.flipper.android.utils.FlipperUtils
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin
@ -31,6 +32,7 @@ import com.kgurgul.flipper.RealmDatabaseDriver
import com.kgurgul.flipper.RealmDatabaseProvider
import im.vector.app.core.debug.FlipperProxy
import io.realm.RealmConfiguration
import okhttp3.Interceptor
import org.matrix.android.sdk.api.Matrix
import javax.inject.Inject
import javax.inject.Singleton
@ -41,10 +43,21 @@ class VectorFlipperProxy @Inject constructor(
) : FlipperProxy {
private val networkFlipperPlugin = NetworkFlipperPlugin()
private val isEnabled: Boolean
get() {
// https://github.com/facebook/flipper/issues/3572
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
return false
}
return FlipperUtils.shouldEnableFlipper(context)
}
override fun init(matrix: Matrix) {
if (!isEnabled) return
SoLoader.init(context, false)
if (FlipperUtils.shouldEnableFlipper(context)) {
val client = AndroidFlipperClient.getInstance(context)
client.addPlugin(CrashReporterPlugin.getInstance())
client.addPlugin(SharedPreferencesFlipperPlugin(context))
@ -63,7 +76,10 @@ class VectorFlipperProxy @Inject constructor(
)
client.start()
}
}
override fun networkInterceptor() = FlipperOkhttpInterceptor(networkFlipperPlugin)
override fun networkInterceptor(): Interceptor? {
if (!isEnabled) return null
return FlipperOkhttpInterceptor(networkFlipperPlugin)
}
}