@@ -5,16 +5,25 @@ import android.content.Context
5
5
import android.provider.Settings
6
6
import android.text.TextUtils
7
7
import dagger.hilt.android.qualifiers.ApplicationContext
8
+ import eu.darken.sdmse.automation.core.errors.AutomationNoConsentException
9
+ import eu.darken.sdmse.automation.core.errors.AutomationNotEnabledException
10
+ import eu.darken.sdmse.automation.core.errors.AutomationNotRunningException
11
+ import eu.darken.sdmse.common.datastore.value
12
+ import eu.darken.sdmse.common.datastore.valueBlocking
8
13
import eu.darken.sdmse.common.debug.logging.log
9
14
import eu.darken.sdmse.common.debug.logging.logTag
15
+ import eu.darken.sdmse.main.core.GeneralSettings
10
16
import javax.inject.Inject
11
17
import javax.inject.Singleton
12
18
13
19
@Singleton
14
20
class AutomationController @Inject constructor(
15
- @ApplicationContext val context : Context
21
+ @ApplicationContext val context : Context ,
22
+ private val generalSettings : GeneralSettings ,
16
23
) {
17
24
25
+ fun hasConsent (): Boolean = generalSettings.hasAcsConsent.valueBlocking == true
26
+
18
27
fun isServiceEnabled (): Boolean {
19
28
val comp = ComponentName (context, AutomationService ::class .java)
20
29
@@ -37,7 +46,12 @@ class AutomationController @Inject constructor(
37
46
38
47
suspend fun submit (task : AutomationTask ): AutomationTask .Result {
39
48
log(TAG ) { " submit(): $task " }
40
- val service = AutomationService .instance ? : throw IllegalStateException (" Accessbility service unavailable" )
49
+
50
+ if (generalSettings.hasAcsConsent.value() != true ) throw AutomationNoConsentException ()
51
+
52
+ if (! isServiceEnabled()) throw AutomationNotEnabledException ()
53
+
54
+ val service = AutomationService .instance ? : throw AutomationNotRunningException ()
41
55
return service.submit(task)
42
56
}
43
57
0 commit comments