Ensure onLost is called
This commit is contained in:
@@ -23,17 +23,16 @@ abstract class FallbackUpstreamMonitor private constructor() : UpstreamMonitor()
|
|||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
if (key == KEY) synchronized(this) {
|
if (key == KEY) synchronized(this) {
|
||||||
val old = monitor
|
val old = monitor
|
||||||
val (active, callbacks) = synchronized(old) {
|
val callbacks = synchronized(old) {
|
||||||
val active = old.currentIface != null
|
|
||||||
val callbacks = old.callbacks.toList()
|
val callbacks = old.callbacks.toList()
|
||||||
old.callbacks.clear()
|
old.callbacks.clear()
|
||||||
old.destroyLocked()
|
old.destroyLocked()
|
||||||
Pair(active, callbacks)
|
callbacks
|
||||||
}
|
}
|
||||||
val new = generateMonitor()
|
val new = generateMonitor()
|
||||||
monitor = new
|
monitor = new
|
||||||
for (callback in callbacks) {
|
for (callback in callbacks) {
|
||||||
if (active) callback.onLost()
|
callback.onLost()
|
||||||
new.registerCallback(callback)
|
new.registerCallback(callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user