Browse Source

Merge pull request #11073 from nextcloud/chore/strictmode-optional

Disable StrictMode by default
Álvaro Brey 2 years ago
parent
commit
bbaf8d369d
3 changed files with 22 additions and 2 deletions
  1. 16 0
      CONTRIBUTING.md
  2. 4 1
      app/build.gradle
  3. 2 1
      app/src/main/java/com/owncloud/android/MainApp.java

+ 16 - 0
CONTRIBUTING.md

@@ -407,6 +407,22 @@ and thereof we'd ask contributors to be mindful of their code testability:
    should at least not make future efforts more challenging
    should at least not make future efforts more challenging
 3. whenever possible, testability should be improved even if the code is not covered by tests
 3. whenever possible, testability should be improved even if the code is not covered by tests
 
 
+### Performance
+
+If you're interested in improving the app's performance, please check the [official documentation](https://developer.android.com/topic/performance)
+for ways you can inspect and improve performance.
+
+For additional analysis, set the `perfAnalysis` property
+in your Gradle build:
+
+```shell
+./gradlew installGplayDebug -P perfAnalysis
+```
+
+This will install the app with [LeakCanary](https://square.github.io/leakcanary/) and 
+[StrictMode](https://developer.android.com/reference/android/os/StrictMode) enabled and configured.
+These tools can help find memory leaks, foreground operations that should be in background, and other performance
+problems.
 
 
 # Releases
 # Releases
 At the moment we are releasing the app in two app stores:
 At the moment we are releasing the app in two app stores:

+ 4 - 1
app/build.gradle

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