fix heartbeat and simplify type
Browse files
puppet/app/src/main/java/com/ttt246/puppet/PuppetAS.kt
CHANGED
|
@@ -42,27 +42,27 @@ open class PuppetAS : AccessibilityService() {
|
|
| 42 |
Thread {
|
| 43 |
while (true) {
|
| 44 |
val uid = getUUID()
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
} finally {
|
| 51 |
-
logs.clear()
|
| 52 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
}
|
| 54 |
-
Thread.sleep((1000..3000).random().toLong())
|
| 55 |
}
|
| 56 |
}.start()
|
| 57 |
}
|
| 58 |
|
| 59 |
-
private fun heartbeat(
|
| 60 |
val serverUrl = getServerUrl()
|
| 61 |
val url = URL("$serverUrl/send_event")
|
| 62 |
-
|
| 63 |
-
put("uid", uid)
|
| 64 |
-
put("event", logMessage)
|
| 65 |
-
}
|
| 66 |
|
| 67 |
val conn = url.openConnection() as HttpURLConnection
|
| 68 |
conn.requestMethod = "POST"
|
|
@@ -136,8 +136,8 @@ open class PuppetAS : AccessibilityService() {
|
|
| 136 |
}
|
| 137 |
|
| 138 |
accCommand.startsWith("TYPE") -> {
|
| 139 |
-
if (accCommand
|
| 140 |
-
val text = "
|
| 141 |
val arguments = Bundle()
|
| 142 |
arguments.putCharSequence(
|
| 143 |
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text
|
|
@@ -145,10 +145,16 @@ open class PuppetAS : AccessibilityService() {
|
|
| 145 |
getFirstTypeableNode()?.performAction(
|
| 146 |
AccessibilityNodeInfo.ACTION_SET_TEXT, arguments
|
| 147 |
)
|
| 148 |
-
} else {
|
| 149 |
-
val
|
| 150 |
-
val text = accCommand.substringAfter("
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
}
|
| 153 |
}
|
| 154 |
}
|
|
@@ -227,21 +233,10 @@ open class PuppetAS : AccessibilityService() {
|
|
| 227 |
|
| 228 |
private fun clickView(id: String) {
|
| 229 |
val rootNode = rootInActiveWindow ?: return
|
| 230 |
-
val nodes = rootNode.
|
| 231 |
-
nodes.forEach {
|
| 232 |
-
it.performAction(AccessibilityNodeInfo.ACTION_CLICK)
|
| 233 |
-
}
|
| 234 |
-
}
|
| 235 |
|
| 236 |
-
private fun typeInView(id: String, text: String) {
|
| 237 |
-
val rootNode = rootInActiveWindow ?: return
|
| 238 |
-
val nodes = rootNode.findAccessibilityNodeInfosByViewId(id)
|
| 239 |
nodes.forEach {
|
| 240 |
-
|
| 241 |
-
arguments.putCharSequence(
|
| 242 |
-
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text
|
| 243 |
-
)
|
| 244 |
-
it.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, arguments)
|
| 245 |
}
|
| 246 |
}
|
| 247 |
|
|
|
|
| 42 |
Thread {
|
| 43 |
while (true) {
|
| 44 |
val uid = getUUID()
|
| 45 |
+
try {
|
| 46 |
+
val logMessage = logs.joinToString()
|
| 47 |
+
val jsonObject = JSONObject().apply {
|
| 48 |
+
put("uid", uid)
|
| 49 |
+
put("event", logMessage)
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
+
heartbeat(jsonObject)
|
| 52 |
+
} catch (e: Exception) {
|
| 53 |
+
Log.e("PuppetAS", "Error in sending POST request: ${e.message}")
|
| 54 |
+
} finally {
|
| 55 |
+
logs.clear()
|
| 56 |
+
Thread.sleep((1000..3000).random().toLong())
|
| 57 |
}
|
|
|
|
| 58 |
}
|
| 59 |
}.start()
|
| 60 |
}
|
| 61 |
|
| 62 |
+
private fun heartbeat(jsonObject: JSONObject) {
|
| 63 |
val serverUrl = getServerUrl()
|
| 64 |
val url = URL("$serverUrl/send_event")
|
| 65 |
+
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
val conn = url.openConnection() as HttpURLConnection
|
| 68 |
conn.requestMethod = "POST"
|
|
|
|
| 136 |
}
|
| 137 |
|
| 138 |
accCommand.startsWith("TYPE") -> {
|
| 139 |
+
if (accCommand.startsWith("TYPE FIRST ")) {
|
| 140 |
+
val text = accCommand.substringAfter("TYPE FIRST ")
|
| 141 |
val arguments = Bundle()
|
| 142 |
arguments.putCharSequence(
|
| 143 |
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text
|
|
|
|
| 145 |
getFirstTypeableNode()?.performAction(
|
| 146 |
AccessibilityNodeInfo.ACTION_SET_TEXT, arguments
|
| 147 |
)
|
| 148 |
+
} else if (accCommand.startsWith("TYPE HERE")) {
|
| 149 |
+
val focusedNode: AccessibilityNodeInfo? = rootInActiveWindow.findFocus(AccessibilityNodeInfo.FOCUS_INPUT)
|
| 150 |
+
val text = accCommand.substringAfter("TYPE HERE ")
|
| 151 |
+
val arguments = Bundle()
|
| 152 |
+
arguments.putCharSequence(
|
| 153 |
+
AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text
|
| 154 |
+
)
|
| 155 |
+
focusedNode?.performAction(
|
| 156 |
+
AccessibilityNodeInfo.ACTION_SET_TEXT, arguments
|
| 157 |
+
)
|
| 158 |
}
|
| 159 |
}
|
| 160 |
}
|
|
|
|
| 233 |
|
| 234 |
private fun clickView(id: String) {
|
| 235 |
val rootNode = rootInActiveWindow ?: return
|
| 236 |
+
val nodes = rootNode.findAccessibilityNodeInfosByText(id)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
|
|
|
|
|
|
|
|
|
| 238 |
nodes.forEach {
|
| 239 |
+
it.performAction(AccessibilityNodeInfo.ACTION_CLICK)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|