Add switch command to switch to a package
Browse files
puppet/app/src/main/java/com/ttt246/puppet/PuppetAS.kt
CHANGED
|
@@ -106,6 +106,7 @@ open class PuppetAS : AccessibilityService() {
|
|
| 106 |
when {
|
| 107 |
isIntentCommand(command) -> executeIntentCommand(command)
|
| 108 |
isAccCommand(command) -> executeAccCommand(command)
|
|
|
|
| 109 |
else -> Log.e("PuppetAS", "Invalid command: $command")
|
| 110 |
}
|
| 111 |
}
|
|
@@ -119,7 +120,12 @@ open class PuppetAS : AccessibilityService() {
|
|
| 119 |
return command.startsWith("acc:")
|
| 120 |
}
|
| 121 |
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
val accCommand = command.removePrefix("acc:")
|
| 124 |
Log.i("PuppetAS", "Executing Acc command: $accCommand")
|
| 125 |
|
|
@@ -249,6 +255,23 @@ open class PuppetAS : AccessibilityService() {
|
|
| 249 |
startActivity(intent)
|
| 250 |
}
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
private var lastOutput: String? = null
|
| 253 |
|
| 254 |
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
|
|
|
|
| 106 |
when {
|
| 107 |
isIntentCommand(command) -> executeIntentCommand(command)
|
| 108 |
isAccCommand(command) -> executeAccCommand(command)
|
| 109 |
+
isSwitchAppCommand(command) -> executeSwitchAppCommand(command)
|
| 110 |
else -> Log.e("PuppetAS", "Invalid command: $command")
|
| 111 |
}
|
| 112 |
}
|
|
|
|
| 120 |
return command.startsWith("acc:")
|
| 121 |
}
|
| 122 |
|
| 123 |
+
fun isSwitchAppCommand(command: String): Boolean {
|
| 124 |
+
return command.startsWith("switch:")
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
fun executeAccCommand(command: String) {
|
| 129 |
val accCommand = command.removePrefix("acc:")
|
| 130 |
Log.i("PuppetAS", "Executing Acc command: $accCommand")
|
| 131 |
|
|
|
|
| 255 |
startActivity(intent)
|
| 256 |
}
|
| 257 |
|
| 258 |
+
fun executeSwitchAppCommand(command: String) {
|
| 259 |
+
val packageName = command.removePrefix("switch:")
|
| 260 |
+
Log.i("PuppetAS", "Executing Switch app command: $packageName")
|
| 261 |
+
// val intent = packageManager.getLaunchIntentForPackage(packageName)
|
| 262 |
+
val launchIntent = Intent(Intent.ACTION_MAIN)
|
| 263 |
+
launchIntent.addCategory(Intent.CATEGORY_LAUNCHER)
|
| 264 |
+
launchIntent.setPackage(packageName)
|
| 265 |
+
launchIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
| 266 |
+
if (launchIntent != null)
|
| 267 |
+
try {
|
| 268 |
+
startActivity(launchIntent)
|
| 269 |
+
} catch (e: Exception) {
|
| 270 |
+
Log.i("PuppetAS", "Error switching to the package: ${e.message}")
|
| 271 |
+
}
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
|
| 275 |
private var lastOutput: String? = null
|
| 276 |
|
| 277 |
override fun onAccessibilityEvent(event: AccessibilityEvent?) {
|