Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions project/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ dependencies {
implementation(libs.paho.mqttclient)
implementation(libs.okhttp)

// External USB GNSS (u-blox F9P et al.)
implementation("com.github.mik3y:usb-serial-for-android:3.5.1")

// Utility libraries
implementation(libs.bundles.hilt)
implementation(libs.square.tape2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.owntracks.android.gms.location.GMSLocationProviderClient
import org.owntracks.android.location.ExternalGnssLocationProviderClient
import org.owntracks.android.location.LocationProviderClient
import org.owntracks.android.location.external.ExternalGnssController

@InstallIn(SingletonComponent::class)
@Module
class LocationProviderClientModule {
@Provides
@Singleton
fun getLocationProviderClient(
@ApplicationContext applicationContext: Context
): LocationProviderClient = GMSLocationProviderClient.create(applicationContext)
@ApplicationContext applicationContext: Context,
externalGnssController: ExternalGnssController,
): LocationProviderClient =
ExternalGnssLocationProviderClient(
delegate = GMSLocationProviderClient.create(applicationContext),
controller = externalGnssController,
)
}
10 changes: 10 additions & 0 deletions project/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
android:name="android.hardware.wifi"
android:required="false" />

<uses-feature
android:name="android.hardware.usb.host"
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<!-- To access the network -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down Expand Up @@ -243,6 +247,12 @@
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/usb_device_filter" />
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.owntracks.android.location

import android.location.Location
import android.os.Looper
import androidx.annotation.RequiresPermission
import org.owntracks.android.location.external.ExternalGnssController

/**
* [LocationProviderClient] that wraps an existing provider (AOSP or GMS) and augments it with fixes
* coming from an external USB GNSS receiver managed by [ExternalGnssController].
*
* All location requests are transparently forwarded to the [delegate]; in addition, every
* [LocationCallback] is registered with the controller so it also receives synthetic
* [android.location.Location] objects built from external NMEA fixes.
*/
class ExternalGnssLocationProviderClient(
private val delegate: LocationProviderClient,
private val controller: ExternalGnssController,
) : LocationProviderClient() {

@RequiresPermission(
anyOf =
["android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"])
override fun singleHighAccuracyLocation(clientCallBack: LocationCallback, looper: Looper) {
delegate.singleHighAccuracyLocation(clientCallBack, looper)
}

@RequiresPermission(
anyOf =
["android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"])
override fun actuallyRequestLocationUpdates(
locationRequest: LocationRequest,
clientCallBack: LocationCallback,
looper: Looper
) {
// Forward to the real provider (uses the public entry point because the "actually" method is
// protected on the delegate).
delegate.requestLocationUpdates(locationRequest, clientCallBack, looper)
controller.registerCallback(clientCallBack)
}

override fun removeLocationUpdates(clientCallBack: LocationCallback) {
delegate.removeLocationUpdates(clientCallBack)
controller.unregisterCallback(clientCallBack)
}

override fun flushLocations() {
delegate.flushLocations()
}

override fun getLastLocation(): Location? {
return controller.getLastExternalLocation() ?: delegate.getLastLocation()
}
}
Loading