Fix resource leaks in service startup error cleanup
This commit is contained in:
@@ -162,7 +162,6 @@ class BoxService(private val service: Service, private val platformInterface: Pl
|
|||||||
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
||||||
}
|
}
|
||||||
if (!service.hasPermission(wifiPermission)) {
|
if (!service.hasPermission(wifiPermission)) {
|
||||||
closeService()
|
|
||||||
stopAndAlert(Alert.RequestLocationPermission)
|
stopAndAlert(Alert.RequestLocationPermission)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -243,7 +242,6 @@ class BoxService(private val service: Service, private val platformInterface: Pl
|
|||||||
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
||||||
}
|
}
|
||||||
if (!service.hasPermission(wifiPermission)) {
|
if (!service.hasPermission(wifiPermission)) {
|
||||||
closeService()
|
|
||||||
stopAndAlert(Alert.RequestLocationPermission)
|
stopAndAlert(Alert.RequestLocationPermission)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -311,6 +309,16 @@ class BoxService(private val service: Service, private val platformInterface: Pl
|
|||||||
|
|
||||||
private suspend fun stopAndAlert(type: Alert, message: String? = null) {
|
private suspend fun stopAndAlert(type: Alert, message: String? = null) {
|
||||||
Settings.startedByUser = false
|
Settings.startedByUser = false
|
||||||
|
val pfd = fileDescriptor
|
||||||
|
if (pfd != null) {
|
||||||
|
pfd.close()
|
||||||
|
fileDescriptor = null
|
||||||
|
}
|
||||||
|
DefaultNetworkMonitor.stop()
|
||||||
|
if (::commandServer.isInitialized) {
|
||||||
|
closeService()
|
||||||
|
commandServer.close()
|
||||||
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (receiverRegistered) {
|
if (receiverRegistered) {
|
||||||
service.unregisterReceiver(receiver)
|
service.unregisterReceiver(receiver)
|
||||||
@@ -321,6 +329,7 @@ class BoxService(private val service: Service, private val platformInterface: Pl
|
|||||||
callback.onServiceAlert(type.ordinal, message)
|
callback.onServiceAlert(type.ordinal, message)
|
||||||
}
|
}
|
||||||
status.value = Status.Stopped
|
status.value = Status.Stopped
|
||||||
|
service.stopSelf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.nekohasekai.sfa.compose.screen.profile
|
package io.nekohasekai.sfa.compose.screen.profile
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -10,7 +11,6 @@ import androidx.navigation.NavType
|
|||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import android.net.Uri
|
|
||||||
import androidx.navigation.navArgument
|
import androidx.navigation.navArgument
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
Reference in New Issue
Block a user