Skip to content

Commit 6b2f633

Browse files
Expand ADB testing bridge actions (#2501)
Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent 2ed7c68 commit 6b2f633

4 files changed

Lines changed: 56 additions & 25 deletions

File tree

TESTING.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ com.enaboapps.switchify.debug.PERFORM_SWITCH_ACTION
2020

2121
### Action Names
2222

23+
Every current `SwitchAction` has a string alias:
24+
2325
```text
2426
none
2527
select
@@ -40,12 +42,19 @@ toggle_gesture_lock_rearm
4042
toggle_gesture_repeat
4143
```
4244

45+
The bridge also accepts this debug-only service command:
46+
47+
```text
48+
reload_settings
49+
```
50+
4351
### Examples
4452

4553
```powershell
4654
adb shell am broadcast -a com.enaboapps.switchify.debug.PERFORM_SWITCH_ACTION -p com.enaboapps.switchify --es action next
4755
adb shell am broadcast -a com.enaboapps.switchify.debug.PERFORM_SWITCH_ACTION -p com.enaboapps.switchify --es action previous
4856
adb shell am broadcast -a com.enaboapps.switchify.debug.PERFORM_SWITCH_ACTION -p com.enaboapps.switchify --es action select
57+
adb shell am broadcast -a com.enaboapps.switchify.debug.PERFORM_SWITCH_ACTION -p com.enaboapps.switchify --es action reload_settings
4958
```
5059

5160
Action IDs are also accepted:
@@ -86,6 +95,6 @@ stop_scanning
8695
change_scanning_direction
8796
```
8897

89-
## Local Harness
98+
## Agentic QA Harness
9099

91-
The local harness in `switchify-agents-testing` can prime scan settings, send bridge actions, capture evidence, and restore preference backups. If it changes preferences or switch configuration, restore from that run directory when finished.
100+
The agentic QA harness in [switchifyapp/switchify-android-agentic-qa](https://github.com/switchifyapp/switchify-android-agentic-qa) can prime scan settings, send bridge actions, capture evidence, and restore preference backups. If it changes preferences or switch configuration, restore from that run directory when finished.

app/src/main/java/com/enaboapps/switchify/screens/DebugScreen.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ fun DebugScreen(navController: NavController) {
164164
.padding(horizontal = 16.dp, vertical = 4.dp),
165165
applyPadding = false
166166
)
167+
ActionButton(
168+
textResId = R.string.debug_adb_reload_settings,
169+
type = ActionButtonType.SECONDARY,
170+
onClick = {
171+
ServiceBridge.sendCommand(ServiceBridge.ServiceCommand.ReloadSettings)
172+
},
173+
modifier = Modifier
174+
.fillMaxWidth()
175+
.padding(horizontal = 16.dp, vertical = 4.dp),
176+
applyPadding = false
177+
)
167178
}
168179
}
169180
}

app/src/main/java/com/enaboapps/switchify/service/core/AdbTestingBridgeReceiver.kt

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ import com.enaboapps.switchify.switches.SwitchAction
1010
class AdbTestingBridgeReceiver : BroadcastReceiver() {
1111
override fun onReceive(context: Context?, intent: Intent?) {
1212
if (!BuildConfig.DEBUG || intent?.action != ACTION_PERFORM_SWITCH_ACTION) return
13+
14+
val actionName = intent.getStringExtra(EXTRA_ACTION)?.lowercase()
15+
if (actionName == ACTION_RELOAD_SETTINGS) {
16+
Log.d(TAG, "Performing ADB testing command: $ACTION_RELOAD_SETTINGS")
17+
ServiceBridge.sendCommand(ServiceBridge.ServiceCommand.ReloadSettings)
18+
return
19+
}
20+
1321
val actionId = resolveActionId(intent)
1422
if (!isValidActionId(actionId)) {
15-
Log.w(TAG, "Ignoring invalid ADB testing action: $actionId")
23+
Log.w(TAG, "Ignoring invalid ADB testing action: ${actionName ?: actionId}")
1624
return
1725
}
1826
ServiceBridge.sendCommand(
@@ -27,26 +35,7 @@ class AdbTestingBridgeReceiver : BroadcastReceiver() {
2735
if (intent.hasExtra(EXTRA_ACTION_ID)) {
2836
return intent.getIntExtra(EXTRA_ACTION_ID, INVALID_ACTION_ID)
2937
}
30-
return when (intent.getStringExtra(EXTRA_ACTION)?.lowercase()) {
31-
"none" -> SwitchAction.ACTION_NONE
32-
"select" -> SwitchAction.ACTION_SELECT
33-
"stop_scanning" -> SwitchAction.ACTION_STOP_SCANNING
34-
"change_scanning_direction" -> SwitchAction.ACTION_CHANGE_SCANNING_DIRECTION
35-
"next" -> SwitchAction.ACTION_MOVE_TO_NEXT_ITEM
36-
"previous" -> SwitchAction.ACTION_MOVE_TO_PREVIOUS_ITEM
37-
"toggle_gesture_lock" -> SwitchAction.ACTION_TOGGLE_GESTURE_LOCK
38-
"home" -> SwitchAction.ACTION_SYS_HOME
39-
"back" -> SwitchAction.ACTION_SYS_BACK
40-
"recents" -> SwitchAction.ACTION_SYS_RECENTS
41-
"quick_settings" -> SwitchAction.ACTION_SYS_QUICK_SETTINGS
42-
"notifications" -> SwitchAction.ACTION_SYS_NOTIFICATIONS
43-
"lock_screen" -> SwitchAction.ACTION_SYS_LOCK_SCREEN
44-
"media_play_pause" -> SwitchAction.ACTION_SYS_HEADSET_HOOK
45-
"pause" -> SwitchAction.ACTION_PAUSE
46-
"toggle_gesture_lock_rearm" -> SwitchAction.ACTION_TOGGLE_GESTURE_LOCK_REARM
47-
"toggle_gesture_repeat" -> SwitchAction.ACTION_TOGGLE_GESTURE_REPEAT
48-
else -> INVALID_ACTION_ID
49-
}
38+
return actionNameToId[intent.getStringExtra(EXTRA_ACTION)?.lowercase()] ?: INVALID_ACTION_ID
5039
}
5140

5241
private fun isValidActionId(actionId: Int): Boolean {
@@ -58,7 +47,28 @@ class AdbTestingBridgeReceiver : BroadcastReceiver() {
5847
"com.enaboapps.switchify.debug.PERFORM_SWITCH_ACTION"
5948
const val EXTRA_ACTION = "action"
6049
const val EXTRA_ACTION_ID = "action_id"
50+
const val ACTION_RELOAD_SETTINGS = "reload_settings"
6151
private const val INVALID_ACTION_ID = -1
6252
private const val TAG = "AdbTestingBridge"
53+
54+
val actionNameToId = mapOf(
55+
"none" to SwitchAction.ACTION_NONE,
56+
"select" to SwitchAction.ACTION_SELECT,
57+
"stop_scanning" to SwitchAction.ACTION_STOP_SCANNING,
58+
"change_scanning_direction" to SwitchAction.ACTION_CHANGE_SCANNING_DIRECTION,
59+
"next" to SwitchAction.ACTION_MOVE_TO_NEXT_ITEM,
60+
"previous" to SwitchAction.ACTION_MOVE_TO_PREVIOUS_ITEM,
61+
"toggle_gesture_lock" to SwitchAction.ACTION_TOGGLE_GESTURE_LOCK,
62+
"home" to SwitchAction.ACTION_SYS_HOME,
63+
"back" to SwitchAction.ACTION_SYS_BACK,
64+
"recents" to SwitchAction.ACTION_SYS_RECENTS,
65+
"quick_settings" to SwitchAction.ACTION_SYS_QUICK_SETTINGS,
66+
"notifications" to SwitchAction.ACTION_SYS_NOTIFICATIONS,
67+
"lock_screen" to SwitchAction.ACTION_SYS_LOCK_SCREEN,
68+
"media_play_pause" to SwitchAction.ACTION_SYS_HEADSET_HOOK,
69+
"pause" to SwitchAction.ACTION_PAUSE,
70+
"toggle_gesture_lock_rearm" to SwitchAction.ACTION_TOGGLE_GESTURE_LOCK_REARM,
71+
"toggle_gesture_repeat" to SwitchAction.ACTION_TOGGLE_GESTURE_REPEAT
72+
)
6373
}
6474
}

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,12 @@
657657
<string name="debug_section_crash_reporting">Crash Reporting</string>
658658
<string name="debug_section_adb_testing">ADB Testing</string>
659659
<string name="debug_force_crash">Force Crash</string>
660-
<string name="debug_adb_testing_summary">Debug builds listen for %1$s while the accessibility service is running. Use it to perform Switchify actions from ADB without relying on synthetic key events.</string>
661-
<string name="debug_adb_testing_examples">adb shell am broadcast -a %1$s -p com.enaboapps.switchify --es action next\nadb shell am broadcast -a %1$s -p com.enaboapps.switchify --es action previous\nadb shell am broadcast -a %1$s -p com.enaboapps.switchify --es action select</string>
660+
<string name="debug_adb_testing_summary">Debug builds listen for %1$s while the accessibility service is running. Use it to perform Switchify actions and reload settings from ADB without relying on synthetic key events.</string>
661+
<string name="debug_adb_testing_examples">adb shell am broadcast -a %1$s -p com.enaboapps.switchify --es action next\nadb shell am broadcast -a %1$s -p com.enaboapps.switchify --es action home\nadb shell am broadcast -a %1$s -p com.enaboapps.switchify --es action reload_settings</string>
662662
<string name="debug_adb_test_next">Test Next</string>
663663
<string name="debug_adb_test_previous">Test Previous</string>
664664
<string name="debug_adb_test_select">Test Select</string>
665+
<string name="debug_adb_reload_settings">Reload Settings</string>
665666

666667
<!-- Button Labels -->
667668
<string name="button_website">Website</string>

0 commit comments

Comments
 (0)