Skip to content

Commit

Permalink
feat(Google Photos): Restore hidden 'Back up while charging' toggle (#…
Browse files Browse the repository at this point in the history
…3678)

Co-authored-by: oSumAtrIX <[email protected]>
  • Loading branch information
xob0t and oSumAtrIX committed Sep 29, 2024
1 parent a684b1c commit f9e19ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OneRegisterInstruction>(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")
}
}
Original file line number Diff line number Diff line change
@@ -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",
),
)

0 comments on commit f9e19ce

Please sign in to comment.