Modern Apps git

← Modern-Apps.git

maauto: wire pairing route into nav + USB entry

Commit
857d9496d68325e30c3c76fc5f086ca6d341a62b
Author
vayun-mathur <[email protected]>
When
2026-09-12 21:20 UTC (2 months ago)
Parents
620e447

Diff

auto/src/main/java/com/vayunmathur/auto/MainActivity.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/MainActivity.kt b/auto/src/main/java/com/vayunmathur/auto/MainActivity.ktindex feb60b19ef..7bd0fcfbbb 100644--- a/auto/src/main/java/com/vayunmathur/auto/MainActivity.kt+++ b/auto/src/main/java/com/vayunmathur/auto/MainActivity.kt@@ -1,27 +1,46 @@ package com.vayunmathur.auto +import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels+import com.vayunmathur.auto.network.UsbConnector import com.vayunmathur.auto.platform.AutoViewModel+import com.vayunmathur.auto.platform.MaosRoleStatus+import com.vayunmathur.auto.platform.PairingViewModel+import com.vayunmathur.auto.platform.TransportState import com.vayunmathur.auto.service.ProjectionService import com.vayunmathur.library.ui.DynamicTheme  class MainActivity : ComponentActivity() {     private val viewModel: AutoViewModel by viewModels()+    private val pairingViewModel: PairingViewModel by viewModels()      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         // Start listening as soon as the app is opened. A head unit can attach at any time         // and the service is what holds the socket.         ProjectionService.start(this)+        // The role read is platform state, not session state: seed it at launch so the+        // pairing screen renders the MAOS capabilities without waiting for a session.+        // BootReceiver re-seeds it after reboot.+        TransportState.publishRole(MaosRoleStatus.isProjectionRoleHeld(this))+        // A plug-in launches the app through the accessory filter; the USB bring-up+        // starts from that same intent.+        intent?.let { UsbConnector.onAccessoryIntent(this, it) }         enableEdgeToEdge()         setContent {             DynamicTheme {-                Navigation(viewModel)+                Navigation(viewModel, pairingViewModel)             }         }     }++    override fun onNewIntent(intent: Intent) {+        super.onNewIntent(intent)+        // Single-top relaunch on plug-in while already open: same USB entry point.+        UsbConnector.onAccessoryIntent(this, intent)+    } }
auto/src/main/java/com/vayunmathur/auto/Navigation.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/Navigation.kt b/auto/src/main/java/com/vayunmathur/auto/Navigation.ktindex ed862ab043..2836b3542e 100644--- a/auto/src/main/java/com/vayunmathur/auto/Navigation.kt+++ b/auto/src/main/java/com/vayunmathur/auto/Navigation.kt@@ -2,16 +2,21 @@ package com.vayunmathur.auto  import androidx.compose.runtime.Composable import com.vayunmathur.auto.platform.AutoViewModel+import com.vayunmathur.auto.platform.PairingViewModel import com.vayunmathur.auto.ui.AutoScreen+import com.vayunmathur.auto.ui.PairingScreen import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.rememberNavBackStack  @Composable-fun Navigation(viewModel: AutoViewModel) {+fun Navigation(viewModel: AutoViewModel, pairingViewModel: PairingViewModel) {     val backStack = rememberNavBackStack<Route>(Route.Home)     MainNavigation(backStack) {         entry<Route.Home> {-            AutoScreen(viewModel = viewModel)+            AutoScreen(viewModel = viewModel, onPairing = { backStack.add(Route.Pairing) })+        }+        entry<Route.Pairing> {+            PairingScreen(viewModel = pairingViewModel, onNavigateBack = { backStack.pop() })         }     } }
auto/src/main/java/com/vayunmathur/auto/Route.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/Route.kt b/auto/src/main/java/com/vayunmathur/auto/Route.ktindex b445e8cc34..c6fe372e4b 100644--- a/auto/src/main/java/com/vayunmathur/auto/Route.kt+++ b/auto/src/main/java/com/vayunmathur/auto/Route.kt@@ -4,12 +4,16 @@ import com.vayunmathur.library.util.NavKey import kotlinx.serialization.Serializable  /**- * Auto has one phone-side screen. The interesting interface lives on the car's display, not- * here; this is only somewhere to see whether a car is attached.+ * Auto has two phone-side screens. The interesting interface lives on the car's display, not+ * here; these are only somewhere to see whether a car is attached and how it is attached.  */ @Serializable sealed interface Route : NavKey {     /** Connection state and how to attach a car. */     @Serializable     data object Home : Route++    /** USB + wireless bring-up, the winning transport, and the MAOS role. */+    @Serializable+    data object Pairing : Route }