Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OS Detection] Improve MacOS detection #24708

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quantum/os_detection.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void process_wlength(const uint16_t w_length) {
} else if (setups_data.count == setups_data.cnt_ff) {
// Linux has 3 packets with 0xFF.
guessed = OS_LINUX;
} else if (setups_data.count == 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff == 1 && setups_data.cnt_02 == 2) {
} else if (setups_data.count >= 5 && setups_data.last_wlength == 0xFF && setups_data.cnt_ff >= 1 && setups_data.cnt_02 >= 2) {
Copy link
Member

@zvecr zvecr Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Some collected sequences of wLength can be found in tests.

Any chance we can collect a sample of the "new" macos behaviour and update tests so they pass?

guessed = OS_MACOS;
} else if (setups_data.count == 4 && setups_data.cnt_ff == 0 && setups_data.cnt_02 == 2) {
// iOS and iPadOS don't have the last 0xFF packet.
Expand Down
61 changes: 54 additions & 7 deletions quantum/os_detection/tests/os_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ void assert_reported(os_variant_t os) {
Windows 10: [FF, FF, 4, 24, 4, 24, 4, FF, 24, FF, 4, FF, 24, 4, 24, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A, 20A]
Windows 10 (another host): [FF, FF, 4, 24, 4, 24, 4, 24, 4, 24, 4, 24]
macOS 12.5: [2, 24, 2, 28, FF]
macOS 15.1.x: [ 2, 4E, 2, 1C, 2, 1A, FF, FF]
macOS 15.x (another host): [ 2, 0E, 2, 1E, 2, 42, FF]
macOS 15.x (periodic weirdness): [ 2, 42, 2, 1C, 2, 1A, FF, 2, 42, 2, 1C, 2, 1A, FF ]
iOS/iPadOS 15.6: [2, 24, 2, 28]
Linux (including Android, Raspberry Pi and WebOS TV): [FF, FF, FF]
Linux (another host): [FF, FF, FF, FF, FF, FF]
PS5: [2, 4, 2, 28, 2, 24]
Nintendo Switch: [82, FF, 40, 40, FF, 40, 40, FF, 40, 40, FF, 40, 40, FF, 40, 40]
Quest 2: [FF, FF, FF, FE, FF, FE, FF, FE, FF, FE, FF]
Expand All @@ -79,6 +83,7 @@ Windows 10 (first connect): [12, FF, FF, 4, 10, FF, FF, FF, 4, 10, 20A, 20A, 20A
Windows 10 (subsequent connect): [FF, FF, 4, 10, FF, 4, FF, 10, FF, 20A, 20A, 20A, 20A, 20A, 20A]
Windows 10 (another host): [FF, FF, 4, 10, 4, 10]
macOS: [2, 10, 2, E, FF]
macOS 15.x: [ 2, 64, 2, 28, FF, FF]
iOS/iPadOS: [2, 10, 2, E]
Linux: [FF, FF, FF]
PS5: [2, 4, 2, E, 2, 10]
Expand Down Expand Up @@ -109,18 +114,67 @@ TEST_F(OsDetectionTest, TestLinux) {
assert_not_reported();
}

TEST_F(OsDetectionTest, TestChibiosLinux) {
EXPECT_EQ(check_sequence({0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}), OS_LINUX);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestChibiosMacos) {
EXPECT_EQ(check_sequence({0x2, 0x24, 0x2, 0x28, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestChibiosMacos2) {
EXPECT_EQ(check_sequence({0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestChibiosMacos3) {
EXPECT_EQ(check_sequence({0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF, 0x2, 0x42, 0x2, 0x1C, 0x2, 0x1A, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

// Regression reported in https://github.com/qmk/qmk_firmware/pull/21777#issuecomment-1922815841
TEST_F(OsDetectionTest, TestChibiosMacM1) {
EXPECT_EQ(check_sequence({0x02, 0x32, 0x02, 0x24, 0x101, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestChibiosMacSequoia) {
EXPECT_EQ(check_sequence({0x02, 0x4E, 0x02, 0x1C, 0x02, 0x1A, 0xFF, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestChibiosMacSequoia2) {
EXPECT_EQ(check_sequence({0x02, 0x4E, 0x02, 0x1C, 0x02, 0x1A, 0xFF, 0x02, 0x42, 0x02, 0x1C, 0x02, 0x1A, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestChibiosMacSequoia3) {
EXPECT_EQ(check_sequence({0x02, 0x0E, 0x02, 0x1E, 0x02, 0x42, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestLufaMacos) {
EXPECT_EQ(check_sequence({0x2, 0x10, 0x2, 0xE, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestDetectLufaMacSequoia2) {
EXPECT_EQ(check_sequence({0x02, 0x64, 0x02, 0x28, 0xFF, 0xFF}), OS_MACOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestVusbMacos) {
EXPECT_EQ(check_sequence({0x2, 0xE, 0x2, 0xE, 0xFF}), OS_MACOS);
os_detection_task();
Expand Down Expand Up @@ -235,13 +289,6 @@ TEST_F(OsDetectionTest, TestVusbQuest2) {
assert_not_reported();
}

// Regression reported in https://github.com/qmk/qmk_firmware/pull/21777#issuecomment-1922815841
TEST_F(OsDetectionTest, TestDetectMacM1AsIOS) {
EXPECT_EQ(check_sequence({0x02, 0x32, 0x02, 0x24, 0x101, 0xFF}), OS_IOS);
os_detection_task();
assert_not_reported();
}

TEST_F(OsDetectionTest, TestDoNotReportIfUsbUnstable) {
EXPECT_EQ(check_sequence({0xFF, 0xFF, 0xFF, 0xFE}), OS_LINUX);
os_detection_task();
Expand Down
Loading