Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppCleaner: When using the scheduler on Android TV use back button in stead of home button after finishing ACS operations #1320

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import eu.darken.sdmse.common.debug.logging.Logging.Priority.WARN
import eu.darken.sdmse.common.debug.logging.asLog
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.device.DeviceDetective
import eu.darken.sdmse.common.funnel.IPCFunnel
import eu.darken.sdmse.common.pkgs.PkgRepo
import eu.darken.sdmse.common.pkgs.features.Installed
Expand All @@ -68,6 +69,7 @@ class ClearCacheModule @AssistedInject constructor(
private val specGenerators: Provider<Set<@JvmSuppressWildcards AppCleanerSpecGenerator>>,
private val userManager2: UserManager2,
private val labelDebugger: LabelDebugger,
private val deviceDetective: DeviceDetective,
) : AutomationModule(automationHost) {

private fun getPriotizedSpecGenerators(): List<AppCleanerSpecGenerator> = specGenerators
Expand Down Expand Up @@ -175,6 +177,7 @@ class ClearCacheModule @AssistedInject constructor(
finishAutomation(
userCancelled = cancelledByUser,
returnToApp = task.returnToApp,
deviceDetective = deviceDetective,
)

return ClearCacheTask.Result(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import eu.darken.sdmse.common.debug.logging.Logging.Priority.WARN
import eu.darken.sdmse.common.debug.logging.asLog
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.debug.logging.logTag
import eu.darken.sdmse.common.device.DeviceDetective
import eu.darken.sdmse.common.pkgs.PkgRepo
import eu.darken.sdmse.common.pkgs.features.Installed
import eu.darken.sdmse.common.pkgs.getPkg
Expand All @@ -56,6 +57,7 @@ class AppControlAutomation @AssistedInject constructor(
private val specGenerators: Provider<Set<@JvmSuppressWildcards AppControlSpecGenerator>>,
private val userManager2: UserManager2,
private val labelDebugger: AppControlLabelDebugger,
private val deviceDetective: DeviceDetective,
) : AutomationModule(automationHost) {

private fun getPriotizedSpecGenerators(): List<AppControlSpecGenerator> = specGenerators
Expand Down Expand Up @@ -170,6 +172,7 @@ class AppControlAutomation @AssistedInject constructor(
finishAutomation(
userCancelled = cancelledByUser,
returnToApp = true,
deviceDetective = deviceDetective,
)

return ForceStopAutomationTask.Result(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import eu.darken.sdmse.common.debug.Bugs
import eu.darken.sdmse.common.debug.logging.Logging.Priority.INFO
import eu.darken.sdmse.common.debug.logging.Logging.Priority.VERBOSE
import eu.darken.sdmse.common.debug.logging.log
import eu.darken.sdmse.common.device.DeviceDetective
import eu.darken.sdmse.common.device.RomType
import eu.darken.sdmse.main.ui.MainActivity
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.NonCancellable
Expand Down Expand Up @@ -36,7 +38,8 @@ suspend fun AutomationHost.waitForWindowRoot(delayMs: Long = 250): Accessibility
suspend fun AutomationModule.finishAutomation(
// If we aborted due to an exception and the reason is "User has cancelled", then still clean up
userCancelled: Boolean,
returnToApp: Boolean
returnToApp: Boolean,
deviceDetective: DeviceDetective,
) = withContext(if (userCancelled) NonCancellable else EmptyCoroutineContext) {
if (returnToApp) {
log(INFO) { "finishAutomation(...): Returning to SD Maid" }
Expand All @@ -48,7 +51,17 @@ suspend fun AutomationModule.finishAutomation(
}
context.startActivity(returnIntern)
} else {
log(INFO) { "finishAutomation(...): Going to home screen" }
host.service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME)
when (deviceDetective.getROMType()) {
RomType.ANDROID_TV -> {
log(INFO) { "finishAutomation(...): Going back via back button" }
val backAction = host.service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)
log(VERBOSE) { "finishAutomation(...): Back button successful=$backAction" }
}

else -> {
log(INFO) { "finishAutomation(...): Going to home screen" }
host.service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME)
}
}
}
}
Loading