Correctly rebind backends after upgrade
This commit is contained in:
parent
8c46f2c48a
commit
9c32fc7619
|
@ -40,16 +40,5 @@
|
|||
<action android:name="org.microg.nlp.service.GEOCODE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver android:name=".PackageChangedReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_CHANGED" />
|
||||
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
|
||||
|
||||
<data android:scheme="package" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
package org.microg.nlp.service
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
import android.location.Address
|
||||
import android.os.Bundle
|
||||
|
@ -52,6 +54,19 @@ class GeocodeService : LifecycleService() {
|
|||
}
|
||||
|
||||
class GeocodeServiceImpl(private val context: Context, private val lifecycle: Lifecycle) : IGeocodeService.Stub(), LifecycleOwner {
|
||||
private val packageFilter: IntentFilter = IntentFilter().apply {
|
||||
addAction(Intent.ACTION_PACKAGE_CHANGED)
|
||||
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
||||
addAction(Intent.ACTION_PACKAGE_REPLACED)
|
||||
addAction(Intent.ACTION_PACKAGE_RESTARTED)
|
||||
addDataScheme("package")
|
||||
}
|
||||
private val packageReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d(TAG, "Package updated, binding")
|
||||
fuser.bind()
|
||||
}
|
||||
}
|
||||
private val fuser = GeocodeFuser(context, lifecycle)
|
||||
|
||||
init {
|
||||
|
@ -60,6 +75,7 @@ class GeocodeServiceImpl(private val context: Context, private val lifecycle: Li
|
|||
fuser.reset()
|
||||
fuser.bind()
|
||||
Log.d(TAG, "Finished preparing GeocodeFuser")
|
||||
context.registerReceiver(packageReceiver, packageFilter)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,6 +204,7 @@ class GeocodeServiceImpl(private val context: Context, private val lifecycle: Li
|
|||
}
|
||||
|
||||
fun destroy() {
|
||||
context.unregisterReceiver(packageReceiver)
|
||||
fuser.destroy()
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
package org.microg.nlp.service
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.*
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
import android.location.Location
|
||||
import android.os.Bundle
|
||||
|
@ -104,6 +107,19 @@ class LocationRequestInternal(private var request: LocationRequest, private val
|
|||
}
|
||||
|
||||
class LocationServiceImpl(private val context: Context, private val lifecycle: Lifecycle) : ILocationService.Stub(), LifecycleOwner, LocationReceiver {
|
||||
private val packageFilter: IntentFilter = IntentFilter().apply {
|
||||
addAction(ACTION_PACKAGE_CHANGED)
|
||||
addAction(ACTION_PACKAGE_REMOVED)
|
||||
addAction(ACTION_PACKAGE_REPLACED)
|
||||
addAction(ACTION_PACKAGE_RESTARTED)
|
||||
addDataScheme("package")
|
||||
}
|
||||
private val packageReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d(TAG, "Package updated, binding")
|
||||
fuser.bind()
|
||||
}
|
||||
}
|
||||
private val requests = arrayListOf<LocationRequestInternal>()
|
||||
private val fuser = LocationFuser(context, lifecycle, this)
|
||||
private var lastLocation: Location? = null
|
||||
|
@ -119,6 +135,7 @@ class LocationServiceImpl(private val context: Context, private val lifecycle: L
|
|||
fuser.bind()
|
||||
fuser.update()
|
||||
Log.d(TAG, "Finished preparing LocationFuser")
|
||||
context.registerReceiver(packageReceiver, packageFilter)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,6 +359,7 @@ class LocationServiceImpl(private val context: Context, private val lifecycle: L
|
|||
}
|
||||
|
||||
fun destroy() {
|
||||
context.unregisterReceiver(packageReceiver)
|
||||
fuser.destroy()
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.content.Intent
|
|||
import android.content.Intent.*
|
||||
import android.util.Log
|
||||
|
||||
@Deprecated("Registered in LocationService or GeocodeService")
|
||||
class PackageChangedReceiver : BroadcastReceiver() {
|
||||
|
||||
private fun isProtectedAction(action: String) = when (action) {
|
||||
|
@ -28,6 +29,7 @@ class PackageChangedReceiver : BroadcastReceiver() {
|
|||
if (backend.startsWith("$packageName/")) {
|
||||
Log.d(TAG, "Reloading location service for $packageName")
|
||||
UnifiedLocationServiceEntryPoint.reloadPreferences()
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,8 +117,12 @@ class BackendDetailsFragment : Fragment(R.layout.backend_details), BackendDetail
|
|||
entry.loadIntents(requireActivity() as AppCompatActivity)
|
||||
}
|
||||
if (entry.type == LOCATION && entry.enabled.get()) {
|
||||
if (updateInProgress) return
|
||||
if (updateInProgress) {
|
||||
Log.d(TAG, "Location update still in progress")
|
||||
return
|
||||
}
|
||||
locationClient.connect()
|
||||
Log.d(TAG, "Connected to location client")
|
||||
updateInProgress = true
|
||||
try {
|
||||
val locationTemp = locationClient.getLastLocationForBackend(
|
||||
|
@ -153,6 +157,7 @@ class BackendDetailsFragment : Fragment(R.layout.backend_details), BackendDetail
|
|||
var locationString =
|
||||
"${location.latitude.toStringWithDigits(6)}, ${location.longitude.toStringWithDigits(6)}"
|
||||
|
||||
Log.d(TAG, "Location reported is $locationString, trying to gather address")
|
||||
val address = geocodeClient.requestReverseGeocode(
|
||||
ReverseGeocodeRequest(
|
||||
LatLon(
|
||||
|
|
Loading…
Reference in New Issue