@@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.emptyFlow
1515import kotlinx.coroutines.flow.filter
1616import kotlinx.coroutines.flow.flatMapLatest
1717import kotlinx.coroutines.flow.update
18+ import kotlinx.coroutines.flow.updateAndGet
1819import kotlin.time.Duration
1920
2021private const val TAG = " RECORDER_SERVICE_BINDER"
@@ -45,14 +46,14 @@ internal class RecorderServiceBinderImpl(private val context: Context) : Recorde
4546 override fun onServiceConnected (name : ComponentName ? , service : IBinder ? ) {
4647 val binder = (service as ? VoiceRecorderService .LocalBinder )
4748 _service = binder?.getService()
48- _isBounded .update { true }
49- Log .d(TAG , " SERVICE CONNECTED" )
49+ val isBounded = _isBounded .updateAndGet { true }
50+ Log .d(TAG , " SERVICE CONNECTED :BOUNDED : $isBounded " )
5051 }
5152
5253 override fun onServiceDisconnected (name : ComponentName ? ) {
53- _isBounded .update { false }
54+ val bounded = _isBounded .updateAndGet { false }
5455 _service = null
55- Log .d(TAG , " SERVICE DISCONNECTED" )
56+ Log .d(TAG , " SERVICE DISCONNECTED :BOUNDED: $bounded " )
5657 }
5758 }
5859
@@ -70,14 +71,15 @@ internal class RecorderServiceBinderImpl(private val context: Context) : Recorde
7071 override fun unBindService () {
7172 try {
7273 context.unbindService(serviceConnection)
73- Log .d(TAG , " SERVICE UN-BIND" )
74+ val isBounded = _isBounded .updateAndGet { false }
75+ Log .d(TAG , " SERVICE UN-BIND BOUNDED:$isBounded " )
7476 } catch (e: Exception ) {
7577 e.printStackTrace()
7678 }
7779 }
7880
7981 override fun cleanUp () {
80- Log .d(TAG ," SERVICE BINDER CLEANUP" )
82+ Log .d(TAG , " SERVICE BINDER CLEANUP" )
8183 _service = null
8284 _isBounded .update { false }
8385 }
0 commit comments