diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 8185c9e021..ad04ff075e 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -321,6 +321,12 @@ public final class app/revanced/patches/googlephotos/misc/integrations/Integrati public static final field INSTANCE Lapp/revanced/patches/googlephotos/misc/integrations/IntegrationsPatch; } +public final class app/revanced/patches/googlephotos/preferences/RestoreHiddenBackUpWhileChargingTogglePatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/googlephotos/preferences/RestoreHiddenBackUpWhileChargingTogglePatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V diff --git a/src/main/kotlin/app/revanced/patches/googlephotos/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt b/src/main/kotlin/app/revanced/patches/googlephotos/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt new file mode 100644 index 0000000000..0b935afd91 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/googlephotos/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt @@ -0,0 +1,33 @@ +package app.revanced.patches.googlephotos.preferences + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.googlephotos.preferences.fingerprints.BackupPreferencesFingerprint +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction + +@Patch( + name = "Restore hidden 'Back up while charging' toggle", + description = "Restores a hidden toggle to only run backups when the device is charging.", + compatiblePackages = [CompatiblePackage("com.google.android.apps.photos")], +) +@Suppress("unused") +object RestoreHiddenBackUpWhileChargingTogglePatch : BytecodePatch( + setOf(BackupPreferencesFingerprint), +) { + override fun execute(context: BytecodeContext) { + // Patches 'backup_prefs_had_backup_only_when_charging_enabled' to always be true. + BackupPreferencesFingerprint.result?.let { + val chargingPrefStringIndex = it.scanResult.stringsScanResult!!.matches.first().index + it.mutableMethod.apply { + // Get the register of move-result. + val resultRegister = getInstruction(chargingPrefStringIndex + 2).registerA + // Insert const after move-result to override register as true. + addInstruction(chargingPrefStringIndex + 3, "const/4 v$resultRegister, 0x1") + } + } ?: throw Exception("BackupPreferencesFingerprint result not found") + } +} diff --git a/src/main/kotlin/app/revanced/patches/googlephotos/preferences/fingerprints/BackupPreferencesFingerprint.kt b/src/main/kotlin/app/revanced/patches/googlephotos/preferences/fingerprints/BackupPreferencesFingerprint.kt new file mode 100644 index 0000000000..7d12ed5b0b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/googlephotos/preferences/fingerprints/BackupPreferencesFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.googlephotos.preferences.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object BackupPreferencesFingerprint : MethodFingerprint( + returnType = "Lcom/google/android/apps/photos/backup/data/BackupPreferences;", + strings = listOf( + "backup_prefs_had_backup_only_when_charging_enabled", + ), +)