mirror of
https://github.com/home-assistant/android
synced 2024-10-04 23:29:31 +00:00
Fix (potential) crashes when deleting a server (#3392)
* Prevent crash when pausing if server is deleted * Handle race when deleting - Handle a race condition where we delete and finish the activity at the same time during which it might not yet have been fully removed - Handle a race condition where a back-up may be restored and a server is deleted on startup, which causes the authentication repository to become unavailable with a minor delay
This commit is contained in:
parent
a74aae6851
commit
231622a0ef
|
@ -27,13 +27,17 @@ abstract class LaunchPresenterBase(
|
|||
.filter { serverManager.authenticationRepository(it.id).getSessionState() == SessionState.ANONYMOUS }
|
||||
.forEach { serverManager.removeServer(it.id) }
|
||||
|
||||
if (
|
||||
serverManager.isRegistered() &&
|
||||
serverManager.authenticationRepository().getSessionState() == SessionState.CONNECTED
|
||||
) {
|
||||
resyncRegistration()
|
||||
view.displayWebview()
|
||||
} else {
|
||||
try {
|
||||
if (
|
||||
serverManager.isRegistered() &&
|
||||
serverManager.authenticationRepository().getSessionState() == SessionState.CONNECTED
|
||||
) {
|
||||
resyncRegistration()
|
||||
view.displayWebview()
|
||||
} else {
|
||||
view.displayOnBoarding(false)
|
||||
}
|
||||
} catch (e: IllegalArgumentException) { // Server was just removed, nothing is added
|
||||
view.displayOnBoarding(false)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,7 +207,11 @@ class SettingsActivity : BaseActivity() {
|
|||
|
||||
fun setAppActive(serverId: Int?, active: Boolean) = runBlocking {
|
||||
serverManager.getServer(serverId ?: ServerManager.SERVER_ID_ACTIVE)?.let {
|
||||
serverManager.integrationRepository(it.id).setAppActive(active)
|
||||
try {
|
||||
serverManager.integrationRepository(it.id).setAppActive(active)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.w(TAG, "Cannot set app active $active for server $serverId")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,10 @@ class ServerSettingsPresenterImpl @Inject constructor(
|
|||
// Remove server anyway, the user wants to delete and we don't need the server for that
|
||||
}
|
||||
serverManager.removeServer(serverId)
|
||||
view.onRemovedServer(success = true, hasAnyRemaining = serverManager.defaultServers.any())
|
||||
view.onRemovedServer(
|
||||
success = true,
|
||||
hasAnyRemaining = serverManager.defaultServers.any { it.id != serverId }
|
||||
)
|
||||
} ?: run {
|
||||
view.onRemovedServer(success = false, hasAnyRemaining = true)
|
||||
}
|
||||
|
@ -178,6 +181,11 @@ class ServerSettingsPresenterImpl @Inject constructor(
|
|||
}
|
||||
|
||||
override fun setAppActive(active: Boolean) = runBlocking {
|
||||
serverManager.integrationRepository(serverId).setAppActive(active)
|
||||
try {
|
||||
serverManager.integrationRepository(serverId).setAppActive(active)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.w(TAG, "Cannot set app active $active for server $serverId")
|
||||
Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,7 +247,12 @@ class WebViewPresenterImpl @Inject constructor(
|
|||
|
||||
override fun setAppActive(active: Boolean) = runBlocking {
|
||||
serverManager.getServer(serverId)?.let {
|
||||
serverManager.integrationRepository(serverId).setAppActive(active)
|
||||
try {
|
||||
serverManager.integrationRepository(serverId).setAppActive(active)
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(TAG, "Cannot set app active $active for server $serverId")
|
||||
Unit
|
||||
}
|
||||
} ?: Unit
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue