diff --git a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt index 0f7870234..5596cac2a 100644 --- a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt +++ b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/entity/DatabaseEnums.kt @@ -49,6 +49,8 @@ enum class ActionType { CHANGE_COUNTER, /** Send a notification. */ NOTIFICATION, + /** Press the Android back button using accessibility services. */ + BACK_BUTTON, } @@ -156,4 +158,4 @@ enum class IntentExtraType { FLOAT, SHORT, STRING -} \ No newline at end of file +} diff --git a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt index e2298f458..08022e900 100644 --- a/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt +++ b/core/smart/database/src/main/java/com/buzbuz/smartautoclicker/core/database/serialization/compat/CompatDeserializer.kt @@ -364,9 +364,24 @@ internal open class CompatDeserializer : Deserializer { ActionType.TOGGLE_EVENT -> deserializeActionToggleEvent(jsonAction) ActionType.CHANGE_COUNTER -> deserializeActionChangeCounter(jsonAction) ActionType.NOTIFICATION -> deserializeActionNotification(jsonAction) + ActionType.BACK_BUTTON -> deserializeActionBackButton(jsonAction) null -> null } + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + open fun deserializeActionBackButton(jsonBackButton: JsonObject): ActionEntity? { + val id = jsonBackButton.getLong("id", true) ?: return null + val eventId = jsonBackButton.getLong("eventId", true) ?: return null + + return ActionEntity( + id = id, + eventId = eventId, + name = jsonBackButton.getString("name") ?: "", + priority = jsonBackButton.getInt("priority")?.coerceAtLeast(0) ?: 0, + type = ActionType.BACK_BUTTON, + ) + } + @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) open fun deserializeActionClick( jsonClick: JsonObject, @@ -588,4 +603,4 @@ internal open class CompatDeserializer : Deserializer { return EventToggleEntity(id, actionId, type, toggleEventId) } -} \ No newline at end of file +} diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt index 7859390f4..68fa121b3 100644 --- a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/SmartActionExecutor.kt @@ -31,6 +31,9 @@ interface SmartActionExecutor : AndroidExecutor { /** Send a notification defined by the provided NotificationRequest. */ fun executeNotification(notification: NotificationRequest) + /** Press the Android back button using accessibility services. */ + fun executeBackButton() + /** Request to reset any state related to action execution, most likely because a new session is starting. */ fun clearState() } @@ -42,4 +45,4 @@ data class NotificationRequest( val message: String, val groupName: String, val importance: Int, -) \ No newline at end of file +) diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt index 6fe0c5c4b..90aa652df 100644 --- a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/Action.kt @@ -51,5 +51,6 @@ sealed class Action : Identifiable, Completable, Prioritizable { is Swipe -> copy(id = id, eventId = eventId, name = name, priority = priority) is ToggleEvent -> copy(id = id, eventId = eventId, name = name, priority = priority) is Notification -> copy(id = id, eventId = eventId, name = name, priority = priority) + is BackButton -> copy(id = id, eventId = eventId, name = name, priority = priority) } } diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt index 70e4792b2..e5f98ab49 100644 --- a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/ActionMapper.kt @@ -1,16 +1,16 @@ /* * Copyright (C) 2024 Kevin Buzeau - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -43,6 +43,7 @@ internal fun Action.toEntity(): ActionEntity { is ToggleEvent -> toToggleEventEntity() is ChangeCounter -> toChangeCounterEntity() is Notification -> toNotificationEntity() + is BackButton -> toBackButtonEntity() } } @@ -151,8 +152,25 @@ internal fun CompleteActionEntity.toDomain(cleanIds: Boolean = false): Action = ActionType.TOGGLE_EVENT -> toDomainToggleEvent(cleanIds) ActionType.CHANGE_COUNTER -> toDomainChangeCounter(cleanIds) ActionType.NOTIFICATION -> toDomainNotification(cleanIds) + ActionType.BACK_BUTTON -> toDomainBackButton(cleanIds) } +private fun BackButton.toBackButtonEntity(): ActionEntity = + ActionEntity( + id = id.databaseId, + eventId = eventId.databaseId, + priority = priority, + name = name!!, + type = ActionType.BACK_BUTTON, + ) + +private fun CompleteActionEntity.toDomainBackButton(cleanIds: Boolean = false) = BackButton( + id = Identifier(id = action.id, asTemporary = cleanIds), + eventId = Identifier(id = action.eventId, asTemporary = cleanIds), + name = action.name, + priority = action.priority, +) + private fun CompleteActionEntity.toDomainClick(cleanIds: Boolean = false) = Click( id = Identifier(id = action.id, asTemporary = cleanIds), eventId = Identifier(id = action.eventId, asTemporary = cleanIds), diff --git a/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/BackButton.kt b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/BackButton.kt new file mode 100644 index 000000000..8e915d3ee --- /dev/null +++ b/core/smart/domain/src/main/java/com/buzbuz/smartautoclicker/core/domain/model/action/BackButton.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2024 Kevin Buzeau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.buzbuz.smartautoclicker.core.domain.model.action + +import com.buzbuz.smartautoclicker.core.base.identifier.Identifier + +/** Press the Android back button using accessibility services. */ +data class BackButton( + override val id: Identifier, + override val eventId: Identifier, + override val name: String?, + override var priority: Int, +) : Action() { + + override fun hashCodeNoIds(): Int { + var result = name?.hashCode() ?: 0 + result = 31 * result + priority + return result + } + + override fun deepCopy(): Action = copy() +} diff --git a/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt b/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt index c2dc2a32b..3281099b2 100644 --- a/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt +++ b/core/smart/processing/src/main/java/com/buzbuz/smartautoclicker/core/processing/data/processor/ActionExecutor.kt @@ -38,6 +38,7 @@ import com.buzbuz.smartautoclicker.core.domain.model.action.Pause import com.buzbuz.smartautoclicker.core.domain.model.action.Swipe import com.buzbuz.smartautoclicker.core.domain.model.action.ToggleEvent import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.Notification import com.buzbuz.smartautoclicker.core.domain.model.action.intent.putDomainExtra import com.buzbuz.smartautoclicker.core.domain.model.event.Event @@ -95,6 +96,7 @@ internal class ActionExecutor( is ToggleEvent -> executeToggleEvent(action) is ChangeCounter -> executeChangeCounter(action) is Notification -> executeNotification(event, action) + is BackButton -> withContext(Dispatchers.Main) { androidExecutor.executeBackButton() } } } } diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt index e550f2961..0ebdba06a 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditedItemsBuilder.kt @@ -1,16 +1,16 @@ /* * Copyright (C) 2024 Kevin Buzeau - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -26,6 +26,7 @@ import com.buzbuz.smartautoclicker.core.base.identifier.IdentifierCreator import com.buzbuz.smartautoclicker.core.domain.IRepository import com.buzbuz.smartautoclicker.core.domain.model.CounterOperationValue import com.buzbuz.smartautoclicker.core.domain.model.action.Action +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter import com.buzbuz.smartautoclicker.core.domain.model.action.Click import com.buzbuz.smartautoclicker.core.domain.model.action.Click.PositionType @@ -303,6 +304,14 @@ class EditedItemsBuilder internal constructor( priority = 0, ) + fun createNewBackButton(context: Context): BackButton = + BackButton( + id = actionsIdCreator.generateNewIdentifier(), + eventId = getEditedEventIdOrThrow(), + name = defaultValues.backButtonName(context), + priority = 0, + ) + fun createNewActionFrom(from: Action, eventId: Identifier = getEditedEventIdOrThrow()): Action = when (from) { is Click -> createNewClickFrom(from, eventId) is Swipe -> createNewSwipeFrom(from, eventId) @@ -311,6 +320,7 @@ class EditedItemsBuilder internal constructor( is ToggleEvent -> createNewToggleEventFrom(from, eventId) is ChangeCounter -> createNewChangeCounterFrom(from, eventId) is Notification -> createNewNotificationFrom(from, eventId) + is BackButton -> createNewBackButtonFrom(from, eventId) } private fun createNewClickFrom(from: Click, eventId: Identifier): Click { @@ -327,6 +337,13 @@ class EditedItemsBuilder internal constructor( ) } + private fun createNewBackButtonFrom(from: BackButton, eventId: Identifier): BackButton = + from.copy( + id = actionsIdCreator.generateNewIdentifier(), + eventId = eventId, + name = "" + from.name, + ) + private fun createNewSwipeFrom(from: Swipe, eventId: Identifier): Swipe = from.copy( id = actionsIdCreator.generateNewIdentifier(), @@ -425,4 +442,4 @@ class EditedItemsBuilder internal constructor( ?: throw IllegalStateException("Can't create items without an edited action") private fun getEditedImageEventsCountOrThrow(): Int = editor.getEditedImageEventsCount() -} \ No newline at end of file +} diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt index 7b1789005..beac1b14d 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/domain/EditionDefaultValues.kt @@ -83,9 +83,12 @@ internal class EditionDefaultValues(private val scenarioRepository: IRepository) fun notificationName(context: Context): String = context.getString(R.string.default_notification_name) + fun backButtonName(context: Context): String = + context.getString(R.string.item_back_button_title) + fun counterComparisonOperation(): TriggerCondition.OnCounterCountReached.ComparisonOperation = TriggerCondition.OnCounterCountReached.ComparisonOperation.EQUALS private fun isTutorialModeEnabled(): Boolean = scenarioRepository.isTutorialModeEnabled() -} \ No newline at end of file +} diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt index 5fcd2cda5..497175667 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/BaseSmartActionUiFlow.kt @@ -21,6 +21,7 @@ import com.buzbuz.smartautoclicker.core.common.overlays.base.BaseOverlay import com.buzbuz.smartautoclicker.core.common.permissions.model.PermissionPostNotification import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.starters.RequestNotificationPermissionActivity import com.buzbuz.smartautoclicker.core.domain.model.action.Action +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter import com.buzbuz.smartautoclicker.core.domain.model.action.Click import com.buzbuz.smartautoclicker.core.domain.model.action.Intent @@ -102,7 +103,11 @@ internal fun BaseOverlay.showActionConfigDialog(configurator: ActionConfigurator if (PermissionPostNotification().checkIfGranted(context)) NotificationDialog(actionConfigDialogListener) else newNotificationPermissionStarterOverlay(context) } - else -> throw IllegalArgumentException("Not yet supported") + is BackButton -> { + configurator.upsertEditedAction() + return + } + else -> throw IllegalArgumentException("Unsupported action type") } @@ -111,4 +116,4 @@ internal fun BaseOverlay.showActionConfigDialog(configurator: ActionConfigurator newOverlay = overlay, hideCurrent = true, ) -} \ No newline at end of file +} diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt index 77ff1bf1e..6fb825a2b 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/brief/SmartActionsBriefViewModel.kt @@ -127,6 +127,7 @@ class SmartActionsBriefViewModel @Inject constructor( add(ActionTypeChoice.ToggleEvent) add(ActionTypeChoice.Notification) add(ActionTypeChoice.Intent) + add(ActionTypeChoice.BackButton) } }.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList()) @@ -169,6 +170,7 @@ class SmartActionsBriefViewModel @Inject constructor( ActionTypeChoice.ToggleEvent -> editionRepository.editedItemsBuilder.createNewToggleEvent(context) ActionTypeChoice.ChangeCounter -> editionRepository.editedItemsBuilder.createNewChangeCounter(context) ActionTypeChoice.Notification -> editionRepository.editedItemsBuilder.createNewNotification(context) + ActionTypeChoice.BackButton -> editionRepository.editedItemsBuilder.createNewBackButton(context) ActionTypeChoice.Copy -> throw IllegalArgumentException("Unsupported action type for creation $choice") } @@ -326,4 +328,4 @@ class SmartActionsBriefViewModel @Inject constructor( private data class BriefVisualizationState( val focusedIndex: Int, val gestureCaptureStarted: Boolean, -) \ No newline at end of file +) diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt index ee2f0a018..abeeae234 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/action/selection/ActionTypeChoices.kt @@ -18,6 +18,7 @@ package com.buzbuz.smartautoclicker.feature.smart.config.ui.action.selection import com.buzbuz.smartautoclicker.core.common.overlays.dialog.implementation.DialogChoice import com.buzbuz.smartautoclicker.feature.smart.config.R +import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getBackButtonIconRes import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getChangeCounterIconRes import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getClickIconRes import com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action.getIntentIconRes @@ -88,4 +89,11 @@ sealed class ActionTypeChoice( R.string.item_notification_desc, getNotificationIconRes(), ) -} \ No newline at end of file + + /** Back Button Action choice. */ + data object BackButton : ActionTypeChoice( + R.string.item_back_button_title, + R.string.item_back_button_desc, + getBackButtonIconRes(), + ) +} diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt index 01b22a0cf..0e833942b 100644 --- a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiAction.kt @@ -19,6 +19,7 @@ package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action import android.content.Context import androidx.annotation.DrawableRes import com.buzbuz.smartautoclicker.core.domain.model.action.Action +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton import com.buzbuz.smartautoclicker.core.domain.model.action.ChangeCounter import com.buzbuz.smartautoclicker.core.domain.model.action.Click import com.buzbuz.smartautoclicker.core.domain.model.action.Intent @@ -55,6 +56,7 @@ internal fun Action.getIconRes(): Int = when (this) { is ToggleEvent -> getToggleEventIconRes() is ChangeCounter -> getChangeCounterIconRes() is Notification -> getNotificationIconRes() + is BackButton -> getBackButtonIconRes() else -> throw IllegalArgumentException("Not yet supported") } @@ -66,5 +68,6 @@ internal fun Action.getActionDescription(context: Context, parent: Event, inErro is ToggleEvent -> getDescription(context, inError) is ChangeCounter -> getDescription(context, inError) is Notification -> getDescription(context, inError) + is BackButton -> getDescription(context) else -> throw IllegalArgumentException("Not yet supported") } diff --git a/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt new file mode 100644 index 000000000..c59c99253 --- /dev/null +++ b/feature/smart-config/src/main/java/com/buzbuz/smartautoclicker/feature/smart/config/ui/common/model/action/UiBackButton.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2024 Kevin Buzeau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.buzbuz.smartautoclicker.feature.smart.config.ui.common.model.action + +import android.content.Context +import androidx.annotation.DrawableRes +import com.buzbuz.smartautoclicker.core.domain.model.action.BackButton +import com.buzbuz.smartautoclicker.feature.smart.config.R + + +@DrawableRes +internal fun getBackButtonIconRes(): Int = R.drawable.ic_back + +internal fun BackButton.getDescription(context: Context): String = + context.getString(R.string.item_back_button_details) diff --git a/feature/smart-config/src/main/res/values/strings.xml b/feature/smart-config/src/main/res/values/strings.xml index f0db1a2ba..2ce22c9ee 100644 --- a/feature/smart-config/src/main/res/values/strings.xml +++ b/feature/smart-config/src/main/res/values/strings.xml @@ -89,6 +89,10 @@ Send \"%1$s\" Send %1$s value + Back Button + Press the Android back button + Press back button + Search by event name @@ -389,4 +393,4 @@ Open the event list The icon of the application to start. - \ No newline at end of file + diff --git a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt index 97a9da7b5..1974f96ea 100644 --- a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt +++ b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/SmartAutoClickerService.kt @@ -198,6 +198,10 @@ class SmartAutoClickerService : AccessibilityService(), SmartActionExecutor { userNotificationsController.showNotification(this, notification) } + override fun executeBackButton() { + serviceActionExecutor?.safePerformGlobalBack() + } + override fun clearState() { userNotificationsController.clearAll() } @@ -231,4 +235,4 @@ class SmartAutoClickerService : AccessibilityService(), SmartActionExecutor { } /** Tag for the logs. */ -private const val TAG = "SmartAutoClickerService" \ No newline at end of file +private const val TAG = "SmartAutoClickerService" diff --git a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt index dda01ca70..f293caf6e 100644 --- a/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt +++ b/smartautoclicker/src/main/java/com/buzbuz/smartautoclicker/actions/ServiceActionExecutor.kt @@ -66,9 +66,15 @@ class ServiceActionExecutor(private val service: AccessibilityService) : Dumpabl } } + fun safePerformGlobalBack() { + if (!service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)) { + Log.w(TAG, "Failed to execute back action") + } + } + override fun dump(writer: PrintWriter, prefix: CharSequence) { gestureExecutor.dump(writer, prefix) } } -private const val TAG = "ServiceActionExecutor" \ No newline at end of file +private const val TAG = "ServiceActionExecutor"