Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep string literals to refrain from getting obfuscated by dexguard #339

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import com.rudderstack.rudderjsonadapter.JsonAdapter
import com.squareup.moshi.Json

data class LibraryMetadata(
@get:JsonProperty("name")
@SerializedName("name")
@Json(name = "name")
val name: String,
@get:JsonProperty("sdk_version")
@SerializedName("sdk_version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,40 @@

package com.rudderstack.android.ruddermetricsreporterandroid.metrics

import androidx.annotation.Keep
import com.fasterxml.jackson.annotation.JsonIgnore
import com.rudderstack.android.ruddermetricsreporterandroid.JSerialize
import com.rudderstack.rudderjsonadapter.JsonAdapter
import com.squareup.moshi.Json

open class MetricModel<T : Any>(val name: String, val type: MetricType,
val value: T, val labels: Map<String,String>) : JSerialize<MetricModel<T>> {
open class MetricModel<T : Any>(
val name: String, val type: MetricType, val value: T, val labels: Map<String, String>
) : JSerialize<MetricModel<T>> {

companion object {
@Keep
private const val NAME_TAG = "name"

@Keep
private const val TYPE_TAG = "type"

@Keep
private const val VALUE_TAG = "value"

@Keep
private const val LABELS_TAG = "labels"
}

override fun serialize(jsonAdapter: JsonAdapter): String? {
mapOf<String, Any>("name" to name, "type" to type, "value" to value, "labels" to labels).let {
toMap().let {
return jsonAdapter.writeToJson(it)
}
}

protected open fun toMap(): Map<String, Any> {
return mapOf(NAME_TAG to name, TYPE_TAG to type, VALUE_TAG to value, LABELS_TAG to labels)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is MetricModel<*>) return false
Expand All @@ -48,21 +69,25 @@ open class MetricModel<T : Any>(val name: String, val type: MetricType,
}

override fun toString(): String {
return "MetricModel(name='$name', type=$type, value=$value, labels=$labels)"
return "MetricModel($NAME_TAG ='$name', $TYPE_TAG = $type, $VALUE_TAG = $value, $LABELS_TAG = $labels)"
}


}

class MetricModelWithId<T : Any>(@Transient
@JsonIgnore
@field:Json(ignore = true)
val id: String, name: String, type: MetricType,
value: T, labels: Map<String,String>) : MetricModel<T>(name, type, value, labels) {
override fun serialize(jsonAdapter: JsonAdapter): String? {
mapOf<String, Any>("id" to id, "name" to name, "type" to type, "value" to value, "labels" to labels).let {
return jsonAdapter.writeToJson(it)
}
class MetricModelWithId<T : Any>(
@Transient @JsonIgnore @field:Json(ignore = true) val id: String,
name: String,
type: MetricType,
value: T,
labels: Map<String, String>
) : MetricModel<T>(name, type, value, labels) {
companion object {
@Keep private const val ID_TAG = "id"
}

override fun toMap(): Map<String, Any> {
return super.toMap() + mapOf(ID_TAG to id)
}

override fun equals(other: Any?): Boolean {
Expand All @@ -74,7 +99,7 @@ class MetricModelWithId<T : Any>(@Transient
}

override fun toString(): String {
return "MetricModelWithId(id='$id'), parent = ${super.toString()})"
return "MetricModelWithId(i$ID_TAG='$id'), parent = ${super.toString()})"
}

}