@@ -10,22 +10,26 @@ import java.util.UUID
1010
1111class RollbackManager (
1212 private val context : Context ,
13- private val executor : CommandExecutor
13+ private val executor : CommandExecutor ? = null
1414) {
1515 private val gson = Gson ()
1616 private val snapshotDir = File (context.filesDir, " snapshots" ).apply { mkdirs() }
1717 private val snapshotFile = File (snapshotDir, " rollback_snapshot.json" )
1818 private val historyFile = File (snapshotDir, " action_history.json" )
1919
20+ // Secondary constructor for read-only access (no executor needed)
21+ constructor (context: Context ) : this (context, null )
22+
2023 companion object {
2124 private const val TAG = " RollbackManager"
2225 }
2326
24- fun saveSnapshot (packages : List <String >): StateSnapshot {
27+ fun saveSnapshot (packages : List <String >): StateSnapshot ? {
28+ val exec = executor ? : return null
2529 val states = packages.map { pkg ->
26- val bgStatus = executor .execute(" appops get $pkg RUN_IN_BACKGROUND" )
27- val wlStatus = executor .execute(" appops get $pkg WAKE_LOCK" )
28- val enabledStatus = executor .execute(" pm list packages -e | grep $pkg " )
30+ val bgStatus = exec .execute(" appops get $pkg RUN_IN_BACKGROUND" )
31+ val wlStatus = exec .execute(" appops get $pkg WAKE_LOCK" )
32+ val enabledStatus = exec .execute(" pm list packages -e | grep $pkg " )
2933
3034 AppState (
3135 packageName = pkg,
@@ -56,6 +60,7 @@ class RollbackManager(
5660 }
5761
5862 fun rollback (): Result <Unit > {
63+ val exec = executor ? : return Result .failure(Exception (" No executor available" ))
5964 val snapshot = getLastSnapshot()
6065 ? : return Result .failure(Exception (" No snapshot found" ))
6166
@@ -69,7 +74,7 @@ class RollbackManager(
6974 }
7075 }
7176
72- return executor .executeBatch(commands)
77+ return exec .executeBatch(commands)
7378 }
7479
7580 fun logAction (action : ActionLog ) {
0 commit comments