From 1786ba30f70b535901a559e0620d291c4b164748 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 11 Jun 2020 19:36:15 +0200 Subject: [PATCH 1/2] Proguard: handle matrix sdk --- matrix-sdk-android/build.gradle | 7 ++-- matrix-sdk-android/proguard-rules.pro | 42 +++++++++++++++++++ .../api/session/room/model/Membership.kt | 2 + .../room/model/RoomDirectoryVisibility.kt | 2 + .../room/model/RoomGuestAccessContent.kt | 1 + .../room/model/RoomHistoryVisibility.kt | 2 + .../api/session/room/model/RoomJoinRules.kt | 2 + .../room/model/create/CreateRoomPreset.kt | 2 + .../internal/network/ssl/Fingerprint.kt | 1 + 9 files changed, 58 insertions(+), 3 deletions(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index abc860d1ff..436d3b6319 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -35,6 +35,10 @@ android { resValue "string", "git_sdk_revision", "\"${gitRevision()}\"" resValue "string", "git_sdk_revision_unix_date", "\"${gitRevisionUnixDate()}\"" resValue "string", "git_sdk_revision_date", "\"${gitRevisionDate()}\"" + + defaultConfig { + consumerProguardFiles 'proguard-rules.pro' + } } buildTypes { @@ -49,9 +53,6 @@ android { release { buildConfigField "boolean", "LOG_PRIVATE_DATA", "false" buildConfigField "okhttp3.logging.HttpLoggingInterceptor.Level", "OKHTTP_LOGGING_LEVEL", "okhttp3.logging.HttpLoggingInterceptor.Level.NONE" - - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/matrix-sdk-android/proguard-rules.pro b/matrix-sdk-android/proguard-rules.pro index f1b424510d..3cb49420b8 100644 --- a/matrix-sdk-android/proguard-rules.pro +++ b/matrix-sdk-android/proguard-rules.pro @@ -19,3 +19,45 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + + +### EVENT BUS ### + +-keepattributes *Annotation* +-keepclassmembers class * { + @org.greenrobot.eventbus.Subscribe ; +} +-keep enum org.greenrobot.eventbus.ThreadMode { *; } + +### MOSHI ### + +# JSR 305 annotations are for embedding nullability information. + +-dontwarn javax.annotation.** + +-keepclasseswithmembers class * { + @com.squareup.moshi.* ; +} + +-keep @com.squareup.moshi.JsonQualifier interface * + +# Enum field names are used by the integrated EnumJsonAdapter. +# values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly +# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi. +-keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum { + ; + **[] values(); +} + +-keep class kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoaderImpl + +-keepclassmembers class kotlin.Metadata { + public ; +} + +### OKHTTP for Android Studio ### +-keep class okhttp3.Headers { *; } +-keep interface okhttp3.Interceptor.* { *; } + +### OLM JNI ### +-keep class org.matrix.olm.** { *; } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/Membership.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/Membership.kt index 7c6a931373..c7a4543184 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/Membership.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/Membership.kt @@ -17,10 +17,12 @@ package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass /** * Represents the membership of a user on a room */ +@JsonClass(generateAdapter = false) enum class Membership(val value: String) { NONE("none"), diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomDirectoryVisibility.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomDirectoryVisibility.kt index ab3407392c..3e63636fc6 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomDirectoryVisibility.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomDirectoryVisibility.kt @@ -17,7 +17,9 @@ package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +@JsonClass(generateAdapter = false) enum class RoomDirectoryVisibility { @Json(name = "private") PRIVATE, @Json(name = "public") PUBLIC diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomGuestAccessContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomGuestAccessContent.kt index 4c814f7914..36e2d769a3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomGuestAccessContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomGuestAccessContent.kt @@ -29,6 +29,7 @@ data class RoomGuestAccessContent( @Json(name = "guest_access") val guestAccess: GuestAccess? = null ) +@JsonClass(generateAdapter = false) enum class GuestAccess(val value: String) { @Json(name = "can_join") CanJoin("can_join"), diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomHistoryVisibility.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomHistoryVisibility.kt index b0e4e2d8e5..44ad777c0e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomHistoryVisibility.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomHistoryVisibility.kt @@ -17,10 +17,12 @@ package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass /** * Ref: https://matrix.org/docs/spec/client_server/latest#room-history-visibility */ +@JsonClass(generateAdapter = false) enum class RoomHistoryVisibility { /** * All events while this is the m.room.history_visibility value may be shared by any diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomJoinRules.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomJoinRules.kt index d7cf8678c3..e4ebcc7044 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomJoinRules.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/RoomJoinRules.kt @@ -18,10 +18,12 @@ package im.vector.matrix.android.api.session.room.model import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass /** * Enum for [RoomJoinRulesContent] : https://matrix.org/docs/spec/client_server/r0.4.0#m-room-join-rules */ +@JsonClass(generateAdapter = false) enum class RoomJoinRules(val value: String) { @Json(name = "public") diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomPreset.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomPreset.kt index eafe9ef292..109ef7f9bd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomPreset.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/create/CreateRoomPreset.kt @@ -17,7 +17,9 @@ package im.vector.matrix.android.api.session.room.model.create import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +@JsonClass(generateAdapter = false) enum class CreateRoomPreset { @Json(name = "private_chat") PRESET_PRIVATE_CHAT, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/ssl/Fingerprint.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/ssl/Fingerprint.kt index 99c2eb9c72..5fd0516dbf 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/ssl/Fingerprint.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/network/ssl/Fingerprint.kt @@ -76,6 +76,7 @@ data class Fingerprint( } } + @JsonClass(generateAdapter = false) enum class HashType { @Json(name = "sha-1") SHA1, @Json(name = "sha-256")SHA256 From 23cbed310a9ab81921e82e49e6e900957fd962b3 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 11 Jun 2020 19:37:20 +0200 Subject: [PATCH 2/2] Proguard: activate it in release --- vector/build.gradle | 10 ++++++++-- vector/proguard-rules.pro | 2 ++ .../riotx/features/rageshake/VectorFileLogger.kt | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index 1eac3106ea..b49cd14b77 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -192,8 +192,14 @@ android { resValue "bool", "debug_mode", "false" buildConfigField "boolean", "LOW_PRIVACY_LOG_ENABLE", "false" - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + + postprocessing { + removeUnusedCode true + removeUnusedResources true + obfuscate false + optimizeCode true + proguardFiles 'proguard-rules.pro' + } } } diff --git a/vector/proguard-rules.pro b/vector/proguard-rules.pro index f1b424510d..56d3b95510 100644 --- a/vector/proguard-rules.pro +++ b/vector/proguard-rules.pro @@ -19,3 +19,5 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + +-keep class im.vector.riotx.features.** { *; } \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt b/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt index bcc48fb96c..d4ad4efb6f 100644 --- a/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt +++ b/vector/src/main/java/im/vector/riotx/features/rageshake/VectorFileLogger.kt @@ -39,7 +39,7 @@ private const val SIZE_20MB = 20 * 1024 * 1024 private const val SIZE_50MB = 50 * 1024 * 1024 @Singleton -class VectorFileLogger @Inject constructor(val context: Context, private val vectorPreferences: VectorPreferences) : Timber.DebugTree() { +class VectorFileLogger @Inject constructor(val context: Context, private val vectorPreferences: VectorPreferences) : Timber.Tree() { private val maxLogSizeByte: Int private val logRotationCount: Int