Skip to content

Commit 5dee8df

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents d84cc05 + 6afa0bf commit 5dee8df

26 files changed

+197
-65
lines changed

app-common-io/src/main/java/eu/darken/sdmse/common/files/core/PathExceptions.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package eu.darken.sdmse.common.files.core
22

3-
import android.content.Context
3+
import eu.darken.sdmse.common.ca.caString
4+
import eu.darken.sdmse.common.ca.toCaString
45
import eu.darken.sdmse.common.error.HasLocalizedError
56
import eu.darken.sdmse.common.error.LocalizedError
67
import eu.darken.sdmse.common.io.R
@@ -21,10 +22,10 @@ open class ReadException(
2122

2223
constructor(file: File) : this(RawPath.build(file))
2324

24-
override fun getLocalizedError(context: Context) = LocalizedError(
25+
override fun getLocalizedError() = LocalizedError(
2526
throwable = this,
26-
label = "ReadException",
27-
description = context.getString(R.string.general_error_cant_access_msg, path)
27+
label = "ReadException".toCaString(),
28+
description = caString { it.getString(R.string.general_error_cant_access_msg, path) }
2829
)
2930
}
3031

@@ -36,9 +37,9 @@ class WriteException(
3637

3738
constructor(file: File) : this(RawPath.build(file))
3839

39-
override fun getLocalizedError(context: Context) = LocalizedError(
40+
override fun getLocalizedError() = LocalizedError(
4041
throwable = this,
41-
label = "WriteException",
42-
description = context.getString(R.string.general_error_cant_access_msg, path)
42+
label = "WriteException".toCaString(),
43+
description = caString { it.getString(R.string.general_error_cant_access_msg, path) }
4344
)
4445
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package eu.darken.sdmse.common.root
22

3-
import android.content.Context
43
import androidx.annotation.StringRes
4+
import eu.darken.sdmse.common.ca.toCaString
55
import eu.darken.sdmse.common.error.HasLocalizedError
66
import eu.darken.sdmse.common.error.LocalizedError
77
import eu.darken.sdmse.common.io.R
@@ -13,9 +13,9 @@ class RootUnavailableException(
1313
@StringRes val errorMsgRes: Int = R.string.general_error_root_unavailable
1414
) : RootException(message, cause), HasLocalizedError {
1515

16-
override fun getLocalizedError(context: Context) = LocalizedError(
16+
override fun getLocalizedError() = LocalizedError(
1717
throwable = this,
18-
label = "RootUnavailableException",
19-
description = context.getString(errorMsgRes)
18+
label = "RootUnavailableException".toCaString(),
19+
description = errorMsgRes.toCaString()
2020
)
2121
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package eu.darken.sdmse.common
22

3-
import android.content.Context
43
import androidx.annotation.StringRes
4+
import eu.darken.sdmse.common.ca.toCaString
55
import eu.darken.sdmse.common.error.HasLocalizedError
66
import eu.darken.sdmse.common.error.LocalizedError
77

@@ -11,9 +11,9 @@ class RootRequiredException(
1111
@StringRes val errorMsgRes: Int = R.string.general_error_root_unavailable
1212
) : IllegalStateException(message, cause), HasLocalizedError {
1313

14-
override fun getLocalizedError(context: Context) = LocalizedError(
14+
override fun getLocalizedError() = LocalizedError(
1515
throwable = this,
16-
label = "RootRequiredException",
17-
description = context.getString(errorMsgRes)
16+
label = "RootRequiredException".toCaString(),
17+
description = errorMsgRes.toCaString()
1818
)
1919
}

app-common/src/main/java/eu/darken/sdmse/common/TypeMissMatchException.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package eu.darken.sdmse.common
22

3-
import android.content.Context
3+
import eu.darken.sdmse.common.ca.caString
4+
import eu.darken.sdmse.common.ca.toCaString
45
import eu.darken.sdmse.common.error.HasLocalizedError
56
import eu.darken.sdmse.common.error.LocalizedError
67

78
class TypeMissMatchException(private val expected: Any, private val actual: Any) :
89
IllegalArgumentException("Type missmatch: Wanted $expected, but got $actual."), HasLocalizedError {
910

10-
override fun getLocalizedError(context: Context) = LocalizedError(
11+
override fun getLocalizedError() = LocalizedError(
1112
throwable = this,
12-
label = "TypeMissMatchException",
13-
description = context.getString(R.string.general_error_type_mismatch_msg, expected, actual)
13+
label = "TypeMissMatchException".toCaString(),
14+
description = caString { it.getString(R.string.general_error_type_mismatch_msg, expected, actual) }
1415
)
1516

1617
companion object {

app-common/src/main/java/eu/darken/sdmse/common/error/ErrorDialog.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ fun Throwable.asErrorDialogBuilder(
99
val error = this@asErrorDialogBuilder
1010
val localizedError = error.localized(context)
1111

12-
setTitle(localizedError.label)
13-
setMessage(localizedError.description)
12+
setTitle(localizedError.label.get(context))
13+
setMessage(localizedError.description.get(context))
1414

1515
setPositiveButton(android.R.string.ok) { _, _ ->
1616

app-common/src/main/java/eu/darken/sdmse/common/error/LocalizedError.kt

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@ package eu.darken.sdmse.common.error
22

33
import android.content.Context
44
import eu.darken.sdmse.common.R
5+
import eu.darken.sdmse.common.ca.CaString
6+
import eu.darken.sdmse.common.ca.caString
57

68
interface HasLocalizedError {
7-
fun getLocalizedError(context: Context): LocalizedError
9+
fun getLocalizedError(): LocalizedError
810
}
911

1012
data class LocalizedError(
1113
val throwable: Throwable,
12-
val label: String,
13-
val description: String
14+
val label: CaString,
15+
val description: CaString,
16+
val fixAction: ((Context) -> Unit)? = null,
17+
val infoAction: ((Context) -> Unit)? = null,
1418
) {
1519
fun asText() = "$label:\n$description"
1620
}
1721

1822
fun Throwable.localized(c: Context): LocalizedError = when {
19-
this is HasLocalizedError -> this.getLocalizedError(c)
23+
this is HasLocalizedError -> this.getLocalizedError()
2024
localizedMessage != null -> LocalizedError(
2125
throwable = this,
22-
label = "${c.getString(R.string.general_error_label)}: ${this::class.simpleName!!}",
23-
description = localizedMessage ?: getStackTracePeek()
26+
label = caString { "${c.getString(R.string.general_error_label)}: ${this::class.simpleName!!}" },
27+
description = caString { localizedMessage ?: getStackTracePeek() }
2428
)
2529
else -> LocalizedError(
2630
throwable = this,
27-
label = "${c.getString(R.string.general_error_label)}: ${this::class.simpleName!!}",
28-
description = getStackTracePeek()
31+
label = caString { "${c.getString(R.string.general_error_label)}: ${this::class.simpleName!!}" },
32+
description = caString { getStackTracePeek() }
2933
)
3034
}
3135

Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package eu.darken.sdmse.common.upgrade.core.billing
22

3-
import android.content.Context
43
import eu.darken.sdmse.R
4+
import eu.darken.sdmse.common.ca.toCaString
55
import eu.darken.sdmse.common.error.HasLocalizedError
66
import eu.darken.sdmse.common.error.LocalizedError
77

88
class GplayServiceUnavailableException(cause: Throwable) :
99
BillingException("Google Play services are unavailable.", cause), HasLocalizedError {
1010

11-
override fun getLocalizedError(context: Context): LocalizedError = LocalizedError(
11+
override fun getLocalizedError(): LocalizedError = LocalizedError(
1212
throwable = this,
13-
label = "Google Play Services Unavailable",
14-
description = context.getString(R.string.upgrades_gplay_unavailable_error)
13+
label = "Google Play Services Unavailable".toCaString(),
14+
description = R.string.upgrades_gplay_unavailable_error.toCaString()
1515
)
1616

1717
}

app/src/main/java/eu/darken/sdmse/appcleaner/core/AppCleaner.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import eu.darken.sdmse.appcleaner.core.tasks.AppCleanerScanTask
1313
import eu.darken.sdmse.appcleaner.core.tasks.AppCleanerSchedulerTask
1414
import eu.darken.sdmse.appcleaner.core.tasks.AppCleanerTask
1515
import eu.darken.sdmse.automation.core.AutomationController
16+
import eu.darken.sdmse.automation.core.errors.AutomationUnavailableException
1617
import eu.darken.sdmse.common.ca.CaString
1718
import eu.darken.sdmse.common.ca.caString
1819
import eu.darken.sdmse.common.coroutine.AppScope
1920
import eu.darken.sdmse.common.debug.logging.Logging.Priority.*
20-
import eu.darken.sdmse.common.debug.logging.asLog
2121
import eu.darken.sdmse.common.debug.logging.log
2222
import eu.darken.sdmse.common.debug.logging.logTag
2323
import eu.darken.sdmse.common.files.core.*
@@ -164,9 +164,8 @@ class AppCleaner @Inject constructor(
164164
val automationTask = ClearCacheTask(automationTargets)
165165
val automationResult = try {
166166
automationController.submit(automationTask) as ClearCacheTask.Result
167-
} catch (e: IllegalStateException) {
168-
log(TAG, WARN) { "Accessibility service was not running: ${e.asLog()}" }
169-
ClearCacheTask.Result(successful = emptySet(), failed = automationTargets)
167+
} catch (e: AutomationUnavailableException) {
168+
throw InaccessibleDeletionException(e)
170169
}
171170

172171
internalData.value = snapshot.copy(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package eu.darken.sdmse.appcleaner.core
2+
3+
import eu.darken.sdmse.R
4+
import eu.darken.sdmse.common.ca.caString
5+
import eu.darken.sdmse.common.ca.toCaString
6+
import eu.darken.sdmse.common.error.HasLocalizedError
7+
import eu.darken.sdmse.common.error.LocalizedError
8+
9+
class InaccessibleDeletionException(
10+
override val cause: Throwable
11+
) : IllegalStateException(), HasLocalizedError {
12+
13+
// TODO how can we get webpage tool and nav actions executed here?
14+
override fun getLocalizedError(): LocalizedError = LocalizedError(
15+
throwable = this,
16+
label = R.string.appcleaner_automation_unavailable_title.toCaString(),
17+
description = caString {
18+
val sb = StringBuilder()
19+
sb.append(it.getString(R.string.appcleaner_automation_unavailable_body))
20+
if (cause is HasLocalizedError) {
21+
sb.append("\n\n")
22+
sb.append(cause.getLocalizedError().description.get(it))
23+
}
24+
sb.toString()
25+
},
26+
)
27+
28+
}

app/src/main/java/eu/darken/sdmse/automation/core/AutomationController.kt

+16-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ import android.content.Context
55
import android.provider.Settings
66
import android.text.TextUtils
77
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
813
import eu.darken.sdmse.common.debug.logging.log
914
import eu.darken.sdmse.common.debug.logging.logTag
15+
import eu.darken.sdmse.main.core.GeneralSettings
1016
import javax.inject.Inject
1117
import javax.inject.Singleton
1218

1319
@Singleton
1420
class AutomationController @Inject constructor(
15-
@ApplicationContext val context: Context
21+
@ApplicationContext val context: Context,
22+
private val generalSettings: GeneralSettings,
1623
) {
1724

25+
fun hasConsent(): Boolean = generalSettings.hasAcsConsent.valueBlocking == true
26+
1827
fun isServiceEnabled(): Boolean {
1928
val comp = ComponentName(context, AutomationService::class.java)
2029

@@ -37,7 +46,12 @@ class AutomationController @Inject constructor(
3746

3847
suspend fun submit(task: AutomationTask): AutomationTask.Result {
3948
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()
4155
return service.submit(task)
4256
}
4357

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package eu.darken.sdmse.automation.core.errors
2+
3+
open class AutomationException : Exception()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package eu.darken.sdmse.automation.core.errors
2+
3+
import eu.darken.sdmse.R
4+
import eu.darken.sdmse.common.ca.toCaString
5+
import eu.darken.sdmse.common.error.HasLocalizedError
6+
import eu.darken.sdmse.common.error.LocalizedError
7+
8+
open class AutomationNoConsentException(
9+
override val message: String = "Accessibility service is not enabled"
10+
) : AutomationUnavailableException(), HasLocalizedError {
11+
12+
override fun getLocalizedError(): LocalizedError = LocalizedError(
13+
throwable = this,
14+
label = R.string.automation_error_not_enabled_title.toCaString(),
15+
description = R.string.automation_error_not_enabled_body.toCaString(),
16+
)
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package eu.darken.sdmse.automation.core.errors
2+
3+
import eu.darken.sdmse.R
4+
import eu.darken.sdmse.common.ca.toCaString
5+
import eu.darken.sdmse.common.error.HasLocalizedError
6+
import eu.darken.sdmse.common.error.LocalizedError
7+
8+
open class AutomationNotEnabledException(
9+
override val message: String = "Accessibility service is not enabled"
10+
) : AutomationUnavailableException(), HasLocalizedError {
11+
12+
override fun getLocalizedError(): LocalizedError = LocalizedError(
13+
throwable = this,
14+
label = R.string.automation_error_not_enabled_title.toCaString(),
15+
description = R.string.automation_error_not_enabled_body.toCaString(),
16+
)
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package eu.darken.sdmse.automation.core.errors
2+
3+
import eu.darken.sdmse.R
4+
import eu.darken.sdmse.common.ca.toCaString
5+
import eu.darken.sdmse.common.error.HasLocalizedError
6+
import eu.darken.sdmse.common.error.LocalizedError
7+
8+
open class AutomationNotRunningException(
9+
override val message: String = "Accessibility service isn't running"
10+
) : AutomationUnavailableException(), HasLocalizedError {
11+
override fun getLocalizedError(): LocalizedError = LocalizedError(
12+
throwable = this,
13+
label = R.string.automation_error_not_running_title.toCaString(),
14+
description = R.string.automation_error_not_running_body.toCaString(),
15+
)
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package eu.darken.sdmse.automation.core.errors
2+
3+
open class AutomationUnavailableException : AutomationException()

app/src/main/java/eu/darken/sdmse/setup/SetupAdapter.kt

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class SetupAdapter @Inject constructor() :
4444
) : VH(layoutId, parent), BindableVH<D, B>
4545

4646
interface Item : DifferItem {
47+
48+
val state: SetupModule.State
49+
4750
override val payloadProvider: ((DifferItem, DifferItem) -> DifferItem?)
4851
get() = { old, new ->
4952
if (new::class.isInstance(old)) new else null

0 commit comments

Comments
 (0)