@mentra/bluetooth-sdk 3.2.1-dev.314 → 3.3.0-beta.1000
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.
- package/README.md +103 -10
- package/android/build.gradle +15 -0
- package/android/lc3Lib/build.gradle +6 -1
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +368 -0
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +156 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalytics.kt +63 -14
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTracker.kt +55 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +4 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkInstallId.kt +23 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +12 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheck.kt +184 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTracker.kt +388 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +2 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +138 -26
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +37 -13
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +3 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +235 -36
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +24 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/NetworkDiagnostics.kt +25 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/VersionInfoResponseAccumulator.kt +13 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +3 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/requests/DisplayRequests.kt +1 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/services/Foreground.kt +33 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/G2ConnectionRecovery.kt +47 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +4 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscovery.kt +70 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.kt +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizer.kt +11 -32
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +72 -21
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/LatinTextSanitizer.kt +39 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +261 -42
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +12 -8
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +314 -395
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodec.kt +247 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +238 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +58 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +180 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +11 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SelectedDeviceAddress.kt +17 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SerializedGattCallback.kt +5 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/G2Text.kt +7 -0
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +20 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkAnalyticsTrackerTest.kt +58 -3
- package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUpdateCheckTest.kt +124 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BluetoothSdkUsageTrackerTest.kt +263 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/DashboardContentFormatterTest.kt +2 -2
- package/android/src/test/java/com/mentra/bluetoothsdk/DeviceIdentityPairingTest.kt +59 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerSceneHandoffTest.kt +666 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/G2TextTest.kt +13 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/NetworkDiagnosticsTest.kt +55 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/ScanCompletionTest.kt +5 -1
- package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/VersionInfoResponseAccumulatorTest.kt +71 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/debug/BleTraceLoggerTest.kt +69 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/services/G2ConnectionRecoveryTest.kt +51 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioServiceDiscoveryTest.kt +124 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G1PairingTest.kt +105 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +29 -4
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G2DisplayThreadTest.kt +120 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/G2PairingTargetTest.kt +90 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveClassicDisconnectTest.kt +133 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveFileTransferSessionTest.kt +55 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGattCallbackTest.kt +33 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +137 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +126 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingTargetTest.kt +65 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveWifiCredentialLogTest.kt +55 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraNexPairingTest.kt +151 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoBitmapAcceptanceTest.kt +105 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCodecTest.kt +233 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +348 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +339 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoMicReconnectTest.kt +93 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoProtocolTest.kt +11 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/SelectedDeviceAddressTest.kt +27 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +287 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +127 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +288 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoReadinessDriverTest.kt +205 -0
- package/build/BluetoothSdk.types.d.ts +22 -1
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js +1 -0
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +6 -1
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +5 -1
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/MentraLocalNetworkModule.d.ts +23 -0
- package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
- package/build/_private/MentraLocalNetworkModule.js.map +1 -1
- package/build/_private/nativeLogConsole.d.ts +19 -0
- package/build/_private/nativeLogConsole.d.ts.map +1 -1
- package/build/_private/nativeLogConsole.js +12 -0
- package/build/_private/nativeLogConsole.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +5 -2
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +6 -2
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +6 -6
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/ota-transport/index.d.ts +4 -0
- package/build/ota-transport/index.d.ts.map +1 -1
- package/build/ota-transport/index.js +2 -0
- package/build/ota-transport/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +25 -4
- package/ios/MentraBluetoothSDK.podspec +3 -2
- package/ios/Source/BluetoothBackgroundMode.swift +32 -0
- package/ios/Source/BluetoothSdkDefaults.swift +7 -2
- package/ios/Source/Bridge.swift +15 -2
- package/ios/Source/DeviceManager.swift +106 -66
- package/ios/Source/DeviceStore.swift +26 -7
- package/ios/Source/GeneratedChangelogCatalog.swift +3 -2
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +324 -54
- package/ios/Source/TouchGesture.swift +13 -0
- package/ios/Source/audio/GlassesMicWatchdog.swift +33 -0
- package/ios/Source/events/BluetoothEvents.swift +4 -0
- package/ios/Source/internal/BluetoothAvailability.swift +6 -0
- package/ios/Source/internal/BluetoothSdkAnalytics.swift +87 -13
- package/ios/Source/internal/BluetoothSdkAnalyticsTracker.swift +54 -1
- package/ios/Source/internal/BluetoothSdkInstallId.swift +21 -0
- package/ios/Source/internal/BluetoothSdkUpdateCheck.swift +223 -0
- package/ios/Source/internal/BluetoothSdkUsageTracker.swift +428 -0
- package/ios/Source/requests/DisplayRequests.swift +1 -1
- package/ios/Source/requests/VersionInfoResponseAccumulator.swift +11 -1
- package/ios/Source/sgcs/Ar99.swift +1 -2
- package/ios/Source/sgcs/G1.swift +68 -38
- package/ios/Source/sgcs/G1ConnectionTarget.swift +13 -0
- package/ios/Source/sgcs/G2.swift +261 -247
- package/ios/Source/sgcs/G2ConnectionSession.swift +101 -0
- package/ios/Source/sgcs/Mach1.swift +19 -7
- package/ios/Source/sgcs/MentraLive.swift +368 -220
- package/ios/Source/sgcs/MentraLiveFileTransferSession.swift +137 -0
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +47 -0
- package/ios/Source/sgcs/MentraNex.swift +8 -31
- package/ios/Source/sgcs/NexConnectionTarget.swift +15 -0
- package/ios/Source/sgcs/Nimo.swift +280 -408
- package/ios/Source/sgcs/NimoCanvasCodec.swift +272 -0
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +233 -0
- package/ios/Source/sgcs/NimoCanvasImage.swift +53 -0
- package/ios/Source/sgcs/NimoCanvasSession.swift +166 -0
- package/ios/Source/sgcs/NimoDiscovery.swift +49 -0
- package/ios/Source/sgcs/SGCManager.swift +25 -1
- package/ios/Source/sgcs/VuzixConnectionTarget.swift +15 -0
- package/ios/Source/status/DeviceStatus.swift +1 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +49 -189
- package/ios/Source/utils/AudioSessionMonitor.swift +44 -8
- package/ios/Source/utils/DemandDrivenAudioWorker.swift +150 -0
- package/ios/Source/utils/G1Text.swift +2 -24
- package/ios/Source/utils/G1TextSanitizer.swift +27 -0
- package/ios/Source/utils/G2Text.swift +11 -0
- package/ios/Source/utils/LatinTextSanitizer.swift +48 -0
- package/ios/Tests/BluetoothAudioRouteTests.swift +26 -0
- package/ios/Tests/BluetoothBackgroundModeTests.swift +32 -0
- package/ios/Tests/BluetoothSdkAnalyticsTrackerTests.swift +54 -3
- package/ios/Tests/BluetoothSdkUpdateCheckTests.swift +153 -0
- package/ios/Tests/BluetoothSdkUsageTrackerTests.swift +296 -0
- package/ios/Tests/DashboardContentFormatterTests.swift +2 -2
- package/ios/Tests/DashboardRenderingTests.swift +31 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +157 -0
- package/ios/Tests/DeviceIdentityPairingTests.swift +49 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +362 -0
- package/ios/Tests/G1PairingTests.swift +162 -0
- package/ios/Tests/G1TextSanitizerTests.swift +32 -0
- package/ios/Tests/G2ConnectionSessionTests.swift +172 -0
- package/ios/Tests/G2TextTests.swift +10 -0
- package/ios/Tests/IncidentLogDispatchTests.swift +111 -0
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveFileTransferSessionTests.swift +47 -0
- package/ios/Tests/MentraLiveReconnectPolicyTests.swift +58 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +292 -0
- package/ios/Tests/NimoCanvasCodecTests.swift +217 -0
- package/ios/Tests/NimoCanvasSessionTests.swift +181 -0
- package/ios/Tests/NimoCanvasTransportTests.swift +186 -0
- package/ios/Tests/NimoDeviceCommandsTests.swift +16 -0
- package/ios/Tests/NimoDiscoveryTests.swift +79 -0
- package/ios/Tests/SGCConnectionTargetTests.swift +48 -0
- package/ios/Tests/TouchGestureCommandTests.swift +87 -0
- package/ios/Tests/VersionInfoCommandTests.swift +194 -0
- package/ios/Tests/VersionInfoResponseAccumulatorTests.swift +65 -0
- package/ios/Tests/VideoRecordingCommandTests.swift +81 -0
- package/ios/Tests/WifiCredentialLoggingTests.swift +42 -0
- package/package.json +2 -2
- package/plugin/build/withIos.d.ts +2 -0
- package/plugin/build/withIos.js +12 -1
- package/src/BluetoothSdk.types.ts +30 -0
- package/src/_private/BluetoothSdkModule.ts +12 -1
- package/src/_private/MentraLocalNetworkModule.ts +28 -0
- package/src/_private/nativeLogConsole.ts +19 -0
- package/src/generated/changelogCatalog.ts +6 -2
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +3 -0
- package/src/ota-transport/index.ts +10 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.bluetooth.BluetoothGattCallback
|
|
5
|
+
import android.bluetooth.BluetoothGattCharacteristic
|
|
6
|
+
import android.os.Looper
|
|
7
|
+
import androidx.test.core.app.ApplicationProvider
|
|
8
|
+
import com.mentra.bluetoothsdk.BluetoothSdkException
|
|
9
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
10
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
11
|
+
import java.nio.charset.StandardCharsets
|
|
12
|
+
import java.time.Duration
|
|
13
|
+
import java.util.UUID
|
|
14
|
+
import java.util.concurrent.atomic.AtomicLong
|
|
15
|
+
import org.junit.Assert.*
|
|
16
|
+
import org.junit.Test
|
|
17
|
+
import org.junit.runner.RunWith
|
|
18
|
+
import org.robolectric.RobolectricTestRunner
|
|
19
|
+
import org.robolectric.Shadows.shadowOf
|
|
20
|
+
import org.robolectric.annotation.Config
|
|
21
|
+
import org.robolectric.annotation.LooperMode
|
|
22
|
+
import org.robolectric.shadows.ShadowLog
|
|
23
|
+
|
|
24
|
+
@RunWith(RobolectricTestRunner::class)
|
|
25
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
26
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
27
|
+
class MentraLiveIncidentDispatchTest {
|
|
28
|
+
private val incident = "rep_01M4HBVT88DFSN8TYNZ1WTV4PB"
|
|
29
|
+
private val apiBase = "https://core.dev.us-west-2.mentraglass.com"
|
|
30
|
+
|
|
31
|
+
@Test fun `missing native BLE link rejects even when cached status is connected`() = withLive { live ->
|
|
32
|
+
DeviceStore.set("glasses", "connected", true)
|
|
33
|
+
expectCode("glasses_not_connected") { live.sendIncidentId(incident, apiBase) }
|
|
34
|
+
assertTrue(queuedWrites(live).isEmpty())
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test fun `missing current token does not fall back to old stored credentials`() = withLive { live ->
|
|
38
|
+
ready(live)
|
|
39
|
+
DeviceStore.set("bluetooth", "core_token", "")
|
|
40
|
+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
|
41
|
+
val prefs = context.getSharedPreferences("augmentos_auth_prefs", android.content.Context.MODE_PRIVATE)
|
|
42
|
+
prefs.edit().putString("core_token", "stale-synthetic-token").commit()
|
|
43
|
+
expectCode("core_token_unavailable") { live.sendIncidentId(incident, apiBase) }
|
|
44
|
+
assertTrue(queuedWrites(live).isEmpty())
|
|
45
|
+
prefs.edit().remove("core_token").commit()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Test fun `current token is queued before upload and never logged`() = withLive { live ->
|
|
49
|
+
ready(live)
|
|
50
|
+
val token = "synthetic-${UUID.randomUUID()}"
|
|
51
|
+
DeviceStore.set("bluetooth", "core_token", token)
|
|
52
|
+
ShadowLog.clear()
|
|
53
|
+
live.sendIncidentId(incident, apiBase)
|
|
54
|
+
val writes = queuedWrites(live)
|
|
55
|
+
val wire = writes.joinToString("") { String(it, StandardCharsets.UTF_8) }
|
|
56
|
+
assertEquals(2, writes.size)
|
|
57
|
+
assertTrue(wire.indexOf("auth_token") < wire.indexOf("upload_incident_logs"))
|
|
58
|
+
assertTrue(wire.contains(token))
|
|
59
|
+
assertTrue(wire.contains(incident))
|
|
60
|
+
assertFalse("token logged", ShadowLog.getLogs().any { it.msg.contains(token) })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test fun `link losing TX characteristic rejects instead of retaining incident relay`() = withLive { live ->
|
|
64
|
+
ready(live)
|
|
65
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic")
|
|
66
|
+
set(live, "txCharacteristic", null)
|
|
67
|
+
expectCode("glasses_not_connected") { live.sendIncidentId(incident, apiBase) }
|
|
68
|
+
assertTrue(queuedWrites(live).isEmpty())
|
|
69
|
+
val relays = get(live, "bleIncidentLogRelays") as Map<*, *>
|
|
70
|
+
assertTrue(relays.isEmpty())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test fun `session loss during token serialization cannot queue an upload into the next session`() = withLive { live ->
|
|
74
|
+
ready(live)
|
|
75
|
+
DeviceStore.set("bluetooth", "core_token", "synthetic-token")
|
|
76
|
+
val generation = get(live, "bleSessionGeneration") as AtomicLong
|
|
77
|
+
val sink = Bridge.addEventSink { type, body ->
|
|
78
|
+
if (type == "log" && body["message"].toString().contains("<auth_token with credentials omitted>")) {
|
|
79
|
+
generation.incrementAndGet()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
expectCode("incident_dispatch_failed") { live.sendIncidentId(incident, apiBase) }
|
|
84
|
+
val wire = queuedWrites(live).joinToString("") { String(it, StandardCharsets.UTF_8) }
|
|
85
|
+
assertFalse(wire.contains("upload_incident_logs"))
|
|
86
|
+
assertTrue((get(live, "bleIncidentLogRelays") as Map<*, *>).isEmpty())
|
|
87
|
+
} finally { Bridge.removeEventSink(sink) }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private fun ready(live: MentraLive) {
|
|
91
|
+
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
|
|
92
|
+
val gatt = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("AA:BB:CC:DD:EE:FF")
|
|
93
|
+
.connectGatt(context, false, object : BluetoothGattCallback() {})
|
|
94
|
+
set(live, "isConnected", true)
|
|
95
|
+
set(live, "bluetoothGatt", gatt)
|
|
96
|
+
set(live, "txCharacteristic", BluetoothGattCharacteristic(UUID.randomUUID(), 0, 0))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private fun withLive(body: (MentraLive) -> Unit) {
|
|
100
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
101
|
+
val live = MentraLive()
|
|
102
|
+
val token = DeviceStore.get("bluetooth", "core_token")
|
|
103
|
+
val connected = DeviceStore.get("glasses", "connected")
|
|
104
|
+
try { body(live) } finally {
|
|
105
|
+
DeviceStore.set("bluetooth", "core_token", token ?: "")
|
|
106
|
+
DeviceStore.set("glasses", "connected", connected ?: false)
|
|
107
|
+
live.destroy()
|
|
108
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private fun expectCode(code: String, body: () -> Unit) {
|
|
113
|
+
try { body(); fail("Expected $code") } catch (error: BluetoothSdkException) { assertEquals(code, error.code) }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private fun get(live: MentraLive, name: String): Any? =
|
|
117
|
+
MentraLive::class.java.getDeclaredField(name).apply { isAccessible = true }.get(live)
|
|
118
|
+
|
|
119
|
+
private fun set(live: MentraLive, name: String, value: Any?) {
|
|
120
|
+
MentraLive::class.java.getDeclaredField(name).apply { isAccessible = true }.set(live, value)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private fun queuedWrites(live: MentraLive): List<ByteArray> = (get(live, "sendQueue") as Iterable<*>).map { write ->
|
|
124
|
+
write!!.javaClass.getDeclaredField("data").apply { isAccessible = true }.get(write) as ByteArray
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import androidx.test.core.app.ApplicationProvider
|
|
6
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
7
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
8
|
+
import java.time.Duration
|
|
9
|
+
import org.junit.Assert.assertEquals
|
|
10
|
+
import org.junit.Assert.assertTrue
|
|
11
|
+
import org.junit.Before
|
|
12
|
+
import org.junit.Test
|
|
13
|
+
import org.junit.runner.RunWith
|
|
14
|
+
import org.robolectric.RobolectricTestRunner
|
|
15
|
+
import org.robolectric.Shadows.shadowOf
|
|
16
|
+
import org.robolectric.annotation.Config
|
|
17
|
+
import org.robolectric.annotation.LooperMode
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
21
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
22
|
+
class MentraLivePairingTargetTest {
|
|
23
|
+
@Before fun setup() {
|
|
24
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
25
|
+
shadowOf(BluetoothAdapter.getDefaultAdapter()).setState(BluetoothAdapter.STATE_ON)
|
|
26
|
+
DeviceStore.set("bluetooth", "pending_device_name", "MENTRA_LIVE_NEW")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Test fun `name-only selection scans instead of connecting the previous Live`() {
|
|
30
|
+
assertTarget("MENTRA_LIVE_OLD", "00:00:00:00:00:01", "", scanExpected = true)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Test fun `normal pairing connects the pending Live address`() {
|
|
34
|
+
assertTarget("MENTRA_LIVE_OLD", "00:00:00:00:00:01", "00:00:00:00:00:02")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Test fun `normal saved Live reconnect keeps the matching address`() {
|
|
38
|
+
assertTarget("MENTRA_LIVE_NEW", "00:00:00:00:00:02", "")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private fun assertTarget(savedName: String, savedAddress: String, pendingAddress: String, scanExpected: Boolean = false) {
|
|
42
|
+
DeviceStore.set("bluetooth", "device_name", savedName)
|
|
43
|
+
DeviceStore.set("bluetooth", "device_address", savedAddress)
|
|
44
|
+
DeviceStore.set("bluetooth", "pending_device_address", pendingAddress)
|
|
45
|
+
val adapter = BluetoothAdapter.getDefaultAdapter()
|
|
46
|
+
val old = adapter.getRemoteDevice("00:00:00:00:00:01")
|
|
47
|
+
val selected = adapter.getRemoteDevice("00:00:00:00:00:02")
|
|
48
|
+
shadowOf(old).setName("MENTRA_LIVE_OLD")
|
|
49
|
+
shadowOf(selected).setName("MENTRA_LIVE_NEW")
|
|
50
|
+
val live = MentraLive()
|
|
51
|
+
try {
|
|
52
|
+
live.connectById("MENTRA_LIVE_NEW")
|
|
53
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
54
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
55
|
+
assertEquals(if (scanExpected) 0 else 1, shadowOf(selected).bluetoothGatts.size)
|
|
56
|
+
assertEquals(if (scanExpected) 1 else 0, shadowOf(adapter.bluetoothLeScanner).scanCallbacks.size)
|
|
57
|
+
assertEquals(savedName, DeviceStore.get("bluetooth", "device_name"))
|
|
58
|
+
} finally {
|
|
59
|
+
live.destroy()
|
|
60
|
+
// Robolectric does not deliver the disconnect callback automatically.
|
|
61
|
+
// Complete the production teardown timeout before another test connects.
|
|
62
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.os.Looper
|
|
4
|
+
import androidx.test.core.app.ApplicationProvider
|
|
5
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
6
|
+
import java.nio.charset.StandardCharsets
|
|
7
|
+
import java.time.Duration
|
|
8
|
+
import java.util.UUID
|
|
9
|
+
import org.junit.Assert.assertFalse
|
|
10
|
+
import org.junit.Assert.assertTrue
|
|
11
|
+
import org.junit.Test
|
|
12
|
+
import org.junit.runner.RunWith
|
|
13
|
+
import org.robolectric.RobolectricTestRunner
|
|
14
|
+
import org.robolectric.Shadows.shadowOf
|
|
15
|
+
import org.robolectric.annotation.Config
|
|
16
|
+
import org.robolectric.annotation.LooperMode
|
|
17
|
+
import org.robolectric.shadows.ShadowLog
|
|
18
|
+
|
|
19
|
+
@RunWith(RobolectricTestRunner::class)
|
|
20
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
21
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
22
|
+
class MentraLiveWifiCredentialLogTest {
|
|
23
|
+
@Test fun `wifi credentials reach the BLE queue without being logged`() {
|
|
24
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
25
|
+
val ssid = "synthetic-${UUID.randomUUID()}"
|
|
26
|
+
val password = UUID.randomUUID().toString()
|
|
27
|
+
val events = mutableListOf<String>()
|
|
28
|
+
val sink = Bridge.addEventSink { type, body -> if (type == "log") events.add(body["message"].toString()) }
|
|
29
|
+
val live = MentraLive()
|
|
30
|
+
try {
|
|
31
|
+
ShadowLog.clear()
|
|
32
|
+
live.sendWifiCredentials(ssid, password)
|
|
33
|
+
|
|
34
|
+
val logs = events + ShadowLog.getLogs().map { it.msg }
|
|
35
|
+
assertFalse("password logged", logs.any { it.contains(password) })
|
|
36
|
+
assertTrue(events.any { it.endsWith("LIVE: Sending data to glasses: <set_wifi_credentials with credentials omitted>") })
|
|
37
|
+
// The glasses still receive the unchanged credentials.
|
|
38
|
+
val wire = queuedWrites(live).joinToString("") { String(it, StandardCharsets.UTF_8) }
|
|
39
|
+
assertTrue(wire.contains("set_wifi_credentials"))
|
|
40
|
+
assertTrue(wire.contains(ssid))
|
|
41
|
+
assertTrue(wire.contains(password))
|
|
42
|
+
} finally {
|
|
43
|
+
Bridge.removeEventSink(sink)
|
|
44
|
+
live.destroy()
|
|
45
|
+
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(2))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private fun queuedWrites(live: MentraLive): List<ByteArray> {
|
|
50
|
+
val queue = MentraLive::class.java.getDeclaredField("sendQueue").apply { isAccessible = true }.get(live)
|
|
51
|
+
return (queue as Iterable<*>).map { write ->
|
|
52
|
+
write!!.javaClass.getDeclaredField("data").apply { isAccessible = true }.get(write) as ByteArray
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.bluetooth.BluetoothAdapter
|
|
4
|
+
import android.bluetooth.BluetoothDevice
|
|
5
|
+
import android.bluetooth.BluetoothGatt
|
|
6
|
+
import android.bluetooth.BluetoothProfile
|
|
7
|
+
import android.bluetooth.le.ScanResult
|
|
8
|
+
import android.bluetooth.le.ScanSettings
|
|
9
|
+
import android.os.Looper
|
|
10
|
+
import androidx.test.core.app.ApplicationProvider
|
|
11
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
12
|
+
import com.mentra.bluetoothsdk.DeviceManager
|
|
13
|
+
import com.mentra.bluetoothsdk.DeviceStore
|
|
14
|
+
import com.mentra.bluetoothsdk.utils.DeviceTypes
|
|
15
|
+
import org.junit.Assert.assertEquals
|
|
16
|
+
import org.junit.Assert.assertTrue
|
|
17
|
+
import org.junit.Before
|
|
18
|
+
import org.junit.Test
|
|
19
|
+
import org.junit.runner.RunWith
|
|
20
|
+
import org.robolectric.RobolectricTestRunner
|
|
21
|
+
import org.robolectric.Shadows.shadowOf
|
|
22
|
+
import org.robolectric.annotation.Config
|
|
23
|
+
import org.robolectric.annotation.Implementation
|
|
24
|
+
import org.robolectric.annotation.Implements
|
|
25
|
+
import org.robolectric.annotation.LooperMode
|
|
26
|
+
import org.robolectric.shadows.ShadowBluetoothGatt
|
|
27
|
+
|
|
28
|
+
@RunWith(RobolectricTestRunner::class)
|
|
29
|
+
@Config(sdk = [33], shadows = [G1PairingTest.ShadowLc3Cpp::class, MentraNexPairingTest.ShadowNexGatt::class], instrumentedPackages = ["com.mentra.lc3Lib"])
|
|
30
|
+
@LooperMode(LooperMode.Mode.PAUSED)
|
|
31
|
+
class MentraNexPairingTest {
|
|
32
|
+
// Robolectric implements connection callbacks but not the PHY binder request.
|
|
33
|
+
@Implements(BluetoothGatt::class)
|
|
34
|
+
class ShadowNexGatt : ShadowBluetoothGatt() {
|
|
35
|
+
@Implementation fun setPreferredPhy(txPhy: Int, rxPhy: Int, phyOptions: Int) {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Before fun setup() {
|
|
39
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
40
|
+
shadowOf(BluetoothAdapter.getDefaultAdapter()).setState(BluetoothAdapter.STATE_ON)
|
|
41
|
+
DeviceStore.set("bluetooth", "pending_device_name", "Nex1-2")
|
|
42
|
+
DeviceStore.set("bluetooth", "pending_device_address", "")
|
|
43
|
+
DeviceStore.set("bluetooth", "device_address", "")
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Test fun `fresh pairing selects only the requested Nex`() {
|
|
47
|
+
assertScansSelectedTarget("", "")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Test fun `simulated pairing selects only the requested Nex`() {
|
|
51
|
+
assertScansSelectedTarget("Simulated Glasses", "")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Test fun `a different saved Nex name and address cannot redirect selection`() {
|
|
55
|
+
assertScansSelectedTarget("Nex1-1", "00:00:00:00:00:01")
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test fun `pending address targets the new Nex instead of the saved pair`() {
|
|
59
|
+
assertDirectTarget("Nex1-1", "00:00:00:00:00:01", "00:00:00:00:00:02")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Test fun `saved Nex reconnect retains its address`() {
|
|
63
|
+
assertDirectTarget("Nex1-2", "00:00:00:00:00:02", "")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Test fun `name-only pairing readiness cannot associate the old MAC with the new Nex`() {
|
|
67
|
+
DeviceStore.set("bluetooth", "default_wearable", DeviceTypes.NEX)
|
|
68
|
+
DeviceStore.set("bluetooth", "pending_wearable", DeviceTypes.NEX)
|
|
69
|
+
DeviceStore.set("bluetooth", "device_name", "Nex1-1")
|
|
70
|
+
DeviceStore.set("bluetooth", "device_address", "00:00:00:00:00:01")
|
|
71
|
+
DeviceStore.set("bluetooth", "shouldSendBootingMessage", false)
|
|
72
|
+
DeviceStore.set("glasses", "fullyBooted", false)
|
|
73
|
+
val old = device("00:00:00:00:00:01", "Nex1-1")
|
|
74
|
+
val selected = device("00:00:00:00:00:02", "Nex1-2")
|
|
75
|
+
val singleton = DeviceManager::class.java.getDeclaredField("_instance").apply { isAccessible = true }
|
|
76
|
+
val previous = singleton.get(null)
|
|
77
|
+
val manager = DeviceManager(initializeHardware = false)
|
|
78
|
+
singleton.set(null, manager)
|
|
79
|
+
try {
|
|
80
|
+
var nex = MentraNex()
|
|
81
|
+
manager.sgc = nex
|
|
82
|
+
nex.connectById("Nex1-2")
|
|
83
|
+
val scanner = shadowOf(BluetoothAdapter.getDefaultAdapter().bluetoothLeScanner)
|
|
84
|
+
scanner.scanCallbacks.single().onScanResult(
|
|
85
|
+
ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanResult(selected, null, -50, 0),
|
|
86
|
+
)
|
|
87
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
88
|
+
// Drive the actual ready callback and DeviceManager's identity promotion.
|
|
89
|
+
shadowOf(selected).simulateGattConnectionChange(BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED)
|
|
90
|
+
assertEquals("Nex1-2", DeviceStore.get("bluetooth", "device_name"))
|
|
91
|
+
assertEquals("", DeviceStore.get("bluetooth", "device_address"))
|
|
92
|
+
assertEquals("", DeviceStore.get("bluetooth", "pending_device_name"))
|
|
93
|
+
manager.disconnect()
|
|
94
|
+
|
|
95
|
+
nex = MentraNex()
|
|
96
|
+
manager.sgc = nex
|
|
97
|
+
nex.connectById(DeviceStore.get("bluetooth", "device_name") as String)
|
|
98
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
99
|
+
scanner.scanCallbacks.single().onScanResult(
|
|
100
|
+
ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanResult(selected, null, -50, 0),
|
|
101
|
+
)
|
|
102
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
103
|
+
assertEquals(2, shadowOf(selected).bluetoothGatts.size)
|
|
104
|
+
} finally {
|
|
105
|
+
manager.disconnect()
|
|
106
|
+
manager.cleanup()
|
|
107
|
+
singleton.set(null, previous)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private fun assertScansSelectedTarget(savedName: String, savedAddress: String) {
|
|
112
|
+
DeviceStore.set("bluetooth", "device_name", savedName)
|
|
113
|
+
DeviceStore.set("bluetooth", "device_address", savedAddress)
|
|
114
|
+
val old = device("00:00:00:00:00:01", "Nex1-1")
|
|
115
|
+
val prefixCollision = device("00:00:00:00:00:03", "Nex1-23")
|
|
116
|
+
val selected = device("00:00:00:00:00:02", "Nex1-2")
|
|
117
|
+
val nex = MentraNex()
|
|
118
|
+
try {
|
|
119
|
+
nex.connectById("Nex1-2")
|
|
120
|
+
val scanner = shadowOf(BluetoothAdapter.getDefaultAdapter().bluetoothLeScanner)
|
|
121
|
+
val callback = scanner.scanCallbacks.single()
|
|
122
|
+
for (found in listOf(old, prefixCollision, selected)) {
|
|
123
|
+
callback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, ScanResult(found, null, -50, 0))
|
|
124
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
125
|
+
}
|
|
126
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
127
|
+
assertTrue(shadowOf(prefixCollision).bluetoothGatts.isEmpty())
|
|
128
|
+
assertEquals(1, shadowOf(selected).bluetoothGatts.size)
|
|
129
|
+
assertEquals(savedName, DeviceStore.get("bluetooth", "device_name"))
|
|
130
|
+
} finally { nex.disconnect() }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fun assertDirectTarget(savedName: String, savedAddress: String, pendingAddress: String) {
|
|
134
|
+
DeviceStore.set("bluetooth", "device_name", savedName)
|
|
135
|
+
DeviceStore.set("bluetooth", "device_address", savedAddress)
|
|
136
|
+
DeviceStore.set("bluetooth", "pending_device_address", pendingAddress)
|
|
137
|
+
val old = device("00:00:00:00:00:01", "Nex1-1")
|
|
138
|
+
val selected = device("00:00:00:00:00:02", "Nex1-2")
|
|
139
|
+
val nex = MentraNex()
|
|
140
|
+
try {
|
|
141
|
+
nex.connectById("Nex1-2")
|
|
142
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
143
|
+
assertTrue(shadowOf(old).bluetoothGatts.isEmpty())
|
|
144
|
+
assertEquals(1, shadowOf(selected).bluetoothGatts.size)
|
|
145
|
+
assertEquals(savedName, DeviceStore.get("bluetooth", "device_name"))
|
|
146
|
+
} finally { nex.disconnect() }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private fun device(address: String, name: String): BluetoothDevice =
|
|
150
|
+
BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address).also { shadowOf(it).setName(name) }
|
|
151
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.sgcs
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import androidx.test.core.app.ApplicationProvider
|
|
5
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
6
|
+
import java.io.ByteArrayOutputStream
|
|
7
|
+
import java.util.Base64
|
|
8
|
+
import org.junit.After
|
|
9
|
+
import org.junit.Assert.*
|
|
10
|
+
import org.junit.Before
|
|
11
|
+
import org.junit.Test
|
|
12
|
+
import org.junit.runner.RunWith
|
|
13
|
+
import org.robolectric.RobolectricTestRunner
|
|
14
|
+
import org.robolectric.annotation.Config
|
|
15
|
+
import org.robolectric.annotation.GraphicsMode
|
|
16
|
+
|
|
17
|
+
@RunWith(RobolectricTestRunner::class)
|
|
18
|
+
@Config(sdk = [33])
|
|
19
|
+
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
|
20
|
+
class NimoBitmapAcceptanceTest {
|
|
21
|
+
private lateinit var nimo: Nimo
|
|
22
|
+
|
|
23
|
+
@Before fun setup() {
|
|
24
|
+
Bridge.initialize(ApplicationProvider.getApplicationContext())
|
|
25
|
+
nimo = Nimo()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@After fun dispose() { nimo.cleanup() }
|
|
29
|
+
|
|
30
|
+
@Test fun malformedInputsAreRejectedBeforeReturning() {
|
|
31
|
+
val invalid = listOf(
|
|
32
|
+
"not base64!",
|
|
33
|
+
"data:image/jpeg;base64,${png()}",
|
|
34
|
+
"data:image/bmp;base64,${png()}",
|
|
35
|
+
Base64.getEncoder().encodeToString(byteArrayOf(0x89.toByte(), 80, 78, 71, 13, 10, 26, 10) + ByteArray(40)),
|
|
36
|
+
Base64.getEncoder().encodeToString(byteArrayOf(66, 77) + ByteArray(60)),
|
|
37
|
+
"A".repeat(NimoCanvasCodec.MAX_IMAGE_BASE64_CHARS + 1)
|
|
38
|
+
)
|
|
39
|
+
for (input in invalid) {
|
|
40
|
+
assertFalse("Malformed bitmap was accepted: ${input.take(50)}", nimo.displayBitmap(input))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test fun validPngAcceptsNullableGeometryAndRejectsOutOfBoundsGeometry() {
|
|
45
|
+
val image = png()
|
|
46
|
+
assertTrue(nimo.displayBitmap(image))
|
|
47
|
+
assertTrue(nimo.displayBitmap(image, 499, 219, null, null))
|
|
48
|
+
assertFalse(nimo.displayBitmap(image, 500, 0, null, null))
|
|
49
|
+
assertFalse(nimo.displayBitmap(image, 0, 0, 0, 1))
|
|
50
|
+
assertFalse(nimo.displayBitmap(image, -1, 0, 10, 10))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Test fun jpegPixelsAreDecodedForRawAndDataUriInputs() {
|
|
54
|
+
val bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888)
|
|
55
|
+
val bytes = ByteArrayOutputStream()
|
|
56
|
+
try {
|
|
57
|
+
bitmap.eraseColor(android.graphics.Color.WHITE)
|
|
58
|
+
assertTrue(bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes))
|
|
59
|
+
} finally { bitmap.recycle() }
|
|
60
|
+
val raw = Base64.getEncoder().encodeToString(bytes.toByteArray())
|
|
61
|
+
val decode = Nimo::class.java.getDeclaredMethod(
|
|
62
|
+
"decodeCanvasImage", String::class.java, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType
|
|
63
|
+
).apply { isAccessible = true }
|
|
64
|
+
for (input in listOf(raw, "data:image/jpeg;base64,$raw")) {
|
|
65
|
+
assertTrue(nimo.displayBitmap(input))
|
|
66
|
+
assertArrayEquals(ByteArray(4) { 255.toByte() }, decode.invoke(nimo, input, 2, 2) as ByteArray)
|
|
67
|
+
}
|
|
68
|
+
assertFalse(nimo.displayBitmap("data:image/png;base64,$raw"))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Test fun sourceRasterBudgetsRejectOversizeAndAcceptBoundaries() {
|
|
72
|
+
for ((width, height) in listOf(4097 to 1, 1 to 4097, 2049 to 2000)) {
|
|
73
|
+
assertFalse("Oversize source $width x $height", nimo.displayBitmap(png(width, height)))
|
|
74
|
+
}
|
|
75
|
+
for ((width, height) in listOf(4096 to 1, 1 to 4096, 2000 to 2000)) {
|
|
76
|
+
assertTrue("Valid boundary $width x $height", nimo.displayBitmap(png(width, height)))
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Test fun coloredRasterQuantizationMatchesIosAtEveryTwoBitBoundary() {
|
|
81
|
+
// Identical opaque 8x1 24-bit BMP in NimoCanvasSceneTests; no scaling.
|
|
82
|
+
val bmp = byteArrayOf(
|
|
83
|
+
66, 77, 78, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0,
|
|
84
|
+
40, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 1, 0, 24, 0,
|
|
85
|
+
0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
86
|
+
0, 72, 0, 0, 73, 0, 0, 217.toByte(), 0, 0, 218.toByte(), 0,
|
|
87
|
+
0, 231.toByte(), 255.toByte(), 0, 232.toByte(), 255.toByte(), 0, 0, 0, -1, -1, -1
|
|
88
|
+
)
|
|
89
|
+
val decode = Nimo::class.java.getDeclaredMethod(
|
|
90
|
+
"decodeCanvasImage", String::class.java, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType
|
|
91
|
+
).apply { isAccessible = true }
|
|
92
|
+
val gray = decode.invoke(nimo, Base64.getEncoder().encodeToString(bmp), 8, 1) as ByteArray
|
|
93
|
+
assertArrayEquals(byteArrayOf(42, 43, 127, 128.toByte(), 212.toByte(), 213.toByte(), 0, -1), gray)
|
|
94
|
+
assertArrayEquals(byteArrayOf(0xE9.toByte(), 0x4C), NimoCanvasCodec.pack2(gray))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private fun png(width: Int = 2, height: Int = 2): String {
|
|
98
|
+
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
99
|
+
return try {
|
|
100
|
+
val bytes = ByteArrayOutputStream()
|
|
101
|
+
assertTrue(bitmap.compress(Bitmap.CompressFormat.PNG, 100, bytes))
|
|
102
|
+
Base64.getEncoder().encodeToString(bytes.toByteArray())
|
|
103
|
+
} finally { bitmap.recycle() }
|
|
104
|
+
}
|
|
105
|
+
}
|