Skip to content

Commit 8a3b061

Browse files
xob0toSumAtrIX
andauthored
feat(Google Photos): Restore hidden 'Back up while charging' toggle (#3678)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent b920355 commit 8a3b061

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

api/revanced-patches.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ public final class app/revanced/patches/googlephotos/misc/integrations/Integrati
321321
public static final field INSTANCE Lapp/revanced/patches/googlephotos/misc/integrations/IntegrationsPatch;
322322
}
323323

324+
public final class app/revanced/patches/googlephotos/preferences/RestoreHiddenBackUpWhileChargingTogglePatch : app/revanced/patcher/patch/BytecodePatch {
325+
public static final field INSTANCE Lapp/revanced/patches/googlephotos/preferences/RestoreHiddenBackUpWhileChargingTogglePatch;
326+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
327+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
328+
}
329+
324330
public final class app/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions : app/revanced/patcher/patch/BytecodePatch {
325331
public static final field INSTANCE Lapp/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions;
326332
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package app.revanced.patches.googlephotos.preferences
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6+
import app.revanced.patcher.patch.BytecodePatch
7+
import app.revanced.patcher.patch.annotation.CompatiblePackage
8+
import app.revanced.patcher.patch.annotation.Patch
9+
import app.revanced.patches.googlephotos.preferences.fingerprints.BackupPreferencesFingerprint
10+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
11+
12+
@Patch(
13+
name = "Restore hidden 'Back up while charging' toggle",
14+
description = "Restores a hidden toggle to only run backups when the device is charging.",
15+
compatiblePackages = [CompatiblePackage("com.google.android.apps.photos")],
16+
)
17+
@Suppress("unused")
18+
object RestoreHiddenBackUpWhileChargingTogglePatch : BytecodePatch(
19+
setOf(BackupPreferencesFingerprint),
20+
) {
21+
override fun execute(context: BytecodeContext) {
22+
// Patches 'backup_prefs_had_backup_only_when_charging_enabled' to always be true.
23+
BackupPreferencesFingerprint.result?.let {
24+
val chargingPrefStringIndex = it.scanResult.stringsScanResult!!.matches.first().index
25+
it.mutableMethod.apply {
26+
// Get the register of move-result.
27+
val resultRegister = getInstruction<OneRegisterInstruction>(chargingPrefStringIndex + 2).registerA
28+
// Insert const after move-result to override register as true.
29+
addInstruction(chargingPrefStringIndex + 3, "const/4 v$resultRegister, 0x1")
30+
}
31+
} ?: throw Exception("BackupPreferencesFingerprint result not found")
32+
}
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package app.revanced.patches.googlephotos.preferences.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
5+
internal object BackupPreferencesFingerprint : MethodFingerprint(
6+
returnType = "Lcom/google/android/apps/photos/backup/data/BackupPreferences;",
7+
strings = listOf(
8+
"backup_prefs_had_backup_only_when_charging_enabled",
9+
),
10+
)

0 commit comments

Comments
 (0)