Skip to content

Commit 252b55d

Browse files
committed
Fix ExecutionModeValidator referencing deleted SettingsDataStore - Replace SettingsDataStore with SharedPreferences - Remove suspend from validateAndFallback (no longer needed)
1 parent 04962bb commit 252b55d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

app/src/main/java/com/appcontrolx/service/ExecutionModeValidator.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
package com.appcontrolx.service
22

33
import android.content.Context
4-
import com.appcontrolx.data.local.SettingsDataStore
4+
import androidx.preference.PreferenceManager
55
import com.appcontrolx.utils.Constants
6-
import kotlinx.coroutines.flow.first
76
import javax.inject.Inject
87
import javax.inject.Singleton
98

109
@Singleton
1110
class ExecutionModeValidator @Inject constructor(
1211
private val context: Context,
13-
private val permissionBridge: PermissionBridge,
14-
private val settingsDataStore: SettingsDataStore
12+
private val permissionBridge: PermissionBridge
1513
) {
1614

15+
private val prefs by lazy { PreferenceManager.getDefaultSharedPreferences(context) }
16+
1717
/**
1818
* Validate current execution mode and fallback to view-only if needed
1919
*/
20-
suspend fun validateAndFallback(): ValidationResult {
21-
val currentMode = settingsDataStore.executionMode.first()
20+
fun validateAndFallback(): ValidationResult {
21+
val currentMode = prefs.getString(Constants.PREFS_EXECUTION_MODE, Constants.MODE_NONE) ?: Constants.MODE_NONE
2222

2323
return when (currentMode) {
2424
Constants.MODE_ROOT -> {
2525
if (permissionBridge.isRootAvailable()) {
2626
ValidationResult.Valid(currentMode)
2727
} else {
28-
settingsDataStore.setExecutionMode(Constants.MODE_NONE)
28+
prefs.edit().putString(Constants.PREFS_EXECUTION_MODE, Constants.MODE_NONE).apply()
2929
ValidationResult.Fallback(Constants.MODE_NONE, "Root access is no longer available")
3030
}
3131
}
@@ -34,7 +34,7 @@ class ExecutionModeValidator @Inject constructor(
3434
if (permissionBridge.isShizukuReady()) {
3535
ValidationResult.Valid(currentMode)
3636
} else {
37-
settingsDataStore.setExecutionMode(Constants.MODE_NONE)
37+
prefs.edit().putString(Constants.PREFS_EXECUTION_MODE, Constants.MODE_NONE).apply()
3838
ValidationResult.Fallback(Constants.MODE_NONE, "Shizuku is no longer available")
3939
}
4040
}

0 commit comments

Comments
 (0)