Update: 2026-05-14 20:19:28
This commit is contained in:
@@ -14,7 +14,9 @@ data class RideLogRequest(
|
||||
val timeToPickup: String,
|
||||
val isAccepted: Boolean,
|
||||
val rawText: String,
|
||||
val fingerprint: String
|
||||
val fingerprint: String,
|
||||
val latitude: Double? = null,
|
||||
val longitude: Double? = null
|
||||
)
|
||||
|
||||
data class LocationPoint(
|
||||
|
||||
@@ -11,9 +11,11 @@ class UberParser : NotificationParser {
|
||||
|
||||
var price: Double? = null
|
||||
var minutes: Int? = null
|
||||
var distance: Double? = null
|
||||
|
||||
val priceRegex = """(\d+\.?\d*)\s*(JOD|د\.أ)""".toRegex()
|
||||
val minutesRegex = """(\d+)\s*(min|دقيقة)""".toRegex()
|
||||
val distanceRegex = """(\d+\.?\d*)\s*(km|كم)""".toRegex()
|
||||
|
||||
val fullText = "$title $text"
|
||||
|
||||
@@ -25,12 +27,15 @@ class UberParser : NotificationParser {
|
||||
minutes = it.groupValues[1].toIntOrNull()
|
||||
}
|
||||
|
||||
// We return the request even if price is null, we can filter it later
|
||||
distanceRegex.find(fullText)?.let {
|
||||
distance = it.groupValues[1].toDoubleOrNull()
|
||||
}
|
||||
|
||||
return RideRequest(
|
||||
appPackage = packageName,
|
||||
priceJod = price,
|
||||
minutesAway = minutes,
|
||||
distanceKm = null, // Uber usually gives mins, not always distance
|
||||
distanceKm = distance,
|
||||
title = title,
|
||||
text = text
|
||||
)
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package com.jordanbot.autoride.service
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.gms.location.FusedLocationProviderClient
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.google.android.gms.tasks.Tasks
|
||||
|
||||
import android.app.Notification
|
||||
import android.service.notification.NotificationListenerService
|
||||
import android.service.notification.StatusBarNotification
|
||||
@@ -18,6 +26,13 @@ class RideNotificationListener : NotificationListenerService() {
|
||||
|
||||
private val serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
private val filterEngine = FilterEngine()
|
||||
private lateinit var fusedLocationClient: FusedLocationProviderClient
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
|
||||
}
|
||||
|
||||
private val parsers = listOf(
|
||||
UberParser(),
|
||||
CareemParser(),
|
||||
@@ -35,12 +50,6 @@ class RideNotificationListener : NotificationListenerService() {
|
||||
var packageName = sbn.packageName
|
||||
Log.d("JordanBot", "Received notification from: $packageName")
|
||||
|
||||
// TEMPORARY: Allow Shell notifications for testing
|
||||
if (packageName == "com.android.shell") {
|
||||
Log.d("JordanBot", "Testing mode: Treating Shell notification as Uber")
|
||||
packageName = "com.ubercab.driver"
|
||||
}
|
||||
|
||||
val parser = parsers.find { it.packageName == packageName }
|
||||
if (parser == null) {
|
||||
Log.d("JordanBot", "No parser found for package: $packageName")
|
||||
@@ -76,18 +85,36 @@ class RideNotificationListener : NotificationListenerService() {
|
||||
}
|
||||
|
||||
private fun sendLogToBackend(ride: com.jordanbot.autoride.model.RideRequest, isAccepted: Boolean, rawText: String) {
|
||||
val logRequest = RideLogRequest(
|
||||
platform = ride.appPackage,
|
||||
price = ride.priceJod ?: 0.0,
|
||||
pickupDistance = ride.distanceKm?.toString() ?: "Unknown",
|
||||
dropoffDistance = "Unknown",
|
||||
timeToPickup = ride.minutesAway?.toString() ?: "Unknown",
|
||||
isAccepted = isAccepted,
|
||||
rawText = rawText,
|
||||
fingerprint = DeviceUtils.getDeviceFingerprint(this)
|
||||
)
|
||||
|
||||
serviceScope.launch {
|
||||
var lat: Double? = null
|
||||
var lng: Double? = null
|
||||
|
||||
// Try to get current location
|
||||
if (ContextCompat.checkSelfPermission(this@RideNotificationListener, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||
try {
|
||||
val location = Tasks.await(fusedLocationClient.lastLocation)
|
||||
if (location != null) {
|
||||
lat = location.latitude
|
||||
lng = location.longitude
|
||||
Log.d("JordanBot", "📍 Location attached to ride: $lat, $lng")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("JordanBot", "Failed to get location for ride log", e)
|
||||
}
|
||||
}
|
||||
|
||||
val logRequest = RideLogRequest(
|
||||
platform = ride.appPackage,
|
||||
price = ride.priceJod ?: 0.0,
|
||||
pickupDistance = ride.distanceKm?.toString() ?: "Unknown",
|
||||
dropoffDistance = "Unknown",
|
||||
timeToPickup = ride.minutesAway?.toString() ?: "Unknown",
|
||||
isAccepted = isAccepted,
|
||||
rawText = rawText,
|
||||
fingerprint = DeviceUtils.getDeviceFingerprint(this@RideNotificationListener),
|
||||
latitude = lat,
|
||||
longitude = lng
|
||||
)
|
||||
try {
|
||||
val response = ApiClient.service.logRide(logRequest)
|
||||
if (response.success) {
|
||||
|
||||
Reference in New Issue
Block a user