Skip to content

Commit

Permalink
feat(All - Firebase): Add `Deactivate Firebase Performance Monitoring…
Browse files Browse the repository at this point in the history
…` patch
  • Loading branch information
jkennethcarino committed Mar 17, 2024
1 parent b09f428 commit b0ac188
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/privacy-revanced-patches.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
public final class dev/jkcarino/revanced/patches/all/firebase/DeactivateFirebasePerfPatch : app/revanced/patcher/patch/ResourcePatch {
public static final field INSTANCE Ldev/jkcarino/revanced/patches/all/firebase/DeactivateFirebasePerfPatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V
}

public final class dev/jkcarino/revanced/patches/all/misc/network/RemoveInternetPermissionPatch : app/revanced/patcher/patch/ResourcePatch {
public static final field INSTANCE Ldev/jkcarino/revanced/patches/all/misc/network/RemoveInternetPermissionPatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.jkcarino.revanced.patches.all.firebase

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch
import dev.jkcarino.revanced.util.createElement
import dev.jkcarino.revanced.util.filterToElements
import dev.jkcarino.revanced.util.firstElementByTagName

@Patch(
name = "Deactivate Firebase Performance Monitoring",
description = "Deactivates the collection of performance data on app start up time, network requests, and other related metrics.",
use = false
)
@Suppress("unused")
object DeactivateFirebasePerfPatch : ResourcePatch() {
private const val META_DATA_TAG = "meta-data"
private const val ATTRIBUTE_NAME = "android:name"
private const val ATTRIBUTE_VALUE = "android:value"
private const val FIREBASE_PERF_DEACTIVATED = "firebase_performance_collection_deactivated"

override fun execute(context: ResourceContext) {
context.xmlEditor["AndroidManifest.xml"].use { editor ->
val document = editor.file
val application = document.firstElementByTagName("application")

val firebasePerfMetaData = application.getElementsByTagName(META_DATA_TAG)
.filterToElements()
.firstOrNull { it.getAttribute(ATTRIBUTE_NAME) == FIREBASE_PERF_DEACTIVATED }
?.setAttribute(ATTRIBUTE_VALUE, "true")

if (firebasePerfMetaData == null) {
application.appendChild(
document.createElement(META_DATA_TAG) {
setAttribute(ATTRIBUTE_NAME, FIREBASE_PERF_DEACTIVATED)
setAttribute(ATTRIBUTE_VALUE, "true")
}
)
}
}
}
}

0 comments on commit b0ac188

Please sign in to comment.