react-native-audio-browser 0.2.0-next.27 → 0.2.0-next.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,18 +19,22 @@ internal class ServiceBinding(private val context: Context) {
|
|
|
19
19
|
var isBound: Boolean = false
|
|
20
20
|
private set
|
|
21
21
|
|
|
22
|
+
@Volatile private var bindSucceeded: Boolean = false
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
|
-
* Binds if not already bound, and returns whether
|
|
24
|
-
*
|
|
25
|
+
* Binds if not already bound, and returns whether the service will connect: what
|
|
26
|
+
* [Context.bindService] returned for the binding held. A second call while bound is a no-op that
|
|
27
|
+
* returns the same answer: Android would otherwise count the extra bind and expect a matching
|
|
25
28
|
* unbind.
|
|
26
29
|
*/
|
|
27
30
|
fun bind(intent: Intent, connection: ServiceConnection): Boolean {
|
|
28
|
-
if (isBound) return
|
|
31
|
+
if (isBound) return bindSucceeded
|
|
29
32
|
// Marked bound whatever the result: Android registers the connection before it asks the
|
|
30
33
|
// ActivityManager, so a false return still leaves one to release — "regardless of the return
|
|
31
34
|
// value, you should later call unbindService()".
|
|
32
35
|
isBound = true
|
|
33
|
-
|
|
36
|
+
bindSucceeded = context.bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
|
37
|
+
return bindSucceeded
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
/**
|
|
@@ -74,6 +74,19 @@ class ServiceBindingTest {
|
|
|
74
74
|
assertEquals(1, shadowOf(app).unboundServiceConnections.size)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* setupPlayer binds after the auto-bind at construction already has. If that first bind failed,
|
|
79
|
+
* the service never connects, so setup must hear false and reject rather than wait for it.
|
|
80
|
+
*/
|
|
81
|
+
@Test
|
|
82
|
+
fun bindingAgainAfterAFailedBindReportsTheFailure() {
|
|
83
|
+
val binding = ServiceBinding(app)
|
|
84
|
+
shadowOf(app).declareActionUnbindable("unbindable")
|
|
85
|
+
|
|
86
|
+
assertFalse(binding.bind(Intent("unbindable"), connection))
|
|
87
|
+
assertFalse(binding.bind(Intent("unbindable"), connection))
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
@Test
|
|
78
91
|
fun unbindIsIdempotent() {
|
|
79
92
|
val binding = ServiceBinding(app)
|