From c868b04a1c88edd866fcd16e3fd1be46b7554efc Mon Sep 17 00:00:00 2001 From: CinderSocket Date: Wed, 17 Jun 2026 15:43:00 -0700 Subject: [PATCH] Reset HF type prompt state on cancel --- lib/host_tests/test_runtime_policy.c | 39 ++++++++++++++++++++++++++++ runtime_policy.c | 14 ++++++++++ runtime_policy.h | 6 +++++ scenes/seader_scene_read_card_type.c | 1 + 4 files changed, 60 insertions(+) diff --git a/lib/host_tests/test_runtime_policy.c b/lib/host_tests/test_runtime_policy.c index d0016ac..6bb0654 100644 --- a/lib/host_tests/test_runtime_policy.c +++ b/lib/host_tests/test_runtime_policy.c @@ -2,6 +2,7 @@ #include "munit.h" #include "runtime_policy.h" +#include "seader_hf_read_plan.h" static MunitResult test_reset_cached_sam_metadata_clears_all_fields( const MunitParameter params[], @@ -237,6 +238,43 @@ static MunitResult test_reset_hf_mode_clears_selection_and_detected_types( return MUNIT_OK; } +static MunitResult test_cancel_hf_type_prompt_resets_future_read_to_full_polling( + const MunitParameter params[], + void* fixture) { + (void)params; + (void)fixture; + + bool hf_mode_active = true; + SeaderCredentialType selected_read_type = SeaderCredentialTypePicopass; + SeaderCredentialType detected_types[3] = { + SeaderCredentialType14A, + SeaderCredentialTypePicopass, + SeaderCredentialTypeNone, + }; + size_t detected_type_count = 2U; + + seader_runtime_cancel_hf_type_prompt( + &hf_mode_active, + &selected_read_type, + detected_types, + 3U, + &detected_type_count); + + munit_assert_false(hf_mode_active); + munit_assert_int(selected_read_type, ==, SeaderCredentialTypeNone); + munit_assert_size(detected_type_count, ==, 0U); + for(size_t i = 0; i < 3U; i++) { + munit_assert_int(detected_types[i], ==, SeaderCredentialTypeNone); + } + + const SeaderHfReadPlan next_plan = + seader_hf_read_plan_build(selected_read_type, detected_types, detected_type_count); + munit_assert_int(next_plan.decision, ==, SeaderHfReadDecisionContinuePolling); + munit_assert_int(next_plan.type_to_read, ==, SeaderCredentialTypeNone); + munit_assert_size(next_plan.detected_type_count, ==, 0U); + return MUNIT_OK; +} + static MunitTest test_runtime_policy_cases[] = { {(char*)"/reset-sam-metadata", test_reset_cached_sam_metadata_clears_all_fields, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, {(char*)"/begin-uhf-probe", test_begin_uhf_probe_sets_runtime_and_initializes_probe, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, @@ -248,6 +286,7 @@ static MunitTest test_runtime_policy_cases[] = { {(char*)"/begin-board-auto-recover", test_begin_board_auto_recover_sets_pending_and_target, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, {(char*)"/begin-board-auto-recover-invalid", test_begin_board_auto_recover_rejects_invalid_or_duplicate_state, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, {(char*)"/reset-hf-mode", test_reset_hf_mode_clears_selection_and_detected_types, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, + {(char*)"/cancel-hf-type-prompt", test_cancel_hf_type_prompt_resets_future_read_to_full_polling, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}, {NULL, NULL, NULL, NULL, 0, NULL}, }; diff --git a/runtime_policy.c b/runtime_policy.c index 920eef9..296a769 100644 --- a/runtime_policy.c +++ b/runtime_policy.c @@ -162,3 +162,17 @@ void seader_runtime_reset_hf_mode( *hf_mode_active = false; } } + +void seader_runtime_cancel_hf_type_prompt( + bool* hf_mode_active, + SeaderCredentialType* selected_read_type, + SeaderCredentialType detected_types[], + size_t detected_capacity, + size_t* detected_type_count) { + seader_runtime_reset_hf_mode( + hf_mode_active, + selected_read_type, + detected_types, + detected_capacity, + detected_type_count); +} diff --git a/runtime_policy.h b/runtime_policy.h index d175912..b531acb 100644 --- a/runtime_policy.h +++ b/runtime_policy.h @@ -50,3 +50,9 @@ void seader_runtime_reset_hf_mode( SeaderCredentialType detected_types[], size_t detected_capacity, size_t* detected_type_count); +void seader_runtime_cancel_hf_type_prompt( + bool* hf_mode_active, + SeaderCredentialType* selected_read_type, + SeaderCredentialType detected_types[], + size_t detected_capacity, + size_t* detected_type_count); diff --git a/scenes/seader_scene_read_card_type.c b/scenes/seader_scene_read_card_type.c index b514f5c..5a9fa74 100644 --- a/scenes/seader_scene_read_card_type.c +++ b/scenes/seader_scene_read_card_type.c @@ -55,6 +55,7 @@ bool seader_scene_read_card_type_on_event(void* context, SceneManagerEvent event consumed = true; } } else if(event.type == SceneManagerEventTypeBack) { + seader_hf_mode_deactivate(seader); consumed = seader_hf_request_teardown(seader, SeaderHfTeardownActionSamPresent); }