@mentra/bluetooth-sdk 3.2.1 → 3.3.0-beta.1001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +99 -6
  2. package/android/build.gradle +15 -0
  3. package/android/lc3Lib/build.gradle +6 -1
  4. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalytics.kt +63 -14
  5. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTracker.kt +55 -1
  6. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +1 -1
  7. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkInstallId.kt +23 -0
  8. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +6 -2
  9. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheck.kt +184 -0
  10. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTracker.kt +388 -0
  11. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +9 -1
  12. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -1
  13. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  14. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +231 -36
  15. package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +24 -0
  16. package/android/src/main/java/com/mentra/bluetoothsdk/NetworkDiagnostics.kt +25 -0
  17. package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
  18. package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +3 -0
  19. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +4 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscovery.kt +70 -0
  21. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizer.kt +11 -32
  22. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/LatinTextSanitizer.kt +39 -0
  23. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +160 -20
  24. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodec.kt +3 -1
  25. package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTrackerTest.kt +58 -3
  26. package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheckTest.kt +124 -0
  27. package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTrackerTest.kt +263 -0
  28. package/android/src/test/java/com/mentra/bluetoothsdk/NetworkDiagnosticsTest.kt +55 -0
  29. package/android/src/test/java/com/mentra/bluetoothsdk/ScanCompletionTest.kt +5 -1
  30. package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
  31. package/android/src/test/java/com/mentra/bluetoothsdk/debug/BleTraceLoggerTest.kt +69 -0
  32. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscoveryTest.kt +124 -0
  33. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +29 -4
  34. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveClassicDisconnectTest.kt +133 -0
  35. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +137 -0
  36. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +126 -0
  37. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveWifiCredentialLogTest.kt +55 -0
  38. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodecTest.kt +20 -7
  39. package/build/BluetoothSdk.types.d.ts +9 -1
  40. package/build/BluetoothSdk.types.d.ts.map +1 -1
  41. package/build/BluetoothSdk.types.js.map +1 -1
  42. package/build/_private/BluetoothSdkModule.d.ts +2 -1
  43. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  44. package/build/_private/BluetoothSdkModule.js +2 -1
  45. package/build/_private/BluetoothSdkModule.js.map +1 -1
  46. package/build/_private/MentraLocalNetworkModule.d.ts +23 -0
  47. package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
  48. package/build/_private/MentraLocalNetworkModule.js.map +1 -1
  49. package/build/_private/nativeLogConsole.d.ts +19 -0
  50. package/build/_private/nativeLogConsole.d.ts.map +1 -1
  51. package/build/_private/nativeLogConsole.js +12 -0
  52. package/build/_private/nativeLogConsole.js.map +1 -1
  53. package/build/generated/changelogCatalog.d.ts +4 -1
  54. package/build/generated/changelogCatalog.d.ts.map +1 -1
  55. package/build/generated/changelogCatalog.js +5 -1
  56. package/build/generated/changelogCatalog.js.map +1 -1
  57. package/build/generated/releaseMetadata.js +6 -6
  58. package/build/generated/releaseMetadata.js.map +1 -1
  59. package/build/index.d.ts +1 -1
  60. package/build/index.d.ts.map +1 -1
  61. package/build/index.js +1 -0
  62. package/build/index.js.map +1 -1
  63. package/build/ota-transport/index.d.ts +4 -0
  64. package/build/ota-transport/index.d.ts.map +1 -1
  65. package/build/ota-transport/index.js +2 -0
  66. package/build/ota-transport/index.js.map +1 -1
  67. package/ios/BluetoothSdkModule.swift +16 -4
  68. package/ios/Source/BluetoothSdkDefaults.swift +2 -2
  69. package/ios/Source/DeviceManager.swift +10 -3
  70. package/ios/Source/GeneratedChangelogCatalog.swift +2 -1
  71. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  72. package/ios/Source/MentraBluetoothSDK.swift +306 -54
  73. package/ios/Source/TouchGesture.swift +13 -0
  74. package/ios/Source/events/BluetoothEvents.swift +4 -0
  75. package/ios/Source/internal/BluetoothAvailability.swift +6 -0
  76. package/ios/Source/internal/BluetoothSdkAnalytics.swift +87 -13
  77. package/ios/Source/internal/BluetoothSdkAnalyticsTracker.swift +54 -1
  78. package/ios/Source/internal/BluetoothSdkInstallId.swift +21 -0
  79. package/ios/Source/internal/BluetoothSdkUpdateCheck.swift +223 -0
  80. package/ios/Source/internal/BluetoothSdkUsageTracker.swift +428 -0
  81. package/ios/Source/sgcs/MentraLive.swift +167 -64
  82. package/ios/Source/sgcs/NimoCanvasCodec.swift +4 -1
  83. package/ios/Source/sgcs/SGCManager.swift +1 -1
  84. package/ios/Source/utils/AudioSessionMonitor.swift +44 -8
  85. package/ios/Source/utils/G1Text.swift +2 -24
  86. package/ios/Source/utils/G1TextSanitizer.swift +27 -0
  87. package/ios/Source/utils/LatinTextSanitizer.swift +48 -0
  88. package/ios/Tests/BluetoothAudioRouteTests.swift +26 -0
  89. package/ios/Tests/BluetoothSdkAnalyticsTrackerTests.swift +54 -3
  90. package/ios/Tests/BluetoothSdkUpdateCheckTests.swift +153 -0
  91. package/ios/Tests/BluetoothSdkUsageTrackerTests.swift +296 -0
  92. package/ios/Tests/G1TextSanitizerTests.swift +32 -0
  93. package/ios/Tests/IncidentLogDispatchTests.swift +111 -0
  94. package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
  95. package/ios/Tests/MentraLiveSessionReadinessTests.swift +292 -0
  96. package/ios/Tests/NimoCanvasCodecTests.swift +17 -4
  97. package/ios/Tests/TouchGestureCommandTests.swift +87 -0
  98. package/ios/Tests/VersionInfoCommandTests.swift +142 -1
  99. package/ios/Tests/WifiCredentialLoggingTests.swift +42 -0
  100. package/package.json +2 -2
  101. package/src/BluetoothSdk.types.ts +16 -0
  102. package/src/_private/BluetoothSdkModule.ts +4 -1
  103. package/src/_private/MentraLocalNetworkModule.ts +28 -0
  104. package/src/_private/nativeLogConsole.ts +19 -0
  105. package/src/generated/changelogCatalog.ts +5 -1
  106. package/src/generated/releaseMetadata.ts +6 -6
  107. package/src/index.ts +2 -0
  108. package/src/ota-transport/index.ts +10 -1
@@ -0,0 +1,48 @@
1
+ import Foundation
2
+
3
+ /// Converts accented and extended Latin letters to base glyphs at the device boundary.
4
+ enum LatinTextSanitizer {
5
+ private static let latinLettersWithMarks = try! NSRegularExpression(pattern: #"\p{Latin}\p{M}*"#)
6
+
7
+ static func sanitizeForDisplay(_ text: String, preserveOtherScripts: Bool = false) -> String {
8
+ if preserveOtherScripts {
9
+ let output = NSMutableString(string: text)
10
+ let range = NSRange(text.startIndex ..< text.endIndex, in: text)
11
+ for match in latinLettersWithMarks.matches(in: text, range: range).reversed() {
12
+ let cluster = output.substring(with: match.range)
13
+ let expanded = cluster.unicodeScalars.map { expandLatinLetter(Character($0)) }.joined()
14
+ output.replaceCharacters(in: match.range, with: stripDiacritics(expanded))
15
+ }
16
+ return output as String
17
+ }
18
+ // Preserve the established G1 folding behavior.
19
+ let expanded = text.reduce(into: "") { result, character in
20
+ result.append(expandLatinLetter(character))
21
+ }
22
+ return stripDiacritics(expanded)
23
+ }
24
+
25
+ private static func stripDiacritics(_ text: String) -> String {
26
+ text.folding(options: .diacriticInsensitive, locale: Locale(identifier: "en_US_POSIX"))
27
+ }
28
+
29
+ private static func expandLatinLetter(_ character: Character) -> String {
30
+ switch character {
31
+ case "Đ", "Ð": return "D"
32
+ case "đ", "ð": return "d"
33
+ case "Ł": return "L"
34
+ case "ł": return "l"
35
+ case "Ø": return "O"
36
+ case "ø": return "o"
37
+ case "Æ": return "AE"
38
+ case "æ": return "ae"
39
+ case "Œ": return "OE"
40
+ case "œ": return "oe"
41
+ case "ẞ": return "SS"
42
+ case "ß": return "ss"
43
+ case "Þ": return "TH"
44
+ case "þ": return "th"
45
+ default: return String(character)
46
+ }
47
+ }
48
+ }
@@ -2,6 +2,32 @@
2
2
  import XCTest
3
3
 
4
4
  final class BluetoothAudioRouteTests: XCTestCase {
5
+ func testObservationSeparatesAbsentBluetoothFromWrongTarget() {
6
+ let builtIn = BluetoothAudioRoute.observe(
7
+ outputs: [(name: "MacBook Speakers", portType: "Speaker")], target: "03BE", isIOSAppOnMac: true
8
+ )
9
+ let wrongTarget = BluetoothAudioRoute.observe(
10
+ outputs: [(name: "Mentra_Live_023B", portType: "Bluetooth")], target: "03BE", isIOSAppOnMac: true
11
+ )
12
+ XCTAssertEqual(builtIn, .init(bluetoothOutputCount: 0, targetNameOutputCount: 0, matchingOutputCount: 0))
13
+ XCTAssertEqual(wrongTarget, .init(bluetoothOutputCount: 1, targetNameOutputCount: 0, matchingOutputCount: 0))
14
+ }
15
+
16
+ func testObservationKeepsIdentityAndTransportSeparate() {
17
+ let matching = BluetoothAudioRoute.observe(
18
+ outputs: [(name: "Mentra_Live_03BE", portType: "Bluetooth")], target: "03BE", isIOSAppOnMac: true
19
+ )
20
+ let usb = BluetoothAudioRoute.observe(
21
+ outputs: [(name: "Mentra_Live_03BE", portType: "USBAudio")], target: "03BE", isIOSAppOnMac: true
22
+ )
23
+ let missingTarget = BluetoothAudioRoute.observe(
24
+ outputs: [(name: "Mentra_Live_03BE", portType: "Bluetooth")], target: "", isIOSAppOnMac: true
25
+ )
26
+ XCTAssertEqual(matching, .init(bluetoothOutputCount: 1, targetNameOutputCount: 1, matchingOutputCount: 1))
27
+ XCTAssertEqual(usb, .init(bluetoothOutputCount: 0, targetNameOutputCount: 1, matchingOutputCount: 0))
28
+ XCTAssertEqual(missingTarget, .init(bluetoothOutputCount: 1, targetNameOutputCount: 0, matchingOutputCount: 0))
29
+ }
30
+
5
31
  func testRecognizesIPhoneProfiles() {
6
32
  for port in ["BluetoothHFP", "BluetoothA2DPOutput"] {
7
33
  XCTAssertTrue(BluetoothAudioRoute.matches(
@@ -4,8 +4,59 @@ import XCTest
4
4
  final class BluetoothSdkAnalyticsTrackerTests: XCTestCase {
5
5
  private var tracker = BluetoothSdkAnalyticsTracker(simulatedModel: "Simulated Glasses")
6
6
 
7
- private func snapshot(connected: Bool, model: String = "Mentra Live", serial: String = "") -> AnalyticsGlassesSnapshot {
8
- AnalyticsGlassesSnapshot(connected: connected, fullyBooted: connected, model: model, serialNumber: serial)
7
+ private func snapshot(
8
+ connected: Bool,
9
+ model: String = "Mentra Live",
10
+ serial: String = "",
11
+ battery: Int = -1,
12
+ charging: Bool = false
13
+ ) -> AnalyticsGlassesSnapshot {
14
+ var snapshot = AnalyticsGlassesSnapshot(connected: connected, fullyBooted: connected, model: model, serialNumber: serial)
15
+ snapshot.batteryLevel = battery
16
+ snapshot.charging = charging
17
+ return snapshot
18
+ }
19
+
20
+ func testCountedConnectionReportsItsLengthReasonAndBatteryWhenItEnds() throws {
21
+ tracker.initialize(snapshot(connected: false), reportingDay: 100)
22
+ _ = tracker.observe(snapshot(connected: true), reportingDay: 100, nowMs: 1000)
23
+ _ = tracker.observe(snapshot(connected: true, battery: 80), reportingDay: 100, nowMs: 2000)
24
+ _ = tracker.observe(snapshot(connected: true, battery: 71, charging: true), reportingDay: 100, nowMs: 3000)
25
+
26
+ let ended = tracker.observe(snapshot(connected: false), reportingDay: 100, nowMs: 61000) {
27
+ BluetoothSdkAnalyticsTracker.disconnectUser
28
+ }
29
+ XCTAssertEqual(ended.count, 1)
30
+ let disconnected = try XCTUnwrap(ended.first)
31
+ XCTAssertEqual(disconnected.name, "bluetooth_sdk_glasses_disconnected")
32
+ XCTAssertEqual(disconnected.properties["session_duration_ms"] as? Int64, 60000)
33
+ XCTAssertEqual(disconnected.properties["disconnect_reason"] as? String, "user_disconnect")
34
+ XCTAssertEqual(disconnected.properties["battery_level_at_connect"] as? Int, 80)
35
+ XCTAssertEqual(disconnected.properties["battery_level_at_disconnect"] as? Int, 71)
36
+ XCTAssertEqual(disconnected.properties["charging"] as? Bool, true)
37
+ XCTAssertEqual(disconnected.properties["glasses_model"] as? String, "Mentra Live")
38
+
39
+ // Further disconnected updates do not report the connection again.
40
+ XCTAssertTrue(tracker.observe(snapshot(connected: false), reportingDay: 100, nowMs: 62000).isEmpty)
41
+ }
42
+
43
+ func testConnectionAlreadyUpWhenTheSdkStartedIsNotReportedAsEnding() {
44
+ tracker.initialize(snapshot(connected: true, serial: "MLAB0001"), reportingDay: 100)
45
+ XCTAssertTrue(tracker.observe(snapshot(connected: false), reportingDay: 100, nowMs: 5000).isEmpty)
46
+ }
47
+
48
+ func testBatteryFromAPreviousConnectionDoesNotLeakIntoTheNextOne() throws {
49
+ tracker.initialize(snapshot(connected: false), reportingDay: 100)
50
+ _ = tracker.observe(snapshot(connected: true, battery: 90), reportingDay: 100, nowMs: 0)
51
+ _ = tracker.observe(snapshot(connected: false), reportingDay: 100, nowMs: 1000)
52
+ _ = tracker.observe(snapshot(connected: true), reportingDay: 100, nowMs: 2000)
53
+ let ended = tracker.observe(snapshot(connected: false), reportingDay: 100, nowMs: 3000)
54
+ XCTAssertEqual(ended.count, 1)
55
+ let second = try XCTUnwrap(ended.first)
56
+ XCTAssertNil(second.properties["battery_level_at_connect"])
57
+ XCTAssertNil(second.properties["battery_level_at_disconnect"])
58
+ XCTAssertNil(second.properties["charging"])
59
+ XCTAssertEqual(second.properties["disconnect_reason"] as? String, "unknown")
9
60
  }
10
61
 
11
62
  func testConnectThenSerialEmitsEachOncePerConnection() {
@@ -40,7 +91,7 @@ final class BluetoothSdkAnalyticsTrackerTests: XCTestCase {
40
91
  tracker.initialize(snapshot(connected: false), reportingDay: 100)
41
92
  _ = tracker.observe(snapshot(connected: true, model: ""), reportingDay: 100)
42
93
  let ended = tracker.observe(snapshot(connected: false, model: ""), reportingDay: 100)
43
- XCTAssertEqual(ended.map(\.name), ["bluetooth_sdk_glasses_connected"])
94
+ XCTAssertEqual(ended.map(\.name), ["bluetooth_sdk_glasses_connected", "bluetooth_sdk_glasses_disconnected"])
44
95
  XCTAssertEqual(ended[0].properties["glasses_model_unresolved"] as? Bool, true)
45
96
  XCTAssertNil(ended[0].properties["glasses_model"])
46
97
  }
@@ -0,0 +1,153 @@
1
+ @testable import MentraBluetoothSDK
2
+ import XCTest
3
+
4
+ final class BluetoothSdkUpdateCheckTests: XCTestCase {
5
+ /// Collects values handed to `@Sendable` callbacks from the check's queue.
6
+ private final class Recorder<Value>: @unchecked Sendable {
7
+ private let lock = NSLock()
8
+ private var stored: [Value] = []
9
+
10
+ var values: [Value] {
11
+ lock.lock()
12
+ defer { lock.unlock() }
13
+ return stored
14
+ }
15
+
16
+ func append(_ value: Value) {
17
+ lock.lock()
18
+ stored.append(value)
19
+ lock.unlock()
20
+ }
21
+ }
22
+
23
+ private final class CheckBox: @unchecked Sendable {
24
+ var check: BluetoothSdkUpdateCheck?
25
+ }
26
+
27
+ private func result(
28
+ _ status: String,
29
+ latest: String? = "3.2.1",
30
+ minimum: String? = nil
31
+ ) -> BluetoothSdkUpdateCheckResult {
32
+ BluetoothSdkUpdateCheckResult(status: status, channel: "latest", latestVersion: latest, minimumSupportedVersion: minimum)
33
+ }
34
+
35
+ func testParsesTheCoreResponseTreatingNullAndBlankVersionsAsUnknown() {
36
+ let parsed = BluetoothSdkUpdateCheckResult.parse(
37
+ #"{"status":"update_available","channel":"dev","latestVersion":"3.3.0-dev.821","minimumSupportedVersion":null}"#
38
+ )
39
+ XCTAssertEqual(
40
+ parsed,
41
+ BluetoothSdkUpdateCheckResult(status: "update_available", channel: "dev", latestVersion: "3.3.0-dev.821", minimumSupportedVersion: nil)
42
+ )
43
+ XCTAssertNil(BluetoothSdkUpdateCheckResult.parse(#"{"status":"current","latestVersion":""}"#)?.latestVersion)
44
+ XCTAssertNotNil(BluetoothSdkUpdateCheckResult.parse(#"{"status":"current","latestVersion":""}"#))
45
+ XCTAssertNil(BluetoothSdkUpdateCheckResult.parse("<html>502</html>"))
46
+ }
47
+
48
+ func testBannerNamesInstalledAndLatestVersionsAndTheSurfaceUpdateCommand() throws {
49
+ let reactNative = try XCTUnwrap(BluetoothSdkUpdateNotice.banner(installedVersion: "3.1.0", result: result("update_available"), surface: "react_native"))
50
+ XCTAssertTrue(reactNative.contains("MENTRA BLUETOOTH SDK UPDATE AVAILABLE"))
51
+ XCTAssertTrue(reactNative.contains("Installed: 3.1.0"))
52
+ XCTAssertTrue(reactNative.contains("Latest: 3.2.1"))
53
+ XCTAssertTrue(reactNative.contains("bun add @mentra/bluetooth-sdk@3.2.1"))
54
+ XCTAssertFalse(reactNative.contains("NO LONGER SUPPORTED"))
55
+ XCTAssertTrue(reactNative.hasPrefix("=================================================================="))
56
+ XCTAssertTrue(reactNative.hasSuffix("=================================================================="))
57
+
58
+ let ios = try XCTUnwrap(BluetoothSdkUpdateNotice.banner(installedVersion: "3.1.0", result: result("update_available"), surface: "ios"))
59
+ XCTAssertTrue(ios.contains("MentraBluetoothSDK Swift package at 3.2.1"))
60
+ let android = try XCTUnwrap(BluetoothSdkUpdateNotice.banner(installedVersion: "3.1.0", result: result("update_available"), surface: "android"))
61
+ XCTAssertTrue(android.contains("com.mentraglass:bluetooth-sdk:3.2.1"))
62
+ }
63
+
64
+ func testUnsupportedVersionGetsTheStrongerBanner() throws {
65
+ let banner = try XCTUnwrap(BluetoothSdkUpdateNotice.banner(
66
+ installedVersion: "3.0.5",
67
+ result: result("unsupported", minimum: "3.1.0"),
68
+ surface: "ios"
69
+ ))
70
+ XCTAssertTrue(banner.contains("MENTRA BLUETOOTH SDK 3.0.5 IS NO LONGER SUPPORTED"))
71
+ XCTAssertTrue(banner.contains("known issues"))
72
+ }
73
+
74
+ func testNoBannerWhenCurrentUnknownOrNoLatestVersionToPointAt() {
75
+ XCTAssertNil(BluetoothSdkUpdateNotice.banner(installedVersion: "3.2.1", result: result("current"), surface: "ios"))
76
+ XCTAssertNil(BluetoothSdkUpdateNotice.banner(installedVersion: "3.2.1", result: result("unknown", latest: nil), surface: "ios"))
77
+ XCTAssertNil(BluetoothSdkUpdateNotice.banner(installedVersion: "3.2.1", result: result("update_available", latest: nil), surface: "ios"))
78
+ }
79
+
80
+ func testSurfaceFollowsTheIntegration() {
81
+ XCTAssertEqual(BluetoothSdkUpdateCheck.surface(forAnalyticsSurface: "react_native"), "react_native")
82
+ XCTAssertEqual(BluetoothSdkUpdateCheck.surface(forAnalyticsSurface: "ios"), "ios")
83
+ XCTAssertEqual(BluetoothSdkUpdateCheck.surface(forAnalyticsSurface: "macos"), "ios")
84
+ }
85
+
86
+ func testRequestIdentifiesTheInstallAppAndSdk() throws {
87
+ let check = BluetoothSdkUpdateCheck(surface: "react_native", sdkVersion: "3.1.0", transport: { _, completion in completion(nil) }) { _, _ in }
88
+ let body = check.requestBody()
89
+ let installId = try XCTUnwrap(body["install_id"] as? String)
90
+ XCTAssertEqual(installId, BluetoothSdkInstallId.get())
91
+ XCTAssertTrue(installId.hasPrefix("mentra-bt-sdk-"))
92
+ XCTAssertEqual(body["app_identifier"] as? String, Bundle.main.bundleIdentifier ?? "")
93
+ XCTAssertEqual(body["sdk_version"] as? String, "3.1.0")
94
+ XCTAssertEqual(body["sdk_platform"] as? String, "ios")
95
+ XCTAssertEqual(body["sdk_surface"] as? String, "react_native")
96
+ XCTAssertNotNil(body["app_build_type"])
97
+ XCTAssertNotNil(body["app_install_source"])
98
+ XCTAssertTrue(JSONSerialization.isValidJSONObject(body))
99
+ }
100
+
101
+ func testOutOfDateSdkPrintsTheBannerOnceAtStartAndStopsOnClose() throws {
102
+ let notices = Recorder<String>()
103
+ let sentBodies = Recorder<Data>()
104
+ let check = BluetoothSdkUpdateCheck(
105
+ surface: "ios",
106
+ sdkVersion: "3.1.0",
107
+ transport: { body, completion in
108
+ sentBodies.append(body)
109
+ completion(Data(#"{"status":"update_available","channel":"latest","latestVersion":"3.2.1","minimumSupportedVersion":null}"#.utf8))
110
+ }
111
+ ) { banner, _ in notices.append(banner) }
112
+ check.start()
113
+ BluetoothSdkUpdateCheck.awaitIdle()
114
+ XCTAssertEqual(notices.values.count, 1)
115
+ XCTAssertTrue(notices.values.first?.contains("Latest: 3.2.1") == true)
116
+ let sentBody = try XCTUnwrap(sentBodies.values.first)
117
+ let sent = try XCTUnwrap(JSONSerialization.jsonObject(with: sentBody) as? [String: Any])
118
+ XCTAssertEqual(sent["sdk_version"] as? String, "3.1.0")
119
+ check.stop()
120
+ }
121
+
122
+ func testFailuresAndUnknownVersionsAreSilent() {
123
+ let notices = Recorder<String>()
124
+ let calls = Recorder<Bool>()
125
+ let checks = [
126
+ BluetoothSdkUpdateCheck(surface: "ios", sdkVersion: "3.1.0", transport: { _, completion in completion(nil) }) { banner, _ in notices.append(banner) },
127
+ BluetoothSdkUpdateCheck(surface: "ios", sdkVersion: "3.1.0", transport: { _, completion in completion(Data("<html>502</html>".utf8)) }) { banner, _ in notices.append(banner) },
128
+ BluetoothSdkUpdateCheck(surface: "ios", sdkVersion: "unknown", transport: { _, completion in calls.append(true); completion(nil) }) { banner, _ in notices.append(banner) },
129
+ BluetoothSdkUpdateCheck(surface: "ios", sdkVersion: nil, transport: { _, completion in calls.append(true); completion(nil) }) { banner, _ in notices.append(banner) },
130
+ ]
131
+ checks.forEach { $0.start() }
132
+ BluetoothSdkUpdateCheck.awaitIdle()
133
+ XCTAssertTrue(notices.values.isEmpty)
134
+ XCTAssertTrue(calls.values.isEmpty)
135
+ }
136
+
137
+ func testCheckStoppedBeforeTheResponseArrivesPrintsNothing() {
138
+ let notices = Recorder<String>()
139
+ let box = CheckBox()
140
+ let check = BluetoothSdkUpdateCheck(
141
+ surface: "ios",
142
+ sdkVersion: "3.1.0",
143
+ transport: { _, completion in
144
+ box.check?.stop()
145
+ completion(Data(#"{"status":"update_available","latestVersion":"3.2.1"}"#.utf8))
146
+ }
147
+ ) { banner, _ in notices.append(banner) }
148
+ box.check = check
149
+ check.start()
150
+ BluetoothSdkUpdateCheck.awaitIdle()
151
+ XCTAssertTrue(notices.values.isEmpty)
152
+ }
153
+ }
@@ -0,0 +1,296 @@
1
+ @testable import MentraBluetoothSDK
2
+ import XCTest
3
+
4
+ final class BluetoothSdkUsageTrackerTests: XCTestCase {
5
+ private var tracker = BluetoothSdkUsageTracker()
6
+
7
+ func testApiPhotoReportsItsRequestShapeLatencyAndOutcome() {
8
+ let ok = tracker.photoSettled(
9
+ size: "medium", mode: "photo", compress: "none", save: true, transferMethod: "auto",
10
+ latencyMs: 812, fileSizeBytes: 204_800, errorCode: nil
11
+ )
12
+ XCTAssertEqual(ok.name, "bluetooth_sdk_photo_taken")
13
+ XCTAssertEqual(ok.properties["trigger"] as? String, "api")
14
+ XCTAssertEqual(ok.properties["success"] as? Bool, true)
15
+ XCTAssertEqual(ok.properties["latency_ms"] as? Int64, 812)
16
+ XCTAssertEqual(ok.properties["photo_size"] as? String, "medium")
17
+ XCTAssertEqual(ok.properties["save_to_gallery"] as? Bool, true)
18
+ XCTAssertEqual(ok.properties["transfer_method"] as? String, "auto")
19
+ XCTAssertEqual(ok.properties["file_size_bytes"] as? Int64, 204_800)
20
+ XCTAssertNil(ok.properties["error_code"])
21
+
22
+ let failed = tracker.photoSettled(
23
+ size: "max", mode: "photo", compress: "none", save: false, transferMethod: "ble",
24
+ latencyMs: 30000, fileSizeBytes: nil, errorCode: "request_timeout"
25
+ )
26
+ XCTAssertEqual(failed.properties["success"] as? Bool, false)
27
+ XCTAssertEqual(failed.properties["error_code"] as? String, "request_timeout")
28
+ XCTAssertNil(failed.properties["file_size_bytes"])
29
+ }
30
+
31
+ func testFailedButtonPhotoIsReportedAsButtonTrigger() {
32
+ let event = tracker.buttonPhotoFailed(errorCode: "CAMERA_BUSY")
33
+ XCTAssertEqual(event.properties["trigger"] as? String, "button")
34
+ XCTAssertEqual(event.properties["success"] as? Bool, false)
35
+ XCTAssertEqual(event.properties["error_code"] as? String, "CAMERA_BUSY")
36
+ XCTAssertEqual(tracker.buttonPhotoFailed(errorCode: nil).properties["error_code"] as? String, "photo_request_failed")
37
+ }
38
+
39
+ func testApiRecordingReportsLengthParametersAndAppStopOnce() throws {
40
+ tracker.videoRequested(requestId: "rec-1", width: 1920, height: 1080, fps: 30, save: true, maxDurationMinutes: 0)
41
+ XCTAssertNil(tracker.videoStatus(requestId: "rec-1", status: "recording_started", success: true, nowMs: 1000))
42
+ // A duplicate start does not move the start time.
43
+ XCTAssertNil(tracker.videoStatus(requestId: "rec-1", status: "recording_started", success: true, nowMs: 2000))
44
+ tracker.videoStopRequested(requestId: "rec-1")
45
+
46
+ let stopped = try XCTUnwrap(tracker.videoStatus(requestId: "rec-1", status: "recording_stopped", success: true, nowMs: 61000))
47
+ XCTAssertEqual(stopped.name, "bluetooth_sdk_video_recorded")
48
+ XCTAssertEqual(stopped.properties["trigger"] as? String, "api")
49
+ XCTAssertEqual(stopped.properties["success"] as? Bool, true)
50
+ XCTAssertEqual(stopped.properties["duration_ms"] as? Int64, 60000)
51
+ XCTAssertEqual(stopped.properties["width"] as? Int, 1920)
52
+ XCTAssertEqual(stopped.properties["fps"] as? Int, 30)
53
+ XCTAssertEqual(stopped.properties["save_to_gallery"] as? Bool, true)
54
+ XCTAssertEqual(stopped.properties["stopped_by_app"] as? Bool, true)
55
+ XCTAssertNil(stopped.properties["max_duration_minutes"])
56
+
57
+ XCTAssertNil(tracker.videoStatus(requestId: "rec-1", status: "recording_stopped", success: true, nowMs: 62000))
58
+ }
59
+
60
+ func testButtonRecordingIsReportedWithButtonTriggerAndNoAppStop() throws {
61
+ let id = "local_video_1728000000_ab12"
62
+ _ = tracker.videoStatus(requestId: id, status: "recording_started", success: true, nowMs: 0)
63
+ let stopped = try XCTUnwrap(tracker.videoStatus(requestId: id, status: "recording_stopped", success: true, nowMs: 5000))
64
+ XCTAssertEqual(stopped.properties["trigger"] as? String, "button")
65
+ XCTAssertEqual(stopped.properties["duration_ms"] as? Int64, 5000)
66
+ XCTAssertEqual(stopped.properties["stopped_by_app"] as? Bool, false)
67
+ }
68
+
69
+ func testRecordingFailureIsReportedButNotRecordingIsNotARecording() throws {
70
+ tracker.videoRequested(requestId: "rec-2", width: 0, height: 0, fps: 0, save: false, maxDurationMinutes: 5)
71
+ let failed = try XCTUnwrap(tracker.videoStatus(requestId: "rec-2", status: "battery_low", success: false, nowMs: 0))
72
+ XCTAssertEqual(failed.properties["success"] as? Bool, false)
73
+ XCTAssertEqual(failed.properties["error_code"] as? String, "battery_low")
74
+ XCTAssertEqual(failed.properties["max_duration_minutes"] as? Int, 5)
75
+ XCTAssertNil(failed.properties["duration_ms"])
76
+ XCTAssertNil(failed.properties["width"])
77
+
78
+ XCTAssertNil(tracker.videoStatus(requestId: "rec-3", status: "not_recording", success: false, nowMs: 0))
79
+ XCTAssertNil(tracker.videoStatus(requestId: "", status: "recording_stopped", success: true, nowMs: 0))
80
+ }
81
+
82
+ func testStreamIsReportedAtStartAndOnceAtItsTerminalStatus() throws {
83
+ XCTAssertNil(tracker.streamRequested(streamId: "s1", streamUrl: "rtmps://live.example.com/app/secret-key", nowMs: 6600))
84
+ // The first live status can arrive before startStream returns.
85
+ XCTAssertNil(stream("streaming", nowMs: 10000))
86
+ let started = tracker.streamStartSettled(
87
+ streamUrl: "rtmps://live.example.com/app/secret-key",
88
+ width: 1280,
89
+ height: 720,
90
+ fps: 30,
91
+ bitrate: 2_000_000,
92
+ captureAudio: true,
93
+ glassesNetwork: "wifi",
94
+ latencyMs: 3400,
95
+ errorCode: nil
96
+ )
97
+ XCTAssertEqual(started.name, "bluetooth_sdk_stream_started")
98
+ XCTAssertEqual(started.properties["success"] as? Bool, true)
99
+ XCTAssertEqual(started.properties["protocol"] as? String, "rtmp")
100
+ XCTAssertEqual(started.properties["glasses_network"] as? String, "wifi")
101
+ XCTAssertFalse(started.properties.values.contains { "\($0)".contains("secret-key") })
102
+
103
+ XCTAssertNil(stream("reconnecting", reconnectAttempt: 1, nowMs: 20000))
104
+ XCTAssertNil(stream("reconnected", reconnectAttempt: 2, nowMs: 21000))
105
+ XCTAssertNil(stream("streaming", bitrate: 1_800_000, droppedFrames: 12, nowMs: 30000))
106
+ // Statuses for another stream id do not touch this one.
107
+ XCTAssertNil(tracker.streamStatus(
108
+ streamId: "other", state: "stopped", terminal: true, reconnectAttempt: nil, bitrate: nil, fps: nil,
109
+ droppedFrames: nil, temperatureC: nil, errorDetails: nil, nowMs: 31000
110
+ ))
111
+ tracker.streamStopRequested()
112
+
113
+ let ended = try XCTUnwrap(stream("stopped", terminal: true, nowMs: 70000))
114
+ XCTAssertEqual(ended.name, "bluetooth_sdk_stream_ended")
115
+ XCTAssertEqual(ended.properties["protocol"] as? String, "rtmp")
116
+ XCTAssertEqual(ended.properties["duration_ms"] as? Int64, 60000)
117
+ XCTAssertEqual(ended.properties["end_state"] as? String, "stopped")
118
+ XCTAssertEqual(ended.properties["stopped_by_app"] as? Bool, true)
119
+ XCTAssertEqual(ended.properties["reconnect_attempts"] as? Int, 2)
120
+ XCTAssertEqual(ended.properties["bitrate"] as? Int64, 1_800_000)
121
+ XCTAssertEqual(ended.properties["dropped_frames"] as? Int64, 12)
122
+
123
+ XCTAssertNil(stream("stopped", terminal: true, nowMs: 71000))
124
+ }
125
+
126
+ func testStreamThatEndsRightAfterGoingLiveIsStillReported() throws {
127
+ _ = tracker.streamRequested(streamId: "s1", streamUrl: "rtmp://host/app", nowMs: 0)
128
+ XCTAssertNil(stream("streaming", nowMs: 1000))
129
+ let ended = try XCTUnwrap(stream("error", terminal: true, nowMs: 1500))
130
+ XCTAssertEqual(ended.properties["duration_ms"] as? Int64, 500)
131
+ XCTAssertEqual(ended.properties["end_state"] as? String, "error")
132
+ }
133
+
134
+ func testNewStartReportsTheLiveStreamItReplaces() throws {
135
+ _ = tracker.streamRequested(streamId: "s1", streamUrl: "rtmp://host/app", nowMs: 0)
136
+ _ = stream("streaming", nowMs: 1000)
137
+ let replaced = try XCTUnwrap(tracker.streamRequested(streamId: "s2", streamUrl: "srt://host:9000", nowMs: 11000))
138
+ XCTAssertEqual(replaced.name, "bluetooth_sdk_stream_ended")
139
+ XCTAssertEqual(replaced.properties["protocol"] as? String, "rtmp")
140
+ XCTAssertEqual(replaced.properties["end_state"] as? String, "replaced")
141
+ XCTAssertEqual(replaced.properties["duration_ms"] as? Int64, 10000)
142
+ // The replaced stream's own late terminal status is not reported again.
143
+ XCTAssertNil(stream("stopped", terminal: true, nowMs: 12000))
144
+ XCTAssertNil(tracker.streamStatus(
145
+ streamId: "s2", state: "streaming", terminal: nil, reconnectAttempt: nil, bitrate: nil, fps: nil,
146
+ droppedFrames: nil, temperatureC: nil, errorDetails: nil, nowMs: 12000
147
+ ))
148
+ let second = try XCTUnwrap(tracker.streamStatus(
149
+ streamId: "s2", state: "stopped", terminal: true, reconnectAttempt: nil, bitrate: nil, fps: nil,
150
+ droppedFrames: nil, temperatureC: nil, errorDetails: nil, nowMs: 20000
151
+ ))
152
+ XCTAssertEqual(second.properties["protocol"] as? String, "srt")
153
+ XCTAssertEqual(second.properties["duration_ms"] as? Int64, 8000)
154
+ }
155
+
156
+ func testOlderGlassesEndAStreamOnStoppedAndErrorDetailsLoseTheirUrls() throws {
157
+ _ = tracker.streamRequested(streamId: "s2", streamUrl: "https://whip.example.com/whip/abc", nowMs: 0)
158
+ XCTAssertNil(tracker.streamStatus(
159
+ streamId: nil, state: "streaming", terminal: nil, reconnectAttempt: nil, bitrate: nil, fps: nil,
160
+ droppedFrames: nil, temperatureC: nil, errorDetails: nil, nowMs: 500
161
+ ))
162
+ XCTAssertNil(tracker.streamStatus(
163
+ streamId: nil, state: "error", terminal: nil, reconnectAttempt: nil, bitrate: nil, fps: nil,
164
+ droppedFrames: nil, temperatureC: nil, errorDetails: nil, nowMs: 1000
165
+ ))
166
+ let ended = try XCTUnwrap(tracker.streamStatus(
167
+ streamId: nil, state: "reconnect_failed", terminal: nil, reconnectAttempt: nil, bitrate: nil, fps: nil,
168
+ droppedFrames: nil, temperatureC: nil, errorDetails: "connect to https://whip.example.com/whip/abc failed",
169
+ nowMs: 9000
170
+ ))
171
+ XCTAssertEqual(ended.properties["protocol"] as? String, "whip")
172
+ XCTAssertEqual(ended.properties["end_state"] as? String, "reconnect_failed")
173
+ XCTAssertEqual(ended.properties["error_code"] as? String, "connect to <url> failed")
174
+ XCTAssertEqual(ended.properties["stopped_by_app"] as? Bool, false)
175
+ }
176
+
177
+ func testStreamThatNeverWentLiveEndsWithoutASecondEvent() {
178
+ _ = tracker.streamRequested(streamId: "s3", streamUrl: "srt://host:9000", nowMs: 0)
179
+ let failed = tracker.streamStartSettled(
180
+ streamUrl: "srt://host:9000", width: nil, height: nil, fps: nil, bitrate: nil,
181
+ captureAudio: true, glassesNetwork: "none", latencyMs: 30000, errorCode: "stream_start_failed"
182
+ )
183
+ XCTAssertEqual(failed.properties["success"] as? Bool, false)
184
+ XCTAssertEqual(failed.properties["error_code"] as? String, "stream_start_failed")
185
+ XCTAssertEqual(failed.properties["protocol"] as? String, "srt")
186
+ XCTAssertNil(tracker.streamStatus(
187
+ streamId: "s3", state: "stopped", terminal: true, reconnectAttempt: nil, bitrate: nil, fps: nil,
188
+ droppedFrames: nil, temperatureC: nil, errorDetails: nil, nowMs: 1000
189
+ ))
190
+ // Nothing live was replaced either.
191
+ XCTAssertNil(tracker.streamRequested(streamId: "s4", streamUrl: "srt://host:9000", nowMs: 2000))
192
+ }
193
+
194
+ func testStreamProtocolFollowsTheGlassesSchemeMapping() {
195
+ XCTAssertEqual(BluetoothSdkUsageTracker.streamProtocol("rtmp://a"), "rtmp")
196
+ XCTAssertEqual(BluetoothSdkUsageTracker.streamProtocol("RTMPS://a"), "rtmp")
197
+ XCTAssertEqual(BluetoothSdkUsageTracker.streamProtocol("srt://a"), "srt")
198
+ XCTAssertEqual(BluetoothSdkUsageTracker.streamProtocol("http://a"), "whip")
199
+ XCTAssertEqual(BluetoothSdkUsageTracker.streamProtocol("rtmpt://a"), "unknown")
200
+ XCTAssertEqual(BluetoothSdkUsageTracker.streamProtocol("not a url"), "unknown")
201
+ }
202
+
203
+ func testMicSessionEndsWhenTheSourceTurnsOffOrChanges() throws {
204
+ XCTAssertNil(tracker.observeMic(currentMic: "", transcribing: false, nowMs: 0))
205
+ XCTAssertNil(tracker.observeMic(currentMic: "glasses", transcribing: false, nowMs: 1000))
206
+ XCTAssertNil(tracker.observeMic(currentMic: "glasses", transcribing: true, nowMs: 2000))
207
+
208
+ let switched = try XCTUnwrap(tracker.observeMic(currentMic: "phone", transcribing: false, nowMs: 11000))
209
+ XCTAssertEqual(switched.name, "bluetooth_sdk_mic_session")
210
+ XCTAssertEqual(switched.properties["mic_source"] as? String, "glasses")
211
+ XCTAssertEqual(switched.properties["duration_ms"] as? Int64, 10000)
212
+ XCTAssertEqual(switched.properties["local_transcription"] as? Bool, true)
213
+
214
+ let off = try XCTUnwrap(tracker.observeMic(currentMic: "", transcribing: false, nowMs: 14000))
215
+ XCTAssertEqual(off.properties["mic_source"] as? String, "phone")
216
+ XCTAssertEqual(off.properties["duration_ms"] as? Int64, 3000)
217
+ XCTAssertEqual(off.properties["local_transcription"] as? Bool, false)
218
+ XCTAssertNil(tracker.observeMic(currentMic: "", transcribing: false, nowMs: 15000))
219
+ }
220
+
221
+ func testWifiAndHotspotSetupReportOutcomeAndLatency() {
222
+ let wifi = tracker.wifiSetupSettled(latencyMs: 4000, errorCode: nil)
223
+ XCTAssertEqual(wifi.properties["success"] as? Bool, true)
224
+ XCTAssertEqual(wifi.properties["latency_ms"] as? Int64, 4000)
225
+ XCTAssertEqual(
226
+ tracker.wifiSetupSettled(latencyMs: 15000, errorCode: "connect_timeout").properties["error_code"] as? String,
227
+ "connect_timeout"
228
+ )
229
+ XCTAssertEqual(tracker.hotspotStartSettled(latencyMs: 2500, errorCode: nil).name, "bluetooth_sdk_hotspot_started")
230
+ }
231
+
232
+ func testOtaSessionIsReportedOnceWithItsStartingVersions() throws {
233
+ XCTAssertNil(ota("ota-1", "in_progress", nowMs: 0, fromBuild: "38"))
234
+ XCTAssertNil(ota("ota-1", "step_complete", nowMs: 60000, fromBuild: "39"))
235
+ let done = try XCTUnwrap(ota("ota-1", "complete", nowMs: 300_000, fromBuild: "40"))
236
+ XCTAssertEqual(done.name, "bluetooth_sdk_ota_finished")
237
+ XCTAssertEqual(done.properties["success"] as? Bool, true)
238
+ XCTAssertEqual(done.properties["duration_ms"] as? Int64, 300_000)
239
+ XCTAssertEqual(done.properties["from_build_number"] as? String, "38")
240
+ XCTAssertEqual(done.properties["total_steps"] as? Int, 2)
241
+ XCTAssertNil(done.properties["failed_step_type"])
242
+ XCTAssertNil(ota("ota-1", "complete", nowMs: 301_000, fromBuild: "40"))
243
+
244
+ let failed = try XCTUnwrap(ota(
245
+ "ota-2", "failed", nowMs: 0, fromBuild: "40", stepType: "bes",
246
+ error: "download failed: https://ota.example.com/x.bin"
247
+ ))
248
+ XCTAssertEqual(failed.properties["success"] as? Bool, false)
249
+ XCTAssertEqual(failed.properties["failed_step_type"] as? String, "bes")
250
+ XCTAssertEqual(failed.properties["error_message"] as? String, "download failed: <url>")
251
+ XCTAssertNil(failed.properties["duration_ms"])
252
+ }
253
+
254
+ func testRequestTimeoutsAreCappedPerTracker() throws {
255
+ var capped = BluetoothSdkUsageTracker(maxRequestTimeouts: 2)
256
+ let first = try XCTUnwrap(capped.requestTimedOut(operation: "photo request"))
257
+ XCTAssertEqual(first.name, "bluetooth_sdk_request_failed")
258
+ XCTAssertEqual(first.properties["operation"] as? String, "photo request")
259
+ XCTAssertEqual(first.properties["error_code"] as? String, "request_timeout")
260
+ XCTAssertNotNil(capped.requestTimedOut(operation: "start stream"))
261
+ XCTAssertNil(capped.requestTimedOut(operation: "start stream"))
262
+ }
263
+
264
+ func testDetailsAreSanitizedAndCapped() {
265
+ XCTAssertNil(BluetoothSdkUsageTracker.sanitizedDetail(" "))
266
+ XCTAssertEqual(BluetoothSdkUsageTracker.sanitizedDetail(String(repeating: "x", count: 500))?.count, 200)
267
+ }
268
+
269
+ private func stream(
270
+ _ state: String,
271
+ terminal: Bool? = nil,
272
+ reconnectAttempt: Int? = nil,
273
+ bitrate: Int64? = nil,
274
+ droppedFrames: Int64? = nil,
275
+ nowMs: Int64
276
+ ) -> AnalyticsEvent? {
277
+ tracker.streamStatus(
278
+ streamId: "s1", state: state, terminal: terminal, reconnectAttempt: reconnectAttempt, bitrate: bitrate,
279
+ fps: nil, droppedFrames: droppedFrames, temperatureC: nil, errorDetails: nil, nowMs: nowMs
280
+ )
281
+ }
282
+
283
+ private func ota(
284
+ _ sessionId: String,
285
+ _ status: String,
286
+ nowMs: Int64,
287
+ fromBuild: String,
288
+ stepType: String = "apk",
289
+ error: String? = nil
290
+ ) -> AnalyticsEvent? {
291
+ tracker.otaStatus(
292
+ sessionId: sessionId, status: status, stepType: stepType, totalSteps: 2, errorMessage: error,
293
+ fromBuildNumber: fromBuild, fromBesFirmwareVersion: "", fromMtkFirmwareVersion: "", nowMs: nowMs
294
+ )
295
+ }
296
+ }
@@ -0,0 +1,32 @@
1
+ @testable import MentraBluetoothSDK
2
+ import XCTest
3
+
4
+ final class G1TextSanitizerTests: XCTestCase {
5
+ func testPreservesSwedishTextAndComposesDecomposedAccents() {
6
+ let text = "“Hallå, hallå”\nÅÄÖ åäö"
7
+ XCTAssertEqual(G1Text.sanitizeForDisplay(text), text)
8
+ XCTAssertEqual(G1Text.sanitizeForDisplay("Halla\u{030A}, halla\u{030A}"), "Hallå, hallå")
9
+ XCTAssertEqual(G1Text.sanitizeForDisplay("Cafe\u{0301}\nĐa Nang"), "Café\nDa Nang")
10
+ }
11
+
12
+ func testFallsBackOnlyForUnmappedLatinAndIsIdempotent() {
13
+ let text = "Tiếng Việt: Đặng, Nguyễn, phở bò; Øresund Łódź Æsir Œuvre Straße Ðingvellir Þingvellir"
14
+ let expected = "Tieng Viet: Dang, Nguyen, pho bò; Øresund Łódź Æsir OEuvre Straße Ðingvellir Þingvellir"
15
+ XCTAssertEqual(G1Text.sanitizeForDisplay(text), expected)
16
+ XCTAssertEqual(G1Text.sanitizeForDisplay(expected), expected)
17
+ }
18
+
19
+ func testPreservesOtherScriptsAndNimoKeepsItsOwnFallback() {
20
+ let otherScripts = "が カ\u{3099} 한\u{302E} Α\u{0301} مُرَحَّبًا शि ❤️"
21
+ XCTAssertEqual(G1Text.sanitizeForDisplay(otherScripts), otherScripts)
22
+ XCTAssertEqual(LatinTextSanitizer.sanitizeForDisplay("Hallå Æsir Straße", preserveOtherScripts: true),
23
+ "Halla AEsir Strasse")
24
+ }
25
+
26
+ func testPreservesEveryEmbeddedExtendedLatinGlyphInComposedAndDecomposedForms() {
27
+ let glyphs = "ÀÂÇÈÉÊËÎÏÔÙÛÜàçèéêëîïôùûüÿŸÄäÖößẞâÁáÍíÑñúÓóÚⁱIJijŠšŽžÃÅÆÌÐÒÕØÝÞãåæìðòõøýþĄąĆćČčĎďĘęĚěĞğŁłŃńŇňŘřŚśŞşŤťŮůŹźŻżĂăıȘșȚțǖǘǚǜǎǐǒǔŐőŰű"
28
+ XCTAssertEqual(Array(G1Text.sanitizeForDisplay(glyphs).utf8), Array(glyphs.utf8))
29
+ let decomposed = glyphs.decomposedStringWithCanonicalMapping
30
+ XCTAssertEqual(Array(G1Text.sanitizeForDisplay(decomposed).utf8), Array(glyphs.utf8))
31
+ }
32
+ }