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

feat: Add Disable analytics and telemetry patches #3448

Draft
wants to merge 21 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public final class app/revanced/patches/all/privacy/UniversalPrivacyPatch : app/
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/all/privacy/UniversalResourcePrivacyPatch : app/revanced/patcher/patch/ResourcePatch {
public static final field INSTANCE Lapp/revanced/patches/all/privacy/UniversalResourcePrivacyPatch;
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V
}

public final class app/revanced/patches/all/screencapture/removerestriction/RemoveCaptureRestrictionPatch : app/revanced/patches/all/misc/transformation/BaseTransformInstructionsPatch {
public static final field INSTANCE Lapp/revanced/patches/all/screencapture/removerestriction/RemoveCaptureRestrictionPatch;
public synthetic fun filterMap (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;I)Ljava/lang/Object;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package app.revanced.patches.all.privacy

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
import app.revanced.patches.shared.resource.AndroidManifest
import java.util.logging.Logger

@Patch(
name = "Disable more privacy invasive components",
description = "Disables multiple embedded analytics and telemetry SDKs by modifying the app's manifest. Please note this can break some apps.",
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
use = false
)
@Suppress("unused")
object UniversalResourcePrivacyPatch : ResourcePatch() {

private val subPatchesOptions = mapOf(
::disableFirebaseCollections to booleanPatchOption(
key = "disableFirebaseCollections",
default = true,
values = mapOf(),
title = "Firebase collections",
description = "Disables multiple Firebase data collection mechanisms.",
required = true
),
::disableFacebookAnalytics to booleanPatchOption(
key = "disableFacebookAnalytics",
default = true,
values = mapOf(),
title = "Facebook Analytics",
description = "Disables parts of the Facebook SDK responsible for data gathering.",
required = true
),
::disableFacebookSDK to booleanPatchOption(
key = "disableFacebookSDK",
default = false,
values = mapOf(),
title = "Facebook SDK",
description = "Disables the Facebook SDK. Will break Facebook login.",
required = true
),
::disableGoogleAnalyticsCollections to booleanPatchOption(
key = "Google Analytics collections",
default = true,
values = mapOf(),
title = "Apps Flyer",
description = "Disables multiple Google Analytics data collection mechanisms.",
required = true
),
)

private fun disableFacebookAnalytics(context: ResourceContext) {
mapOf(
"com.facebook.sdk.AutoLogAppEventsEnabled" to "false",
"com.facebook.sdk.AdvertiserIDCollectionEnabled" to "false",
"com.facebook.sdk.MonitorEnabled" to "false"
).forEach {
AndroidManifest.addMetadata(context, it.key, it.value)
}
}

private fun disableFacebookSDK(context: ResourceContext) {
AndroidManifest.addMetadata(context, "com.facebook.sdk.AutoInitEnabled", "false")
}

private fun disableFirebaseCollections(context: ResourceContext) {
mapOf(
"firebase_analytics_collection_enabled" to "false",
"firebase_analytics_collection_deactivated" to "true",
"firebase_crashlytics_collection_enabled" to "false",
"firebase_performance_collection_enabled" to "false",
"firebase_performance_collection_deactivated" to "true",
"firebase_data_collection_default_enabled" to "false"
).forEach {
AndroidManifest.addMetadata(context, it.key, it.value)
}
}

private fun disableGoogleAnalyticsCollections(context: ResourceContext) {
mapOf(
"google_analytics_adid_collection_enabled" to "false",
"google_analytics_default_allow_ad_personalization_signals" to "false",
"google_analytics_automatic_screen_reporting_enabled" to "false",
"google_analytics_default_allow_ad_storage" to "false",
"google_analytics_default_allow_ad_user_data" to "false",
"google_analytics_default_allow_analytics_storage" to "false",
"google_analytics_sgtm_upload_enabled" to "false",
"google_analytics_deferred_deep_link_enabled" to "false"
).forEach {
AndroidManifest.addMetadata(context, it.key, it.value)
}
}

override fun execute(context: ResourceContext) {
subPatchesOptions.forEach {
if (it.value.value == true){
try {
it.key(context)
Logger.getLogger(this::class.java.name).info("Applied privacy patch to disable ${it.value.title}")
}catch (exception: PatchException){
Logger.getLogger(this::class.java.name).info("${it.value.title} not found, skipping")
}
}
}

}
}
Loading