mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-10 16:02:25 +01:00
car apps: say an app won't start when it never answers, instead of showing Starting for ever
Apps on Car App Library 1.9 and later (Yandex Maps and 2GIS among them) don't reply to a host that isn't Google's, so a map app on Home sat on its loading message. After 10 seconds without an answer it now counts as refused, and Home offers another app.
This commit is contained in:
1 parent
8fbd1701b1
commit
405cecf2e9
1 file changed
+18
@@ -226,6 +226,7 @@ class CarAppConnection(private val context: Context) {
|
|||||||
fun disconnect() = disconnect(keepLocation = false)
|
fun disconnect() = disconnect(keepLocation = false)
|
||||||
|
|
||||||
private fun disconnect(keepLocation: Boolean) {
|
private fun disconnect(keepLocation: Boolean) {
|
||||||
|
main.removeCallbacks(handshakeTimeout)
|
||||||
clearToasts()
|
clearToasts()
|
||||||
lent?.let { sendSurfaceDestroyed(it) }
|
lent?.let { sendSurfaceDestroyed(it) }
|
||||||
lent = null
|
lent = null
|
||||||
@@ -257,11 +258,24 @@ class CarAppConnection(private val context: Context) {
|
|||||||
|
|
||||||
// --- handshake ---------------------------------------------------------------------
|
// --- handshake ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An app that won't have Gearslip as its host never answers the first question. Car App
|
||||||
|
* Library 1.9 and later throw inside the app when a host that isn't Google's asks, and since
|
||||||
|
* the call is one-way the error never comes back, so without this the car would show
|
||||||
|
* "Starting..." for ever.
|
||||||
|
*/
|
||||||
|
private val handshakeTimeout = Runnable {
|
||||||
|
if (_status.value.phase == Phase.HANDSHAKE) {
|
||||||
|
fail(Phase.REJECTED, "It didn't answer Gearslip. Apps built for newer versions of Android Auto only run on Google's.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun onBound(service: IBinder) {
|
private fun onBound(service: IBinder) {
|
||||||
val app = ICarApp.Stub.asInterface(service)
|
val app = ICarApp.Stub.asInterface(service)
|
||||||
carApp = app
|
carApp = app
|
||||||
update { it.copy(phase = Phase.HANDSHAKE, detail = "bound, asking for app info") }
|
update { it.copy(phase = Phase.HANDSHAKE, detail = "bound, asking for app info") }
|
||||||
GearslipLog.i("host: bound; requesting app info")
|
GearslipLog.i("host: bound; requesting app info")
|
||||||
|
main.postDelayed(handshakeTimeout, HANDSHAKE_TIMEOUT_MS)
|
||||||
|
|
||||||
call("getAppInfo", onValue = { value ->
|
call("getAppInfo", onValue = { value ->
|
||||||
val info = value as? AppInfo ?: return@call fail(Phase.FAILED, "app info was ${value?.javaClass?.simpleName}")
|
val info = value as? AppInfo ?: return@call fail(Phase.FAILED, "app info was ${value?.javaClass?.simpleName}")
|
||||||
@@ -274,6 +288,7 @@ class CarAppConnection(private val context: Context) {
|
|||||||
* offers cannot be rendered correctly, so it is refused here rather than half-drawn.
|
* offers cannot be rendered correctly, so it is refused here rather than half-drawn.
|
||||||
*/
|
*/
|
||||||
private fun onAppInfo(info: AppInfo) {
|
private fun onAppInfo(info: AppInfo) {
|
||||||
|
main.removeCallbacks(handshakeTimeout)
|
||||||
val negotiated = minOf(HOST_API_LEVEL, info.latestCarAppApiLevel)
|
val negotiated = minOf(HOST_API_LEVEL, info.latestCarAppApiLevel)
|
||||||
GearslipLog.i(
|
GearslipLog.i(
|
||||||
"host: app api ${info.minCarAppApiLevel}..${info.latestCarAppApiLevel} " +
|
"host: app api ${info.minCarAppApiLevel}..${info.latestCarAppApiLevel} " +
|
||||||
@@ -839,6 +854,9 @@ class CarAppConnection(private val context: Context) {
|
|||||||
/** How long a new destination waits for the old route to end; see [navigateTo]. */
|
/** How long a new destination waits for the old route to end; see [navigateTo]. */
|
||||||
const val REROUTE_WAIT_MS = 1_500L
|
const val REROUTE_WAIT_MS = 1_500L
|
||||||
|
|
||||||
|
/** How long an app gets to answer the first question before it counts as refusing. */
|
||||||
|
const val HANDSHAKE_TIMEOUT_MS = 10_000L
|
||||||
|
|
||||||
/** Context.BIND_FOREGROUND_SERVICE; the constant itself is hidden from the SDK. */
|
/** Context.BIND_FOREGROUND_SERVICE; the constant itself is hidden from the SDK. */
|
||||||
const val BIND_FOREGROUND_SERVICE = 0x04000000
|
const val BIND_FOREGROUND_SERVICE = 0x04000000
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user