Skip to content

Commit 5e00632

Browse files
committed
Fix: Action logs now readable without active executor (Shizuku/Root)
1 parent 2d511a3 commit 5e00632

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

app/src/main/java/com/appcontrolx/rollback/RollbackManager.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@ import java.util.UUID
1010

1111
class 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) {

app/src/main/java/com/appcontrolx/ui/ActionLogBottomSheet.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class ActionLogBottomSheet : BottomSheetDialogFragment() {
5454
}
5555

5656
private fun setupExecutor() {
57+
// RollbackManager for reading logs - no executor needed
58+
rollbackManager = RollbackManager(requireContext())
59+
60+
// Executor only needed for rollback actions
5761
val mode = PermissionBridge(requireContext()).detectMode()
5862
val executor: com.appcontrolx.executor.CommandExecutor? = when (mode) {
5963
is ExecutionMode.Root -> RootExecutor()
@@ -63,6 +67,7 @@ class ActionLogBottomSheet : BottomSheetDialogFragment() {
6367

6468
executor?.let {
6569
policyManager = BatteryPolicyManager(it)
70+
// Create new RollbackManager with executor for rollback capability
6671
rollbackManager = RollbackManager(requireContext(), it)
6772
}
6873
}
@@ -86,14 +91,7 @@ class ActionLogBottomSheet : BottomSheetDialogFragment() {
8691

8792
private fun loadLogs() {
8893
val b = binding ?: return
89-
val rm = rollbackManager
90-
91-
if (rm == null) {
92-
b.emptyState.visibility = View.VISIBLE
93-
b.recyclerView.visibility = View.GONE
94-
b.tvEmptyMessage.text = getString(R.string.log_no_mode)
95-
return
96-
}
94+
val rm = rollbackManager ?: RollbackManager(requireContext()) // Fallback for read-only
9795

9896
lifecycleScope.launch {
9997
val logs = withContext(Dispatchers.IO) {
@@ -125,8 +123,13 @@ class ActionLogBottomSheet : BottomSheetDialogFragment() {
125123

126124
private fun performRollback(log: ActionLog) {
127125
val b = binding ?: return
128-
val pm = policyManager ?: return
129-
val rm = rollbackManager ?: return
126+
val pm = policyManager
127+
val rm = rollbackManager
128+
129+
if (pm == null || rm == null) {
130+
Toast.makeText(context, R.string.log_no_mode, Toast.LENGTH_SHORT).show()
131+
return
132+
}
130133

131134
lifecycleScope.launch {
132135
b.progressBar.visibility = View.VISIBLE

0 commit comments

Comments
 (0)