Fixing missing cleanUp of the LocationSharingAndroidService
This commit is contained in:
parent
2c10d9dcaa
commit
e311d0e469
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.location
|
||||
|
||||
import android.os.Binder
|
||||
|
||||
class LocationSharingAndroidServiceBinder : Binder() {
|
||||
|
||||
private var locationSharingAndroidService: LocationSharingAndroidService? = null
|
||||
|
||||
fun setup(service: LocationSharingAndroidService) {
|
||||
locationSharingAndroidService = service
|
||||
}
|
||||
|
||||
fun cleanUp() {
|
||||
locationSharingAndroidService = null
|
||||
}
|
||||
|
||||
fun getService() = locationSharingAndroidService
|
||||
}
|
|
@ -67,7 +67,7 @@ class LocationSharingServiceConnection @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onServiceConnected(className: ComponentName, binder: IBinder) {
|
||||
locationSharingAndroidService = (binder as LocationSharingAndroidService.LocalBinder).getService().also { service ->
|
||||
locationSharingAndroidService = (binder as LocationSharingAndroidServiceBinder).getService()?.also { service ->
|
||||
service.callback = this
|
||||
getActiveSessionCoroutineScope()?.let { scope ->
|
||||
service.roomIdsOfActiveLives
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package im.vector.app.features.location.live.tracking
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import android.os.Parcelable
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
|
@ -62,7 +61,7 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
|
|||
@Inject lateinit var getLiveLocationShareSummaryUseCase: GetLiveLocationShareSummaryUseCase
|
||||
@Inject lateinit var checkIfEventIsRedactedUseCase: CheckIfEventIsRedactedUseCase
|
||||
|
||||
private val binder = LocalBinder()
|
||||
private var binder: LocationSharingAndroidServiceBinder? = null
|
||||
|
||||
private val liveInfoSet = linkedSetOf<LiveInfo>()
|
||||
var callback: Callback? = null
|
||||
|
@ -76,6 +75,7 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
|
|||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
Timber.i("onCreate")
|
||||
binder = LocationSharingAndroidServiceBinder().also { it.setup(this) }
|
||||
initLocationTracking()
|
||||
}
|
||||
|
||||
|
@ -205,6 +205,8 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
|
|||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
Timber.i("onDestroy")
|
||||
binder?.cleanUp()
|
||||
binder = null
|
||||
jobs.forEach { it.cancel() }
|
||||
jobs.clear()
|
||||
locationTracker.removeCallback(this)
|
||||
|
@ -251,14 +253,10 @@ class LocationSharingAndroidService : VectorAndroidService(), LocationTracker.Ca
|
|||
return liveInfoSet.map { it.roomArgs.roomId }.toSet()
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder {
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return binder
|
||||
}
|
||||
|
||||
inner class LocalBinder : Binder() {
|
||||
fun getService(): LocationSharingAndroidService = this@LocationSharingAndroidService
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
fun onServiceError(error: Throwable)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue