generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(All - Firebase): Add `Deactivate Firebase Performance Monitoring…
…` patch
- Loading branch information
1 parent
b09f428
commit b0ac188
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/dev/jkcarino/revanced/patches/all/firebase/DeactivateFirebasePerfPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} |