@@ -33,7 +33,6 @@ import androidx.compose.material.icons.rounded.Close
3333import androidx.compose.material.icons.rounded.Notifications
3434import androidx.compose.material.icons.rounded.Numbers
3535import androidx.compose.material.icons.rounded.RestartAlt
36- import androidx.compose.material.icons.rounded.Tune
3736import androidx.compose.material.icons.rounded.Usb
3837import androidx.compose.material.icons.rounded.WarningAmber
3938import androidx.compose.material3.BottomAppBar
@@ -78,9 +77,7 @@ import io.github.sds100.keymapper.common.utils.State
7877@Composable
7978fun ExpertModeScreen (modifier : Modifier = Modifier , viewModel : ExpertModeViewModel ) {
8079 val expertModeWarningState by viewModel.warningState.collectAsStateWithLifecycle()
81- val expertModeSetupState by viewModel.setupState.collectAsStateWithLifecycle()
82- val autoStartBootChecked by viewModel.autoStartBootChecked.collectAsStateWithLifecycle()
83- val autoStartBootEnabled by viewModel.autoStartBootEnabled.collectAsStateWithLifecycle()
80+ val expertModeState by viewModel.state.collectAsStateWithLifecycle()
8481
8582 ExpertModeScreen (
8683 modifier = modifier,
@@ -90,7 +87,7 @@ fun ExpertModeScreen(modifier: Modifier = Modifier, viewModel: ExpertModeViewMod
9087 ) {
9188 Content (
9289 warningState = expertModeWarningState,
93- setupState = expertModeSetupState ,
90+ setupState = expertModeState ,
9491 showInfoCard = viewModel.showInfoCard,
9592 onInfoCardDismiss = { viewModel.hideInfoCard() },
9693 onWarningButtonClick = viewModel::onWarningButtonClick,
@@ -99,9 +96,8 @@ fun ExpertModeScreen(modifier: Modifier = Modifier, viewModel: ExpertModeViewMod
9996 onRootButtonClick = viewModel::onRootButtonClick,
10097 onSetupWithKeyMapperClick = viewModel::onSetupWithKeyMapperClick,
10198 onRequestNotificationPermissionClick = viewModel::onRequestNotificationPermissionClick,
102- autoStartAtBoot = autoStartBootChecked,
10399 onAutoStartAtBootToggled = { viewModel.onAutoStartBootToggled() },
104- autoStartAtBootEnabled = autoStartBootEnabled ,
100+ onLaunchDeveloperOptionsClick = viewModel::onLaunchDeveloperOptionsClick ,
105101 )
106102 }
107103}
@@ -181,9 +177,8 @@ private fun Content(
181177 onRootButtonClick : () -> Unit = {},
182178 onSetupWithKeyMapperClick : () -> Unit = {},
183179 onRequestNotificationPermissionClick : () -> Unit = {},
184- autoStartAtBoot : Boolean ,
185- onAutoStartAtBootToggled : (Boolean ) -> Unit = {},
186- autoStartAtBootEnabled : Boolean ,
180+ onAutoStartAtBootToggled : () -> Unit = {},
181+ onLaunchDeveloperOptionsClick : () -> Unit = {},
187182) {
188183 Column (modifier = modifier.verticalScroll(rememberScrollState())) {
189184 AnimatedVisibility (
@@ -230,9 +225,8 @@ private fun Content(
230225 onRootButtonClick = onRootButtonClick,
231226 onSetupWithKeyMapperClick = onSetupWithKeyMapperClick,
232227 onRequestNotificationPermissionClick = onRequestNotificationPermissionClick,
233- autoStartAtBoot = autoStartAtBoot,
234228 onAutoStartAtBootToggled = onAutoStartAtBootToggled,
235- autoStartAtBootEnabled = autoStartAtBootEnabled ,
229+ onLaunchDeveloperOptionsClick = onLaunchDeveloperOptionsClick ,
236230 )
237231 }
238232 }
@@ -255,9 +249,8 @@ private fun LoadedContent(
255249 onStopServiceClick : () -> Unit ,
256250 onSetupWithKeyMapperClick : () -> Unit ,
257251 onRequestNotificationPermissionClick : () -> Unit = {},
258- autoStartAtBoot : Boolean ,
259- onAutoStartAtBootToggled : (Boolean ) -> Unit = {},
260- autoStartAtBootEnabled : Boolean ,
252+ onAutoStartAtBootToggled : () -> Unit = {},
253+ onLaunchDeveloperOptionsClick : () -> Unit = {},
261254) {
262255 Column (modifier) {
263256 OptionsHeaderRow (
@@ -306,6 +299,15 @@ private fun LoadedContent(
306299
307300 when (state) {
308301 is ExpertModeState .Started -> {
302+ ExpertModeStartedCard (
303+ modifier = Modifier
304+ .fillMaxWidth()
305+ .padding(horizontal = 8 .dp),
306+ onStopClick = onStopServiceClick,
307+ )
308+
309+ Spacer (modifier = Modifier .height(8 .dp))
310+
309311 if (! state.isDefaultUsbModeCompatible) {
310312 IncompatibleUsbModeCard (
311313 modifier = Modifier
@@ -316,11 +318,33 @@ private fun LoadedContent(
316318 Spacer (Modifier .height(8 .dp))
317319 }
318320
319- ExpertModeStartedCard (
320- modifier = Modifier
321- .fillMaxWidth()
322- .padding(horizontal = 8 .dp),
323- onStopClick = onStopServiceClick,
321+ // Only show auto-start options and warnings when Expert Mode is started
322+ // Show USB debugging security settings warning if disabled
323+ if (state.isAdbInputSecurityEnabled == false ) {
324+ UsbDebuggingSecuritySettingsCard (
325+ modifier = Modifier
326+ .fillMaxWidth()
327+ .padding(horizontal = 8 .dp),
328+ onLaunchDeveloperOptionsClick = onLaunchDeveloperOptionsClick,
329+ )
330+
331+ Spacer (modifier = Modifier .height(8 .dp))
332+ }
333+
334+ SwitchPreferenceCompose (
335+ modifier = Modifier .padding(horizontal = 8 .dp),
336+ title = stringResource(R .string.title_pref_expert_mode_auto_start),
337+ text = if (state.autoStartBootEnabled) {
338+ stringResource(R .string.summary_pref_expert_mode_auto_start)
339+ } else {
340+ stringResource(
341+ R .string.summary_pref_expert_mode_auto_start_disabled,
342+ )
343+ },
344+ icon = Icons .Rounded .RestartAlt ,
345+ isChecked = state.autoStartBootChecked,
346+ onCheckedChange = { onAutoStartAtBootToggled() },
347+ isEnabled = state.autoStartBootEnabled,
324348 )
325349 }
326350
@@ -425,41 +449,14 @@ private fun LoadedContent(
425449 buttonText = setupKeyMapperText,
426450 onButtonClick = onSetupWithKeyMapperClick,
427451 enabled =
428- Build .VERSION .SDK_INT >= Build .VERSION_CODES .R &&
429- state.isNotificationPermissionGranted,
452+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .R &&
453+ state.isNotificationPermissionGranted,
430454 isLoading = state.isStarting,
431455 )
456+
457+ Spacer (modifier = Modifier .height(8 .dp))
432458 }
433459 }
434-
435- // Options section
436- Spacer (modifier = Modifier .height(16 .dp))
437-
438- OptionsHeaderRow (
439- modifier = Modifier .padding(horizontal = 16 .dp),
440- icon = Icons .Rounded .Tune ,
441- text = stringResource(R .string.expert_mode_options_title),
442- )
443-
444- Spacer (modifier = Modifier .height(8 .dp))
445-
446- SwitchPreferenceCompose (
447- modifier = Modifier .padding(horizontal = 8 .dp),
448- title = stringResource(R .string.title_pref_expert_mode_auto_start),
449- text = if (autoStartAtBootEnabled) {
450- stringResource(R .string.summary_pref_expert_mode_auto_start)
451- } else {
452- stringResource(
453- R .string.summary_pref_expert_mode_auto_start_disabled,
454- )
455- },
456- icon = Icons .Rounded .RestartAlt ,
457- isChecked = autoStartAtBoot,
458- onCheckedChange = onAutoStartAtBootToggled,
459- isEnabled = autoStartAtBootEnabled,
460- )
461-
462- Spacer (modifier = Modifier .height(8 .dp))
463460 }
464461}
465462
@@ -501,6 +498,39 @@ private fun IncompatibleUsbModeCard(modifier: Modifier = Modifier) {
501498 )
502499}
503500
501+ @Composable
502+ private fun UsbDebuggingSecuritySettingsCard (
503+ modifier : Modifier = Modifier ,
504+ onLaunchDeveloperOptionsClick : () -> Unit = {},
505+ ) {
506+ SetupCard (
507+ modifier = modifier,
508+ color = MaterialTheme .colorScheme.errorContainer,
509+ icon = {
510+ Icon (
511+ imageVector = Icons .Rounded .WarningAmber ,
512+ contentDescription = null ,
513+ tint = MaterialTheme .colorScheme.onErrorContainer,
514+ )
515+ },
516+ title = stringResource(
517+ R .string.expert_mode_usb_debugging_security_settings_title,
518+ ),
519+ content = {
520+ Text (
521+ text = stringResource(
522+ R .string.expert_mode_usb_debugging_security_settings_description,
523+ ),
524+ style = MaterialTheme .typography.bodyMedium,
525+ )
526+ },
527+ buttonText = stringResource(
528+ R .string.expert_mode_usb_debugging_security_settings_button,
529+ ),
530+ onButtonClick = onLaunchDeveloperOptionsClick,
531+ )
532+ }
533+
504534@Composable
505535private fun WarningCard (
506536 modifier : Modifier = Modifier ,
@@ -761,9 +791,8 @@ private fun Preview() {
761791 ),
762792 showInfoCard = true ,
763793 onInfoCardDismiss = {},
764- autoStartAtBoot = false ,
765794 onAutoStartAtBootToggled = {},
766- autoStartAtBootEnabled = true ,
795+ onLaunchDeveloperOptionsClick = {} ,
767796 )
768797 }
769798 }
@@ -776,12 +805,18 @@ private fun PreviewDark() {
776805 ExpertModeScreen {
777806 Content (
778807 warningState = ExpertModeWarningState .Understood ,
779- setupState = State .Data (ExpertModeState .Started (isDefaultUsbModeCompatible = true )),
808+ setupState = State .Data (
809+ ExpertModeState .Started (
810+ isDefaultUsbModeCompatible = true ,
811+ autoStartBootChecked = true ,
812+ autoStartBootEnabled = true ,
813+ isAdbInputSecurityEnabled = null ,
814+ ),
815+ ),
780816 showInfoCard = false ,
781817 onInfoCardDismiss = {},
782- autoStartAtBoot = true ,
783818 onAutoStartAtBootToggled = {},
784- autoStartAtBootEnabled = true ,
819+ onLaunchDeveloperOptionsClick = {} ,
785820 )
786821 }
787822 }
@@ -799,9 +834,8 @@ private fun PreviewCountingDown() {
799834 setupState = State .Loading ,
800835 showInfoCard = true ,
801836 onInfoCardDismiss = {},
802- autoStartAtBoot = false ,
803837 onAutoStartAtBootToggled = {},
804- autoStartAtBootEnabled = true ,
838+ onLaunchDeveloperOptionsClick = {} ,
805839 )
806840 }
807841 }
@@ -815,13 +849,17 @@ private fun PreviewStarted() {
815849 Content (
816850 warningState = ExpertModeWarningState .Understood ,
817851 setupState = State .Data (
818- ExpertModeState .Started (isDefaultUsbModeCompatible = false ),
852+ ExpertModeState .Started (
853+ isDefaultUsbModeCompatible = false ,
854+ autoStartBootChecked = false ,
855+ autoStartBootEnabled = true ,
856+ isAdbInputSecurityEnabled = null ,
857+ ),
819858 ),
820859 showInfoCard = false ,
821860 onInfoCardDismiss = {},
822- autoStartAtBoot = false ,
823861 onAutoStartAtBootToggled = {},
824- autoStartAtBootEnabled = true ,
862+ onLaunchDeveloperOptionsClick = {} ,
825863 )
826864 }
827865 }
@@ -844,9 +882,32 @@ private fun PreviewNotificationPermissionNotGranted() {
844882 ),
845883 showInfoCard = false ,
846884 onInfoCardDismiss = {},
847- autoStartAtBoot = false ,
848885 onAutoStartAtBootToggled = {},
849- autoStartAtBootEnabled = true ,
886+ onLaunchDeveloperOptionsClick = {},
887+ )
888+ }
889+ }
890+ }
891+
892+ @Preview
893+ @Composable
894+ private fun PreviewUsbDebuggingSecuritySettingsCard () {
895+ KeyMapperTheme {
896+ ExpertModeScreen {
897+ Content (
898+ warningState = ExpertModeWarningState .Understood ,
899+ setupState = State .Data (
900+ ExpertModeState .Started (
901+ isDefaultUsbModeCompatible = true ,
902+ autoStartBootChecked = false ,
903+ autoStartBootEnabled = true ,
904+ isAdbInputSecurityEnabled = false ,
905+ ),
906+ ),
907+ showInfoCard = false ,
908+ onInfoCardDismiss = {},
909+ onAutoStartAtBootToggled = {},
910+ onLaunchDeveloperOptionsClick = {},
850911 )
851912 }
852913 }
0 commit comments