Update: 2026-05-16 02:03:46
This commit is contained in:
@@ -17,6 +17,8 @@ import com.jordanbot.autoride.subscription.SubscriptionManager
|
|||||||
class RideAccessibilityService : AccessibilityService() {
|
class RideAccessibilityService : AccessibilityService() {
|
||||||
|
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
private var lastScrapeTime = 0L
|
||||||
|
private val SCRAPE_THROTTLE_MS = 1000L // 1 second throttle
|
||||||
|
|
||||||
override fun onAccessibilityEvent(event: AccessibilityEvent) {
|
override fun onAccessibilityEvent(event: AccessibilityEvent) {
|
||||||
val rootNode = rootInActiveWindow ?: return
|
val rootNode = rootInActiveWindow ?: return
|
||||||
@@ -28,6 +30,13 @@ class RideAccessibilityService : AccessibilityService() {
|
|||||||
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED ||
|
if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED ||
|
||||||
event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
|
event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
|
||||||
|
|
||||||
|
// Throttle scraping to save battery and prevent device heating
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
if (currentTime - lastScrapeTime < SCRAPE_THROTTLE_MS) {
|
||||||
|
return // Ignore this event, it's too soon
|
||||||
|
}
|
||||||
|
lastScrapeTime = currentTime
|
||||||
|
|
||||||
val screenData = scrapeScreen(rootNode, packageName)
|
val screenData = scrapeScreen(rootNode, packageName)
|
||||||
if (screenData != null) {
|
if (screenData != null) {
|
||||||
RideDataMerger.updateFromScreen(screenData)
|
RideDataMerger.updateFromScreen(screenData)
|
||||||
@@ -44,6 +53,31 @@ class RideAccessibilityService : AccessibilityService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun scrapeScreen(root: AccessibilityNodeInfo, pkg: String): RideRequest? {
|
private fun scrapeScreen(root: AccessibilityNodeInfo, pkg: String): RideRequest? {
|
||||||
|
// ULTRA-FAST CHECK 1: Ask Android native layer to find currency symbols
|
||||||
|
val jodNodes = root.findAccessibilityNodeInfosByText("JOD")
|
||||||
|
val dinarArNodes = root.findAccessibilityNodeInfosByText("د.أ")
|
||||||
|
val dinarWordNodes = root.findAccessibilityNodeInfosByText("دينار")
|
||||||
|
|
||||||
|
val hasCurrency = jodNodes.isNotEmpty() || dinarArNodes.isNotEmpty() || dinarWordNodes.isNotEmpty()
|
||||||
|
|
||||||
|
// ULTRA-FAST CHECK 2: Look for Accept buttons
|
||||||
|
val acceptEnNodes = root.findAccessibilityNodeInfosByText("Accept")
|
||||||
|
val acceptArNodes = root.findAccessibilityNodeInfosByText("قبول")
|
||||||
|
val confirmNodes = root.findAccessibilityNodeInfosByText("Confirm")
|
||||||
|
val confirmArNodes = root.findAccessibilityNodeInfosByText("تأكيد")
|
||||||
|
val tapToAcceptNodes = root.findAccessibilityNodeInfosByText("Tap to accept")
|
||||||
|
|
||||||
|
val hasAcceptButton = acceptEnNodes.isNotEmpty() || acceptArNodes.isNotEmpty() ||
|
||||||
|
confirmNodes.isNotEmpty() || confirmArNodes.isNotEmpty() ||
|
||||||
|
tapToAcceptNodes.isNotEmpty()
|
||||||
|
|
||||||
|
// If it doesn't have BOTH a price indicator AND an accept button, it's not a ride request!
|
||||||
|
if (!hasCurrency || !hasAcceptButton) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// We only reach here if BOTH currency and an accept button are detected.
|
||||||
|
// Now it's safe to collect text to extract the exact price.
|
||||||
val allText = mutableListOf<String>()
|
val allText = mutableListOf<String>()
|
||||||
collectAllText(root, allText)
|
collectAllText(root, allText)
|
||||||
val combinedText = allText.joinToString(" ")
|
val combinedText = allText.joinToString(" ")
|
||||||
|
|||||||
Reference in New Issue
Block a user