Răsfoiți Sursa

Disable StrictMode by default

StrictMode is not a good fit for the state of our app, since we are way too far from async operations or correct threading.
As a result, we find ourselves disabling the strict mode manually every time we actually want to work on something, as otherwise the
logspam drowns everything else.

With this PR I propose to disable StrictMode unless a prop is set in the Gradle build, which will also control LeakCanary.
Running `./gradlew installGplayDebug -P perfAnalysis` will install the app with both LeakCanary and StrictMode enabled.
This allows us to analyze performance problems on demand, without making our daily work harder.

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 ani în urmă
părinte
comite
e85737f41d
2 a modificat fișierele cu 6 adăugiri și 2 ștergeri
  1. 4 1
      app/build.gradle
  2. 2 1
      app/src/main/java/com/owncloud/android/MainApp.java

+ 4 - 1
app/build.gradle

@@ -69,6 +69,8 @@ file("$project.rootDir/ndk.env").readLines().each() {
     ndkEnv.put(key, value)
 }
 
+def perfAnalysis = project.hasProperty('perfAnalysis')
+
 android {
 
     compileSdkVersion 32
@@ -85,6 +87,7 @@ android {
         targetSdkVersion 31
 
         buildConfigField 'boolean', 'CI', ciBuild.toString()
+        buildConfigField 'boolean', 'RUNTIME_PERF_ANALYSIS', perfAnalysis.toString()
 
         javaCompileOptions {
             annotationProcessorOptions {
@@ -309,7 +312,7 @@ dependencies {
         }
     }
 
-    if (project.hasProperty("leakCanary")) {
+    if (perfAnalysis) {
         debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10'
     }
 

+ 2 - 1
app/src/main/java/com/owncloud/android/MainApp.java

@@ -488,7 +488,8 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
     }
 
     private void enableStrictMode() {
-        if (BuildConfig.DEBUG) {
+        if (BuildConfig.DEBUG && BuildConfig.RUNTIME_PERF_ANALYSIS) {
+            Log_OC.d(TAG, "Enabling StrictMode");
             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                                            .detectDiskReads()
                                            .detectDiskWrites()