From 0c3d7517bc6e4300f56fa91cd8808863d30f423f Mon Sep 17 00:00:00 2001 From: James Babcock Date: Sun, 20 Sep 2026 18:23:33 -0700 Subject: [PATCH 01/27] Resource management for the texture cache --- .../faceclaw/app/FaceclawBleCommunicator.java | 47 ++--- app/g2/firmware-compat.ts | 2 +- app/g2/firmware/cfw-patches.ts | 68 +++---- app/g2/glasses-session.ts | 14 +- app/g2/texture-planner.ts | 2 +- app/native/kotlin-protocol-smoke.ios.ts | 6 +- app/native/texture-planner.ios.ts | 2 +- native/kotlin/migrated-java-sources.json | 2 +- .../app/g2protocol/BleImageOptimizer.kt | 2 +- .../app/g2protocol/CfwMessageWindow.kt | 7 + .../app/g2protocol/ConnectionOptions.kt | 4 +- .../app/g2protocol/ResourceCacheState.kt | 150 ++++++++++++++ .../app/g2protocol/TextureCacheState.kt | 191 ------------------ .../faceclaw/app/g2protocol/TexturePlanner.kt | 128 +++++------- .../app/graphics/FontResourceAtlas.kt | 39 ++++ .../com/faceclaw/app/graphics/GlyphAtlas.kt | 2 +- .../com/faceclaw/app/graphics/ImageAtlas.kt | 5 +- .../app/graphics/SurfaceCompositor.kt | 2 +- .../kotlin/com/faceclaw/app/util/BmpUtil.kt | 2 +- .../kotlin/com/faceclaw/app/IosTextureApi.kt | 10 +- tests/ios-ble.test.cjs | 36 +++- .../app/ResourceCacheProtocolTest.java | 20 ++ .../app/TextureCacheProtocolTest.java | 58 ------ .../com/faceclaw/app/JavaCompatibilityTest.kt | 2 +- .../kotlin/com/faceclaw/app/ProtocolTest.kt | 14 ++ .../com/faceclaw/app/ResourceCacheTest.kt | 166 +++++++++++++++ .../com/faceclaw/app/TextureCacheTest.kt | 99 --------- .../com/faceclaw/app/IosTextureApiTest.kt | 13 +- 28 files changed, 569 insertions(+), 524 deletions(-) create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt delete mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TextureCacheState.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt create mode 100644 tests/kotlin/src/androidHostTest/java/com/faceclaw/app/ResourceCacheProtocolTest.java delete mode 100644 tests/kotlin/src/androidHostTest/java/com/faceclaw/app/TextureCacheProtocolTest.java create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt delete mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/TextureCacheTest.kt diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java index 9f32fadb..c5f4dfeb 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java @@ -130,7 +130,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private int faceclawWakePendingNonce = -1; /** * The last firmware-info read said the glasses run Faceclaw's custom - * firmware. Gates the private modes (cleanup, texture cache, ...) so stock + * firmware. Gates the private modes (cleanup, resource cache, ...) so stock * or third-party firmware never sees them; the TS side checks the actual * revision and disconnects on a mismatch, so no per-feature gating is * needed here. @@ -245,7 +245,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private int desiredPaintMs; private int desiredFrameId; // Screen-space deferred draws (glyphs + images) whose pixels are baked - // into desiredPacked; the texture-cache planner may replay them as + // into desiredPacked; the resource-cache planner may replay them as // on-glasses cached draws. private SurfaceCompositor.ScreenDraw[] desiredDraws = new SurfaceCompositor.ScreenDraw[0]; // (frame, reason) of the last "waiting to send" line, so a frame that @@ -260,11 +260,11 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private final SurfaceCompositor compositor = new SurfaceCompositor(); - // Phone-side model of the CFW's 64 KiB texture cache (modes 12/13/14). + // Phone-side model of the CFW's 256 KiB resource cache (modes 19/20/21/22). // Reset whenever the image pipeline / EvenHub session is torn down: the // firmware frees the cache with the fb lease, and after any resync the // cheap safe assumption is an empty cache (glyphs re-upload lazily). - private final TextureCacheState textureCache = new TextureCacheState(); + private final ResourceCacheState resourceCache = new ResourceCacheState(); private final ArrayDeque pendingMessages = new ArrayDeque<>(); private final CfwTransport[] cfwTransports = { new CfwTransport(AndroidProtocolPlatform.INSTANCE), new CfwTransport(AndroidProtocolPlatform.INSTANCE) }; @@ -1210,7 +1210,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { /** * As above, with the frame's glyph draws (see SurfaceCompositor's glyph * overload for the buffer format): the surface's full text content as - * structured draws, letting the texture-cache planner ship glyphs as + * structured draws, letting the resource-cache planner ship glyphs as * on-glasses cached draws instead of pixels. Null when the submitter has * no glyph metadata; the pixels alone remain fully correct. */ @@ -1415,10 +1415,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { */ public boolean suspendEvenHubSession() { // Ending the plugin task releases the fb lease, which frees the - // on-glasses texture cache; forget it phone-side either way (a lost + // on-glasses resource cache; forget it phone-side either way (a lost // ack may still have taken effect). synchronized (lock) { - textureCache.reset(); + resourceCache.reset(); } if (sendShutdownInternal(0, false)) { return true; @@ -2439,7 +2439,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { return ConnectionOptions.IDLE_SLEEP_MS; } - if (messageToPrewrite == null && sessionReady && windowHasRoom && !pendingMessages.isEmpty()) { + if (messageToPrewrite == null && sessionReady && windowHasRoom && !pendingMessages.isEmpty() + && CfwMessageWindow.canSend(inFlightMessages, pendingMessages.peekFirst())) { messageToWrite = pendingMessages.removeFirst(); Log.i(TAG, "sending pending message: " + messageToWrite.label); } else if (messageToPrewrite == null && !shutdownRequested && !benchmarkActive @@ -2954,8 +2955,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { return; } - // Texture-cache path: ship text as cached-glyph draws, punching their - // ink out of the baked deltas. Uploads (mode 12) ride ahead of the + // Resource-cache path: ship text as cached-glyph draws, punching their + // ink out of the baked deltas. Resource commands (modes 21/22) ride ahead of the // image message on the ordered transport. Falls through to the plain // paths whenever the planner has nothing to draw. if (customFirmwareDetected && connectionOptions.TEXTURE_CACHE_FRAMES @@ -2965,13 +2966,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { ? lastEnqueuedPacked : null; FrameTimings.getInstance().spanStart(frameId, "texture-plan"); TexturePlanner.Result tex = TexturePlanner.plan( - deltaBase, packed, width, height, draws, textureCache, + deltaBase, packed, width, height, draws, resourceCache, nextImageFrameId, connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS); if (tex != null) { nextImageFrameId = tex.nextFid; - for (byte[] upload : tex.uploads) { - enqueueTextureUploadLocked(upload); + for (byte[] upload : tex.resourceCommands) { + enqueueResourceCommandLocked(upload); } BleImageOptimizer.TileImagePlan plan = new BleImageOptimizer.TileImagePlan( 0, DASHBOARD_TILE, packed, width, height, nextMapSessionId(), tex.payload); @@ -2982,7 +2983,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { + " fw=" + tex.fwGlyphs + "/" + tex.fwRuns + " baked=" + tex.bakedCandidates + (tex.uploadBytes > 0 ? " upload=" + tex.uploadBytes + "B" : "") - + " cache=" + textureCache.usedBytes() + "B" + + " cache=" + resourceCache.usedBytes() + "B" + " payload=" + tex.payload.length + "B" + " (rects " + tex.rectsMs + "ms, match " + tex.matchMs + "ms, cache " + tex.cacheMs + "ms, punch " + tex.punchMs @@ -3081,23 +3082,23 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } /** - * Enqueue one mode-12 texture-cache upload ahead of the image message that + * Enqueue one resource eviction/upload command ahead of the image message that * references its glyphs (the transport is FIFO, so no ack round trip is * needed before use). A timeout means the on-glasses cache state is * unknown; forget everything phone-side (glyphs re-upload lazily) and let * the accompanying image update's own timeout drive the frame resync. */ - private void enqueueTextureUploadLocked(byte[] payload) { + private void enqueueResourceCommandLocked(byte[] payload) { OutboundMessage message = messageBuilder.imagePayload( - "texcache", + "resources", DASHBOARD_TILE, nextMapSessionId(), payload, - "texture upload " + payload.length + "B", + "resource command " + payload.length + "B", connectionOptions.sendImagesToLeft); message.onTimeout = () -> { - textureCache.reset(); - logLine("texture upload ack timeout; texture cache state reset"); + resourceCache.reset(); + logLine("resource command ack timeout; resource cache state reset"); }; pendingMessages.addLast(message); logLine("queue " + message.label); @@ -3591,10 +3592,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { // image is a full keyframe rather than a delta onto a stale base. lastEnqueuedPacked = new byte[0]; lastEnqueuedFingerprint = ""; - // Queued texture uploads (if any) were dropped with the rest, and the + // Queued resource commands (if any) were dropped with the rest, and the // session churn behind a full clear may have freed the on-glasses // cache; forget it phone-side so glyphs re-upload lazily. - textureCache.reset(); + resourceCache.reset(); } /** @@ -3625,7 +3626,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { clearInFlightMessagesLocked(reason); lastEnqueuedPacked = new byte[0]; lastEnqueuedFingerprint = ""; - textureCache.reset(); + resourceCache.reset(); } /** Any image update whose fragments are still queued (not yet sent). */ diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index 2da29b2d..944fa312 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -26,7 +26,7 @@ export type FirmwareInfo = { }; /** The Faceclaw firmware revision this build of the app needs. */ -export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 22; +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 23; const FACECLAW_PREFIX = "Faceclaw/"; const LEGACY_PREFIX = "EVENCFW"; diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index b5c7b0ff..dd0da9f6 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,12 +19,12 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "059ff37a5455b9b272b715ab62c2910ee4dc4966fbfb2e117159bda746bd7315", + "outputSha256": "393ea24203d9a388975c732cae4698339f8af0e13139b73d71386181a1bc004e", "patches": [ { "offset": 1045797, "old": "38b584b0", - "new": "5af317bf", + "new": "59f3efbf", "desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease" }, { @@ -36,49 +36,49 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1437923, "old": "fef788ff", - "new": "fbf226fc", + "new": "faf2fefc", "desc": "cfw_ancs_event" }, { "offset": 1437951, "old": "fef7e8fb", - "new": "fbf260f9", + "new": "faf238fa", "desc": "cfw_ancs_open" }, { "offset": 1437969, "old": "fef7e7fb", - "new": "fbf277f9", + "new": "faf24ffa", "desc": "cfw_ancs_close" }, { "offset": 1388387, "old": "39694d00", - "new": "35407d00", + "new": "e5317d00", "desc": "connection-bound ANCS EUS write callback" }, { "offset": 971497, "old": "fff717f8", - "new": "6df347f8", + "new": "6cf31ff9", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 971845, "old": "fef769ff", - "new": "6cf399ff", + "new": "6cf371f8", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 979579, "old": "fdf74ef8", - "new": "6bf37ef8", + "new": "6af356f9", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 1428895, "old": "f8f76cfd", - "new": "faf224f9", + "new": "f9f28afd", "desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)" }, { @@ -108,145 +108,145 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1248487, "old": "d4f712fb", - "new": "28f378f9", + "new": "27f354fb", "desc": "bl settings_send_wrapper (append caps field 100)" }, { "offset": 1246183, "old": "f5f7e2f8", - "new": "28f310fb", + "new": "27f374fd", "desc": "bl settings_decode_wrapper (Faceclaw lease field 101)" }, { "offset": 975219, "old": "02f083fc", - "new": "6af372fb", + "new": "69f3d6fd", "desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)" }, { "offset": 975411, "old": "02f023fc", - "new": "6af3e0fb", + "new": "69f344fe", "desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)" }, { "offset": 975103, "old": "07f085fb", - "new": "6cf350f8", + "new": "6bf328f9", "desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)" }, { "offset": 830549, "old": "19f03efb", - "new": "8ff3fff9", + "new": "8ef3d7fa", "desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)" }, { "offset": 830795, "old": "1ff071ff", - "new": "8ff3b8f9", + "new": "8ef390fa", "desc": "bl gesture_press (owned event 9 before stock menu gate)" }, { "offset": 830887, "old": "1ff043ff", - "new": "8ff3b2f9", + "new": "8ef38afa", "desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)" }, { "offset": 831763, "old": "1ff08dfd", - "new": "8ef3e8ff", + "new": "8ef3c0f8", "desc": "bl gesture_release (owned event 10 before stock menu gate)" }, { "offset": 1570209, "old": "7fb50600", - "new": "d9f209bd", + "new": "d8f2e5be", "desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline" }, { "offset": 1051545, "old": "f6f787f9", - "new": "53f3d7fe", + "new": "53f3cbfc", "desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)" }, { "offset": 1051861, "old": "f6f7e9f8", - "new": "53f339fe", + "new": "53f32dfc", "desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)" }, { "offset": 1262237, "old": "d9f7d0fd", - "new": "24f3cff9", + "new": "23f3b3fc", "desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)" }, { "offset": 1262337, "old": "d9f79efd", - "new": "24f39df9", + "new": "23f381fc", "desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)" }, { "offset": 1309405, "old": "67f02dff", - "new": "18f3b7fa", + "new": "17f39bfd", "desc": "bl compass_decode_capture (sample-matched GAF diagnostics)" }, { "offset": 1307865, "old": "fff7c9fb", - "new": "18f335fe", + "new": "18f319f9", "desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)" }, { "offset": 1300937, "old": "00210170", - "new": "1af31bfb", + "new": "19f3fffd", "desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)" }, { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fa5b04ef66c6b4ff29c5416460d46ccf2ff0bc2f229044ff6ff7900274ff00108019006e048f2a351c0f24501bff32f8f8847d4f800a0bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0c3804ff4407005f073f9002800f0b7824ff60051cff6ff714218403182f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d7382f82e7382f82f7382f8307382f8317382f8327382f8337382f8347382f8357382f8367382f8377382f8387382f8397382f83a7382f83b7382f83c7382f83d7382f83e7382f83f737ff47cafc0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001f51457ff42fafbff35f8f00bf44e8000121b154e8001f5145f8d023e7aa4645ea064100260127c0f8701206e048f2a351c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0c2804ff4407005f090f8002800f0d4814ff60051cff6ff7100bf4218403182f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382f8196382f81a6382f81b6382f81c6382f81d6382f81e6382f81f6382f8206382f8216382f8226382f8236382f8246382f8256382f8266382f8276382f8286382f8296382f82a6382f82b6382f82c6382f82d6382f82e6382f82f6382f8306382f8316382f8326382f8336382f8346382f8356382f8366382f8376382f8386382f8396382f83a6382f83b6382f83c6382f83d6382f83e6382f83f637ff47cafc0f800b08772a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff430afbff35f8f44e8000121b154e8001fa942f8d025e7d0f8746242f6f767c0f24407002ebff35f8f00f0f38007f19a0230464ff0ff314ff0ff379047002840f0498147f6df40c0f24f00804700274ff001080397adf8107006e048f2a351c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0e9804ff4407004f094ff002800f0e1804ff60051cff6ff7100bf4218403182f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d7382f82e7382f82f7382f8307382f8317382f8327382f8337382f8347382f8357382f8367382f8377382f8387382f8397382f83a7382f83b7382f83c7382f83d7382f83e7382f83f737ff47cafc0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff42fafbff35f8f00bf44e8000149b354e8001fa942f8d023e705460020b847b0b105f51d7151e8006f4eb9bff35f8f00bf41e8000292b151e8006f002ef8d00021bff32f8fbff35f8f21b10646f1e64ff0ff3742e007f5a9718847eae60121f1e70020019d42f6f764002d4ff0010bc0f2440418bfbaf1000f33d10df108098046484602f061fa03ab28465146012206f093fa9df8111007464846002918bf4ff0ff3702f08dfbbbf1000f044608d19df8100028b94af21f30c0f247004c308047b8f1000f18bfc8f80c4042f6f764c0f2440404f5807130468847384625b0bde8f08f2a7802f07f01a1f1150313f1030f0bd802f07b030b2b07d002f07e02082a03d0032901d00629b7d140b14af21f31c0f247010746884797f8641111b14ff0ff37d6e738464ff0000ba6e72de9f04f81b04ef66c6b4ff29c554ff6005848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0b2804ff4407004f019fe002800f0aa80414600bf4218403182f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d7382f82e7382f82f7382f8307382f8317382f8327382f8337382f8347382f8357382f8367382f8377382f8387382f8397382f83a7382f83b7382f83c7382f83d7382f83e7382f83f737ff47cafc0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff447afbff35f8f00bf45e8000129b155e8001fa142f8d03be7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04f9fb04ff29c50c2f229000668bff35f8f30466ff39600b0f1005f43d130684ef66c65ccf2ff05a8423cd196f8640138b3d6f8604124b340f24030c2f20000d0f8787504a802f0a6f8002f00f0738140f2030a384621464ff416320296cff6807a4ff6ff760397fff759fa4ff6005b48f2a358cff6ff7b00270124c0f245081ce096f8660170b1d6f8680140b147f64c61c2f207010968401a002802f37180002086f8660140f6a120c0f247001fb0bde8f04f0047bff32f8fc0474ff29c50c2f22900d0f80090bff35f8f0068bff35f8f00ea0a01b1f1005f03d10168a94200f0b3804ff4407004f091fc002802f03080594600bf4218403182f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d7382f82e7382f82f7382f8307382f8317382f8327382f8337382f8347382f8357382f8367382f8377382f8387382f8397382f83a7382f83b7382f83c7382f83d7382f83e7382f83f737ff47caf4ff29c52056084728683c683068446848684c684068546858685c685068646868686c68606874687c2f2290252e8001f49457ff441afbff35f8f00bf42e8000121b152e8001f4945f8d035e7817a002941f08087027e0021002a8df81c107cd04ff29c5507aac2f22905535c002b00f0b68053185f78002f74d09f78002f73d0df78002f72d01f79002f71d05f79002f70d09f79002f6fd0df79002f6ed01f7a002f6dd05f7a002f6cd09f7a002f6bd0df7a002f6ad01f7b002f69d05f7b002f68d09f7b002f67d0df7b002f66d01f7c002f65d05f7c002f64d09f7c002f63d0df7c002f62d01f7d002f61d05f7d002f60d09f7d002f5fd0df7d002f5ed01f7e002f5dd05f7e002f5cd09f7e002f5bd0df7e002f5ad01f7f002f59d05f7f002f58d09f7f002f57d0db7f002b56d0203160297ff49aaf76e0002086f86401c6f8600186f86601012086f8650140f6a120c0f24700804701f011bf4ff29c55c2f2290564e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0d68300218df87b100121427e002a00f0c280002207ab9f5c002f00f0a0809f187e78002e5ed0be78002e5dd0fe78002e5cd03e79002e5bd07e79002e5ad0be79002e59d0fe79002e58d03e7a002e57d07e7a002e56d0be7a002e55d0fe7a002e54d03e7b002e53d07e7b002e52d0be7b002e51d0fe7b002e50d03e7c002e4fd07e7c002e4ed0be7c002e4dd0fe7c002e4cd03e7d002e4bd07e7d002e4ad0be7d002e49d0fe7d002e48d03e7e002e47d07e7e002e46d0be7e002e45d0fe7e002e44d03e7f002e43d07e7f002e42d0be7f002e41d0ff7f002f40d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff053079f5411d013444b275e2a5f700cd049275d2a9f7008d050275c2adf7004d020275b2a1f7140f0f08100228df87b200131827e002a00f0be80002107aa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df87b1001216a6846f23f53c5f28803b3eb520f40f08b80d20700f08d80002107aa535c002b00f0858153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0fc805f7a002f00f0fc809f7a002f00f0fc80df7a002f00f0fc801f7b002f00f0fc805f7b002f00f0fc809f7b002f00f0fc80df7b002f00f0fc801f7c002f00f0fc805f7c002f00f0fc809f7c002f00f0fc80df7c002f00f0fc801f7d002f00f0fc805f7d002f00f0fc809f7d002f00f0fc80df7d002f00f0fc801f7e002f00f0fc805f7e002f00f0fc809f7e002f00f0fc80df7e002f00f0fc801f7f002f00f00d815f7f002f00f00b819f7f002f00f00981db7f002b00f00781203160297ff47baf1de14cf67e22caf210126a60002940f01981002107aa535c002b00f0dc8053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f68d01f7b002f69d05f7b002f6ad09f7b002f6bd0df7b002f6cd01f7c002f6dd05f7c002f6ed09f7c002f6fd0df7c002f70d01f7d002f71d05f7d002f72d09f7d002f73d0df7d002f74d01f7e002f75d05f7e002f76d09f7e002f77d0df7e002f78d01f7f002f79d05f7f002f7ad09f7f002f7bd0db7f002b7cd0203160297ff49aaface000211171f6e6013173e0023171e003316fe004316de0013184e0053169e0023180e0063165e003317ce0073161e0043178e008315de0053174e0093159e0063170e00a3155e007316ce000225a710fe60b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0948000218df87b1000210df11c0c1cf80120002a00f0a1800ceb01025378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff498af43e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d84ff077020cf8012003d100218df87b1002e0614400224a70c2684ff0000e1cf80e10002900f0c4800ceb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000818eb0e0a52d0b2fbf3f40a2b04f130010cf80e104cf6cd41ccf6cc41a3fb011646d31af1010141d004fb1324f708b4fbf7fb0ceb0e020bf13001517048f21f51c5f2eb11642ba3fb011634d31af102012cd00bfb17447709b4fbf7f6b3f57a7f06f13001917044f6d351c1f26201a3fb015123d31af1030518d006fb1744890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114242f210710ef1040e8b424fea5733aad209e0ce4607e00ef1010e04e00ef1020e01e00ef1030e0022e2460cf80e201af80210002900f0a1800aeb02014b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff498af52e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a13d84ff075010af802100ed00aeb020173235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df87b1002694ff000081af80810002900f0c7800aeb08035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d008f12008b8f1600f7ff496af4ff060085ee008f101085be008f1020858e008f1030855e008f1040852e008f105084fe008f106084ce008f1070849e008f1080846e008f1090843e008f10a0840e008f10b083de008f10c083ae008f10d0837e008f10e0834e000220a7162e708f10f082ee008f110082be008f1110828e008f1120825e008f1130822e008f114081fe008f115081ce008f1160819e008f1170816e008f1180813e008f1190810e008f11a080de008f11b080ae008f11c0807e008f11d0804e008f11e0801e008f11f0801230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46c646b8f15f0f98bf4ff05f0ecef1000b42f2107c1beb080950d0b2fbf3f40a2b04f130010af808104cf6cd41ccf6cc41a3fb011644d319f101013fd004fb1324f708b4fbf7f60aeb080206f13001517048f21f51c5f2eb11642ba3fb015132d319f102052ad006fb17444e09b4fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb015121d319f1030516d007fb1644890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114208f1040863454fea5733acd209e0f04607e008f1010804e008f1020801e008f10308039f00220af808201af80210002900f0a1800aeb02014b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff498af4ae001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a0bd84ff075010af8021006d00aeb020173235e2a4b7040f08780044600208df87b0038460221524608f0d6fdd4f870c272208df81c0078208df81d0020204ff000091ffa8cf28df81e008df81f901af80900002800f0c8800aeb09035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d009f12009b9f1600f7ff496af4ff060095fe004460020887078e709f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7642f2107503eb83004000b2fbf0f40a2c11d303fb07f0b2fbf0f40a2c0bd303fb06f0b2fbf0f40a2c05d36b43b2fbf3f00928e7d800e00346cb46b9f15f0f98bf4ff05f0bcbf1000842f2107e18eb09054dd0b2fbf3f04cf6cd4100f13004ccf6cc410af809400a2ba3fb016441d36e1c3dd000fb1320e408b0fbf4f748f21f5107f130060aeb0902c5f2eb115670642ba3fb011630d3a91c29d007fb14007409b0fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb011620d3e91c16d007fb1400b10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb110209f1040973454fea5633afd209e0d94607e009f1010904e009f1020901e009f1030900220af8092040f24039c2f200091af80200002800f0a1800aeb0201487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff498af56e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a17d84ff020000af8020012d00aeb020163205e2a48700cd072205d2a887008d063205c2ac87004d020205b2a087140f0628100208df87b0037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df8171000f137010a2838bf00f13001ccf303508df8181000f137010a2838bf00f13001ccf303408df8191000f137010a2838bf00f1300100208df81b001f208df81a100aeb000111f81f2c002a00f0818011f81e2c002a7ed011f81d2c002a7cd011f81c2c002a7ad011f81b2c002a78d011f81a2c002a76d011f8192c002a74d011f8182c002a72d011f8172c002a70d011f8162c002a6ed011f8152c002a6cd011f8142c002a6ad011f8132c002a68d011f8122c002a66d011f8112c002a64d011f8102c002a62d011f80f2c002a60d011f80e2c002a5ed011f80d2c002a5cd011f80c2c002a5ad011f80b2c002a58d011f80a2c002a56d011f8092c002a54d011f8082c002a52d011f8072c002a50d011f8062c002a4ed011f8052c002a4cd011f8042c002a4ad011f8032c002a48d011f8022c002a46d011f8011c002944d01af80010002941d020307f287ff479af61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c504400260df11705af5d8755b7b1b34211d0af1979788419617079b1b2420ad0b978a17051b1b64505d0f978e17029b10436b445e8d100208df87b00039842f2941845f29c1407aa0e21c2f22008c2f2130408f07ffad9f81c00a0425fd1d9f82800b0f54d2f5ad1d9f82c00a04256d145f610630020c2f213034cf6394508f1040c002763454ad81c6834f003061cd098454ff0ff3228bf0c2c42d3a8eb03018e424ff0ff313ed83946be4288bf3146e2071cbf0f4630449919013d01f10403e0d12ce0002048719de60421b7f5807f1ed300223e46b6f5007f14d3b6f5806f13d3b6f5006f12d30901b2eb163f4fea1616f0d10ce000219171fef76bbf00211172fef729bc490002e0890000e0c900634504d1494207ea0102014603e04ff0ff324ff0ff3147f64c60c2f20700d0f8840008f1080342f6941c9842c2f2270c4dd142f610674ff0000bc2f2200746f6b9750cf1040a00264ff0ff394ff0ff3857453cd83c6834f0030015d0bc4528bf0c2c36d3aceb0703984234d8b042334688bf0346e4071cbf1e4683443844013d00f10407e4d122e00425b6f5807f17d34ff0000e3046b0f5007f0cd3b0f5806f0bd3b0f5006f0ad32d01beeb103f4fea1010f0d104e06d0002e0ad0000e0ed00574504d1684206ea0009d84603e04ff0ff394ff0ff3840f24037c2f200073b680cf1080083425bd1fb68b3f5333f57d13b69834254d14ff29c5043f21063c2f229004ff0000bc2f2270342f6f934a0f1040ca0f1080e00264ff0ff3a63453fd81d6835f0030718d09e454ff0ff30019028bf0c2d37d3aeeb0300874235d83046b74288bf3846ed071cbf0646bb44d819013c00f10403e1d122e00425b6f5807f16d300273446b4f5007f0cd3b4f5806f0bd3b4f5006f0ad32d01b7eb143f4fea1414f0d104e06d0002e0ad0000e0ed00634505d16b4206ea03000190da4604e04ff0ff3001904ff0ff3a66208df81c0072208df81d0065208df81e008df81f002f208df820006d204b238df8210061208df8253069238df8220078208df82630422356278df8230020208df827303a238df82b70472707ac8df824008df828308df829004c238df82c708df82e00002720468df82a308df82d308df82f7008f08ffae05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df87b00204641464a4608f0bbf9039d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df87b0007ac019a2046514608f0edf828461a21224607f06aff029e002086f86401c6f8600103984ef2173107904ff41630089007a8c0f247018847012086f8660104a800f047f930611fb0bde8f08f0020c871d6e70021417206e700bf2de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff6005a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f0ae804ff4407002f0f2fb002800f0e48051464218403182f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382f8195382f81a5382f81b5382f81c5382f81d5382f81e5382f81f5382f8205382f8215382f8225382f8235382f8245382f8255382f8265382f8275382f8285382f8295382f82a5382f82b5382f82c5382f82d5382f82e5382f82f5382f8305382f8315382f8325382f8335382f8345382f8355382f8365382f8375382f8385382f8395382f83a5382f83b5382f83c5382f83d5382f83e5382f83f537ff47caf066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff448afbff35f8f47e8000121b157e8001f4945f8d03de74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c56d1f8009000684ff6005bccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108009007e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168b94200f0ae804ff4407002f0c6fa002800f0028159464218403182f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382f8195382f81a5382f81b5382f81c5382f81d5382f81e5382f81f5382f8205382f8215382f8225382f8235382f8245382f8255382f8265382f8275382f8285382f8295382f82a5382f82b5382f82c5382f82d5382f82e5382f82f5382f8305382f8315382f8325382f8335382f8345382f8355382f8365382f8375382f8385382f8395382f83a5382f83b5382f83c5382f83d5382f83e5382f83f537ff47caf076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f51457ff444afbff35f8f46e8000121b156e8001f5145f8d039e74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ce047f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422fd041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94217d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a9eb0501b1fbf0f001b0bde8f08f002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204607f0e3fa854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f03381207887f00301084200f02f81012039464246334600f07afa0446002898f8080018bf062422e14ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f005814ef66c6a4ff29c574ff600580294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168514500f0b1804ff4407002f017f9002800f0d280414600bf4218403182f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382f8196382f81a6382f81b6382f81c6382f81d6382f81e6382f81f6382f8206382f8216382f8226382f8236382f8246382f8256382f8266382f8276382f8286382f8296382f82a6382f82b6382f82c6382f82d6382f82e6382f82f6382f8306382f8316382f8326382f8336382f8346382f8356382f8366382f8376382f8386382f8396382f83a6382f83b6382f83c6382f83d6382f83e6382f83f637ff47cafc0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff442afbff35f8f00bf47e8000121b157e8001f4945f8d036e705eb450100eb011090f85d1201b300f513760024304629462a460323009407f073fa706840b14bf69b71c0f25d018847706807f0e3f874603068b475002818bf07f0dcf80020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f06af9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104607f060f9201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009507f006fa606840b14bf69b71c0f25d018847606807f076f865602068a575002818bf07f06ff800202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff600598046ccf2ff05c2f229064ff6ff77cff6ff7900244ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0af804ff4407001f0a0ff002800f0a78049464218403182f8004382f8014382f8024382f8034382f8044382f8054382f8064382f8074382f8084382f8094382f80a4382f80b4382f80c4382f80d4382f80e4382f80f4382f8104382f8114382f8124382f8134382f8144382f8154382f8164382f8174382f8184382f8194382f81a4382f81b4382f81c4382f81d4382f81e4382f81f4382f8204382f8214382f8224382f8234382f8244382f8254382f8264382f8274382f8284382f8294382f82a4382f82b4382f82c4382f82d4382f82e4382f82f4382f8304382f8314382f8324382f8334382f8344382f8354382f8364382f8374382f8384382f8394382f83a4382f83b4382f83c4382f83d4382f83e4382f83f437ff47caf056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff444afbff35f8f46e8000129b156e8001f5945f8d039e7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fcf75dfca81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c654ff29c564ff6005948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450bcde90612cde9080303e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0ae804ff4407001f092fe002800f04a8449464218403182f8004382f8014382f8024382f8034382f8044382f8054382f8064382f8074382f8084382f8094382f80a4382f80b4382f80c4382f80d4382f80e4382f80f4382f8104382f8114382f8124382f8134382f8144382f8154382f8164382f8174382f8184382f8194382f81a4382f81b4382f81c4382f81d4382f81e4382f81f4382f8204382f8214382f8224382f8234382f8244382f8254382f8264382f8274382f8284382f8294382f82a4382f82b4382f82c4382f82d4382f82e4382f82f4382f8304382f8314382f8324382f8334382f8344382f8354382f8364382f8374382f8384382f8394382f83a4382f83b4382f83c4382f83d4382f83e4382f83f437ff47caf056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff448afbff35f8f46e8000121b156e8001f4145f8d03de70999089d01eb410100eb011095f9081000f51376b1f1ff3f01f0030409dd374617f8110fd0bb3068002818bf06f064fe2ee3307cf0b1707ce0b10799099a002730460323009706f0ddff706840b14bf69b71c0f25d018847706806f04dfe77603068b775002818bf06f046fe00203060b06030823068002818bf06f03dfe00204ff480713060b0603182a978b081092006f11107f174b17434757076b07ca978884240f0da82317da14240f0d682069b411ca3f10b00727e02971e2828bf1e209042b17488bf7076981e84b200270a2c4ff00008c0f0e682092241f221090920039419e030684f46002818bf06f004feb089376001303774b760b081002c18bf4ff00608039cd146ddf814a00aeb0b0082b2a24280f0c682317c80b20429824600f28880aa5c00f1010a4b1c0129337405dd022906d0032970d1f28106e021b9727503e0338943ea02223281a24580f0a98204296ed015f80a204ff0000c831c8f1c0129377406ddff290bd0032967460dd19a4652e000291cbf378947ea0222328100e072756746a34204d38ae2f281a34280f08782022936d8ea5c00f1030acb1c0129337407dd022937d0fe2907d17275a2450cd375e231b9338943ea02223281a24504d36de2f281a24580f06a8202292fd015f80a20031d41f00407fc29377408ddfd2909d0fe291cbf378947ea0222328103e079b9f28100e072756746a34280f04f8209b19a4613e0ea5c00f1050a0520307401e09a466746f189308941ea0221f18128b106f070fd0028306000f0698233897089191a1ffa81fb1ffa8af1621a5a45b8bf93465fea0b4208d03268294410441ffa8bf2fcf741fa70893389584481b2994270817ff44faf0025cdf81080d6f800808df82b50707db8f1000f06930df12b0108bf88460f2806d8317d00f00302511ab1fa81f14d09000706d4317e707e814238bf30760fe000bf706840b14bf69b71c0f25d018847706806f01afd7760707e30760120f082cdf814a09db1707db57d400714d4002d4ff0000400f0888106984ff6ff7381b2002900f00d8101295ed10020d2e0707d400753d4002477e14ff4803006f0fffc002d804600f06f81b07d002800f06b81b8f1000f00f067817568002d00f0ff8030890428c0f05f8131680a1812f8043c002b40f0588112f8033c002b40f0538112f8023cff2b40f04e8112f8012cff2a40f049814ff4803429606860c5f80c802c610028019000f066814bf69b70c0f25d0000f58572284600219047002840f032812969002900f02e8168688c420c46e7d1019a0c468242e3d124e14ff4803006f0adfc04461fe1069a4ff6fe701040a44642426ff0010000bf08eb0005ac78ed7883ea04231cb25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead73787ea430383ea05231fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead737023087ea430309ead5371518023587ea430395d1023000276446069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003f0899ab282426fd14046fcf7b6f900286ad141f2210a4ff00009012375e0382006f0edfb00285ed00546077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377046f6c530c0f200007844286246f6cd30c0f20000784468624bf69b70c0f25d0045f6e46200f13c0c28460f21c0f27c023823e04740b3284606f082fb4446706841f2210a40b14bf69b71c0f25d018847706806f075fb77604ff000090323b77506980799099a089dddf8108087b23046009706f0ebfc002c214604463ff456ad084606f05dfb51e5756074e6c4f58030b4f5803f444606902f60ef607ff647aecde70799099a002430460323009406f0cdfc706840b14bf69b71c0f25d018847706806f03dfb74603068b475002818bf06f036fb0020387000203060b06030824ff00a0840460bb0bde8f08f287a4006f8d5307c08b302980078e0b10799099a002430460323009406f0a0fc706840b14bf69b71c0f25d018847706806f010fb74603068b475002818bf06f009fb00203060b06030824ff00b083068002818bf06f0fefa00203060b0603082cae702980078e0b10799099a002430460323009406f074fc706840b14bf69b71c0f25d018847706806f0e4fa74603068b475002818bf06f0ddfa00203060b06030824ff00608a7e72de9f041f02846d100294ff00b0000f08880022ac0f0858045f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a0072d07578e91ec9b2fe2938bfbde8f081307833463946022829d0012866d1ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7d5f920b306462846fff72cfa21462a46fff700fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac4219d1a1f1210010f1160f06d36ff0480048432330c0b2242810d90b20bde8f081b07a204207d04046394622462b46bde8f041fff70abb0020bde8f0811a4612f8020f40f00207032f18d19b796340032b14d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22fbf7a3fd04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522fbf75ffd0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522fbf709fd4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2bd110684ef66c61ccf2ff01884224d1d2f8680108b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f8660108bf704710b5c2f86c0148f2a352c0f245020446084690472046bde8104070470020704700bff0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff766ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff600580446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f0b0804ff4407000f05cfe002800f0d58041464218403182f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382f8195382f81a5382f81b5382f81c5382f81d5382f81e5382f81f5382f8205382f8215382f8225382f8235382f8245382f8255382f8265382f8275382f8285382f8295382f82a5382f82b5382f82c5382f82d5382f82e5382f82f5382f8305382f8315382f8325382f8335382f8345382f8355382f8365382f8375382f8385382f8395382f83a5382f83b5382f83c5382f83d5382f83e5382f83f537ff47cafc0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff443afbff35f8f00bf46e8000121b156e8001f5945f8d037e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff7defd2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff6f530cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023a6e745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04468002c00f0c7828368002b00f0c38204eb030b4ff000090027002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310ceb0a0300275b451c464ff0000680f0a782a04618f9013b03f07f05bd40002b46ea050610d406f00703012b16dc0bb3012b40f09582abeb0803082bc0f0908204f10903dee700bfd84580f08982182f07f107074446dcd982e200bf022b3ad0052b40f07d82abeb0803042bc0f07882631dc7e7d84580f0738294f90130002b04f10203bed55b4580f06a8294f90230b3f1ff3f04f10303b4dc5b4580f0608294f90330b3f1ff3f04f10403aadc5b4580f0568294f90430b3f1ff3f04f10503a0dc5b4580f04c8294f90530002b00f14782a31d96e7d84580f0428294f9013004f1020c002b03f07f0a1ed5dc4580f0378294f90270e31c07f07f05b7f1ff3f4aeac51a02dde0469c460ee05b4580f0278294f9037004f1040c07f07f05b7f1ff3f4aea853a33dd9846abeb0c039a4500f21682f308672b1dd0652b7ff460afbaf1060ffff45caf9cf80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf4ff29c54c2f229040290cde9002132e0044660460e4651461746654600f021fcac4631463a46204637e7dc4580f0e58194f90470631d07f07f05b7f1ff3f4aea455aaddc5b4580f0d88194f90570002f00f1d38104f1060c4aea077ab1e748f2a3513046c0f24501bff32f8f8847dde900210298ac462768bff35f8f2668bff35f8f33466ff39603b3f1005f07d133684ef66c65ccf2ff05ab4200f0c2804ff44070654600f083fbdde9002106460298ac46002e3ff4f1ae4ff60053cff6ff7300bff418403384f8009384f8019384f8029384f8039384f8049384f8059384f8069384f8079384f8089384f8099384f80a9384f80b9384f80c9384f80d9384f80e9384f80f9384f8109384f8119384f8129384f8139384f8149384f8159384f8169384f8179384f8189384f8199384f81a9384f81b9384f81c9384f81d9384f81e9384f81f9384f8209384f8219384f8229384f8239384f8249384f8259384f8269384f8279384f8289384f8299384f82a9384f82b9384f82c9384f82d9384f82e9384f82f9384f8309384f8319384f8329384f8339384f8349384f8359384f8369384f8379384f8389384f8399384f83a9384f83b9384f83c9384f83d9384f83e9384f83f937ff47caf4ef66c63ccf2ff0333600123b3724ff6ff734ff29c54b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290454e8003fbb427ff428afbff35f8f44e8006323b154e8003fbb42f8d01de798f8043098f8057098f80650032b47ea052433dd052b54dc042b74d0052b7ff42baed6f868313bb147f64c67c2f207073f68db1b002b14dcd6f86c3186f866917bb10c4648f2a35180461846c0f24501c6f86c91174665468847ac4621463a46404647f64c63c2f207031b6845f69077c0f201073b44c6f86831fde5012b3ff4efad022b00f08380032b7ff4f5ad174688466546fff704fb03460298ac4641463a46002b3ff4e8ad96f84231002b3ff4e3ad304641f28831a6f8404105f04efd47e0062b4ad0072b7ff4d6ad80464df6db50c0f24a0016460f466446804703465d1ea446394632464046012d3ff6c4ad981eb0fa80f04009fff7bafba446394632464046b8e5174688466546fff7c8fa03460298ac4641463a46002b3ff4acad96f84231002b3ff4a7adb6f84031a3427ff4a2add6f83c3186f84291002ba6f840913ff499ad42f68d411846c0f2440188470298ac4641463a468de5d6f86c31c6f86891002b86f866913ff485ad0f4648f2a35104461846c0f24501c6f86c91164665468847ac46394632463ae696f84231c6f83891002b3ff46ead0446d6f83c0165468846174686f84291a6f8409120b142f68d41c0f2440188474af273660120002100220023c0f24606b04720463a464146ac464fe54ff2a513c0f2490303b0bde8f04f18477fb50646002806d1fff756fa002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817046f24c71c0f20001033079440b22faf72eff0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522faf7f6fe0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522faf747fe1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246faf79dfd4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f0ff800c46014600784d2840f0f9804878432840f0f5808878012840f0f1804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f03d10268424500f0b4804ff44070fff766ff002800f0c2804ff600525146cff6ff728318403283f8005383f8015383f8025383f8035383f8045383f8055383f8065383f8075383f8085383f8095383f80a5383f80b5383f80c5383f80d5383f80e5383f80f5383f8105383f8115383f8125383f8135383f8145383f8155383f8165383f8175383f8185383f8195383f81a5383f81b5383f81c5383f81d5383f81e5383f81f5383f8205383f8215383f8225383f8235383f8245383f8255383f8265383f8275383f8285383f8295383f82a5383f82b5383f82c5383f82d5383f82e5383f82f5383f8305383f8315383f8325383f8335383f8345383f8355383f8365383f8375383f8385383f8395383f83a5383f83b5383f83c5383f83d5383f83e5383f83f537ff47cafc0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a457ff43eafbff35f8f00bf47e8000222b157e8002f4a45f8d032e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff69122cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6e930cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff3504e1cde901100120cff680704ef66c644ff29c564ff6005bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f03d10168a14200f0ad804ff44070fff739fb0028c5d059464218403182f8008382f8018382f8028382f8038382f8048382f8058382f8068382f8078382f8088382f8098382f80a8382f80b8382f80c8382f80d8382f80e8382f80f8382f8108382f8118382f8128382f8138382f8148382f8158382f8168382f8178382f8188382f8198382f81a8382f81b8382f81c8382f81d8382f81e8382f81f8382f8208382f8218382f8228382f8238382f8248382f8258382f8268382f8278382f8288382f8298382f82a8382f82b8382f82c8382f82d8382f82e8382f82f8382f8308382f8318382f8328382f8338382f8348382f8358382f8368382f8378382f8388382f8398382f83a8382f83b8382f83c8382f83d8382f83e8382f83f837ff47caf046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff446afbff35f8f46e8000121b156e8001f5145f8d03be7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff40daf00210025fff766fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff7e2fd0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff718fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff69912cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff73efd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef746fa014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef726fa0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef713fa204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd45f2ca50c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef763f90028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f9f725fe4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf78bbd00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf7b5f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e52de9f04f8bb0044600284ff0ff3000f03f830d46002900f03b83217801f07f070a2f0edd102f27dc0b2f00f09282102f40f03282204629460bb0bde8f04ffff76db8052f00f03881072f00f024830a2f40f02282022dc0f01b834ef66c6b4ff29c57ccf2ff0bc2f229074ff6ff764ff0000a4ff0010858e0112f00f00483122f40f00a82b5f1010b01f08f8004f1010a00230021abeb03000628c0f0ce860aeb0304207962799d1d40ea0222abeb050082424ff0ff3000f2eb821af803306778a678e47843ea072343ea064343ea0463b3f5802f00f2dc82c3f580239a4200f2d782002a02eb050318bf01215b45d1d3002901f05a80fdf735fc002800f09d864ef66c674ff29c55ccf2ff07c2f229054ff6ff764ff0000800f045bc48f2a351c0f24501bff32f8f8847d7f80090bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168594500f0b8834ff44070fef759fb002800f06f864ff60051cff6ff714218403182f800a382f801a382f802a382f803a382f804a382f805a382f806a382f807a382f808a382f809a382f80aa382f80ba382f80ca382f80da382f80ea382f80fa382f810a382f811a382f812a382f813a382f814a382f815a382f816a382f817a382f818a382f819a382f81aa382f81ba382f81ca382f81da382f81ea382f81fa382f820a382f821a382f822a382f823a382f824a382f825a382f826a382f827a382f828a382f829a382f82aa382f82ba382f82ca382f82da382f82ea382f82fa382f830a382f831a382f832a382f833a382f834a382f835a382f836a382f837a382f838a382f839a382f83aa382f83ba382f83ca382f83da382f83ea382f83fa37ff47cafc0f800b080f80a808683c683068446848684c684068546858685c685068646868686c6860687468757e8001f49457ff43fafbff35f8f00bf47e80001002900f0088357e8001f4945f6d031e74ef66c664ff29c57ccf2ff06c2f229074ff6ff7b4ff000084ff00109022d2cbf6078ff20059006e048f2a351c0f24501bff32f8f8847d7f800a0bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168b14200f09f824ff44070fef777fa002800f0ee844ff60051cff6ff714218403182f8008382f8018382f8028382f8038382f8048382f8058382f8068382f8078382f8088382f8098382f80a8382f80b8382f80c8382f80d8382f80e8382f80f8382f8108382f8118382f8128382f8138382f8148382f8158382f8168382f8178382f8188382f8198382f81a8382f81b8382f81c8382f81d8382f81e8382f81f8382f8208382f8218382f8228382f8238382f8248382f8258382f8268382f8278382f8288382f8298382f82a8382f82b8382f82c8382f82d8382f82e8382f82f8382f8308382f8318382f8328382f8338382f8348382f8358382f8368382f8378382f8388382f8398382f83a8382f83b8382f83c8382f83d8382f83e8382f83f837ff47caf066080f80a90a0f81cb0a0f81eb0a0f820b0a0f822b0a0f824b0a0f826b0a0f828b0a0f82ab0a0f82cb0a0f82eb0a0f830b0a0f832b0a0f834b0a0f836b0a0f838b0a0f83ab057e8001f51457ff430afbff35f8f47e80001002900f0e18157e8001f5145f6d023e70f2f9b4600f0fc81a7f11300012840f2f781092f00f06c83082f40f0e483002a4ff0ff3000f0e880022dc0f0e58094f80190b9f1000f00f0bc8402264ff0010848f2482ab21caa4200f2ab84a019a15d407851ea002100f0a4848e18ae4200f2a084a05cde4600f07f07153fffb2fd2f16d8c0b20f280ed9a0f1830cbcf10c0f4ff0ff3000f2b88008fa0cf741f249031f4205d1b0e008fa00f717ea0a0febd0a01800227346fff75ffd002840f07984b9f10109c6d100f07cbc4ff29c56c2f229063468bff35f8f20466ff39600b0f1005f40f01e8620684ef66c67ccf2ff07b8424ff0000040f08780c4f8680184f8660184f86401d4f86c11c4f8600184f8650139b148f2a352c4f86c01c0f2450208469047d4f87802002818bf03f0bcf90021c4f87812206c40f2030942f68d48cff68079c0f24408a4f8441040b1c047206c08f166018847002804bf002020644bf63940c0f2510080473568bff35f8f05ea0900b0f1005f2bd12868b84228d195f877014ff0000ac5f880a188b149f25962c0f25902002044f2436185f877a190474ef6e37bc0f25a0bd8470bf1bc008047d5f8840185f870a150b1c047d5f8840108f166018847002804bf0020c5f884013068bff35f8f00ea0901b1f1005f40f038850168b94240f0348590f8a811002900f02985fef73bfc00f02bbd022d08bf112900f033810bb0bde8f08f4ef66c6a4ff29c57ccf2ff0ac2f229074ff6ff764ff0000b4ff0010806e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168514500f06d834ff44070fef78df8002800f065834ff60051cff6ff714218403182f800b382f801b382f802b382f803b382f804b382f805b382f806b382f807b382f808b382f809b382f80ab382f80bb382f80cb382f80db382f80eb382f80fb382f810b382f811b382f812b382f813b382f814b382f815b382f816b382f817b382f818b382f819b382f81ab382f81bb382f81cb382f81db382f81eb382f81fb382f820b382f821b382f822b382f823b382f824b382f825b382f826b382f827b382f828b382f829b382f82ab382f82bb382f82cb382f82db382f82eb382f82fb382f830b382f831b382f832b382f833b382f834b382f835b382f836b382f837b382f838b382f839b382f83ab382f83bb382f83cb382f83db382f83eb382f83fb37ff47cafc0f800a080f80a808683c683068446848684c684068546858685c685068646868686c6860687468757e8001f49457ff43fafbff35f8f00bf47e80001002900f0bd8257e8001f4945f6d031e790f84410059f61b1016c39b142f68d42c0f244020646084690473046002180f844100121002f40f04782032dc0f04482a078082800f291844bf63941c0f251019631884700f089bc164600f0affc002800f0cb82611c142fa5f1010200f0be82132f5b4640f0be8200f0fcfdbce26678002e00f04c81022e00f2b78240f04484062dc0f0b282a178e2782379677941ea022143ea072232290691079280f02e84322100f030bc6078002840f09e8245f64d50c0f24600804701284ff000007ff4bfaecde9070040f20830c0f210000690ff208df8280044f25220c0f20100099040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8272008d80721b0f5807f38bf03218df827108df8280040f2d260adf81c00052006ac8df81e00e01d09a90522f8f7cdfc4ff22507c0f247070120092122460c23b8470bb0bde8f08f48f2a3514846c0f24501bff32f8f88472c68bff35f8fd5f800900320cff6807000ea0900b0f1005fbff35f8f04d1d9f80000b84200f042824ff44070fdf719ff002800f02f8281464ff60050cff6ff7000bf09eb0001403081f8008381f8018381f8028381f8038381f8048381f8058381f8068381f8078381f8088381f8098381f80a8381f80b8381f80c8381f80d8381f80e8381f80f8381f8108381f8118381f8128381f8138381f8148381f8158381f8168381f8178381f8188381f8198381f81a8381f81b8381f81c8381f81d8381f81e8381f81f8381f8208381f8218381f8228381f8238381f8248381f8258381f8268381f8278381f8288381f8298381f82a8381f82b8381f82c8381f82d8381f82e8381f82f8381f8308381f8318381f8328381f8338381f8348381f8358381f8368381f8378381f8388381f8398381f83a8381f83b8381f83c8381f83d8381f83e8381f83f837ff47baf0120c9f8007089f80a00a9f81c60a9f81e60a9f82060a9f82260a9f82460a9f82660a9f82860a9f82a60a9f82c60a9f82e60a9f83060a9f83260a9f83460a9f83660a9f83860a9f83a6055e8000fa0427ff428afbff35f8f45e80090002800f07f8155e8000fa042f6d01be7002480f8434145f64d50c0f2460080470146204601297ff48cad43f2a310c0f256000bb0bde8f04f004708064ff0210158bf11218d42c0f05181002804f101060ad545f64d50c0f24600154680472a46022818bf04f111063079717950ea01244ff0ff301ebfb179f37951ea03253ff460ad317b737b41ea03218c427ff459adb17bf37b41ea03218d427ff452ad3078717840ea012804eb0800b0f5207f4ff0ff303ff646adb178f37841ea0327e919b1f5f07f3ff63dad317a737a41ea032904eb0901b1f5207f3ff633adb17af37a41ea0326a919b1f5f07f3ff62aad924600f0ddfa002800f0f98041463a464b46cde90145009602f0c6f9dbf800100f2909d80bebc1020131a2f80690168154819581cbf80010baf1000f40f0e78095e2f81e18bf0120bb1f18bf012318424ff0ff307ff4feac032dfff4fbac032f00f0b281062f7ff4f5ac00200021164602f006fb00f0a4fa002800f0c0800246601c691e4ff4f0774ff4a073009702f03dfc002800f0b380dbf800100f2900f2b3800bebc1020023d38013814ff4207353814ff4f07301319381cbf80010a3e0059f00210020002f3ff4b9ad012f19d1052d17d3a378581e06284ff000003ff6b9ace17803293ff6b5ac2279002a3ff4b1ac4bf63940c0f2510000f59a771846b84734e2022f05d14bf63940c0f2510080472ce2032f40f01381072dc0f01081a078e278217940ea02206579a67901284ff0010498bf204644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0048245ea0621012988bf0c4642f68d41c0f24401a1f1400221469047f5e10020022d2cbf6178ff21002800f0ee81024602294ff0000025d0012920d000297ff457ac4cf67e21caf21011907610837960108150609683d683168456849684d684168556859685d685168656869686d6861687568782f83c000bb0bde8f08f01209072c2e190720bb0bde8f08f5b4600f0f9fe01e001f07afb20b14ff0ff300bb0bde8f08f002e00f0b081584601f0baffabe1d9f86c0100286ed14ff48020fdf7d3fc0028e9d000210022831881544032b2f5802f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c9f86c0100210aeb010006794579437846ea0525d9f86c611af8012087788c1d06eb0321c078114401eb074101eb00600aeb04012a46f8f7d5f9291959454ff00000e0d3fff78abb3a1f80460020b2fa82f2022d88bf012052091040084001284ff000007ff47aab4cf6cd42e91eccf6cc42a578a1fb0212b5eb920f88bf95082f4608f14603302d28bf3027e11c07eb870204461846f8f7a5f9002d88f8447088f8454000f0b480d8f8400038b94046f8f7fafe0028c8f8400000f0fc8042f68d41c0f24401a1f1400201219047d2e0080600f1d480082dfff415af07214ff0050c0123e71897f802804ff0ff30b8f1000f3ff433abfe78002e3ff42fab14f8039005914fea880101eb8903b3f5207f04913ff623ab97f801a0770007eb4a03b3f5f07f3ff61aab04eb0c0014f80c104078039241ea002081b2012002f024f900f0c2f800283ff4deae05990aeb8a020c4400ebc2104fea4803691a00eb49022046009702f056fa00283ff4ccaedbf800100f290dd84fea89020bebc106f280049a4fea4a03013133817281b781cbf80010039900297ff4beae6ce090f8a911002918bffdf70eff94f84301002684f8436158b145f64d50c0f246008047012804d143f2a310c0f256008047d4f83c0194f84251c4f8386184f84261a4f8406150b1c047d4f83c0108f166018847002804bf0020c4f83c010120a072ddb34af27367c0f246070021002200230024b84720460bb0bde8f08fb1f5fa6f02d94ff4fa6106910121044680f8431145f64d50c0f24600804701281dd143f2a315c0f25605a5f188008047022e08bf002801d058b910e04bf2110206a9c0f24b020220904740b10646a8473046002184f843110bb0bde8f08f00200bb0bde8f08f0c2dfff441aee078e17988427ff43cae2079217a88427ff437ae45f64d50c0f24600164680470523022808bf01230b214ff0090c324616e74bf639400024c0f2510088f844408047a3e72de9f04f81b04ef66c6b4ff29c554ff6005848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0b1804ff44070fdf7d5fa002800f02281414600bf4218403182f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d7382f82e7382f82f7382f8307382f8317382f8327382f8337382f8347382f8357382f8367382f8377382f8387382f8397382f83a7382f83b7382f83c7382f83d7382f83e7382f83f737ff47cafc0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff447afbff35f8f00bf45e8000121b155e8001fa142f8d03be7d0f87812002974d104464ff4163002f0bdfa014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8781200e00021084601b0bde8f08f00bf092a1cbf4ff0ff3070472de9f04f8db08a4683460693fcf74bfa002800f01b824ef66c684ff29c57ccf2ff08c2f229074ff6ff740026012507e000bf48f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168414500f0b3804ff44070fdf770f9002800f0ab804ff60051cff6ff7100bf4218403182f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382f8196382f81a6382f81b6382f81c6382f81d6382f81e6382f81f6382f8206382f8216382f8226382f8236382f8246382f8256382f8266382f8276382f8286382f8296382f82a6382f82b6382f82c6382f82d6382f82e6382f82f6382f8306382f8316382f8326382f8336382f8346382f8356382f8366382f8376382f8386382f8396382f83a6382f83b6382f83c6382f83d6382f83e6382f83f637ff47cafc0f8008085728483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff440afbff35f8f47e8000129b157e8001f4945f8d035e70020002800f03f819af800109af801209af802309af8037041ea022141ea034141ea07624ff6fe77c0f20307ba424ff0ff3100f28982d0f86c310846002b00f02481995c4ff0ff30002900f01e81134493f80190b9f1000f00f0178109fb01f09d1c4ff0000c4ff0000368b3a7f101089e18be4200f007819e462b441c78240904d00126a0421bd2fde000bf464500f0fa805c781cb10226a04211d2f3e00524cff6fc743444042cc0f0ed809c78db7854ea032400f0e7800426a042c0f0e380001b06eb0e03d3d19af804009af8052098469af806309af807609af80870cdf8009040ea022943ea0626b8060f2307f00f0403eae07000fb04f389204343db0a8df824300e2317f0200f08bf4ff00f0c08bf012304fb03f300fb03f34fead3238df825304ff00d0308bf022304fb03f300fb03f34fead3238df826304ff00c0308bf032304fb03f300fb03f34fead3238df827304ff00b0308bf042304fb03f300fb03f34fead3238df828304ff00a0308bf052304fb03f300fb03f34fead3238df829304ff0090308bf062304fb03f300fb03f34fead3238df82a304ff0080308bf072304fb03f300fb03f34fead3238df82b304ff0070308bf082304fb03f300fb03f34fead3238df82c304ff0060308bf092304fb03f300fb03f34fead3238df82d304ff0050308bf0a2304fb03f300fb03f34fead3238df82e304ff0040308bf0b2304fb03f300fb03f34fead3238df82f304ff0030308bf0c2304fb03f300fb03f34fead3238df830304ff0020308bf0d2304fb03f300fb03f34fead3238df831304ff0010308bf0e2363434343db0a8df832300cfb04f358434ff0010ec00ab8f1000fcdf814808df8330000f06f8107f010008eea1010002403904ff0000804950ce04ff0ff300db0bde8f08fdde90704049d04440598844280f05881285d0894020901d0012313e0059a171b012f00f04d812b195a780ab1022309e0042fc0f045819f78db7857ea032200f03f810423079310f00f0309a810f803a018bf012303984fea0a1e40ea030c12f00300474600f08080b8fbf1f300259f19b7f1ff3fc8bf012505ea0c05012d1dd103fb11834b44dd09042d17d87d090e2d14d807eb87050beb85155f08ec5ddb076ff00f03019408bf0f230290504608bf7046019c234003430298eb55012808f1010751d0b7fbf1f300249d19b5f1ff3fc8bf012404ea0c04012c1ad103fb11734b44dc09042c14d86c090e2c11d805eb85040beb84145d08db070290605d6ff00f03574604bf0f237746034002983b436355022808f1020726d0b7fbf1f300259c19b4f1ff3fc8bf012505ea0c05012d18d103fb11734b44dd09042d12d865090e2d0fd804eb84040beb84145d08db07605d6ff00f03574604bf0f23774603403b43635508f10307531e032b904405d246e700bf0437b8453ff442afb7fbf1f40025a319b3f1ff3fc8bf012505ea0c05012d18d104fb11744c44e509042d12d85d090e2d0fd803eb83030beb831365085a5de4076ff00f04504604bf0f2470462240104358557c1cb4fbf1f50020ab19b3f1ff3fc8bf012000ea0c00012819d105fb114000eb0904e009042812d858090e280fd803eb83000beb80106208835ce4076ff00f04554604bf0f24754623402b438354bc1cb4fbf1f50020ab19b3f1ff3fc8bf012000ea0c00012819d105fb114000eb0904e009042812d858090e280fd803eb83000beb80106208835ce4076ff00f04554604bf0f24754623402b438354fc1cb4fbf1f50020ab19b3f1ff3fc8bf012000ea0c0001287ff47baf05fb114000eb0904e00904283ff673af58090e283ff66faf03eb83000beb80106208835ce4076ff00f04554604bf0f24754623402b4383545de708460db0bde8f08f09eb01000099b0f5207f06eb0103a8bf4ff42070b3f5f07fa8bf4ff4f0730699484588bfb34203d800200db0bde8f08f0f680f2ff8d89a1ba0eb090001ebc7035881781ca3f806901e819a810860ebe70a2a3cbf4ff0ff3070472de9f04f95b017468a4605461c46fbf792fe002800f0ff809af8096006f10a0087424ff0ff3040f0f8809af800109af801209af802309af8037041ea022141ea034141ea07624ff68061c0f203018a4200f2e38010960e95cde90c429af808004ef66c644ff29c554ff60056ccf2ff04c2f229054ff6ff77cff6ff764ff0000b4ff001080f9007e000bf48f2a351c0f24501bff32f8f8847d5f80090bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168a14200f0b3804ff44070fcf78cfd002800f0ec8131464218403182f800b382f801b382f802b382f803b382f804b382f805b382f806b382f807b382f808b382f809b382f80ab382f80bb382f80cb382f80db382f80eb382f80fb382f810b382f811b382f812b382f813b382f814b382f815b382f816b382f817b382f818b382f819b382f81ab382f81bb382f81cb382f81db382f81eb382f81fb382f820b382f821b382f822b382f823b382f824b382f825b382f826b382f827b382f828b382f829b382f82ab382f82bb382f82cb382f82db382f82eb382f82fb382f830b382f831b382f832b382f833b382f834b382f835b382f836b382f837b382f838b382f839b382f83ab382f83bb382f83cb382f83db382f83eb382f83fb37ff47caf046080f80a808783c783078447848784c784078547858785c785078647868786c7860787478755e8001f49457ff444afbff35f8f45e8000149b155e8001f4945f8d039e74ff0ff3015b0bde8f08fd0f86c91109eb9f1000f00f039810f9c0f23a10604f00f0203eae171514389235943c90a8df844100e219af804c09af805709af806e09af8075014f0200f08bf012102fb01f103fb01f14fead1218df845104ff00d0108bf022102fb01f103fb01f14fead1218df846104ff00c0108bf032102fb01f103fb01f14fead1218df847104ff00b0108bf042102fb01f103fb01f14fead1218df848104ff00a0108bf052102fb01f103fb01f14fead1218df849104ff0090108bf062102fb01f103fb01f14fead1218df84a104ff0080108bf072102fb01f103fb01f14fead1218df84b104ff0070108bf082102fb01f103fb01f14fead1218df84c104ff0060108bf092102fb01f103fb01f14fead1218df84d104ff0050108bf0a2102fb01f103fb01f14fead1218df84e104ff0040108bf0b2102fb01f103fb01f14fead1218df84f104ff0030108bf0c2102fb01f103fb01f14fead1218df850104ff0020108bf0d2102fb01f103fb01f14fead1218df851104ff0010108bf0e2102fb01f103fb01f14fead1218df852104ff0000108bf0f21514359430024c90a002e8df853106ad00d994ff6fe7449440af10a0a4cea07284eea052b4ff0000cc0f203040d9104e010990cf1010c8c455ed01af80c104a1e1f2af5d34ab2202a4bdb0d9a02eb810111f8802c11f87f3c11f87e7c11f87d1c42ea032242ea074242ea0165a54238d819f805104ff0ff34a9b309eb050253788bb34ff6fe7402f1020e03fb01f60023c0f2030406e000bf0121be4221d3f61b0b44c5d05a19a2421bd00eeb03010f783f09f1d1671eba4213d04f781fb10221be42ecd20de00527cff6fc773a44042a07d38a78c97852ea012702d00421be42ddd24ff0ff34204615b0bde8f08f4ff0ff3015b0bde8f08f0c990122063100910f99002601f0100182ea1111cde9071a1af806101f2908d84144109f0b3901360024be428846f3d1dde7d0f86c214ff0ff34002ad7d00d9b03eb810111f8803c11f87f7c11f87e5c11f87d1c43ea072343ea054343ea01614ff6fe73c0f203039942c0d812f801e0bef1000fbbd053185f78002fb7d007fb0ef2ddf83890002acde9027600f0ac819d1c00244ff6fe736618c0f203039e42a3d02f193b781b0901d0012718e04ff6fe73c0f20303013b9e4296d07b780bb102270de00523cff6fc733344042bfff48cafbb78ff7853ea07233ff486af04279a42fff482afd21a3c44d3d1002c00f07b81002100220f91cde9054509e0dde90a12059c0a44ddf820a0069da24280f06b81a95c0b920e0901d0012212e0a71a012f00f06181ab185e780eb1022209e0042fc0f059819f78db7857ea032600f0538104220a9211f00f0111aa525c18bf0121079b0f9c19434fea021a16f00305a446099600f08c80b4fbfef7002607fb1e434344b3f1ff3fc8bf01260e40012e1fd117eb0b071cd4de09042e19d87e090e2e16d807eb870709eb871c5e081cf80670db076ff00f03019708bf0f230495154608bf5546019f3b402b43049d0cf80630012d04f1010c5ad0bcfbfef6002706fb1ec34344b3f1ff3fc8bf01270f40012f1fd116eb0b071cd4de09042e19d87e090e2e16d807eb870709eb871c5e081cf80670db076ff00f03019708bf0f230495154608bf5546019f3b402b43049d0cf80630022d04f1020c29d0bcfbfef5002705fb1ec34344b3f1ff3fc8bf01270f40012f1ad115eb0b0717d4de09042e14d87e090e2e11d807eb870709eb87175e08db0717f806c06ff00f03154604bf0f23554603ea0c032b43bb5504f1030c099d6b1e032b2c440f9407d237e700bf0f9b0cf1040c63453ff431afbcfbfef5002605fb1ec34344b3f1ff3fc8bf01260e40012e1bd115eb0b0518d4de09042e15d86e090e2e12d805eb850509eb85155e08db07af5d6ff00f03914604bf0f23d1463b4043ea0903ddf83890ab550cf10103b3fbfef5002605fb1e334344b3f1ff3fc8bf01260e40012e18d115eb0b0515d4de09042e12d86e090e2e0fd805eb850509eb85155e08db07af5d6ff00f03144604bf0f2354463b402343ab550cf10203b3fbfef5002405fb1e334344b3f1ff3fc8bf01240c40012c18d115eb0b0515d4dc09042c12d86c090e2c0fd805eb850409eb84145d08db07665d6ff00f03174604bf0f23574633403b4363550cf10303b3fbfef5002405fb1e334344b3f1ff3fc8bf01240c40012c7ff471af15eb0b053ff56dafdc09042c3ff669af6c090e2c3ff665af05eb850409eb84145d08db07665d6ff00f03174604bf0f23574633403b43635553e7029a08eb0e010beb0203b1f5207f0d4628eae872a8bf4ff42075b3f5f07fa8bf4ff4f07395421edd039e109f5b457ff606aeddf830e0def800400f2c3ff6ffada3eb0b0c009ba5eb020803ebc40523f83420621ca5f802b0a5f80480a5f806c0cef80020ebe5039e109fe8e5062a3cbf4ff0ff3070472de9f04fadf2944d9a46154688460f90fbf70dfa002800f0d68098f80510881d854240f0298447f65420c2f20700d0f800b0bbf1000f00f01f849bf80c009bf80d209bf80e309bf80f7040ea022040ea034040ea0769a9f1810010f1800f4ff0ff30c0f0b2809bf810209bf811309bf8137042ea03229bf8123042ea034242ea07620692813a12f5817f40f29e800029cdf828b000f09d8008f1060b002426aa4ff4e01c00270ae000bf05f1004042f8240001378f4204f1010480f08e801bf80750681e1e28f0d968b21f2801dd012075e0a5f1c2000beb07061d28a1eb07000fd8012800f0c88396f9010010f1410f00f3c28300f03f0365f38a1302201d465de005f0f003e02b24d10328c0f0b48396f9013013f1410f00f3ae8396f9020010f1410f00f3a883e02ddeb202d1a02ec0f0a283ed2d02d19f2e00f29d832b039bb206f03f0643ea861300f03f001d18032034e004284ff0ff3036d3a5f1f50313f1050f31d396f9013013f1410f2cdc96f9020010f1410f00f37e8396f9036016f1410f00f37883f02ddbb202d1902bc0f07283f42d02d18f2b00f26d830cea854e03f03f054eea053300f03f0043ea801006f03f0326aac518042000bf074442f8245076e74ff0ff300df2944dbde8f08f0021012007915ee0002c57d0a4f1010bcdf86090cdf810a000250df1780a5f46914608e026aaab4505f1010509f10409a7f1010739d052f825100029f3d400202b4687421dd009eb80067268b2f1ff3f18dc5a1c934514d0b268b2f1ff3f11dc9a1c93450dd0f268b2f1ff3f0adcda1c934506d032690433002a00f10400e0d400e000220a9853461aae009601f0f8f8002800f008831a980028c3d04af20d315046c0f24e018847bce7ddf810a0ddf828b0ddf860900020079404e00020ddf828b00790012098f804400f21a20604f00f0501eae271694389225143c90a8df8681001260e2198f800c098f801e098f8023098f8037014f0200f08bf0e2608bf012105fb01f102fb01f14fead1218df869104ff00d0108bf022105fb01f102fb01f14fead1218df86a104ff00c0108bf032105fb01f102fb01f14fead1218df86b104ff00b0108bf042105fb01f102fb01f14fead1218df86c104ff00a0108bf052105fb01f102fb01f14fead1218df86d104ff0090108bf062105fb01f102fb01f14fead1218df86e104ff0080108bf072105fb01f102fb01f14fead1218df86f104ff0070108bf082105fb01f102fb01f14fead1218df870104ff0060108bf092105fb01f102fb01f14fead1218df871104ff0050108bf0a2105fb01f102fb01f14fead1218df872104ff0040108bf0b2105fb01f102fb01f14fead1218df873104ff0030108bf0c2105fb01f102fb01f14fead1218df874104ff0020108bf0d2105fb01f102fb01f14fead1218df8751006fb05f102fb01f14fead1218df876104ff0000108bf0f2169435143c90a00284ff000008df877107ff4cdae43ea0720079a484403904cea0e290af10600571e00260df198080190cdf810a0029718e000bf4af20d311ea8c0f24e0188479df87c009df87d10dde90ab9029fdde9072640ea01200df1980801369642814400f0ff8158f82610b1f1ff3f1edd33469f421fd008eb83004268b2f1ff3f1adc0133bb4216d08268b2f1ff3f13dc0133bb420fd0c268b2f1ff3f0cdc0133bb4208d002690133002ae2d404e001f01f000b38d2e7002258461eab19ad009500f0b7ff002800f0c781199900290d9100f0ba819df880209df881309df87e009df87f1052ea03259df8822040ea01279df8833010979df884704fea024208969df8856042ea0362069b4fea074747ea06672b4403eb2743039fcdf82c90a7eb030609eb22491aaf149500f05e810902109b014400f0030809f101004ff0010c099009f102000ceb530305900d980c934b1e0e930b9b0130121415900ceb510003eb020e9a1acde91180a1eb08001890d0074ff0000a17904feace70169013960ae014980af1010a824512981599139e0144159100f029810aeb06014b090e2befd810980028ecd00e9801eb810103280f984ff0000600eb811e80f0848011980028ded0dde90c105feac67c0afb01084fea560018f8000000f00f03c1b208bf0b09b3fa83f0400910ea141f14d106eb0901c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef8002011980128b1d0701c400818f80000bcf1000fc1b24fea111308bf00f00f03d8b2b0fa80f0400910ea141f14d109983118c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef80020119802283ff486afb01c400818f80000bcf1000f00f00f01c2b208bf1109b1fa81f0400910ea141f7ff474af05983318d80904283ff66eaf58081ef80020795c02f00f0602f0f0020a43db0708bf46ea01120ef800205de7ddf8548007e000bf18980436b04208f102083ff471af18f8011c0023c9b2102938bf012313ea141f09eb060c16d14feadc13042b12d84fea5c0309091ef80320795c02f00f0b02f0f0020a431aaf5feac97008bf4bea01120ef8032018f8010c00f00f01b1fa81f0400910ea141f15d10cf10103d809042810d858081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003098f80000c1b210294ff0000038bf012010ea141f15d10cf10203d809042810d8080959081ef80120385c02f00f0302f0f002169d0243002d08bf43ea00120ef8012098f8000000f00f01b1fa81f0400910ea141f8ad10cf10303d80904283ff685af58081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003072e700bf109809eb00011498b1f5207f06eb000229eae970a8bf4ff42071b2f5f07fa8bf4ff4f072ddf810a081427ff70fae26eae6739a427ff70aaedaf800700f2f3ff605ae019dd21a091a05ebc70625f83700781c7380b180f280caf80000f6e59df87c009df87d10079a40ea012001e64ff0ff300df2944dbde8f08f00200df2944dbde8f08f2de9f04f83b04ef66c654ff29c564ff6005948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b029002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0ae804ff44070fbf7f0fc002800f0d88049464218403182f8004382f8014382f8024382f8034382f8044382f8054382f8064382f8074382f8084382f8094382f80a4382f80b4382f80c4382f80d4382f80e4382f80f4382f8104382f8114382f8124382f8134382f8144382f8154382f8164382f8174382f8184382f8194382f81a4382f81b4382f81c4382f81d4382f81e4382f81f4382f8204382f8214382f8224382f8234382f8244382f8254382f8264382f8274382f8284382f8294382f82a4382f82b4382f82c4382f82d4382f82e4382f82f4382f8304382f8314382f8324382f8334382f8344382f8354382f8364382f8374382f8384382f8394382f83a4382f83b4382f83c4382f83d4382f83e4382f83f437ff47caf056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff448afbff35f8f46e8000121b156e8001f4145f8d03de70446fef73df9002c18bf002805d102990120487103b0bde8f08fc4f8600101254ff4f07084f8645101904ff420704af61f470090c0f2470700200021002200230026b84740b184f864610298c4f86061457103b0bde8f08f0298057103b0bde8f08f0024cde700bf2de9f04f87b0dde91065924643ea0102ddf848b02a43d20722d14fea550800eb510900eb5304abf1010700252846564588bf384600eb0a01304401eb810100eb800009eb811104eb80104246f6f7bef9013f781c05f10105e8d107b0bde8f08f4ff6fc722a4005f0030406926a1e002701920494cde902a005e000bf059f039801375f45e9d0fa435645059788bf0beb020707eb0a0202eb820200eb821cba1902eb8202042d00eb821e4ff00008c0f09c80ddf8049000bf40468b4288bf484600eb010200eb03044fea52001cf800706ff0010088ea000608f1010088bfa8196ff0020686ea080608f1020b88bf05eb060b6ff0030686ea080608f1030a4feac27288bf05eb060a07f00f06002a4fea540208bf3e091ef80270e40707f00f0407f0f007374408bf44ea06170ef80270421854081cf804401844d20704f00f064fea500208bf26091ef80240c00704f00f0004f0f004344408bf40ea06140beb01000ef8024042081cf802200beb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef800200aeb010042081cf802200aeb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef80020069808f104088045a9f104097ff46dafddf808a0109eddf848b0049c002c3ff446af6fea080047468b4288bf2f18781842081f441cf80220c0074fea57091ef8090002f00f0408bf140900f00f0200f0f0002044ff0708bf42ea0410049c0ef80900012c3ff423af08f10102a5eb08098b4288bfa9f102025418670802eb030ae4074fea5a041cf807701ef8042007f00f0002f00f0b02f0f00208bf380902445feaca77ddf808a008bf4bea00120498109eddf848b00ef80420049c02283ff4f6ae08f102008b4288bfa9f10300421854081cf8047000eb030cd2074fea5c021ef8020007f00f0400f00f0800f0f00008bf3c0920445feacc7708bf48ea0410049c0ef80200d2e600bf2de9f04f83b04ef66c664ff29c574ff6005a48f2a358ccf2ff06c2f229074ff6ff74cff6ff7a00254ff0010bc0f24508cde9010103e000bfbff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f0ae804ff44070fbf772fa002800f00b8151464218403182f8005382f8015382f8025382f8035382f8045382f8055382f8065382f8075382f8085382f8095382f80a5382f80b5382f80c5382f80d5382f80e5382f80f5382f8105382f8115382f8125382f8135382f8145382f8155382f8165382f8175382f8185382f8195382f81a5382f81b5382f81c5382f81d5382f81e5382f81f5382f8205382f8215382f8225382f8235382f8245382f8255382f8265382f8275382f8285382f8295382f82a5382f82b5382f82c5382f82d5382f82e5382f82f5382f8305382f8315382f8325382f8335382f8345382f8355382f8365382f8375382f8385382f8395382f83a5382f83b5382f83c5382f83d5382f83e5382f83f537ff47caf066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff448afbff35f8f47e8000121b157e8001f4945f8d03de7019a029b01210172b2b3014631f81c2f9a422cd0c28b9a4229d0028c9a4226d0428c9a4223d0828c9a4220d0c28c9a421dd0028d9a421ad0428d9a4217d0828d9a4214d0c28d9a4211d0028e9a420ed0428e9a420bd0828e9a4208d0c28e9a4205d0028f9a4202d0428f9a4208d10121817603b0bde8f08f417203b0bde8f08f427a72b98288029b9a1a13b2b3f1ff3f05dd92b2022a24bf0122427601e00122027600224272029ac38882809a4284bf029ac28090f83c20029b21f81230511c01f00f0180f83c1003b0bde8f08f00bf2de9f04f89b0129f029003fb07f000294fea400b069300f0d58100200890029807924ff0010a4ff000084ff0000e002400264ff0000c0022009107e04ff0000c03244e4601328a4200f0c181bcf1000f40f0bb8110f80290022cefd0012c15d0ddf81cc0129b002c554640f095805fea191409f00f070596089700f09b80a34580f0a1804ff0010c002499e1ddf81cc0129bb9f1000f00f08980cb45c0f0828008980392069a5546abeb090b00eb001700010596cdf810b0019016e010f80810089e01f0f001314300f8081008f10108a9f101090125904524bf4ff000080ef1010eb9f1000f00f062819e4580f05a810eeb8e00002d0ceb8010dfd0a2eb0801b1eb590f88bf4fea590169b38c0800eb080b1cd000220bf10106a2eb840a6ff0030c00bf06eb0c020cf1040c0aeb0c040434d770177157719771f3d10cf10406dde9062c129b11f0030404d10ce0002611f0030408d0012c0bf8067004d05e44022c777018bfb770a9eb4109b9f1000f88440dd09045aed210f80810019c01f00f012143a9f10109002500f80810a8e74ff000099fe700bf56ea09260ed0b34580f088804ff0010c00244be74ff0000c022447e74ff0000c012401e14ff0010c002400263ee708980392069aabeb040b00eb00170001cdf810b0019015e000bf1af80800089900f0f00008440af8080008f10108013c0125904524bf4ff000080ef1010e002c00f0d2809e4580f0ca800eeb8e00002d0ceb801ae1d0a2eb0800b0eb540f88bf600880b381080aeb08091ed00022ab4609f10106a2eb81016ff0030c00bf06eb0c020cf1040c01eb0c050435d770177157719771f3d10cf10401dde9062c129b5d4610f0030604d10de0002110f0030609d0012e09f8017005d04944022e4f7018bf8f7000bfa4eb400480446cb19045afd21af80800019900f00f000843013c00250af80800aae700bf0024a1e708980392069aabeb060b314600eb00170001cdf810b00190059613e01af80800089e00f0f00030430af8080008f1010801390125904524bf4ff000080ef1010e00295ad09e4553d20eeb8e00002d0ceb801ae3d0a2eb0800b0eb510f88bf480880b384080aeb08091ed00022ab4609f10106a2eb84046ff0030c00bf06eb0c020cf1040c04eb0c050435d770177157719771f3d10cf10406dde9062c129b5d4610f0030404d10de0002610f0030409d0012c09f8067005d04e44022c777018bfb77000bfa1eb4001804479b19045b1d21af80800019c00f00f002043013900250af808000029add107e000bf0021a1e7aa464ff0010c002403e0aa4600244ff0000c0df1080b00999be80508059e3fe60120012106e04ff0010cb4fa84f08cf001014009bbfa8bf252091140084009b0bde8f08f014640f258304df69f22c2f20000c0f248021047b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf2de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f081f0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f5f7fffa06f1210506f1280029460722f5f7f7fa284621460722f5f7f2fa20465146032207f10905f5f7ebfa06f11d0049460422f5f7e5faf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f5f7b9faa81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0b7e50846abe570b50446d0f83c0142f665360d46c0f2440668b949f6e130cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3232000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a8900000000000000000000000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fa5b04ef66c6a4ff29c5516460c46ccf2ff0ac2f229054ff6ff7800274ff00109019006e048f2a351c0f24501bff32f8f8847d5f800b0bff35f8f28680321cff680710140b1f1005fbff35f8f02d10168514543d04ff4417004f050fb002800f036810021421847540431b1f5417f57709770d770f6d1c0f800a080f80a90a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8055e8001f5945aed1bff35f8f00bf45e8000121b155e8001f5945f8d0a3e7a34644ea064100260127c0f8701206e048f2a351c0f24501bff32f8f88472c68bff35f8f28680321cff680710140b1f1005fbff35f8f02d10168514542d04ff4417004f0edfa002800f0d380002100bf421846540431b1f5417f56709670d670f6d1c0f800a08772a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8055e8001fa142afd1bff35f8f45e8000121b155e8001fa142f8d0a5e7d0f8746242f6f767c0f24407002ebff35f8f71d007f19a0230464ff0ff314ff0ff379047002840f0c28047f6df40c0f24f00804700274ff001090397adf8107007e000bf48f2a351c0f24501bff32f8f88472c68bff35f8f28680321cff680710140b1f1005fbff35f8f02d10168514567d04ff4417004f071fa002860d00021421847540431b1f5417f57709770d770f6d1c0f800a080f80a90a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8055e8001fa142b0d1bff35f8f00bf45e8000149b355e8001fa142f8d0a5e704460020b847b0b104f51d7151e8006f4eb9bff35f8f00bf41e8000292b151e8006f002ef8d00021bff32f8fbff35f8f21b1064672e74ff0ff373ce007f5a97188476be70121f1e70020019f42f6f769002f4ff00104c0f2440918bfbbf1000f2dd102ad8046284602f054f903ab38465946012205f0eefc9df8111007462846002918bf4ff0ff3702f0f6f9002c044608d19df8100028b94af21f30c0f247004c308047b8f1000f18bfc8f80c4009f5807130468847384625b0bde8f08f3a7802f07f01a1f1150313f1030f0bd802f07b030b2b07d002f07e02082a03d0032901d00629bdd140b14af21f31c0f247010446884794f8641111b14ff0ff37d6e720460024ade700bf2de9f0474ef66c6a4ff29c5548f2a359ccf2ff0ac2f229054ff6ff7600274ff00108c0f2450902e0bff32f8fc8472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168514535d04ff4417004f084f978b30021421847540431b1f5417f57709770d770f6d1c0f800a080f80a808683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142c6d1bff35f8f00bf45e80001002908bfbde8f08755e8001fa142f5d0b8e70020bde8f08770b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04f9db04ff29c50c2f22900d0f800b0bff35f8f58466ff39600b0f1005f3fd1dbf800004ef66c65ccf2ff05a84237d19bf8640110b3dbf86041fcb140f24030c2f20000d0f8787502a802f020f8002f00f0f18040f20308384621464ff41632cff680784ff6ff760197fff764fc48f2a35900240127c0f245091ce09bf8660170b1dbf8680140b147f64c61c2f207010968401a002801f3cc8700208bf8660140f6a120c0f247001db0bde8f04f0047bff32f8fc8474ff29c50c2f22900d0f800a0bff35f8f0068bff35f8f00ea0801b1f1005f02d10168a94236d04ff4417004f07df8002801f08c87002100bf421844540431b1f5417f54709470d470f6d14ff29c52056087728683c683068446848684c684068546858685c685068646868686c68606874687c2f2290252e8001f5145bdd1bff35f8f00bf42e8000121b152e8001f5145f8d0b2e7817a002941f05887027e0021002a8df814107cd04ff29c5605aac2f22906535c002b00f0b68053185f78002f74d09f78002f73d0df78002f72d01f79002f71d05f79002f70d09f79002f6fd0df79002f6ed01f7a002f6dd05f7a002f6cd09f7a002f6bd0df7a002f6ad01f7b002f69d05f7b002f68d09f7b002f67d0df7b002f66d01f7c002f65d05f7c002f64d09f7c002f63d0df7c002f62d01f7d002f61d05f7d002f60d09f7d002f5fd0df7d002f5ed01f7e002f5dd05f7e002f5cd09f7e002f5bd0df7e002f5ad01f7f002f59d05f7f002f58d09f7f002f57d0db7f002b56d0203160297ff49aaf76e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804701f0e8be4ff29c56c2f2290664e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0cf8300218df873100121427e002a00f0c280002205ab9f5c002f00f0a0809d186f78002f5ed0af78002f5dd0ef78002f5cd02f79002f5bd06f79002f5ad0af79002f59d0ef79002f58d02f7a002f57d06f7a002f56d0af7a002f55d0ef7a002f54d02f7b002f53d06f7b002f52d0af7b002f51d0ef7b002f50d02f7c002f4fd06f7c002f4ed0af7c002f4dd0ef7c002f4cd02f7d002f4bd06f7d002f4ad0af7d002f49d0ef7d002f48d02f7e002f47d06f7e002f46d0af7e002f45d0ef7e002f44d02f7f002f43d06f7f002f42d0af7f002f41d0ef7f002f40d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff053079f5411d013444b275e2a5f700cd049275d2a9f7008d050275c2adf7004d020275b2a1f7140f0f08100228df873200131827e002a00f0be80002105aa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df873100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d80002105aa535c002b00f0858153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0fc805f7a002f00f0fc809f7a002f00f0fc80df7a002f00f0fc801f7b002f00f0fc805f7b002f00f0fc809f7b002f00f0fc80df7b002f00f0fc801f7c002f00f0fc805f7c002f00f0fc809f7c002f00f0fc80df7c002f00f0fc801f7d002f00f0fc805f7d002f00f0fc809f7d002f00f0fc80df7d002f00f0fc801f7e002f00f0fc805f7e002f00f0fc809f7e002f00f0fc80df7e002f00f0fc801f7f002f00f00d815f7f002f00f00b819f7f002f00f00981db7f002b00f00781203160297ff47baf1de14cf67e22caf210127260002940f01981002105aa535c002b00f0dc8053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f68d01f7b002f69d05f7b002f6ad09f7b002f6bd0df7b002f6cd01f7c002f6dd05f7c002f6ed09f7c002f6fd0df7c002f70d01f7d002f71d05f7d002f72d09f7d002f73d0df7d002f74d01f7e002f75d05f7e002f76d09f7e002f77d0df7e002f78d01f7f002f79d05f7f002f7ad09f7f002f7bd0db7f002b7cd0203160297ff49aaface000211171f6e6013173e0023171e003316fe004316de0013184e0053169e0023180e0063165e003317ce0073161e0043178e008315de0053174e0093159e0063170e00a3155e007316ce000225a710fe60b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f08d8000218df87310002105af7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8731002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46f246bef15f0f98bf4ff05f0acaf1000805ad18eb0e0c53d0b2fbf3f40a2b04f1300105f80e104cf6cd41ccf6cc41a3fb011647d31cf1010142d004fb1324f708b4fbf7f905eb0e0209f13001517048f21f51c5f2eb11642ba3fb011635d31cf102012dd009fb17447709b4fbf7f6b3f57a7f06f13001917044f6d351c1f26201a3fb015124d31cf1030524d006fb1747890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea543305ada9d20ce0d6460ae00ef1010e07e00ef1020e04e00ef1030e00e0d64605ad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8731002694ff0000815f80810002900f0c78005eb08035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d008f12008b8f1600f7ff496af4ff060085ee008f101085be008f1020858e008f1030855e008f1040852e008f105084fe008f106084ce008f1070849e008f1080846e008f1090843e008f10a0840e008f10b083de008f10c083ae008f10d0837e008f10e0834e000220a7162e708f10f082ee008f110082be008f1110828e008f1120825e008f1130822e008f114081fe008f115081ce008f1160819e008f1170816e008f1180813e008f1190810e008f11a080de008f11b080ae008f11c0807e008f11d0804e008f11e0801e008f11f0801230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46c646b8f15f0f98bf4ff05f0ecef1000942f2107c05ad19eb080a51d0b2fbf3f40a2b04f1300105f808104cf6cd41ccf6cc41a3fb011647d31af1010140d004fb1324f708b4fbf7f605eb080206f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd006fb17444e09b4fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1644890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114208f1040863454fea573305adabd20ce0f0460ae0f04607e008f1010805e008f1020801e008f1030805ad019f002205f80820a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df87300384602212a4608f0e5f9d4f870c272208df8140078208df8150020204ff0000a1ffa8cf28df816008df817a015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7642f2107503eb83004000b2fbf0f40a2c11d303fb07f0b2fbf0f40a2c0bd303fb06f0b2fbf0f40a2c05d36b43b2fbf3f00928e7d800e00346d146baf15f0f98bf4ff05f09c9f1000842f2107e18eb0a054fd0b2fbf3f005a900f1300401f80a404cf6cd41ccf6cc410a2ba3fb016442d36e1c3ed000fb1320e408b0fbf4f705a901eb0a0248f21f5107f13006c5f2eb115670642ba3fb011630d3a91c29d007fb14007409b0fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb011620d3e91c16d007fb1400b10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0ca4607e00af1010a04e00af1020a01e00af1030addf80490002205ac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a11863205e2a48700cd072205d2a887008d063205c2ac87004d020205b2a087140f0618100208df8730037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df80f1000f137010a2838bf00f13001ccf303508df8101000f137010a2838bf00f13001ccf303408df8111000f137010a2838bf00f1300100208df813001f208df81210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400260df10f05af5d8755b7b1b34211d0af1979788419617079b1b2420ad0b978a17051b1b64505d0f978e17029b10436b445e8d100208df8730042f2941845f29c1405aa48460e21c2f22008c2f2130407f093fe40f24031c2f20001c869a0425dd1886ab0f54d2f59d1c86aa04256d145f610630020c2f213034cf6394708f1040c002563454ad81c6834f003061cd098454ff0ff3228bf0c2c42d3a8eb03018e424ff0ff313ed82946ae4288bf3146e2071cbf0d4630449919013f01f10403e0d12ce0002048719ee60421b5f5807f1ed300222f46b7f5007f14d3b7f5806f13d3b7f5006f12d30901b2eb173f4fea1717f0d10ce000219171fef772bf00211172fef730bc490002e0890000e0c900634504d1494205ea0102014603e04ff0ff324ff0ff3147f64c60c2f20700d0f8840008f1080342f6941c9842c2f2270c4dd142f610644ff00009c2f2200446f6b9760cf1040a00254ff0ff3e4ff0ff3854453cd8276837f0030015d0a44528bf0c2f36d3aceb0403984234d8a8422b4688bf0346ff071cbf1d4681442044013e00f10404e4d122e00426b5f5807f17d34ff0000e2846b0f5007f0cd3b0f5806f0bd3b0f5006f0ad33601beeb103f4fea1010f0d104e0760002e0b60000e0f600544504d1704205ea000ec84603e04ff0ff3e4ff0ff3840f24037c2f200073b680cf1080083423ad1fb68b3f5333f36d13b69f246834233d14ff29c5043f21063c2f229004ff00009c2f2270342f6f936a0f1040ca0f1080e0027634520d81c6834f0030500f01e829e454ff0ff30009028bf0c2c17d3aeeb030085424ff0ff3011d83846bd4288bf2846e4071cbf0746a9445819013e00f10403ded100e0f2464ff0ff300090064666208df8140072208df8150065208df816008df817002f208df818006d204b238df8190061208df81d3069238df81a0078208df81e30422356278df81b0020208df81f303a238df82370472705ac8df81c008df820308df821004c238df824708df82600002720468df822308df825308df8277007f0c3fe019de05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f00e8100208df8730020464146524607f0eefd0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a713ed100208df8730005ac009a2046314607f021fd28461a21224607f09efb00208bf86401cbf8600101984ef2173105904ff41630069005a8c0f24701884701208bf8660102a800f0e2f8cbf810001db0bde8f08f0426b7f5807f1cd300253c46b4f5007f12d3b4f5806f11d3b4f5006f10d33601b5eb143f4fea1414f0d10ae00020c871c0e700214172f1e6760002e0b60000e0f60063457ff4daad734207ea030000904846d6e500bf2de9f04f81b0009041f204094cf65560cef20009ccf2ac50c9f8ac0f4ef6fc50cef2000001684ef66c6641f08071016059f8040c4ff29c5748f2a35bccf2ff06c2f229074ff6ff7440f0010000254ff0010ac0f2450b49f8040c02e0bff32f8fd847d7f80080bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14230d04ff4417002f063f8002862d00021421845540431b1f5417f55709570d570f6d1066080f80aa08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4145c5d1bff35f8f47e8000121b157e8001f4145f8d0bbe74169a9bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4219d0d9f80030176800bf1168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94203d0d9f80010c91a4161d9f800000099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c560968d0f800a048f2a358ccf2ff07c2f229064ff6ff7400254ff0010bc0f24508009103e000bfbff32f8fc047d6f80090bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94232d04ff4417001f0c1ff002800f08680002100bf421845540431b1f5417f55709570d570f6d1076080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448756e8001f4945c3d1bff35f8f46e8000121b156e8001f4945f8d0b9e74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094be047f64c6245f6e466c2f20702cff6f876136841f2040c3146cef2000c17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422ad0dcf80030176800bf1168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94214d0dcf8001044f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a5eb0a01b1fbf0f001b0bde8f08f00bf002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204606f0fdff854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0b180207887f00301084200f0ad80012039464246334600f076f90446002898f8080018bf0624a0e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f083804ef66c684ff29c5748f2a35b0294ccf2ff08c2f229074ff6ff7400264ff0010ac0f2450b02e0bff32f8fd847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168414533d04ff4417001f092fe002855d0002100bf421846540431b1f5417f56709670d670f6d1c0f8008080f80aa08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945c3d1bff35f8f00bf47e8000121b157e8001f4945f8d0b8e705eb450100eb011090f85d1201b300f513760024304629462a460323009407f00ff8706840b14bf69b71c0f25d018847706806f07ffe74603068b475002818bf06f078fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f0e8f8002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104606f0fcfe201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009506f0a2ff606840b14bf69b71c0f25d018847606806f012fe65602068a575002818bf06f00bfe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c6b4ff29c5648f2a35a8046ccf2ff0bc2f229064ff6ff7700244ff00109c0f2450a02e0bff32f8fd0473568bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168594532d04ff4417001f09efd60b30021421844540431b1f5417f54709470d470f6d1c0f800b080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa942c6d1bff35f8f00bf46e8000129b156e8001fa942f8d0bbe7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fdf7fbf8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c6b4ff29c5648f2a35a8846ccf2ff0bc2f229064ff6ff7700254ff00109c0f2450a09930792089003e000bfbff32f8fd0473468bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168594533d04ff4417001f012fd002800f0d1830021421845540431b1f5417f55709570d570f6d1c0f800b080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa142c4d1bff35f8f00bf46e8000121b156e8001fa142f8d0b9e70999089d01eb410100eb011095f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bf06f002fd2fe3207cf8b1607ce8b10799099a002520460323009506f07bfe606840b14bf69b71c0f25d018847606806f0ebfc65602068a575002818bf06f0e4fc089d00202060a06020822068002818bf06f0dafc00204ff480712060a0602182a978a081092004f11107e174a17426756076a07ca978884240f0da82217db14240f0d682411ca8f10b00627e02971e2828bf1e209042a17488bf6076a8f1020086b200270a2e4ff00008c0f0e682092241f22109092003961ae000bf20684f46002818bf06f0a0fca089276001302774a760a081002d18bf4ff00608089dd146ddf814a00aeb0b0082b2b24280f0c582217c80b20429824600f28880aa5c00f1010a4b1c0129237405dd022906d0032970d1e28106e021b9627503e0238943ea02222281b24580f0a88204296ed015f80a204ff0000c831c8f1c0129277406ddff290bd0032967460dd19a4652e000291cbf278947ea0222228100e062756746b34204d389e2e281b34280f08682022936d8ea5c00f1030acb1c0129237407dd022937d0fe2907d16275b2450cd374e231b9238943ea02222281b24504d36ce2e281b24580f0698202292fd015f80a20031d41f00407fc29277408ddfd2909d0fe291cbf278947ea0222228103e079b9e28100e062756746b34280f04e8209b19a4613e0ea5c00f1050a0520207401e09a466746e189208941ea0221e18128b106f00cfc0028206000f0688223896089191a1ffa81fb1ffa8af1721a5a45b8bf93465fea0b4208d02268294410441ffa8bf2fcf75dff60892389584481b2994260817ff44faf0026cdf81080d4f800808df82b60607db8f1000f06930df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d018847606806f0b6fb6760607e20760120e082cdf814a09eb1607da67d400714d4002e4ff0000500f0888106984ff6ff7381b2002900f00d8101295ed10020d2e0607d400753d4002577e14ff4803006f09bfb002e804600f06f81a07d002800f06b81b8f1000f00f067816668002e00f0ff8020890428c0f05f8121680a1812f8043c002b40f0588112f8033c002b40f0538112f8023cff2b40f04e8112f8012cff2a40f049814ff4803531607060c6f80c8035610028019000f065814bf69b70c0f25d0000f58572304600219047002840f032813169002900f02e8170688d420d46e7d1019a0d468242e3d124e14ff4803006f049fb05461fe1069a4ff6fe701040ac4642426ff0010000bf08eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1023000276546069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd14046fcf7d2fe00286ad141f2210a4ff00009012375e0382006f089fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377046f6fd00c0f200007844306246f60510c0f20000784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04738b3304606f01efa4546606841f2210a40b14bf69b71c0f25d018847606806f011fa67604ff000090323a77506980799099adde9036887b22046009706f088fb002d294605463ff457ad084606f0faf952e5666075e6c5f58030b5f5803f454606903760f7607ff648aecee70799099a002520460323009506f06afb606840b14bf69b71c0f25d018847606806f0daf965602068a575002818bf06f0d3f90020387000202060a06020824ff00a0840460bb0bde8f08f287a4006f8d5207c08b302980078e0b10799099a002520460323009506f03dfb606840b14bf69b71c0f25d018847606806f0adf965602068a575002818bf06f0a6f900202060a06020824ff00b082068002818bf06f09bf900202060a0602082cae702980078e0b10799099a002520460323009506f011fb606840b14bf69b71c0f25d018847606806f081f965602068a575002818bf06f07af900202060a06020824ff00608a7e700bf2de9f041f02846d100294ff00b0000f08880022ac0f0858045f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a0072d07578e91ec9b2fe2938bfbde8f081307833463946022829d0012866d1ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7d5fa20b306462846fff72cfb21462a46fff700fb3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac4219d1a1f1210010f1160f06d36ff0480048432330c0b2242810d90b20bde8f081b07a204207d04046394622462b46bde8f041fff788bb0020bde8f0811a4612f8020f40f00207032f18d19b796340032b14d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22fcf7bffa04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522fcf77bfa0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522fcf725fa4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2cd110684ef66c61ccf2ff01884225d1d2f8680110b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f8000308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff766ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c684ff29c5648f2a35a8346ccf2ff08c2f229064ff6ff7700254ff00109c0f2450a02e0bff32f8fd0473468bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168414533d04ff4417000f05afd00285bd0002100bf421845540431b1f5417f55709570d570f6d1c0f8008080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa142c4d1bff35f8f00bf46e8000121b156e8001fa142f8d0b9e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31bbf1000f18bf4ff0010bc0f2470c012010210a2387f85db101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff75efe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff6f540cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023a6e745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04568002d00f03e828368002b00f03a8205eb03080024002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310aeb0b03002443451d464ff0000680f02082a94619f9013b03f07f07a740002b46ea070610d406f00703012b16dc0bb3012b40f00e82a8eb0903082bc0f0098205f10903dee700bfc14580f00282182c04f107044d46dcd9fbe100bf022b3ad0052b40f0f681a8eb0903042bc0f0f1816b1dc7e7c14580f0ec8195f90130002b05f10203bed5434580f0e38195f90230b3f1ff3f05f10303b4dc434580f0d98195f90330b3f1ff3f05f10403aadc434580f0cf8195f90430b3f1ff3f05f10503a0dc434580f0c58195f90530002b00f1c081ab1d96e7c14580f0bb8195f9013005f1020a002b03f07f0b3dd5c24580f0b08195f90270eb1c07f07f04b7f1ff3f4beac41b02ddd1469a462de0434580f0a08195f9037005f1040a07f07f04b7f1ff3f4bea843b01dd99461de0c24580f0908195f9043005f1050c03f07f07b3f1ff3f4bea475b02ddd146e2460ce0c44580f07f8195f90530002b00f17a8105f1060a4bea037be146a8eb0a039b4500f27081f308672b19d0652b7ff441afbbf1060ffff43daf9af80030462b7ff438af99f80230432b7ff433af99f80330012b7ff42eaf0290cde9002115e0054650460e465946144600f081fb3146224628461ee748f2a3513046c0f24501bff32f8f8847dde9002102984ff29c53c2f229031c68bff35f8f1e68bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4240d04ff4417000f0fdfadde9002106460298002e3ff4f2ae00230025f718f5540433b3f5417f7d70bd70fd70f6d14ef66c63ccf2ff0333600123b3724ff6ff734ff29c57b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290757e8003fa342a6d1bff35f8f47e800632bb157e8003fa342f8d09ce7002599f8043099f8057099f80640032b47ea042734dd052b52dc042b6fd0052b7ff4aaaed6f868313bb147f64c67c2f207073f68db1b002b15dcd6f86c31002786f86671c6f86c71c6f800735bb10c4648f2a35181461846c0f245011546884721462a46484647f64c63c2f207031b6845f69077c0f201073b44c6f868317be6012b3ff46dae022b7bd0032b7ff474ae14468946fff706fc0346029849462246002b3ff469ae96f84231002b3ff464ae304641f28831a6f8407105f0edfc43e0062b45d0072b7ff457ae81464df6db50c0f24a0016460d46804703465f1e294632464846012f3ff647ae981eb0fa80f04009fff7bffc2946324648463ce614468946fff7cffb0346029849462246002b3ff432ae96f84231002b3ff42daeb6f84031bb427ff428aed6f83c310027002b86f84271a6f840713ff41eae42f68d411846c0f24401884702984946224613e6d6f86c31c6f86851002b86f86651c6f86c51c6f800533ff407ae0c4648f2a35105461846c0f245011646884721463246d9e696f84231c6f83851002b3ff4f4ad0546d6f83c0189461446002186f84211a6f8401120b142f68d41c0f2440188474af273670120002100220023c0f24607b847284622464946d6e54ff2a513c0f2490303b0bde8f04f184700bf7fb50646002806d1fff75efb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817046f29461c0f20001033079440b22fbf752fd0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522fbf71afd0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522fbf76bfc1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246fbf7c1fb4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b004297bd30c46014600784d2876d14878432873d18878012870d14ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010a894607e048f2a351c0f24501bff32f8f88474946d7f800b0bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424534d04ff44170fff76bff002843d04946002200bf831885540432b2f5417f5d709d70dd70f6d1c0f8008080f80aa08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f5a45bdd1bff35f8f00bf47e8000222b157e8002f5a45f8d0b2e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204649460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff69932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6f140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff3584e0cde901100120cff680704ef66c6b4ff29c5648f2a359ccf2ff0bc2f229064ff6ff77851c00244ff00108c0f2450902e0bff32f8fc847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168594533d04ff44170fff7c4fb0028ccd0002100bf421844540431b1f5417f54709470d470f6d1c0f800b080f80a808783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145c4d1bff35f8f00bf46e8000121b156e8001f5145f8d0b9e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff48daf00210025fff7e6fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff762fe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff798fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff69922cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7befd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef752fc014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef732fc0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef71ffc204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd45f21a70c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef76ffb0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22faf74dfd4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf797bf00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf755fec8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e52de9f04f9fb0804600284ff0ff302bd00e4649b398f8001001f07f070f2f15dc092f73dc052f00f0e581072f40f0ce824ef66c694ff29c57ccf2ff09c2f229074ff6ff7500244ff0010a17e0142f00f3fe80102f00f03282112f40f0b782022e08bf112900f0be831fb0bde8f08f48f2a351c0f24501bff32f8f8847d7f800b0bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168494500f030854ff44170fef7b4fc002800f028850021421844540431b1f5417f54709470d470f6d1c0f8009080f80aa08583c583058445848584c584058545858585c585058645868586c5860587458757e8001f5945bdd1bff35f8f00bf47e80001002900f0ff8457e8001f5945f6d0b0e70a2f00f0dc810b2f40f05a824ff29c56c2f229063468bff35f8f20466ff39600b0f1005f41f0d68220684ef66c67ccf2ff07b8424ff0000090d1c4f8680184f8660184f86401d4f86c11c4f8600184f86501c4f86c01c4f8000329b148f2a352c0f2450208469047d4f87802002818bf03f080fc0021c4f87812206c40f2030942f68d48cff68079c0f24408a4f8441040b1c047206c08f166018847002804bf002020644bf63940c0f2510080473568bff35f8f05ea0900b0f1005f2bd12868b84228d195f877014ff0000ac5f880a188b149f25962c0f25902002044f2436185f877a190474ef6e37bc0f25a0bd8470bf1bc008047d5f8840185f870a150b1c047d5f8840108f166018847002804bf0020c5f884013068bff35f8f00ea0901b1f1005f41f096810168b94241f0928190f8a811002901f08781fef7d7fe01f089b9152f00f09c81162f40f0b981701e0228c0f08e8498f8010098f8021040ea0121b1f5007f4ff0ff303ff6f7ae032202eb410296427ff4f1ae002000298df83c008df83d008df83e008df83f008df840008df841008df842008df843008df844008df845008df846008df847008df848008df849008df84a008df84b008df84c008df84d008df84e008df84f008df850008df851008df852008df853008df854008df855008df856008df857008df858008df859008df85a008df85b008df85c008df85d008df85e008df85f008df860008df861008df862008df863008df864008df865008df866008df867008df868008df869008df86a008df86b008df86c008df86d008df86e008df86f008df870008df871008df872008df873008df874008df875008df876008df877008df878008df879008df87a008df87b003ff46dae08f103000fac01224378012b00f2f083077847ea0323db08e65c07f0070702fa07f7374240f0e483e65c013947ea060700f10200e754e7d1fdf7d9fc002800f0d78340f203094ef66c6a4ff29c57cff68079ccf2ff0ac2f229074ff6ff7500264ff0010bd8e34ef66c6b4ff29c55ccf2ff0bc2f229054ff6ff7700244ff0010a022e2cbf98f80100ff200c9006e048f2a351c0f24501bff32f8f8847d5f80090bff35f8f28680321cff680710140b1f1005fbff35f8f03d10168594500f01c814ff44170fef7ddfa0021002800f0e58200bf421844540431b1f5417f54709470d470f6d1c0f800b080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478755e8001f4945bcd1bff35f8f00bf45e80001002900f0ea8055e8001f4945f6d0afe7404631461fb0bde8f04ffef7a9be022efff4ccad4ef66c6a4ff29c55ccf2ff0ac2f229054ff6ff7700244ff0010906e048f2a351c0f24501bff32f8f8847d5f800b0bff35f8f28680321cff680710140b1f1005fbff35f8f03d10168514500f043814ff44170fef775fa002800f02983002100bf421844540431b1f5417f54709470d470f6d1c0f800a080f80a908783c783078447848784c784078547858785c785078647868786c7860787478755e8001f5945bcd1bff35f8f00bf45e80001002900f0118155e8001f5945f6d0afe7721e022afff46aad98f8010098f8021040ea0120b0f5007f0c9000f2ea824ef66c694ff29c5708f10100ccf2ff09c2f229074ff6ff744ff0000a06920b9089e00f2f9b4600f0d480a7f11300012840f2cf80092f00f06681082f40f0df81002a4ff0ff303ff43aad022efff437ad98f801a0baf1000f00f0c48202274ff00109ba1cb24200f2b58208eb070018f80710407851ea002100f0ac828f18b74200f2a88218f802005b4600f07f05153dedb2fd2d16d8c0b20f280dd9a0f183050c2d4ff0ff303ff60aad09fa05f541f24904254206d102e509fa00f548f248242542ebd008eb02000022fff7c4fc002840f08082baf1010ac3d183e290f844100c9d61b1016c39b142f68d42c0f244020446084690472046002180f844100121002d40f0c181032ec0f0be8198f80200082801f210804bf63941c0f251019631884701f008b848f2a3512846c0f24501bff32f8f8847d7f800b0bff35f8f3d680320cff680702840b0f1005fbff35f8f03d12868484500f064834ff44170fef782f9002800f05c830546002000bf291805f800a00430b0f5417f81f801a081f802a081f803a0f2d10120c5f80090a872ac83ec832c846c84ac84ec842c856c85ac85ec852c866c86ac86ec862c876c8757e8000f5845b6d1bff35f8f00bf47e80050002800f02d8357e8000f5845f6d0a9e7144601f02df8002800f0fb8108f10101142fa6f1010200f0ed81132f5b4640f0ed8101f0f3f8ebe198f80140002c6cd0022c00f2e68140f06c87062ec0f0e18198f8021098f8032098f8043098f8057041ea022143ea072232290f91109280f05287322100f054bf98f80100002840f0c88145f64d50c0f24600804701284ff000007ff433accde9100040f20830c0f210000f90ff208df8380044f25220c0f201000d9040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8372008d80721b0f5807f38bf03218df837108df8380040f2d260adf8400005200fac8df84200e01d0da90522f9f77dfc4ff22507c0f247070120092122460c23b8471fb0bde8f08f002480f8434145f64d50c0f2460080470146204601297ff4e4ab43f2a310c0f256001fb0bde8f04f004708064ff0210158bf11218e42c0f05f81002808f101070ad545f64d50c0f24600144680472246022818bf08f111073879797950ea01244ff0ff301ebfb979fb7951ea03263ff4b8ab397b7b7b41ea03218c427ff4b1abb97bfb7b41ea03218e427ff4aaab3878797840ea012804eb0800b0f5207f4ff0ff303ff69eabb978fb7841ea032a06eb0a01b1f5f07f3ff694ab397a7b7a41ea032904eb0901b1f5207f3ff68aabb97afb7a41ea0327f119b1f5f07f3ff681ab154600f038ff002800f00681414652464b46cde90146009702f059fcdbf800100f2909d80bebc1020131a2f80690178154819681cbf80010002d40f0f58000f09cbef81e18bf0120bb1f18bf012318424ff0ff307ff455ab032efff452ab032f00f09a81062f7ff44cab00200021144602f099fd00f0fffe002800f0cd80024608f10100711e4ff4f0774ff4a073009702f04ffe002800f0bf80dbf800100f2900f2bf800bebc1020023d38013814ff4207353814ff4f07301319381cbf80010afe00c9d0020002d3ff43fae012d1dd1052e1bd398f80230581e06284ff000003ff60fab98f8031003293ff60aab98f80420002a3ff405ab4bf63940c0f2510000f59a771846b84700f037be022d06d14bf63940c0f25100804700f02ebe032d40f0d080072ec0f0cd8098f8020098f8032098f8041040ea022098f8055098f8066001284ff0010498bf204644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0008645ea0621012988bf0c4642f68d41c0f24401a1f140022146904700f0f1bd0020022e2cbf98f80110ff21002800f0e885024602294ff0000026d0012920d000297ff4a2aa4cf67e21caf21011907610837960108150609583d583158455849584d584158555859585d585158655869586d5861587558782f83c001fb0bde8f08f0120907200f0bcbd90721fb0bde8f08f5b4601f047fa01e001f082fe20b14ff0ff301fb0bde8f08f002c00f0a985584602f0c2fa00f0a4bd48f2a351c0f24501bff32f8f8847d7f80080bff35f8f3868bff35f8f00ea0901b1f1005f02d10168514577d04ff44170fdf722ff0028d6d00021421846540431b1f5417f56709670d670f6d1c0f800a080f80ab08583c583058445848584c584058545858585c585058645868586c5860587458757e8001f4145c1d1bff35f8f47e80001002949d057e8001f4145f7d0b6e72a1f04460020b2fa82f2022e88bf012052091040084001284ff000007ff40faa4cf6cd42f11eccf6cc4298f80260a1fb0212b6eb920f88bf9608374604f14603302e28bf302708f1030107eb870280461846f9f774fa002e84f8447084f8458000f09085206c30b92046f9f7befd0028206400f0938542f68d41c0f24401a1f140020121904700f016bdd0f86c11864600294ff000003ff4d2a94ff400634ff0ff3c05e032681344b3f5802f80f07d84ce18b568b0eb552ff4d1ea08a25c05f00707fa40d2071ebf41f82500c6f808c0f060e7e7080600f13585082efff43aaf07250521012308eb030797f802904ff0ff30b9f1000f3ff4a2a9fc78002c3ff49ea918f803a04fea89030c950b9303eb8a03b3f5207f3ff692a97d78670007eb4503b3f5f07f3ff68aa908eb010018f8011040780a9241ea002081b2012002f0d0fb00f036fd00283ff404af0c9905eb850208eb010c00ebc2104fea4903711a00eb4a026046009702f081fc00283ff4f1aedbf800100f290cd84fea8a020bebc106f2800b9a6b00013133817281b781cbf800100a9900297ff4e4ae00f08bbc00250c9848b1fcf7d4ff0146002d4ff0ff3018bf00293ff442a90c984ff0000ab0fa80f040098df83ca08df83da08df83ea08df83fa08df840a08df841a08df842a08df843a08df844a08df845a08df846a08df847a08df848a08df849a08df84aa08df84ba08df84ca08df84da08df84ea08df84fa08df850a08df851a08df852a08df853a08df854a08df855a08df856a08df857a08df858a08df859a08df85aa08df85ba08df85ca08df85da08df85ea08df85fa08df860a08df861a08df862a08df863a08df864a08df865a08df866a08df867a08df868a08df869a08df86aa08df86ba08df86ca08df86da08df86ea08df86fa08df870a08df871a08df872a08df873a08df874a08df875a08df876a08df877a08df878a08df879a08df87aa08df87ba0cdb1d5f86c21ddf818e0b2b14ff4006304e03f683b44b3f5802f0ed2d718bc680134f6d07c68033424f003040aeb040101f1100aede7ddf818e00c9a4ff0020c002a00f0f480f21e0a2ac0f0f08000230df13c0b09930b9800eb0c0672784ff0ff30012a3ff688a8b378f478377943ea0423747943ea074141ea0469a9f1011313f5803f0791fff477a8317a737a059141ea03210cf10a040894aeeb04074c1ebc42bff469a8b779f679049747ea062eb9eb0e04fff460a8a1423ff65da80a910b98614610f80c404ff0010c44ea0220c2081bf8027004f007040cfa04f43c427ff4d5ad1bf8027044ea07044ff6ff77c0f203070bf802406db3d5f86cb1bbf1000f28d04fea062c1e024ff400620beb02039c68844240d01b681a44ba421ad80beb02039c68844237d01b681a44ba4211d80beb02039c6884422ed01b681a44ba4208d80beb02039c68844225d01b681a44ba42dbd9bef1000f7ff498ad0798fa1e03301040504400f1100a0df13c0b0a990898099b01eb000c0c98013383424ff0000028bf0120ddf818e04fd2aeeb0c02092a3ff65eaf49e058680df13c0b48457ff474add8687045fff470addfd90a9aa0eb0e0082423ff669ad002ad7d0059806eb000bcbf1000007900498abf101090ceb000208eb010c0a9903eb020e00230eeb03020ceb0306107cf47aa0427ff44dad994517d0547c377bbc427ff446ad0798c418a71c0ed0977c707b87427ff43dade01c07d0d07cb27b90427ff436ad04339b45dcd10df13c0ba1e700283ff42dadbceb0e004ff0000118bf0120baf57e3f88bf012101430c980028c1f100003ef491af00297ef48eafd5f86c91b9f1000f40f08b804ff48020fdf758fc00283ff40cad814600206ff02001002209eb020309f80200403209eb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff47e30c5f86c91c9f800080020c9f804084ff0ff31c9f80c084ff40060c9f80818c5f800034ff6ff740222c0f203044ff0000a09e00c980af1010a06eb080282454ff000003ef4ebae0b9800eb0206b178f379805c7778069196f8038096f804e096f805c0b1790893337a767a40ea072009960a900793bdb3012f35d84ff4006709eb070bdbf808000a9eb04200f0ae80dbf800000744a74226d809eb070bdbf808000a9eb04200f0a180dbf800000744a74219d809eb070bdbf808000a9eb04200f09480dbf800000744a7420cd809eb070bdbf808000a9eb04200f08780dbf800000744a742cbd903a880e806040698d5f800a340ea082040ea0e4040ea0c67f81c20f00300099e00f1100800200697baf1000f26d009eb0a0359f80a105a68414580f0a180eab109eb020059f80210d0f804a0414580f09280baf1000f11d009eb0a0359f80a105a68414580f08c8042b109eb020059f80210d0f804a04145d6d37ce0b34600204ff4006a4ff4006603e03e44b6f5802f23d209eb06018a6859f806700132f4d04868ca68033020f0030000f1100409eb0a001032f8f70bff49f80a404168c2688368d5f86c918a424ff00001a24408bf00f1100149f82310d7e7caf580210f294ff00002c5f8002311d909eb0a0049f80a104ff0ff3142608160c260c5f800a35e460be0dbf80c00dde9083664e05e4610b10268114401604ff0000a0020baf1000f00f0488109eb0a0359f80a105a68414525d2002a00f03e8109eb020059f80210d0f804a0414515d2baf1000f00f0328109eb0a0359f80a105a6841450fd2002a00f0288109eb020059f80210d0f804a04145d3d3834657469246184601e09b461746a1eb080110290ed30aeb080209eb020349f802104ff0ff315f60996000211746d960cbf800800df10c0a9ae80604089b00280cbfc5f80073476006984ff6ff74cbf804000a98c0f20304cbf808000020cbf80c0041ea0321079b814243ea062602f10a087ff4b0ae0bf1100778180b9932464144f8f71dfedbf80c10dbf804003144cbf80c10dbf80820d5f86c9181424ff0000018bf074649f8227094e690f8a911002918bffdf74cfd94f84301002684f8436158b145f64d50c0f246008047012804d143f2a310c0f256008047d4f83c0194f84251c4f8386184f84261a4f8406150b1c047d4f83c0108f166018847002804bf0020c4f83c010120002da07200f093804af27367c0f246070021002200230024b84720461fb0bde8f08f4ff0000c7246cef800c34ff400634ff0000e0de0bef1000fc7f804c00cbfc2f80033cef804303344b3f5802fbe466dd2cf18b868ce58013001d07746f3e7f418bceb944fe6d1081985680135e2d105682e443e6000680444bceb944f02bf0819856815f10105d5d105682e443e6000680444bceb944f02bf0819856815f10105c8d105682e443e6000680444bceb944f02bf0819856815f10105bbd105682e443e6000680444b4f5802fccd3b2e7b1f5fa6f02d94ff4fa610f910121054680f8431145f64d50c0f24600804701281dd143f2a316c0f25606a6f188008047022c08bf002801d058b910e04bf211020fa9c0f24b020220904740b10446b0472046002185f843111fb0bde8f08f00201fb0bde8f08f00204ff400684ff4006703e03744b7f5802f23d209eb07018a6859f807600132f4d04868ca68033020f0030000f1100409eb08001032f8f76ffd49f808404168c2688368d5f86c918a424ff00001a04408bf00f1100149f82310d7e7c8f5802200210f2ac5f8001331d909eb08034ff0ff3049f8082059609860d960c5f800831fb0bde8f08f0c2efff405aa98f8030098f8071088427ff4fea998f8040098f8081088427ff4f7a945f64d50c0f24600144680470523022808bf01230b2509212246fff7b1ba40461fb0bde8f08f00283ff4e1a9016811440160fff7dcb94bf6394025460024c0f2510085f844408047f8e600bf2de9f0474ef66c6a4ff29c5548f2a359ccf2ff0ac2f229054ff6ff7600274ff00108c0f2450902e0bff32f8fc8472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168514533d04ff44170fdf7f0f8002800f0a6800021421847540431b1f5417f57709770d770f6d1c0f800a080f80a808683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142c4d1bff35f8f00bf45e8000121b155e8001fa142f8d0b9e70446d0f87802002818bfbde8f0874ff4163002f0f7f800284ff0000169d00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f87802bde8f0870020bde8f087072a1cbf4ff0ff3070472de9f04f8db01c4688460890fcf7edf9002800f0828007944ef66c674ff29c5448f2a35accf2ff07c2f229044ff6ff7500264ff00109c0f2450a03e000bfbff32f8fd047d4f800b0bff35f8f2068bff35f8f01466ff39601b1f1005f02d10168b94230d04ff44170fdf709f8002854d00021421846540431b1f5417f56709670d670f6d1076080f80a908583c583058445848584c584058545858585c585058645868586c5860587458754e8001f5945c5d1bff35f8f44e8000121b154e8001f5945f8d0bbe7d0f86c214ff0ff3032b398f80110012922d898f8000040ea012752f82700c8b1811a88074ff0ff3016d16ff4802340f60f060b44cff6fc76b3420dd3531853f8080cb84206d153f80c2ca2f1011010f5803f04d24ff0ff300db0bde8f08f002b4ff0ff30f8d053f8047c9742f4d1c1f580218a42f0d8022aeed319780029ebd093f801e0bef1000fe6d00efb01f003f1020b4ff0000cf8b1951e00229542d9d00beb02073b781b0901d001270ee0ae1a012ecfd07b780bb1022707e0042ec9d3bb78ff7853ea0723c4d004279842c1d3c01a3a44e2d100e0002298f8020098f8033098f8047040ea032a98f8063098f8056098060f25cdf804e047ea062e03f00f0705eae07000fb07f589204543ed0a8df824500e2513f0200f08bf4ff00f0c08bf012507fb05f500fb05f54fead5258df825504ff00d0508bf022507fb05f500fb05f54fead5258df826504ff00c0508bf032507fb05f500fb05f54fead5258df827504ff00b0508bf042507fb05f500fb05f54fead5258df828504ff00a0508bf052507fb05f500fb05f54fead5258df829504ff0090508bf062507fb05f500fb05f54fead5258df82a504ff0080508bf072507fb05f500fb05f54fead5258df82b504ff0070508bf082507fb05f500fb05f54fead5258df82c504ff0060508bf092507fb05f500fb05f54fead5258df82d504ff0050508bf0a2507fb05f500fb05f54fead5258df82e504ff0040508bf0b2507fb05f500fb05f54fead5258df82f504ff0030508bf0c2507fb05f500fb05f54fead5258df830504ff0020508bf0d2507fb05f500fb05f54fead5258df831504ff0010508bf0e257d430cfb07f7454378430126ed0ac00a002a8df832508df8330000f0708103f0100086ea1010002402904ff00009cde9032b08e0dde90504039a0444ddf810b0944280f05c811bf8043006941e0901d0012013e0151b012d00f051810beb04077e780eb1022009e0042dc0f04881b878ff7850ea072600f042810420059013f00f0009aa12f800b018bf0120029a4fea0b1842ea000c16f003034f4600f08280b9fbf1f5002005eb0e07b7f1ff3fc8bf012000ea0c0001281ad105fb119000eb0a05e809042813d878090e2810d8089a07eb870002eb80106c08ed07075d6ff00f055a4604bf0f2542463d4015430555012b09f1010755d0b7fbf1f4002004eb0e05b5f1ff3fc8bf012000ea0c0001281ad104fb117000eb0a07f809042813d868090e2810d8089a05eb850002eb80107c08ff07025d6ff00f075d4604bf0f27454617403d430555022b09f1020729d0b7fbf1f5002005eb0e04b4f1ff3fc8bf012000ea0c0001281ad105fb117000eb0a05e809042813d860090e2810d8089a04eb840002eb80106c08ed07025d6ff00f055f4604bf0f25474615403d43055509f10307701eb144089e032804d241e70437b9453ff43eafb7fbf1f4002004eb0e05b5f1ff3fc8bf012000ea0c00012819d104fb117000eb0a04e009042812d868090e280fd805eb850006eb80106508425de4076ff00f045b4604bf0f24434622401a4342557c1cb4fbf1f0002200eb0e05b5f1ff3fc8bf012202ea0c02012a19d100fb114000eb0a04e009042812d868090e280fd805eb850006eb80106208835ce5076ff00f055c4604bf0f2544462b4023438354bc1cb4fbf1f0002200eb0e05b5f1ff3fc8bf012202ea0c02012a19d100fb114000eb0a04e009042812d868090e280fd805eb850006eb80106208835ce5076ff00f055c4604bf0f2544462b4023438354fc1cb4fbf1f0002200eb0e05b5f1ff3fc8bf012202ea0c02012a7ff476af00fb114000eb0a04e00904283ff66eaf68090e283ff66aaf05eb850006eb80106208835ce5076ff00f055c4604bf0f2544462b402343835458e70aeb01000199b0f5207f7144a8bf4ff42070b1f5f07fa8bf4ff4f071079f504588bf714503d800200db0bde8f08f3b680f2bf8d8a0eb0a0007ebc302a1eb0e015081581ca2f806a0a2f808e091813860e9e7082a3cbf4ff0ff3070472de9f04f95b015460c46cde90f30fbf7aefe00287bd0e17901f10800854240f0a380207867780d91a1794ef66c664ff29c5a40ea0720ccf2ff06c2f2290a4ff6ff784ff0000b4ff001090c910e9007e000bf48f2a351c0f24501bff32f8f8847daf80050bff35f8fdaf80000bff35f8f01466ff39601b1f1005f02d10168b1424ad04ff44170fcf7bcfc00286cd0002100bf421800f801b00431b1f5417f82f801b082f802b082f803b0f2d1066080f80a90a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a805ae8001fa942abd1bff35f8f4ae8000149b15ae8001fa942f8d0a1e74ff0ff3015b0bde8f08fd0f86c114ff0ff300029f6d0012ff4d80e9851f82000d8b1431a98074ff0ff30ebd16ff4802240f60f071a44cff6fc77ba42e2d301eb030a5af8080c0e99884206d15af80c2ca2f1011010f5803f04d24ff0ff3015b0bde8f08f5af8040c90424ff0ff30c9d1c3f580218a42c5d8baf1000fc2d0c02ac0d30c9d0f21a80605f00f0701eae070784389235843c00a8df844000e2094f802c0e67894f804e094f805b015f0200f08bf012007fb00f003fb00f04fead0208df845004ff00d0008bf022007fb00f003fb00f04fead0208df846004ff00c0008bf032007fb00f003fb00f04fead0208df847004ff00b0008bf042007fb00f003fb00f04fead0208df848004ff00a0008bf052007fb00f003fb00f04fead0208df849004ff0090008bf062007fb00f003fb00f04fead0208df84a004ff0080008bf072007fb00f003fb00f04fead0208df84b004ff0070008bf082007fb00f003fb00f04fead0208df84c004ff0060008bf092007fb00f003fb00f04fead0208df84d004ff0050008bf0a2007fb00f003fb00f04fead0208df84e004ff0040008bf0b2007fb00f003fb00f04fead0208df84f004ff0030008bf0c2007fb00f003fb00f04fead0208df850004ff0020008bf0d2007fb00f003fb00f04fead0208df851004ff0010008bf0e2007fb00f003fb00f04fead0204ff000018df8520008bf0f21794359430d9b0020c90a002b8df853103ff4f6ae04f108084cea06204eea0b2ea2f1020c00220b9003e00d98013282424bd018f80200411e1f29f6d341b22029fff609af0aeb400010f8401c10f83f0c41ea0027c02f4ff0ff30fff4d1ae67453ff6ceae1af80730002b3ff4c9ae0aeb07014e78002e3ff4c3ae881c06fb03f50023d9198c453ff4e6aec6183478240901d0012612e0aceb010101293ff4dbae74780cb1022609e00429fff4d4aeb178f67851ea06243ff4ceae0426a542fff4caae2d1b3344dcd1afe70f980121063000900c98002600f0100081ea10100790cdf830e0cdf814c0cdf8048018f806001f2804d80b990844a0f10b0228e20aeb400010f8401c10f83f0c41ea0027c02f4ff0ff30fff474ae67453ff671ae1af80720002a3ff46cae0aeb0703597800293ff466ae01fb02f00b9d0028cde9021600f0d1819d1c00240a95e1198c453ff482ae2e1933781b0901d0012615e0aceb010101293ff477ae73780bb102260ce00429fff470aeb178f37851ea03233ff46aae0a9dddf814c004269842fff463aec01a3444d9d1dde90b5e002c00f0a38100270021069406e0dde90807069c0744a74280f098810a980997c35d5fea131902d00120089012e0e01b012800f08b810e460a990f4497f80190b9f1000f00f076810220ddf830e00b9d0890314613f00f0311a810f8038018bf0123079819f0030740ea030b4fea08108c460e9000f09680b1fbf2f6002406fb12132b44b3f1ff3fc8bf012404ea0b04012c1fd116eb0e061cd4dc09042c19d874090e2c16d8109806eb860600eb86105c08065ddb076ff00f0c049008bf4ff00f0c43460e9808bf034606ea0c06049833430355012f01f1010c63d0bcfbf2f4002604fb12c304912b44b3f1ff3fc8bf012606ea0b06012e1dd114eb0e061ad4dc09042c17d874090e2c14d8109806eb860600eb86115c080d5ddb076ff00f0c434608bf4ff00f0c0e9808bf034605ea0c0633430b5504990b9d022f01f1020c30d0bcfbf2f3002603fb12c02844b0f1ff3fc8bf012606ea0b06012e1dd10c995b181ad4c609042e17d85e090e2e14d803eb8306109b444603eb86134608c00713f806c06ff00f0008bf0f2000ea0c000e9908bf0c46204398550499dde90b5e01f1030ca9f10103032b494406d22ee70cf1040c4946e1453ff429afbcfbf2f4002604fb12c389462b44b3f1ff3fc8bf012606ea0b06012e1ed114eb0e041bd4de09042e18d866090e2e15d8109804eb840400eb84145e08a15ddb076ff00f03c64608bf0f230e9808bf8646194041ea0e01ddf830e0a1550cf10101b1fbf2f404fb12114b190021b3f1ff3fc8bf012101ea0b0101291bd114eb0e0418d4d909042915d861090e2912d8109804eb840100eb81115e08db078c5d6ff00f0308bf0f2340460e9f08bf38462340184388550cf10200b0fbf2f404fb120043190020b3f1ff3fc8bf012000ea0b0001281cd114eb0e0419d4d809042816d860090e2813d8109904eb840001eb80105908db07465c6ff00f0308bf0f23444603ea06030e9f08bf3c46234343540cf10300b0fbf2f404fb120043190020b3f1ff3fc8bf012000ea0b0001287ff462af14eb0e043ff55eafd80904283ff65aaf60090e283ff656af109904eb840001eb80105908db07465c6ff00f0308bf0f2344464546ddf8388008bf4446a8460b9d3340234343543de7dde90b5e042807d33146be78ff7856ea072901d004206ee602982a440eeb0003b2f5207f174625eae570a8bf4ff42077b3f5f07fa8bf4ff4f07387421add0c998b4217d90f990e680f2e13d8ddf830e0009da3eb0e013b1a05ebc60725f836000f98ddf80480f980711ca7f802e0bb80016003e0ddf80480ddf830e0039eddf814c00d99013600208e420b927ff4c7ad4fe4062a3cbf4ff0ff3070472de9f04fadf2944d9a46154688460f90fbf76ffa002800f0d68098f80510881d854240f0298447f65420c2f20700d0f800b0bbf1000f00f01f849bf80c009bf80d209bf80e309bf80f7040ea022040ea034040ea0769a9f1810010f1800f4ff0ff30c0f0b2809bf810209bf811309bf8137042ea03229bf8123042ea034242ea07620692813a12f5817f40f29e800029cdf828b000f09d8008f1060b002426aa4ff4e01c00270ae000bf05f1004042f8240001378f4204f1010480f08e801bf80750681e1e28f0d968b21f2801dd012075e0a5f1c2000beb07061d28a1eb07000fd8012800f0c88396f9010010f1410f00f3c28300f03f0365f38a1302201d465de005f0f003e02b24d10328c0f0b48396f9013013f1410f00f3ae8396f9020010f1410f00f3a883e02ddeb202d1a02ec0f0a283ed2d02d19f2e00f29d832b039bb206f03f0643ea861300f03f001d18032034e004284ff0ff3036d3a5f1f50313f1050f31d396f9013013f1410f2cdc96f9020010f1410f00f37e8396f9036016f1410f00f37883f02ddbb202d1902bc0f07283f42d02d18f2b00f26d830cea854e03f03f054eea053300f03f0043ea801006f03f0326aac518042000bf074442f8245076e74ff0ff300df2944dbde8f08f0021012007915ee0002c57d0a4f1010bcdf86090cdf810a000250df1780a5f46914608e026aaab4505f1010509f10409a7f1010739d052f825100029f3d400202b4687421dd009eb80067268b2f1ff3f18dc5a1c934514d0b268b2f1ff3f11dc9a1c93450dd0f268b2f1ff3f0adcda1c934506d032690433002a00f10400e0d400e000220a9853461aae009600f0f6ff002800f008831a980028c3d04af20d315046c0f24e018847bce7ddf810a0ddf828b0ddf860900020079404e00020ddf828b00790012098f804400f21a20604f00f0501eae271694389225143c90a8df8681001260e2198f800c098f801e098f8023098f8037014f0200f08bf0e2608bf012105fb01f102fb01f14fead1218df869104ff00d0108bf022105fb01f102fb01f14fead1218df86a104ff00c0108bf032105fb01f102fb01f14fead1218df86b104ff00b0108bf042105fb01f102fb01f14fead1218df86c104ff00a0108bf052105fb01f102fb01f14fead1218df86d104ff0090108bf062105fb01f102fb01f14fead1218df86e104ff0080108bf072105fb01f102fb01f14fead1218df86f104ff0070108bf082105fb01f102fb01f14fead1218df870104ff0060108bf092105fb01f102fb01f14fead1218df871104ff0050108bf0a2105fb01f102fb01f14fead1218df872104ff0040108bf0b2105fb01f102fb01f14fead1218df873104ff0030108bf0c2105fb01f102fb01f14fead1218df874104ff0020108bf0d2105fb01f102fb01f14fead1218df8751006fb05f102fb01f14fead1218df876104ff0000108bf0f2169435143c90a00284ff000008df877107ff4cdae43ea0720079a484403904cea0e290af10600571e00260df198080190cdf810a0029718e000bf4af20d311ea8c0f24e0188479df87c009df87d10dde90ab9029fdde9072640ea01200df1980801369642814400f0ff8158f82610b1f1ff3f1edd33469f421fd008eb83004268b2f1ff3f1adc0133bb4216d08268b2f1ff3f13dc0133bb420fd0c268b2f1ff3f0cdc0133bb4208d002690133002ae2d404e001f01f000b38d2e7002258461eab19ad009500f0b5fe002800f0c781199900290d9100f0ba819df880209df881309df87e009df87f1052ea03259df8822040ea01279df8833010979df884704fea024208969df8856042ea0362069b4fea074747ea06672b4403eb2743039fcdf82c90a7eb030609eb22491aaf149500f05e810902109b014400f0030809f101004ff0010c099009f102000ceb530305900d980c934b1e0e930b9b0130121415900ceb510003eb020e9a1acde91180a1eb08001890d0074ff0000a17904feace70169013960ae014980af1010a824512981599139e0144159100f029810aeb06014b090e2befd810980028ecd00e9801eb810103280f984ff0000600eb811e80f0848011980028ded0dde90c105feac67c0afb01084fea560018f8000000f00f03c1b208bf0b09b3fa83f0400910ea141f14d106eb0901c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef8002011980128b1d0701c400818f80000bcf1000fc1b24fea111308bf00f00f03d8b2b0fa80f0400910ea141f14d109983118c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef80020119802283ff486afb01c400818f80000bcf1000f00f00f01c2b208bf1109b1fa81f0400910ea141f7ff474af05983318d80904283ff66eaf58081ef80020795c02f00f0602f0f0020a43db0708bf46ea01120ef800205de7ddf8548007e000bf18980436b04208f102083ff471af18f8011c0023c9b2102938bf012313ea141f09eb060c16d14feadc13042b12d84fea5c0309091ef80320795c02f00f0b02f0f0020a431aaf5feac97008bf4bea01120ef8032018f8010c00f00f01b1fa81f0400910ea141f15d10cf10103d809042810d858081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003098f80000c1b210294ff0000038bf012010ea141f15d10cf10203d809042810d8080959081ef80120385c02f00f0302f0f002169d0243002d08bf43ea00120ef8012098f8000000f00f01b1fa81f0400910ea141f8ad10cf10303d80904283ff685af58081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003072e700bf109809eb00011498b1f5207f06eb000229eae970a8bf4ff42071b2f5f07fa8bf4ff4f072ddf810a081427ff70fae26eae6739a427ff70aaedaf800700f2f3ff605ae019dd21a091a05ebc70625f83700781c7380b180f280caf80000f6e59df87c009df87d10079a40ea012001e64ff0ff300df2944dbde8f08f00200df2944dbde8f08f2de9f04f83b04ef66c6b4ff29c5648f2a35a8046ccf2ff0bc2f229064ff6ff7700244ff00109c0f2450a02e0bff32f8fd0473568bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168594533d04ff44170fbf750fc00285cd0002100bf421844540431b1f5417f54709470d470f6d1c0f800b080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa942c4d1bff35f8f00bf46e8000121b156e8001fa942f8d0b9e70446fef703fb002c18bf002805d1012088f8050003b0bde8f08fc4f8600101254ff4f07084f8645101904ff420704af61f470090c0f2470700200021002200230026b84700280fbf88f8045084f86461c4f8606188f8055003b0bde8f08f0024cfe700bf2de9f04f87b0dde91065924643ea0102ddf848b02a43d20722d14fea550800eb510900eb5304abf1010700252846564588bf384600eb0a01304401eb810100eb800009eb811104eb80104246f6f7beff013f781c05f10105e8d107b0bde8f08f4ff6fc722a4005f0030406926a1e002701920494cde902a005e000bf059f039801375f45e9d0fa435645059788bf0beb020707eb0a0202eb820200eb821cba1902eb8202042d00eb821e4ff00008c0f09c80ddf8049000bf40468b4288bf484600eb010200eb03044fea52001cf800706ff0010088ea000608f1010088bfa8196ff0020686ea080608f1020b88bf05eb060b6ff0030686ea080608f1030a4feac27288bf05eb060a07f00f06002a4fea540208bf3e091ef80270e40707f00f0407f0f007374408bf44ea06170ef80270421854081cf804401844d20704f00f064fea500208bf26091ef80240c00704f00f0004f0f004344408bf40ea06140beb01000ef8024042081cf802200beb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef800200aeb010042081cf802200aeb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef80020069808f104088045a9f104097ff46dafddf808a0109eddf848b0049c002c3ff446af6fea080047468b4288bf2f18781842081f441cf80220c0074fea57091ef8090002f00f0408bf140900f00f0200f0f0002044ff0708bf42ea0410049c0ef80900012c3ff423af08f10102a5eb08098b4288bfa9f102025418670802eb030ae4074fea5a041cf807701ef8042007f00f0002f00f0b02f0f00208bf380902445feaca77ddf808a008bf4bea00120498109eddf848b00ef80420049c02283ff4f6ae08f102008b4288bfa9f10300421854081cf8047000eb030cd2074fea5c021ef8020007f00f0400f00f0800f0f00008bf3c0920445feacc7708bf48ea0410049c0ef80200d2e600bf2de9f04f81b04ef66c664ff29c5748f2a35b8146ccf2ff06c2f229074ff6ff7400254ff0010ac0f2450b009103e000bfbff32f8fd847d7f80080bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14232d04ff44170fbf753fa002800f09180002100bf421845540431b1f5417f55709570d570f6d1066080f80aa08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4145c3d1bff35f8f47e8000121b157e8001f4145f8d0b9e70121b9f1000f017237d0014631f81c2f009b9a422cd0c28b9a4229d0028c9a4226d0428c9a4223d0828c9a4220d0c28c9a421dd0028d9a421ad0428d9a4217d0828d9a4214d0c28d9a4211d0028e9a420ed0428e9a420bd0828e9a4208d0c28e9a4205d0028f9a4202d0428f9a4208d10121817601b0bde8f08f417201b0bde8f08f427a72b98288009b9a1a13b2b3f1ff3f05dd92b2022a24bf0122427601e00122027600224272009ac38882809a4284bf009ac28090f83c20009b21f81230511c01f00f0180f83c1001b0bde8f08f2de9f04f89b0129f029003fb07f000294fea400b069300f0d58100200890029807924ff0010a4ff000084ff0000e002400264ff0000c0022009107e04ff0000c03244e4601328a4200f0c181bcf1000f40f0bb8110f80290022cefd0012c15d0ddf81cc0129b002c554640f095805fea191409f00f070596089700f09b80a34580f0a1804ff0010c002499e1ddf81cc0129bb9f1000f00f08980cb45c0f0828008980392069a5546abeb090b00eb001700010596cdf810b0019016e010f80810089e01f0f001314300f8081008f10108a9f101090125904524bf4ff000080ef1010eb9f1000f00f062819e4580f05a810eeb8e00002d0ceb8010dfd0a2eb0801b1eb590f88bf4fea590169b38c0800eb080b1cd000220bf10106a2eb840a6ff0030c00bf06eb0c020cf1040c0aeb0c040434d770177157719771f3d10cf10406dde9062c129b11f0030404d10ce0002611f0030408d0012c0bf8067004d05e44022c777018bfb770a9eb4109b9f1000f88440dd09045aed210f80810019c01f00f012143a9f10109002500f80810a8e74ff000099fe700bf56ea09260ed0b34580f088804ff0010c00244be74ff0000c022447e74ff0000c012401e14ff0010c002400263ee708980392069aabeb040b00eb00170001cdf810b0019015e000bf1af80800089900f0f00008440af8080008f10108013c0125904524bf4ff000080ef1010e002c00f0d2809e4580f0ca800eeb8e00002d0ceb801ae1d0a2eb0800b0eb540f88bf600880b381080aeb08091ed00022ab4609f10106a2eb81016ff0030c00bf06eb0c020cf1040c01eb0c050435d770177157719771f3d10cf10401dde9062c129b5d4610f0030604d10de0002110f0030609d0012e09f8017005d04944022e4f7018bf8f7000bfa4eb400480446cb19045afd21af80800019900f00f000843013c00250af80800aae700bf0024a1e708980392069aabeb060b314600eb00170001cdf810b00190059613e01af80800089e00f0f00030430af8080008f1010801390125904524bf4ff000080ef1010e00295ad09e4553d20eeb8e00002d0ceb801ae3d0a2eb0800b0eb510f88bf480880b384080aeb08091ed00022ab4609f10106a2eb84046ff0030c00bf06eb0c020cf1040c04eb0c050435d770177157719771f3d10cf10406dde9062c129b5d4610f0030404d10de0002610f0030409d0012c09f8067005d04e44022c777018bfb77000bfa1eb4001804479b19045b1d21af80800019c00f00f002043013900250af808000029add107e000bf0021a1e7aa464ff0010c002403e0aa4600244ff0000c0df1080b00999be80508059e3fe60120012106e04ff0010cb4fa84f08cf001014009bbfa8bf252091140084009b0bde8f08f014640f258304df69f22c2f20000c0f248021047b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf2de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f081f0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f6f77ff906f1210506f1280029460722f6f777f9284621460722f6f772f920465146032207f10905f6f76bf906f11d0049460422f6f765f9f07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f6f739f9a81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0b7e50846abe570b50446d0f83c0142f665360d46c0f2440668b949f6a960cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3233000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a8900000000000000000000000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "f0173a00", + "new": "f00a3a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "70183a00", + "new": "700b3a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "f0173a04", + "new": "f00a3a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "ed6be905", + "new": "09a9afac", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "18540264", + "new": "19292813", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "18540264", + "new": "19292813", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/g2/glasses-session.ts b/app/g2/glasses-session.ts index c3dd390f..1a63c70f 100644 --- a/app/g2/glasses-session.ts +++ b/app/g2/glasses-session.ts @@ -496,6 +496,7 @@ export class GlassesSession { this.timer = setTimeout(() => { this.timer = null; void this.pump() }, delay) } private canSendDisplay(): boolean { + if (this.displaySending?.commands[this.displaySending.offset][0] === 22 && this.cfwPending.length) return false // Also bound completed frames retained behind a missing/out-of-order ACK. return this.displayInFlight < DISPLAY_WINDOW_SIZE && !!(this.displaySending || (this.latest && !this.charging && this.displayFrames.length < DISPLAY_WINDOW_SIZE)) @@ -511,11 +512,11 @@ export class GlassesSession { const texturePlan = textureFrame ? this.textures?.plan(this.lastEnqueued, packed, textureFrame, this.nextImageFrameId) : null let commands: Uint8Array[] if (texturePlan) { - // Uploads participate in the same ordered, acknowledged command window as + // Resource commands participate in the same ordered, acknowledged command window as // the image. Coalescing only happens before planning mutates residency. - commands = [...texturePlan.uploads, texturePlan.payload] + commands = [...texturePlan.resourceCommands, texturePlan.payload] this.nextImageFrameId = texturePlan.nextFid - this.log(`Display textures (${texturePlan.uploads.length} uploads, cache=${texturePlan.usedBytes}B)`) + this.log(`Display textures (${texturePlan.resourceCommands.length} resource commands, cache=${texturePlan.usedBytes}B)`) } else { const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId) const payload = delta ?? protocol.concat(new Uint8Array([6]), protocol.rle4(packed)) @@ -528,7 +529,10 @@ export class GlassesSession { this.displaySending = { packed, commands, offset: 0, pending: 0 } this.displayFrames.push(this.displaySending); this.lastEnqueued = packed } - const frame = this.displaySending, payload = frame.commands[frame.offset++] + const frame = this.displaySending + // Drain earlier commands before evicting: recovery may replay any unresolved draw/upload. + if (frame.commands[frame.offset][0] === 22 && this.cfwPending.length) return + const payload = frame.commands[frame.offset++] frame.pending++; this.displayInFlight++ if (frame.offset >= frame.commands.length) this.displaySending = null // Writes serialize on L while up to three complete commands await their @@ -554,7 +558,7 @@ export class GlassesSession { this.pumping = true; const generation = this.generation try { const now = Date.now() - // Firmware frees textures when its 90-second framebuffer lease expires. + // Firmware frees resources when its 90-second framebuffer lease expires. // After a long iOS suspension, reconnect rather than replaying pending // draws against unknown memory. Leave a margin for the two arm writes. if (now - this.lastLease >= 80_000) throw new Error('Display lease lapsed; restarting session') diff --git a/app/g2/texture-planner.ts b/app/g2/texture-planner.ts index b41af272..f8274896 100644 --- a/app/g2/texture-planner.ts +++ b/app/g2/texture-planner.ts @@ -1,6 +1,6 @@ /** Platform-owned snapshot of the same composite as the submitted pixels. */ export type TextureFrame = { readonly native: object } -export type TexturePlan = { uploads: Uint8Array[]; payload: Uint8Array; nextFid: number; usedBytes: number } +export type TexturePlan = { resourceCommands: Uint8Array[]; payload: Uint8Array; nextFid: number; usedBytes: number } /** Sessions own residency; frame snapshots may be coalesced without changing it. */ export interface SessionTexturePlanner { plan(previous: Uint8Array | null, next: Uint8Array, frame: TextureFrame, firstId: number): TexturePlan | null diff --git a/app/native/kotlin-protocol-smoke.ios.ts b/app/native/kotlin-protocol-smoke.ios.ts index d3c41337..65a06c35 100644 --- a/app/native/kotlin-protocol-smoke.ios.ts +++ b/app/native/kotlin-protocol-smoke.ios.ts @@ -40,10 +40,10 @@ export function runKotlinProtocolSmokeTest(): void { textured.submitSurfaceFrame('icon', white, { x: 0, y: 0, width: 2, height: 2 }, draw.buffer) const snapshot = textured.compositeFrame(), packed = protocol.packGray4(snapshot.pixels, 4, 2) const cold = textures.plan(null, packed, snapshot.textures, 1) - assert(!!cold && cold.uploads[0]?.[0] === 18 && cold.payload[0] === 8, 'texture upload and draw') - assert(textures.plan(null, packed, snapshot.textures, 1)?.uploads.length === 0, 'texture reuse') + assert(!!cold && cold.resourceCommands.some(command => command[0] === 21) && cold.payload[0] === 8, 'texture upload and draw') + assert(textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length === 0, 'texture reuse') textures.reset() - assert((textures.plan(null, packed, snapshot.textures, 1)?.uploads.length ?? 0) > 0, 'texture reset') + assert((textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length ?? 0) > 0, 'texture reset') const changed = new Uint8Array(16); changed[0] = 255 assert(buildBoundingBoxPayload(new Uint8Array(16), changed, 8, 4, 1)?.[0] === 3, 'image update') assert(lvglMetrics('/nonexistent/faceclaw-font').length === 0, 'font bridge') diff --git a/app/native/texture-planner.ios.ts b/app/native/texture-planner.ios.ts index aabbc056..7de63cbd 100644 --- a/app/native/texture-planner.ios.ts +++ b/app/native/texture-planner.ios.ts @@ -7,7 +7,7 @@ export class IosTexturePlanner implements SessionTexturePlanner { reset(): void { this.native.reset() } plan(previous: Uint8Array | null, next: Uint8Array, frame: TextureFrame, firstId: number): TexturePlan | null { const result = this.native.planPreviousNextFrameFirstId(previous ? toData(previous) : null, toData(next), frame.native, firstId) - return result ? { payload: fromData(result.payload), uploads: nativeArray(result.uploads, fromData), + return result ? { payload: fromData(result.payload), resourceCommands: nativeArray(result.resourceCommands, fromData), nextFid: result.nextFid, usedBytes: result.usedBytes } : null } } diff --git a/native/kotlin/migrated-java-sources.json b/native/kotlin/migrated-java-sources.json index 2342cdf2..9d676c85 100644 --- a/native/kotlin/migrated-java-sources.json +++ b/native/kotlin/migrated-java-sources.json @@ -161,7 +161,7 @@ }, { "java": "com/faceclaw/app/g2protocol/TextureCacheState.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TextureCacheState.kt" + "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt" }, { "java": "com/faceclaw/app/g2protocol/TexturePlanner.java", diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt index c2fa50a0..0e06f6c8 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt @@ -249,7 +249,7 @@ class BleImageOptimizer { * multiples of 4 (=> left>>1, width>>1 are whole bytes), top/ height multiples of 2. The * box pixels are top-down rows of `next` (4bpp packed, width>>1 bytes/row), run-length * encoded before deflate. Shared by the single-bbox path, each rect of a mode-8 multi-rect - * batch, and the texture-cache planner. + * batch, and the resource-cache planner. */ @JvmStatic fun encodeMode3Rect( diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageWindow.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageWindow.kt index 74868596..c75f3215 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageWindow.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageWindow.kt @@ -10,6 +10,13 @@ class CfwMessageWindow private constructor() { const val ACK_TIMEOUT_MS = 500 const val MAX_RETRIES = 3 + /** ID reuse must not invalidate an earlier command still eligible for replay. */ + @JvmStatic + fun canSend(messages: Iterable, candidate: OutboundMessage): Boolean = + candidate.sid != CfwTransport.SID || + candidate.message.firstOrNull()?.toInt() != ResourceCacheState.EVICT_MODE || + messages.none { it.sid == CfwTransport.SID } + @JvmStatic fun acknowledgedHead(messages: Iterable): OutboundMessage? { for (message in messages) { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ConnectionOptions.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ConnectionOptions.kt index caba97a1..735502aa 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ConnectionOptions.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ConnectionOptions.kt @@ -71,8 +71,8 @@ class ConnectionOptions { // Falls back to the single bounding box whenever multi-rect isn't smaller. @JvmField val MULTI_RECT_FRAMES = true - // Ship text as on-glasses cached-glyph draws (CFW modes 12/14) instead of + // Ship text as on-glasses cached-glyph draws (CFW modes 19/20/21/22) instead of // pixels, punching glyph ink out of the baked deltas (see TexturePlanner). - // Also gated at runtime on the firmware advertising texcache12 + texstr14. + // Also gated at runtime on the firmware advertising Faceclaw/23 or later. @JvmField val TEXTURE_CACHE_FRAMES = true } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt new file mode 100644 index 00000000..59ad80ee --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt @@ -0,0 +1,150 @@ +package com.faceclaw.app + +/** Immutable content-addressed bytes; equality verifies bytes when hashes collide. */ +class CachedResource(bytes: ByteArray) { + val bytes: ByteArray = bytes.copyOf() + val hash: Long = this.bytes.fold(-3750763034362895579L) { hash, byte -> + (hash xor (byte.toLong() and 255)) * 1099511628211L + } + override fun hashCode(): Int = (hash xor (hash ushr 32)).toInt() + override fun equals(other: Any?): Boolean = this === other || + other is CachedResource && hash == other.hash && bytes.contentEquals(other.bytes) +} + +/** + * Phone-side residency for the firmware's compacting resource arena. The owner serializes calls. + * prepare() protects the current frame's hits before admitting misses, evicting only unprotected + * LRU entries. Commands must be sent in returned order, before any dependent draws. + */ +class ResourceCacheState { + companion object { + const val CACHE_SIZE = 262144 + const val RESOURCE_COUNT = 512 + const val TABLE_BYTES = RESOURCE_COUNT * 4 + const val ARENA_BYTES = CACHE_SIZE - TABLE_BYTES + const val MAX_RESOURCE_SIZE = 65536 + const val BLOCK_HEADER_BYTES = 16 + const val UPLOAD_MODE = 21 + const val EVICT_MODE = 22 + fun allocationBytes(size: Int): Int = BLOCK_HEADER_BYTES + ((size + 3) and -4) + } + + private data class Resident(val id: Int, val resource: CachedResource, var lastUsed: Long) + private val residents = LinkedHashMap() + private val occupied = BooleanArray(RESOURCE_COUNT) + private var allocated = 0 + private var clock = 0L + private var resetRequired = true + private val evictions = linkedSetOf() + private val uploads = ArrayList() + + /** Forget uncertain device state. The next upload first evicts every ID on both lenses. */ + fun reset() { + residents.clear(); occupied.fill(false); allocated = 0; clock = 0 + evictions.clear(); uploads.clear(); resetRequired = true + } + + fun usedBytes(): Int = TABLE_BYTES + allocated + fun residentCount(): Int = residents.size + fun resourceId(resource: CachedResource): Int = residents[resource]?.id ?: -1 + + /** Called once per frame after coalescing. -1 entries stay baked into the pixel fallback. */ + fun prepare(resources: List): IntArray { + check(uploads.isEmpty() && evictions.isEmpty()) { "Previous resource commands have not been drained" } + val protected = HashSet() + for (resource in resources) residents[resource]?.let { protected.add(it.id) } + return IntArray(resources.size) { index -> + val resource = resources[index] + val hit = residents[resource] + if (hit != null) { + hit.lastUsed = ++clock + hit.id + } else if (resource.bytes.isEmpty() || resource.bytes.size > MAX_RESOURCE_SIZE) { + -1 + } else { + val needed = allocationBytes(resource.bytes.size) + // Check feasibility before evicting anything for a request that cannot fit. + val available = ARENA_BYTES - allocated + residents.values + .filter { it.id !in protected }.sumOf { allocationBytes(it.resource.bytes.size) } + val canGetId = residents.size < RESOURCE_COUNT || residents.values.any { it.id !in protected } + if (needed > available || !canGetId) -1 + else { + while (allocated + needed > ARENA_BYTES || residents.size >= RESOURCE_COUNT) { + val victim = residents.values.filter { it.id !in protected }.minBy { it.lastUsed } + residents.remove(victim.resource); occupied[victim.id] = false + allocated -= allocationBytes(victim.resource.bytes.size) + evictions.add(victim.id) + } + val id = occupied.indexOfFirst { !it } + val entry = Resident(id, resource, ++clock) + occupied[id] = true; allocated += needed + residents[resource] = entry; uploads.add(entry); protected.add(id) + id + } + } + } + } + + /** A rejected image plan must not commit unsent allocations or LRU changes. */ + fun checkpoint(): () -> Unit { + val oldResidents = residents.mapValues { it.value.copy() } + val oldOccupied = occupied.copyOf() + val oldAllocated = allocated + val oldClock = clock + val oldReset = resetRequired + val oldEvictions = evictions.toList() + val oldUploads = uploads.toList() + return { + residents.clear(); residents.putAll(oldResidents); oldOccupied.copyInto(occupied) + allocated = oldAllocated; clock = oldClock; resetRequired = oldReset + evictions.clear(); evictions.addAll(oldEvictions) + uploads.clear(); uploads.addAll(oldUploads) + } + } + + /** Batched evictions followed by bounded upload chunks, including exactly 64 KiB resources. */ + fun drainCommands(maxPayloadBytes: Int): MutableList { + require(maxPayloadBytes in 14..65535) + val result = ArrayList() + val ids = if (resetRequired && uploads.isNotEmpty()) (0 until RESOURCE_COUNT).toList() else evictions.toList() + for (batch in ids.chunked((maxPayloadBytes - 3) / 2)) { + val out = ByteSink() + out.write(EVICT_MODE); write16(out, batch.size) + batch.forEach { write16(out, it) } + result.add(out.toByteArray()) + } + var entries = ArrayList() + var entryIds = HashSet() + var size = 3 + fun flush() { + if (entries.isEmpty()) return + val out = ByteSink() + out.write(UPLOAD_MODE); write16(out, entries.size) + entries.forEach { out.write(it, 0, it.size) } + result.add(out.toByteArray()) + entries = ArrayList(); entryIds = HashSet(); size = 3 + } + for (entry in uploads) { + val data = entry.resource.bytes + var offset = 0 + while (offset < data.size) { + val count = minOf(data.size - offset, maxPayloadBytes - 13) + val out = ByteSink() + write16(out, entry.id); write32(out, data.size) + write16(out, offset); write16(out, count) + out.write(data, offset, count) + val bytes = out.toByteArray() + if (size + bytes.size > maxPayloadBytes || entry.id in entryIds) flush() + entries.add(bytes); entryIds.add(entry.id); size += bytes.size + offset += count + } + } + flush() + if (uploads.isNotEmpty()) resetRequired = false + evictions.clear(); uploads.clear() + return result + } + + private fun write16(out: ByteSink, value: Int) { out.write(value and 255); out.write((value ushr 8) and 255) } + private fun write32(out: ByteSink, value: Int) { write16(out, value); write16(out, value ushr 16) } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TextureCacheState.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TextureCacheState.kt deleted file mode 100644 index 623ff165..00000000 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TextureCacheState.kt +++ /dev/null @@ -1,191 +0,0 @@ -package com.faceclaw.app - -/** - * Phone-side model of the CFW's flat 256 KiB texture cache (zlib_glue mode 18). The firmware holds - * only bytes; every structural decision — where font tables and glyph images live, what is - * resident, when to start over — is made here. Layout per font: a 96-entry uint32 offset table - * (chars 32..127) whose entries are written lazily as each glyph is uploaded; glyph images are the - * GlyphAtlas cached bytes ([w][h][4bpp RLE]). - * - * Allocation is a bump pointer with reset-on-full: the realistic working set (a few fonts' tables - * plus ~hundreds of glyphs at tens of bytes each) is far below 256 KiB, so eviction sophistication - * buys nothing. After a reset the firmware cache still holds stale bytes; that is safe because a - * draw only ever references (font table entry, glyph image) pairs uploaded in the current - * generation — stale table entries are never named in a mode-20 string. - * - * Upload entries accumulate as complete [offset u32][len u16][data] records and drain into one or - * more standalone mode-18 payloads, each independently valid, enqueued ahead of the image message - * that references them (the transport is FIFO, so no ack round-trip is needed before use). - * - * Not thread-safe by itself: the communicator calls it under its own lock. - */ -class TextureCacheState { - companion object { - const val CACHE_SIZE: Int = 262144 - - private val FONT_TABLE_BYTES: Int = (96 * 4) - } - - private var allocEnd: Int = 0 - - private val fontTableOffsets: MutableMap = HashMap() - - private val glyphOffsets: MutableMap = HashMap() - - private val imageOffsets: MutableMap = HashMap() - - private val pendingEntries: MutableList = ArrayList() - - private var pendingBytes: Int = 0 - - private var generation: Int = 0 - - /** - * Forget everything: the on-glasses cache is gone (session teardown, lease loss) or no longer - * trustworthy (upload timeout), or we ran out of space. Glyphs and images re-upload lazily on - * next use. - */ - fun reset(): Unit { - allocEnd = 0 - fontTableOffsets.clear() - glyphOffsets.clear() - imageOffsets.clear() - pendingEntries.clear() - pendingBytes = 0 - generation++ - } - - /** Bumped by every reset; lets a planner detect a mid-plan reset. */ - fun generation(): Int { - return generation - } - - /** - * Bytes currently allocated out of CACHE_SIZE, for logging/tuning (a sudden drop in the frame - * log means a reset-on-full re-upload cycle — the signal that the 256 KiB budget is being - * outgrown). - */ - fun usedBytes(): Int { - return allocEnd - } - - /** - * The font's 96-entry table offset in the cache, or -1 when it exists but this glyph can't fit. - */ - fun fontTableOffset(fontId: Int): Int { - var existing: Int? = fontTableOffsets.get(fontId) - return (if ((existing == null)) -1 else existing) - } - - /** - * Ensure a glyph image (and its font table slot) is resident, queuing the mode-18 upload - * entries for anything newly placed. Returns the glyph's image offset, or -1 when the cache is - * full (caller resets and retries) or the encoding is outside the mode-20 table (32..127). - */ - fun ensureGlyph(fontId: Int, encoding: Int, glyph: GlyphAtlas.Glyph?): Int { - if ((((glyph == null) || (encoding < 32)) || (encoding > 127))) { - return -1 - } - var key: Long = (((fontId).toLong() shl 32) or (encoding.toLong() and 0xffffffffL)) - var existing: Int? = glyphOffsets.get(key) - if ((existing != null)) { - return existing - } - var table: Int? = fontTableOffsets.get(fontId) - var need: Int = (glyph.cachedBytes.size + (if ((table == null)) FONT_TABLE_BYTES else 0)) - if (((allocEnd + need) > CACHE_SIZE)) { - return -1 - } - if ((table == null)) { - table = allocEnd - allocEnd += FONT_TABLE_BYTES - fontTableOffsets.put(fontId, table) - } - var offset: Int = allocEnd - allocEnd += glyph.cachedBytes.size - glyphOffsets.put(key, offset) - addEntry(offset, glyph.cachedBytes) - addEntry( - (table + (4 * (encoding - 32))), - byteArrayOf( - (offset).toByte(), - ((offset shr 8)).toByte(), - ((offset shr 16)).toByte(), - ((offset shr 24)).toByte(), - ), - ) - return offset - } - - /** - * Ensure an ImageAtlas entry is resident (mode-19 draws reference it by raw cache offset; no - * table involved). Returns the image offset, or -1 when the cache is full (caller resets and - * retries). - */ - fun ensureImage(imageId: Int, image: ImageAtlas.Entry?): Int { - if ((image == null)) { - return -1 - } - var existing: Int? = imageOffsets.get(imageId) - if ((existing != null)) { - return existing - } - if (((allocEnd + image.cachedBytes.size) > CACHE_SIZE)) { - return -1 - } - var offset: Int = allocEnd - allocEnd += image.cachedBytes.size - imageOffsets.put(imageId, offset) - addEntry(offset, image.cachedBytes) - return offset - } - - private fun addEntry(offset: Int, data: ByteArray): Unit { - var entry: ByteArray = ByteArray((6 + data.size)) - entry[0] = ((offset and 0xff)).toByte() - entry[1] = (((offset shr 8) and 0xff)).toByte() - entry[2] = (((offset shr 16) and 0xff)).toByte() - entry[3] = (((offset shr 24) and 0xff)).toByte() - entry[4] = ((data.size and 0xff)).toByte() - entry[5] = (((data.size shr 8) and 0xff)).toByte() - data.copyInto(entry, 6, 0, 0 + data.size) - pendingEntries.add(entry) - pendingBytes += entry.size - } - - fun hasPendingUploads(): Boolean { - return !pendingEntries.isEmpty() - } - - /** Total queued upload bytes (entry framing included), for logging. */ - fun pendingUploadBytes(): Int { - return pendingBytes - } - - /** - * Drain the queued entries into complete mode-18 payloads ([18][entries]), each at most - * maxPayloadBytes so a payload fits one BLE image message without fragmentation. A single entry - * larger than the cap still gets its own payload (the transport can fragment it). - */ - fun drainUploadPayloads(maxPayloadBytes: Int): MutableList { - var payloads: MutableList = ArrayList() - var current: ByteSink? = null - for (entry in pendingEntries) { - if (((current != null) && ((current.size() + entry.size) > maxPayloadBytes))) { - payloads.add(current.toByteArray()) - current = null - } - if ((current == null)) { - current = ByteSink(minOf(maxPayloadBytes, (4 + entry.size))) - current.write(18) - } - current.write(entry, 0, entry.size) - } - if ((current != null)) { - payloads.add(current.toByteArray()) - } - pendingEntries.clear() - pendingBytes = 0 - return payloads - } -} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt index d23383a9..1b6ecc88 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt @@ -6,14 +6,14 @@ import kotlin.jvm.JvmStatic /** * Plans a screen update that ships text and icons as on-glasses cached draws instead of pixels (CFW - * modes 18/19/20; see g2flash/patches/zlib_glue.c and texture_cache.c). + * modes 19/20/21/22; see g2flash/patches/zlib_glue.c and resource_cache.c). * * Approach: dirty rects come from comparing the fully composited old and new frames, exactly as the * plain incremental path does. For each deferred draw (glyph or image) whose pixels intersect a * sent rect, check that every pixel the on-glasses draw would write lands correct — i.e. the new * composite's 4bpp value at each in-panel nonzero-source pixel equals what the draw produces (this * one check subsumes plane occlusion, surface occlusion/clipping, and draw-on-draw overlap). A draw - * that passes and is (or can be made) resident in the texture cache is replayed on-glasses: its + * that passes and is (or can be made) resident in the resource cache is replayed on-glasses: its * written pixels are punched to 0 in the delta rect content — which is what makes text and icons * nearly free to compress — and re-emitted as a mode-20 string or mode-19 image sub-message in the * same atomic mode-8 batch, so the shadow after apply equals the full composite exactly. Everything @@ -40,7 +40,7 @@ class TexturePlanner { /** Cap on mode-15 builtin-font string sub-messages per update. */ private const val MAX_FWTEXT_RUNS: Int = 80 - /** Mode-18 payload size that fits one BLE image message comfortably. */ + /** Resource command payload size that fits one BLE image message comfortably. */ private const val UPLOAD_PAYLOAD_MAX: Int = 3600 /** Max x-adjust control bytes between two glyphs before starting a new run. */ @@ -62,7 +62,7 @@ class TexturePlanner { width: Int, height: Int, draws: Array?, - cache: TextureCacheState, + cache: ResourceCacheState, fidStart: Int, allowMultiRect: Boolean, maxRects: Int, @@ -180,6 +180,7 @@ class TexturePlanner { if ((selected.isEmpty() && fwSubs.isEmpty())) { return null } + val rollback = cache.checkpoint() var cacheStartedAtMs: Long = platform.elapsedRealtimeMs() var drawable: MutableList = (if (selected.isEmpty()) mutableListOf() else ensureResident(cache, selected)) @@ -194,7 +195,7 @@ class TexturePlanner { } } var runs: MutableList = ArrayList() - var drawnGlyphs: MutableList = buildRuns(cache, glyphDrawable, runs) + var drawnGlyphs: MutableList = buildRuns(glyphDrawable, runs) bakedCandidates += (glyphDrawable.size - drawnGlyphs.size) var drawn: MutableList = ArrayList(drawnGlyphs) drawn.addAll(imageDrawable) @@ -203,7 +204,7 @@ class TexturePlanner { ((((rects.size + runs.size) + imageDrawable.size) + fwSubs.size) > 255)) ) { if (!selected.isEmpty()) { - cache.reset() + rollback() } return null } @@ -237,17 +238,21 @@ class TexturePlanner { } } for (sel in imageDrawable) { - subs.add(encodeImageDraw(cache, sel)) + subs.add(encodeImageDraw(sel)) } subs.addAll(runs) subs.addAll(fwSubs) var payload: ByteArray = assembleMode8(subs) - var uploadBytes: Int = cache.pendingUploadBytes() - var uploads: MutableList = cache.drainUploadPayloads(UPLOAD_PAYLOAD_MAX) + if (payload.size > CfwTransport.MAX_MESSAGE) { + rollback() + return null + } + val resourceCommands = cache.drainCommands(UPLOAD_PAYLOAD_MAX) + val uploadBytes = resourceCommands.sumOf { it.size } var result: Result = Result( payload, - uploads, + resourceCommands, fid, rects.size, drawnGlyphs.size, @@ -694,65 +699,31 @@ class TexturePlanner { } } - /** - * Ensure residency for all of `selected`, resetting the cache once if the allocator fills - * mid-plan (a reset invalidates offsets handed out earlier in the same pass, so the whole - * pass reruns). Returns the draws that are resident afterwards. - */ + /** Protect every hit before LRU admission so a miss cannot evict this frame's later draws. */ private fun ensureResident( - cache: TextureCacheState, + cache: ResourceCacheState, selected: MutableList, ): MutableList { - run { - var attempt: Int = 0 - while ((attempt < 2)) { - var resident: MutableList = ArrayList(selected.size) - var full: Boolean = false - for (sel in selected) { - var offset: Int = - (if ((sel.glyphAtlas != null)) - cache.ensureGlyph( - sel.draw.fontId, - sel.draw.encoding, - sel.glyphAtlas, - ) - else cache.ensureImage(sel.draw.imageId, sel.imageAtlas)) - if ((offset >= 0)) { - resident.add(sel) - } else { - full = true - } - } - if ((!full || (attempt == 1))) { - return resident - } - cache.reset() - attempt++ - } + val fonts = selected.filter { it.glyphAtlas != null }.groupBy { it.draw.fontId } + .mapValues { (id, draws) -> FontResourceAtlas.get(id, draws.map { it.draw.encoding }.toSet()) } + val candidates = selected.filter { it.glyphAtlas == null || it.draw.encoding in fonts.getValue(it.draw.fontId).encodings } + val resources = candidates.map { sel -> + if (sel.glyphAtlas != null) fonts.getValue(sel.draw.fontId).resource else sel.imageAtlas!!.resource } - return mutableListOf() + val ids = cache.prepare(resources) + return candidates.filterIndexed { index, sel -> sel.resourceId = ids[index]; ids[index] >= 0 }.toMutableList() } - /** Mode-19 cached-image draw: [19][offset u32][x u16][y u16][options u8]. */ + /** Mode-19 cached-image draw: [19][resourceId u16][x u16][y u16][options u8]. */ @JvmStatic - private fun encodeImageDraw(cache: TextureCacheState, sel: Selected): ByteArray { - var offset: Int = cache.ensureImage(sel.draw.imageId, sel.imageAtlas) - var sub: ByteArray = ByteArray(10) - sub[0] = 19 - sub[1] = ((offset and 0xff)).toByte() - sub[2] = (((offset shr 8) and 0xff)).toByte() - sub[3] = (((offset shr 16) and 0xff)).toByte() - sub[4] = (((offset shr 24) and 0xff)).toByte() - sub[5] = ((sel.draw.x and 0xff)).toByte() - sub[6] = (((sel.draw.x shr 8) and 0xff)).toByte() - sub[7] = ((sel.draw.y and 0xff)).toByte() - sub[8] = (((sel.draw.y shr 8) and 0xff)).toByte() - sub[9] = (IMAGE_DRAW_OPTIONS).toByte() - return sub - } + private fun encodeImageDraw(sel: Selected): ByteArray = byteArrayOf( + 19, sel.resourceId.toByte(), (sel.resourceId ushr 8).toByte(), + sel.draw.x.toByte(), (sel.draw.x ushr 8).toByte(), + sel.draw.y.toByte(), (sel.draw.y ushr 8).toByte(), IMAGE_DRAW_OPTIONS.toByte(), + ) /** - * Group selected glyphs into mode-20 string sub-messages: [20][fontTable u32][x u16][y + * Group selected glyphs into mode-20 string sub-messages: [20][fontResource u16][x u16][y * u16][options u8][strlen u8][string] One run per (font, line y, top color) span; within a * run, control bytes 1..31 adjust x by -10..+20 to hit each glyph's exact position, and * each glyph advances x by its cached width. Order across runs is free: every drawn glyph's @@ -761,7 +732,6 @@ class TexturePlanner { */ @JvmStatic private fun buildRuns( - cache: TextureCacheState, drawable: MutableList, outRuns: MutableList, ): MutableList { @@ -776,8 +746,8 @@ class TexturePlanner { var i: Int = 0 while (((i < sorted.size) && (outRuns.size < MAX_GLYPH_RUNS))) { var first: Selected = sorted.get(i) - var fontTable: Int = cache.fontTableOffset(first.draw.fontId) - if ((fontTable < 0)) { + val fontResource = first.resourceId + if ((fontResource < 0)) { i++ continue } @@ -809,19 +779,17 @@ class TexturePlanner { } if (!runGlyphs.isEmpty()) { var stringBytes: ByteArray = string.toByteArray() - var run: ByteArray = ByteArray((11 + stringBytes.size)) + val run = ByteArray(9 + stringBytes.size) run[0] = 20 - run[1] = ((fontTable and 0xff)).toByte() - run[2] = (((fontTable shr 8) and 0xff)).toByte() - run[3] = (((fontTable shr 16) and 0xff)).toByte() - run[4] = (((fontTable shr 24) and 0xff)).toByte() - run[5] = ((first.gx and 0xff)).toByte() - run[6] = (((first.gx shr 8) and 0xff)).toByte() - run[7] = ((first.draw.y and 0xff)).toByte() - run[8] = (((first.draw.y shr 8) and 0xff)).toByte() - run[9] = ((first.top or 0x10)).toByte() - run[10] = (stringBytes.size).toByte() - stringBytes.copyInto(run, 11, 0, 0 + stringBytes.size) + run[1] = fontResource.toByte() + run[2] = (fontResource ushr 8).toByte() + run[3] = first.gx.toByte() + run[4] = (first.gx ushr 8).toByte() + run[5] = first.draw.y.toByte() + run[6] = (first.draw.y ushr 8).toByte() + run[7] = (first.top or 0x10).toByte() + run[8] = stringBytes.size.toByte() + stringBytes.copyInto(run, 9) outRuns.add(run) drawn.addAll(runGlyphs) i = j @@ -876,8 +844,8 @@ class TexturePlanner { /** Complete image payload: a mode-8 batch of rect deltas + cached draws. */ @JvmField val payload: ByteArray - /** Mode-18 upload payloads to enqueue BEFORE the image message. */ - @JvmField val uploads: MutableList + /** Mode-22 evictions and mode-21 uploads to enqueue BEFORE the image message. */ + @JvmField val resourceCommands: MutableList /** Next mode-3 frame id (deltas consumed some). */ @JvmField val nextFid: Int @@ -919,7 +887,7 @@ class TexturePlanner { constructor( payload: ByteArray, - uploads: MutableList, + resourceCommands: MutableList, nextFid: Int, rectCount: Int, drawnGlyphs: Int, @@ -932,7 +900,7 @@ class TexturePlanner { fullFrame: Boolean, ) { this.payload = payload - this.uploads = uploads + this.resourceCommands = resourceCommands this.nextFid = nextFid this.rectCount = rectCount this.drawnGlyphs = drawnGlyphs @@ -948,6 +916,8 @@ class TexturePlanner { /** One draw selected for on-glasses replay. */ private class Selected { + var resourceId: Int = -1 + @JvmField val draw: SurfaceCompositor.ScreenDraw @JvmField val glyphAtlas: GlyphAtlas.Glyph? diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt new file mode 100644 index 00000000..3005f3ed --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt @@ -0,0 +1,39 @@ +package com.faceclaw.app + +/** Self-contained font snapshots; their 96 u16 glyph offsets survive firmware compaction. */ +class FontResourceAtlas { + class Font(val resource: CachedResource, val encodings: Set) + + companion object { + private val lock = protocolPlatform().createLock() + private val fonts = HashMap() + + fun get(fontId: Int, requested: Set): Font { + lock.withLock { + val old = fonts[fontId] + if (old != null && old.encodings.containsAll(requested)) return old + val glyphs = HashMap() + var size = 192 + // Current-frame glyphs take precedence if the entire font cannot fit. + for (encoding in requested.sorted() + (old?.encodings ?: emptySet()).sorted()) { + if (encoding !in 32..127 || glyphs.containsKey(encoding)) continue + val glyph = GlyphAtlas.get(fontId, encoding) ?: continue + if (size + glyph.cachedBytes.size > ResourceCacheState.MAX_RESOURCE_SIZE) continue + glyphs[encoding] = glyph; size += glyph.cachedBytes.size + } + val bytes = ByteArray(size) + var offset = 192 + for (encoding in glyphs.keys.sorted()) { + val glyph = glyphs.getValue(encoding) + val slot = (encoding - 32) * 2 + bytes[slot] = offset.toByte(); bytes[slot + 1] = (offset ushr 8).toByte() + glyph.cachedBytes.copyInto(bytes, offset) + offset += glyph.cachedBytes.size + } + val font = Font(CachedResource(bytes), glyphs.keys.toSet()) + fonts[fontId] = font + return font + } + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt index 97450875..6ddc2fce 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt @@ -6,7 +6,7 @@ import kotlin.jvm.JvmStatic /** * Process-wide registry of glyph rasters, fed from the TS side so glyph identity survives to the * BLE encoder (see notes/texture-cache-display-list- design.md). A frame's glyph list references - * entries here by (fontId, encoding); the texture-cache planner uses the raster three ways: + * entries here by (fontId, encoding); the resource-cache planner uses the raster three ways: * * - as the ink mask for the "would this draw land correctly" check against the composited frame, * - to punch the ink pixels out of the baked delta rect it replaces, diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt index 01af3217..31533760 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt @@ -4,7 +4,7 @@ import kotlin.jvm.JvmField import kotlin.jvm.JvmStatic /** - * Process-wide registry of icon/image rasters for the texture-cache pipeline, the image counterpart + * Process-wide registry of icon/image rasters for the resource-cache pipeline, the image counterpart * of GlyphAtlas. Entries are content-addressed: the TS side keys each image by a hash of its * dimensions and pixels, so the same icon registered from any thread or rendered at any time * dedupes to one entry, and an icon whose content changes is simply a new entry. @@ -81,11 +81,14 @@ class ImageAtlas { /** CFW cached-image bytes: [w][h][RLE(w*h pixels)]. */ @JvmField val cachedBytes: ByteArray + val resource: CachedResource + constructor(width: Int, height: Int, nibbles: ByteArray) { this.width = width this.height = height this.nibbles = nibbles this.cachedBytes = encodeCachedImage() + this.resource = CachedResource(cachedBytes) } /** The 4bpp value the mode-13 draw would write at (col, row); 0 = skipped. */ diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index daf4cfed..a08a21d1 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -98,7 +98,7 @@ class SurfaceCompositor { /** * One deferred draw (a text glyph or an icon image) within a frame, in screen coordinates. The * draw's pixels are already baked into the composited gray buffer (the TS side bakes before - * submitting); this record preserves the draw's identity so the texture-cache planner can + * submitting); this record preserves the draw's identity so the resource-cache planner can * replay it as an on-glasses cached draw instead of image bytes. * * Glyphs: x/y are the pen position and line top; the raster (and its bearing/cell placement) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt index b68046cf..1e3636db 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt @@ -16,7 +16,7 @@ class BmpUtil { ByteArray(256) { v -> if (v == 0) 0 else minOf(15, (v + 8) shr 4).toByte() } /** - * The 4bpp level an 8-bit gray value packs to. Public so the texture-cache planner computes + * The 4bpp level an 8-bit gray value packs to. Public so the resource-cache planner computes * a glyph draw's top color with the exact quantization the composited frame was packed * with. */ diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt index 09dd5077..b97f5b49 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt @@ -23,13 +23,13 @@ class IosTextureFrame internal constructor(internal val composite: SurfaceCompos class IosTexturePlan internal constructor(result: TexturePlanner.Result, val usedBytes: Int) { val payload: NSData = result.payload.data() - val uploads: List = result.uploads.map { it.data() } + val resourceCommands: List = result.resourceCommands.map { it.data() } val nextFid: Int = result.nextFid } /** One instance per BLE session, called on the session's serial JS thread. */ class IosTexturePlanner { - private val cache = TextureCacheState() + private val cache = ResourceCacheState() fun reset() = cache.reset() @@ -39,12 +39,6 @@ class IosTexturePlanner { previous?.byteArray(), next.byteArray(), composite.width, composite.height, composite.draws, cache, firstId, true, ConnectionOptions.MULTI_RECT_MAX_RECTS, ) ?: return null - // A plan is atomic. If it cannot fit the CFW transport, discard its uploads - // and residency too, before the session falls back to ordinary pixel bands. - if (result.payload.size > 65535 || result.uploads.any { it.size > 65535 }) { - cache.reset() - return null - } return IosTexturePlan(result, cache.usedBytes()) } } diff --git a/tests/ios-ble.test.cjs b/tests/ios-ble.test.cjs index c6647841..d7c3d5e6 100644 --- a/tests/ios-ble.test.cjs +++ b/tests/ios-ble.test.cjs @@ -306,14 +306,14 @@ const ack = (transport, sent, overrides) => transport.ack(sent.id, sent.message, const tick = () => new Promise(resolve => setImmediate(resolve)); const noisy = () => Uint8Array.from({ length: 640 * 480 }, (_, i) => (i % 2) * 255); -test('texture uploads precede their frame, share ACK accounting, and coalesce pixels with draw identities', async t => { +test('resource evictions and uploads precede their frame, share ACK accounting, and coalesce pixels with draw identities', async t => { const plans = []; let resets = 0; const textures = { reset() { resets++; }, plan(previous, next, frame, firstId) { plans.push({ previous, next, frame, firstId }); - return { uploads: plans.length === 1 ? [new Uint8Array([18, 1]), new Uint8Array([18, 2])] : [], + return { resourceCommands: plans.length === 1 ? [new Uint8Array([22, 1]), new Uint8Array([21, 2])] : [], payload: new Uint8Array([8, plans.length]), nextFid: firstId + 2, usedBytes: 100 }; }, }; @@ -323,7 +323,7 @@ test('texture uploads precede their frame, share ACK accounting, and coalesce pi h.session.setFrame(new Uint8Array(640 * 480), a); await until(() => imageMessages(h.transport).length === 3); const sent = imageMessages(h.transport); - assert.deepEqual(sent.map(s => s.message.payload[0]), [18, 18, 8]); + assert.deepEqual(sent.map(s => s.message.payload[0]), [22, 21, 8]); h.session.setFrame(new Uint8Array(640 * 480).fill(80), b); h.session.setFrame(new Uint8Array(640 * 480).fill(160), c); assert.equal(plans.length, 1, 'coalesced frames must not allocate textures'); @@ -340,15 +340,39 @@ test('texture uploads precede their frame, share ACK accounting, and coalesce pi assert.ok(resets > 0); }); -test('a failed texture upload invalidates residency and the pipelined frame base', async t => { +test('evictions drain earlier replayable draws before resource IDs can be reused', async t => { + let plans = 0; + const textures = { + reset() {}, + plan() { return { resourceCommands: ++plans === 1 ? [] : [new Uint8Array([22]), new Uint8Array([21])], + payload: new Uint8Array([8]), nextFid: 1, usedBytes: 100 }; }, + }; + const h = harness(t, new FakeTransport(), textures); await h.session.start(addresses); + h.transport.hold = true; + h.session.setFrame(new Uint8Array(640 * 480), { native: {} }); + await until(() => imageMessages(h.transport).length === 1); + h.session.setFrame(new Uint8Array(640 * 480).fill(80), { native: {} }); + await until(() => plans === 2); await tick(); + assert.equal(imageMessages(h.transport).length, 1, 'eviction cannot enter an unresolved window'); + h.session.recoverCfw(); await tick(); + assert.equal(imageMessages(h.transport).length, 1); + ack(h.transport, imageMessages(h.transport)[0]); + await until(() => imageMessages(h.transport).length === 4); + assert.deepEqual(imageMessages(h.transport).map(s => s.message.payload[0]), [8, 22, 21, 8]); + h.transport.hold = false; + for (const sent of imageMessages(h.transport).slice(1)) ack(h.transport, sent); + await until(() => h.session.state.frames === 2); +}); + +test('a failed resource upload invalidates residency and the pipelined frame base', async t => { let resets = 0; const textures = { reset() { resets++; }, - plan() { return { uploads: [new Uint8Array([18])], payload: new Uint8Array([8]), nextFid: 1, usedBytes: 4 }; }, + plan() { return { resourceCommands: [new Uint8Array([21])], payload: new Uint8Array([8]), nextFid: 1, usedBytes: 4 }; }, }; const h = harness(t, new FakeTransport(), textures); await h.session.start(addresses); const original = h.session.requestCfw.bind(h.session); - h.session.requestCfw = (role, payload) => payload[0] === 18 ? Promise.reject(new Error('texture upload failed')) : original(role, payload); + h.session.requestCfw = (role, payload) => payload[0] === 21 ? Promise.reject(new Error('texture upload failed')) : original(role, payload); h.session.setFrame(new Uint8Array(640 * 480), { native: {} }); await until(() => h.session.state.phase === 'retrying'); assert.equal(resets, 1); assert.equal(h.session.lastEnqueued, null); diff --git a/tests/kotlin/src/androidHostTest/java/com/faceclaw/app/ResourceCacheProtocolTest.java b/tests/kotlin/src/androidHostTest/java/com/faceclaw/app/ResourceCacheProtocolTest.java new file mode 100644 index 00000000..39e204a2 --- /dev/null +++ b/tests/kotlin/src/androidHostTest/java/com/faceclaw/app/ResourceCacheProtocolTest.java @@ -0,0 +1,20 @@ +package com.faceclaw.app; + +import java.util.*; + +/** Android's Java communicator and iOS share the same resource API and wire commands. */ +public class ResourceCacheProtocolTest { + public static void main(String[] args) { + ResourceCacheState cache = new ResourceCacheState(); + CachedResource image = new CachedResource(new byte[]{1, 1, 31}); + assert cache.prepare(Collections.singletonList(image))[0] == 0; + List commands = cache.drainCommands(3600); + assert commands.size() == 2 && commands.get(0)[0] == 22; + assert Arrays.equals(commands.get(1), new byte[]{21,1,0,0,0,3,0,0,0,0,0,3,0,1,1,31}); + assert cache.prepare(Collections.singletonList(image))[0] == 0; + assert cache.drainCommands(3600).isEmpty(); + cache.reset(); + assert cache.prepare(Collections.singletonList(image))[0] == 0; + assert cache.drainCommands(3600).get(0)[0] == 22; + } +} diff --git a/tests/kotlin/src/androidHostTest/java/com/faceclaw/app/TextureCacheProtocolTest.java b/tests/kotlin/src/androidHostTest/java/com/faceclaw/app/TextureCacheProtocolTest.java deleted file mode 100644 index 77ecac96..00000000 --- a/tests/kotlin/src/androidHostTest/java/com/faceclaw/app/TextureCacheProtocolTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.faceclaw.app; - -import java.lang.reflect.*; -import java.util.*; - -public class TextureCacheProtocolTest { - static int u16(byte[] b, int p) { return (b[p]&255) | (b[p+1]&255)<<8; } - static int u32(byte[] b, int p) { return u16(b,p) | u16(b,p+2)<<16; } - public static void main(String[] args) throws Exception { - TextureCacheState cache = new TextureCacheState(); - byte[] pixels = new byte[255*255]; - for (int i=0;i=0; - ImageAtlas.Entry tiny = new ImageAtlas.Entry(1,1,new byte[]{15}); - int imageOffset = cache.ensureImage(100,tiny); - assert imageOffset>65535; - GlyphAtlas.Glyph glyph = new GlyphAtlas.Glyph(1,1,0,1,0,null,new byte[]{15}); - int glyphOffset = cache.ensureGlyph(42,'A',glyph); - int table = cache.fontTableOffset(42); - assert table>65535 && glyphOffset==table+96*4; - byte[] memory = new byte[262144]; - for (byte[] upload: cache.drainUploadPayloads(3600)) { - assert upload[0]==18; - int pos=1; - while (pos selected=Class.forName("com.faceclaw.app.TexturePlanner$Selected"); - Constructor ctor=selected.getDeclaredConstructors()[0]; ctor.setAccessible(true); - Object image=ctor.newInstance(SurfaceCompositor.ScreenDraw.image(100,321,123),null,tiny,321,15); - Method encode=TexturePlanner.class.getDeclaredMethod("encodeImageDraw",TextureCacheState.class,selected); - encode.setAccessible(true); - byte[] draw=(byte[])encode.invoke(null,cache,image); - assert draw.length==10 && draw[0]==19 && u32(draw,1)==imageOffset; - assert u16(draw,5)==321 && u16(draw,7)==123 && draw[9]==31; - Object letter=ctor.newInstance(SurfaceCompositor.ScreenDraw.glyph(42,'A',321,123,255),glyph,null,321,15); - Method runs=TexturePlanner.class.getDeclaredMethod("buildRuns",TextureCacheState.class,List.class,List.class); - runs.setAccessible(true); List out=new ArrayList<>(); - runs.invoke(null,cache,Collections.singletonList(letter),out); - byte[] run=out.get(0); - assert run.length==12 && run[0]==20 && u32(run,1)==table; - assert u16(run,5)==321 && u16(run,7)==123 && run[9]==31 && run[10]==1 && run[11]=='A'; - int id=200; - while (cache.ensureImage(id++,big)>=0) {} - int before=cache.usedBytes(); - assert cache.ensureImage(id,big)==-1 && cache.usedBytes()==before; - cache.reset(); assert cache.usedBytes()==0 && !cache.hasPendingUploads(); - assert cache.ensureImage(id,tiny)==0; - } -} diff --git a/tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/JavaCompatibilityTest.kt b/tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/JavaCompatibilityTest.kt index 1edb969a..db32038b 100644 --- a/tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/JavaCompatibilityTest.kt +++ b/tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/JavaCompatibilityTest.kt @@ -10,7 +10,7 @@ class JavaCompatibilityTest { @Test fun gestures() = FaceclawGestureEventTest.main(emptyArray()) - @Test fun textureCache() = TextureCacheProtocolTest.main(emptyArray()) + @Test fun resourceCache() = ResourceCacheProtocolTest.main(emptyArray()) } class AndroidByteReaderTest { diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ProtocolTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ProtocolTest.kt index a2c006e6..17db733f 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ProtocolTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ProtocolTest.kt @@ -198,6 +198,20 @@ class ProtocolTest { assertEquals(1, callbacks) } + @Test + fun evictionWaitsForAllEarlierReplayableCommands() { + val earlier = message(input = byteArrayOf(19, 0, 0)) + val eviction = message(input = byteArrayOf(22, 1, 0, 0, 0)) + val upload = message(input = byteArrayOf(21, 1, 0)) + assertFalse(CfwMessageWindow.canSend(listOf(earlier), eviction)) + earlier.cfwAckLenses = 3 // Still retained behind an unresolved window head. + assertFalse(CfwMessageWindow.canSend(listOf(earlier), eviction)) + assertTrue(CfwMessageWindow.canSend(emptyList(), eviction)) + assertTrue(CfwMessageWindow.canSend(listOf(message(sid = 1)), eviction)) + assertTrue(CfwMessageWindow.canSend(listOf(earlier), upload)) + assertTrue(CfwMessageWindow.canSend(listOf(eviction), upload)) + } + @Test fun orderedCompletionAndWholeWindowRecovery() { val head = message() diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt new file mode 100644 index 00000000..88d7815f --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt @@ -0,0 +1,166 @@ +package com.faceclaw.app + +import kotlin.test.* + +class ResourceCacheTest { + private fun resource(size: Int, value: Int) = CachedResource(ByteArray(size) { value.toByte() }) + private fun u16(bytes: ByteArray, offset: Int) = (bytes[offset].toInt() and 255) or ((bytes[offset + 1].toInt() and 255) shl 8) + private fun u32(bytes: ByteArray, offset: Int) = u16(bytes, offset) or (u16(bytes, offset + 2) shl 16) + private fun uploaded(commands: List): Map { + val resources = HashMap() + val received = HashMap() + for (command in commands) { + assertTrue(command.size <= 3600) + if (command[0].toInt() != 21) continue + var pos = 3 + val seen = HashSet() + repeat(u16(command, 1)) { + val id = u16(command, pos) + assertTrue(id in 0..511 && seen.add(id)) + val total = u32(command, pos + 2) + val offset = u16(command, pos + 6) + val length = u16(command, pos + 8) + assertEquals(received[id] ?: 0, offset) + val bytes = resources.getOrPut(id) { ByteArray(total) } + command.copyInto(bytes, offset, pos + 10, pos + 10 + length) + received[id] = offset + length + pos += 10 + length + } + assertEquals(command.size, pos) + } + resources.forEach { (id, data) -> assertEquals(data.size, received[id]) } + return resources + } + + @Test fun contentAddressingAndWireVector() { + val cache = ResourceCacheState() + val image = CachedResource(byteArrayOf(1, 1, 31)) + val ids = cache.prepare(listOf(image, CachedResource(image.bytes))) + assertContentEquals(intArrayOf(0, 0), ids) + val commands = cache.drainCommands(3600) + assertEquals(22, commands.first()[0].toInt()) + assertEquals(512, u16(commands.first(), 1)) + assertEquals(511, u16(commands.first(), 1025)) + assertContentEquals(byteArrayOf(21, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 1, 1, 31), commands.last()) + assertContentEquals(image.bytes, uploaded(commands).getValue(0)) + assertEquals(2068, cache.usedBytes()) + assertEquals(0, cache.prepare(listOf(image))[0]) + assertTrue(cache.drainCommands(3600).isEmpty()) + cache.reset(); cache.prepare(listOf(image)) + assertEquals(22, cache.drainCommands(3600).first()[0].toInt()) + } + + @Test fun exactly64KiBUploadsInBoundedContiguousChunks() { + val cache = ResourceCacheState() + val data = CachedResource(ByteArray(65536) { (it * 37).toByte() }) + assertEquals(0, cache.prepare(listOf(data))[0]) + val commands = cache.drainCommands(3600) + assertTrue(commands.count { it[0].toInt() == 21 } > 1) + assertContentEquals(data.bytes, uploaded(commands).getValue(0)) + assertEquals(-1, cache.prepare(listOf(resource(65537, 1)))[0]) + assertTrue(cache.drainCommands(3600).isEmpty()) + assertEquals(0, cache.resourceId(data)) + } + + @Test fun lruEvictsByBytesAndProtectsAllCurrentFrameHits() { + val cache = ResourceCacheState() + val a = resource(65536, 1); val b = resource(65536, 2); val c = resource(65536, 3); val d = resource(65536, 4) + assertContentEquals(intArrayOf(0, 1, 2), cache.prepare(listOf(a, b, c))) + cache.drainCommands(3600) + cache.prepare(listOf(a)); cache.drainCommands(3600) // b is oldest now. + assertContentEquals(intArrayOf(1, 2), cache.prepare(listOf(d, c))) // protect later hit c before d. + val commands = cache.drainCommands(3600) + assertContentEquals(byteArrayOf(22, 1, 0, 1, 0), commands.first()) + assertEquals(-1, cache.resourceId(b)) + assertEquals(0, cache.resourceId(a)); assertEquals(2, cache.resourceId(c)) + assertEquals(1, cache.resourceId(d)) + assertContentEquals(d.bytes, uploaded(commands).getValue(1)) + val tooLarge = cache.prepare(listOf(a, c, d, b)) + assertEquals(-1, tooLarge.last()) + assertTrue(cache.drainCommands(3600).isEmpty()) + assertEquals(3, cache.residentCount()) + } + + @Test fun idPressureUsesLruEvenWhenBytesAreAvailable() { + val cache = ResourceCacheState() + val resources = (0..512).map { CachedResource(byteArrayOf(it.toByte(), (it ushr 8).toByte())) } + assertContentEquals(IntArray(512) { it }, cache.prepare(resources.take(512))) + cache.drainCommands(3600) + cache.prepare(listOf(resources[0])); cache.drainCommands(3600) + assertEquals(1, cache.prepare(listOf(resources[512]))[0]) + val commands = cache.drainCommands(3600) + assertContentEquals(byteArrayOf(22, 1, 0, 1, 0), commands.first()) + assertEquals(0, cache.resourceId(resources[0])) + assertEquals(-1, cache.resourceId(resources[1])) + } + + @Test fun rejectedPlansRestoreResidencyAndLru() { + val cache = ResourceCacheState() + val resources = (0..3).map { resource(65536, it) } + cache.prepare(resources.take(3)); cache.drainCommands(3600) + val rollback = cache.checkpoint() + cache.prepare(listOf(resources[3])) + assertEquals(-1, cache.resourceId(resources[0])) + rollback() + assertEquals(0, cache.resourceId(resources[0])); assertEquals(-1, cache.resourceId(resources[3])) + assertTrue(cache.drainCommands(3600).isEmpty()) + cache.prepare(listOf(resources[3])) + assertContentEquals(byteArrayOf(22, 1, 0, 0, 0), cache.drainCommands(3600).first()) + } + + @Test fun imagePlannerEmitsResourceIdsAndReusesResidency() { + val cache = ResourceCacheState() + val id = ImageAtlas.ensure("resource-test-white", 2, 2, ArrayByteReader(ByteArray(4) { -1 })) + val pixels = ByteArray(8 * 4) + for (y in 0..1) for (x in 0..1) pixels[y * 8 + x] = -1 + val packed = BmpUtil.pack4bppFromGray8(pixels, 8, 4) + val draws = arrayOf(SurfaceCompositor.ScreenDraw.image(id, 0, 0)) + fun plan() = assertNotNull(TexturePlanner.plan(null, packed, 8, 4, draws, cache, 1, true, 8, testPlatform())) + val cold = plan() + assertEquals(1, cold.drawnImages) + assertContentEquals(byteArrayOf(19, 0, 0, 0, 0, 0, 0, 31), cold.payload.takeLast(8).toByteArray()) + assertTrue(cold.resourceCommands.isNotEmpty()) + val warm = plan() + assertTrue(warm.resourceCommands.isEmpty()); assertContentEquals(cold.payload, warm.payload) + cache.reset(); assertTrue(plan().resourceCommands.isNotEmpty()) + assertNull(TexturePlanner.plan(null, ByteArray(packed.size), 8, 4, draws, cache, 1, true, 8, testPlatform())) + } + + private fun registerFont(key: String, encodings: List, size: Int = 2): Int { + val out = ByteSink(); val name = key.encodeToByteArray() + out.write(name.size); out.write(name, 0, name.size); out.write(size) + out.write(encodings.size); out.write(0) + for (encoding in encodings) { + out.write(encoding); repeat(3) { out.write(0) } + out.write(0); out.write(0); out.write(size); out.write(size) + repeat(size * ((size + 1) / 2)) { out.write(0x12) } + } + GlyphAtlas.registerAa(ArrayByteReader(out.toByteArray())) + return GlyphAtlas.fontId(key) + } + + @Test fun fontTablesUseRelativeU16OffsetsAndGrowOnDemand() { + val id = registerFont("resource-font-relative", listOf(65, 66)) + val first = FontResourceAtlas.get(id, setOf(65)) + assertEquals(192, u16(first.resource.bytes, (65 - 32) * 2)) + assertEquals(0, u16(first.resource.bytes, (66 - 32) * 2)) + assertSame(first, FontResourceAtlas.get(id, setOf(65))) + val second = FontResourceAtlas.get(id, setOf(66)) + assertTrue(second.encodings.containsAll(setOf(65, 66))) + assertEquals(192 + GlyphAtlas.get(id, 65)!!.cachedBytes.size, u16(second.resource.bytes, (66 - 32) * 2)) + val cache = ResourceCacheState() + cache.prepare(listOf(second.resource)); val commands = cache.drainCommands(3600) + assertContentEquals(second.resource.bytes, uploaded(commands).getValue(0)) + } + + @Test fun oversizedFontsPrioritizeTheCurrentFrameWithin64KiB() { + val id = registerFont("resource-font-limit", listOf(65, 66), 255) + val a = FontResourceAtlas.get(id, setOf(65)) + assertEquals(setOf(65), a.encodings) + val b = FontResourceAtlas.get(id, setOf(66)) + assertEquals(setOf(66), b.encodings) + assertTrue(b.resource.bytes.size <= 65536) + assertEquals(0, u16(b.resource.bytes, (65 - 32) * 2)) + assertEquals(192, u16(b.resource.bytes, (66 - 32) * 2)) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/TextureCacheTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/TextureCacheTest.kt deleted file mode 100644 index 7a02c8fe..00000000 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/TextureCacheTest.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.faceclaw.app - -import kotlin.test.* - -class TextureCacheTest { - private fun u32(bytes: ByteArray, offset: Int): Int = - (0..3).fold(0) { n, i -> n or ((bytes[offset + i].toInt() and 255) shl (i * 8)) } - - @Test - fun offsetsAbove64KiBAndLazyFontSlotsRoundTripOnBothPlatforms() { - val cache = TextureCacheState() - val large = ImageAtlas.Entry(255, 255, ByteArray(255 * 255) { (it % 15 + 1).toByte() }) - repeat(3) { assertTrue(cache.ensureImage(it, large) >= 0) } - val glyph = GlyphAtlas.Glyph(1, 1, 0, 1, 0, null, byteArrayOf(15)) - val offset = cache.ensureGlyph(42, 65, glyph) - val table = cache.fontTableOffset(42) - assertTrue(table > 65535) - assertEquals(table + 384, offset) - val memory = ByteArray(TextureCacheState.CACHE_SIZE) - for (upload in cache.drainUploadPayloads(3600)) { - assertEquals(18, upload[0].toInt()) - var pos = 1 - while (pos < upload.size) { - val address = u32(upload, pos) - val length = (upload[pos + 4].toInt() and 255) or ((upload[pos + 5].toInt() and 255) shl 8) - upload.copyInto(memory, address, pos + 6, pos + 6 + length) - pos += 6 + length - } - assertEquals(upload.size, pos) - } - assertEquals(offset, u32(memory, table + (65 - 32) * 4)) - assertContentEquals(glyph.cachedBytes, memory.copyOfRange(offset, offset + glyph.cachedBytes.size)) - assertEquals(offset, cache.ensureGlyph(42, 65, glyph)) - assertFalse(cache.hasPendingUploads()) - cache.reset() - assertEquals(0, cache.usedBytes()) - assertEquals(384, cache.ensureGlyph(42, 65, glyph)) - assertTrue(cache.hasPendingUploads()) - } - - @Test - fun plannerReusesResidencyAndReuploadsAfterReset() { - val cache = TextureCacheState() - val id = ImageAtlas.ensure("texture-test-white", 2, 2, ArrayByteReader(ByteArray(4) { -1 })) - val pixels = ByteArray(8 * 4) - for (y in 0..1) for (x in 0..1) pixels[y * 8 + x] = -1 - val packed = BmpUtil.pack4bppFromGray8(pixels, 8, 4) - val draws = arrayOf(SurfaceCompositor.ScreenDraw.image(id, 0, 0)) - fun plan() = assertNotNull(TexturePlanner.plan(null, packed, 8, 4, draws, cache, 1, true, 8, testPlatform())) - val cold = plan() - assertEquals(1, cold.drawnImages) - assertTrue(cold.uploads.isNotEmpty()) - val warm = plan() - assertTrue(warm.uploads.isEmpty()) - assertContentEquals(cold.payload, warm.payload) - cache.reset() - assertTrue(plan().uploads.isNotEmpty()) - // Occlusion fails the correctness check and leaves the image baked. - assertNull(TexturePlanner.plan(null, ByteArray(packed.size), 8, 4, draws, cache, 1, true, 8, testPlatform())) - } - - @Test - fun fullCacheResetsAndRetriesTheCurrentFrame() { - val cache = TextureCacheState() - val large = ImageAtlas.Entry(255, 255, ByteArray(255 * 255) { (it % 15 + 1).toByte() }) - var fillerId = -1 - while (cache.ensureImage(fillerId--, large) >= 0) {} - // Fill the remaining tail, forcing the next real allocation to fail. - val remaining = TextureCacheState.CACHE_SIZE - cache.usedBytes() - while (cache.ensureImage(fillerId--, ImageAtlas.Entry(1, 1, byteArrayOf(15))) >= 0) {} - assertTrue(remaining > 0) - val generation = cache.generation() - val id = ImageAtlas.ensure("texture-test-full", 2, 2, ArrayByteReader(ByteArray(4) { -1 })) - val result = assertNotNull(TexturePlanner.plan(null, ByteArray(4) { -1 }, 4, 2, - arrayOf(SurfaceCompositor.ScreenDraw.image(id, 0, 0)), cache, 1, true, 8, testPlatform())) - assertEquals(generation + 1, cache.generation()) - assertEquals(1, result.drawnImages) - assertTrue(cache.usedBytes() < 100) - assertTrue(result.uploads.isNotEmpty()) - } - - @Test - fun workingSetLargerThanTheCacheFallsBackWithoutAResetLoop() { - val cache = TextureCacheState() - val raster = ByteArray(255 * 255) { if (it % 2 == 0) 16 else 32 } - val draws = (0..4).map { - val id = ImageAtlas.ensure("oversized-working-set-$it", 255, 255, ArrayByteReader(raster)) - SurfaceCompositor.ScreenDraw.image(id, 0, 0) - }.toTypedArray() - val gray = ByteArray(256 * 256) - repeat(255) { raster.copyInto(gray, it * 256, it * 255, (it + 1) * 255) } - val result = assertNotNull(TexturePlanner.plan(null, - BmpUtil.pack4bppFromGray8(gray, 256, 256), 256, 256, draws, cache, 1, true, 8, testPlatform())) - assertEquals(1, cache.generation()) - assertEquals(4, result.drawnImages) - assertEquals(1, result.bakedCandidates) - assertTrue(cache.usedBytes() <= TextureCacheState.CACHE_SIZE) - } -} diff --git a/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt index 57895601..e3eeda4c 100644 --- a/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt +++ b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt @@ -24,13 +24,14 @@ class IosTextureApiTest { val next = IosProtocol().pack(frame.pixels, 8, 4) val planner = IosTexturePlanner() val cold = assertNotNull(planner.plan(null, next, frame, 1)) - assertEquals(18, cold.uploads.first().byteArray()[0].toInt()) + assertEquals(22, cold.resourceCommands.first().byteArray()[0].toInt()) + assertTrue(cold.resourceCommands.any { it.byteArray()[0].toInt() == 21 }) assertEquals(8, cold.payload.byteArray()[0].toInt()) val warm = assertNotNull(planner.plan(null, next, frame, 1)) - assertTrue(warm.uploads.isEmpty()) + assertTrue(warm.resourceCommands.isEmpty()) assertContentEquals(cold.payload.byteArray(), warm.payload.byteArray()) planner.reset() - assertTrue(assertNotNull(planner.plan(null, next, frame, 1)).uploads.isNotEmpty()) + assertTrue(assertNotNull(planner.plan(null, next, frame, 1)).resourceCommands.isNotEmpty()) // A partial update clears identities even if the caller supplies stale draws. compositor.submitDraws("app", byteArrayOf(-1).data(), 0, 0, 1, 1, imageDraw(id).data()) assertTrue(compositor.compositeFrame().composite.draws!!.isEmpty()) @@ -50,10 +51,10 @@ class IosTextureApiTest { compositor.submitDraws("text", ByteArray(4) { -1 }.data(), 0, 0, 2, 2, draws.data()) val frame = compositor.compositeFrame() val plan = assertNotNull(IosTexturePlanner().plan(null, IosProtocol().pack(frame.pixels, 4, 2), frame, 1)) - assertTrue(plan.usedBytes > 384) + assertTrue(plan.usedBytes > 2048 + 192) val payload = plan.payload.byteArray() // The last mode-8 submessage is the shared mode-20 cached glyph run. - assertEquals(20, payload[payload.size - 12].toInt()) + assertEquals(20, payload[payload.size - 10].toInt()) assertEquals(65, payload.last().toInt()) } @@ -81,6 +82,6 @@ class IosTextureApiTest { small.submitDraws("icon", white, 0, 0, 2, 2, imageDraw(id).data()) val next = small.compositeFrame() val retry = assertNotNull(planner.plan(null, IosProtocol().pack(next.pixels, 4, 2), next, 1)) - assertTrue(retry.uploads.isNotEmpty(), "the rejected plan's image was never uploaded") + assertTrue(retry.resourceCommands.isNotEmpty(), "the rejected plan's image was never uploaded") } } From a7af84e2316196d6e64c88e3fb6e6586bf25ddb2 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Mon, 21 Sep 2026 18:07:37 -0700 Subject: [PATCH 02/27] Nightscout glanceboard widget shows out-of-bounds values when out of space --- CHANGELOG | 1 + .../glanceboard/widgets/nightscout-widget.ts | 45 +++++++----- tests/nightscout.test.cjs | 70 +++++++++++++++++++ 3 files changed, 99 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 202fd417..4b57d7fb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ * Add tokens and faceclaw-input script, which allows using a CLI utility as an input device for the glasses * Navigate app: Add map-without-destination mode +* Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space ### iOS port: diff --git a/app/apps/glanceboard/widgets/nightscout-widget.ts b/app/apps/glanceboard/widgets/nightscout-widget.ts index d9425d84..14139486 100644 --- a/app/apps/glanceboard/widgets/nightscout-widget.ts +++ b/app/apps/glanceboard/widgets/nightscout-widget.ts @@ -1,4 +1,4 @@ -import { type GrayImage } from "../../../graphics/image"; +import { GrayImage } from "../../../graphics/image"; import { getDefaultLargeFont, getDefaultSmallFont } from "../../../graphics/ui-fonts"; import { truncateText } from "../../../graphics/textwrap"; import { nightscoutBridge, type NightscoutState } from "../../../native/nightscout-bridge"; @@ -91,22 +91,6 @@ export class NightscoutWidget implements GlanceWidget { image.drawText(small, PAD, y, `IOB ${state.iob === null ? "--" : state.iob.toFixed(2)}`, 160); y += step; - // Breached limits only, one per line while they fit, inverted like the - // app's warning fields. Nothing here means nothing is out of range. - const alerts = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs); - const warnings: string[] = []; - if (alerts.cannula) warnings.push(`CAGE ${formatAgeShortFromTimestamp(state.cageTimestampMs, nowMs)}`); - if (alerts.cartridge) warnings.push(`Reservoir ${state.reservoirUnits === null ? "--" : Math.round(state.reservoirUnits)}U`); - if (alerts.battery) warnings.push(`Battery ${state.batteryVoltage === null ? "--" : state.batteryVoltage.toFixed(2)}V`); - if (alerts.loop) warnings.push(`Loop ${formatAgeShortFromTimestamp(state.loopTimestampMs, nowMs)}`); - for (const warning of warnings) { - if (y + small.lineHeight > image.height - 2) break; - const text = truncateText(small, warning, READOUT_WIDTH - 4); - image.fillRect(PAD - 2, y - 1, small.measureText(text) + 4, small.lineHeight + 2, 230); - image.drawText(small, PAD, y, text, 1); - y += step; - } - const graphX = PAD + READOUT_WIDTH + PAD; drawNightscoutGraph( image, @@ -115,5 +99,32 @@ export class NightscoutWidget implements GlanceWidget { nowMs, small, ); + + // Breached limits only, inverted like the app's warning fields. Continue + // at the top of a second column over the graph when the readout is full. + const alerts = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs); + const warnings: string[] = []; + if (alerts.cannula) warnings.push(`CAGE ${formatAgeShortFromTimestamp(state.cageTimestampMs, nowMs)}`); + if (alerts.cartridge) warnings.push(`Reservoir ${state.reservoirUnits === null ? "--" : Math.round(state.reservoirUnits)}U`); + if (alerts.battery) warnings.push(`Battery ${state.batteryVoltage === null ? "--" : state.batteryVoltage.toFixed(2)}V`); + if (alerts.loop) warnings.push(`Loop ${formatAgeShortFromTimestamp(state.loopTimestampMs, nowMs)}`); + let warningX = PAD; + for (const warning of warnings) { + if (y + small.lineHeight > image.height - 2) { + warningX = graphX; + y = PAD; + } + const text = truncateText(small, warning, READOUT_WIDTH - 4); + const width = Math.ceil(small.measureText(text)) + 4; + if (warningX === PAD) { + image.fillRect(warningX - 2, y - 1, width, small.lineHeight + 2, 230); + } else { + // Graph labels are deferred glyphs: a deferred opaque background + // covers those as well as the graph's raster lines. + image.drawImage(new GrayImage(width, small.lineHeight + 2, 230), warningX - 2, y - 1); + } + image.drawText(small, warningX, y, text, 1); + y += step; + } } } diff --git a/tests/nightscout.test.cjs b/tests/nightscout.test.cjs index 03e69c2b..9251c491 100644 --- a/tests/nightscout.test.cjs +++ b/tests/nightscout.test.cjs @@ -54,6 +54,76 @@ class Image { fillRect(...args) { this.draws.push(['rect', ...args]); } } const font = { measureText: text => text.length * 6, lineHeight: 12, hasGlyph: () => true }; + +function paintWidget(smallHeight, largeHeight, height = 144, measurements = {}) { + const { GrayImage } = require('../.test-build/app/graphics/image.js'); + const textDraws = []; + const small = { + ...font, lineHeight: smallHeight, ascent: 1, + drawText(image, x, y, text, value) { + textDraws.push({ x, y, text, value }); + // A tiny deferred glyph leaves room to inspect the opaque background. + image.drawGlyph(this, { bbxWidth: 1, bbxHeight: 1, bbxX: 2, bbxY: 0, bitmapRows: [128] }, x, y, value); + }, + }; + const state = { + available: true, latest: { sgv: 100, timestampMs: now }, units: 'mg/dL', delta: 0, direction: '', iob: 1, + cageTimestampMs: now - 100 * 3_600_000, reservoirUnits: 1, batteryVoltage: 1, loopTimestampMs: now - 60 * 60_000, + ...measurements, + }; + const { NightscoutWidget } = load('app/apps/glanceboard/widgets/nightscout-widget.ts', { + '../../../graphics/image': { GrayImage }, + '../../../graphics/ui-fonts': { getDefaultSmallFont: () => small, getDefaultLargeFont: () => ({ ...small, lineHeight: largeHeight }) }, + '../../../graphics/textwrap': require('../.test-build/app/graphics/textwrap.js'), + '../../../native/nightscout-bridge': { nightscoutBridge: { snapshot: () => state } }, + '../../../ui/dashboard-settings': { isNightscoutSettingsConfigured: () => true, loadNightscoutThresholds: () => limits }, + '../../../ui/metrics': { lineStep: font => font.lineHeight + 2 }, + '~/util/date-util': { formatAgeShortFromTimestamp: () => '1h' }, + '../../nightscout/nightscout-alerts': alerts, + '../../nightscout/nightscout': { + formatDelta: () => '+0', isNightscoutPointStale: () => false, drawDirectionIndicator() {}, + drawNightscoutGraph(image, bounds) { + image.fillRect(bounds.x, bounds.y, bounds.width, bounds.height, 56); + image.drawText(small, bounds.x - 2, bounds.y, 'graph label', 150); + }, + }, + }, { Date: { now: () => now } }); + const image = new GrayImage(288, height); + new NightscoutWidget().paint(image); + return { image, warnings: textDraws.filter(draw => draw.value === 1) }; +} + +test('glanceboard keeps fitting warnings in the readout and flows the rest over the graph', () => { + for (const [small, large] of [[8, 24], [12, 24], [16, 26], [21, 30]]) { + const { warnings } = paintWidget(small, large); + assert.deepEqual(warnings.map(draw => draw.text.split(' ')[0]), ['CAGE', 'Reservoir', 'Battery', 'Loop']); + assert.ok(warnings.every(draw => draw.y >= 8 && draw.y + small <= 142)); + const firstY = 8 + 4 * (small + 2) + large + 2; + const fitting = Math.max(0, Math.min(4, Math.floor((142 - firstY - small) / (small + 2)) + 1)); + assert.equal(warnings.filter(draw => draw.x === 8).length, fitting); + if (fitting < 4) { + assert.equal(warnings[fitting].y, 8); + assert.ok(warnings.slice(fitting).every(draw => draw.x === 112)); + } + } +}); + +test('glanceboard wraps only when a warning exceeds the bottom margin', () => { + assert.equal(paintWidget(12, 24, 104).warnings[0].x, 8); + assert.equal(paintWidget(12, 24, 103).warnings[0].x, 112); + assert.ok(paintWidget(21, 30, 240).warnings.every(draw => draw.x === 8)); + assert.equal(paintWidget(21, 30, 144, healthy).warnings.length, 0); +}); + +test('overflow warning backgrounds cover graph pixels and deferred graph labels', () => { + const { image } = paintWidget(21, 30); + const baked = image.withDrawsBaked(); + assert.equal(baked.getPixel(114, 7), 230, 'background covers the graph'); + assert.equal(baked.getPixel(112, 8), 230, 'background covers the deferred graph label'); + assert.equal(baked.getPixel(114, 8), 1, 'warning glyph remains visible'); + assert.equal(baked.getPixel(200, 8), 56, 'uncovered graph remains visible'); +}); + function fixture(always = false) { let time = now, icon, tick, changed, notify, renders = 0; const state = { ...healthy, available: true, latest: { sgv: 100, timestampMs: now }, history: [], units: 'mg/dL', delta: 0, direction: '', iob: 1, cob: 0, pumpStatus: '0m ago', configurationMissing: false }; From 43200212224c962d1d77589c358856d50aae1e4c Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 00:25:40 -0700 Subject: [PATCH 03/27] Display lists --- .../faceclaw/app/FaceclawBleCommunicator.java | 81 ++++------ .../app/FaceclawPreviewCompositor.java | 7 + app/g2/dashboard-controller.ts | 29 +--- app/g2/draw-protocol.ts | 14 ++ app/g2/firmware-compat.ts | 2 +- app/g2/firmware/cfw-patches.ts | 68 ++++----- app/g2/glasses-session.ts | 10 +- app/g2/ios-preview-controller.ts | 4 +- app/graphics/plane.ts | 2 + app/graphics/shell-scene.ts | 33 ++++ app/graphics/surface-compositor.ios.ts | 1 + app/graphics/surface-compositor.ts | 21 ++- app/native/faceclaw-communicator.ts | 5 + app/native/kotlin-protocol-smoke.ios.ts | 4 +- app/native/preview-display.ts | 5 + app/ui/layers.ts | 20 ++- app/ui/menu.ts | 8 +- app/ui/shell/assistant.ts | 6 +- app/ui/shell/brightness-picker-layer.ts | 4 +- app/ui/shell/chrome-layer.ts | 36 ++++- app/ui/shell/input-dialog.ts | 6 +- app/ui/shell/modal-layer.ts | 8 +- app/ui/shell/shell.ts | 8 +- app/ui/shell/tool-debug-layer.ts | 7 +- .../faceclaw/app/g2protocol/DrawProtocol.kt | 90 +++++++++++ .../app/g2protocol/ResourceCacheState.kt | 22 ++- .../faceclaw/app/g2protocol/ScenePlanner.kt | 77 ++++++++++ .../faceclaw/app/g2protocol/TexturePlanner.kt | 2 +- .../app/graphics/DisplayListRenderer.kt | 144 ++++++++++++++++++ .../app/graphics/FontResourceAtlas.kt | 7 +- .../com/faceclaw/app/graphics/GlyphAtlas.kt | 17 ++- .../com/faceclaw/app/graphics/ImageAtlas.kt | 13 +- .../com/faceclaw/app/graphics/ShellScene.kt | 41 +++++ .../app/graphics/SurfaceCompositor.kt | 30 ++-- .../kotlin/com/faceclaw/app/IosNativeApi.kt | 2 + .../kotlin/com/faceclaw/app/IosTextureApi.kt | 13 +- tests/ai-chat.test.cjs | 1 + tests/helpers/display-payload.cjs | 17 ++- tests/ios-app-host.test.cjs | 4 +- tests/ios-ble.test.cjs | 114 ++++++-------- tests/ios-glanceboard.test.cjs | 12 +- .../com/faceclaw/app/DisplayListTest.kt | 83 ++++++++++ .../com/faceclaw/app/ResourceCacheTest.kt | 12 +- .../com/faceclaw/app/IosTextureApiTest.kt | 17 ++- 44 files changed, 823 insertions(+), 284 deletions(-) create mode 100644 app/g2/draw-protocol.ts create mode 100644 app/graphics/shell-scene.ts create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java index c5f4dfeb..05d7bfc0 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java @@ -260,11 +260,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private final SurfaceCompositor compositor = new SurfaceCompositor(); - // Phone-side model of the CFW's 256 KiB resource cache (modes 19/20/21/22). + // Phone-side model of the CFW's 192 KiB resource cache. // Reset whenever the image pipeline / EvenHub session is torn down: the // firmware frees the cache with the fb lease, and after any resync the // cheap safe assumption is an empty cache (glyphs re-upload lazily). private final ResourceCacheState resourceCache = new ResourceCacheState(); + private final ScenePlanner scenePlanner = new ScenePlanner(resourceCache); + private ShellScene desiredShellScene = ShellScene.Companion.getEMPTY(); private final ArrayDeque pendingMessages = new ArrayDeque<>(); private final CfwTransport[] cfwTransports = { new CfwTransport(AndroidProtocolPlatform.INSTANCE), new CfwTransport(AndroidProtocolPlatform.INSTANCE) }; @@ -1141,7 +1143,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { "compositor:visible " + id + "=" + visible); compositor.setSurfaceVisible(id, visible); SurfaceCompositor.Composite composite = compositor.composite(); - byte[] packed = BmpUtil.pack4bppFromGray8(composite.gray, composite.width, composite.height); + byte[] packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height); storeDesiredComposite(composite, packed, 0, frameId); } @@ -1155,7 +1157,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { "compositor:" + (blanked ? "blank" : "unblank")); compositor.setBlanked(blanked); SurfaceCompositor.Composite composite = compositor.composite(); - byte[] packed = BmpUtil.pack4bppFromGray8(composite.gray, composite.width, composite.height); + byte[] packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height); storeDesiredComposite(composite, packed, 0, frameId); } @@ -1172,12 +1174,14 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { compositor.removeSurface(id); } - /** - * Dim every surface below zOrder belowZOrder to factor256/256 (see - * SurfaceCompositor.setUnderlayDim). Takes effect with the next submitted - * frame: the shell always submits its own surface right after changing - * this, so no recomposite happens here. - */ + /** Stage an immutable shell snapshot alongside the retained app screen. */ + public void submitShellScene(java.nio.ByteBuffer bytes, int paintMs, int frameId) { + compositor.setShellScene(new AndroidByteReader(bytes)); + SurfaceCompositor.Composite composite = compositor.composite(); + storeDesiredComposite(composite, BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height), paintMs, frameId); + } + + /** Legacy compositor dimming for callers without a shell scene. */ public void setUnderlayDim(int belowZOrder, int factor256) { compositor.setUnderlayDim(belowZOrder, factor256); } @@ -1239,7 +1243,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { // format the wire planners consume; BMP framing is added later only for // the uncompressed fallback. FrameTimings.getInstance().spanStart(frameId, "pack-4bpp"); - byte[] packed = BmpUtil.pack4bppFromGray8(composite.gray, composite.width, composite.height); + byte[] packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height); FrameTimings.getInstance().spanEnd(frameId, "pack-4bpp"); storeDesiredComposite(composite, packed, paintMs, frameId); } @@ -1263,6 +1267,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { desiredPaintMs = paintMs; desiredFrameId = frameId; desiredDraws = composite.draws; + desiredShellScene = composite.shellScene; } } if (stale) { @@ -2936,6 +2941,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { int paintMs; int frameId; SurfaceCompositor.ScreenDraw[] draws; + ShellScene scene; synchronized (desiredTilesLock) { packed = desiredPacked; width = desiredWidth; @@ -2943,58 +2949,25 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { paintMs = desiredPaintMs; frameId = desiredFrameId; draws = desiredDraws; + scene = desiredShellScene; desiredFrameId = 0; } if (packed == null) { packed = new byte[0]; } - if (lastEnqueuedWidth == width && lastEnqueuedHeight == height - && Arrays.equals(packed, lastEnqueuedPacked)) { - lastEnqueuedFingerprint = fingerprint; - finishFrame(frameId, "discarded: image content identical to displayed"); + if (customFirmwareDetected && packed.length > 0) { + ScenePlanner.Plan rendered = scenePlanner.plan(packed, width, height, draws, scene, nextImageFrameId, + connectionOptions.TEXTURE_CACHE_FRAMES, connectionOptions.INCREMENTAL_FRAMES, + connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS); + nextImageFrameId = rendered.getNextFid(); + List commands = rendered.getCommands(); + for (int i = 0; i < commands.size() - 1; i++) enqueueResourceCommandLocked(commands.get(i)); + BleImageOptimizer.TileImagePlan plan = new BleImageOptimizer.TileImagePlan( + 0, DASHBOARD_TILE, packed, width, height, nextMapSessionId(), commands.get(commands.size() - 1)); + finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId); return; } - // Resource-cache path: ship text as cached-glyph draws, punching their - // ink out of the baked deltas. Resource commands (modes 21/22) ride ahead of the - // image message on the ordered transport. Falls through to the plain - // paths whenever the planner has nothing to draw. - if (customFirmwareDetected && connectionOptions.TEXTURE_CACHE_FRAMES - && draws != null && draws.length > 0 && packed.length > 0) { - byte[] deltaBase = (connectionOptions.INCREMENTAL_FRAMES && lastEnqueuedPacked.length > 0 - && lastEnqueuedWidth == width && lastEnqueuedHeight == height) - ? lastEnqueuedPacked : null; - FrameTimings.getInstance().spanStart(frameId, "texture-plan"); - TexturePlanner.Result tex = TexturePlanner.plan( - deltaBase, packed, width, height, draws, resourceCache, - nextImageFrameId, - connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS); - if (tex != null) { - nextImageFrameId = tex.nextFid; - for (byte[] upload : tex.resourceCommands) { - enqueueResourceCommandLocked(upload); - } - BleImageOptimizer.TileImagePlan plan = new BleImageOptimizer.TileImagePlan( - 0, DASHBOARD_TILE, packed, width, height, nextMapSessionId(), tex.payload); - FrameTimings.getInstance().spanEnd(frameId, "texture-plan"); - String texLog = "texture update " + (tex.fullFrame ? "full" : ("rects=" + tex.rectCount)) - + " glyphs=" + tex.drawnGlyphs + " runs=" + tex.runCount - + " images=" + tex.drawnImages - + " fw=" + tex.fwGlyphs + "/" + tex.fwRuns - + " baked=" + tex.bakedCandidates - + (tex.uploadBytes > 0 ? " upload=" + tex.uploadBytes + "B" : "") - + " cache=" + resourceCache.usedBytes() + "B" - + " payload=" + tex.payload.length + "B" - + " (rects " + tex.rectsMs + "ms, match " + tex.matchMs - + "ms, cache " + tex.cacheMs + "ms, punch " + tex.punchMs - + "ms, encode " + tex.encodeMs + "ms)"; - FrameTimings.getInstance().log(frameId, texLog); - finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId); - return; - } - FrameTimings.getInstance().spanEnd(frameId, "texture-plan"); - } - FrameTimings.getInstance().spanStart(frameId, "compress-and-plan"); // Incremental (mode 3 bounding box) update against the last ENQUEUED frame // (the base the firmware shadow will hold when this update is applied). diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java index b95f9061..b0304992 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java @@ -73,6 +73,13 @@ public final class FaceclawPreviewCompositor { } /** Dim every surface below zOrder belowZOrder to factor256/256 (see SurfaceCompositor). */ + public void submitShellScene(java.nio.ByteBuffer bytes, int paintMs, int frameId) { + compositor.setShellScene(new AndroidByteReader(bytes)); + FrameTimings.getInstance().finishFrame(frameId, "composited (preview-only, no glasses)"); + Runnable listener = frameListener; + if (listener != null) mainHandler.post(listener); + } + public void setUnderlayDim(int belowZOrder, int factor256) { compositor.setUnderlayDim(belowZOrder, factor256); } diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 519d9a71..9c431239 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -2467,7 +2467,7 @@ class DashboardController { beginRenderPass(!wantFreshData); const paintStartedAtMs = Date.now(); const planes = frameTimings.span(frameId, "paint", () => - frameTimings.runWithFrame(frameId, () => shell.paintSurface()), + frameTimings.runWithFrame(frameId, () => shell.paintScene()), ); const paintMs = Date.now() - paintStartedAtMs; const paintUsedStaleData = endRenderPass(); @@ -2484,32 +2484,7 @@ class DashboardController { frameTimings.finishFrame(frameId, "discarded: shell render with no display target"); return; } - // A shell overlay that dims what it covers (a context menu) must dim the - // window surfaces too, which live below the shell surface in the - // compositor: forward the factor before this frame composites. - const underlayDim = shell.underlayDim(); - if (underlayDim !== this.appliedUnderlayDim) { - this.appliedUnderlayDim = underlayDim; - await display.setUnderlayDim(SHELL_SURFACE_Z_ORDER, underlayDim); - } - const fingerprint = frameTimings.span(frameId, "fingerprint", () => planesFingerprint(planes)); - const { image, draws } = frameTimings.span(frameId, "flatten", () => flattenPlanesWithDraws(planes)); - const buffer = frameTimings.span(frameId, "to8bpp", () => image.to8bppBuffer()); - const preparedDraws = frameTimings.span(frameId, "prepareFrameDraws", () => prepareFrameDraws(draws)); - // Spanned because the bridge serializes Java calls: a frame can sit here - // behind another surface's submission, which is otherwise an unexplained - // jump between the paint spans and the composite. - await frameTimings.spanAsync(frameId, "submit", () => - display.submitSurfaceFrame( - SHELL_SURFACE_ID, - buffer, - { x: 0, y: 0, width: image.width, height: image.height }, - fingerprint, - paintMs, - frameId, - preparedDraws, - ), - ); + await frameTimings.spanAsync(frameId, "submit", () => display.submitShellScene(planes, paintMs, frameId)); // Backpressure: the next shell render waits for this one to reach the // glasses. Timing out here means the loop was blocked for the full timeout // and any input arriving meanwhile had its chrome repaint delayed, so say diff --git a/app/g2/draw-protocol.ts b/app/g2/draw-protocol.ts new file mode 100644 index 00000000..1774b9be --- /dev/null +++ b/app/g2/draw-protocol.ts @@ -0,0 +1,14 @@ +/** Adapter for raster-only senders; optimized legacy layouts remain internal to the phone. */ +export function drawMessages(payload: Uint8Array, width = 640, height = 480): Uint8Array[] { + const word = (v: number) => [v & 255, (v >>> 8) & 255] + const mode = payload[0] & 127 + let calls: Uint8Array[] + if (mode === 8) { + const output: Uint8Array[] = []; let p=2 + for(let i=0;i new Uint8Array([26,1,0,...word(call.length),...call])) +} diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index 944fa312..493b3a87 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -26,7 +26,7 @@ export type FirmwareInfo = { }; /** The Faceclaw firmware revision this build of the app needs. */ -export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 23; +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 25; const FACECLAW_PREFIX = "Faceclaw/"; const LEGACY_PREFIX = "EVENCFW"; diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index dd0da9f6..de68485e 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,12 +19,12 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "393ea24203d9a388975c732cae4698339f8af0e13139b73d71386181a1bc004e", + "outputSha256": "986930903c6ea41ad7fd7ed15c73c0a1af00cc9b58604abfe2092a79745bb641", "patches": [ { "offset": 1045797, "old": "38b584b0", - "new": "59f3efbf", + "new": "5cf337be", "desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease" }, { @@ -36,49 +36,49 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1437923, "old": "fef788ff", - "new": "faf2fefc", + "new": "fdf246fb", "desc": "cfw_ancs_event" }, { "offset": 1437951, "old": "fef7e8fb", - "new": "faf238fa", + "new": "fdf280f8", "desc": "cfw_ancs_open" }, { "offset": 1437969, "old": "fef7e7fb", - "new": "faf24ffa", + "new": "fdf297f8", "desc": "cfw_ancs_close" }, { "offset": 1388387, "old": "39694d00", - "new": "e5317d00", + "new": "755e7d00", "desc": "connection-bound ANCS EUS write callback" }, { "offset": 971497, "old": "fff717f8", - "new": "6cf31ff9", + "new": "6ef367ff", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 971845, "old": "fef769ff", - "new": "6cf371f8", + "new": "6ef3b9fe", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 979579, "old": "fdf74ef8", - "new": "6af356f9", + "new": "6cf39eff", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 1428895, "old": "f8f76cfd", - "new": "f9f28afd", + "new": "fcf292f8", "desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)" }, { @@ -108,145 +108,145 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1248487, "old": "d4f712fb", - "new": "27f354fb", + "new": "2af3bef8", "desc": "bl settings_send_wrapper (append caps field 100)" }, { "offset": 1246183, "old": "f5f7e2f8", - "new": "27f374fd", + "new": "2af360fa", "desc": "bl settings_decode_wrapper (Faceclaw lease field 101)" }, { "offset": 975219, "old": "02f083fc", - "new": "69f3d6fd", + "new": "6cf3c2fa", "desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)" }, { "offset": 975411, "old": "02f023fc", - "new": "69f344fe", + "new": "6cf330fb", "desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)" }, { "offset": 975103, "old": "07f085fb", - "new": "6bf328f9", + "new": "6df370ff", "desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)" }, { "offset": 830549, "old": "19f03efb", - "new": "8ef3d7fa", + "new": "91f31ff9", "desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)" }, { "offset": 830795, "old": "1ff071ff", - "new": "8ef390fa", + "new": "91f3d8f8", "desc": "bl gesture_press (owned event 9 before stock menu gate)" }, { "offset": 830887, "old": "1ff043ff", - "new": "8ef38afa", + "new": "91f3d2f8", "desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)" }, { "offset": 831763, "old": "1ff08dfd", - "new": "8ef3c0f8", + "new": "90f308ff", "desc": "bl gesture_release (owned event 10 before stock menu gate)" }, { "offset": 1570209, "old": "7fb50600", - "new": "d8f2e5be", + "new": "dbf24fbc", "desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline" }, { "offset": 1051545, "old": "f6f787f9", - "new": "53f3cbfc", + "new": "55f3fbfb", "desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)" }, { "offset": 1051861, "old": "f6f7e9f8", - "new": "53f32dfc", + "new": "55f35dfb", "desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)" }, { "offset": 1262237, "old": "d9f7d0fd", - "new": "23f3b3fc", + "new": "26f333f9", "desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)" }, { "offset": 1262337, "old": "d9f79efd", - "new": "23f381fc", + "new": "26f301f9", "desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)" }, { "offset": 1309405, "old": "67f02dff", - "new": "17f39bfd", + "new": "1af319fa", "desc": "bl compass_decode_capture (sample-matched GAF diagnostics)" }, { "offset": 1307865, "old": "fff7c9fb", - "new": "18f319f9", + "new": "1af397fd", "desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)" }, { "offset": 1300937, "old": "00210170", - "new": "19f3fffd", + "new": "1cf37dfa", "desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)" }, { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fa5b04ef66c6a4ff29c5516460c46ccf2ff0ac2f229054ff6ff7800274ff00109019006e048f2a351c0f24501bff32f8f8847d5f800b0bff35f8f28680321cff680710140b1f1005fbff35f8f02d10168514543d04ff4417004f050fb002800f036810021421847540431b1f5417f57709770d770f6d1c0f800a080f80a90a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8055e8001f5945aed1bff35f8f00bf45e8000121b155e8001f5945f8d0a3e7a34644ea064100260127c0f8701206e048f2a351c0f24501bff32f8f88472c68bff35f8f28680321cff680710140b1f1005fbff35f8f02d10168514542d04ff4417004f0edfa002800f0d380002100bf421846540431b1f5417f56709670d670f6d1c0f800a08772a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8055e8001fa142afd1bff35f8f45e8000121b155e8001fa142f8d0a5e7d0f8746242f6f767c0f24407002ebff35f8f71d007f19a0230464ff0ff314ff0ff379047002840f0c28047f6df40c0f24f00804700274ff001090397adf8107007e000bf48f2a351c0f24501bff32f8f88472c68bff35f8f28680321cff680710140b1f1005fbff35f8f02d10168514567d04ff4417004f071fa002860d00021421847540431b1f5417f57709770d770f6d1c0f800a080f80a90a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8055e8001fa142b0d1bff35f8f00bf45e8000149b355e8001fa142f8d0a5e704460020b847b0b104f51d7151e8006f4eb9bff35f8f00bf41e8000292b151e8006f002ef8d00021bff32f8fbff35f8f21b1064672e74ff0ff373ce007f5a97188476be70121f1e70020019f42f6f769002f4ff00104c0f2440918bfbbf1000f2dd102ad8046284602f054f903ab38465946012205f0eefc9df8111007462846002918bf4ff0ff3702f0f6f9002c044608d19df8100028b94af21f30c0f247004c308047b8f1000f18bfc8f80c4009f5807130468847384625b0bde8f08f3a7802f07f01a1f1150313f1030f0bd802f07b030b2b07d002f07e02082a03d0032901d00629bdd140b14af21f31c0f247010446884794f8641111b14ff0ff37d6e720460024ade700bf2de9f0474ef66c6a4ff29c5548f2a359ccf2ff0ac2f229054ff6ff7600274ff00108c0f2450902e0bff32f8fc8472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168514535d04ff4417004f084f978b30021421847540431b1f5417f57709770d770f6d1c0f800a080f80a808683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142c6d1bff35f8f00bf45e80001002908bfbde8f08755e8001fa142f5d0b8e70020bde8f08770b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04f9db04ff29c50c2f22900d0f800b0bff35f8f58466ff39600b0f1005f3fd1dbf800004ef66c65ccf2ff05a84237d19bf8640110b3dbf86041fcb140f24030c2f20000d0f8787502a802f020f8002f00f0f18040f20308384621464ff41632cff680784ff6ff760197fff764fc48f2a35900240127c0f245091ce09bf8660170b1dbf8680140b147f64c61c2f207010968401a002801f3cc8700208bf8660140f6a120c0f247001db0bde8f04f0047bff32f8fc8474ff29c50c2f22900d0f800a0bff35f8f0068bff35f8f00ea0801b1f1005f02d10168a94236d04ff4417004f07df8002801f08c87002100bf421844540431b1f5417f54709470d470f6d14ff29c52056087728683c683068446848684c684068546858685c685068646868686c68606874687c2f2290252e8001f5145bdd1bff35f8f00bf42e8000121b152e8001f5145f8d0b2e7817a002941f05887027e0021002a8df814107cd04ff29c5605aac2f22906535c002b00f0b68053185f78002f74d09f78002f73d0df78002f72d01f79002f71d05f79002f70d09f79002f6fd0df79002f6ed01f7a002f6dd05f7a002f6cd09f7a002f6bd0df7a002f6ad01f7b002f69d05f7b002f68d09f7b002f67d0df7b002f66d01f7c002f65d05f7c002f64d09f7c002f63d0df7c002f62d01f7d002f61d05f7d002f60d09f7d002f5fd0df7d002f5ed01f7e002f5dd05f7e002f5cd09f7e002f5bd0df7e002f5ad01f7f002f59d05f7f002f58d09f7f002f57d0db7f002b56d0203160297ff49aaf76e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804701f0e8be4ff29c56c2f2290664e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0cf8300218df873100121427e002a00f0c280002205ab9f5c002f00f0a0809d186f78002f5ed0af78002f5dd0ef78002f5cd02f79002f5bd06f79002f5ad0af79002f59d0ef79002f58d02f7a002f57d06f7a002f56d0af7a002f55d0ef7a002f54d02f7b002f53d06f7b002f52d0af7b002f51d0ef7b002f50d02f7c002f4fd06f7c002f4ed0af7c002f4dd0ef7c002f4cd02f7d002f4bd06f7d002f4ad0af7d002f49d0ef7d002f48d02f7e002f47d06f7e002f46d0af7e002f45d0ef7e002f44d02f7f002f43d06f7f002f42d0af7f002f41d0ef7f002f40d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff053079f5411d013444b275e2a5f700cd049275d2a9f7008d050275c2adf7004d020275b2a1f7140f0f08100228df873200131827e002a00f0be80002105aa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df873100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d80002105aa535c002b00f0858153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0fc805f7a002f00f0fc809f7a002f00f0fc80df7a002f00f0fc801f7b002f00f0fc805f7b002f00f0fc809f7b002f00f0fc80df7b002f00f0fc801f7c002f00f0fc805f7c002f00f0fc809f7c002f00f0fc80df7c002f00f0fc801f7d002f00f0fc805f7d002f00f0fc809f7d002f00f0fc80df7d002f00f0fc801f7e002f00f0fc805f7e002f00f0fc809f7e002f00f0fc80df7e002f00f0fc801f7f002f00f00d815f7f002f00f00b819f7f002f00f00981db7f002b00f00781203160297ff47baf1de14cf67e22caf210127260002940f01981002105aa535c002b00f0dc8053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f68d01f7b002f69d05f7b002f6ad09f7b002f6bd0df7b002f6cd01f7c002f6dd05f7c002f6ed09f7c002f6fd0df7c002f70d01f7d002f71d05f7d002f72d09f7d002f73d0df7d002f74d01f7e002f75d05f7e002f76d09f7e002f77d0df7e002f78d01f7f002f79d05f7f002f7ad09f7f002f7bd0db7f002b7cd0203160297ff49aaface000211171f6e6013173e0023171e003316fe004316de0013184e0053169e0023180e0063165e003317ce0073161e0043178e008315de0053174e0093159e0063170e00a3155e007316ce000225a710fe60b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f08d8000218df87310002105af7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8731002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46f246bef15f0f98bf4ff05f0acaf1000805ad18eb0e0c53d0b2fbf3f40a2b04f1300105f80e104cf6cd41ccf6cc41a3fb011647d31cf1010142d004fb1324f708b4fbf7f905eb0e0209f13001517048f21f51c5f2eb11642ba3fb011635d31cf102012dd009fb17447709b4fbf7f6b3f57a7f06f13001917044f6d351c1f26201a3fb015124d31cf1030524d006fb1747890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea543305ada9d20ce0d6460ae00ef1010e07e00ef1020e04e00ef1030e00e0d64605ad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8731002694ff0000815f80810002900f0c78005eb08035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d008f12008b8f1600f7ff496af4ff060085ee008f101085be008f1020858e008f1030855e008f1040852e008f105084fe008f106084ce008f1070849e008f1080846e008f1090843e008f10a0840e008f10b083de008f10c083ae008f10d0837e008f10e0834e000220a7162e708f10f082ee008f110082be008f1110828e008f1120825e008f1130822e008f114081fe008f115081ce008f1160819e008f1170816e008f1180813e008f1190810e008f11a080de008f11b080ae008f11c0807e008f11d0804e008f11e0801e008f11f0801230a2a1ed364274ff47a7642f2107503eb83014900b2fbf1f40a2c11d303fb07f1b2fbf1f40a2c0bd303fb06f1b2fbf1f40a2c05d36b43b2fbf3f10929e7d800e00b46c646b8f15f0f98bf4ff05f0ecef1000942f2107c05ad19eb080a51d0b2fbf3f40a2b04f1300105f808104cf6cd41ccf6cc41a3fb011647d31af1010140d004fb1324f708b4fbf7f605eb080206f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd006fb17444e09b4fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1644890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114208f1040863454fea573305adabd20ce0f0460ae0f04607e008f1010805e008f1020801e008f1030805ad019f002205f80820a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df87300384602212a4608f0e5f9d4f870c272208df8140078208df8150020204ff0000a1ffa8cf28df816008df817a015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7642f2107503eb83004000b2fbf0f40a2c11d303fb07f0b2fbf0f40a2c0bd303fb06f0b2fbf0f40a2c05d36b43b2fbf3f00928e7d800e00346d146baf15f0f98bf4ff05f09c9f1000842f2107e18eb0a054fd0b2fbf3f005a900f1300401f80a404cf6cd41ccf6cc410a2ba3fb016442d36e1c3ed000fb1320e408b0fbf4f705a901eb0a0248f21f5107f13006c5f2eb115670642ba3fb011630d3a91c29d007fb14007409b0fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb011620d3e91c16d007fb1400b10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0ca4607e00af1010a04e00af1020a01e00af1030addf80490002205ac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a11863205e2a48700cd072205d2a887008d063205c2ac87004d020205b2a087140f0618100208df8730037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df80f1000f137010a2838bf00f13001ccf303508df8101000f137010a2838bf00f13001ccf303408df8111000f137010a2838bf00f1300100208df813001f208df81210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400260df10f05af5d8755b7b1b34211d0af1979788419617079b1b2420ad0b978a17051b1b64505d0f978e17029b10436b445e8d100208df8730042f2941845f29c1405aa48460e21c2f22008c2f2130407f093fe40f24031c2f20001c869a0425dd1886ab0f54d2f59d1c86aa04256d145f610630020c2f213034cf6394708f1040c002563454ad81c6834f003061cd098454ff0ff3228bf0c2c42d3a8eb03018e424ff0ff313ed82946ae4288bf3146e2071cbf0d4630449919013f01f10403e0d12ce0002048719ee60421b5f5807f1ed300222f46b7f5007f14d3b7f5806f13d3b7f5006f12d30901b2eb173f4fea1717f0d10ce000219171fef772bf00211172fef730bc490002e0890000e0c900634504d1494205ea0102014603e04ff0ff324ff0ff3147f64c60c2f20700d0f8840008f1080342f6941c9842c2f2270c4dd142f610644ff00009c2f2200446f6b9760cf1040a00254ff0ff3e4ff0ff3854453cd8276837f0030015d0a44528bf0c2f36d3aceb0403984234d8a8422b4688bf0346ff071cbf1d4681442044013e00f10404e4d122e00426b5f5807f17d34ff0000e2846b0f5007f0cd3b0f5806f0bd3b0f5006f0ad33601beeb103f4fea1010f0d104e0760002e0b60000e0f600544504d1704205ea000ec84603e04ff0ff3e4ff0ff3840f24037c2f200073b680cf1080083423ad1fb68b3f5333f36d13b69f246834233d14ff29c5043f21063c2f229004ff00009c2f2270342f6f936a0f1040ca0f1080e0027634520d81c6834f0030500f01e829e454ff0ff30009028bf0c2c17d3aeeb030085424ff0ff3011d83846bd4288bf2846e4071cbf0746a9445819013e00f10403ded100e0f2464ff0ff300090064666208df8140072208df8150065208df816008df817002f208df818006d204b238df8190061208df81d3069238df81a0078208df81e30422356278df81b0020208df81f303a238df82370472705ac8df81c008df820308df821004c238df824708df82600002720468df822308df825308df8277007f0c3fe019de05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f00e8100208df8730020464146524607f0eefd0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a713ed100208df8730005ac009a2046314607f021fd28461a21224607f09efb00208bf86401cbf8600101984ef2173105904ff41630069005a8c0f24701884701208bf8660102a800f0e2f8cbf810001db0bde8f08f0426b7f5807f1cd300253c46b4f5007f12d3b4f5806f11d3b4f5006f10d33601b5eb143f4fea1414f0d10ae00020c871c0e700214172f1e6760002e0b60000e0f60063457ff4daad734207ea030000904846d6e500bf2de9f04f81b0009041f204094cf65560cef20009ccf2ac50c9f8ac0f4ef6fc50cef2000001684ef66c6641f08071016059f8040c4ff29c5748f2a35bccf2ff06c2f229074ff6ff7440f0010000254ff0010ac0f2450b49f8040c02e0bff32f8fd847d7f80080bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14230d04ff4417002f063f8002862d00021421845540431b1f5417f55709570d570f6d1066080f80aa08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4145c5d1bff35f8f47e8000121b157e8001f4145f8d0bbe74169a9bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4219d0d9f80030176800bf1168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94203d0d9f80010c91a4161d9f800000099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c560968d0f800a048f2a358ccf2ff07c2f229064ff6ff7400254ff0010bc0f24508009103e000bfbff32f8fc047d6f80090bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94232d04ff4417001f0c1ff002800f08680002100bf421845540431b1f5417f55709570d570f6d1076080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448756e8001f4945c3d1bff35f8f46e8000121b156e8001f4945f8d0b9e74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094be047f64c6245f6e466c2f20702cff6f876136841f2040c3146cef2000c17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422ad0dcf80030176800bf1168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94214d0dcf8001044f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a5eb0a01b1fbf0f001b0bde8f08f00bf002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204606f0fdff854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0b180207887f00301084200f0ad80012039464246334600f076f90446002898f8080018bf0624a0e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f083804ef66c684ff29c5748f2a35b0294ccf2ff08c2f229074ff6ff7400264ff0010ac0f2450b02e0bff32f8fd847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168414533d04ff4417001f092fe002855d0002100bf421846540431b1f5417f56709670d670f6d1c0f8008080f80aa08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945c3d1bff35f8f00bf47e8000121b157e8001f4945f8d0b8e705eb450100eb011090f85d1201b300f513760024304629462a460323009407f00ff8706840b14bf69b71c0f25d018847706806f07ffe74603068b475002818bf06f078fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f0e8f8002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104606f0fcfe201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009506f0a2ff606840b14bf69b71c0f25d018847606806f012fe65602068a575002818bf06f00bfe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c6b4ff29c5648f2a35a8046ccf2ff0bc2f229064ff6ff7700244ff00109c0f2450a02e0bff32f8fd0473568bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168594532d04ff4417001f09efd60b30021421844540431b1f5417f54709470d470f6d1c0f800b080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa942c6d1bff35f8f00bf46e8000129b156e8001fa942f8d0bbe7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fdf7fbf8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c6b4ff29c5648f2a35a8846ccf2ff0bc2f229064ff6ff7700254ff00109c0f2450a09930792089003e000bfbff32f8fd0473468bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168594533d04ff4417001f012fd002800f0d1830021421845540431b1f5417f55709570d570f6d1c0f800b080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa142c4d1bff35f8f00bf46e8000121b156e8001fa142f8d0b9e70999089d01eb410100eb011095f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bf06f002fd2fe3207cf8b1607ce8b10799099a002520460323009506f07bfe606840b14bf69b71c0f25d018847606806f0ebfc65602068a575002818bf06f0e4fc089d00202060a06020822068002818bf06f0dafc00204ff480712060a0602182a978a081092004f11107e174a17426756076a07ca978884240f0da82217db14240f0d682411ca8f10b00627e02971e2828bf1e209042a17488bf6076a8f1020086b200270a2e4ff00008c0f0e682092241f22109092003961ae000bf20684f46002818bf06f0a0fca089276001302774a760a081002d18bf4ff00608089dd146ddf814a00aeb0b0082b2b24280f0c582217c80b20429824600f28880aa5c00f1010a4b1c0129237405dd022906d0032970d1e28106e021b9627503e0238943ea02222281b24580f0a88204296ed015f80a204ff0000c831c8f1c0129277406ddff290bd0032967460dd19a4652e000291cbf278947ea0222228100e062756746b34204d389e2e281b34280f08682022936d8ea5c00f1030acb1c0129237407dd022937d0fe2907d16275b2450cd374e231b9238943ea02222281b24504d36ce2e281b24580f0698202292fd015f80a20031d41f00407fc29277408ddfd2909d0fe291cbf278947ea0222228103e079b9e28100e062756746b34280f04e8209b19a4613e0ea5c00f1050a0520207401e09a466746e189208941ea0221e18128b106f00cfc0028206000f0688223896089191a1ffa81fb1ffa8af1721a5a45b8bf93465fea0b4208d02268294410441ffa8bf2fcf75dff60892389584481b2994260817ff44faf0026cdf81080d4f800808df82b60607db8f1000f06930df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d018847606806f0b6fb6760607e20760120e082cdf814a09eb1607da67d400714d4002e4ff0000500f0888106984ff6ff7381b2002900f00d8101295ed10020d2e0607d400753d4002577e14ff4803006f09bfb002e804600f06f81a07d002800f06b81b8f1000f00f067816668002e00f0ff8020890428c0f05f8121680a1812f8043c002b40f0588112f8033c002b40f0538112f8023cff2b40f04e8112f8012cff2a40f049814ff4803531607060c6f80c8035610028019000f065814bf69b70c0f25d0000f58572304600219047002840f032813169002900f02e8170688d420d46e7d1019a0d468242e3d124e14ff4803006f049fb05461fe1069a4ff6fe701040ac4642426ff0010000bf08eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1023000276546069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd14046fcf7d2fe00286ad141f2210a4ff00009012375e0382006f089fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377046f6fd00c0f200007844306246f60510c0f20000784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04738b3304606f01efa4546606841f2210a40b14bf69b71c0f25d018847606806f011fa67604ff000090323a77506980799099adde9036887b22046009706f088fb002d294605463ff457ad084606f0faf952e5666075e6c5f58030b5f5803f454606903760f7607ff648aecee70799099a002520460323009506f06afb606840b14bf69b71c0f25d018847606806f0daf965602068a575002818bf06f0d3f90020387000202060a06020824ff00a0840460bb0bde8f08f287a4006f8d5207c08b302980078e0b10799099a002520460323009506f03dfb606840b14bf69b71c0f25d018847606806f0adf965602068a575002818bf06f0a6f900202060a06020824ff00b082068002818bf06f09bf900202060a0602082cae702980078e0b10799099a002520460323009506f011fb606840b14bf69b71c0f25d018847606806f081f965602068a575002818bf06f07af900202060a06020824ff00608a7e700bf2de9f041f02846d100294ff00b0000f08880022ac0f0858045f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a0072d07578e91ec9b2fe2938bfbde8f081307833463946022829d0012866d1ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7d5fa20b306462846fff72cfb21462a46fff700fb3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac4219d1a1f1210010f1160f06d36ff0480048432330c0b2242810d90b20bde8f081b07a204207d04046394622462b46bde8f041fff788bb0020bde8f0811a4612f8020f40f00207032f18d19b796340032b14d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22fcf7bffa04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522fcf77bfa0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522fcf725fa4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2cd110684ef66c61ccf2ff01884225d1d2f8680110b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f8000308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff766ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c684ff29c5648f2a35a8346ccf2ff08c2f229064ff6ff7700254ff00109c0f2450a02e0bff32f8fd0473468bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168414533d04ff4417000f05afd00285bd0002100bf421845540431b1f5417f55709570d570f6d1c0f8008080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa142c4d1bff35f8f00bf46e8000121b156e8001fa142f8d0b9e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31bbf1000f18bf4ff0010bc0f2470c012010210a2387f85db101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff75efe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff6f540cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023a6e745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04568002d00f03e828368002b00f03a8205eb03080024002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310aeb0b03002443451d464ff0000680f02082a94619f9013b03f07f07a740002b46ea070610d406f00703012b16dc0bb3012b40f00e82a8eb0903082bc0f0098205f10903dee700bfc14580f00282182c04f107044d46dcd9fbe100bf022b3ad0052b40f0f681a8eb0903042bc0f0f1816b1dc7e7c14580f0ec8195f90130002b05f10203bed5434580f0e38195f90230b3f1ff3f05f10303b4dc434580f0d98195f90330b3f1ff3f05f10403aadc434580f0cf8195f90430b3f1ff3f05f10503a0dc434580f0c58195f90530002b00f1c081ab1d96e7c14580f0bb8195f9013005f1020a002b03f07f0b3dd5c24580f0b08195f90270eb1c07f07f04b7f1ff3f4beac41b02ddd1469a462de0434580f0a08195f9037005f1040a07f07f04b7f1ff3f4bea843b01dd99461de0c24580f0908195f9043005f1050c03f07f07b3f1ff3f4bea475b02ddd146e2460ce0c44580f07f8195f90530002b00f17a8105f1060a4bea037be146a8eb0a039b4500f27081f308672b19d0652b7ff441afbbf1060ffff43daf9af80030462b7ff438af99f80230432b7ff433af99f80330012b7ff42eaf0290cde9002115e0054650460e465946144600f081fb3146224628461ee748f2a3513046c0f24501bff32f8f8847dde9002102984ff29c53c2f229031c68bff35f8f1e68bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4240d04ff4417000f0fdfadde9002106460298002e3ff4f2ae00230025f718f5540433b3f5417f7d70bd70fd70f6d14ef66c63ccf2ff0333600123b3724ff6ff734ff29c57b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290757e8003fa342a6d1bff35f8f47e800632bb157e8003fa342f8d09ce7002599f8043099f8057099f80640032b47ea042734dd052b52dc042b6fd0052b7ff4aaaed6f868313bb147f64c67c2f207073f68db1b002b15dcd6f86c31002786f86671c6f86c71c6f800735bb10c4648f2a35181461846c0f245011546884721462a46484647f64c63c2f207031b6845f69077c0f201073b44c6f868317be6012b3ff46dae022b7bd0032b7ff474ae14468946fff706fc0346029849462246002b3ff469ae96f84231002b3ff464ae304641f28831a6f8407105f0edfc43e0062b45d0072b7ff457ae81464df6db50c0f24a0016460d46804703465f1e294632464846012f3ff647ae981eb0fa80f04009fff7bffc2946324648463ce614468946fff7cffb0346029849462246002b3ff432ae96f84231002b3ff42daeb6f84031bb427ff428aed6f83c310027002b86f84271a6f840713ff41eae42f68d411846c0f24401884702984946224613e6d6f86c31c6f86851002b86f86651c6f86c51c6f800533ff407ae0c4648f2a35105461846c0f245011646884721463246d9e696f84231c6f83851002b3ff4f4ad0546d6f83c0189461446002186f84211a6f8401120b142f68d41c0f2440188474af273670120002100220023c0f24607b847284622464946d6e54ff2a513c0f2490303b0bde8f04f184700bf7fb50646002806d1fff75efb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817046f29461c0f20001033079440b22fbf752fd0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522fbf71afd0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522fbf76bfc1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246fbf7c1fb4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b004297bd30c46014600784d2876d14878432873d18878012870d14ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010a894607e048f2a351c0f24501bff32f8f88474946d7f800b0bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424534d04ff44170fff76bff002843d04946002200bf831885540432b2f5417f5d709d70dd70f6d1c0f8008080f80aa08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f5a45bdd1bff35f8f00bf47e8000222b157e8002f5a45f8d0b2e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204649460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff69932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6f140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff3584e0cde901100120cff680704ef66c6b4ff29c5648f2a359ccf2ff0bc2f229064ff6ff77851c00244ff00108c0f2450902e0bff32f8fc847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168594533d04ff44170fff7c4fb0028ccd0002100bf421844540431b1f5417f54709470d470f6d1c0f800b080f80a808783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145c4d1bff35f8f00bf46e8000121b156e8001f5145f8d0b9e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff48daf00210025fff7e6fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff762fe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff798fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff69922cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7befd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef752fc014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef732fc0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef71ffc204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd45f21a70c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef76ffb0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22faf74dfd4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf797bf00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf755fec8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e52de9f04f9fb0804600284ff0ff302bd00e4649b398f8001001f07f070f2f15dc092f73dc052f00f0e581072f40f0ce824ef66c694ff29c57ccf2ff09c2f229074ff6ff7500244ff0010a17e0142f00f3fe80102f00f03282112f40f0b782022e08bf112900f0be831fb0bde8f08f48f2a351c0f24501bff32f8f8847d7f800b0bff35f8f38680321cff680710140b1f1005fbff35f8f03d10168494500f030854ff44170fef7b4fc002800f028850021421844540431b1f5417f54709470d470f6d1c0f8009080f80aa08583c583058445848584c584058545858585c585058645868586c5860587458757e8001f5945bdd1bff35f8f00bf47e80001002900f0ff8457e8001f5945f6d0b0e70a2f00f0dc810b2f40f05a824ff29c56c2f229063468bff35f8f20466ff39600b0f1005f41f0d68220684ef66c67ccf2ff07b8424ff0000090d1c4f8680184f8660184f86401d4f86c11c4f8600184f86501c4f86c01c4f8000329b148f2a352c0f2450208469047d4f87802002818bf03f080fc0021c4f87812206c40f2030942f68d48cff68079c0f24408a4f8441040b1c047206c08f166018847002804bf002020644bf63940c0f2510080473568bff35f8f05ea0900b0f1005f2bd12868b84228d195f877014ff0000ac5f880a188b149f25962c0f25902002044f2436185f877a190474ef6e37bc0f25a0bd8470bf1bc008047d5f8840185f870a150b1c047d5f8840108f166018847002804bf0020c5f884013068bff35f8f00ea0901b1f1005f41f096810168b94241f0928190f8a811002901f08781fef7d7fe01f089b9152f00f09c81162f40f0b981701e0228c0f08e8498f8010098f8021040ea0121b1f5007f4ff0ff303ff6f7ae032202eb410296427ff4f1ae002000298df83c008df83d008df83e008df83f008df840008df841008df842008df843008df844008df845008df846008df847008df848008df849008df84a008df84b008df84c008df84d008df84e008df84f008df850008df851008df852008df853008df854008df855008df856008df857008df858008df859008df85a008df85b008df85c008df85d008df85e008df85f008df860008df861008df862008df863008df864008df865008df866008df867008df868008df869008df86a008df86b008df86c008df86d008df86e008df86f008df870008df871008df872008df873008df874008df875008df876008df877008df878008df879008df87a008df87b003ff46dae08f103000fac01224378012b00f2f083077847ea0323db08e65c07f0070702fa07f7374240f0e483e65c013947ea060700f10200e754e7d1fdf7d9fc002800f0d78340f203094ef66c6a4ff29c57cff68079ccf2ff0ac2f229074ff6ff7500264ff0010bd8e34ef66c6b4ff29c55ccf2ff0bc2f229054ff6ff7700244ff0010a022e2cbf98f80100ff200c9006e048f2a351c0f24501bff32f8f8847d5f80090bff35f8f28680321cff680710140b1f1005fbff35f8f03d10168594500f01c814ff44170fef7ddfa0021002800f0e58200bf421844540431b1f5417f54709470d470f6d1c0f800b080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478755e8001f4945bcd1bff35f8f00bf45e80001002900f0ea8055e8001f4945f6d0afe7404631461fb0bde8f04ffef7a9be022efff4ccad4ef66c6a4ff29c55ccf2ff0ac2f229054ff6ff7700244ff0010906e048f2a351c0f24501bff32f8f8847d5f800b0bff35f8f28680321cff680710140b1f1005fbff35f8f03d10168514500f043814ff44170fef775fa002800f02983002100bf421844540431b1f5417f54709470d470f6d1c0f800a080f80a908783c783078447848784c784078547858785c785078647868786c7860787478755e8001f5945bcd1bff35f8f00bf45e80001002900f0118155e8001f5945f6d0afe7721e022afff46aad98f8010098f8021040ea0120b0f5007f0c9000f2ea824ef66c694ff29c5708f10100ccf2ff09c2f229074ff6ff744ff0000a06920b9089e00f2f9b4600f0d480a7f11300012840f2cf80092f00f06681082f40f0df81002a4ff0ff303ff43aad022efff437ad98f801a0baf1000f00f0c48202274ff00109ba1cb24200f2b58208eb070018f80710407851ea002100f0ac828f18b74200f2a88218f802005b4600f07f05153dedb2fd2d16d8c0b20f280dd9a0f183050c2d4ff0ff303ff60aad09fa05f541f24904254206d102e509fa00f548f248242542ebd008eb02000022fff7c4fc002840f08082baf1010ac3d183e290f844100c9d61b1016c39b142f68d42c0f244020446084690472046002180f844100121002d40f0c181032ec0f0be8198f80200082801f210804bf63941c0f251019631884701f008b848f2a3512846c0f24501bff32f8f8847d7f800b0bff35f8f3d680320cff680702840b0f1005fbff35f8f03d12868484500f064834ff44170fef782f9002800f05c830546002000bf291805f800a00430b0f5417f81f801a081f802a081f803a0f2d10120c5f80090a872ac83ec832c846c84ac84ec842c856c85ac85ec852c866c86ac86ec862c876c8757e8000f5845b6d1bff35f8f00bf47e80050002800f02d8357e8000f5845f6d0a9e7144601f02df8002800f0fb8108f10101142fa6f1010200f0ed81132f5b4640f0ed8101f0f3f8ebe198f80140002c6cd0022c00f2e68140f06c87062ec0f0e18198f8021098f8032098f8043098f8057041ea022143ea072232290f91109280f05287322100f054bf98f80100002840f0c88145f64d50c0f24600804701284ff000007ff433accde9100040f20830c0f210000f90ff208df8380044f25220c0f201000d9040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8372008d80721b0f5807f38bf03218df837108df8380040f2d260adf8400005200fac8df84200e01d0da90522f9f77dfc4ff22507c0f247070120092122460c23b8471fb0bde8f08f002480f8434145f64d50c0f2460080470146204601297ff4e4ab43f2a310c0f256001fb0bde8f04f004708064ff0210158bf11218e42c0f05f81002808f101070ad545f64d50c0f24600144680472246022818bf08f111073879797950ea01244ff0ff301ebfb979fb7951ea03263ff4b8ab397b7b7b41ea03218c427ff4b1abb97bfb7b41ea03218e427ff4aaab3878797840ea012804eb0800b0f5207f4ff0ff303ff69eabb978fb7841ea032a06eb0a01b1f5f07f3ff694ab397a7b7a41ea032904eb0901b1f5207f3ff68aabb97afb7a41ea0327f119b1f5f07f3ff681ab154600f038ff002800f00681414652464b46cde90146009702f059fcdbf800100f2909d80bebc1020131a2f80690178154819681cbf80010002d40f0f58000f09cbef81e18bf0120bb1f18bf012318424ff0ff307ff455ab032efff452ab032f00f09a81062f7ff44cab00200021144602f099fd00f0fffe002800f0cd80024608f10100711e4ff4f0774ff4a073009702f04ffe002800f0bf80dbf800100f2900f2bf800bebc1020023d38013814ff4207353814ff4f07301319381cbf80010afe00c9d0020002d3ff43fae012d1dd1052e1bd398f80230581e06284ff000003ff60fab98f8031003293ff60aab98f80420002a3ff405ab4bf63940c0f2510000f59a771846b84700f037be022d06d14bf63940c0f25100804700f02ebe032d40f0d080072ec0f0cd8098f8020098f8032098f8041040ea022098f8055098f8066001284ff0010498bf204644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0008645ea0621012988bf0c4642f68d41c0f24401a1f140022146904700f0f1bd0020022e2cbf98f80110ff21002800f0e885024602294ff0000026d0012920d000297ff4a2aa4cf67e21caf21011907610837960108150609583d583158455849584d584158555859585d585158655869586d5861587558782f83c001fb0bde8f08f0120907200f0bcbd90721fb0bde8f08f5b4601f047fa01e001f082fe20b14ff0ff301fb0bde8f08f002c00f0a985584602f0c2fa00f0a4bd48f2a351c0f24501bff32f8f8847d7f80080bff35f8f3868bff35f8f00ea0901b1f1005f02d10168514577d04ff44170fdf722ff0028d6d00021421846540431b1f5417f56709670d670f6d1c0f800a080f80ab08583c583058445848584c584058545858585c585058645868586c5860587458757e8001f4145c1d1bff35f8f47e80001002949d057e8001f4145f7d0b6e72a1f04460020b2fa82f2022e88bf012052091040084001284ff000007ff40faa4cf6cd42f11eccf6cc4298f80260a1fb0212b6eb920f88bf9608374604f14603302e28bf302708f1030107eb870280461846f9f774fa002e84f8447084f8458000f09085206c30b92046f9f7befd0028206400f0938542f68d41c0f24401a1f140020121904700f016bdd0f86c11864600294ff000003ff4d2a94ff400634ff0ff3c05e032681344b3f5802f80f07d84ce18b568b0eb552ff4d1ea08a25c05f00707fa40d2071ebf41f82500c6f808c0f060e7e7080600f13585082efff43aaf07250521012308eb030797f802904ff0ff30b9f1000f3ff4a2a9fc78002c3ff49ea918f803a04fea89030c950b9303eb8a03b3f5207f3ff692a97d78670007eb4503b3f5f07f3ff68aa908eb010018f8011040780a9241ea002081b2012002f0d0fb00f036fd00283ff404af0c9905eb850208eb010c00ebc2104fea4903711a00eb4a026046009702f081fc00283ff4f1aedbf800100f290cd84fea8a020bebc106f2800b9a6b00013133817281b781cbf800100a9900297ff4e4ae00f08bbc00250c9848b1fcf7d4ff0146002d4ff0ff3018bf00293ff442a90c984ff0000ab0fa80f040098df83ca08df83da08df83ea08df83fa08df840a08df841a08df842a08df843a08df844a08df845a08df846a08df847a08df848a08df849a08df84aa08df84ba08df84ca08df84da08df84ea08df84fa08df850a08df851a08df852a08df853a08df854a08df855a08df856a08df857a08df858a08df859a08df85aa08df85ba08df85ca08df85da08df85ea08df85fa08df860a08df861a08df862a08df863a08df864a08df865a08df866a08df867a08df868a08df869a08df86aa08df86ba08df86ca08df86da08df86ea08df86fa08df870a08df871a08df872a08df873a08df874a08df875a08df876a08df877a08df878a08df879a08df87aa08df87ba0cdb1d5f86c21ddf818e0b2b14ff4006304e03f683b44b3f5802f0ed2d718bc680134f6d07c68033424f003040aeb040101f1100aede7ddf818e00c9a4ff0020c002a00f0f480f21e0a2ac0f0f08000230df13c0b09930b9800eb0c0672784ff0ff30012a3ff688a8b378f478377943ea0423747943ea074141ea0469a9f1011313f5803f0791fff477a8317a737a059141ea03210cf10a040894aeeb04074c1ebc42bff469a8b779f679049747ea062eb9eb0e04fff460a8a1423ff65da80a910b98614610f80c404ff0010c44ea0220c2081bf8027004f007040cfa04f43c427ff4d5ad1bf8027044ea07044ff6ff77c0f203070bf802406db3d5f86cb1bbf1000f28d04fea062c1e024ff400620beb02039c68844240d01b681a44ba421ad80beb02039c68844237d01b681a44ba4211d80beb02039c6884422ed01b681a44ba4208d80beb02039c68844225d01b681a44ba42dbd9bef1000f7ff498ad0798fa1e03301040504400f1100a0df13c0b0a990898099b01eb000c0c98013383424ff0000028bf0120ddf818e04fd2aeeb0c02092a3ff65eaf49e058680df13c0b48457ff474add8687045fff470addfd90a9aa0eb0e0082423ff669ad002ad7d0059806eb000bcbf1000007900498abf101090ceb000208eb010c0a9903eb020e00230eeb03020ceb0306107cf47aa0427ff44dad994517d0547c377bbc427ff446ad0798c418a71c0ed0977c707b87427ff43dade01c07d0d07cb27b90427ff436ad04339b45dcd10df13c0ba1e700283ff42dadbceb0e004ff0000118bf0120baf57e3f88bf012101430c980028c1f100003ef491af00297ef48eafd5f86c91b9f1000f40f08b804ff48020fdf758fc00283ff40cad814600206ff02001002209eb020309f80200403209eb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff47e30c5f86c91c9f800080020c9f804084ff0ff31c9f80c084ff40060c9f80818c5f800034ff6ff740222c0f203044ff0000a09e00c980af1010a06eb080282454ff000003ef4ebae0b9800eb0206b178f379805c7778069196f8038096f804e096f805c0b1790893337a767a40ea072009960a900793bdb3012f35d84ff4006709eb070bdbf808000a9eb04200f0ae80dbf800000744a74226d809eb070bdbf808000a9eb04200f0a180dbf800000744a74219d809eb070bdbf808000a9eb04200f09480dbf800000744a7420cd809eb070bdbf808000a9eb04200f08780dbf800000744a742cbd903a880e806040698d5f800a340ea082040ea0e4040ea0c67f81c20f00300099e00f1100800200697baf1000f26d009eb0a0359f80a105a68414580f0a180eab109eb020059f80210d0f804a0414580f09280baf1000f11d009eb0a0359f80a105a68414580f08c8042b109eb020059f80210d0f804a04145d6d37ce0b34600204ff4006a4ff4006603e03e44b6f5802f23d209eb06018a6859f806700132f4d04868ca68033020f0030000f1100409eb0a001032f8f70bff49f80a404168c2688368d5f86c918a424ff00001a24408bf00f1100149f82310d7e7caf580210f294ff00002c5f8002311d909eb0a0049f80a104ff0ff3142608160c260c5f800a35e460be0dbf80c00dde9083664e05e4610b10268114401604ff0000a0020baf1000f00f0488109eb0a0359f80a105a68414525d2002a00f03e8109eb020059f80210d0f804a0414515d2baf1000f00f0328109eb0a0359f80a105a6841450fd2002a00f0288109eb020059f80210d0f804a04145d3d3834657469246184601e09b461746a1eb080110290ed30aeb080209eb020349f802104ff0ff315f60996000211746d960cbf800800df10c0a9ae80604089b00280cbfc5f80073476006984ff6ff74cbf804000a98c0f20304cbf808000020cbf80c0041ea0321079b814243ea062602f10a087ff4b0ae0bf1100778180b9932464144f8f71dfedbf80c10dbf804003144cbf80c10dbf80820d5f86c9181424ff0000018bf074649f8227094e690f8a911002918bffdf74cfd94f84301002684f8436158b145f64d50c0f246008047012804d143f2a310c0f256008047d4f83c0194f84251c4f8386184f84261a4f8406150b1c047d4f83c0108f166018847002804bf0020c4f83c010120002da07200f093804af27367c0f246070021002200230024b84720461fb0bde8f08f4ff0000c7246cef800c34ff400634ff0000e0de0bef1000fc7f804c00cbfc2f80033cef804303344b3f5802fbe466dd2cf18b868ce58013001d07746f3e7f418bceb944fe6d1081985680135e2d105682e443e6000680444bceb944f02bf0819856815f10105d5d105682e443e6000680444bceb944f02bf0819856815f10105c8d105682e443e6000680444bceb944f02bf0819856815f10105bbd105682e443e6000680444b4f5802fccd3b2e7b1f5fa6f02d94ff4fa610f910121054680f8431145f64d50c0f24600804701281dd143f2a316c0f25606a6f188008047022c08bf002801d058b910e04bf211020fa9c0f24b020220904740b10446b0472046002185f843111fb0bde8f08f00201fb0bde8f08f00204ff400684ff4006703e03744b7f5802f23d209eb07018a6859f807600132f4d04868ca68033020f0030000f1100409eb08001032f8f76ffd49f808404168c2688368d5f86c918a424ff00001a04408bf00f1100149f82310d7e7c8f5802200210f2ac5f8001331d909eb08034ff0ff3049f8082059609860d960c5f800831fb0bde8f08f0c2efff405aa98f8030098f8071088427ff4fea998f8040098f8081088427ff4f7a945f64d50c0f24600144680470523022808bf01230b2509212246fff7b1ba40461fb0bde8f08f00283ff4e1a9016811440160fff7dcb94bf6394025460024c0f2510085f844408047f8e600bf2de9f0474ef66c6a4ff29c5548f2a359ccf2ff0ac2f229054ff6ff7600274ff00108c0f2450902e0bff32f8fc8472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168514533d04ff44170fdf7f0f8002800f0a6800021421847540431b1f5417f57709770d770f6d1c0f800a080f80a808683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142c4d1bff35f8f00bf45e8000121b155e8001fa142f8d0b9e70446d0f87802002818bfbde8f0874ff4163002f0f7f800284ff0000169d00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f87802bde8f0870020bde8f087072a1cbf4ff0ff3070472de9f04f8db01c4688460890fcf7edf9002800f0828007944ef66c674ff29c5448f2a35accf2ff07c2f229044ff6ff7500264ff00109c0f2450a03e000bfbff32f8fd047d4f800b0bff35f8f2068bff35f8f01466ff39601b1f1005f02d10168b94230d04ff44170fdf709f8002854d00021421846540431b1f5417f56709670d670f6d1076080f80a908583c583058445848584c584058545858585c585058645868586c5860587458754e8001f5945c5d1bff35f8f44e8000121b154e8001f5945f8d0bbe7d0f86c214ff0ff3032b398f80110012922d898f8000040ea012752f82700c8b1811a88074ff0ff3016d16ff4802340f60f060b44cff6fc76b3420dd3531853f8080cb84206d153f80c2ca2f1011010f5803f04d24ff0ff300db0bde8f08f002b4ff0ff30f8d053f8047c9742f4d1c1f580218a42f0d8022aeed319780029ebd093f801e0bef1000fe6d00efb01f003f1020b4ff0000cf8b1951e00229542d9d00beb02073b781b0901d001270ee0ae1a012ecfd07b780bb1022707e0042ec9d3bb78ff7853ea0723c4d004279842c1d3c01a3a44e2d100e0002298f8020098f8033098f8047040ea032a98f8063098f8056098060f25cdf804e047ea062e03f00f0705eae07000fb07f589204543ed0a8df824500e2513f0200f08bf4ff00f0c08bf012507fb05f500fb05f54fead5258df825504ff00d0508bf022507fb05f500fb05f54fead5258df826504ff00c0508bf032507fb05f500fb05f54fead5258df827504ff00b0508bf042507fb05f500fb05f54fead5258df828504ff00a0508bf052507fb05f500fb05f54fead5258df829504ff0090508bf062507fb05f500fb05f54fead5258df82a504ff0080508bf072507fb05f500fb05f54fead5258df82b504ff0070508bf082507fb05f500fb05f54fead5258df82c504ff0060508bf092507fb05f500fb05f54fead5258df82d504ff0050508bf0a2507fb05f500fb05f54fead5258df82e504ff0040508bf0b2507fb05f500fb05f54fead5258df82f504ff0030508bf0c2507fb05f500fb05f54fead5258df830504ff0020508bf0d2507fb05f500fb05f54fead5258df831504ff0010508bf0e257d430cfb07f7454378430126ed0ac00a002a8df832508df8330000f0708103f0100086ea1010002402904ff00009cde9032b08e0dde90504039a0444ddf810b0944280f05c811bf8043006941e0901d0012013e0151b012d00f051810beb04077e780eb1022009e0042dc0f04881b878ff7850ea072600f042810420059013f00f0009aa12f800b018bf0120029a4fea0b1842ea000c16f003034f4600f08280b9fbf1f5002005eb0e07b7f1ff3fc8bf012000ea0c0001281ad105fb119000eb0a05e809042813d878090e2810d8089a07eb870002eb80106c08ed07075d6ff00f055a4604bf0f2542463d4015430555012b09f1010755d0b7fbf1f4002004eb0e05b5f1ff3fc8bf012000ea0c0001281ad104fb117000eb0a07f809042813d868090e2810d8089a05eb850002eb80107c08ff07025d6ff00f075d4604bf0f27454617403d430555022b09f1020729d0b7fbf1f5002005eb0e04b4f1ff3fc8bf012000ea0c0001281ad105fb117000eb0a05e809042813d860090e2810d8089a04eb840002eb80106c08ed07025d6ff00f055f4604bf0f25474615403d43055509f10307701eb144089e032804d241e70437b9453ff43eafb7fbf1f4002004eb0e05b5f1ff3fc8bf012000ea0c00012819d104fb117000eb0a04e009042812d868090e280fd805eb850006eb80106508425de4076ff00f045b4604bf0f24434622401a4342557c1cb4fbf1f0002200eb0e05b5f1ff3fc8bf012202ea0c02012a19d100fb114000eb0a04e009042812d868090e280fd805eb850006eb80106208835ce5076ff00f055c4604bf0f2544462b4023438354bc1cb4fbf1f0002200eb0e05b5f1ff3fc8bf012202ea0c02012a19d100fb114000eb0a04e009042812d868090e280fd805eb850006eb80106208835ce5076ff00f055c4604bf0f2544462b4023438354fc1cb4fbf1f0002200eb0e05b5f1ff3fc8bf012202ea0c02012a7ff476af00fb114000eb0a04e00904283ff66eaf68090e283ff66aaf05eb850006eb80106208835ce5076ff00f055c4604bf0f2544462b402343835458e70aeb01000199b0f5207f7144a8bf4ff42070b1f5f07fa8bf4ff4f071079f504588bf714503d800200db0bde8f08f3b680f2bf8d8a0eb0a0007ebc302a1eb0e015081581ca2f806a0a2f808e091813860e9e7082a3cbf4ff0ff3070472de9f04f95b015460c46cde90f30fbf7aefe00287bd0e17901f10800854240f0a380207867780d91a1794ef66c664ff29c5a40ea0720ccf2ff06c2f2290a4ff6ff784ff0000b4ff001090c910e9007e000bf48f2a351c0f24501bff32f8f8847daf80050bff35f8fdaf80000bff35f8f01466ff39601b1f1005f02d10168b1424ad04ff44170fcf7bcfc00286cd0002100bf421800f801b00431b1f5417f82f801b082f802b082f803b0f2d1066080f80a90a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a805ae8001fa942abd1bff35f8f4ae8000149b15ae8001fa942f8d0a1e74ff0ff3015b0bde8f08fd0f86c114ff0ff300029f6d0012ff4d80e9851f82000d8b1431a98074ff0ff30ebd16ff4802240f60f071a44cff6fc77ba42e2d301eb030a5af8080c0e99884206d15af80c2ca2f1011010f5803f04d24ff0ff3015b0bde8f08f5af8040c90424ff0ff30c9d1c3f580218a42c5d8baf1000fc2d0c02ac0d30c9d0f21a80605f00f0701eae070784389235843c00a8df844000e2094f802c0e67894f804e094f805b015f0200f08bf012007fb00f003fb00f04fead0208df845004ff00d0008bf022007fb00f003fb00f04fead0208df846004ff00c0008bf032007fb00f003fb00f04fead0208df847004ff00b0008bf042007fb00f003fb00f04fead0208df848004ff00a0008bf052007fb00f003fb00f04fead0208df849004ff0090008bf062007fb00f003fb00f04fead0208df84a004ff0080008bf072007fb00f003fb00f04fead0208df84b004ff0070008bf082007fb00f003fb00f04fead0208df84c004ff0060008bf092007fb00f003fb00f04fead0208df84d004ff0050008bf0a2007fb00f003fb00f04fead0208df84e004ff0040008bf0b2007fb00f003fb00f04fead0208df84f004ff0030008bf0c2007fb00f003fb00f04fead0208df850004ff0020008bf0d2007fb00f003fb00f04fead0208df851004ff0010008bf0e2007fb00f003fb00f04fead0204ff000018df8520008bf0f21794359430d9b0020c90a002b8df853103ff4f6ae04f108084cea06204eea0b2ea2f1020c00220b9003e00d98013282424bd018f80200411e1f29f6d341b22029fff609af0aeb400010f8401c10f83f0c41ea0027c02f4ff0ff30fff4d1ae67453ff6ceae1af80730002b3ff4c9ae0aeb07014e78002e3ff4c3ae881c06fb03f50023d9198c453ff4e6aec6183478240901d0012612e0aceb010101293ff4dbae74780cb1022609e00429fff4d4aeb178f67851ea06243ff4ceae0426a542fff4caae2d1b3344dcd1afe70f980121063000900c98002600f0100081ea10100790cdf830e0cdf814c0cdf8048018f806001f2804d80b990844a0f10b0228e20aeb400010f8401c10f83f0c41ea0027c02f4ff0ff30fff474ae67453ff671ae1af80720002a3ff46cae0aeb0703597800293ff466ae01fb02f00b9d0028cde9021600f0d1819d1c00240a95e1198c453ff482ae2e1933781b0901d0012615e0aceb010101293ff477ae73780bb102260ce00429fff470aeb178f37851ea03233ff46aae0a9dddf814c004269842fff463aec01a3444d9d1dde90b5e002c00f0a38100270021069406e0dde90807069c0744a74280f098810a980997c35d5fea131902d00120089012e0e01b012800f08b810e460a990f4497f80190b9f1000f00f076810220ddf830e00b9d0890314613f00f0311a810f8038018bf0123079819f0030740ea030b4fea08108c460e9000f09680b1fbf2f6002406fb12132b44b3f1ff3fc8bf012404ea0b04012c1fd116eb0e061cd4dc09042c19d874090e2c16d8109806eb860600eb86105c08065ddb076ff00f0c049008bf4ff00f0c43460e9808bf034606ea0c06049833430355012f01f1010c63d0bcfbf2f4002604fb12c304912b44b3f1ff3fc8bf012606ea0b06012e1dd114eb0e061ad4dc09042c17d874090e2c14d8109806eb860600eb86115c080d5ddb076ff00f0c434608bf4ff00f0c0e9808bf034605ea0c0633430b5504990b9d022f01f1020c30d0bcfbf2f3002603fb12c02844b0f1ff3fc8bf012606ea0b06012e1dd10c995b181ad4c609042e17d85e090e2e14d803eb8306109b444603eb86134608c00713f806c06ff00f0008bf0f2000ea0c000e9908bf0c46204398550499dde90b5e01f1030ca9f10103032b494406d22ee70cf1040c4946e1453ff429afbcfbf2f4002604fb12c389462b44b3f1ff3fc8bf012606ea0b06012e1ed114eb0e041bd4de09042e18d866090e2e15d8109804eb840400eb84145e08a15ddb076ff00f03c64608bf0f230e9808bf8646194041ea0e01ddf830e0a1550cf10101b1fbf2f404fb12114b190021b3f1ff3fc8bf012101ea0b0101291bd114eb0e0418d4d909042915d861090e2912d8109804eb840100eb81115e08db078c5d6ff00f0308bf0f2340460e9f08bf38462340184388550cf10200b0fbf2f404fb120043190020b3f1ff3fc8bf012000ea0b0001281cd114eb0e0419d4d809042816d860090e2813d8109904eb840001eb80105908db07465c6ff00f0308bf0f23444603ea06030e9f08bf3c46234343540cf10300b0fbf2f404fb120043190020b3f1ff3fc8bf012000ea0b0001287ff462af14eb0e043ff55eafd80904283ff65aaf60090e283ff656af109904eb840001eb80105908db07465c6ff00f0308bf0f2344464546ddf8388008bf4446a8460b9d3340234343543de7dde90b5e042807d33146be78ff7856ea072901d004206ee602982a440eeb0003b2f5207f174625eae570a8bf4ff42077b3f5f07fa8bf4ff4f07387421add0c998b4217d90f990e680f2e13d8ddf830e0009da3eb0e013b1a05ebc60725f836000f98ddf80480f980711ca7f802e0bb80016003e0ddf80480ddf830e0039eddf814c00d99013600208e420b927ff4c7ad4fe4062a3cbf4ff0ff3070472de9f04fadf2944d9a46154688460f90fbf76ffa002800f0d68098f80510881d854240f0298447f65420c2f20700d0f800b0bbf1000f00f01f849bf80c009bf80d209bf80e309bf80f7040ea022040ea034040ea0769a9f1810010f1800f4ff0ff30c0f0b2809bf810209bf811309bf8137042ea03229bf8123042ea034242ea07620692813a12f5817f40f29e800029cdf828b000f09d8008f1060b002426aa4ff4e01c00270ae000bf05f1004042f8240001378f4204f1010480f08e801bf80750681e1e28f0d968b21f2801dd012075e0a5f1c2000beb07061d28a1eb07000fd8012800f0c88396f9010010f1410f00f3c28300f03f0365f38a1302201d465de005f0f003e02b24d10328c0f0b48396f9013013f1410f00f3ae8396f9020010f1410f00f3a883e02ddeb202d1a02ec0f0a283ed2d02d19f2e00f29d832b039bb206f03f0643ea861300f03f001d18032034e004284ff0ff3036d3a5f1f50313f1050f31d396f9013013f1410f2cdc96f9020010f1410f00f37e8396f9036016f1410f00f37883f02ddbb202d1902bc0f07283f42d02d18f2b00f26d830cea854e03f03f054eea053300f03f0043ea801006f03f0326aac518042000bf074442f8245076e74ff0ff300df2944dbde8f08f0021012007915ee0002c57d0a4f1010bcdf86090cdf810a000250df1780a5f46914608e026aaab4505f1010509f10409a7f1010739d052f825100029f3d400202b4687421dd009eb80067268b2f1ff3f18dc5a1c934514d0b268b2f1ff3f11dc9a1c93450dd0f268b2f1ff3f0adcda1c934506d032690433002a00f10400e0d400e000220a9853461aae009600f0f6ff002800f008831a980028c3d04af20d315046c0f24e018847bce7ddf810a0ddf828b0ddf860900020079404e00020ddf828b00790012098f804400f21a20604f00f0501eae271694389225143c90a8df8681001260e2198f800c098f801e098f8023098f8037014f0200f08bf0e2608bf012105fb01f102fb01f14fead1218df869104ff00d0108bf022105fb01f102fb01f14fead1218df86a104ff00c0108bf032105fb01f102fb01f14fead1218df86b104ff00b0108bf042105fb01f102fb01f14fead1218df86c104ff00a0108bf052105fb01f102fb01f14fead1218df86d104ff0090108bf062105fb01f102fb01f14fead1218df86e104ff0080108bf072105fb01f102fb01f14fead1218df86f104ff0070108bf082105fb01f102fb01f14fead1218df870104ff0060108bf092105fb01f102fb01f14fead1218df871104ff0050108bf0a2105fb01f102fb01f14fead1218df872104ff0040108bf0b2105fb01f102fb01f14fead1218df873104ff0030108bf0c2105fb01f102fb01f14fead1218df874104ff0020108bf0d2105fb01f102fb01f14fead1218df8751006fb05f102fb01f14fead1218df876104ff0000108bf0f2169435143c90a00284ff000008df877107ff4cdae43ea0720079a484403904cea0e290af10600571e00260df198080190cdf810a0029718e000bf4af20d311ea8c0f24e0188479df87c009df87d10dde90ab9029fdde9072640ea01200df1980801369642814400f0ff8158f82610b1f1ff3f1edd33469f421fd008eb83004268b2f1ff3f1adc0133bb4216d08268b2f1ff3f13dc0133bb420fd0c268b2f1ff3f0cdc0133bb4208d002690133002ae2d404e001f01f000b38d2e7002258461eab19ad009500f0b5fe002800f0c781199900290d9100f0ba819df880209df881309df87e009df87f1052ea03259df8822040ea01279df8833010979df884704fea024208969df8856042ea0362069b4fea074747ea06672b4403eb2743039fcdf82c90a7eb030609eb22491aaf149500f05e810902109b014400f0030809f101004ff0010c099009f102000ceb530305900d980c934b1e0e930b9b0130121415900ceb510003eb020e9a1acde91180a1eb08001890d0074ff0000a17904feace70169013960ae014980af1010a824512981599139e0144159100f029810aeb06014b090e2befd810980028ecd00e9801eb810103280f984ff0000600eb811e80f0848011980028ded0dde90c105feac67c0afb01084fea560018f8000000f00f03c1b208bf0b09b3fa83f0400910ea141f14d106eb0901c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef8002011980128b1d0701c400818f80000bcf1000fc1b24fea111308bf00f00f03d8b2b0fa80f0400910ea141f14d109983118c80904280fd848081ef80020fb5c02f00f0b02f0f0021a431aafc90708bf4bea03120ef80020119802283ff486afb01c400818f80000bcf1000f00f00f01c2b208bf1109b1fa81f0400910ea141f7ff474af05983318d80904283ff66eaf58081ef80020795c02f00f0602f0f0020a43db0708bf46ea01120ef800205de7ddf8548007e000bf18980436b04208f102083ff471af18f8011c0023c9b2102938bf012313ea141f09eb060c16d14feadc13042b12d84fea5c0309091ef80320795c02f00f0b02f0f0020a431aaf5feac97008bf4bea01120ef8032018f8010c00f00f01b1fa81f0400910ea141f15d10cf10103d809042810d858081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003098f80000c1b210294ff0000038bf012010ea141f15d10cf10203d809042810d8080959081ef80120385c02f00f0302f0f002169d0243002d08bf43ea00120ef8012098f8000000f00f01b1fa81f0400910ea141f8ad10cf10303d80904283ff685af58081ef80020795c02f00f03179d43ea011302f0f002002d08bf42ea01030ef8003072e700bf109809eb00011498b1f5207f06eb000229eae970a8bf4ff42071b2f5f07fa8bf4ff4f072ddf810a081427ff70fae26eae6739a427ff70aaedaf800700f2f3ff605ae019dd21a091a05ebc70625f83700781c7380b180f280caf80000f6e59df87c009df87d10079a40ea012001e64ff0ff300df2944dbde8f08f00200df2944dbde8f08f2de9f04f83b04ef66c6b4ff29c5648f2a35a8046ccf2ff0bc2f229064ff6ff7700244ff00109c0f2450a02e0bff32f8fd0473568bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168594533d04ff44170fbf750fc00285cd0002100bf421844540431b1f5417f54709470d470f6d1c0f800b080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001fa942c4d1bff35f8f00bf46e8000121b156e8001fa942f8d0b9e70446fef703fb002c18bf002805d1012088f8050003b0bde8f08fc4f8600101254ff4f07084f8645101904ff420704af61f470090c0f2470700200021002200230026b84700280fbf88f8045084f86461c4f8606188f8055003b0bde8f08f0024cfe700bf2de9f04f87b0dde91065924643ea0102ddf848b02a43d20722d14fea550800eb510900eb5304abf1010700252846564588bf384600eb0a01304401eb810100eb800009eb811104eb80104246f6f7beff013f781c05f10105e8d107b0bde8f08f4ff6fc722a4005f0030406926a1e002701920494cde902a005e000bf059f039801375f45e9d0fa435645059788bf0beb020707eb0a0202eb820200eb821cba1902eb8202042d00eb821e4ff00008c0f09c80ddf8049000bf40468b4288bf484600eb010200eb03044fea52001cf800706ff0010088ea000608f1010088bfa8196ff0020686ea080608f1020b88bf05eb060b6ff0030686ea080608f1030a4feac27288bf05eb060a07f00f06002a4fea540208bf3e091ef80270e40707f00f0407f0f007374408bf44ea06170ef80270421854081cf804401844d20704f00f064fea500208bf26091ef80240c00704f00f0004f0f004344408bf40ea06140beb01000ef8024042081cf802200beb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef800200aeb010042081cf802200aeb0304c00702f00f064fea540008bf16091ef80020e40702f00f0402f0f002324408bf44ea06120ef80020069808f104088045a9f104097ff46dafddf808a0109eddf848b0049c002c3ff446af6fea080047468b4288bf2f18781842081f441cf80220c0074fea57091ef8090002f00f0408bf140900f00f0200f0f0002044ff0708bf42ea0410049c0ef80900012c3ff423af08f10102a5eb08098b4288bfa9f102025418670802eb030ae4074fea5a041cf807701ef8042007f00f0002f00f0b02f0f00208bf380902445feaca77ddf808a008bf4bea00120498109eddf848b00ef80420049c02283ff4f6ae08f102008b4288bfa9f10300421854081cf8047000eb030cd2074fea5c021ef8020007f00f0400f00f0800f0f00008bf3c0920445feacc7708bf48ea0410049c0ef80200d2e600bf2de9f04f81b04ef66c664ff29c5748f2a35b8146ccf2ff06c2f229074ff6ff7400254ff0010ac0f2450b009103e000bfbff32f8fd847d7f80080bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14232d04ff44170fbf753fa002800f09180002100bf421845540431b1f5417f55709570d570f6d1066080f80aa08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4145c3d1bff35f8f47e8000121b157e8001f4145f8d0b9e70121b9f1000f017237d0014631f81c2f009b9a422cd0c28b9a4229d0028c9a4226d0428c9a4223d0828c9a4220d0c28c9a421dd0028d9a421ad0428d9a4217d0828d9a4214d0c28d9a4211d0028e9a420ed0428e9a420bd0828e9a4208d0c28e9a4205d0028f9a4202d0428f9a4208d10121817601b0bde8f08f417201b0bde8f08f427a72b98288009b9a1a13b2b3f1ff3f05dd92b2022a24bf0122427601e00122027600224272009ac38882809a4284bf009ac28090f83c20009b21f81230511c01f00f0180f83c1001b0bde8f08f2de9f04f89b0129f029003fb07f000294fea400b069300f0d58100200890029807924ff0010a4ff000084ff0000e002400264ff0000c0022009107e04ff0000c03244e4601328a4200f0c181bcf1000f40f0bb8110f80290022cefd0012c15d0ddf81cc0129b002c554640f095805fea191409f00f070596089700f09b80a34580f0a1804ff0010c002499e1ddf81cc0129bb9f1000f00f08980cb45c0f0828008980392069a5546abeb090b00eb001700010596cdf810b0019016e010f80810089e01f0f001314300f8081008f10108a9f101090125904524bf4ff000080ef1010eb9f1000f00f062819e4580f05a810eeb8e00002d0ceb8010dfd0a2eb0801b1eb590f88bf4fea590169b38c0800eb080b1cd000220bf10106a2eb840a6ff0030c00bf06eb0c020cf1040c0aeb0c040434d770177157719771f3d10cf10406dde9062c129b11f0030404d10ce0002611f0030408d0012c0bf8067004d05e44022c777018bfb770a9eb4109b9f1000f88440dd09045aed210f80810019c01f00f012143a9f10109002500f80810a8e74ff000099fe700bf56ea09260ed0b34580f088804ff0010c00244be74ff0000c022447e74ff0000c012401e14ff0010c002400263ee708980392069aabeb040b00eb00170001cdf810b0019015e000bf1af80800089900f0f00008440af8080008f10108013c0125904524bf4ff000080ef1010e002c00f0d2809e4580f0ca800eeb8e00002d0ceb801ae1d0a2eb0800b0eb540f88bf600880b381080aeb08091ed00022ab4609f10106a2eb81016ff0030c00bf06eb0c020cf1040c01eb0c050435d770177157719771f3d10cf10401dde9062c129b5d4610f0030604d10de0002110f0030609d0012e09f8017005d04944022e4f7018bf8f7000bfa4eb400480446cb19045afd21af80800019900f00f000843013c00250af80800aae700bf0024a1e708980392069aabeb060b314600eb00170001cdf810b00190059613e01af80800089e00f0f00030430af8080008f1010801390125904524bf4ff000080ef1010e00295ad09e4553d20eeb8e00002d0ceb801ae3d0a2eb0800b0eb510f88bf480880b384080aeb08091ed00022ab4609f10106a2eb84046ff0030c00bf06eb0c020cf1040c04eb0c050435d770177157719771f3d10cf10406dde9062c129b5d4610f0030404d10de0002610f0030409d0012c09f8067005d04e44022c777018bfb77000bfa1eb4001804479b19045b1d21af80800019c00f00f002043013900250af808000029add107e000bf0021a1e7aa464ff0010c002403e0aa4600244ff0000c0df1080b00999be80508059e3fe60120012106e04ff0010cb4fa84f08cf001014009bbfa8bf252091140084009b0bde8f08f014640f258304df69f22c2f20000c0f248021047b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf2de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f081f0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f6f77ff906f1210506f1280029460722f6f777f9284621460722f6f772f920465146032207f10905f6f76bf906f11d0049460422f6f765f9f07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f6f739f9a81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0b7e50846abe570b50446d0f83c0142f665360d46c0f2440668b949f6a960cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3233000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a8900000000000000000000000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff690454ef66c6b4ff29c591446cff6ff75ccf2ff0bc2f229094ff6ff78002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7007f0b4f8002800f0eb8129464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001f51457ff445afbff35f8f00bf49e8000121b159e8001f5145f8d039e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7006f0e6ff002800f01d8129464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb9427ff445afbff35f8f00bf49e8000121b159e8001fb942f8d039e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f08f810f98002861d00e980778a7f1170002285bd80f980c2840f078810e9e7078b178084300f07281f0780138022800f26d81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f07f83172f40f09583002a40f05481fe2800f0cb87812800f0bd87002840f0d28751ea030040f0478101f062b904460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0e78051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0d680824692e74ff0ff3729e147f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0b3804ff45c7006f09afe002800f0ab8029464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f00bf49e8000159b159e8001fa142f8d039e706f5a9718847bae601211ee700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0e1f94ff0ff3701269df84900002810a818bf4ff0ff3704f0fffa054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f0a0f90e98007800f07f040f2c2ddd142c40f3a981152c00f01183162c00f01c831d2c40f0da830f9801380228c0f04f850e994878897840ea0124b4f5007f00f2468504eb4400032101eb40000f99884240f03d8505f02ffe002800f038850c96002601270f9400f055bd092c00f3d180052c00f00c82072c40f0af83002706e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f085864ff45c7006f033fd002800f07d86294600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed10121c0f800b08172a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff443afbff35f8f49e80001002900f0db8559e8001fa142f6d036e70a2c00f043810b2c40f0de82d9f800500320cff680702840b0f1005fbff35f8f41f0f0822868002758457ff4a3aec5f8687185f8667185f86471d5f86c01c5f8607185f86571c5f86c71c5f80073a5f86c7320b148f2a351c0f245018847d5f87802002818bf09f0bff80024c5f87842d5f868030c9620b148f2a351c0f245018847c5f86843a5f86c43286c42f68d46c0f24406a5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f41f0a9810168594541f0a58190f8a811002901f09a8106f044ff01f09cb9102c00f07081112c40f034820f994ff0ff37022908bf11287ff402ae0e98407800287ff4fdad45f64d50c0f24600804701284ff000077ff4f3ad40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff7ccf94ff22507c0f247070120092132460c23b84707462646afe500294ff0ff3708bf002b7ff4d6ad1328bff4d3ad102a4ff0000138bf01211228b2fa82f218bf510901297ff4c6ad00f0dfbd182f4ff0ff3708bf00297ff4bdad002b7ff4baad352800f33283002800f0b785012800f0c385312840f0b585082abff4abad00f0c4bd0f980c960228c0f000820e984078fde10f980228c0f014830c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0e8824ff45c7006f01cfb002800f0a78729464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0408259e8001fa142f6d038e70e980f990130013907f057fe07469ce4dde90e0106f0ddfe074696e40f9801380228c0f036820e994ff0ff374878897840ea0120b0f5007f3ff687ac03210f9a01eb400191427ff480ac002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff4fcab0e9935aa03314ff0010c4b78012b00f297810f7847ea0323db08d45c07f007070cfa07f7274240f08b81d45c013847ea040701f10201d754e7d105f075fa002800f07e810c960027012645e300f07e001a2818bf1c2c40f0738105f065fa002800f06e8101f03ef9814608f071fab9f1000f4ff0ff3718bf00283ff4bdab1b2c00f096851a2c40f0c08504460e984ff48052471c0f98b346461e4ff4a0704ff4f07135924ff0000835aa4ff42075cde90382cde901104846394632462346cdf8d880cdf8ec80009508f0dafd002840f0e3854ff48050cde9350835a80490012003904ff4a07002904ff4f070019048463946324623464ff42077cdf8ec80009708f0befd074600f0c9bdff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7006f022f9002800f0b58229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e8000121b159e8001fa142f8d03ae790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f2d9864bf63941c0f25101963188470027fff788ba0f9a052a39d3012d37d10e9a00279078411e06293ff67caad17803293ff678aa1279002a3ff474aa4bf63943c0f2510303f59a7398470027fff76aba0e990c9e4c78002c00f0eb80022c05d840f07e860f99062980f0bd844ff0ff37fff758ba362800f09d82462800f09782572840f08382002e7ff479aa92e2022d40f02a814bf63940c0f2510080470027fff740ba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0a1834ff45c7005f0f0ff002800f07b8429464218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800b08772a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0f98259e8001fa142f6d038e7002780f8437145f64d50c0f24600804701287ff46ea943f2a310c0f2560080470746fff766b90c294ff0ff377ff48ea9b3f5005fc0f0a581fff788b9481e1f284ff0ff373ff682a9c1f51630834240f29881fff77bb9002b7ff476a9421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f07d81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f070819f284ff0ff377ff450a9042900f06881fff74bb90f9a072ac0f0b082032d40f0ad820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0ca8244ea0521012988bf0e4642f68d41c0f24401a1f140023146bbe200200f99022902d30e99497800e0ff21002800f0228502294ff0000736d0012930d000297ff4d1a84cf67e21caf2101187760783c9f8041007814760a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8080f83c70fff7a3b801218172fff79fb88772fff79cb8dde90b5600210020fce548f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ee824ff45c7005f047fe002800f0d28229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0468259e8001fa142f6d038e7022abef4faaf13e0002a7ef4f6afa0f1fd0102290cd397287ef4efaf08e06ff0780002427ef4e9af02e0402abef4e5af45f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fef7d1bf48f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7005f054fd00283ef4aeaf29464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08472a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb1427ff445afbff35f8f49e8000121b159e8001fb142f8d03ae74af21f35c0f247050446a84794f864010e9a00287ef4feae94f80403214600287ef4f8ae107817281bd0d1f8640342f68d46c0f2440668b947f2bf00c0f20000a6f594777844012100220023b847c4f8640340b3a6f140024ff47a719047214608bb01f206300e460e990c22fef7b7fa0d98002186f805030120bff35f8f86f804034ff4f07001904ff4207005f5106600900020002200230027b04700283ef4bbae84f8047305f14c0080474ff0ff37fef7b2bed0f86c110a90002900f0198100204ff4006205e01b681a44b2f5403f80f0ca808b189f680137f5d05f68033727f0030738441030eee70f9a0027032afef465ae2a1fb2fa82f25209b046114000f0f4800f994cf6cd420339ccf6cc42a1fb02120e9900f146038c780331b4eb920f88bf94082546302c28bf302505eb850206461846fef752fa0027002c86f8445086f8457000f0d180306c344630b9204600f0cafc0028206400f09b8342f68d41c0f24401a1f140020121904700274646fef724be02460f9803287ef41fae0e9934464878897840ea01264ff6ff70864200f05f824ff480503590002035a936903b90cde902014ff4a07001904ff4f077484631464ff4207300970af0b1f9002800f047824ff0ff372646fef7f7bd04460f9801287ef4f2adb34607f0e3fde8b30646b9f86c03002800f048834ff48051a0f101084ff4a0703591002535a94ff4f0770391cde901054846414632464ff4207336953b9500970af082f9f0b9304621464ff41632fef7d9f94ff48050cde9350535a80390012002904ff4a07001904846414632464ff420734ff4f0773b9500970af065f9002800f016834ff0ff375e46fef7abbd0f9a002a46d1b0f53e3f40f2eb810c9e4ff0ff37fef79fbd0e9fb978fa783b797f7941ea022143ea072232293591369280f0a9813221abe1d0f86c110027002900f0e6824ff400624ff0ff3c0df1d40e05e02b681a44b2f5403f80f041818d18ac68b7eb542ff4d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e6e74646fef766bd0f98002800f0a98100200e9a4ff0000b02f1030e16324ff0ff3c0e92cdf82ce00beb4b020eeb420465784ff0ff37012d00f2a982a678e37856ea032900f0a3822379647953ea042800f09d82b9f5207f00f29982b8f5f07f00f2958209f101035b0803fb08f44ff6fb739c4200f28b821ef81220bbf1000f42ea05270e9d62462cd015f8133c15f8126c43ea0623bb423ff478af12b315f80d3c15f80c6c43ea0623bb423ff46eaf012a17d015f8073c15f8066c43ea0623bb423ff463af022a0cd015f8013c2e7843ea0623bb423ff459af043a531c05f11805d2d100293ed0631d4ff4006201eb020edef80850bd423fd0def8006032444ff6ff76c0f20206b2422cd801eb020edef80850bd4230d0def8006032444ff6ff76c0f20206b2421dd801eb020edef80850bd4221d0def8006032444ff6ff76c0f20206b2420ed801eb020edef80850bd4212d0def8006032444ff6ff76c0f20206b242c3d94ff6fc7304f10802c0f201031a401044103020e0def804209a427ff404afdef80c209a427ff4ffae9ef81020042a7ff4faae9ef811209ef8123042ea03224a457ff4f1ae9ef813209ef8143042ea032242457ff4e8ae0f9a0bf1010bddf82ce093450cf1010c7ff42cafb0f53e3f3ff6daae002500200e90e3e090f8a911002918bf05f0a6fd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08e804af27366c0f246060021002200230027b0470c9efef73bbc4ff0000c4ff400634ff0000ec0f800c30de0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe466ad2cf18ba68ce58013201d07746f3e7f418220c022ae6d80a1995680135e2d115682e443e6012681444220c022adad80a1995680135d6d115682e443e6012681444220c022aced80a1995680135cad115682e443e6012681444220c022ac2d80a1995680135bed115682e443e6012681444b4f5403fcfd3b5e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f24600804701281ed143f2a316c0f25606a6f188008047022c074608bf002f01d057b90fe04bf2110235a9c0f24b020220904738b10746b047002085f843010c9efef7b9bb0c9e0027fef7b5bb701ca9f86c0300272646fef7aebb0a99d1f86c114268836890454ff00002c0f80c8008bf00f1100241f823200e9a0f98013282424ff000070e9200f0f3800e980b9b00eb400003eb400213f81000937892f801b00893d37807931379527940ea0b2909930692a1b3bbf1010f31d84ff400628b189f684f45d8d01b681a444ff6ff73c0f202039a4223d88b189f684f45ccd01b681a444ff6ff73c0f202039a4217d88b189f684f45c0d01b681a444ff6ff73c0f202039a420bd88b189f684f45b4d01b681a444ff6ff73c0f202039a42cfd9dde90773099e43ea0721069c013146ea04224908514301f105088df8d6004fea18208df8d9004fea18408df8da000520059101218df8de0004208df8d4108df8e00035a811218df8d5508df8d7b08df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e3608df8e44006f0c9fc00287ff46aad0a98d0f86c110020a9b3bbf1010f32d84ff40062881883684b452cd0006802444ff6ff70c0f20200824223d8881883684b4520d0006802444ff6ff70c0f20200824217d8881883684b4514d0006802444ff6ff70c0f2020082420bd8881883684b4508d0006802444ff6ff70c0f202008242cfd90020059a002a3ff424af0799089b0902069a41f001011944099b120249081a434a43511e032901d200210ae022f003030021471804318b427d75bd75fd753d76f7d112f003023ff401af00f11503012a5d543ff4fbae1944022a4d7018bf8d70f4e60c9efef7a0ba304621464ff41632fdf7aafe11a807f0d3fb0027e6e44bf639400027c0f2510084f8447080474646fef78aba2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09e804ff45c7005f027f8002800f09680414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000129b155e8001fa142f8d04fe7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db03f0b3ff68b940460af0c9f948b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f098ff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f04982172f40f05482fe2804f22737884600f06d82002840f0788200980af043f9414602e0022084f8200350460c22fdf7e6fb94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7b6fb47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf785fbb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f80080bff35f8f08ea0700b0f1005f47d1d8f80000b04243d198f8500338b1002088f86401c8f860014db0bde8f08f98f8640118b3d8f8604104b340f6b800c2f20000d0f8009006a802f00df9b9f1000f00f07581484621464ff41632b346ba464ff6ff75cdf81490fdf72ffb4ff29c5600274ff00109c2f2290620e098f8660170b1d8f8680140b147f64c61c2f207010968401a002802f3dc80002088f8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0a01b1f1005f03d10168594500f09f804ff45c7004f0b1fc002802f09c804ff69041cff6ff714218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa1427ff455afbff35f8f46e8000121b156e8001fa142f8d04ae7817a002942f00080027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e0002088f86401c8f8600188f86601012088f8650140f6a120c0f24700804701f074bf40460d460af069f8d8b102304ff0030008bf022084f820032946bce584f85003d9f800204ef660231a44c4f8602380b140460d460af02ffa0af003fa294630b9a9e50af0fef9002829463ff4a4ad03209fe5002084f866019de51868624600eb0620704400eb0b4000eb056138466546fdf77bf90fe04eea062141ea0b4141ea056339466246654609f0fdff00281cbf032084f8200305f1080084f84f03414679e501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0e48300218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f09a8000218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f346bef15f0f98bf4ff05f0bcbf1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f905eb0e0209f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd009fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0de460ae00ef1010e07e00ef1020e04e00ef1030e00e0de460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000a15f80a10002900f0c78005eb0a035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d00af1200abaf1600f7ff496af4ff0600a5ee00af1010a5be00af1020a58e00af1030a55e00af1040a52e00af1050a4fe00af1060a4ce00af1070a49e00af1080a46e00af1090a43e00af10a0a40e00af10b0a3de00af10c0a3ae00af10d0a37e00af10e0a34e000220a7162e70af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46d646baf15f0f98bf4ff05f0ecef1000942f2107c0aad19eb0a0b51d0b2fbf3f40a2b04f1300105f80a104cf6cd41ccf6cc41a3fb011747d31bf1010140d004fb1326ff08b6fbf7f405eb0a0204f13001517048f21f51c5f2eb11642ba3fb015135d31bf102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31bf1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb11420af1040a63454fea57330aadabd20ce0f2460ae0f24607e00af1010a05e00af1020a01e00af1030a0aad059f002205f80a20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a4609f051fad4f870c272208df8280078208df8290020204ff0000b1ffa8cf28df82a008df82bb015f80b00002800f0c88005eb0b035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00bf1200bbbf1600f7ff496af4ff0600b5fe004460020887078e70bf1010b58e00bf1020b55e00bf1030b52e00bf1040b4fe00bf1050b4ce00bf1060b49e00bf1070b46e00bf1080b43e00bf1090b40e00bf10a0b3de00bf10b0b3ae00bf10c0b37e00bf10d0b34e00bf10e0b31e00bf10f0b2ee00bf1100b2be00bf1110b28e00bf1120b25e00bf1130b22e00bf1140b1fe00bf1150b1ce00bf1160b19e00bf1170b16e00bf1180b13e00bf1190b10e00bf11a0b0de00bf11b0b0ae00bf11c0b07e00bf11d0b04e00bf11e0b01e00bf11f0b01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d946bbf15f0f98bf4ff05f09c9f1000a42f2107e1aeb0b004fd0b2fbf3f50aa905f1300401f80b404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0b0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020bf1040b73454fea5633add209e0cb4607e00bf1010b04e00bf1020b01e00bf1030bddf8149000220aac04f80b20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06e8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df8870042f2941645f29c140aaa48460e21c2f22006c2f2130408f0fffe4ff6a42040f6b801cff6ff70c2f200010858a04266d14ff6b020cff6ff700858b0f54d2f5ed14ff6b420cff6ff700858a04257d145f610634ff0000ec2f213034cf6394506f1040c00274ff0ff32634548d8186830f003041ad09e4228bf0c2842d3f11a8c424ff0ff313fd8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e2d12ce00021417191e60421b7f5807f1ed300223d46b5f5007f14d3b5f5806f13d3b5f5006f12d30901b2eb153f4fea1515f0d10ce000219171fef765bf00211172fef71bbc490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006806f1080342f6941c9842c2f2270c4cd142f610674ff0000bc2f2200746f6b9700cf1040e00244ff0ff3a4ff0ff3977453bd83e6836f0030515d0bc4528bf0c2e35d3aceb07039d4233d82346a54288bf2b46f6071cbf1c46ab447b19013803f10407e4d121e00420b4f5807f16d300262546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b6eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea000ad94603e04ff0ff3a4ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834264d14ff69423cff6ff73fb58b3f5333f5cd14ff69823cff6ff73fb58834255d14ff29c5043f21063c2f229004ff0000bc2f2270342f6f935a0f1040ca0f1080e0024634542d81e6836f003071ad09e454ff0ff30049028bf0c2e3ad3aeeb030087424ff0ff3034d82046a74288bf3846f6071cbf0446bb44d819013d00f10403dfd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff00634505d17b4204ea03000490584602e04ff0ff300490064666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b7008f0f7fe059de05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f88000208df8870020464946524608f022fe0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac049a2046314608f055fd28461a21224608f0d2fb002088f86401c8f8600105984ef217310a904ff416300b900aa8c0f247018847012088f8660106a800f036f9c8f810004db0bde8f08f0020c871d6e70021417207e700bf2de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff6904a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f09c804ff45c7002f0a6fb002800f0d28051464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff45bafbff35f8f00bf47e8000121b157e8001f4945f8d04fe74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c56d1f8009000684ff6904bccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108009007e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168b94200f09c804ff45c7002f08cfa002800f0f08059464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f51457ff457afbff35f8f00bf46e8000121b156e8001f5145f8d04be74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ce047f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422fd041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94217d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a9eb0501b1fbf0f001b0bde8f08f002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204607f0b5fa854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f01f81207887f00301084200f01b81012039464246334600f054fa0446002898f8080018bf06240ee14ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f0f1804ef66c6a4ff29c574ff690480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168514500f09d804ff45c7002f0eff8002800f0be80414600bf4218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff455afbff35f8f47e8000121b157e8001f4945f8d04ae705eb450100eb011090f85d1201b300f513760024304629462a460323009407f059fa706840b14bf69b71c0f25d018847706804f0a7fc74603068b475002818bf04f0a0fc0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f058f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104607f046f9201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009507f0ecf9606840b14bf69b71c0f25d018847606804f03afc65602068a575002818bf04f033fc00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff690498046ccf2ff05c2f229064ff6ff77cff6ff7900244ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09d804ff45c7001f08cff002800f0958049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff457afbff35f8f00bf46e8000129b156e8001f5945f8d04be7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46faf715fda81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450bcde90612cde9080303e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c7001f090fe002800f0398449464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70999089d01eb410100eb011095f9081000f51376b1f1ff3f01f0030409dd374617f8110fd0bb3068002818bf04f04cfa2fe3307cf0b1707ce0b10799099a002730460323009706f0e7ff706840b14bf69b71c0f25d018847706804f035fa77603068b775002818bf04f02efa00203060b06030823068002818bf04f025fa00204ff480713060b0603182a978b081092006f11107f174b17434757076b07ca978884240f0db82317da14240f0d782069b411ca3f10b00727e02971e2828bf1e209042b17488bf7076981e84b200270a2c4ff00008c0f0e782092241f221090920039419e030684f46002818bf04f0ecf9b089376001303774b760b081002c18bf4ff00608039cd146ddf814a00aeb0b0082b2a24280f0c782317c80b20429824600f28880aa5c00f1010a4b1c0129337405dd022906d0032970d1f28106e021b9727503e0338943ea02223281a24580f0aa8204296ed015f80a204ff0000c831c8f1c0129377406ddff290bd0032967460dd19a4652e000291cbf378947ea0222328100e072756746a34204d38be2f281a34280f08882022936d8ea5c00f1030acb1c0129337407dd022937d0fe2907d17275a2450cd376e231b9338943ea02223281a24504d36ee2f281a24580f06b8202292fd015f80a20031d41f00407fc29377408ddfd2909d0fe291cbf378947ea0222328103e079b9f28100e072756746a34280f0508209b19a4613e0ea5c00f1050a0520307401e09a466746f189308941ea0221f18128b106f01cfe0028306000f06a8233897089191a1ffa81fb1ffa8af1621a5a45b8bf93465fea0b4208d03268294410441ffa8bf2faf70bfb70893389584481b2994270817ff44faf0025cdf81080d6f800808df82b50707db8f1000f06930df12b0108bf88460f2806d8317d00f00302511ab1fa81f14d09000706d4317e707e814238bf30760fe000bf706840b14bf69b71c0f25d018847706804f002f97760707e30760120f082cdf814a09db1707db57d400714d4002d4ff0000400f0898106984ff6ff7381b2002900f00d8101295ed10020d2e0707d400753d4002478e14ff4803006f0abfd002d804600f07081b07d002800f06c81b8f1000f00f068817568002d00f0008130890428c0f0608131680a1812f8043c002b40f0598112f8033c002b40f0548112f8023cff2b40f04f8112f8012cff2a40f04a814ff4803429606860c5f80c802c610028019000f067814bf69b70c0f25d0000f58572284600219047002840f033812969002900f02f8168688c420c46e7d1019a0c468242e3d125e14ff4803006f059fd044620e1069a4ff6fe701040a44642426ff0010000bf08eb0005ac78ed7883ea04231cb25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead73787ea430383ea05231fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead737023087ea430309ead5371518023587ea430395d1023000276446069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003f0899ab2824270d1099b4046faf77ffa00286ad141f2210a4ff00009012375e0382006f098fc00285ed00546077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377046f6d730c0f200007844286246f6df30c0f20000784468624bf69b70c0f25d0045f6e46200f13c0c28460f21c0f27c023823e04740b3284603f069ff4446706841f2210a40b14bf69b71c0f25d018847706803f05cff77604ff000090323b77506980799099a089dddf8108087b23046009706f0f4fc002c214604463ff455ad084603f044ff50e5756073e6c4f58030b4f5803f444606902f60ef607ff646aecde70799099a002430460323009406f0d6fc706840b14bf69b71c0f25d018847706803f024ff74603068b475002818bf03f01dff0020387000203060b06030824ff00a0840460bb0bde8f08f287a4006f8d5307c08b302980078e0b10799099a002430460323009406f0a9fc706840b14bf69b71c0f25d018847706803f0f7fe74603068b475002818bf03f0f0fe00203060b06030824ff00b083068002818bf03f0e5fe00203060b0603082cae702980078e0b10799099a002430460323009406f07dfc706840b14bf69b71c0f25d018847706803f0cbfe74603068b475002818bf03f0c4fe00203060b06030824ff00608a7e700bf2de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7f3f9002869d006462846fff749fa21462a46fff71dfa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff7d0ba0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22f9f741fe04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522f9f7fdfd0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522f9f7a7fd4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff764ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff690480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f09c804ff45c7000f03efe002800f0c18041464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff456afbff35f8f46e8000121b156e8001f5945f8d04be7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff7f0fd2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff61d40cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023a6e745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04468002c00f0bd828368002b00f0b98204eb030b4ff000090027002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310ceb0a0300275b451c464ff0000680f09d82a04618f9013b03f07f05bd40002b46ea050610d406f00703012b16dc0bb3012b40f08b82abeb0803082bc0f0868204f10903dee700bfd84580f07f82182f07f107074446dcd978e200bf022b3ad0052b40f07382abeb0803042bc0f06e82631dc7e7d84580f0698294f90130002b04f10203bed55b4580f0608294f90230b3f1ff3f04f10303b4dc5b4580f0568294f90330b3f1ff3f04f10403aadc5b4580f04c8294f90430b3f1ff3f04f10503a0dc5b4580f0428294f90530002b00f13d82a31d96e7d84580f0388294f9013004f1020c002b03f07f0a1ed5dc4580f02d8294f90270e31c07f07f05b7f1ff3f4aeac51a02dde0469c460ee05b4580f01d8294f9037004f1040c07f07f05b7f1ff3f4aea853a33dd9846abeb0c039a4500f20c82f308672b1dd0652b7ff460afbaf1060ffff45caf9cf80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf4ff29c54c2f229040290cde9002132e0044660460e4651461746654600f017fcac4631463a46204637e7dc4580f0db8194f90470631d07f07f05b7f1ff3f4aea455aaddc5b4580f0ce8194f90570002f00f1c98104f1060c4aea077ab1e748f2a3513046c0f24501bff32f8f8847dde900210298ac462768bff35f8f2668bff35f8f33466ff39603b3f1005f07d133684ef66c65ccf2ff05ab4200f0b0804ff45c70654600f079fbdde9002106460298ac46002e3ff4f1ae4ff69043cff6ff7300bff418373384f8709384f8719384f8729384f8739384f8749384f8759384f8769384f8779384f8789384f8799384f87a9384f87b9384f87c9384f87d9384f87e9384f87f9384f8809384f8819384f8829384f8839384f8849384f8859384f8869384f8879384f8889384f8899384f88a9384f88b9384f88c9384f88d9384f88e9384f88f9384f8909384f8919384f8929384f8939384f8949384f8959384f8969384f8979384f8989384f8999384f89a9384f89b9384f89c9384f89d9384f89e9384f89f9384f8a09384f8a19384f8a29384f8a39384f8a49384f8a59384f8a6938ed14ef66c63ccf2ff0333600123b3724ff6ff734ff29c54b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290454e8003fbb427ff43bafbff35f8f00bf44e8006323b154e8003fbb42f8d02fe798f8043098f8057098f80650032b47ea052437dd052b58dc042b78d0052b7ff43daed6f868313bb147f64c67c2f207073f68db1b002b18dcd6f86c3186f86691c6f86c91c6f80093a6f86c936bb10c4648f2a35180461846c0f24501174665468847ac4621463a46404647f64c63c2f207031b6845f69077c0f201073b44c6f868310be6012b3ff4fdad022b00f08780032b7ff403ae174688466546fff724fb03460298ac4641463a46002b3ff4f6ad96f84231002b3ff4f1ad304641f28831a6f8404106f006fa47e0062b4ad0072b7ff4e4ad80464df6db50c0f24a0016460f466446804703465d1ea446394632464046012d3ff6d2ad981eb0fa80f04009fff7dcfba446394632464046c6e5174688466546fff7e8fa03460298ac4641463a46002b3ff4baad96f84231002b3ff4b5adb6f84031a3427ff4b0add6f83c3186f84291002ba6f840913ff4a7ad42f68d411846c0f2440188470298ac4641463a469be5d6f86c31c6f86891002b86f86691c6f86c91c6f80093a6f86c933ff48dad0f4648f2a35104461846c0f24501164665468847ac463946324644e696f84231c6f83891002b3ff478ad0446d6f83c0165468846174686f84291a6f8409120b142f68d41c0f2440188474af273660120002100220023c0f24606b04720463a464146ac4659e54ff2a513c0f2490303b0bde8f04f18477fb50646002806d1fff772fa002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817047f2b401c0f20001033079440b22f8f7e8ff0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f8f7b0ff0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f8f701ff1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f8f757fe4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f0eb800c46014600784d2840f0e5804878432840f0e1808878012840f0dd804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f03d10268424500f0a0804ff45c70fff766ff002800f0ae804ff690425146cff6ff728318373283f8705383f8715383f8725383f8735383f8745383f8755383f8765383f8775383f8785383f8795383f87a5383f87b5383f87c5383f87d5383f87e5383f87f5383f8805383f8815383f8825383f8835383f8845383f8855383f8865383f8875383f8885383f8895383f88a5383f88b5383f88c5383f88d5383f88e5383f88f5383f8905383f8915383f8925383f8935383f8945383f8955383f8965383f8975383f8985383f8995383f89a5383f89b5383f89c5383f89d5383f89e5383f89f5383f8a05383f8a15383f8a25383f8a35383f8a45383f8a55383f8a6538ed1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a457ff451afbff35f8f47e8000222b157e8002f4a45f8d046e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff6b922cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff61140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff35f2e0cde901100120cff680704ef66c644ff29c564ff6904bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f03d10168a14200f09b804ff45c70fff74dfb0028c5d059464218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff459afbff35f8f00bf46e8000121b156e8001f5145f8d04de7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff41faf00210025fff778fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff7f4fd0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff72afe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff6bd12cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff750fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef788fa014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef768fa0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef757fa204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd45f67e70c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7a5f90028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f7f705ff4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7a3bd00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1f9f7cdfec8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f9bb00278437842ea0325b5f5007f04d94ff0ff301bb0bde8f08f4ef66c6a4ff29c56ccf2ff0ac2f229064ff6ff774ff000084ff0010b0791099008e000bf48f2a3512046c0f24501bff32f8f8847d6f80090bff35f8f3468bff35f8f20466ff39600b0f1005f03d12068504500f0a2804ff45c70fef7d3fb002800f09a8004464ff69040cff6ff7000bf2118373081f8708381f8718381f8728381f8738381f8748381f8758381f8768381f8778381f8788381f8798381f87a8381f87b8381f87c8381f87d8381f87e8381f87f8381f8808381f8818381f8828381f8838381f8848381f8858381f8868381f8878381f8888381f8898381f88a8381f88b8381f88c8381f88d8381f88e8381f88f8381f8908381f8918381f8928381f8938381f8948381f8958381f8968381f8978381f8988381f8998381f89a8381f89b8381f89c8381f89d8381f89e8381f89f8381f8a08381f8a18381f8a28381f8a38381f8a48381f8a58381f8a6838ed1c4f800a084f80ab0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f48457ff450afbff35f8f46e8004028b156e8000f4845f8d045e70024ddf824805db1fdf7fafb0146002c4ff0ff3018bf002902d11bb0bde8f08fb5fa85f040094ff000098df82c908df82d908df82e908df82f908df830908df831908df832908df833908df834908df835908df836908df837908df838908df839908df83a908df83b908df83c908df83d908df83e908df83f908df840908df841908df842908df843908df844908df845908df846908df847908df848908df849908df84a908df84b908df84c908df84d908df84e908df84f908df850908df851908df852908df853908df854908df855908df856908df857908df858908df859908df85a908df85b908df85c908df85d908df85e908df85f908df860908df861908df862908df863908df864908df865908df866908df867908df868908df869908df86a908df86b90bcb1d4f86c21a2b14ff4006304e03f683b44b3f5403f0cd2d718be680136f6d07e68033626f0030609eb060101f11009ede7002d4ff0020a039500f00581ddf81cc0acf102020a2ac0f00081002608eb0a0b9bf801504ff0ff30012d3ff648af9bf802209bf803309bf8047042ea03229bf8053042ea074747ea0361a1f1011212f5803f0a91fff433af9bf808109bf809e0029141ea0e210af10a020497aceb02034f1e9f42bff423afcde905269bf806209bf807300a9e42ea032cb6eb0c07fff416afb9423ff613af18f80a70089147ea052a4feada000ba90e5c07f00705012707fa05f5354240f003830e5c45ea06050d5407994ff6ff75c0f20205b4b3d4f86c0198b317461a0201924fea0e264ff4006200eb0208d8f8083053454bd0d8f800301a44aa4221d800eb0208d8f80830534540d0d8f800301a44aa4216d800eb0208d8f80830534535d0d8f800301a44aa420bd800eb0208d8f8083053452ad0d8f800301a44aa42d3d900bfbcf1000f40f0be8204980a464ff6fc710330c0f2030108404844944600f1100908980599069e00eb010a0398013686424ff0000028bf0120ddf824804fd2aceb0a02092a3ff64caf49e0d8f804000a9a904240f09782d8f80c006045c0f0928236d9089aa0eb0c00824200f28b827ab3029831180198c1f1000cc2199044a1f1010e002208eb02050beb0203287c9e7ab04240f0778296451cd06e7cdf7abe4240f070820ceb0207be1c13d0ae7c187b864240f06782079ef81c07d0e87c5b7b984240f05f8204329142dbd1b446a7e78c46a5e7ddf81cc0a2e7ddf81cc0002800f05082baeb0c004ff0000118bf0120b9f53e3f88bf0121014303980028c1f100003ff43eae00297ff43baed4f86cb1bbf1000f40f08b804ff44030fef75af9002800f02f82834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760222c0f2020600210ae00aeb080209f10101ddf8248071454ff000003ff498ad08eb02050a9218f80200aa786f7805922a7a95f803e095f8049095f805c095f806a0eb7908926a7a40ea0728cde906215cb3012f29d84ff400670beb0705a868404500f0a28028680744b7421dd80beb0705a868404500f0988028680744b74213d80beb0705a868404500f08e8028680744b74209d80beb0705a868404500f0848028680744b742d7d90598cdf810a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a002002930597b9f1000f26d00beb09035bf809105a68514580f09c80eab10beb02005bf80210d0f80490514580f08d80b9f1000f11d00beb09035bf809105a68514580f0878042b10beb02005bf80210d0f804905145d6d377e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f6f7affe4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f8002311d90beb09004bf809104ff0ff3142608160c260c4f800930be0e868ddf80ce00a9a089f60e010b10268114401604ff000090020b9f1000f7bd00beb09035bf809105a68514522d2002a72d00beb02005bf80210d0f80490514513d2b9f1000f67d00beb09035bf809105a6851450ed2002a5ed00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf80ce00a9addf810a0029b089f00280cbfc4f800c3c0f804c005984ff6ff7668600020c0f20206c5f80880e8604aea0321069bddf81c9047ea032a814202f10a087ff4bdae05f110077818099952464144f346f6f7c2fde968de466868aa68d4f86cb15144e96081424ff0000018bf07464bf82270a3e600204ff400684ff4006703e02f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f6f7e1fd4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f800831bb0bde8f08f00281ebf0168114401604ff0ff301bb0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7f1fe002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f86813002974d104464ff41630fdf74ffe014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8681300e00021084601b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7a9fd002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f87812002974d104464ff4163002f041fe014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8781200e00021084601b0bde8f08f00bf2de9f04f83b04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b029002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c70fdf760fc002800f0c68049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70446fff7ebfd002c18bf002805d102990120487103b0bde8f08fc4f8600101254ff4f07084f8645101904ff420704af61f470090c0f2470700200021002200230026b84740b184f864610298c4f86061457103b0bde8f08f0298057103b0bde8f08f0024cde700bf014640f258304df69f22c2f20000c0f248021047022a3cbf4ff0ff3070472de9f04fadf2cc4d189008784f781e9240ea0727b7fa87f04fea501822f0010002284ff002001f9001f05a83002f16910f93129701f054831f90002015901f9a169b9818995c4078023241ea00241e981f92801a844201f24183022cc1f03e83ddf800753868411e0028396001f036839e187078012801f2318396f800800028a4f1020769d01898022f0df1d009c1f02583d0f86c01002801f02083f178012901f21c8396f802a04aea012750f82710002901f013830a1a910741f00f836ff4403140f60f031144cff6fd739942c1f00583104450f8081cb94241f0ff8250f80c1c0025a1f10113cff6ff75ab42c1f0f58250f8043c8b4241f0f082c2f54032914201f2eb82002801f0e882027812f00b0f41f0e38200224b4601f07cfb002801f0dc82349804362290dde936b0251f2190ddf800050bf1010180694908269140b1fa080af00701835c012707fa01f119438154b2462f460de0ddf8f804ddf8f0b42690ddf8f40406f1020a21900f980df1d0092290b8f1030f119459d0b8f1020f33d0b8f1010f1d9740f0e280002f01f0a4829af80060012e01f29f82002e4ff0050c18bf4ff0090c6745c1f096829af801109af80300002ecdf86ca000f0ca819af802209af8043055469af805709af8064041ea022140ea032ae8792a7a259147ea042e40ea0222bfe10e2f41f075829af800409af801004ff6fe7144ea00278f422699219e229b5d46249100f08a834ff6ff718f4240f02c8318984ff42075d0f868334ff4a0704ff4f076249079e3062fc1f052829af805000630874241f04c82062f2cad17d0062402e00134bc4212d21af8040001381e28f7d90aeb0400391b4a462b4601f049fa002801f0358234980444bc42ecd3ddf8fc04002801f004822298002801f02882fcf707fb002801f023829af80550a81d874241f01d8247f65420c2f207000768002f01f01582387b797bba7bfb7b40ea012040ea024040ea0362a2f1810010f1800f4ff00008c1f00582387c797cfb7c40ea0120b97c40ea014040ea03600690813810f5817f41f2f5815446002d24920d9700f0db85a61d4ff0000c00270df1d00a0df1b0081b9409e000f100404af824000137af4204f1010c80f07b85f05d6446411e1e29f0d9f019e91b424628ab01f0dff9002800f069852c9928980f444af82400e6e708f0fe00042840f086801898b8f1040f02d1072f41f0b981b8f1050f09d1082fc1f0b3819af8070008308742189841f0ac81d0f86c71c446002f4ff0000801f0a6819af80100012801f2a1819af8005045ea002057f82020002a01f09881d31b9a0741f094816ff440329e1840f60f02cff6fd729642c1f08a81fc1854f8082c824241f0848154f80c1c0027a1f10112cff6ff77ba42c1f07a81002c01f0778154f8047c8f4241f07281c3f54033994201f26d81ddf8002592693ab1c00805f00706135c0127b7403b431354bcf1040f40f0c984204600222cab01f0f3f9ddf8fc1400284ff0000408bf4ff0ff34002918bf002801f02081002034901d98269901902298219b5a46cdf80890cdf800a001f04cfad7e2b8f1060f40f0b582219a102f41f032819af804009af805104ff0000850ea01231ebf9af806009af8071050ea012701f023819af800609af8015046ea0524a345c1f01a81abeb0400834201f215819af802009af8031040ea01294a45c1f00c81a2eb0900874201f20781ddf8fc04002801f0d88007eb090051462590a80203eb040a01f1080b40ea860826982299464609fb0015a64620464ff0040c00bf4208ac5c2cea060124fa01f1c1f342031bf803302cea810123fa01f101f00f0304f00f0704f0f0042344c40700f1010008bf47ea0113504506f10406ab54dfd3259809f1010981457446cfd301f09bb89af802209af8047089004fea420a4fea800e7a002591ddf88490bef1000f4ff0000818bf002a01f0b08025988345c1f0ac80abeb0000864501f2a780d145c1f0a480a9eb0a00824201f29f801d9f6546bc4502fb0ef41096199280f035821098ddf8fc24002818bf0120d846002a18bf0122104000211390149400bf1b98475d3b0901d0012015e01d98461b012e01f07a801b98421953780bb102200ae0042ec1f071809678d27856ea022301f06b80042000bf621a934201f265801c901398002800f085805e1e07f00f00032e4fea0712179524901a93239280f085804ff0000c1a9b179d13f0030b71d00ceb0107b7fbfef0259b00fb1e76f41800eb0a0656ea040016d4444514d24e4512d22698229d249a06fb00506608855de40705f00f0c05f0f0051544239a08bf4cea02058555179d1a9bbbf1010f49d0781cb0fbfef6259b06fb1e005644c41856ea040016d4444514d24e4512d22698229d249a06fb00506608855de40705f00f0c05f0f0051544239a08bf4cea02058555179d1a9bbbf1020f23d0b81cb0fbfef6259b06fb1e005644c7181a9b56ea070017d4474515d24e4513d22698229d144606fb00507e08855d249a05f00f0c05f0f0051544ff0708bf4cea04058555179d00bf1c981d9f0544bd42194480f09487149ca142fff44baf70e123f003004ff0000c209005e020980cf1040c60453ff471af01eb0c0bbbfbfef60b4606fb1eb4259956440c4456ea0409ddf8849015d4444513d24e4511d22698229d249a06fb00566508705de40700f00f0700f0f0001044239a08bf47ea020070550bf10100b0fbfef505fb1e0005eb0a06441856ea040015d4444513d24e4511d22698229d249a06fb00506508465de40706f00f0706f0f0061644239a08bf47ea020646550bf10200b0fbfef505fb1e0005eb0a06441856ea0400194614d4444512d24e4510d22698229d249b06fb00506508465de40706f00f0706f0f0061e4408bf47ea020646550bf10300b0fbfef5259b05fb1e0005eb0a06c41856ea04003ff583af4445bff480af4e45bff47daf2698229d249b06fb00506508465de40706f00f0706f0f0061e4408bf47ea020646556ae7012800f231871898d0f86c01002800f02b8750f82710002900f026870a1a910740f022876ff4403140f60f031144cff6fd739942c0f01887104450f8081cb94240f0128750f80c1c0026a1f10113cff6ff76b342c0f0088750f8043c8b4240f00387c2f54032914200f2fe86002800f0fb86027812f00b0f40f0f68600224b4600f08fff002800f0ef86ddf80005dde936568069349b691c4fea5101249140b1fa0804f00701845c012707fa01f121438154002b4ff00008239300f0d7869af806e09af807105eea01291fbfcdf894b09af808009af8097050ea072b00f0c6869af802209af8033042ea03229542c0f0bd86ab1a994500f2b98620929af804209af8053042ea0325ae424ff00002a6eb050338bf01229b454ff0000388bf01231a43ddf8fc345442002b00f07486002a40f071869af80b209af80a30120642ea034253464fea224a5a7b1b7b120642ea0342dde922364fea22489e4200f07a82002300f06cbd219fb8f1070f4ff0000840f07c861d98022840f078869af800009af80110229a40ea0121ddf800055b460390ddf8fc040097029026980190189801f05dfc044600f036be0021bd424ff0000808bfa14240f05986ddf8fc04002800f02a861098002840f02686781fddf864c021902ef001000cfb00f200f031861b991d922698229a05310afb0020229125994fea5e0e00eb5108002101234ff000090027002000251c902390cdf88080cde924e008e001250027259a219801328242259200f01186002d40f00d862298259a022f865c00f0f680012f7cd0002f40f0f580370906f00f00239000f072811d98b842dfd3c01b1d90239800eb001600011b9012e01bf80100239a00f0f00010440bf801000131013f0123714524bf002109f10109002f00f04e81e145c2d22698002b09fb008be5d0aeeb0104b4eb570f88bf7c0874b3a2080beb010a1dd09e4600230af10100a3eb82026ff0030c00bf00eb0c030cf1040c02eb0c0818f10405de701e715e719e71f2d10cf10400ddf864c0ddf88080734600e0002014f0030208d0012a0af8006004d05044022a467018bf8670a7eb4407214487b1ddf890e07145b2d21bf801001b9a00f00f001043013f00230bf80100002faed1fbe0ddf890e00027a1e7002e00f0f8801d98b042fff468af801b1d90239800eb001700011b9010e0685c239a00f0f000104368540131013e0123714524bf002109f10109002e00f0d880e145bff44caf2698002b09fb0085e6d0aeeb010cbceb560f44469b4688bf4fea560cbcf1000f28d05fea9c0005eb010816d0002208f10103a2eb800a6ff0030000bf1a1804300aeb00040434d770177157719771f5d1209cddf890e0043000e000201cf0030208d0012a08f8007004d04044022a477018bf8770a6eb4c0661447eb1ddf864c071450ed2685c1b9a00f00f0010436854013e0023a046002eafd186e0ddf864c000265b46a046a0e7002503271c96f5e61c9d55ea062500f081801d981c95a842fff4eaae401b1d90239800eb001700011b9011e01af80100239a00f0f00010430af801000131013d0123714524bf002109f10109002d58d0e145bff4cdae2698002b09fb008ae5d0aeeb0104b4eb550f46469b4688bf6c083cb3a2080aeb010816d0002308f10100a3eb82026ff0030c00eb0c030cf1040c02eb0c060436df701f715f719f71f3d1209e0cf1040000e0002014f0030208d0012a08f8007004d04044022a477018bf8770a5eb440521449db1ddf890e0ddf864c0714512d21af801001b9a00f00f0010430af80100013d0023b046002dafd107e0ddf864c0ddf890e000255b46b0469fe70027002575e60025022772e6002501276fe60020012500271c906ae6c1292caf2cd32078012829d11d980928c0f04b84a4f13f0025901d980af10805a0f1080602e0013e00f03f8415f8010b421e1f2af7d342b2202a11db259b03eb400213f81000527840ea0222c12a07d320463b46884600f002fd41460028e2d14ff0ff3400f035bcbcf1000f59d0acf101054ff00008564608e0cc46454508f10108a4f1010406f1040646d05af828100029f3d40020434684421dd006eb80077a68b2f1ff3f18dc5a1c954214d0ba68b2f1ff3f11dc9a1c95420dd0fa68b2f1ff3f0adcda1c954206d03a690433002a00f10400e0d400e000220d982cab28afe146009701f0b9fa0028b9d028980028c3d04af20d312ca8c0f24e018847bce701204ff0000c0df1d00a0df1b0080ce0a84540f3e5820123efe200200df1b00802e04ff0000c01201b9c217994f800e06278a378e7788d060f2401f00f0604eae575754389246543ed0a8df8a0500e25259111f0200f08bf012506fb05f504fb05f54fead5258df8a1504ff00d0508bf022506fb05f504fb05f54fead5258df8a2504ff00c0508bf032506fb05f504fb05f54fead5258df8a3504ff00b0508bf042506fb05f504fb05f54fead5258df8a4504ff00a0508bf052506fb05f504fb05f54fead5258df8a5504ff0090508bf062506fb05f504fb05f54fead5258df8a6504ff0080508bf072506fb05f504fb05f54fead5258df8a7504ff0070508bf082506fb05f504fb05f54fead5258df8a8504ff0060508bf092506fb05f504fb05f54fead5258df8a9504ff0050508bf0a2506fb05f504fb05f54fead5258df8aa504ff0040508bf0b2506fb05f504fb05f54fead5258df8ab504ff0030508bf0c2506fb05f504fb05f54fead5258df8ac504ff0020508bf0d2506fb05f504fb05f54fead5258df8ad504ff0010508bf0e2506fb05f504fb05f54fead5258df8ae504ff0000508bf0f256e436643f60a00284ff000048df8af6040f00a83120642ea0e4138060c14249940ea0340acf1010501eb204000260590cdf824c0079518e00df1b0084af20d314046c0f24e0188479df8b4009df8b5100c9c079ddde909c640ea01200df1d00a01366645044400f0de825af82610b1f1ff3f1edd33469d421fd00aeb83004268b2f1ff3f1adc0133ab4216d08268b2f1ff3f13dc0133ab420fd0c268b2f1ff3f0cdc0133ab4208d002690133002ae2d404e001f01f000b38d2e700220d98434627af009701f074f900283ff474ae27990029109100f0a6819df8b8009df8b9100a9650ea012c0c94a6d09df8bc709df8bd603f0447ea0667069e9df8b7009df8b6106644020241ea00259df8ba0006eb2747059e9df8bb300004a6eb07080c9e40ea0360031406eb204a01201b9500eb55070a4401f003050af101010b910af10201089110990e97571e1497f718f31a4c1c511b00eb52002491d9074ff0000e2391f907074646461c952091cdf85cc0cde9190806e000bf0ef1010ee6453c443ff45aaf1eeb0602f6d421988242f3d21b980028f0d0269822994ff0000902fb001814981d94032880f0a1801c98ddf85cc0dde919761d9c0028ddd010980e9901220efb010325984fea5901595c00f0100082ea1015c8b201f00f025feac971139108bf02091046002a18bf01202843012816d119eb0a0413d45c4511d2600818f8001028afba5c01f00f0701f0f0011143e60708bf47ea0211dde9197608f800101c981d9c0128a6d009f101004008185cc1b24fea111c1399002908bf00f00f0c5ffa8cf0002818bf01202843012819d10b9819eb000215d45a4513d2500818f8001028ac14f80c7001f00f0601f0f00139431d9cd20708bf46ea0711dde9197608f800101c98ddf85cc002283ff473af09f102004008185cc1b200f00f021398002808bf0a091046002a18bf0120284301287ff460af089819eb00033ff55baf5b45bff458af580818f8001028afba5c01f00f0701f0f0011143db0708bf47ea0211dde9197608f8001044e7a44608e000bf249809f1040948450cf1020c3ff454af25981cf8014c00f01002012080ea1213e4b200220f2c88bf01221a43012a0aeb090215d1002a13d45a4511d25708240918f8076028a8045d06f00f0106f0f00626435feaca7008bf41ea041608f807601cf8010c5f4610f00f04204618bf01201843012817d112f1010b14d4bb4512d24fea5b0018f8001028ae345d01f00f06239d46ea041601f0f001002d08bf41ea040608f800609cf80000bb46c4b200200f2c88bf01201843012815d1971c13d45f4511d27908200918f8014028ae305c04f00f0604f0f004209d0443002d08bf46ea001408f801409cf8000010f00f04204618bf0120184301287ff481af03323ff57eaf5a45bff47baf500818f8001028aa125d01f00f03239c43ea021301f0f001002c08bf41ea020308f8003067e79df8b4009df8b510ddf824c040ea012014e6209ba8eb0502b2fa82f29a454ff000034fea5212c8bf0123134009023a02104341ea0e0100fb01f2511e0bfb09f01d9000f08d8022f001001b9000204feac37b1c9519921a9305e000bf501c1b9a0239904276d002468646bbf1000f18bf0a46b2fbf9f000fb192400eb080304eb0a0253ea020625d4259fba4222d2219fbb421fd21c9f3844dde9237600fb0670209fe6197408005d042727ea8606f040269f229e00f00f0503fb076356089c5dd20704f00f0704f0f004254408bf47ea00159d556ff001000ef1010280ea0e001346bbf1000f1d9f18bf3b18b3fbf9f000fb193400eb080304eb0a0c53ea0c05acd4259dac45a9d2219dab42a6d21c9d2844dde9235600fb0650209d2c446508405d042525ea8404e040269c229d00f00f0603fb04534fea5c041d5d05f00f0705f0f00535445feacc7608bf47ea00151d5583e71c9ddde919230ef1020000e00020259ed1074ed0da076fea00011d9a18bf5018b0fbf9f303fb190203eb080102eb0a0051ea00073dd4b0423bd2219fb94238d2dde923762b4403fb0673209f3a445708db5d042727ea820223fa02f2269b229f02f00f0601fb03714308cf5cc00707f00f0507f0f007374408bf45ea0217cf5417e0149cfff7dfb9ddf8fc0478b1002034901d98269901902298219b5a46cdf80890cdf800a000f079fbfff7c8b900243cbb1f991198159a01441298013282424ff0000828bf4ff001081f911bd21e981592401a01283ef6c5ac14e00121012006e00125b7fa87f11d9a85f00100490900294ff0000818bf002804d0002ad8d001e04ff00008dde91e01081a18bf012060ea080000f0010040420df2cc4dbde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe791429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f93b0054600284ff0ff3000f030821d9f072f40f02c82cde90651cde90823faf7bdff002800f006814ef66c674ff29c544ff6904a48f2a355ccf2ff07c2f229044ff6ff79cff6ff7a4ff000084ff0010bc0f2450503e000bfbff32f8fa8472668bff35f8f2068bff35f8f01466ff39601b1f1005f03d10168b94200f0ad804ff45c70fbf7c1fe002800f0d480514600bf4218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed1076080f80ab0a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fb1427ff44bafbff35f8f00bf44e8000121b154e8001fb142f8d03fe7d0f86c111c9d00294ff0ff3000f043816a78012a00f23f81287840ea022751f82700d8b1431a98074ff0ff3040f033816ff4403240f60f061a44cff6fd76b242c0f02981ca1852f8080cb84206d152f80c1ca1f1011010f5803f04d24ff0ff3013b0bde8f08f002a4ff0ff3000f0138152f8047c8f4240f00e81c3f54033994200f209810df1380a1046002253460024fff754fe0028e1d0e978a8786b7909062a7941ea0049a8794fea036848ea024782060f23059100f00f0103eae27202fb01f389225343db0a8df828300e2310f0200f08bf0f2408bf012301fb03f302fb03f34fead3238df829304ff00d0308bf022301fb03f302fb03f34fead3238df82a304ff00c0308bf032301fb03f302fb03f34fead3238df82b304ff00b0308bf042301fb03f302fb03f34fead3238df82c304ff00a0308bf052301fb03f302fb03f34fead3238df82d304ff0090308bf062301fb03f302fb03f34fead3238df82e304ff0080308bf072301fb03f302fb03f34fead3238df82f304ff0070308bf082301fb03f302fb03f34fead3238df830304ff0060308bf092301fb03f302fb03f34fead3238df831304ff0050308bf0a2301fb03f302fb03f34fead3238df832304ff0040308bf0b2301fb03f302fb03f34fead3238df833304ff0030308bf0c2301fb03f302fb03f34fead3238df834304ff0020308bf0d2301fb03f302fb03f34fead3238df835304ff0010308bf0e234b4361435143c0f300105343c90a04900aa806ac099ddb0a8df83710039013cc4fea29464fea274b8df8363022462b46cde901ba009600f018fcdde9100100eb2942059801eb2741a24226eae070b8bf1446a942b8bf0d46844212dd2beae8718d420edd1e9a12680f2a0ad86b1a1e9d271a05ebc206f080501c31817781b3812860002013b0bde8f08f2de9f04f99b0814600284ff0ff3000f0a282239c082cc0f09e820f4616461d46faf782fd002800f01581229ad17901f10800844240f00e81cde90a171078577891794ef66c684ff29c5bcde90c6540ea0720ccf2ff08c2f2290b4ff6ff7a002601250f910e9006e048f2a351c0f24501bff32f8f8847dbf80040bff35f8fdbf80000bff35f8f01466ff39601b1f1005f03d10168414500f0af804ff45c70fbf779fc002800f0d6804ff69041cff6ff714218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800808572a0f81ca0a0f81ea0a0f820a0a0f822a0a0f824a0a0f826a0a0f828a0a0f82aa0a0f82ca0a0f82ea0a0f830a0a0f832a0a0f834a0a0f836a0a0f838a0a0f83aa05be8001fa1427ff443afbff35f8f00bf4be8000121b15be8001fa142f8d037e7d0f86c210f9dddf888e0002a4ff0ff3000f0a581012f00f2a2810e9852f82000e0b1811a88074ff0ff3040f098816ff4403340f60f060b44cff6fd76b342c0f08e81571857f8080c0e9a904206d157f80cbcabf1011010f5803f04d24ff0ff3019b0bde8f08f57f8040c58454ff0ff3040f07581c1f540318b4500f27081002f00f06d81bbf1c10fc0f0698138780128e4d1a8060f2405f00f0604eae070704389246043c00a8df854000e209ef802809ef803209ef804c09ef8053015f0200f08bf012006fb00f004fb00f04fead0208df855004ff00d0008bf022006fb00f004fb00f04fead0208df856004ff00c0008bf032006fb00f004fb00f04fead0208df857004ff00b0008bf042006fb00f004fb00f04fead0208df858004ff00a0008bf052006fb00f004fb00f04fead0208df859004ff0090008bf062006fb00f004fb00f04fead0208df85a004ff0080008bf072006fb00f004fb00f04fead0208df85b004ff0070008bf082006fb00f004fb00f04fead0208df85c004ff0060008bf092006fb00f004fb00f04fead0208df85d004ff0050008bf0a2006fb00f004fb00f04fead0208df85e004ff0040008bf0b2006fb00f004fb00f04fead0208df85f004ff0030008bf0c2006fb00f004fb00f04fead0208df860004ff0020008bf0d2006fb00f004fb00f04fead0208df861004ff0010008bf0e2006fb00f004fb00f04fead0204ff000018df8620008bf0f2171430a9e61430020c90a002e8df8631000f09b80100640ea08404fea2048180640ea0c400ef1080a00140e90c5f30010a7f13f045546099001e0013e1ad015f8010b411e1f29f8d341b22029fff6fcae04eb400114f81000497840ea0122c12afff4f2ae3846594610abfff713fb0028e3d1e9e60e980a9d20eae07008902498cde9064b0630059004e040440b38013d804659d01af8010b1f28f6d904eb400114f81000497810ac40ea0122c12acdf83ca0fff4c9ae384659462346fff7eafa00283ff4c1ae0998dde90b1b0d9e049015a8ddf838a0cde9024048465a463346cdf804a0cdf8008000f074f9dde91201404401eb0a02584528eae871b8bf8346b242a8bf32468b4519dd089eb24216dd249e34680f2c12d8ddf820c0abeb0103a2eb0c0e059a02ebc40622f83410249a611ca6f802c0b380a6f806e01160ddf83ca0dde9064ba2e7002019b0bde8f08f2de9f04f85b0119d6c68072c72d824b12f89b9426ed0012c69d1d0f86c61002e68d00027b7eb512f64d156f82170002f60d0a7eb060c5fea8c775bd16ff440370ceb070e40f60f07cff6fd77be4551d306eb0c0e5ef8086c8e424bd15ef80c6ca6f1011717f5803f44d35ef8047cb74240d1ccf54037be423cd8bef1000f39d0032e37d39ef80070022f33d19446aa69dde90e87ddf840a099468ab1cb0801f007045746c24612f803804ff0010b0bfa04f444ea0804d454d046ba460f9f6c6805eb4402631c6b6011810ef10101721e6346cde903a5cde90187cdf80090fdf721fe69680139696005b0bde8f08f6f89b94204d14ff0ff3005b0bde8f08f022c3ff48bafaf89b942f4d0032c3ff485afef89b942eed0042c3ff47faf2f8ab942e8d0052c3ff479af6f8ab942e2d0062c3ff473afaf8ab9427ff46fafdae700bf2de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f87b00591dde91171ddf84cc00c692cb10c68844200f0948100259ee14f68002f00f0fc8100260021069609e0dde90361daf804703144ddf84cc0b94280f0ee81ddf848a00491daf80040655c2e0901d0012113e07f1a012f00f0e0810c4466780eb102210ae0042fc0f0d881a778e47857ea042600f0d281042100bf0391149915f00f04b1fa81f54fea55151cf804c018bf0124069945ea040e029616f00304ddf81490119e4fea0c188b4600f092800194daf80840b1fbf4f505fb1414109967180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990129069901f1010b5fd0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990229069901f1020b2ed0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050194fc07644604bf0f254446019f3d402c4301f80b40069901f1030b00bf029d6c1e032c2944069107d224e700bf06990bf1040b59453ff41eafdaf808401099bbfbf4f5002705fb14b40c44b4f1ff3fc8bf012707ea0e07012f1ad1ad1918d4944216d29d4214d205fb09056708e40715f807906ff00f04e24604bf0f24c24604ea0904ddf8149044ea0a04ddf848a0ec55daf808400bf10107b7fbf4f505fb147400270c44b4f1ff3fc8bf012707ea0e07012f14d1ad1912d4944210d29d420ed205fb09056708e407ee5d6ff00f04614604bf0f2441463440119e2143e955daf808100bf10204b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e01012914d1ad1912d4944210d29d420ed205fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c55daf808100bf10304b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e0101297ff46bafad193ff568af9442bff465af9d42bff462af05fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c5551e7002f01dd012508e0b7fa87f4109f00256409002fc8bf01252540d1f80880c96801fb08f9b9f1000f58d08e4614994ff0000ab1fa81f461094ff0ff3b0491e907069107e00af1010a0efb08f9ca45abf1010b43d2069954460029129918bf09eb0b04b4fbf8f50e6808f1010705fb18447f0805fb07666708f65d042121ea8407fe4016f00f094e4618bf012604990e43012ed7d1109964185cbf119915eb0105d0d49442ced29d42ccd20599660805fb01081cf8095018f80670129907f00f0907f0f0072f43e40708bf49ea051708f80670d1f80880d1f80ce0b3e707b0bde8f08f00bfb0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f3f7bffb06f1210506f1280029460722f3f7b7fb284621460722f3f7b2fb20465146032207f10905f3f7abfb06f11d0049460422f3f7a5fbf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f3f779fba81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f059e60846fdf789b900bf2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f3f731fb012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f3f718fb572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f3f701fb312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f3f7ebfa462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f3f7d4fa362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f67320c0f20000784410f80b0041f66d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f3f769facde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f3f74afa8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f3f74bf9284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f3f7f7f8002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f3f7c5f804a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f3f7b1f80020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f3f79af8352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f3f776f804a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f3f763f8002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f3f74ff804a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f3f72bf804f14f0051460722f3f725f884f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f26a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2f241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f797ff84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f2f7adfe284641462246c84703b0bde8f08370b50446d0f83c0142f665360d46c0f2440668b949f2b520cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3235000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "f00a3a00", + "new": "04403a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "700b3a00", + "new": "84403a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "f00a3a04", + "new": "04403a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "09a9afac", + "new": "4c01635d", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "19292813", + "new": "155cd97f", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "19292813", + "new": "155cd97f", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/g2/glasses-session.ts b/app/g2/glasses-session.ts index 1a63c70f..850d0327 100644 --- a/app/g2/glasses-session.ts +++ b/app/g2/glasses-session.ts @@ -1,3 +1,4 @@ +import { drawMessages } from './draw-protocol' import { setBrightness } from './brightness-protocol' import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client' import { type CompassEvent } from '../native/compass-types' @@ -254,7 +255,7 @@ export class GlassesSession { return Promise.all(['right', 'left'].map(role => this.send(role, protocol.SID.settings, 0x20, protocol.framebufferLease(acquire)))) } private requestCfw(role: string, payload: Uint8Array): Promise { - if (payload.length > CFW_MAX_MESSAGE) return Promise.reject(new Error('CFW message too large')) + if (payload.length > CFW_MAX_MESSAGE - 16) return Promise.reject(new Error('CFW message too large')) return new Promise((resolve, reject) => { const item: CfwPending = { role, payload, checksum: protocol.crc16(payload), magic: this.nextMagic(), ackLenses: 0, retries: 0, retryPending: false, deadline: 0, resolve, reject } @@ -508,7 +509,7 @@ export class GlassesSession { const textureFrame = this.latestTextures; this.latestTextures = null // Compare with the last enqueued image, not the last ACKed one. In an // A -> B -> A sequence, B may still be in flight when A is requested. - if (this.lastEnqueued && packed.every((value, i) => value === this.lastEnqueued![i])) continue + if (!textureFrame && this.lastEnqueued && packed.every((value, i) => value === this.lastEnqueued![i])) continue const texturePlan = textureFrame ? this.textures?.plan(this.lastEnqueued, packed, textureFrame, this.nextImageFrameId) : null let commands: Uint8Array[] if (texturePlan) { @@ -521,9 +522,10 @@ export class GlassesSession { const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId) const payload = delta ?? protocol.concat(new Uint8Array([6]), protocol.rle4(packed)) if (delta) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 - commands = payload.length <= CFW_MAX_MESSAGE ? [payload] : buildFullFrameBands(packed, 640, 480, this.nextImageFrameId) - if (payload.length > CFW_MAX_MESSAGE) for (const _ of commands) + commands = payload.length <= CFW_MAX_MESSAGE - 16 ? [payload] : buildFullFrameBands(packed, 640, 480, this.nextImageFrameId) + if (payload.length > CFW_MAX_MESSAGE - 16) for (const _ of commands) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 + commands = [...commands.flatMap(command => drawMessages(command)), new Uint8Array([28])] this.log(`Display ${delta ? 'bbox' : 'full'} (${commands.length} CFW commands)`) } this.displaySending = { packed, commands, offset: 0, pending: 0 } diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts index 3593cdb5..14246b00 100644 --- a/app/g2/ios-preview-controller.ts +++ b/app/g2/ios-preview-controller.ts @@ -352,9 +352,7 @@ export class IosPreviewController { try { if (this.shellDirty) { this.shellDirty = false - const { image, draws } = flattenPlanesWithDraws(shell.paintSurface(), { width: 640, height: 480 }) - this.compositor.submitSurfaceFrame('shell', image.pixels, { x: 0, y: 0, width: 640, height: 480 }, prepareFrameDraws(draws)) - this.compositor.setUnderlayDim(1, shell.underlayDim()) + this.compositor.setShellScene(shell.paintScene()) } const { pixels, textures } = this.compositor.compositeFrame() this.session?.setFrame(pixels, textures) diff --git a/app/graphics/plane.ts b/app/graphics/plane.ts index 15cf5c98..d7527b32 100644 --- a/app/graphics/plane.ts +++ b/app/graphics/plane.ts @@ -15,6 +15,8 @@ import { GrayImage, type DeferredDraw } from "./image"; * existing incremental-update and screen-preview pipeline. */ export type Plane = { + shellKey?: number; + dimUnderneath?: number; image: GrayImage; /** * Offset of the plane's top-left within the submitted frame. Applied diff --git a/app/graphics/shell-scene.ts b/app/graphics/shell-scene.ts new file mode 100644 index 00000000..bd637510 --- /dev/null +++ b/app/graphics/shell-scene.ts @@ -0,0 +1,33 @@ +import { GrayImage } from './image' +import type { Plane } from './plane' + +/** Crop one independently owned, opaque shell surface; never split it into tiles. */ +export function shellCrop(image: GrayImage, x: number, y: number, width: number, height: number, key: number): Plane { + const baked = image.withDrawsBaked(), crop = new GrayImage(width, height, 0) + for (let row = 0; row < height; row++) crop.pixels.set(baked.pixels.subarray((y + row) * image.width + x, (y + row) * image.width + x + width), row * width) + return { image: crop, x, y, shellKey: key } +} + +/** Shared Kotlin receives original 8-bit pixels and quantizes once, before composing. */ +export function encodeShellScene(planes: readonly Plane[]): Uint8Array { + const layers: { image: GrayImage; x: number; y: number; key: number; dim: number }[] = [] + for (const plane of planes) { + const image = plane.image.withDrawsBaked() + let left = image.width, top = image.height, right = -1, bottom = -1 + for (let y = 0; y < image.height; y++) for (let x = 0; x < image.width; x++) { + if (image.pixels[y * image.width + x] === 0) continue + left = Math.min(left, x); right = Math.max(right, x); top = Math.min(top, y); bottom = Math.max(bottom, y) + } + if (right < left) continue + const w = right - left + 1, h = bottom - top + 1 + if (5 + Math.ceil(w / 2) * h > 65536) throw new Error(`Shell surface ${plane.shellKey} exceeds 64 KiB (${w}×${h})`) + const cropped = shellCrop(image, left, top, w, h, plane.shellKey!) + layers.push({ image: cropped.image, x: plane.x + left, y: plane.y + top, key: plane.shellKey!, dim: Math.round((plane.dimUnderneath ?? 1) * 256) }) + } + const result = new Uint8Array(2 + layers.reduce((n, l) => n + 14 + l.image.pixels.length, 0)) + const view = new DataView(result.buffer); let p = 0 + const word = (n: number) => { view.setUint16(p, n, true); p += 2 } + word(layers.length) + for (const l of layers) { word(l.key); word(l.x); word(l.y); word(l.image.width); word(l.image.height); word(l.dim); word(0); result.set(l.image.pixels, p); p += l.image.pixels.length } + return result +} diff --git a/app/graphics/surface-compositor.ios.ts b/app/graphics/surface-compositor.ios.ts index 10f869d2..c99e559e 100644 --- a/app/graphics/surface-compositor.ios.ts +++ b/app/graphics/surface-compositor.ios.ts @@ -33,6 +33,7 @@ export class SurfaceCompositor { this.native.submitDrawsIdDataXYWidthHeightDraws(id, toData(pixels), rect.x, rect.y, rect.width, rect.height, draws ? toData(new Uint8Array(draws)) : null) } + setShellScene(bytes: Uint8Array): void { this.native.shellData(toData(bytes)) } composite(): Uint8Array { return fromData(this.native.composite()) } compositeFrame(): { pixels: Uint8Array; textures: TextureFrame } { const native = this.native.compositeFrame() diff --git a/app/graphics/surface-compositor.ts b/app/graphics/surface-compositor.ts index d7ea2ca6..e63afba4 100644 --- a/app/graphics/surface-compositor.ts +++ b/app/graphics/surface-compositor.ts @@ -9,6 +9,8 @@ type Surface = SurfaceConfiguration & { pixels: Uint8Array; visible: boolean } export class SurfaceCompositor { private readonly surfaces = new Map() + private shellScene: Uint8Array | null = null + setShellScene(bytes: Uint8Array): void { this.shellScene = new Uint8Array(bytes) } private dimBelow = 0 private dimFactor = 1 private blanked = false @@ -55,11 +57,11 @@ export class SurfaceCompositor { composite(): Uint8Array { const output = new Uint8Array(this.width * this.height) if (this.blanked) return output - const surfaces = [...this.surfaces.values()].filter(s => s.visible).sort((a, b) => a.zOrder - b.zOrder) + const surfaces = [...this.surfaces.values()].filter(s => s.visible && !(this.shellScene && s === this.surfaces.get('shell'))).sort((a, b) => a.zOrder - b.zOrder) for (const surface of surfaces) { const left = Math.max(0, surface.x), right = Math.min(this.width, surface.x + surface.width) const top = Math.max(0, surface.y), bottom = Math.min(this.height, surface.y + surface.height) - const dim = surface.zOrder < this.dimBelow ? this.dimFactor : 1 + const dim = !this.shellScene && surface.zOrder < this.dimBelow ? this.dimFactor : 1 for (let y = top; y < bottom; y++) { let source = (y - surface.y) * surface.width + left - surface.x let target = y * this.width + left @@ -72,6 +74,21 @@ export class SurfaceCompositor { } } } + if (this.shellScene && !surfaces.some(s => s.zOrder > 1)) { + const quantize = (v: number) => Math.min(15, (v + 8) >> 4) + for (let i=0;i=0 && y+yy>=0 && x+xx { + const snapshot = new Uint8Array(bytes); + await this.enqueueJavaCall(() => this.communicator.submitShellScene(snapshot.buffer, paintMs, frameId), true); + } + async setUnderlayDim(belowZOrder: number, factor: number): Promise { await this.enqueueJavaCall(() => { this.communicator.setUnderlayDim(Math.round(belowZOrder), dimFactor256(factor)); diff --git a/app/native/kotlin-protocol-smoke.ios.ts b/app/native/kotlin-protocol-smoke.ios.ts index 65a06c35..b471f525 100644 --- a/app/native/kotlin-protocol-smoke.ios.ts +++ b/app/native/kotlin-protocol-smoke.ios.ts @@ -31,6 +31,8 @@ export function runKotlinProtocolSmokeTest(): void { c.submitSurfaceFrame('test', new Uint8Array([0, 16, 255, 32, 48, 64]), { x: 0, y: 0, width: 3, height: 2 }) assert(hex(c.composite()) === '0010ff203040', 'composition') assert(hex(protocol.packGray4(c.composite(), 3, 2)) === '01f02340', 'packing') + c.setShellScene(new Uint8Array([1,0,1,0,0,0,0,0,1,0,1,0,128,0,0,0,255])) + assert(hex(c.composite()) === 'f00070101020', 'shell scene bridge and 4bpp composition') c.setScreenBlanked(true); assert(c.composite().every(p => p === 0), 'blanking') const textures = new IosTexturePlanner(), textured = new SurfaceCompositor(4, 2) textured.configureSurface('icon', { x: 0, y: 0, width: 2, height: 2, zOrder: 0, transparency: 'opaque' }) @@ -40,7 +42,7 @@ export function runKotlinProtocolSmokeTest(): void { textured.submitSurfaceFrame('icon', white, { x: 0, y: 0, width: 2, height: 2 }, draw.buffer) const snapshot = textured.compositeFrame(), packed = protocol.packGray4(snapshot.pixels, 4, 2) const cold = textures.plan(null, packed, snapshot.textures, 1) - assert(!!cold && cold.resourceCommands.some(command => command[0] === 21) && cold.payload[0] === 8, 'texture upload and draw') + assert(!!cold && cold.resourceCommands.some(command => command[0] === 21) && cold.payload[0] === 28, 'texture upload and draw') assert(textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length === 0, 'texture reuse') textures.reset() assert((textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length ?? 0) > 0, 'texture reset') diff --git a/app/native/preview-display.ts b/app/native/preview-display.ts index baad5305..729d66f5 100644 --- a/app/native/preview-display.ts +++ b/app/native/preview-display.ts @@ -22,6 +22,7 @@ export type DisplayTarget = Pick< | "setUnderlayDim" | "setScreenBlanked" | "submitSurfaceFrame" + | "submitShellScene" | "waitForFrameFinished" | "getCompositePreview" | "saveScreenshot" @@ -97,6 +98,10 @@ export class PreviewDisplayTarget implements DisplayTarget { this.compositor.setSurfaceVisible(id, Boolean(visible)); } + async submitShellScene(bytes: Uint8Array, paintMs = 0, frameId = 0): Promise { + this.compositor.submitShellScene(new Uint8Array(bytes).buffer, paintMs, frameId); + } + async setUnderlayDim(belowZOrder: number, factor: number): Promise { this.compositor.setUnderlayDim(Math.round(belowZOrder), dimFactor256(factor)); } diff --git a/app/ui/layers.ts b/app/ui/layers.ts index 7bd79480..36bbf3a9 100644 --- a/app/ui/layers.ts +++ b/app/ui/layers.ts @@ -80,6 +80,7 @@ export interface LayerContext { } export interface Layer { + paintParts?(): Plane[]; readonly paintOverBase?: boolean; /** * Dim everything painted beneath this layer: a 0..1 brightness factor @@ -116,6 +117,12 @@ export interface Layer { export class LayerStack { private readonly layers: Layer[]; + private static nextShellKey = 3; + static allocateShellKey(): number { + if (this.nextShellKey > 65535) this.nextShellKey = 3; + return this.nextShellKey++; + } + private readonly shellKeys = new WeakMap(); private readonly ctx: LayerContext; private baseWidth: number; private baseHeight: number; @@ -225,6 +232,8 @@ export class LayerStack { * A stack whose base is transparent over something else (the shell chrome * over the window surfaces) forwards this to what lies beneath. */ + paintUndimmed(): Plane[] { return this.paintLayer(this.layers.length - 1, 1, true); } + baseDim(): number | false { return this.lastBaseDim; } @@ -259,8 +268,11 @@ export class LayerStack { /** Paint layer `index`; `dimSoFar` is the factor the layers above apply to it. */ - private paintLayer(index: number, dimSoFar: number): Plane[] { + private paintLayer(index: number, dimSoFar: number, raw = false): Plane[] { const layer = this.layers[index]!; + if (raw && index === 0 && layer.paintParts) return layer.paintParts(); + let key = this.shellKeys.get(layer); + if (key === undefined) { key = LayerStack.allocateShellKey(); this.shellKeys.set(layer, key); } let canvas: GrayImage | null = null; let belowRequested = false; const image = spanCurrent(`paint[${index}]:${layer.constructor.name}`, () => @@ -272,7 +284,7 @@ export class LayerStack { return canvas; }), ); - const ownPlane: Plane = { image, x: 0, y: 0 }; + const ownPlane: Plane = { image, x: 0, y: 0, shellKey: key, dimUnderneath: layer.dimUnderneath === false ? 1 : layer.dimUnderneath }; if (index <= 0) { this.lastBaseDim = dimSoFar; return [ownPlane]; @@ -281,7 +293,7 @@ export class LayerStack { return [ownPlane]; } const dim = layer.dimUnderneath || 1; - const below = this.paintLayer(layer.paintOverBase ? 0 : index - 1, dimSoFar * dim); - return [...(dim < 1 ? dimPlanes(below, dim) : below), ownPlane]; + const below = this.paintLayer(layer.paintOverBase ? 0 : index - 1, dimSoFar * dim, raw); + return [...(!raw && dim < 1 ? dimPlanes(below, dim) : below), ownPlane]; } } diff --git a/app/ui/menu.ts b/app/ui/menu.ts index 199b51a1..04b8b1fd 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -42,6 +42,7 @@ export type MenuLayout = { * renders over whatever is below it (modal/window menus). */ opaque?: boolean; + squareCorners?: boolean; }; export type MenuItemRenderArgs = { @@ -226,6 +227,7 @@ export class MenuLayer implements Layer { const maxHeight = Math.min( this.layout.maxHeight ?? image.height - y - DEFAULT_MENU_Y, image.height - y, + this.layout.squareCorners ? Math.floor(65530 / Math.ceil(width / 2)) : Infinity, ); const footerHeight = this.layout.footer ? MENU_FOOTER_GAP + lineStep(font) : 0; const contentHeight = chromeTop + this.items.length * rowHeight + footerHeight + MENU_BODY_PADDING; @@ -243,9 +245,11 @@ export class MenuLayer implements Layer { // Fill 1, not 0: identical after 4bpp quantization, but 0 is the // transparent color key when a menu paints on the shell surface. - image.fillRoundedRect(x, y, width, height, 1); + if (this.layout.squareCorners) image.fillRect(x, y, width, height, 1); + else image.fillRoundedRect(x, y, width, height, 1); if (this.layout.showBorder !== false) { - image.drawRoundedRect(x, y, width, height, 72); + if (this.layout.squareCorners) image.drawRect(x, y, width, height, 72); + else image.drawRoundedRect(x, y, width, height, 72); } if (this.title) { image.drawText(font, x + 12, y + 8, this.title, 220); diff --git a/app/ui/shell/assistant.ts b/app/ui/shell/assistant.ts index 7dfd9532..05f5b0ec 100644 --- a/app/ui/shell/assistant.ts +++ b/app/ui/shell/assistant.ts @@ -12,7 +12,7 @@ const DIALOG_X = 40; const DIALOG_W = G2_LENS_WIDTH - 80; // The dialog fits inside the min-height window band (like the other shell // overlays), wherever the vertical position setting puts it. -const DIALOG_MARGIN_Y = 24; +const DIALOG_MARGIN_Y = 28; const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y; const TEXT_MAX_WIDTH = DIALOG_W - 32; const MENU_ROWS = 2; @@ -95,8 +95,8 @@ export class AssistantLayer implements Layer { // Solid dialog box (fill 1, matching the voice dialog: opaque after 4bpp // quantization, but not the color-key transparent 0). - image.fillRoundedRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1, 10); - image.drawRoundedRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90, 10); + image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1); + image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90); const left = DIALOG_X + 16; image.drawText(font, left, top + 12, this.phase === "thinking" ? "Assistant ●" : "Assistant", 220); diff --git a/app/ui/shell/brightness-picker-layer.ts b/app/ui/shell/brightness-picker-layer.ts index 6ff3108b..b45f1fee 100644 --- a/app/ui/shell/brightness-picker-layer.ts +++ b/app/ui/shell/brightness-picker-layer.ts @@ -25,8 +25,8 @@ export class BrightnessPickerLayer implements Layer { const height = BAR_HEIGHT + 3 * font.lineHeight + 56; const left = viewport.x + Math.round((viewport.width - DIALOG_WIDTH) / 2); const top = viewport.y + Math.round((viewport.height - height) / 2); - image.fillRoundedRect(left, top, DIALOG_WIDTH, height, SHELL_OPAQUE_BLACK, 8); - image.drawRoundedRect(left, top, DIALOG_WIDTH, height, 110, 8); + image.fillRect(left, top, DIALOG_WIDTH, height, SHELL_OPAQUE_BLACK); + image.drawRect(left, top, DIALOG_WIDTH, height, 110); const centeredText = (text: string, y: number, value: number) => { image.drawText(font, left + Math.round((DIALOG_WIDTH - font.measureText(text)) / 2), y, text, value); diff --git a/app/ui/shell/chrome-layer.ts b/app/ui/shell/chrome-layer.ts index ebb57300..88a216c5 100644 --- a/app/ui/shell/chrome-layer.ts +++ b/app/ui/shell/chrome-layer.ts @@ -1,3 +1,5 @@ +import { shellCrop } from "../../graphics/shell-scene"; +import type { Plane } from "../../graphics/plane"; import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image"; import { getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts"; import { truncateText } from "../../graphics/textwrap"; @@ -18,7 +20,7 @@ import { } from "../dashboard-settings"; import { formatClockDate, formatClockTime } from "../clock-format"; import { getFont } from "../../graphics/bdffont"; -import { Layer } from "../layers"; +import { Layer, LayerStack } from "../layers"; import { scrollToKeepSelectionVisible } from "../menu"; import { lineStep } from "../metrics"; import { @@ -216,6 +218,21 @@ export class ShellChromeLayer implements Layer { return image; } + paintParts(): Plane[] { + const state = this.getState(), parts: Plane[] = []; + if (sidebarStripVisible(state.focus, state.foregroundAppId)) { + const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); + this.drawSidebar(canvas, state); + parts.push(shellCrop(canvas, 0, minWindowTop(state.foregroundAppId), SIDEBAR_WIDTH, MIN_WINDOW_HEIGHT, 1)); + } + const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); + this.drawTopBar(canvas, state); + const left = sidebarStripVisible(state.focus, state.foregroundAppId) ? SIDEBAR_WIDTH : 0; + parts.push(shellCrop(canvas, left, windowTop(state.foregroundHeightMode, state.foregroundAppId), G2_LENS_WIDTH-left, TOP_BAR_HEIGHT, 2)); + drawAmbientCards(canvas, parts); + return parts; + } + handleInput(): void { // Shell input is handled by the shell state machine before it reaches the // layer stack; the chrome itself never consumes events. @@ -500,7 +517,8 @@ const AMBIENT_MAX_LINES_PER_CARD = 3; * bottom of the window band and newer ones stack above it. Cards that would * cross into the top bar are dropped rather than clipped. */ -function drawAmbientCards(image: GrayImage): void { +const ambientKeys = new Map(); +function drawAmbientCards(image: GrayImage, parts?: Plane[]): void { const cards = activeAmbientCards(); if (!cards.length) return; const font = getDefaultSmallFont(); @@ -514,10 +532,11 @@ function drawAmbientCards(image: GrayImage): void { const height = 2 * AMBIENT_CARD_PADDING_Y + lines.length * lineStep(font); const y = bottom - height; if (y < bandTop + TOP_BAR_HEIGHT) break; - image.fillRoundedRect(x, y, AMBIENT_CARD_WIDTH, height, SHELL_OPAQUE_BLACK, 6); - image.drawRoundedRect(x, y, AMBIENT_CARD_WIDTH, height, 90, 6); + const target = parts ? new GrayImage(image.width, image.height, 0) : image; + target.fillRect(x, y, AMBIENT_CARD_WIDTH, height, SHELL_OPAQUE_BLACK); + target.drawRect(x, y, AMBIENT_CARD_WIDTH, height, 90); for (let index = 0; index < lines.length; index++) { - image.drawText( + target.drawText( font, x + AMBIENT_CARD_PADDING_X, y + AMBIENT_CARD_PADDING_Y + index * lineStep(font), @@ -525,6 +544,11 @@ function drawAmbientCards(image: GrayImage): void { index === 0 ? 220 : 160, ); } + if (parts) { + let key = ambientKeys.get(card.id); + if (key === undefined) { key = LayerStack.allocateShellKey(); ambientKeys.set(card.id, key); } + parts.push(shellCrop(target, x, y, AMBIENT_CARD_WIDTH, height, key)); + } bottom = y - AMBIENT_CARD_GAP; } } @@ -557,7 +581,7 @@ function attentionDot(value: number): GrayImage { const TAB_RADIUS = 6; // How far the diversion pokes past the separator into the main area. -const TAB_EXTEND = 1; +const TAB_EXTEND = 0; const TAB_STROKE = 150; /** diff --git a/app/ui/shell/input-dialog.ts b/app/ui/shell/input-dialog.ts index 7b36d9d1..17d89fed 100644 --- a/app/ui/shell/input-dialog.ts +++ b/app/ui/shell/input-dialog.ts @@ -16,7 +16,7 @@ const DIALOG_X = 40; const DIALOG_W = G2_LENS_WIDTH - 80; // The dialog fits inside the min-height window band (like the other shell // overlays), wherever the vertical position setting puts it. -const DIALOG_MARGIN_Y = 24; +const DIALOG_MARGIN_Y = 28; const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y; const TEXT_MAX_WIDTH = DIALOG_W - 32; @@ -51,8 +51,8 @@ export function paintInputDialog(image: GrayImage, content: InputDialogContent): // Solid dialog box over the underlying UI. Fill 1, not 0: identical after // 4bpp quantization, but 0 is transparent on the color-key shell surface. - image.fillRoundedRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1, 10); - image.drawRoundedRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90, 10); + image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1); + image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90); const left = DIALOG_X + 16; image.drawText(font, left, top + 12, content.title, 220); diff --git a/app/ui/shell/modal-layer.ts b/app/ui/shell/modal-layer.ts index 07b53761..0e200e7d 100644 --- a/app/ui/shell/modal-layer.ts +++ b/app/ui/shell/modal-layer.ts @@ -16,7 +16,7 @@ function modalInterior(): { width: number; height: number } { const viewport = appViewportSize("min"); return { width: viewport.width - 2 * MODAL_MARGIN - 2 * MODAL_PADDING, - height: viewport.height - 2 * MODAL_MARGIN - 2 * MODAL_PADDING, + height: Math.min(viewport.height - 2 * MODAL_MARGIN, Math.floor(65530 / Math.ceil((viewport.width - 2 * MODAL_MARGIN) / 2))) - 2 * MODAL_PADDING, }; } @@ -27,7 +27,7 @@ export function modalRect(): { x: number; y: number; width: number; height: numb x: viewport.x + MODAL_MARGIN, y: viewport.y + MODAL_MARGIN, width: viewport.width - 2 * MODAL_MARGIN, - height: viewport.height - 2 * MODAL_MARGIN, + height: Math.min(viewport.height - 2 * MODAL_MARGIN, Math.floor(65530 / Math.ceil((viewport.width - 2 * MODAL_MARGIN) / 2))), }; } @@ -54,8 +54,8 @@ export class ShellModalLayer implements Layer { // below transplants the finished modal content into this layer's plane. const inner = flattenPlanes(this.stack.paint(), interior); const rect = modalRect(); - image.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK, 8); - image.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 110, 8); + image.fillRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK); + image.drawRect(rect.x, rect.y, rect.width, rect.height, 110); image.bitBlt(inner, rect.x + MODAL_PADDING, rect.y + MODAL_PADDING, { transparentZero: true }); return image; } diff --git a/app/ui/shell/shell.ts b/app/ui/shell/shell.ts index e385ab54..692a3dc8 100644 --- a/app/ui/shell/shell.ts +++ b/app/ui/shell/shell.ts @@ -1,3 +1,4 @@ +import { encodeShellScene } from "../../graphics/shell-scene"; import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image"; import { singlePlane, type Plane } from "../../graphics/plane"; import { getDefaultSmallFont } from "../../graphics/ui-fonts"; @@ -229,6 +230,7 @@ class ShellOverlayMenuLayer extends MenuLayer { y: minWindowTop() + TOP_BAR_HEIGHT + 8, width, minHeight: 150, + squareCorners: true, footer, dimUnderneath: CONTEXT_MENU_DIM, }); @@ -266,8 +268,8 @@ class ShellAlertLayer implements Layer { const font = getDefaultSmallFont(); // Positioned within the min-height window band, like the other shell overlays. const alertY = minWindowTop() + ALERT_Y; - image.fillRoundedRect(ALERT_X, alertY, ALERT_W, ALERT_H, 1, 10); - image.drawRoundedRect(ALERT_X, alertY, ALERT_W, ALERT_H, 90, 10); + image.fillRect(ALERT_X, alertY, ALERT_W, ALERT_H, 1); + image.drawRect(ALERT_X, alertY, ALERT_W, ALERT_H, 90); image.drawText(font, ALERT_X + 16, alertY + 12, "Assistant", 200); image.drawTextWrapped({ font, @@ -690,6 +692,8 @@ class Shell { } /** Paint the shell surface: transparent chrome, or all-transparent when asleep. */ + paintScene(): Uint8Array { return encodeShellScene(this.screenOn ? this.stack.paintUndimmed() : []); } + paintSurface(): Plane[] { if (!this.screenOn) { return singlePlane(new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0)); diff --git a/app/ui/shell/tool-debug-layer.ts b/app/ui/shell/tool-debug-layer.ts index 29b636fc..debc9d73 100644 --- a/app/ui/shell/tool-debug-layer.ts +++ b/app/ui/shell/tool-debug-layer.ts @@ -19,7 +19,7 @@ import { lineStep } from "../metrics"; const DIALOG_WIDTH = 420; // Shell overlays align to the min-height window band; the detail box fills // the band below the top bar with an 8px margin on each side. -const DETAIL_HEIGHT = MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 16; +const DETAIL_HEIGHT = 208; /** Dialog left edge: past the sidebar strip where one reserves width. */ function dialogX(): number { @@ -42,6 +42,7 @@ export class ToolDebugMenuLayer extends MenuLayer { x: dialogX(), y: dialogY(), width: DIALOG_WIDTH, + squareCorners: true, minHeight: 0, }); } @@ -89,8 +90,8 @@ class ToolDetailLayer implements Layer { const left = dialogX(); const width = detailWidth(); const top = dialogY(); - image.fillRoundedRect(left, top, width, DETAIL_HEIGHT, 1, 10); - image.drawRoundedRect(left, top, width, DETAIL_HEIGHT, 72, 10); + image.fillRect(left, top, width, DETAIL_HEIGHT, 1); + image.drawRect(left, top, width, DETAIL_HEIGHT, 72); const textX = left + DETAIL_PADDING; const textWidth = width - 2 * DETAIL_PADDING - 8; diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt new file mode 100644 index 00000000..ce7766a1 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt @@ -0,0 +1,90 @@ +package com.faceclaw.app + +/** Revision 25 wire grammar, shared by scene planning and the local renderer. */ +object DrawProtocol { + const val DRAW = 26 + const val ROOT = 27 + const val PRESENT = 28 + const val CREATE = 29 + const val IMAGE = 0 + const val FONT = 1 + const val LIST = 2 + const val LARGE = 4 + const val RLE = 8 + const val SCREEN = 65535 + const val CURRENT = 65534 + fun u16(b: ByteArray, p: Int): Int = (b[p].toInt() and 255) or ((b[p + 1].toInt() and 255) shl 8) + fun word(n: Int) = byteArrayOf(n.toByte(), (n ushr 8).toByte()) + fun call(op: Int, args: ByteArray, target: Int? = null): ByteArray = + byteArrayOf(op.toByte(), if (target == null) 0 else 1) + (target?.let { word(it) } ?: byteArrayOf()) + args + fun sequence(calls: List): ByteArray { + require(calls.size <= 4096) + val out = ByteSink(); out.write(word(calls.size)) + for (call in calls) { require(call.size <= 65535); out.write(word(call.size)); out.write(call) } + return out.toByteArray() + } + fun message(calls: List) = byteArrayOf(DRAW.toByte()) + sequence(calls) + fun displayList(calls: List) = byteArrayOf(LIST.toByte()) + sequence(calls) + fun root(id: Int) = byteArrayOf(ROOT.toByte()) + word(id) + fun image(id: Int, x: Int, y: Int, options: Int = 15, target: Int? = null) = + call(4, word(id) + word(x) + word(y) + byteArrayOf(options.toByte()), target) + fun lut(width: Int, height: Int, factor: Int): ByteArray { + val table = ByteArray(8) { i -> + (((i * 2 * factor / 256).coerceIn(0, 15) shl 4) or ((i * 2 + 1) * factor / 256).coerceIn(0, 15)).toByte() + } + return call(6, word(0) + word(0) + word(width) + word(height) + table) + } + fun rawImage(width: Int, height: Int, pixels: ByteArray = ByteArray(((width + 1) / 2) * height)): ByteArray { + require(width in 1..640 && height in 1..480 && pixels.size == ((width + 1) / 2) * height) + val result = byteArrayOf(LARGE.toByte()) + word(width) + word(height) + pixels + require(result.size <= ResourceCacheState.MAX_RESOURCE_SIZE) + return result + } + /** Packed rows -> RLE of exactly width*height pixels, omitting odd-row padding. */ + fun bbox(packed: ByteArray, stride: Int, x: Int, y: Int, width: Int, height: Int, target: Int? = null): ByteArray { + val compact = x % 4 == 0 && y % 2 == 0 && width % 4 == 0 && height % 2 == 0 && x / 4 < 256 && y / 2 < 256 && width / 4 < 256 && height / 2 < 256 + val header = if (compact) byteArrayOf(0, (x / 4).toByte(), (y / 2).toByte(), (width / 4).toByte(), (height / 2).toByte()) + else byteArrayOf(1) + word(x) + word(y) + word(width) + word(height) + val out = ByteSink(); out.write(header) + var color = -1; var count = 0 + fun flush() { + if (count == 0) return + if (count <= 15) out.write((count shl 4) or color) + else { out.write(color); if (count <= 255) out.write(count) else { out.write(0); out.write(word(count)) } } + } + for (yy in y until y + height) for (xx in x until x + width) { + val value = (packed[yy * stride + xx / 2].toInt() ushr (if (xx % 2 == 0) 4 else 0)) and 15 + if (value != color || count == 65535) { flush(); color = value; count = 0 } + count++ + } + flush() + return call(1, out.toByteArray(), target) + } + /** Internal optimizer formats are translated here; they are never sent to revision 25. */ + fun fromOptimized(payload: ByteArray, width: Int = 640, height: Int = 480): List { + return when (val mode = payload[0].toInt() and 127) { + 8 -> { + val result = ArrayList(); var pos = 2 + repeat(payload[1].toInt() and 255) { val n = u16(payload, pos); pos += 2; result.addAll(fromOptimized(payload.copyOfRange(pos, pos + n), width, height)); pos += n } + require(pos == payload.size); result + } + 3 -> listOf(call(1, byteArrayOf(0) + payload.copyOfRange(1, 5) + payload.copyOfRange(7, payload.size))) + 6 -> listOf(call(1, byteArrayOf(1) + word(0) + word(0) + word(width) + word(height) + payload.copyOfRange(1, payload.size))) + 15 -> listOf(call(3, payload.copyOfRange(1, payload.size))) + 19 -> listOf(call(4, payload.copyOfRange(1, payload.size))) + 20 -> listOf(call(5, payload.copyOfRange(1, payload.size))) + 9 -> listOf(call(2, word(CURRENT) + payload.copyOfRange(1, 9) + payload.copyOfRange(9, 13))) + else -> error("Unsupported internal draw format $mode") + } + } + fun messages(calls: List, maxBytes: Int = 65535): List { + val result = ArrayList(); var batch = ArrayList(); var size = 3 + for (call in calls) { + require(call.size + 5 <= maxBytes) + if (size + 2 + call.size > maxBytes) { result.add(message(batch)); batch = ArrayList(); size = 3 } + batch.add(call); size += call.size + 2 + } + if (batch.isNotEmpty()) result.add(message(batch)) + return result + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt index 59ad80ee..b9bccf6b 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt @@ -1,14 +1,16 @@ package com.faceclaw.app +import kotlin.jvm.JvmOverloads + /** Immutable content-addressed bytes; equality verifies bytes when hashes collide. */ -class CachedResource(bytes: ByteArray) { +class CachedResource @JvmOverloads constructor(bytes: ByteArray, val owner: String? = null) { val bytes: ByteArray = bytes.copyOf() val hash: Long = this.bytes.fold(-3750763034362895579L) { hash, byte -> (hash xor (byte.toLong() and 255)) * 1099511628211L } - override fun hashCode(): Int = (hash xor (hash ushr 32)).toInt() + override fun hashCode(): Int = owner?.hashCode() ?: (hash xor (hash ushr 32)).toInt() override fun equals(other: Any?): Boolean = this === other || - other is CachedResource && hash == other.hash && bytes.contentEquals(other.bytes) + other is CachedResource && owner == other.owner && hash == other.hash && bytes.contentEquals(other.bytes) } /** @@ -18,7 +20,7 @@ class CachedResource(bytes: ByteArray) { */ class ResourceCacheState { companion object { - const val CACHE_SIZE = 262144 + const val CACHE_SIZE = 196608 const val RESOURCE_COUNT = 512 const val TABLE_BYTES = RESOURCE_COUNT * 4 const val ARENA_BYTES = CACHE_SIZE - TABLE_BYTES @@ -32,6 +34,10 @@ class ResourceCacheState { private data class Resident(val id: Int, val resource: CachedResource, var lastUsed: Long) private val residents = LinkedHashMap() private val occupied = BooleanArray(RESOURCE_COUNT) + var generation = 0 + private set + private var pinned = emptySet() + fun pin(resources: Collection) { pinned = resources.toSet() } private var allocated = 0 private var clock = 0L private var resetRequired = true @@ -40,6 +46,8 @@ class ResourceCacheState { /** Forget uncertain device state. The next upload first evicts every ID on both lenses. */ fun reset() { + generation++ + pinned = emptySet() residents.clear(); occupied.fill(false); allocated = 0; clock = 0 evictions.clear(); uploads.clear(); resetRequired = true } @@ -52,6 +60,7 @@ class ResourceCacheState { fun prepare(resources: List): IntArray { check(uploads.isEmpty() && evictions.isEmpty()) { "Previous resource commands have not been drained" } val protected = HashSet() + for (resource in pinned) residents[resource]?.let { protected.add(it.id) } for (resource in resources) residents[resource]?.let { protected.add(it.id) } return IntArray(resources.size) { index -> val resource = resources[index] @@ -126,6 +135,11 @@ class ResourceCacheState { } for (entry in uploads) { val data = entry.resource.bytes + if (entry.resource.owner != null) { + flush() + result.add(byteArrayOf(DrawProtocol.CREATE.toByte(), 1, 0) + DrawProtocol.word(entry.id) + data.copyOfRange(1, 5)) + continue + } var offset = 0 while (offset < data.size) { val count = minOf(data.size - offset, maxPayloadBytes - 13) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt new file mode 100644 index 00000000..25e77715 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt @@ -0,0 +1,77 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmOverloads + +/** The delta base contains only app pixels. Shell resources are composed at presentation. */ +class ScenePlanner(private val cache: ResourceCacheState) { + class Plan(val commands: List, val nextFid: Int) + private val owned = HashMap() + private val pixels = HashMap() + private var previous: ByteArray? = null + private var screenWidth = 0 + private var screenHeight = 0 + private var epoch = -1 + private var root = -1 + @JvmOverloads + fun plan(screen: ByteArray, width: Int, height: Int, draws: Array?, scene: ShellScene, firstId: Int, textures: Boolean = true, incremental: Boolean = true, multiRect: Boolean = true, maxRects: Int = 6): Plan { + require(width in 1..640 && height in 1..480) + if (epoch != cache.generation) { previous = null; pixels.clear(); root = -1; epoch = cache.generation } + require(screen.size == ((width + 1) / 2) * height) + if (width != screenWidth || height != screenHeight) previous = null + screenWidth = width; screenHeight = height + val commands = ArrayList() + val keys = scene.layers.map { "shell:${it.key}:${it.width}x${it.height}" } + val surfaces = scene.layers.mapIndexed { i, layer -> owned.getOrPut(keys[i]) { + CachedResource(DrawProtocol.rawImage(layer.width, layer.height), keys[i]) + } } + owned.keys.retainAll(keys.toSet()); pixels.keys.retainAll(keys.toSet()) + cache.pin(surfaces) + val absent = surfaces.map { cache.resourceId(it) < 0 } + val ids = cache.prepare(surfaces) + check(ids.all { it >= 0 }) { "Shell surfaces exceed the resource budget" } + commands.addAll(cache.drainCommands(3600)) + val rootCalls = ArrayList() + for ((i, layer) in scene.layers.withIndex()) { + val old = if (absent[i]) null else pixels[keys[i]] + commands.addAll(DrawProtocol.messages(pixelCalls(old, layer.packed, layer.width, layer.height, ids[i]))) + pixels[keys[i]] = layer.packed + if (layer.dim < 256) rootCalls.add(DrawProtocol.lut(width, height, layer.dim)) + rootCalls.add(DrawProtocol.image(ids[i], layer.x, layer.y)) + } + val base = if (incremental) previous else null + val texture = if (textures) TexturePlanner.plan(base, screen, width, height, draws, cache, firstId, multiRect, maxRects) else null + if (texture != null) { + commands.addAll(texture.resourceCommands) + commands.addAll(DrawProtocol.messages(DrawProtocol.fromOptimized(texture.payload, width, height))) + } else commands.addAll(DrawProtocol.messages(pixelCalls(base, screen, width, height, null))) + val list = CachedResource(DrawProtocol.displayList(rootCalls)) + val rootId = cache.prepare(listOf(list))[0] + check(rootId >= 0) { "No space for root display list" } + commands.addAll(cache.drainCommands(3600)) + cache.pin(surfaces + list) + val evicted = commands.any { it[0].toInt() == ResourceCacheState.EVICT_MODE } + if (evicted) commands.add(0, DrawProtocol.root(DrawProtocol.SCREEN)) + if (root != rootId || evicted) commands.add(DrawProtocol.root(rootId)) + commands.add(byteArrayOf(DrawProtocol.PRESENT.toByte())) + root = rootId; previous = screen.copyOf() + return Plan(commands, texture?.nextFid ?: firstId) + } + private fun pixelCalls(old: ByteArray?, next: ByteArray, width: Int, height: Int, target: Int?): List { + val stride = (width + 1) / 2 + if (old != null && old.contentEquals(next)) return emptyList() + val calls = ArrayList() + for (top in 0 until height step 32) { + val rows = minOf(32, height - top) + if (old != null && (top * stride until (top + rows) * stride).all { old[it] == next[it] }) continue + var left = width; var right = -1 + for (y in top until top + rows) for (x in 0 until width) { + val p = y * stride + x / 2; val shift = if (x % 2 == 0) 4 else 0 + if (old == null || (((old[p].toInt() xor next[p].toInt()) ushr shift) and 15) != 0) { left = minOf(left, x); right = maxOf(right, x) } + } + if (right < left) continue + if (width % 4 == 0 && rows % 2 == 0) { left = left / 4 * 4; right = minOf(width, ((right + 4) / 4) * 4) - 1 } + calls.add(DrawProtocol.bbox(next, stride, left, top, right - left + 1, rows, target)) + } + return calls + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt index 1b6ecc88..48057a2b 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt @@ -243,7 +243,7 @@ class TexturePlanner { subs.addAll(runs) subs.addAll(fwSubs) var payload: ByteArray = assembleMode8(subs) - if (payload.size > CfwTransport.MAX_MESSAGE) { + if (payload.size > CfwTransport.MAX_MESSAGE - 16) { rollback() return null } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt new file mode 100644 index 00000000..d9354529 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt @@ -0,0 +1,144 @@ +package com.faceclaw.app + +/** Reference interpreter. It uses the firmware's packed rows, clipping, LUT and call grammar. */ +class DisplayListRenderer(private val resources: Map, private val builtin: ((Int, Int) -> BuiltinGlyph)? = null) { + class BuiltinGlyph(val image: ByteArray, val advance: Int, val x: Int = 0, val y: Int = 0) + class Target(val bytes: ByteArray, val width: Int, val height: Int, val offset: Int = 0) { + val stride = (width + 1) / 2 + init { require(width > 0 && height > 0 && offset >= 0 && bytes.size - offset >= stride * height) } + fun get(x: Int, y: Int) = (bytes[offset + y * stride + x / 2].toInt() ushr (if (x % 2 == 0) 4 else 0)) and 15 + fun put(x: Int, y: Int, v: Int) { + if (x !in 0 until width || y !in 0 until height) return + val index = offset + y * stride + x / 2; val old = bytes[index].toInt() + bytes[index] = (if (x % 2 == 0) (old and 15) or (v shl 4) else (old and 240) or v).toByte() + } + } + private class Image(val width: Int, val height: Int, val pixels: IntArray) + private fun word(b: ByteArray, p: Int): Int { require(p >= 0 && p + 2 <= b.size); return DrawProtocol.u16(b, p) } + private fun signed(b: ByteArray, p: Int) = word(b, p).toShort().toInt() + private fun resource(id: Int) = requireNotNull(resources[id]) { "Missing resource $id" } + private fun decodeRle(b: ByteArray, start: Int, count: Int, exact: Boolean): IntArray { + var p = start; var i = 0; val result = IntArray(count) + while (i < count) { + require(p < b.size); val token = b[p++].toInt() and 255; var n = token ushr 4 + if (n == 0) { require(p < b.size); n = b[p++].toInt() and 255 + if (n == 0) { n = word(b, p); p += 2 } } + require(n > 0 && n <= count - i); result.fill(token and 15, i, i + n); i += n + } + require(!exact || p == b.size) + return result + } + private fun image(b: ByteArray, start: Int = 0): Image { + require(start in b.indices); val flags = b[start].toInt() and 255 + require(flags and 12 == flags) + val header = if (flags and 4 != 0) 5 else 3 + require(b.size - start >= header) + val w = if (header == 5) word(b, start + 1) else b[start + 1].toInt() and 255 + val h = if (header == 5) word(b, start + 3) else b[start + 2].toInt() and 255 + require(w in 1..640 && h in 1..480) + val pixels = if (flags and 8 != 0) decodeRle(b, start + header, w * h, false) + else { val t = Target(b, w, h, start + header); IntArray(w * h) { t.get(it % w, it / w) } } + return Image(w, h, pixels) + } + private fun target(id: Int): Target { + val b = resource(id); require(b.isNotEmpty() && b[0].toInt() and 11 == 0) + image(b) // Validate the complete raw image before exposing a write target. + return if (b[0].toInt() and 4 != 0) Target(b, word(b, 1), word(b, 3), 5) + else Target(b, b[1].toInt() and 255, b[2].toInt() and 255, 3) + } + private fun draw(image: Image, target: Target, x: Int, y: Int, options: Int, apply: Boolean) { + if (!apply) return + for (i in image.pixels.indices) { + val v = image.pixels[i]; if (v == 0 && options and 16 != 0) continue + val source = if (options and 32 != 0) 15 - v else v + target.put(x + i % image.width, y + i / image.width, source * (options and 15) / 15) + } + } + /** Validate the whole graph before changing any pixels. Resource writes remain call-scoped. */ + fun render(root: Int, screen: Target, composition: Target): Set { + val references = mutableSetOf() + for (apply in listOf(false, true)) { + if (apply) for (y in 0 until screen.height) for (x in 0 until screen.width) composition.put(x, y, screen.get(x, y)) + if (root != DrawProtocol.SCREEN) executeList(root, composition, screen, apply, mutableListOf(), intArrayOf(4096), references) + } + return references + } + fun execute(sequence: ByteArray, target: Target, screen: Target = target): Set { + val references = mutableSetOf() + for (apply in listOf(false, true)) executeSequence(sequence, target, screen, apply, mutableListOf(), intArrayOf(4096), references) + return references + } + private fun executeList(id: Int, t: Target, screen: Target, apply: Boolean, stack: MutableList, budget: IntArray, refs: MutableSet) { + require(stack.size < 8 && id !in stack); val b = resource(id); require(b.size >= 3 && b[0].toInt() == 2) + refs.add(id); stack.add(id); executeSequence(b.copyOfRange(1, b.size), t, screen, apply, stack, budget, refs); stack.removeAt(stack.lastIndex) + } + private fun executeSequence(b: ByteArray, inherited: Target, screen: Target, apply: Boolean, stack: MutableList, budget: IntArray, refs: MutableSet) { + val count = word(b, 0); var pos = 2 + repeat(count) { + val n = word(b, pos); pos += 2; require(n >= 2 && n <= b.size - pos && budget[0]-- > 0) + val call = b.copyOfRange(pos, pos + n); pos += n + val flags = call[1].toInt() and 255; require(flags <= 1) + var t = inherited; var header = 2 + if (flags == 1) { val id = word(call, 2); refs.add(id); t = target(id); header += 2 } + val p = call.copyOfRange(header, call.size) + when (call[0].toInt()) { + 1 -> { + require(p.isNotEmpty() && p[0].toInt() in 0..1); val wide = p[0].toInt() == 1 + require(p.size >= if (wide) 9 else 5) + val x = if (wide) word(p, 1) else (p[1].toInt() and 255) * 4 + val y = if (wide) word(p, 3) else (p[2].toInt() and 255) * 2 + val w = if (wide) word(p, 5) else (p[3].toInt() and 255) * 4 + val h = if (wide) word(p, 7) else (p[4].toInt() and 255) * 2 + require(w > 0 && h > 0 && x + w <= t.width && y + h <= t.height) + val pixels = decodeRle(p, if (wide) 9 else 5, w * h, true) + if (apply) for (i in pixels.indices) t.put(x + i % w, y + i / w, pixels[i]) + } + 2 -> { + require(p.size == 14); val id = word(p, 0) + val src = when(id) { DrawProtocol.SCREEN -> screen; DrawProtocol.CURRENT -> t; else -> { refs.add(id); target(id) } } + val x = word(p, 2); val y = word(p, 4); val w = word(p, 6); val h = word(p, 8) + require(w > 0 && h > 0 && x + w <= src.width && y + h <= src.height) + val dx = signed(p, 10); val dy = signed(p, 12) + if (apply) { val copy = IntArray(w * h) { src.get(x + it % w, y + it / w) } + for (i in copy.indices) t.put(dx + i % w, dy + i / w, copy[i]) } + } + 3 -> { + require(p.size >= 6 && p.size == 6 + (p[5].toInt() and 255)) + val text = p.copyOfRange(6, p.size).decodeToString(throwOnInvalidSequence = true) + val cps = ArrayList(); var i = 0 + while (i < text.length) { val c = text[i++].code + cps.add(if (c in 0xd800..0xdbff) { require(i < text.length); 0x10000 + ((c - 0xd800) shl 10) + text[i++].code - 0xdc00 } else c) } + var x = signed(p, 0); val y = signed(p, 2) + for (j in cps.indices) { val cp = cps[j] + if (cp in 1..31) { x += cp - 11; continue } + val next = cps.drop(j + 1).firstOrNull { it !in 1..31 } ?: 0 + val g = requireNotNull(builtin) { "Builtin font provider required" }(cp, next) + draw(image(g.image), t, x + g.x, y + g.y, p[4].toInt() and 255, apply); x += g.advance + } + } + 4, 5 -> { + val font = call[0].toInt() == 5; require(if(font) p.size >= 8 && p.size == 8 + (p[7].toInt() and 255) else p.size == 7) + val id = word(p, 0); refs.add(id); val data = resource(id) + var x = signed(p, 2); val y = signed(p, 4); val options = p[6].toInt() and 255 + if (!font) draw(image(data), t, x, y, options, apply) + else { require(data.size >= 193 && data[0].toInt() == 1) + for (j in 8 until p.size) { val ch = p[j].toInt() and 255 + if(ch in 1..31) { x += ch - 11; continue }; require(ch in 32..127) + val offset = word(data, 1 + (ch - 32) * 2); require(offset >= 193) + val glyph = image(data, offset); draw(glyph, t, x, y, options, apply); x += glyph.width + } + } + } + 6 -> { + require(p.size == 16); val x = word(p, 0); val y = word(p, 2); val w = word(p, 4); val h = word(p, 6) + require(w > 0 && h > 0 && x + w <= t.width && y + h <= t.height) + if (apply) for(yy in y until y + h) for(xx in x until x + w) { val v = t.get(xx, yy) + t.put(xx, yy, (p[8 + v / 2].toInt() ushr (if(v % 2 == 0) 4 else 0)) and 15) } + } + 7 -> { require(p.size == 2); executeList(word(p, 0), t, screen, apply, stack, budget, refs) } + else -> error("Unknown draw opcode") + } + } + require(pos == b.size) + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt index 3005f3ed..4c8c7edc 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FontResourceAtlas.kt @@ -13,7 +13,7 @@ class FontResourceAtlas { val old = fonts[fontId] if (old != null && old.encodings.containsAll(requested)) return old val glyphs = HashMap() - var size = 192 + var size = 193 // Current-frame glyphs take precedence if the entire font cannot fit. for (encoding in requested.sorted() + (old?.encodings ?: emptySet()).sorted()) { if (encoding !in 32..127 || glyphs.containsKey(encoding)) continue @@ -22,10 +22,11 @@ class FontResourceAtlas { glyphs[encoding] = glyph; size += glyph.cachedBytes.size } val bytes = ByteArray(size) - var offset = 192 + bytes[0] = DrawProtocol.FONT.toByte() + var offset = 193 for (encoding in glyphs.keys.sorted()) { val glyph = glyphs.getValue(encoding) - val slot = (encoding - 32) * 2 + val slot = 1 + (encoding - 32) * 2 bytes[slot] = offset.toByte(); bytes[slot + 1] = (offset ushr 8).toByte() glyph.cachedBytes.copyInto(bytes, offset) offset += glyph.cachedBytes.size diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt index 6ddc2fce..5d3b3cb7 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt @@ -10,8 +10,8 @@ import kotlin.jvm.JvmStatic * * - as the ink mask for the "would this draw land correctly" check against the composited frame, * - to punch the ink pixels out of the baked delta rect it replaces, - * - pre-encoded as the CFW cached-image bytes ([w][h][4bpp RLE]) uploaded via mode 12 and drawn via - * mode 14 with a top-color LUT. 1bpp (BDF) glyphs store ink at 15 so the LUT maps them to exactly + * - pre-encoded as the CFW cached-image bytes ([flags=RLE][w][h][4bpp RLE]) uploaded as resources and drawn via + * the resource-text draw call with a top-color LUT. 1bpp (BDF) glyphs store ink at 15 so the LUT maps them to exactly * the requested level; AA (TTF) glyphs store true coverage nibbles the LUT scales. * * Fonts are identified by a stable string key (the embedded font name), NOT a per-JS-context @@ -232,7 +232,7 @@ class GlyphAtlas { /** AA coverage, width*inkHeight nibble values 0..15; null for 1bpp glyphs. */ @JvmField val coverage: ByteArray? - /** CFW cached-image bytes: [w][cellHeight][RLE(w*cellHeight px)]. */ + /** CFW cached-image bytes: [flags=RLE][w][cellHeight][RLE(w*cellHeight px)]. */ @JvmField val cachedBytes: ByteArray constructor( @@ -280,16 +280,17 @@ class GlyphAtlas { } /** - * The firmware cached-image encoding: [width][height][RLE tokens] covering exactly + * The firmware cached-image encoding: [flags=RLE][width][height][RLE tokens] covering exactly * width*cellHeight pixels (no row padding), each pixel's stored color being its nibbleAt * value. */ private fun encodeCachedImage(): ByteArray { var total: Int = (width * cellHeight) - var out: ByteArray = ByteArray((2 + total)) - out[0] = (width).toByte() - out[1] = (cellHeight).toByte() - var o: Int = 2 + var out: ByteArray = ByteArray((3 + total)) + out[0] = DrawProtocol.RLE.toByte() + out[1] = (width).toByte() + out[2] = (cellHeight).toByte() + var o: Int = 3 var i: Int = 0 while ((i < total)) { var color: Int = nibbleAt((i % width), (i / width)) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt index 31533760..2a8b21e7 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt @@ -11,7 +11,7 @@ import kotlin.jvm.JvmStatic * * Unlike glyphs (1-bit ink recolored at draw time), images keep their exact 4bpp values: the cached * bytes quantize the registered 8bpp pixels with the same GRAY_TO_NIBBLE table the composite is - * packed with, and the planner draws them via mode 13 with an identity LUT (top color 15) and the + * packed with, and the planner draws them via the image draw call with an identity LUT (top color 15) and the * transparent bit — the draw writes exactly the nonzero-nibble pixels, which is what the * eligibility check and hole punching are defined over. */ @@ -78,7 +78,7 @@ class ImageAtlas { /** One 4bpp value per pixel, row-major. */ @JvmField val nibbles: ByteArray - /** CFW cached-image bytes: [w][h][RLE(w*h pixels)]. */ + /** CFW cached-image bytes: [flags=RLE][w][h][RLE(w*h pixels)]. */ @JvmField val cachedBytes: ByteArray val resource: CachedResource @@ -98,10 +98,11 @@ class ImageAtlas { private fun encodeCachedImage(): ByteArray { var total: Int = (width * height) - var out: ByteArray = ByteArray((2 + total)) - out[0] = (width).toByte() - out[1] = (height).toByte() - var o: Int = 2 + var out: ByteArray = ByteArray((3 + total)) + out[0] = DrawProtocol.RLE.toByte() + out[1] = (width).toByte() + out[2] = (height).toByte() + var o: Int = 3 var i: Int = 0 while ((i < total)) { var color: Int = (nibbles[i] and 0xff) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt new file mode 100644 index 00000000..cfb1570e --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt @@ -0,0 +1,41 @@ +package com.faceclaw.app + +/** Immutable shell snapshot. Keys identify writable surfaces across repaints, not their pixels. */ +class ShellScene(val layers: List) { + class Layer(val key: Int, val x: Int, val y: Int, val width: Int, val height: Int, val dim: Int, val packed: ByteArray) + val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${CachedResource(it.packed).hash}" } + fun preview(screenGray: ByteArray, width: Int, height: Int): ByteArray { + val screen = BmpUtil.pack4bppFromGray8(screenGray, width, height) + val output = ByteArray(screen.size); val resources = HashMap(); val calls = ArrayList() + for ((id, layer) in layers.withIndex()) { + if (layer.dim < 256) calls.add(DrawProtocol.lut(width, height, layer.dim)) + resources[id] = DrawProtocol.rawImage(layer.width, layer.height, layer.packed) + calls.add(DrawProtocol.image(id, layer.x, layer.y)) + } + resources[511] = DrawProtocol.displayList(calls) + DisplayListRenderer(resources).render(511, DisplayListRenderer.Target(screen, width, height), DisplayListRenderer.Target(output, width, height)) + val target = DisplayListRenderer.Target(output, width, height) + return ByteArray(width * height) { (target.get(it % width, it / width) * 16).toByte() } + } + companion object { + val EMPTY = ShellScene(emptyList()) + fun decode(reader: ByteReader): ShellScene { + val count = reader.getShort().toInt() and 65535; require(count <= 64) + val layers = ArrayList() + repeat(count) { + require(reader.remaining() >= 14) + val key = reader.getShort().toInt() and 65535 + val x = reader.getShort().toInt(); val y = reader.getShort().toInt() + val w = reader.getShort().toInt() and 65535; val h = reader.getShort().toInt() and 65535 + val dim = reader.getShort().toInt() and 65535 + val reserved = reader.getShort().toInt(); require(reserved == 0 && dim <= 256) + require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) + val gray = ByteArray(w * h); reader.get(gray) + layers.add(Layer(key, x, y, w, h, dim, BmpUtil.pack4bppFromGray8(gray, w, h))) + } + require(reader.remaining() == 0) + require(layers.map { it.key }.toSet().size == layers.size) + return ShellScene(layers) + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index a08a21d1..e9284a03 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -202,6 +202,8 @@ class SurfaceCompositor { /** One composited full-screen frame plus the metadata the pipeline needs. */ class Composite { + @JvmField var screenGray: ByteArray + @JvmField var shellScene: ShellScene = ShellScene.EMPTY /** Full-screen 8bpp grayscale pixels, screenWidth*screenHeight bytes. */ @JvmField val gray: ByteArray @@ -233,6 +235,7 @@ class SurfaceCompositor { draws: Array?, ) { this.gray = gray + this.screenGray = gray this.width = width this.height = height this.fingerprint = fingerprint @@ -241,6 +244,12 @@ class SurfaceCompositor { } } + private var shellScene: ShellScene? = null + fun setShellScene(reader: ByteReader) { + val scene = ShellScene.decode(reader) + lock.withLock { shellScene = scene } + } + private class Surface { @JvmField val id: String @@ -372,6 +381,7 @@ class SurfaceCompositor { /** The dim factor (256 = none) that applies to a surface. */ private fun dimForLocked(surface: Surface): Int { + if (shellScene != null) return 256 return (if ((surface.zOrder < underlayDimBelowZOrder)) underlayDim else 256) } @@ -560,8 +570,10 @@ class SurfaceCompositor { if (((screenWidth <= 0) || (screenHeight <= 0))) { return null } - var gray: ByteArray = buildGrayLocked() - return Composite(gray, screenWidth, screenHeight, "preview", 0, NO_DRAWS) + val seq = nextCompositeSeq + val result = compositeLocked() + nextCompositeSeq = seq + return result } } @@ -598,7 +610,7 @@ class SurfaceCompositor { fingerprint.append(screenWidth).append('x').append(screenHeight) var draws: MutableList = ArrayList() for (surface in ordered) { - if (!surface.visible) { + if (!surface.visible || (shellScene != null && surface.id == "shell")) { continue } blendLocked(gray, surface) @@ -644,14 +656,10 @@ class SurfaceCompositor { fingerprint.append(":dim").append(dim) } } - return Composite( - gray, - screenWidth, - screenHeight, - fingerprint.toString(), - nextCompositeSeq++, - draws.toTypedArray(), - ) + val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene.EMPTY else shellScene ?: ShellScene.EMPTY + val preview = if (shellScene != null) scene.preview(gray, screenWidth, screenHeight) else gray + return Composite(preview, screenWidth, screenHeight, fingerprint.append("|shell:").append(scene.fingerprint).toString(), + nextCompositeSeq++, draws.toTypedArray()).also { it.screenGray = gray; it.shellScene = scene } } private fun blendLocked(gray: ByteArray, surface: Surface): Unit { diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt index 9129c3d7..c2a9b2ea 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt @@ -230,6 +230,8 @@ class IosSurfaceCompositor(width: Int, height: Int) { fun blank(blanked: Boolean) = compositor.setBlanked(blanked) + fun shell(data: NSData) = compositor.setShellScene(IosByteReader(data)) + fun submit(id: String, data: NSData, x: Int, y: Int, width: Int, height: Int) = submitDraws(id, data, x, y, width, height, null) diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt index b97f5b49..968dd637 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosTextureApi.kt @@ -21,24 +21,23 @@ class IosTextureFrame internal constructor(internal val composite: SurfaceCompos val pixels: NSData = composite.gray.data() } -class IosTexturePlan internal constructor(result: TexturePlanner.Result, val usedBytes: Int) { - val payload: NSData = result.payload.data() - val resourceCommands: List = result.resourceCommands.map { it.data() } +class IosTexturePlan internal constructor(result: ScenePlanner.Plan, val usedBytes: Int) { + val payload: NSData = result.commands.last().data() + val resourceCommands: List = result.commands.dropLast(1).map { it.data() } val nextFid: Int = result.nextFid } /** One instance per BLE session, called on the session's serial JS thread. */ class IosTexturePlanner { private val cache = ResourceCacheState() + private val planner = ScenePlanner(cache) fun reset() = cache.reset() fun plan(previous: NSData?, next: NSData, frame: IosTextureFrame, firstId: Int): IosTexturePlan? { val composite = frame.composite - val result = TexturePlanner.plan( - previous?.byteArray(), next.byteArray(), composite.width, composite.height, - composite.draws, cache, firstId, true, ConnectionOptions.MULTI_RECT_MAX_RECTS, - ) ?: return null + val result = planner.plan(BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height), + composite.width, composite.height, composite.draws, composite.shellScene, firstId) return IosTexturePlan(result, cache.usedBytes()) } } diff --git a/tests/ai-chat.test.cjs b/tests/ai-chat.test.cjs index dccf7f0a..8367b291 100644 --- a/tests/ai-chat.test.cjs +++ b/tests/ai-chat.test.cjs @@ -248,6 +248,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {}) const settings = { wakeWordActionSetting: { get: () => wakeAction }, brightnessSetting: { get: () => 'auto' }, assistantSkipConfirmationSetting: { get: () => skipConfirmation } }; const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', { + '../../graphics/shell-scene': { encodeShellScene: () => new Uint8Array([0, 0]) }, '../../graphics/image': images, '../../graphics/plane': {}, '../../graphics/ui-fonts': {}, '../../g2/events': load('app/g2/events.ts', {}), '../gestures': gestures, '../layers': layers, '../menu': { MenuLayer: Menu }, '../input-monitor': load('app/ui/input-monitor.ts', {}), diff --git a/tests/helpers/display-payload.cjs b/tests/helpers/display-payload.cjs index 52fac8c1..40bae279 100644 --- a/tests/helpers/display-payload.cjs +++ b/tests/helpers/display-payload.cjs @@ -2,7 +2,22 @@ const assert = require('node:assert/strict'); // Independent firmware-format decoder for reconstruction tests (not app code). function applyDisplayPayload(base, payload, width = 640, height = 480) { - const mode = payload[0]; assert.ok(mode === 3 || mode === 6); + const mode = payload[0]; + if (mode === 28) return base; + if (mode === 26) { + const word = i => payload[i] | payload[i+1] << 8; + let pos=3, out=base; + for(let n=0;n>8,height&255,height>>8]);legacy=Uint8Array.from([6,...call.subarray(11)]); } + out=applyDisplayPayload(out,legacy,width,height); + } + assert.equal(pos,payload.length);return out; + } + assert.ok(mode === 3 || mode === 6); const [left, top, w, h] = mode === 3 ? [payload[1] * 4, payload[2] * 2, payload[3] * 4, payload[4] * 2] : [0, 0, width, height]; assert.ok(w > 0 && h > 0 && left + w <= width && top + h <= height); diff --git a/tests/ios-app-host.test.cjs b/tests/ios-app-host.test.cjs index 3f8543b9..2547a4a4 100644 --- a/tests/ios-app-host.test.cjs +++ b/tests/ios-app-host.test.cjs @@ -212,7 +212,7 @@ test('background glasses input still composites frames; phone resume preserves t setScreenOn: on => screenStates.push(on), requestRender() {} }; const shell = { configure() {}, registerWindow() {}, wake() {}, focusWindow() {}, getWindows: () => [window], foregroundWindow: () => window, isScreenOn: () => true, - setBatteryLevels() {}, paintSurface() {}, underlayDim: () => 0, getFocus: () => 'app', + setBatteryLevels() {}, paintScene() { return new Uint8Array([0,0]); }, paintSurface() {}, underlayDim: () => 0, getFocus: () => 'app', receiveInput: async input => { inputs.push(input); } }; class Session { state = { phase: 'disconnected' }; @@ -247,7 +247,7 @@ test('background glasses input still composites frames; phone resume preserves t '../apps/all-apps': { ALL_APPS: [] }, '../ui/dashboard-settings': settings, '../native/phone-battery': { readPhoneBatteryState: () => ({ battery: 80, charging: false }) }, '../graphics/surface-compositor': { SurfaceCompositor: class { - configureSurface() {} setSurfaceVisible() {} submitSurfaceFrame() {} setUnderlayDim() {} setScreenBlanked() {} + setShellScene() {} configureSurface() {} setSurfaceVisible() {} submitSurfaceFrame() {} setUnderlayDim() {} setScreenBlanked() {} compositeFrame() { return { pixels: new Uint8Array([1, 2]) }; } } }, '../graphics/plane': { flattenPlanesWithDraws: () => ({ image: { pixels: new Uint8Array([1, 2]), width: 2, height: 1 }, draws: [] }) }, diff --git a/tests/ios-ble.test.cjs b/tests/ios-ble.test.cjs index d7c3d5e6..3003c085 100644 --- a/tests/ios-ble.test.cjs +++ b/tests/ios-ble.test.cjs @@ -178,9 +178,9 @@ test('session authenticates both arms, checks firmware and sends acknowledged di assert.equal(h.session.state.charging, false); assert.deepEqual(h.transport.sent.filter(s => s.message.sid === 128).map(s => s.id).sort(), ['L', 'R']); h.session.setFrame(new Uint8Array(640 * 480)); await until(() => h.session.state.frames === 1); - const image = h.transport.sent.find(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 6); + const image = h.transport.sent.find(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 26); assert.equal(image.id, 'L'); - assert.equal(image.message.payload[0], 6); + assert.equal(image.message.payload[0], 26); const layout = h.transport.sent.find(s => s.message.sid === p.SID.hub && s.message.command === 0); assert.equal(p.readBytes(p.readBytes(layout.message.payload, 3), 4), undefined); await h.session.stop(); @@ -399,14 +399,15 @@ test('CFW ACK identity and both-lens completion gate display metrics', async t = const write = h.transport.write.bind(h.transport); h.transport.write = async (...args) => { written += args[2].length; await write(...args); }; h.session.setFrame(new Uint8Array(640 * 480)); - await until(() => imageMessages(h.transport).length === 1); - const sent = imageMessages(h.transport)[0]; + await until(() => imageMessages(h.transport).length === 2); + const [draw, sent] = imageMessages(h.transport); + ack(h.transport,draw); for (const wrong of [{ identifier: 'R' }, { size: 99 }, { checksum: 0 }, { ordinal: 1 }, { magic: sent.message.magic + 1 }]) ack(h.transport, sent, wrong); ack(h.transport, sent, { lenses: [1] }); await tick(); assert.equal(h.session.state.frames, 0); ack(h.transport, sent, { lenses: [2] }); await until(() => h.session.state.frames === 1); assert.equal(iosBleTraffic.sample().bytes - before.bytes, written); - assert.equal(iosBleTraffic.sample().messages - before.messages, 1); + assert.equal(iosBleTraffic.sample().messages - before.messages, 2); assert.equal(iosBleTraffic.sample().frames - before.frames, 1); ack(h.transport, sent); await tick(); assert.equal(h.session.state.frames, 1); }); @@ -421,7 +422,7 @@ test('large frames use bounded RLE bands and ordered three-message pipelining', assert.equal(imageMessages(h.transport).length, 3); assert.equal(h.session.state.frames, 0); ack(h.transport, first[0]); await until(() => imageMessages(h.transport).length === 6); for (const sent of imageMessages(h.transport).slice(3)) ack(h.transport, sent); - await until(() => imageMessages(h.transport).length === 8); + await until(() => imageMessages(h.transport).length === 9); assert.equal(h.session.state.frames, 0); for (const sent of imageMessages(h.transport).slice(6)) ack(h.transport, sent); await until(() => h.session.state.frames === 1); @@ -433,19 +434,21 @@ test('large frames use bounded RLE bands and ordered three-message pipelining', assert.deepEqual(shadow, p.packGray4(gray, 640, 480)); }); -test('display pipelines A-B-A and coalesces newer waiting frames', async t => { - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - const submit = async value => { h.session.setFrame(new Uint8Array(640 * 480).fill(value)); await h.session.pump(); await tick(); }; - await submit(0); await submit(0); assert.equal(imageMessages(h.transport).length, 1); - await submit(255); await submit(0); await until(() => imageMessages(h.transport).length === 3); - await submit(80); await submit(160); - const sent = imageMessages(h.transport); - ack(h.transport, sent[2]); ack(h.transport, sent[1]); await tick(); - assert.equal(h.session.state.frames, 0); assert.equal(imageMessages(h.transport).length, 3); - ack(h.transport, sent[0]); await until(() => imageMessages(h.transport).length === 4); - assert.equal(h.session.state.frames, 3); - assert.deepEqual(imageBody(imageMessages(h.transport)[3]), p.concat(new Uint8Array([6]), p.rle4(p.packGray4(new Uint8Array(640 * 480).fill(160), 640, 480)))); - ack(h.transport, imageMessages(h.transport)[3]); await until(() => h.session.state.frames === 4); +test('draw/present pairs pipeline and coalesce waiting frames', async t => { + const h=harness(t);await h.session.start(addresses);h.transport.hold=true; + const submit=async v=>{h.session.setFrame(new Uint8Array(640*480).fill(v));await h.session.pump();await tick();}; + await submit(0);await submit(0);assert.equal(imageMessages(h.transport).length,2); + await submit(255);await until(()=>imageMessages(h.transport).length===3); + await submit(80);await submit(160); + const first=imageMessages(h.transport);ack(h.transport,first[2]);ack(h.transport,first[1]);await tick(); + assert.equal(h.session.state.frames,0);assert.equal(imageMessages(h.transport).length,3); + ack(h.transport,first[0]);await until(()=>imageMessages(h.transport).length===6); + for(const message of imageMessages(h.transport).slice(3)) ack(h.transport,message); + await until(()=>h.session.state.frames===3); + const {applyDisplayPayload}=require('./helpers/display-payload.cjs');let screen=new Uint8Array(320*480); + for(const {message} of imageMessages(h.transport)) screen=applyDisplayPayload(screen,message.payload); + assert.deepEqual(screen,p.packGray4(new Uint8Array(640*480).fill(160),640,480)); + assert.deepEqual(imageMessages(h.transport).map(s=>s.message.payload[0]),[26,28,26,28,26,28]); }); test('NACK replays the unresolved window with fresh IDs and reset compression; stale ACKs are ignored', async t => { @@ -459,6 +462,8 @@ test('NACK replays the unresolved window with fresh IDs and reset compression; s for (const sent of old) ack(h.transport, sent); await tick(); assert.equal(h.session.state.frames, 0); replay.forEach((sent, i) => { assert.notEqual(sent.message.magic, old[i].message.magic); assert.ok(sent.message.flags & 8); assert.deepEqual(sent.message.payload, old[i].message.payload); ack(h.transport, sent); }); + await until(() => imageMessages(h.transport).length === 9); + imageMessages(h.transport).slice(6).forEach(sent=>ack(h.transport,sent)); await until(() => h.session.state.frames === 3); }); @@ -470,10 +475,10 @@ test('timeout starts after writes; missing ACK retries are bounded and invalidat h.session.setFrame(new Uint8Array(640 * 480)); await h.session.pump(); await new Promise(resolve => setTimeout(resolve, 550)); assert.equal(h.session.state.phase, 'connected'); assert.equal(imageMessages(h.transport).length, 0); - release(); await until(() => imageMessages(h.transport).length === 1); await tick(); + release(); await until(() => imageMessages(h.transport).length === 2); await tick(); for (let i = 1; i <= 4; i++) { h.session.cfwPending.forEach(p => p.deadline = 1); h.session.recoverCfw(); - if (i < 4) await until(() => imageMessages(h.transport).length === i + 1); + if (i < 4) await until(() => imageMessages(h.transport).length === 2 * (i + 1)); } assert.equal(h.session.state.phase, 'retrying'); assert.match(h.session.state.status, /retry limit/); assert.equal(h.session.lastEnqueued, null); assert.equal(h.session.cfwPending.length, 0); @@ -509,55 +514,30 @@ test('full display window still services input and microphone control', async t assert.deepEqual(audio, ['010203']); assert.equal(h.session.displayInFlight, 3); }); -test('pipelined bounding boxes reconstruct moving and erased content against the last queued frame', async t => { - const { applyDisplayPayload } = require('./helpers/display-payload.cjs'); - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - const base = new Uint8Array(640 * 480), a = base.slice(), b = base.slice(); - a[11 * 640 + 13] = 255; b[11 * 640 + 101] = 160; - const frames = [base, a, b]; - for (let i = 0; i < frames.length; i++) { - h.session.setFrame(frames[i]); await h.session.pump(); - await until(() => imageMessages(h.transport).length === i + 1); +test('draw updates reconstruct moving and erased pixels while present gates frame completion', async t => { + const {applyDisplayPayload}=require('./helpers/display-payload.cjs'); + const h=harness(t);await h.session.start(addresses);h.transport.hold=true; + const base=new Uint8Array(640*480),a=base.slice(),b=base.slice();a[11*640+13]=255;b[11*640+101]=160; + let screen=new Uint8Array(320*480); + for(const [i,frame] of [base,a,b,base].entries()) { + h.session.setFrame(frame);await h.session.pump();await until(()=>imageMessages(h.transport).length===(i+1)*2); + const [draw,present]=imageMessages(h.transport).slice(i*2); + assert.equal(draw.message.payload[0],26);assert.equal(present.message.payload[0],28); + screen=applyDisplayPayload(screen,draw.message.payload);assert.deepEqual(screen,p.packGray4(frame,640,480)); + ack(h.transport,draw);await tick();assert.equal(h.session.state.frames,i); + ack(h.transport,present);await until(()=>h.session.state.frames===i+1); } - const messages = imageMessages(h.transport), payloads = messages.map(m => imageBody(m)); - assert.deepEqual(payloads.map(b => b[0]), [6, 3, 3]); - assert.deepEqual(payloads.slice(1).map(b => b[5] | (b[6] << 8)), [1, 2]); - assert.equal(h.session.state.frames, 0); // All three updates precede any ACK. - let shadow = new Uint8Array(320 * 480); - for (let i = 0; i < payloads.length; i++) { - shadow = applyDisplayPayload(shadow, payloads[i]); - assert.deepEqual(shadow, p.packGray4(frames[i], 640, 480)); - } - // A late ACK for the old full frame must not replace the delta comparison base. - ack(h.transport, messages[0]); await until(() => h.session.state.frames === 1); - h.session.setFrame(base); await h.session.pump(); - await until(() => imageMessages(h.transport).length === 4); - const clear = imageBody(imageMessages(h.transport)[3]); - assert.equal(clear[0], 3); assert.equal(clear[1], 25); // Only B's dot needs clearing. - assert.deepEqual(applyDisplayPayload(shadow, clear), p.packGray4(base, 640, 480)); - for (const message of imageMessages(h.transport).slice(1)) ack(h.transport, message); - await until(() => h.session.state.frames === 4); + assert.equal(imageMessages(h.transport)[2].message.payload[7],0); // compact bbox }); -test('delta ids skip reserved values and advance only on emitted deltas; reconnect reseeds with a full frame', async t => { - const h = harness(t); await h.session.start(addresses); - const submit = async gray => { - const before = h.session.state.frames; h.session.setFrame(gray); - await until(() => h.session.state.frames === before + 1); - return imageBody(imageMessages(h.transport).at(-1)); - }; - const base = new Uint8Array(640 * 480), next = base.slice(); next[1234] = 255; - assert.equal((await submit(base))[0], 6); - h.session.nextImageFrameId = 0xfffe; - const delta = await submit(next); assert.equal(delta[5] | (delta[6] << 8), 0xfffe); - h.session.setFrame(next); await h.session.pump(); await tick(); - assert.equal(h.session.nextImageFrameId, 1); - const full = await submit(new Uint8Array(640 * 480).fill(255)); assert.equal(full[0], 6); - assert.equal(h.session.nextImageFrameId, 1); - const clear = await submit(next); assert.equal(clear[0], 6); // Whole-screen bounding box. - const wrapped = await submit(base); assert.equal(wrapped[5] | (wrapped[6] << 8), 1); - await h.session.stop(); await h.session.start(addresses); - assert.equal((await submit(base))[0], 6); // Even the same pixels need a trusted full base. +test('reconnect reseeds the screen and unified draw calls carry no legacy frame id', async t => { + const h=harness(t);await h.session.start(addresses); + const submit=async gray=>{const before=h.session.state.frames;h.session.setFrame(gray);await until(()=>h.session.state.frames===before+1);return imageBody(imageMessages(h.transport).at(-2));}; + const base=new Uint8Array(640*480),next=base.slice();next[1234]=255; + assert.equal((await submit(base))[7],1); // wide full-screen bounds + const delta=await submit(next);assert.equal(delta[7],0); // compact bbox, immediately followed by RLE + const count=imageMessages(h.transport).length;h.session.setFrame(next);await h.session.pump();await tick();assert.equal(imageMessages(h.transport).length,count); + await h.session.stop();await h.session.start(addresses);assert.equal((await submit(next))[7],1); }); const compassMessages = transport => transport.sent.filter(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 10); diff --git a/tests/ios-glanceboard.test.cjs b/tests/ios-glanceboard.test.cjs index 52572abc..555acfe2 100644 --- a/tests/ios-glanceboard.test.cjs +++ b/tests/ios-glanceboard.test.cjs @@ -48,7 +48,7 @@ function fixture() { isScreenOn: () => screenOn, getWindows: () => [window], foregroundWindow: () => window, setBatteryLevels() {}, underlayDim: () => 1, getFocus: () => 'app', hasOverlay: () => false, describeInputTarget: () => 'test app', - paintSurface: () => [{ image: new images.GrayImage(640, 480, 0), x: 0, y: 0 }], + paintScene: () => new Uint8Array([0, 0]), paintSurface: () => [{ image: new images.GrayImage(640, 480, 0), x: 0, y: 0 }], receiveInput: async input => { received.push(input); if (input.type === 'display-wake' || !screenOn && input.type === 'double-click') shell.wake(); @@ -179,17 +179,17 @@ test('double-tap and other shell wakes replace Glanceboard without waking it aga const f = fixture(); await f.controller.connect(); f.shell.sleep(); await f.hardware(9); await f.hardware(3); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.controller.glance.isVisible(), false); - assert.equal(f.sent.at(-1)[0], 75); assert.equal(f.boardStats.stops, 1); + assert.equal(f.sent.at(-1)[0], 80); assert.equal(f.boardStats.stops, 1); f.shell.sleep(); await f.hardware(0); f.shell.wake(); await f.render(); - assert.equal(f.controller.glance.isVisible(), false); assert.equal(f.sent.at(-1)[0], 75); - await f.advance(5000); await f.render(); assert.equal(f.sent.at(-1)[0], 75); + assert.equal(f.controller.glance.isVisible(), false); assert.equal(f.sent.at(-1)[0], 80); + await f.advance(5000); await f.render(); assert.equal(f.sent.at(-1)[0], 80); }); test('head tilt uses Glanceboard when enabled and otherwise wakes the regular UI', async () => { const f = fixture(); await f.controller.connect(); f.shell.sleep(); await f.hardware(12, 1); assertBoard(f.sent.at(-1)); assert.equal(f.shell.isScreenOn(), false); await f.hardware(3); f.shell.sleep(); f.settings.tilt = false; - await f.hardware(12, 1); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.sent.at(-1)[0], 75); + await f.hardware(12, 1); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.sent.at(-1)[0], 80); }); test('disabled triggers and scrolls do not show the board; awake taps still reach the shell', async () => { @@ -234,7 +234,7 @@ test('iOS lock hides apps and Glanceboard, blocks input, and stays locked when p await f.hardware(12, 1); assert.ok(f.sent.at(-1).every(p => p === 123)); f.observers.get('unlock')(); await f.render(); assert.equal(f.controller.glassesLocked, false); - assert.equal(f.sent.at(-1)[0], 75); + assert.equal(f.sent.at(-1)[0], 80); await f.hardware(0); assert.equal(f.received.length, 1); }); diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt new file mode 100644 index 00000000..b694b83c --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt @@ -0,0 +1,83 @@ +package com.faceclaw.app + +import kotlin.test.* + +class DisplayListTest { + private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray() + @Test fun oddPixelsRawRleClippingFontsNestedListsAndLut() { + val raw = DrawProtocol.rawImage(3, 3, hex("123045607890")) + val font = ByteArray(197); font[0]=1; font[67]=193.toByte(); hex("0801011f").copyInto(font,193) + val resources = mutableMapOf(10 to raw, 11 to hex("0802024f"), 12 to font) + val nested = listOf(DrawProtocol.image(11, -1, 0), DrawProtocol.bbox(hex("0c000000"), 2, 1, 0, 1, 1, 10)) + resources[20]=DrawProtocol.displayList(nested) + val calls = listOf(DrawProtocol.call(7,DrawProtocol.word(20)), DrawProtocol.image(10,3,1), + DrawProtocol.call(5,hex("0c00070003000f0141")), DrawProtocol.lut(8,4,128)) + resources[21]=DrawProtocol.displayList(calls) + val screen=hex("123456789abcdef0123456789abcdef0"); val output=ByteArray(16) + val renderer=DisplayListRenderer(resources) + assertEquals(setOf(10,11,12,20,21),renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4))) + // Shared with the C sanitizer harness: signed clipping, resource target override, font and LUT. + assertContentEquals(hex("71122334755061700112233445534477"),output) + val first=output.copyOf(); renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4)) + assertContentEquals(first,output) + assertContentEquals(hex("123456789abcdef0123456789abcdef0"),screen) + } + @Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() { + val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1) + val copy=DrawProtocol.call(2,hex("feff000000000600010002000000")) + DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(copy)),target) + assertContentEquals(hex("12123456"),screen) + val valid=DrawProtocol.bbox(hex("ffffffff"),4,0,0,8,1) + assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(valid,byteArrayOf(99,0))),target) } + assertContentEquals(hex("12123456"),screen) + val cyclic=mapOf(1 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(2)))), + 2 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(1))))) + assertFails { DisplayListRenderer(cyclic).render(1,target,target) } + } + private class Glasses { + val resources=mutableMapOf(); val screen=ByteArray(640*480/2);val composition=ByteArray(screen.size) + var root=65535 + fun apply(commands: List) { + for(b in commands) when(b[0].toInt()) { + 21 -> { var p=3;repeat(DrawProtocol.u16(b,1)) { + val id=DrawProtocol.u16(b,p); val total=DrawProtocol.u16(b,p+2) or (DrawProtocol.u16(b,p+4) shl 16) + val offset=DrawProtocol.u16(b,p+6);val n=DrawProtocol.u16(b,p+8) + b.copyInto(resources.getOrPut(id){ByteArray(total)},offset,p+10,p+10+n);p+=10+n + } } + 22 -> repeat(DrawProtocol.u16(b,1)) { resources.remove(DrawProtocol.u16(b,3+it*2)) } + 29 -> repeat(DrawProtocol.u16(b,1)) { val p=3+it*6;resources.getOrPut(DrawProtocol.u16(b,p)) { DrawProtocol.rawImage(DrawProtocol.u16(b,p+2),DrawProtocol.u16(b,p+4)) } } + 26 -> DisplayListRenderer(resources).execute(b.copyOfRange(1,b.size),DisplayListRenderer.Target(screen,640,480)) + 27 -> root=DrawProtocol.u16(b,1) + 28 -> DisplayListRenderer(resources).render(root,DisplayListRenderer.Target(screen,640,480),DisplayListRenderer.Target(composition,640,480)) + else -> error("legacy command ${b[0]}") + } + } + } + @Test fun persistentShellUpdatesDoNotPolluteScreenAndClosingRevealsCurrentApp() { + val cache=ResourceCacheState();val planner=ScenePlanner(cache);val glasses=Glasses() + val app=ByteArray(640*480/2){0x99.toByte()} + val overlay=ShellScene(listOf(ShellScene.Layer(1,0,0,3,3,128,hex("fff0fff0fff0")))) + val first=planner.plan(app,640,480,null,overlay,1);glasses.apply(first.commands) + assertContentEquals(app,glasses.screen);assertEquals(255,glasses.composition[0].toInt() and 255) + assertEquals(0x44,glasses.composition[100].toInt() and 255) + val changed=ShellScene(listOf(ShellScene.Layer(1,0,0,3,3,128,hex("111011101110")))) + val repaint=planner.plan(app,640,480,null,changed,1) + assertFalse(repaint.commands.any { it[0].toInt() in listOf(21,22,29) }) + glasses.apply(repaint.commands);assertContentEquals(app,glasses.screen) + val newer=app.copyOf();newer[0]=0x22 + glasses.apply(planner.plan(newer,640,480,null,changed,1).commands) + glasses.apply(planner.plan(newer,640,480,null,ShellScene.EMPTY,1).commands) + assertContentEquals(newer,glasses.composition) + cache.reset();val reconnect=planner.plan(newer,640,480,null,changed,1) + assertTrue(reconnect.commands.any { it[0].toInt()==29 });glasses.apply(reconnect.commands) + assertContentEquals(newer,glasses.screen) + } + @Test fun noisyFramesRemainBoundedAndResourceBudgetIs192KiB() { + val cache=ResourceCacheState();val planner=ScenePlanner(cache);val glasses=Glasses() + val app=ByteArray(640*480/2){(it*37).toByte()} + val plan=planner.plan(app,640,480,null,ShellScene.EMPTY,1) + assertTrue(plan.commands.all { it.size<=65535 });glasses.apply(plan.commands) + assertContentEquals(app,glasses.screen);assertContentEquals(app,glasses.composition) + assertEquals(196608,ResourceCacheState.CACHE_SIZE) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt index 88d7815f..2666890b 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt @@ -64,7 +64,7 @@ class ResourceCacheTest { @Test fun lruEvictsByBytesAndProtectsAllCurrentFrameHits() { val cache = ResourceCacheState() - val a = resource(65536, 1); val b = resource(65536, 2); val c = resource(65536, 3); val d = resource(65536, 4) + val a = resource(60000, 1); val b = resource(60000, 2); val c = resource(60000, 3); val d = resource(60000, 4) assertContentEquals(intArrayOf(0, 1, 2), cache.prepare(listOf(a, b, c))) cache.drainCommands(3600) cache.prepare(listOf(a)); cache.drainCommands(3600) // b is oldest now. @@ -142,12 +142,12 @@ class ResourceCacheTest { @Test fun fontTablesUseRelativeU16OffsetsAndGrowOnDemand() { val id = registerFont("resource-font-relative", listOf(65, 66)) val first = FontResourceAtlas.get(id, setOf(65)) - assertEquals(192, u16(first.resource.bytes, (65 - 32) * 2)) - assertEquals(0, u16(first.resource.bytes, (66 - 32) * 2)) + assertEquals(193, u16(first.resource.bytes, 1 + (65 - 32) * 2)) + assertEquals(0, u16(first.resource.bytes, 1 + (66 - 32) * 2)) assertSame(first, FontResourceAtlas.get(id, setOf(65))) val second = FontResourceAtlas.get(id, setOf(66)) assertTrue(second.encodings.containsAll(setOf(65, 66))) - assertEquals(192 + GlyphAtlas.get(id, 65)!!.cachedBytes.size, u16(second.resource.bytes, (66 - 32) * 2)) + assertEquals(193 + GlyphAtlas.get(id, 65)!!.cachedBytes.size, u16(second.resource.bytes, 1 + (66 - 32) * 2)) val cache = ResourceCacheState() cache.prepare(listOf(second.resource)); val commands = cache.drainCommands(3600) assertContentEquals(second.resource.bytes, uploaded(commands).getValue(0)) @@ -160,7 +160,7 @@ class ResourceCacheTest { val b = FontResourceAtlas.get(id, setOf(66)) assertEquals(setOf(66), b.encodings) assertTrue(b.resource.bytes.size <= 65536) - assertEquals(0, u16(b.resource.bytes, (65 - 32) * 2)) - assertEquals(192, u16(b.resource.bytes, (66 - 32) * 2)) + assertEquals(0, u16(b.resource.bytes, 1 + (65 - 32) * 2)) + assertEquals(193, u16(b.resource.bytes, 1 + (66 - 32) * 2)) } } diff --git a/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt index e3eeda4c..2271ed98 100644 --- a/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt +++ b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosTextureApiTest.kt @@ -24,9 +24,9 @@ class IosTextureApiTest { val next = IosProtocol().pack(frame.pixels, 8, 4) val planner = IosTexturePlanner() val cold = assertNotNull(planner.plan(null, next, frame, 1)) - assertEquals(22, cold.resourceCommands.first().byteArray()[0].toInt()) + assertEquals(27, cold.resourceCommands.first().byteArray()[0].toInt()) assertTrue(cold.resourceCommands.any { it.byteArray()[0].toInt() == 21 }) - assertEquals(8, cold.payload.byteArray()[0].toInt()) + assertEquals(28, cold.payload.byteArray()[0].toInt()) val warm = assertNotNull(planner.plan(null, next, frame, 1)) assertTrue(warm.resourceCommands.isEmpty()) assertContentEquals(cold.payload.byteArray(), warm.payload.byteArray()) @@ -52,10 +52,11 @@ class IosTextureApiTest { val frame = compositor.compositeFrame() val plan = assertNotNull(IosTexturePlanner().plan(null, IosProtocol().pack(frame.pixels, 4, 2), frame, 1)) assertTrue(plan.usedBytes > 2048 + 192) - val payload = plan.payload.byteArray() - // The last mode-8 submessage is the shared mode-20 cached glyph run. - assertEquals(20, payload[payload.size - 10].toInt()) - assertEquals(65, payload.last().toInt()) + assertEquals(28, plan.payload.byteArray()[0].toInt()) + assertTrue(plan.resourceCommands.any { command -> + val bytes = command.byteArray() + bytes[0].toInt() == 26 && bytes.last().toInt() == 65 + }) } @Test @@ -76,7 +77,9 @@ class IosTextureApiTest { compositor.submitDraws("noise", gray.data(), 0, 0, 640, 480, imageDraw(id).data()) val frame = compositor.compositeFrame() val planner = IosTexturePlanner() - assertNull(planner.plan(null, IosProtocol().pack(frame.pixels, 640, 480), frame, 1)) + val noisy = assertNotNull(planner.plan(null, IosProtocol().pack(frame.pixels, 640, 480), frame, 1)) + assertTrue(noisy.resourceCommands.all { it.length <= 65535uL }) + planner.reset() val small = IosSurfaceCompositor(4, 2) small.configure("icon", 0, 0, 2, 2, 0, false) small.submitDraws("icon", white, 0, 0, 2, 2, imageDraw(id).data()) From 392554dd37378a33d815be4e3f07f1d7f6a818c1 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 02:33:29 -0700 Subject: [PATCH 04/27] Depth effects --- app/g2/firmware-compat.ts | 2 +- app/g2/firmware/cfw-patches.ts | 68 +++++------ app/graphics/glyph-wire.ts | 8 +- app/graphics/image.ts | 53 ++++++++- app/graphics/plane.ts | 75 +++++++++--- app/graphics/presentation-wire.ts | 64 ++++++++++ app/graphics/shell-scene.ts | 20 ++-- app/graphics/surface-compositor.ts | 18 ++- app/native/kotlin-protocol-smoke.ios.ts | 12 +- app/ui/layers.ts | 3 +- app/ui/menu.ts | 29 +++-- app/ui/shell/chrome-layer.ts | 16 ++- app/ui/shell/shell.ts | 1 + app/ui/window-menu.ts | 1 + .../faceclaw/app/g2protocol/DrawProtocol.kt | 23 +++- .../faceclaw/app/g2protocol/ScenePlanner.kt | 15 +-- .../app/graphics/DisplayListRenderer.kt | 37 +++++- .../faceclaw/app/graphics/MenuSelection.kt | 56 +++++++++ .../com/faceclaw/app/graphics/ShellScene.kt | 41 ++++--- .../app/graphics/SurfaceCompositor.kt | 9 +- tests/compass-texture-cache.test.cjs | 2 +- .../com/faceclaw/app/DisplayListTest.kt | 85 +++++++++++++- tests/menu-display-list.test.cjs | 110 ++++++++++++++++++ tests/music-settings.test.cjs | 4 + tests/notification-filter.test.cjs | 4 + tests/tsconfig.json | 3 + 26 files changed, 623 insertions(+), 136 deletions(-) create mode 100644 app/graphics/presentation-wire.ts create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt create mode 100644 tests/menu-display-list.test.cjs diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index 493b3a87..e2bfad68 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -26,7 +26,7 @@ export type FirmwareInfo = { }; /** The Faceclaw firmware revision this build of the app needs. */ -export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 25; +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 26; const FACECLAW_PREFIX = "Faceclaw/"; const LEGACY_PREFIX = "EVENCFW"; diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index de68485e..fdbd123f 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,12 +19,12 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "986930903c6ea41ad7fd7ed15c73c0a1af00cc9b58604abfe2092a79745bb641", + "outputSha256": "dc9808a442dd475f3cb2c2945a5afa1408458222842cd9fef6288e435920c9b0", "patches": [ { "offset": 1045797, "old": "38b584b0", - "new": "5cf337be", + "new": "5cf339be", "desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease" }, { @@ -36,49 +36,49 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1437923, "old": "fef788ff", - "new": "fdf246fb", + "new": "fdf248fb", "desc": "cfw_ancs_event" }, { "offset": 1437951, "old": "fef7e8fb", - "new": "fdf280f8", + "new": "fdf282f8", "desc": "cfw_ancs_open" }, { "offset": 1437969, "old": "fef7e7fb", - "new": "fdf297f8", + "new": "fdf299f8", "desc": "cfw_ancs_close" }, { "offset": 1388387, "old": "39694d00", - "new": "755e7d00", + "new": "795e7d00", "desc": "connection-bound ANCS EUS write callback" }, { "offset": 971497, "old": "fff717f8", - "new": "6ef367ff", + "new": "6ef369ff", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 971845, "old": "fef769ff", - "new": "6ef3b9fe", + "new": "6ef3bbfe", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 979579, "old": "fdf74ef8", - "new": "6cf39eff", + "new": "6cf3a0ff", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 1428895, "old": "f8f76cfd", - "new": "fcf292f8", + "new": "fcf294f8", "desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)" }, { @@ -108,145 +108,145 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1248487, "old": "d4f712fb", - "new": "2af3bef8", + "new": "2af3c0f8", "desc": "bl settings_send_wrapper (append caps field 100)" }, { "offset": 1246183, "old": "f5f7e2f8", - "new": "2af360fa", + "new": "2af362fa", "desc": "bl settings_decode_wrapper (Faceclaw lease field 101)" }, { "offset": 975219, "old": "02f083fc", - "new": "6cf3c2fa", + "new": "6cf3c4fa", "desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)" }, { "offset": 975411, "old": "02f023fc", - "new": "6cf330fb", + "new": "6cf332fb", "desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)" }, { "offset": 975103, "old": "07f085fb", - "new": "6df370ff", + "new": "6df372ff", "desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)" }, { "offset": 830549, "old": "19f03efb", - "new": "91f31ff9", + "new": "91f321f9", "desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)" }, { "offset": 830795, "old": "1ff071ff", - "new": "91f3d8f8", + "new": "91f3daf8", "desc": "bl gesture_press (owned event 9 before stock menu gate)" }, { "offset": 830887, "old": "1ff043ff", - "new": "91f3d2f8", + "new": "91f3d4f8", "desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)" }, { "offset": 831763, "old": "1ff08dfd", - "new": "90f308ff", + "new": "90f30aff", "desc": "bl gesture_release (owned event 10 before stock menu gate)" }, { "offset": 1570209, "old": "7fb50600", - "new": "dbf24fbc", + "new": "dbf251bc", "desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline" }, { "offset": 1051545, "old": "f6f787f9", - "new": "55f3fbfb", + "new": "55f3fdfb", "desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)" }, { "offset": 1051861, "old": "f6f7e9f8", - "new": "55f35dfb", + "new": "55f35ffb", "desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)" }, { "offset": 1262237, "old": "d9f7d0fd", - "new": "26f333f9", + "new": "26f335f9", "desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)" }, { "offset": 1262337, "old": "d9f79efd", - "new": "26f301f9", + "new": "26f303f9", "desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)" }, { "offset": 1309405, "old": "67f02dff", - "new": "1af319fa", + "new": "1af31bfa", "desc": "bl compass_decode_capture (sample-matched GAF diagnostics)" }, { "offset": 1307865, "old": "fff7c9fb", - "new": "1af397fd", + "new": "1af399fd", "desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)" }, { "offset": 1300937, "old": "00210170", - "new": "1cf37dfa", + "new": "1cf37ffa", "desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)" }, { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff690454ef66c6b4ff29c591446cff6ff75ccf2ff0bc2f229094ff6ff78002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7007f0b4f8002800f0eb8129464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001f51457ff445afbff35f8f00bf49e8000121b159e8001f5145f8d039e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7006f0e6ff002800f01d8129464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb9427ff445afbff35f8f00bf49e8000121b159e8001fb942f8d039e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f08f810f98002861d00e980778a7f1170002285bd80f980c2840f078810e9e7078b178084300f07281f0780138022800f26d81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f07f83172f40f09583002a40f05481fe2800f0cb87812800f0bd87002840f0d28751ea030040f0478101f062b904460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0e78051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0d680824692e74ff0ff3729e147f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0b3804ff45c7006f09afe002800f0ab8029464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f00bf49e8000159b159e8001fa142f8d039e706f5a9718847bae601211ee700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0e1f94ff0ff3701269df84900002810a818bf4ff0ff3704f0fffa054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f0a0f90e98007800f07f040f2c2ddd142c40f3a981152c00f01183162c00f01c831d2c40f0da830f9801380228c0f04f850e994878897840ea0124b4f5007f00f2468504eb4400032101eb40000f99884240f03d8505f02ffe002800f038850c96002601270f9400f055bd092c00f3d180052c00f00c82072c40f0af83002706e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f085864ff45c7006f033fd002800f07d86294600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed10121c0f800b08172a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff443afbff35f8f49e80001002900f0db8559e8001fa142f6d036e70a2c00f043810b2c40f0de82d9f800500320cff680702840b0f1005fbff35f8f41f0f0822868002758457ff4a3aec5f8687185f8667185f86471d5f86c01c5f8607185f86571c5f86c71c5f80073a5f86c7320b148f2a351c0f245018847d5f87802002818bf09f0bff80024c5f87842d5f868030c9620b148f2a351c0f245018847c5f86843a5f86c43286c42f68d46c0f24406a5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f41f0a9810168594541f0a58190f8a811002901f09a8106f044ff01f09cb9102c00f07081112c40f034820f994ff0ff37022908bf11287ff402ae0e98407800287ff4fdad45f64d50c0f24600804701284ff000077ff4f3ad40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff7ccf94ff22507c0f247070120092132460c23b84707462646afe500294ff0ff3708bf002b7ff4d6ad1328bff4d3ad102a4ff0000138bf01211228b2fa82f218bf510901297ff4c6ad00f0dfbd182f4ff0ff3708bf00297ff4bdad002b7ff4baad352800f33283002800f0b785012800f0c385312840f0b585082abff4abad00f0c4bd0f980c960228c0f000820e984078fde10f980228c0f014830c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0e8824ff45c7006f01cfb002800f0a78729464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0408259e8001fa142f6d038e70e980f990130013907f057fe07469ce4dde90e0106f0ddfe074696e40f9801380228c0f036820e994ff0ff374878897840ea0120b0f5007f3ff687ac03210f9a01eb400191427ff480ac002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff4fcab0e9935aa03314ff0010c4b78012b00f297810f7847ea0323db08d45c07f007070cfa07f7274240f08b81d45c013847ea040701f10201d754e7d105f075fa002800f07e810c960027012645e300f07e001a2818bf1c2c40f0738105f065fa002800f06e8101f03ef9814608f071fab9f1000f4ff0ff3718bf00283ff4bdab1b2c00f096851a2c40f0c08504460e984ff48052471c0f98b346461e4ff4a0704ff4f07135924ff0000835aa4ff42075cde90382cde901104846394632462346cdf8d880cdf8ec80009508f0dafd002840f0e3854ff48050cde9350835a80490012003904ff4a07002904ff4f070019048463946324623464ff42077cdf8ec80009708f0befd074600f0c9bdff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7006f022f9002800f0b58229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e8000121b159e8001fa142f8d03ae790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f2d9864bf63941c0f25101963188470027fff788ba0f9a052a39d3012d37d10e9a00279078411e06293ff67caad17803293ff678aa1279002a3ff474aa4bf63943c0f2510303f59a7398470027fff76aba0e990c9e4c78002c00f0eb80022c05d840f07e860f99062980f0bd844ff0ff37fff758ba362800f09d82462800f09782572840f08382002e7ff479aa92e2022d40f02a814bf63940c0f2510080470027fff740ba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0a1834ff45c7005f0f0ff002800f07b8429464218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800b08772a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0f98259e8001fa142f6d038e7002780f8437145f64d50c0f24600804701287ff46ea943f2a310c0f2560080470746fff766b90c294ff0ff377ff48ea9b3f5005fc0f0a581fff788b9481e1f284ff0ff373ff682a9c1f51630834240f29881fff77bb9002b7ff476a9421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f07d81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f070819f284ff0ff377ff450a9042900f06881fff74bb90f9a072ac0f0b082032d40f0ad820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0ca8244ea0521012988bf0e4642f68d41c0f24401a1f140023146bbe200200f99022902d30e99497800e0ff21002800f0228502294ff0000736d0012930d000297ff4d1a84cf67e21caf2101187760783c9f8041007814760a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8080f83c70fff7a3b801218172fff79fb88772fff79cb8dde90b5600210020fce548f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ee824ff45c7005f047fe002800f0d28229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0468259e8001fa142f6d038e7022abef4faaf13e0002a7ef4f6afa0f1fd0102290cd397287ef4efaf08e06ff0780002427ef4e9af02e0402abef4e5af45f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fef7d1bf48f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7005f054fd00283ef4aeaf29464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08472a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb1427ff445afbff35f8f49e8000121b159e8001fb142f8d03ae74af21f35c0f247050446a84794f864010e9a00287ef4feae94f80403214600287ef4f8ae107817281bd0d1f8640342f68d46c0f2440668b947f2bf00c0f20000a6f594777844012100220023b847c4f8640340b3a6f140024ff47a719047214608bb01f206300e460e990c22fef7b7fa0d98002186f805030120bff35f8f86f804034ff4f07001904ff4207005f5106600900020002200230027b04700283ef4bbae84f8047305f14c0080474ff0ff37fef7b2bed0f86c110a90002900f0198100204ff4006205e01b681a44b2f5403f80f0ca808b189f680137f5d05f68033727f0030738441030eee70f9a0027032afef465ae2a1fb2fa82f25209b046114000f0f4800f994cf6cd420339ccf6cc42a1fb02120e9900f146038c780331b4eb920f88bf94082546302c28bf302505eb850206461846fef752fa0027002c86f8445086f8457000f0d180306c344630b9204600f0cafc0028206400f09b8342f68d41c0f24401a1f140020121904700274646fef724be02460f9803287ef41fae0e9934464878897840ea01264ff6ff70864200f05f824ff480503590002035a936903b90cde902014ff4a07001904ff4f077484631464ff4207300970af0b1f9002800f047824ff0ff372646fef7f7bd04460f9801287ef4f2adb34607f0e3fde8b30646b9f86c03002800f048834ff48051a0f101084ff4a0703591002535a94ff4f0770391cde901054846414632464ff4207336953b9500970af082f9f0b9304621464ff41632fef7d9f94ff48050cde9350535a80390012002904ff4a07001904846414632464ff420734ff4f0773b9500970af065f9002800f016834ff0ff375e46fef7abbd0f9a002a46d1b0f53e3f40f2eb810c9e4ff0ff37fef79fbd0e9fb978fa783b797f7941ea022143ea072232293591369280f0a9813221abe1d0f86c110027002900f0e6824ff400624ff0ff3c0df1d40e05e02b681a44b2f5403f80f041818d18ac68b7eb542ff4d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e6e74646fef766bd0f98002800f0a98100200e9a4ff0000b02f1030e16324ff0ff3c0e92cdf82ce00beb4b020eeb420465784ff0ff37012d00f2a982a678e37856ea032900f0a3822379647953ea042800f09d82b9f5207f00f29982b8f5f07f00f2958209f101035b0803fb08f44ff6fb739c4200f28b821ef81220bbf1000f42ea05270e9d62462cd015f8133c15f8126c43ea0623bb423ff478af12b315f80d3c15f80c6c43ea0623bb423ff46eaf012a17d015f8073c15f8066c43ea0623bb423ff463af022a0cd015f8013c2e7843ea0623bb423ff459af043a531c05f11805d2d100293ed0631d4ff4006201eb020edef80850bd423fd0def8006032444ff6ff76c0f20206b2422cd801eb020edef80850bd4230d0def8006032444ff6ff76c0f20206b2421dd801eb020edef80850bd4221d0def8006032444ff6ff76c0f20206b2420ed801eb020edef80850bd4212d0def8006032444ff6ff76c0f20206b242c3d94ff6fc7304f10802c0f201031a401044103020e0def804209a427ff404afdef80c209a427ff4ffae9ef81020042a7ff4faae9ef811209ef8123042ea03224a457ff4f1ae9ef813209ef8143042ea032242457ff4e8ae0f9a0bf1010bddf82ce093450cf1010c7ff42cafb0f53e3f3ff6daae002500200e90e3e090f8a911002918bf05f0a6fd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08e804af27366c0f246060021002200230027b0470c9efef73bbc4ff0000c4ff400634ff0000ec0f800c30de0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe466ad2cf18ba68ce58013201d07746f3e7f418220c022ae6d80a1995680135e2d115682e443e6012681444220c022adad80a1995680135d6d115682e443e6012681444220c022aced80a1995680135cad115682e443e6012681444220c022ac2d80a1995680135bed115682e443e6012681444b4f5403fcfd3b5e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f24600804701281ed143f2a316c0f25606a6f188008047022c074608bf002f01d057b90fe04bf2110235a9c0f24b020220904738b10746b047002085f843010c9efef7b9bb0c9e0027fef7b5bb701ca9f86c0300272646fef7aebb0a99d1f86c114268836890454ff00002c0f80c8008bf00f1100241f823200e9a0f98013282424ff000070e9200f0f3800e980b9b00eb400003eb400213f81000937892f801b00893d37807931379527940ea0b2909930692a1b3bbf1010f31d84ff400628b189f684f45d8d01b681a444ff6ff73c0f202039a4223d88b189f684f45ccd01b681a444ff6ff73c0f202039a4217d88b189f684f45c0d01b681a444ff6ff73c0f202039a420bd88b189f684f45b4d01b681a444ff6ff73c0f202039a42cfd9dde90773099e43ea0721069c013146ea04224908514301f105088df8d6004fea18208df8d9004fea18408df8da000520059101218df8de0004208df8d4108df8e00035a811218df8d5508df8d7b08df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e3608df8e44006f0c9fc00287ff46aad0a98d0f86c110020a9b3bbf1010f32d84ff40062881883684b452cd0006802444ff6ff70c0f20200824223d8881883684b4520d0006802444ff6ff70c0f20200824217d8881883684b4514d0006802444ff6ff70c0f2020082420bd8881883684b4508d0006802444ff6ff70c0f202008242cfd90020059a002a3ff424af0799089b0902069a41f001011944099b120249081a434a43511e032901d200210ae022f003030021471804318b427d75bd75fd753d76f7d112f003023ff401af00f11503012a5d543ff4fbae1944022a4d7018bf8d70f4e60c9efef7a0ba304621464ff41632fdf7aafe11a807f0d3fb0027e6e44bf639400027c0f2510084f8447080474646fef78aba2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09e804ff45c7005f027f8002800f09680414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000129b155e8001fa142f8d04fe7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db03f0b3ff68b940460af0c9f948b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f098ff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f04982172f40f05482fe2804f22737884600f06d82002840f0788200980af043f9414602e0022084f8200350460c22fdf7e6fb94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7b6fb47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf785fbb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f80080bff35f8f08ea0700b0f1005f47d1d8f80000b04243d198f8500338b1002088f86401c8f860014db0bde8f08f98f8640118b3d8f8604104b340f6b800c2f20000d0f8009006a802f00df9b9f1000f00f07581484621464ff41632b346ba464ff6ff75cdf81490fdf72ffb4ff29c5600274ff00109c2f2290620e098f8660170b1d8f8680140b147f64c61c2f207010968401a002802f3dc80002088f8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0a01b1f1005f03d10168594500f09f804ff45c7004f0b1fc002802f09c804ff69041cff6ff714218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa1427ff455afbff35f8f46e8000121b156e8001fa142f8d04ae7817a002942f00080027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e0002088f86401c8f8600188f86601012088f8650140f6a120c0f24700804701f074bf40460d460af069f8d8b102304ff0030008bf022084f820032946bce584f85003d9f800204ef660231a44c4f8602380b140460d460af02ffa0af003fa294630b9a9e50af0fef9002829463ff4a4ad03209fe5002084f866019de51868624600eb0620704400eb0b4000eb056138466546fdf77bf90fe04eea062141ea0b4141ea056339466246654609f0fdff00281cbf032084f8200305f1080084f84f03414679e501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0e48300218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f09a8000218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f346bef15f0f98bf4ff05f0bcbf1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f905eb0e0209f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd009fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0de460ae00ef1010e07e00ef1020e04e00ef1030e00e0de460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000a15f80a10002900f0c78005eb0a035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d00af1200abaf1600f7ff496af4ff0600a5ee00af1010a5be00af1020a58e00af1030a55e00af1040a52e00af1050a4fe00af1060a4ce00af1070a49e00af1080a46e00af1090a43e00af10a0a40e00af10b0a3de00af10c0a3ae00af10d0a37e00af10e0a34e000220a7162e70af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46d646baf15f0f98bf4ff05f0ecef1000942f2107c0aad19eb0a0b51d0b2fbf3f40a2b04f1300105f80a104cf6cd41ccf6cc41a3fb011747d31bf1010140d004fb1326ff08b6fbf7f405eb0a0204f13001517048f21f51c5f2eb11642ba3fb015135d31bf102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31bf1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb11420af1040a63454fea57330aadabd20ce0f2460ae0f24607e00af1010a05e00af1020a01e00af1030a0aad059f002205f80a20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a4609f051fad4f870c272208df8280078208df8290020204ff0000b1ffa8cf28df82a008df82bb015f80b00002800f0c88005eb0b035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00bf1200bbbf1600f7ff496af4ff0600b5fe004460020887078e70bf1010b58e00bf1020b55e00bf1030b52e00bf1040b4fe00bf1050b4ce00bf1060b49e00bf1070b46e00bf1080b43e00bf1090b40e00bf10a0b3de00bf10b0b3ae00bf10c0b37e00bf10d0b34e00bf10e0b31e00bf10f0b2ee00bf1100b2be00bf1110b28e00bf1120b25e00bf1130b22e00bf1140b1fe00bf1150b1ce00bf1160b19e00bf1170b16e00bf1180b13e00bf1190b10e00bf11a0b0de00bf11b0b0ae00bf11c0b07e00bf11d0b04e00bf11e0b01e00bf11f0b01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d946bbf15f0f98bf4ff05f09c9f1000a42f2107e1aeb0b004fd0b2fbf3f50aa905f1300401f80b404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0b0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020bf1040b73454fea5633add209e0cb4607e00bf1010b04e00bf1020b01e00bf1030bddf8149000220aac04f80b20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06e8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df8870042f2941645f29c140aaa48460e21c2f22006c2f2130408f0fffe4ff6a42040f6b801cff6ff70c2f200010858a04266d14ff6b020cff6ff700858b0f54d2f5ed14ff6b420cff6ff700858a04257d145f610634ff0000ec2f213034cf6394506f1040c00274ff0ff32634548d8186830f003041ad09e4228bf0c2842d3f11a8c424ff0ff313fd8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e2d12ce00021417191e60421b7f5807f1ed300223d46b5f5007f14d3b5f5806f13d3b5f5006f12d30901b2eb153f4fea1515f0d10ce000219171fef765bf00211172fef71bbc490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006806f1080342f6941c9842c2f2270c4cd142f610674ff0000bc2f2200746f6b9700cf1040e00244ff0ff3a4ff0ff3977453bd83e6836f0030515d0bc4528bf0c2e35d3aceb07039d4233d82346a54288bf2b46f6071cbf1c46ab447b19013803f10407e4d121e00420b4f5807f16d300262546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b6eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea000ad94603e04ff0ff3a4ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834264d14ff69423cff6ff73fb58b3f5333f5cd14ff69823cff6ff73fb58834255d14ff29c5043f21063c2f229004ff0000bc2f2270342f6f935a0f1040ca0f1080e0024634542d81e6836f003071ad09e454ff0ff30049028bf0c2e3ad3aeeb030087424ff0ff3034d82046a74288bf3846f6071cbf0446bb44d819013d00f10403dfd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff00634505d17b4204ea03000490584602e04ff0ff300490064666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b7008f0f7fe059de05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f88000208df8870020464946524608f022fe0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac049a2046314608f055fd28461a21224608f0d2fb002088f86401c8f8600105984ef217310a904ff416300b900aa8c0f247018847012088f8660106a800f036f9c8f810004db0bde8f08f0020c871d6e70021417207e700bf2de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff6904a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f09c804ff45c7002f0a6fb002800f0d28051464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff45bafbff35f8f00bf47e8000121b157e8001f4945f8d04fe74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c56d1f8009000684ff6904bccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108009007e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168b94200f09c804ff45c7002f08cfa002800f0f08059464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f51457ff457afbff35f8f00bf46e8000121b156e8001f5145f8d04be74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ce047f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422fd041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94217d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a9eb0501b1fbf0f001b0bde8f08f002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204607f0b5fa854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f01f81207887f00301084200f01b81012039464246334600f054fa0446002898f8080018bf06240ee14ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f0f1804ef66c6a4ff29c574ff690480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168514500f09d804ff45c7002f0eff8002800f0be80414600bf4218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff455afbff35f8f47e8000121b157e8001f4945f8d04ae705eb450100eb011090f85d1201b300f513760024304629462a460323009407f059fa706840b14bf69b71c0f25d018847706804f0a7fc74603068b475002818bf04f0a0fc0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f058f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104607f046f9201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009507f0ecf9606840b14bf69b71c0f25d018847606804f03afc65602068a575002818bf04f033fc00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff690498046ccf2ff05c2f229064ff6ff77cff6ff7900244ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09d804ff45c7001f08cff002800f0958049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff457afbff35f8f00bf46e8000129b156e8001f5945f8d04be7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46faf715fda81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450bcde90612cde9080303e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c7001f090fe002800f0398449464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70999089d01eb410100eb011095f9081000f51376b1f1ff3f01f0030409dd374617f8110fd0bb3068002818bf04f04cfa2fe3307cf0b1707ce0b10799099a002730460323009706f0e7ff706840b14bf69b71c0f25d018847706804f035fa77603068b775002818bf04f02efa00203060b06030823068002818bf04f025fa00204ff480713060b0603182a978b081092006f11107f174b17434757076b07ca978884240f0db82317da14240f0d782069b411ca3f10b00727e02971e2828bf1e209042b17488bf7076981e84b200270a2c4ff00008c0f0e782092241f221090920039419e030684f46002818bf04f0ecf9b089376001303774b760b081002c18bf4ff00608039cd146ddf814a00aeb0b0082b2a24280f0c782317c80b20429824600f28880aa5c00f1010a4b1c0129337405dd022906d0032970d1f28106e021b9727503e0338943ea02223281a24580f0aa8204296ed015f80a204ff0000c831c8f1c0129377406ddff290bd0032967460dd19a4652e000291cbf378947ea0222328100e072756746a34204d38be2f281a34280f08882022936d8ea5c00f1030acb1c0129337407dd022937d0fe2907d17275a2450cd376e231b9338943ea02223281a24504d36ee2f281a24580f06b8202292fd015f80a20031d41f00407fc29377408ddfd2909d0fe291cbf378947ea0222328103e079b9f28100e072756746a34280f0508209b19a4613e0ea5c00f1050a0520307401e09a466746f189308941ea0221f18128b106f01cfe0028306000f06a8233897089191a1ffa81fb1ffa8af1621a5a45b8bf93465fea0b4208d03268294410441ffa8bf2faf70bfb70893389584481b2994270817ff44faf0025cdf81080d6f800808df82b50707db8f1000f06930df12b0108bf88460f2806d8317d00f00302511ab1fa81f14d09000706d4317e707e814238bf30760fe000bf706840b14bf69b71c0f25d018847706804f002f97760707e30760120f082cdf814a09db1707db57d400714d4002d4ff0000400f0898106984ff6ff7381b2002900f00d8101295ed10020d2e0707d400753d4002478e14ff4803006f0abfd002d804600f07081b07d002800f06c81b8f1000f00f068817568002d00f0008130890428c0f0608131680a1812f8043c002b40f0598112f8033c002b40f0548112f8023cff2b40f04f8112f8012cff2a40f04a814ff4803429606860c5f80c802c610028019000f067814bf69b70c0f25d0000f58572284600219047002840f033812969002900f02f8168688c420c46e7d1019a0c468242e3d125e14ff4803006f059fd044620e1069a4ff6fe701040a44642426ff0010000bf08eb0005ac78ed7883ea04231cb25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead73787ea430383ea05231fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead737023087ea430309ead5371518023587ea430395d1023000276446069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003f0899ab2824270d1099b4046faf77ffa00286ad141f2210a4ff00009012375e0382006f098fc00285ed00546077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377046f6d730c0f200007844286246f6df30c0f20000784468624bf69b70c0f25d0045f6e46200f13c0c28460f21c0f27c023823e04740b3284603f069ff4446706841f2210a40b14bf69b71c0f25d018847706803f05cff77604ff000090323b77506980799099a089dddf8108087b23046009706f0f4fc002c214604463ff455ad084603f044ff50e5756073e6c4f58030b4f5803f444606902f60ef607ff646aecde70799099a002430460323009406f0d6fc706840b14bf69b71c0f25d018847706803f024ff74603068b475002818bf03f01dff0020387000203060b06030824ff00a0840460bb0bde8f08f287a4006f8d5307c08b302980078e0b10799099a002430460323009406f0a9fc706840b14bf69b71c0f25d018847706803f0f7fe74603068b475002818bf03f0f0fe00203060b06030824ff00b083068002818bf03f0e5fe00203060b0603082cae702980078e0b10799099a002430460323009406f07dfc706840b14bf69b71c0f25d018847706803f0cbfe74603068b475002818bf03f0c4fe00203060b06030824ff00608a7e700bf2de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7f3f9002869d006462846fff749fa21462a46fff71dfa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff7d0ba0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22f9f741fe04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522f9f7fdfd0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522f9f7a7fd4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff764ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff690480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f09c804ff45c7000f03efe002800f0c18041464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff456afbff35f8f46e8000121b156e8001f5945f8d04be7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff7f0fd2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff61d40cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023a6e745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04468002c00f0bd828368002b00f0b98204eb030b4ff000090027002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310ceb0a0300275b451c464ff0000680f09d82a04618f9013b03f07f05bd40002b46ea050610d406f00703012b16dc0bb3012b40f08b82abeb0803082bc0f0868204f10903dee700bfd84580f07f82182f07f107074446dcd978e200bf022b3ad0052b40f07382abeb0803042bc0f06e82631dc7e7d84580f0698294f90130002b04f10203bed55b4580f0608294f90230b3f1ff3f04f10303b4dc5b4580f0568294f90330b3f1ff3f04f10403aadc5b4580f04c8294f90430b3f1ff3f04f10503a0dc5b4580f0428294f90530002b00f13d82a31d96e7d84580f0388294f9013004f1020c002b03f07f0a1ed5dc4580f02d8294f90270e31c07f07f05b7f1ff3f4aeac51a02dde0469c460ee05b4580f01d8294f9037004f1040c07f07f05b7f1ff3f4aea853a33dd9846abeb0c039a4500f20c82f308672b1dd0652b7ff460afbaf1060ffff45caf9cf80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf4ff29c54c2f229040290cde9002132e0044660460e4651461746654600f017fcac4631463a46204637e7dc4580f0db8194f90470631d07f07f05b7f1ff3f4aea455aaddc5b4580f0ce8194f90570002f00f1c98104f1060c4aea077ab1e748f2a3513046c0f24501bff32f8f8847dde900210298ac462768bff35f8f2668bff35f8f33466ff39603b3f1005f07d133684ef66c65ccf2ff05ab4200f0b0804ff45c70654600f079fbdde9002106460298ac46002e3ff4f1ae4ff69043cff6ff7300bff418373384f8709384f8719384f8729384f8739384f8749384f8759384f8769384f8779384f8789384f8799384f87a9384f87b9384f87c9384f87d9384f87e9384f87f9384f8809384f8819384f8829384f8839384f8849384f8859384f8869384f8879384f8889384f8899384f88a9384f88b9384f88c9384f88d9384f88e9384f88f9384f8909384f8919384f8929384f8939384f8949384f8959384f8969384f8979384f8989384f8999384f89a9384f89b9384f89c9384f89d9384f89e9384f89f9384f8a09384f8a19384f8a29384f8a39384f8a49384f8a59384f8a6938ed14ef66c63ccf2ff0333600123b3724ff6ff734ff29c54b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290454e8003fbb427ff43bafbff35f8f00bf44e8006323b154e8003fbb42f8d02fe798f8043098f8057098f80650032b47ea052437dd052b58dc042b78d0052b7ff43daed6f868313bb147f64c67c2f207073f68db1b002b18dcd6f86c3186f86691c6f86c91c6f80093a6f86c936bb10c4648f2a35180461846c0f24501174665468847ac4621463a46404647f64c63c2f207031b6845f69077c0f201073b44c6f868310be6012b3ff4fdad022b00f08780032b7ff403ae174688466546fff724fb03460298ac4641463a46002b3ff4f6ad96f84231002b3ff4f1ad304641f28831a6f8404106f006fa47e0062b4ad0072b7ff4e4ad80464df6db50c0f24a0016460f466446804703465d1ea446394632464046012d3ff6d2ad981eb0fa80f04009fff7dcfba446394632464046c6e5174688466546fff7e8fa03460298ac4641463a46002b3ff4baad96f84231002b3ff4b5adb6f84031a3427ff4b0add6f83c3186f84291002ba6f840913ff4a7ad42f68d411846c0f2440188470298ac4641463a469be5d6f86c31c6f86891002b86f86691c6f86c91c6f80093a6f86c933ff48dad0f4648f2a35104461846c0f24501164665468847ac463946324644e696f84231c6f83891002b3ff478ad0446d6f83c0165468846174686f84291a6f8409120b142f68d41c0f2440188474af273660120002100220023c0f24606b04720463a464146ac4659e54ff2a513c0f2490303b0bde8f04f18477fb50646002806d1fff772fa002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817047f2b401c0f20001033079440b22f8f7e8ff0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f8f7b0ff0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f8f701ff1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f8f757fe4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f0eb800c46014600784d2840f0e5804878432840f0e1808878012840f0dd804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f03d10268424500f0a0804ff45c70fff766ff002800f0ae804ff690425146cff6ff728318373283f8705383f8715383f8725383f8735383f8745383f8755383f8765383f8775383f8785383f8795383f87a5383f87b5383f87c5383f87d5383f87e5383f87f5383f8805383f8815383f8825383f8835383f8845383f8855383f8865383f8875383f8885383f8895383f88a5383f88b5383f88c5383f88d5383f88e5383f88f5383f8905383f8915383f8925383f8935383f8945383f8955383f8965383f8975383f8985383f8995383f89a5383f89b5383f89c5383f89d5383f89e5383f89f5383f8a05383f8a15383f8a25383f8a35383f8a45383f8a55383f8a6538ed1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a457ff451afbff35f8f47e8000222b157e8002f4a45f8d046e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff6b922cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff61140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff35f2e0cde901100120cff680704ef66c644ff29c564ff6904bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f03d10168a14200f09b804ff45c70fff74dfb0028c5d059464218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff459afbff35f8f00bf46e8000121b156e8001f5145f8d04de7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff41faf00210025fff778fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff7f4fd0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff72afe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff6bd12cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff750fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef788fa014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef768fa0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef757fa204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd45f67e70c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7a5f90028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f7f705ff4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7a3bd00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1f9f7cdfec8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f9bb00278437842ea0325b5f5007f04d94ff0ff301bb0bde8f08f4ef66c6a4ff29c56ccf2ff0ac2f229064ff6ff774ff000084ff0010b0791099008e000bf48f2a3512046c0f24501bff32f8f8847d6f80090bff35f8f3468bff35f8f20466ff39600b0f1005f03d12068504500f0a2804ff45c70fef7d3fb002800f09a8004464ff69040cff6ff7000bf2118373081f8708381f8718381f8728381f8738381f8748381f8758381f8768381f8778381f8788381f8798381f87a8381f87b8381f87c8381f87d8381f87e8381f87f8381f8808381f8818381f8828381f8838381f8848381f8858381f8868381f8878381f8888381f8898381f88a8381f88b8381f88c8381f88d8381f88e8381f88f8381f8908381f8918381f8928381f8938381f8948381f8958381f8968381f8978381f8988381f8998381f89a8381f89b8381f89c8381f89d8381f89e8381f89f8381f8a08381f8a18381f8a28381f8a38381f8a48381f8a58381f8a6838ed1c4f800a084f80ab0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f48457ff450afbff35f8f46e8004028b156e8000f4845f8d045e70024ddf824805db1fdf7fafb0146002c4ff0ff3018bf002902d11bb0bde8f08fb5fa85f040094ff000098df82c908df82d908df82e908df82f908df830908df831908df832908df833908df834908df835908df836908df837908df838908df839908df83a908df83b908df83c908df83d908df83e908df83f908df840908df841908df842908df843908df844908df845908df846908df847908df848908df849908df84a908df84b908df84c908df84d908df84e908df84f908df850908df851908df852908df853908df854908df855908df856908df857908df858908df859908df85a908df85b908df85c908df85d908df85e908df85f908df860908df861908df862908df863908df864908df865908df866908df867908df868908df869908df86a908df86b90bcb1d4f86c21a2b14ff4006304e03f683b44b3f5403f0cd2d718be680136f6d07e68033626f0030609eb060101f11009ede7002d4ff0020a039500f00581ddf81cc0acf102020a2ac0f00081002608eb0a0b9bf801504ff0ff30012d3ff648af9bf802209bf803309bf8047042ea03229bf8053042ea074747ea0361a1f1011212f5803f0a91fff433af9bf808109bf809e0029141ea0e210af10a020497aceb02034f1e9f42bff423afcde905269bf806209bf807300a9e42ea032cb6eb0c07fff416afb9423ff613af18f80a70089147ea052a4feada000ba90e5c07f00705012707fa05f5354240f003830e5c45ea06050d5407994ff6ff75c0f20205b4b3d4f86c0198b317461a0201924fea0e264ff4006200eb0208d8f8083053454bd0d8f800301a44aa4221d800eb0208d8f80830534540d0d8f800301a44aa4216d800eb0208d8f80830534535d0d8f800301a44aa420bd800eb0208d8f8083053452ad0d8f800301a44aa42d3d900bfbcf1000f40f0be8204980a464ff6fc710330c0f2030108404844944600f1100908980599069e00eb010a0398013686424ff0000028bf0120ddf824804fd2aceb0a02092a3ff64caf49e0d8f804000a9a904240f09782d8f80c006045c0f0928236d9089aa0eb0c00824200f28b827ab3029831180198c1f1000cc2199044a1f1010e002208eb02050beb0203287c9e7ab04240f0778296451cd06e7cdf7abe4240f070820ceb0207be1c13d0ae7c187b864240f06782079ef81c07d0e87c5b7b984240f05f8204329142dbd1b446a7e78c46a5e7ddf81cc0a2e7ddf81cc0002800f05082baeb0c004ff0000118bf0120b9f53e3f88bf0121014303980028c1f100003ff43eae00297ff43baed4f86cb1bbf1000f40f08b804ff44030fef75af9002800f02f82834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760222c0f2020600210ae00aeb080209f10101ddf8248071454ff000003ff498ad08eb02050a9218f80200aa786f7805922a7a95f803e095f8049095f805c095f806a0eb7908926a7a40ea0728cde906215cb3012f29d84ff400670beb0705a868404500f0a28028680744b7421dd80beb0705a868404500f0988028680744b74213d80beb0705a868404500f08e8028680744b74209d80beb0705a868404500f0848028680744b742d7d90598cdf810a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a002002930597b9f1000f26d00beb09035bf809105a68514580f09c80eab10beb02005bf80210d0f80490514580f08d80b9f1000f11d00beb09035bf809105a68514580f0878042b10beb02005bf80210d0f804905145d6d377e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f6f7affe4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f8002311d90beb09004bf809104ff0ff3142608160c260c4f800930be0e868ddf80ce00a9a089f60e010b10268114401604ff000090020b9f1000f7bd00beb09035bf809105a68514522d2002a72d00beb02005bf80210d0f80490514513d2b9f1000f67d00beb09035bf809105a6851450ed2002a5ed00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf80ce00a9addf810a0029b089f00280cbfc4f800c3c0f804c005984ff6ff7668600020c0f20206c5f80880e8604aea0321069bddf81c9047ea032a814202f10a087ff4bdae05f110077818099952464144f346f6f7c2fde968de466868aa68d4f86cb15144e96081424ff0000018bf07464bf82270a3e600204ff400684ff4006703e02f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f6f7e1fd4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f800831bb0bde8f08f00281ebf0168114401604ff0ff301bb0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7f1fe002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f86813002974d104464ff41630fdf74ffe014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8681300e00021084601b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7a9fd002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f87812002974d104464ff4163002f041fe014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8781200e00021084601b0bde8f08f00bf2de9f04f83b04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b029002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c70fdf760fc002800f0c68049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70446fff7ebfd002c18bf002805d102990120487103b0bde8f08fc4f8600101254ff4f07084f8645101904ff420704af61f470090c0f2470700200021002200230026b84740b184f864610298c4f86061457103b0bde8f08f0298057103b0bde8f08f0024cde700bf014640f258304df69f22c2f20000c0f248021047022a3cbf4ff0ff3070472de9f04fadf2cc4d189008784f781e9240ea0727b7fa87f04fea501822f0010002284ff002001f9001f05a83002f16910f93129701f054831f90002015901f9a169b9818995c4078023241ea00241e981f92801a844201f24183022cc1f03e83ddf800753868411e0028396001f036839e187078012801f2318396f800800028a4f1020769d01898022f0df1d009c1f02583d0f86c01002801f02083f178012901f21c8396f802a04aea012750f82710002901f013830a1a910741f00f836ff4403140f60f031144cff6fd739942c1f00583104450f8081cb94241f0ff8250f80c1c0025a1f10113cff6ff75ab42c1f0f58250f8043c8b4241f0f082c2f54032914201f2eb82002801f0e882027812f00b0f41f0e38200224b4601f07cfb002801f0dc82349804362290dde936b0251f2190ddf800050bf1010180694908269140b1fa080af00701835c012707fa01f119438154b2462f460de0ddf8f804ddf8f0b42690ddf8f40406f1020a21900f980df1d0092290b8f1030f119459d0b8f1020f33d0b8f1010f1d9740f0e280002f01f0a4829af80060012e01f29f82002e4ff0050c18bf4ff0090c6745c1f096829af801109af80300002ecdf86ca000f0ca819af802209af8043055469af805709af8064041ea022140ea032ae8792a7a259147ea042e40ea0222bfe10e2f41f075829af800409af801004ff6fe7144ea00278f422699219e229b5d46249100f08a834ff6ff718f4240f02c8318984ff42075d0f868334ff4a0704ff4f076249079e3062fc1f052829af805000630874241f04c82062f2cad17d0062402e00134bc4212d21af8040001381e28f7d90aeb0400391b4a462b4601f049fa002801f0358234980444bc42ecd3ddf8fc04002801f004822298002801f02882fcf707fb002801f023829af80550a81d874241f01d8247f65420c2f207000768002f01f01582387b797bba7bfb7b40ea012040ea024040ea0362a2f1810010f1800f4ff00008c1f00582387c797cfb7c40ea0120b97c40ea014040ea03600690813810f5817f41f2f5815446002d24920d9700f0db85a61d4ff0000c00270df1d00a0df1b0081b9409e000f100404af824000137af4204f1010c80f07b85f05d6446411e1e29f0d9f019e91b424628ab01f0dff9002800f069852c9928980f444af82400e6e708f0fe00042840f086801898b8f1040f02d1072f41f0b981b8f1050f09d1082fc1f0b3819af8070008308742189841f0ac81d0f86c71c446002f4ff0000801f0a6819af80100012801f2a1819af8005045ea002057f82020002a01f09881d31b9a0741f094816ff440329e1840f60f02cff6fd729642c1f08a81fc1854f8082c824241f0848154f80c1c0027a1f10112cff6ff77ba42c1f07a81002c01f0778154f8047c8f4241f07281c3f54033994201f26d81ddf8002592693ab1c00805f00706135c0127b7403b431354bcf1040f40f0c984204600222cab01f0f3f9ddf8fc1400284ff0000408bf4ff0ff34002918bf002801f02081002034901d98269901902298219b5a46cdf80890cdf800a001f04cfad7e2b8f1060f40f0b582219a102f41f032819af804009af805104ff0000850ea01231ebf9af806009af8071050ea012701f023819af800609af8015046ea0524a345c1f01a81abeb0400834201f215819af802009af8031040ea01294a45c1f00c81a2eb0900874201f20781ddf8fc04002801f0d88007eb090051462590a80203eb040a01f1080b40ea860826982299464609fb0015a64620464ff0040c00bf4208ac5c2cea060124fa01f1c1f342031bf803302cea810123fa01f101f00f0304f00f0704f0f0042344c40700f1010008bf47ea0113504506f10406ab54dfd3259809f1010981457446cfd301f09bb89af802209af8047089004fea420a4fea800e7a002591ddf88490bef1000f4ff0000818bf002a01f0b08025988345c1f0ac80abeb0000864501f2a780d145c1f0a480a9eb0a00824201f29f801d9f6546bc4502fb0ef41096199280f035821098ddf8fc24002818bf0120d846002a18bf0122104000211390149400bf1b98475d3b0901d0012015e01d98461b012e01f07a801b98421953780bb102200ae0042ec1f071809678d27856ea022301f06b80042000bf621a934201f265801c901398002800f085805e1e07f00f00032e4fea0712179524901a93239280f085804ff0000c1a9b179d13f0030b71d00ceb0107b7fbfef0259b00fb1e76f41800eb0a0656ea040016d4444514d24e4512d22698229d249a06fb00506608855de40705f00f0c05f0f0051544239a08bf4cea02058555179d1a9bbbf1010f49d0781cb0fbfef6259b06fb1e005644c41856ea040016d4444514d24e4512d22698229d249a06fb00506608855de40705f00f0c05f0f0051544239a08bf4cea02058555179d1a9bbbf1020f23d0b81cb0fbfef6259b06fb1e005644c7181a9b56ea070017d4474515d24e4513d22698229d144606fb00507e08855d249a05f00f0c05f0f0051544ff0708bf4cea04058555179d00bf1c981d9f0544bd42194480f09487149ca142fff44baf70e123f003004ff0000c209005e020980cf1040c60453ff471af01eb0c0bbbfbfef60b4606fb1eb4259956440c4456ea0409ddf8849015d4444513d24e4511d22698229d249a06fb00566508705de40700f00f0700f0f0001044239a08bf47ea020070550bf10100b0fbfef505fb1e0005eb0a06441856ea040015d4444513d24e4511d22698229d249a06fb00506508465de40706f00f0706f0f0061644239a08bf47ea020646550bf10200b0fbfef505fb1e0005eb0a06441856ea0400194614d4444512d24e4510d22698229d249b06fb00506508465de40706f00f0706f0f0061e4408bf47ea020646550bf10300b0fbfef5259b05fb1e0005eb0a06c41856ea04003ff583af4445bff480af4e45bff47daf2698229d249b06fb00506508465de40706f00f0706f0f0061e4408bf47ea020646556ae7012800f231871898d0f86c01002800f02b8750f82710002900f026870a1a910740f022876ff4403140f60f031144cff6fd739942c0f01887104450f8081cb94240f0128750f80c1c0026a1f10113cff6ff76b342c0f0088750f8043c8b4240f00387c2f54032914200f2fe86002800f0fb86027812f00b0f40f0f68600224b4600f08fff002800f0ef86ddf80005dde936568069349b691c4fea5101249140b1fa0804f00701845c012707fa01f121438154002b4ff00008239300f0d7869af806e09af807105eea01291fbfcdf894b09af808009af8097050ea072b00f0c6869af802209af8033042ea03229542c0f0bd86ab1a994500f2b98620929af804209af8053042ea0325ae424ff00002a6eb050338bf01229b454ff0000388bf01231a43ddf8fc345442002b00f07486002a40f071869af80b209af80a30120642ea034253464fea224a5a7b1b7b120642ea0342dde922364fea22489e4200f07a82002300f06cbd219fb8f1070f4ff0000840f07c861d98022840f078869af800009af80110229a40ea0121ddf800055b460390ddf8fc040097029026980190189801f05dfc044600f036be0021bd424ff0000808bfa14240f05986ddf8fc04002800f02a861098002840f02686781fddf864c021902ef001000cfb00f200f031861b991d922698229a05310afb0020229125994fea5e0e00eb5108002101234ff000090027002000251c902390cdf88080cde924e008e001250027259a219801328242259200f01186002d40f00d862298259a022f865c00f0f680012f7cd0002f40f0f580370906f00f00239000f072811d98b842dfd3c01b1d90239800eb001600011b9012e01bf80100239a00f0f00010440bf801000131013f0123714524bf002109f10109002f00f04e81e145c2d22698002b09fb008be5d0aeeb0104b4eb570f88bf7c0874b3a2080beb010a1dd09e4600230af10100a3eb82026ff0030c00bf00eb0c030cf1040c02eb0c0818f10405de701e715e719e71f2d10cf10400ddf864c0ddf88080734600e0002014f0030208d0012a0af8006004d05044022a467018bf8670a7eb4407214487b1ddf890e07145b2d21bf801001b9a00f00f001043013f00230bf80100002faed1fbe0ddf890e00027a1e7002e00f0f8801d98b042fff468af801b1d90239800eb001700011b9010e0685c239a00f0f000104368540131013e0123714524bf002109f10109002e00f0d880e145bff44caf2698002b09fb0085e6d0aeeb010cbceb560f44469b4688bf4fea560cbcf1000f28d05fea9c0005eb010816d0002208f10103a2eb800a6ff0030000bf1a1804300aeb00040434d770177157719771f5d1209cddf890e0043000e000201cf0030208d0012a08f8007004d04044022a477018bf8770a6eb4c0661447eb1ddf864c071450ed2685c1b9a00f00f0010436854013e0023a046002eafd186e0ddf864c000265b46a046a0e7002503271c96f5e61c9d55ea062500f081801d981c95a842fff4eaae401b1d90239800eb001700011b9011e01af80100239a00f0f00010430af801000131013d0123714524bf002109f10109002d58d0e145bff4cdae2698002b09fb008ae5d0aeeb0104b4eb550f46469b4688bf6c083cb3a2080aeb010816d0002308f10100a3eb82026ff0030c00eb0c030cf1040c02eb0c060436df701f715f719f71f3d1209e0cf1040000e0002014f0030208d0012a08f8007004d04044022a477018bf8770a5eb440521449db1ddf890e0ddf864c0714512d21af801001b9a00f00f0010430af80100013d0023b046002dafd107e0ddf864c0ddf890e000255b46b0469fe70027002575e60025022772e6002501276fe60020012500271c906ae6c1292caf2cd32078012829d11d980928c0f04b84a4f13f0025901d980af10805a0f1080602e0013e00f03f8415f8010b421e1f2af7d342b2202a11db259b03eb400213f81000527840ea0222c12a07d320463b46884600f002fd41460028e2d14ff0ff3400f035bcbcf1000f59d0acf101054ff00008564608e0cc46454508f10108a4f1010406f1040646d05af828100029f3d40020434684421dd006eb80077a68b2f1ff3f18dc5a1c954214d0ba68b2f1ff3f11dc9a1c95420dd0fa68b2f1ff3f0adcda1c954206d03a690433002a00f10400e0d400e000220d982cab28afe146009701f0b9fa0028b9d028980028c3d04af20d312ca8c0f24e018847bce701204ff0000c0df1d00a0df1b0080ce0a84540f3e5820123efe200200df1b00802e04ff0000c01201b9c217994f800e06278a378e7788d060f2401f00f0604eae575754389246543ed0a8df8a0500e25259111f0200f08bf012506fb05f504fb05f54fead5258df8a1504ff00d0508bf022506fb05f504fb05f54fead5258df8a2504ff00c0508bf032506fb05f504fb05f54fead5258df8a3504ff00b0508bf042506fb05f504fb05f54fead5258df8a4504ff00a0508bf052506fb05f504fb05f54fead5258df8a5504ff0090508bf062506fb05f504fb05f54fead5258df8a6504ff0080508bf072506fb05f504fb05f54fead5258df8a7504ff0070508bf082506fb05f504fb05f54fead5258df8a8504ff0060508bf092506fb05f504fb05f54fead5258df8a9504ff0050508bf0a2506fb05f504fb05f54fead5258df8aa504ff0040508bf0b2506fb05f504fb05f54fead5258df8ab504ff0030508bf0c2506fb05f504fb05f54fead5258df8ac504ff0020508bf0d2506fb05f504fb05f54fead5258df8ad504ff0010508bf0e2506fb05f504fb05f54fead5258df8ae504ff0000508bf0f256e436643f60a00284ff000048df8af6040f00a83120642ea0e4138060c14249940ea0340acf1010501eb204000260590cdf824c0079518e00df1b0084af20d314046c0f24e0188479df8b4009df8b5100c9c079ddde909c640ea01200df1d00a01366645044400f0de825af82610b1f1ff3f1edd33469d421fd00aeb83004268b2f1ff3f1adc0133ab4216d08268b2f1ff3f13dc0133ab420fd0c268b2f1ff3f0cdc0133ab4208d002690133002ae2d404e001f01f000b38d2e700220d98434627af009701f074f900283ff474ae27990029109100f0a6819df8b8009df8b9100a9650ea012c0c94a6d09df8bc709df8bd603f0447ea0667069e9df8b7009df8b6106644020241ea00259df8ba0006eb2747059e9df8bb300004a6eb07080c9e40ea0360031406eb204a01201b9500eb55070a4401f003050af101010b910af10201089110990e97571e1497f718f31a4c1c511b00eb52002491d9074ff0000e2391f907074646461c952091cdf85cc0cde9190806e000bf0ef1010ee6453c443ff45aaf1eeb0602f6d421988242f3d21b980028f0d0269822994ff0000902fb001814981d94032880f0a1801c98ddf85cc0dde919761d9c0028ddd010980e9901220efb010325984fea5901595c00f0100082ea1015c8b201f00f025feac971139108bf02091046002a18bf01202843012816d119eb0a0413d45c4511d2600818f8001028afba5c01f00f0701f0f0011143e60708bf47ea0211dde9197608f800101c981d9c0128a6d009f101004008185cc1b24fea111c1399002908bf00f00f0c5ffa8cf0002818bf01202843012819d10b9819eb000215d45a4513d2500818f8001028ac14f80c7001f00f0601f0f00139431d9cd20708bf46ea0711dde9197608f800101c98ddf85cc002283ff473af09f102004008185cc1b200f00f021398002808bf0a091046002a18bf0120284301287ff460af089819eb00033ff55baf5b45bff458af580818f8001028afba5c01f00f0701f0f0011143db0708bf47ea0211dde9197608f8001044e7a44608e000bf249809f1040948450cf1020c3ff454af25981cf8014c00f01002012080ea1213e4b200220f2c88bf01221a43012a0aeb090215d1002a13d45a4511d25708240918f8076028a8045d06f00f0106f0f00626435feaca7008bf41ea041608f807601cf8010c5f4610f00f04204618bf01201843012817d112f1010b14d4bb4512d24fea5b0018f8001028ae345d01f00f06239d46ea041601f0f001002d08bf41ea040608f800609cf80000bb46c4b200200f2c88bf01201843012815d1971c13d45f4511d27908200918f8014028ae305c04f00f0604f0f004209d0443002d08bf46ea001408f801409cf8000010f00f04204618bf0120184301287ff481af03323ff57eaf5a45bff47baf500818f8001028aa125d01f00f03239c43ea021301f0f001002c08bf41ea020308f8003067e79df8b4009df8b510ddf824c040ea012014e6209ba8eb0502b2fa82f29a454ff000034fea5212c8bf0123134009023a02104341ea0e0100fb01f2511e0bfb09f01d9000f08d8022f001001b9000204feac37b1c9519921a9305e000bf501c1b9a0239904276d002468646bbf1000f18bf0a46b2fbf9f000fb192400eb080304eb0a0253ea020625d4259fba4222d2219fbb421fd21c9f3844dde9237600fb0670209fe6197408005d042727ea8606f040269f229e00f00f0503fb076356089c5dd20704f00f0704f0f004254408bf47ea00159d556ff001000ef1010280ea0e001346bbf1000f1d9f18bf3b18b3fbf9f000fb193400eb080304eb0a0c53ea0c05acd4259dac45a9d2219dab42a6d21c9d2844dde9235600fb0650209d2c446508405d042525ea8404e040269c229d00f00f0603fb04534fea5c041d5d05f00f0705f0f00535445feacc7608bf47ea00151d5583e71c9ddde919230ef1020000e00020259ed1074ed0da076fea00011d9a18bf5018b0fbf9f303fb190203eb080102eb0a0051ea00073dd4b0423bd2219fb94238d2dde923762b4403fb0673209f3a445708db5d042727ea820223fa02f2269b229f02f00f0601fb03714308cf5cc00707f00f0507f0f007374408bf45ea0217cf5417e0149cfff7dfb9ddf8fc0478b1002034901d98269901902298219b5a46cdf80890cdf800a000f079fbfff7c8b900243cbb1f991198159a01441298013282424ff0000828bf4ff001081f911bd21e981592401a01283ef6c5ac14e00121012006e00125b7fa87f11d9a85f00100490900294ff0000818bf002804d0002ad8d001e04ff00008dde91e01081a18bf012060ea080000f0010040420df2cc4dbde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe791429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f93b0054600284ff0ff3000f030821d9f072f40f02c82cde90651cde90823faf7bdff002800f006814ef66c674ff29c544ff6904a48f2a355ccf2ff07c2f229044ff6ff79cff6ff7a4ff000084ff0010bc0f2450503e000bfbff32f8fa8472668bff35f8f2068bff35f8f01466ff39601b1f1005f03d10168b94200f0ad804ff45c70fbf7c1fe002800f0d480514600bf4218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed1076080f80ab0a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fb1427ff44bafbff35f8f00bf44e8000121b154e8001fb142f8d03fe7d0f86c111c9d00294ff0ff3000f043816a78012a00f23f81287840ea022751f82700d8b1431a98074ff0ff3040f033816ff4403240f60f061a44cff6fd76b242c0f02981ca1852f8080cb84206d152f80c1ca1f1011010f5803f04d24ff0ff3013b0bde8f08f002a4ff0ff3000f0138152f8047c8f4240f00e81c3f54033994200f209810df1380a1046002253460024fff754fe0028e1d0e978a8786b7909062a7941ea0049a8794fea036848ea024782060f23059100f00f0103eae27202fb01f389225343db0a8df828300e2310f0200f08bf0f2408bf012301fb03f302fb03f34fead3238df829304ff00d0308bf022301fb03f302fb03f34fead3238df82a304ff00c0308bf032301fb03f302fb03f34fead3238df82b304ff00b0308bf042301fb03f302fb03f34fead3238df82c304ff00a0308bf052301fb03f302fb03f34fead3238df82d304ff0090308bf062301fb03f302fb03f34fead3238df82e304ff0080308bf072301fb03f302fb03f34fead3238df82f304ff0070308bf082301fb03f302fb03f34fead3238df830304ff0060308bf092301fb03f302fb03f34fead3238df831304ff0050308bf0a2301fb03f302fb03f34fead3238df832304ff0040308bf0b2301fb03f302fb03f34fead3238df833304ff0030308bf0c2301fb03f302fb03f34fead3238df834304ff0020308bf0d2301fb03f302fb03f34fead3238df835304ff0010308bf0e234b4361435143c0f300105343c90a04900aa806ac099ddb0a8df83710039013cc4fea29464fea274b8df8363022462b46cde901ba009600f018fcdde9100100eb2942059801eb2741a24226eae070b8bf1446a942b8bf0d46844212dd2beae8718d420edd1e9a12680f2a0ad86b1a1e9d271a05ebc206f080501c31817781b3812860002013b0bde8f08f2de9f04f99b0814600284ff0ff3000f0a282239c082cc0f09e820f4616461d46faf782fd002800f01581229ad17901f10800844240f00e81cde90a171078577891794ef66c684ff29c5bcde90c6540ea0720ccf2ff08c2f2290b4ff6ff7a002601250f910e9006e048f2a351c0f24501bff32f8f8847dbf80040bff35f8fdbf80000bff35f8f01466ff39601b1f1005f03d10168414500f0af804ff45c70fbf779fc002800f0d6804ff69041cff6ff714218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800808572a0f81ca0a0f81ea0a0f820a0a0f822a0a0f824a0a0f826a0a0f828a0a0f82aa0a0f82ca0a0f82ea0a0f830a0a0f832a0a0f834a0a0f836a0a0f838a0a0f83aa05be8001fa1427ff443afbff35f8f00bf4be8000121b15be8001fa142f8d037e7d0f86c210f9dddf888e0002a4ff0ff3000f0a581012f00f2a2810e9852f82000e0b1811a88074ff0ff3040f098816ff4403340f60f060b44cff6fd76b342c0f08e81571857f8080c0e9a904206d157f80cbcabf1011010f5803f04d24ff0ff3019b0bde8f08f57f8040c58454ff0ff3040f07581c1f540318b4500f27081002f00f06d81bbf1c10fc0f0698138780128e4d1a8060f2405f00f0604eae070704389246043c00a8df854000e209ef802809ef803209ef804c09ef8053015f0200f08bf012006fb00f004fb00f04fead0208df855004ff00d0008bf022006fb00f004fb00f04fead0208df856004ff00c0008bf032006fb00f004fb00f04fead0208df857004ff00b0008bf042006fb00f004fb00f04fead0208df858004ff00a0008bf052006fb00f004fb00f04fead0208df859004ff0090008bf062006fb00f004fb00f04fead0208df85a004ff0080008bf072006fb00f004fb00f04fead0208df85b004ff0070008bf082006fb00f004fb00f04fead0208df85c004ff0060008bf092006fb00f004fb00f04fead0208df85d004ff0050008bf0a2006fb00f004fb00f04fead0208df85e004ff0040008bf0b2006fb00f004fb00f04fead0208df85f004ff0030008bf0c2006fb00f004fb00f04fead0208df860004ff0020008bf0d2006fb00f004fb00f04fead0208df861004ff0010008bf0e2006fb00f004fb00f04fead0204ff000018df8620008bf0f2171430a9e61430020c90a002e8df8631000f09b80100640ea08404fea2048180640ea0c400ef1080a00140e90c5f30010a7f13f045546099001e0013e1ad015f8010b411e1f29f8d341b22029fff6fcae04eb400114f81000497840ea0122c12afff4f2ae3846594610abfff713fb0028e3d1e9e60e980a9d20eae07008902498cde9064b0630059004e040440b38013d804659d01af8010b1f28f6d904eb400114f81000497810ac40ea0122c12acdf83ca0fff4c9ae384659462346fff7eafa00283ff4c1ae0998dde90b1b0d9e049015a8ddf838a0cde9024048465a463346cdf804a0cdf8008000f074f9dde91201404401eb0a02584528eae871b8bf8346b242a8bf32468b4519dd089eb24216dd249e34680f2c12d8ddf820c0abeb0103a2eb0c0e059a02ebc40622f83410249a611ca6f802c0b380a6f806e01160ddf83ca0dde9064ba2e7002019b0bde8f08f2de9f04f85b0119d6c68072c72d824b12f89b9426ed0012c69d1d0f86c61002e68d00027b7eb512f64d156f82170002f60d0a7eb060c5fea8c775bd16ff440370ceb070e40f60f07cff6fd77be4551d306eb0c0e5ef8086c8e424bd15ef80c6ca6f1011717f5803f44d35ef8047cb74240d1ccf54037be423cd8bef1000f39d0032e37d39ef80070022f33d19446aa69dde90e87ddf840a099468ab1cb0801f007045746c24612f803804ff0010b0bfa04f444ea0804d454d046ba460f9f6c6805eb4402631c6b6011810ef10101721e6346cde903a5cde90187cdf80090fdf721fe69680139696005b0bde8f08f6f89b94204d14ff0ff3005b0bde8f08f022c3ff48bafaf89b942f4d0032c3ff485afef89b942eed0042c3ff47faf2f8ab942e8d0052c3ff479af6f8ab942e2d0062c3ff473afaf8ab9427ff46fafdae700bf2de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f87b00591dde91171ddf84cc00c692cb10c68844200f0948100259ee14f68002f00f0fc8100260021069609e0dde90361daf804703144ddf84cc0b94280f0ee81ddf848a00491daf80040655c2e0901d0012113e07f1a012f00f0e0810c4466780eb102210ae0042fc0f0d881a778e47857ea042600f0d281042100bf0391149915f00f04b1fa81f54fea55151cf804c018bf0124069945ea040e029616f00304ddf81490119e4fea0c188b4600f092800194daf80840b1fbf4f505fb1414109967180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990129069901f1010b5fd0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990229069901f1020b2ed0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050194fc07644604bf0f254446019f3d402c4301f80b40069901f1030b00bf029d6c1e032c2944069107d224e700bf06990bf1040b59453ff41eafdaf808401099bbfbf4f5002705fb14b40c44b4f1ff3fc8bf012707ea0e07012f1ad1ad1918d4944216d29d4214d205fb09056708e40715f807906ff00f04e24604bf0f24c24604ea0904ddf8149044ea0a04ddf848a0ec55daf808400bf10107b7fbf4f505fb147400270c44b4f1ff3fc8bf012707ea0e07012f14d1ad1912d4944210d29d420ed205fb09056708e407ee5d6ff00f04614604bf0f2441463440119e2143e955daf808100bf10204b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e01012914d1ad1912d4944210d29d420ed205fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c55daf808100bf10304b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e0101297ff46bafad193ff568af9442bff465af9d42bff462af05fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c5551e7002f01dd012508e0b7fa87f4109f00256409002fc8bf01252540d1f80880c96801fb08f9b9f1000f58d08e4614994ff0000ab1fa81f461094ff0ff3b0491e907069107e00af1010a0efb08f9ca45abf1010b43d2069954460029129918bf09eb0b04b4fbf8f50e6808f1010705fb18447f0805fb07666708f65d042121ea8407fe4016f00f094e4618bf012604990e43012ed7d1109964185cbf119915eb0105d0d49442ced29d42ccd20599660805fb01081cf8095018f80670129907f00f0907f0f0072f43e40708bf49ea051708f80670d1f80880d1f80ce0b3e707b0bde8f08f00bfb0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f3f7bffb06f1210506f1280029460722f3f7b7fb284621460722f3f7b2fb20465146032207f10905f3f7abfb06f11d0049460422f3f7a5fbf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f3f779fba81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f059e60846fdf789b900bf2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f3f731fb012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f3f718fb572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f3f701fb312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f3f7ebfa462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f3f7d4fa362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f67320c0f20000784410f80b0041f66d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f3f769facde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f3f74afa8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f3f74bf9284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f3f7f7f8002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f3f7c5f804a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f3f7b1f80020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f3f79af8352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f3f776f804a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f3f763f8002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f3f74ff804a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f3f72bf804f14f0051460722f3f725f884f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f26a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2f241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f797ff84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f2f7adfe284641462246c84703b0bde8f08370b50446d0f83c0142f665360d46c0f2440668b949f2b520cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3235000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc7b04ff690454ef66c6b4ff29c591446cff6ff75ccf2ff0bc2f229094ff6ff78002701260f93cde9100106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7007f0b6f8002800f0eb8129464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001f51457ff445afbff35f8f00bf49e8000121b159e8001f5145f8d039e71199012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7006f0e8ff002800f01d8129464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb9427ff445afbff35f8f00bf49e8000121b159e8001fb942f8d039e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f08f811198002861d010980778a7f1170002285bd811980c2840f07881109e7078b178084300f07281f0780138022800f26d81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f07f83172f40f09583002a40f05481fe2800f0c987812800f0bb87002840f0d08751ea030040f0478101f060b904460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0e78051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0d680824692e74ff0ff3729e147f6df40c0f24f008047002701261397adf8507006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0b3804ff45c7006f09cfe002800f0ab8029464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f00bf49e8000159b159e8001fa142f8d039e706f5a9718847bae601211ee70020109999b1119a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00f9012a804f0e3f94ff0ff3701269df85100002812a818bf4ff0ff3704f001fb054646b99df8500028b94af21f30c0f247004c3080470f98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384647b0bde8f08f0f9012a8264004f0a2f91098007800f07f040f2c2ddd142c40f3a981152c00f01183162c00f01c831d2c40f0da83119801380228c0f04d8510994878897840ea0124b4f5007f00f2448504eb4400032101eb40001199884240f03b8505f031fe002800f036850e9600260127119400f053bd092c00f3d180052c00f00c82072c40f0af83002706e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f083864ff45c7006f035fd002800f07b86294600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed10121c0f800b08172a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff443afbff35f8f49e80001002900f0d98559e8001fa142f6d036e70a2c00f043810b2c40f0de82d9f800500320cff680702840b0f1005fbff35f8f41f0f2822868002758457ff4a3aec5f8687185f8667185f86471d5f86c01c5f8607185f86571c5f86c71c5f80073a5f86c7320b148f2a351c0f245018847d5f87802002818bf09f0c1f80024c5f87842d5f868030e9620b148f2a351c0f245018847c5f86843a5f86c43286c42f68d46c0f24406a5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f41f0ab810168594541f0a78190f8a811002901f09c8106f046ff01f09eb9102c00f07081112c40f0348211994ff0ff37022908bf11287ff402ae1098407800287ff4fdad45f64d50c0f24600804701284ff000077ff4f3ad40f20830c0f210003790ff208df8d80044f25220c0f20100359040f2c960c0f248003446cde93877804798b148f27e30c2f2070000880122c1b264298df8d72008d80721b0f5807f38bf03218df8d7108df8d80040f2d260adf8e000052037ae8df8e200f01d35a90522fff7ccf94ff22507c0f247070120092132460c23b84707462646afe500294ff0ff3708bf002b7ff4d6ad1328bff4d3ad102a4ff0000138bf01211228b2fa82f218bf510901297ff4c6ad00f0ddbd182f4ff0ff3708bf00297ff4bdad002b7ff4baad352800f33083002800f0b585012800f0c185312840f0b385082abff4abad00f0c2bd11980e960228c0f0fe8110984078fbe111980228c0f012830e960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0e6824ff45c7006f01efb002800f0a98729464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f03e8259e8001fa142f6d038e7109811990130013907f059fe07469ce4dde9100106f0dffe074696e4119801380228c0f0348210994ff0ff374878897840ea0120b0f5007f3ff687ac0321119a01eb400191427ff480ac002700288df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813718df814718df815718df816718df817718df818718df819718df81a718df81b713ff4fcab109937aa03314ff0010c4b78012b00f295810f7847ea0323db08d45c07f007070cfa07f7274240f08981d45c013847ea040701f10201d754e7d105f077fa002800f07c810e960027012643e300f07e001a2818bf1c2c40f0718105f067fa002800f06c8101f040f9814608f073fab9f1000f4ff0ff3718bf00283ff4bdab1b2c00f094851a2c40f0bf85804610980025471c11984ff48052b346461e4ff4a0704ff4f071cde9372537aa4ff420740592cde9011048463946324643463d95cde90355009408f0defd002840f0e7854ff48050cde9370537a805900120cde903504ff4a07002904ff4f070019048463946324643464ff420773d95009708f0c2fd074600f0cdbdff20002701260d9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7006f026f9002800f0b58229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e8000121b159e8001fa142f8d03ae790f84410dde90d5661b1016c39b142f68d42c0f244020446084690472046002180f844100121119a032a0ed36db910988078082800f2dd864bf63941c0f25101963188470027fff78aba119a052a39d3012d37d1109a00279078411e06293ff67eaad17803293ff67aaa1279002a3ff476aa4bf63943c0f2510303f59a7398470027fff76cba10990e9e4c78002c00f0eb80022c05d840f082861199062980f0c1844ff0ff37fff75aba362800f09d82462800f09782572840f08382002e7ff47baa92e2022d40f02a814bf63940c0f2510080470027fff742ba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0a1834ff45c7005f0f4ff002800f07f8429464218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800b08772a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0f98259e8001fa142f6d038e7002780f8437145f64d50c0f24600804701287ff470a943f2a310c0f2560080470746fff768b90c294ff0ff377ff490a9b3f5005fc0f0a581fff78ab9481e1f284ff0ff373ff684a9c1f51630834240f29881fff77db9002b7ff478a9421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f07d81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f070819f284ff0ff377ff452a9042900f06881fff74db9119a072ac0f0b082032d40f0ad82109bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0ca8244ea0521012988bf0e4642f68d41c0f24401a1f140023146bbe200201199022902d31099497800e0ff21002800f0268502294ff0000736d0012930d000297ff4d3a84cf67e21caf2101187760783c9f8041007814760a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8080f83c70fff7a5b801218172fff7a1b88772fff79eb8dde90d5600210020fce548f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0f2824ff45c7005f04bfe002800f0d68229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f04a8259e8001fa142f6d038e7022abef4fcaf13e0002a7ef4f8afa0f1fd0102290cd397287ef4f1af08e06ff0780002427ef4ebaf02e0402abef4e7af45f64d50c0f24600804710990128c9784ff001004ff0010408bf022008424ff0000708d1fef7d3bf48f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7005f058fd00283ef4b0af29464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08472a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb1427ff445afbff35f8f49e8000121b159e8001fb142f8d03ae74af21f35c0f247050446a84794f86401109a00287ef400af94f80403214600287ef4faae107817281bd0d1f8640342f68d46c0f2440668b947f2c700c0f20000a6f594777844012100220023b847c4f8640340b3a6f140024ff47a719047214608bb01f206300e4610990c22fef7b9fa0f98002186f805030120bff35f8f86f804034ff4f07001904ff4207005f5106600900020002200230027b04700283ef4bdae84f8047305f14c0080474ff0ff37fef7b4bed0f86c110c90002900f01d8100204ff4006205e01b681a44b2f5403f80f0ce808b189f680137f5d05f68033727f0030738441030eee7119a0027032afef467ae2a1fb2fa82f25209b046114000f0f88011994cf6cd420339ccf6cc42a1fb0212109900f146038c780331b4eb920f88bf94082546302c28bf302505eb850206461846fef754fa0027002c86f8445086f8457000f0d580306c344630b9204600f0cefc0028206400f09f8342f68d41c0f24401a1f140020121904700274646fef726be0246119803287ef421ae109934464878897840ea01264ff6ff70864200f063824ff480503790002038903d9037a9cde902004ff4a070049101904ff4f077484631464ff4207300970af01afc002800f04a824ff0ff372646fef7f8bd0546119801287ef4f3adb34607f0e6fd00283fd00646b9f86c03002800f04a834ff48051a0f101084ff4a0703791002437a94ff4f077cde90341cde901044846414632464ff4207338943d9400970af0e9fbf8b9304629464ff41632fef7d8f94ff48050cde9370437a804900120cde902404ff4a07001904846414632464ff420734ff4f0773d9400970af0cbfb002800f016834ff0ff375e46fef7a9bd119a002a46d1b0f53e3f40f2eb810e9e4ff0ff37fef79dbd109fb978fa783b797f7941ea022143ea072232293791389280f0a9813221abe1d0f86c110027002900f0e6824ff400624ff0ff3c0df1dc0e05e02b681a44b2f5403f80f041818d18ac68b7eb542ff4d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e6e74646fef764bd1198002800f0a9810020109a4ff0000b02f1030e16324ff0ff3c1092cdf834e00beb4b020eeb420465784ff0ff37012d00f2a982a678e37856ea032900f0a3822379647953ea042800f09d82b9f5207f00f29982b8f5f07f00f2958209f101035b0803fb08f44ff6fb739c4200f28b821ef81220bbf1000f42ea0527109d62462cd015f8133c15f8126c43ea0623bb423ff478af12b315f80d3c15f80c6c43ea0623bb423ff46eaf012a17d015f8073c15f8066c43ea0623bb423ff463af022a0cd015f8013c2e7843ea0623bb423ff459af043a531c05f11805d2d100293ed0631d4ff4006201eb020edef80850bd423fd0def8006032444ff6ff76c0f20206b2422cd801eb020edef80850bd4230d0def8006032444ff6ff76c0f20206b2421dd801eb020edef80850bd4221d0def8006032444ff6ff76c0f20206b2420ed801eb020edef80850bd4212d0def8006032444ff6ff76c0f20206b242c3d94ff6fc7304f10802c0f201031a401044103020e0def804209a427ff404afdef80c209a427ff4ffae9ef81020042a7ff4faae9ef811209ef8123042ea03224a457ff4f1ae9ef813209ef8143042ea032242457ff4e8ae119a0bf1010bddf834e093450cf1010c7ff42cafb0f53e3f3ff6daae002500201090e3e090f8a911002918bf05f0a6fd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08e804af27366c0f246060021002200230027b0470e9efef739bc4ff0000c4ff400634ff0000ec0f800c30de0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe466ad2cf18ba68ce58013201d07746f3e7f418220c022ae6d80a1995680135e2d115682e443e6012681444220c022adad80a1995680135d6d115682e443e6012681444220c022aced80a1995680135cad115682e443e6012681444220c022ac2d80a1995680135bed115682e443e6012681444b4f5403fcfd3b5e7b1f5fa6f02d94ff4fa6137910121054680f8431145f64d50c0f24600804701281ed143f2a316c0f25606a6f188008047022c074608bf002f01d057b90fe04bf2110237a9c0f24b020220904738b10746b047002085f843010e9efef7b7bb0e9e0027fef7b3bb701ca9f86c0300272646fef7acbb0c99d1f86c114268836890454ff00002c0f80c8008bf00f1100241f82320109a1198013282424ff00007109200f0f38010980d9b00eb400003eb400213f81000937892f801b00a93d37809931379527940ea0b290b930892a1b3bbf1010f31d84ff400628b189f684f45d8d01b681a444ff6ff73c0f202039a4223d88b189f684f45ccd01b681a444ff6ff73c0f202039a4217d88b189f684f45c0d01b681a444ff6ff73c0f202039a420bd88b189f684f45b4d01b681a444ff6ff73c0f202039a42cfd9dde909730b9e43ea0721089c013146ea04224908514301f105088df8de004fea18208df8e1004fea18408df8e2000520079101218df8e60004208df8dc108df8e80037a811218df8dd508df8dfb08df8e0808df8e3508df8e5508df8e4508df8e7508df8e9308df8ea708df8eb608df8ec4006f0c9fc00287ff46aad0c98d0f86c110020a9b3bbf1010f32d84ff40062881883684b452cd0006802444ff6ff70c0f20200824223d8881883684b4520d0006802444ff6ff70c0f20200824217d8881883684b4514d0006802444ff6ff70c0f2020082420bd8881883684b4508d0006802444ff6ff70c0f202008242cfd90020079a002a3ff424af09990a9b0902089a41f0010119440b9b120249081a434a43511e032901d200210ae022f003030021471804318b427d75bd75fd753d76f7d112f003023ff401af00f11503012a5d543ff4fbae1944022a4d7018bf8d70f4e60e9efef79eba304629464ff41632fdf7a8fe13a807f0d3fb0027e6e44bf639400027c0f2510084f8447080474646fef788ba2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09e804ff45c7005f027f8002800f09680414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000129b155e8001fa142f8d04fe7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db03f0b3ff68b940460af033fc48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f098ff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f04982172f40f05482fe2804f22737884600f06d82002840f0788200980af0adfb414602e0022084f8200350460c22fdf7e4fb94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7b4fb47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf783fbb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f80080bff35f8f08ea0700b0f1005f47d1d8f80000b04243d198f8500338b1002088f86401c8f860014db0bde8f08f98f8640118b3d8f8604104b340f6b800c2f20000d0f8009006a802f00df9b9f1000f00f07581484621464ff41632b346ba464ff6ff75cdf81490fdf72dfb4ff29c5600274ff00109c2f2290620e098f8660170b1d8f8680140b147f64c61c2f207010968401a002802f3dc80002088f8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0a01b1f1005f03d10168594500f09f804ff45c7004f0b1fc002802f09c804ff69041cff6ff714218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa1427ff455afbff35f8f46e8000121b156e8001fa142f8d04ae7817a002942f00080027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e0002088f86401c8f8600188f86601012088f8650140f6a120c0f24700804701f074bf40460d460af0d3fad8b102304ff0030008bf022084f820032946bce584f85003d9f800204ef660231a44c4f8602380b140460d460af099fc0af06dfc294630b9a9e50af068fc002829463ff4a4ad03209fe5002084f866019de51868624600eb0620704400eb0b4000eb056138466546fdf779f90fe04eea062141ea0b4141ea05633946624665460af067fa00281cbf032084f8200305f1080084f84f03414679e501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0e48300218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f09a8000218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f346bef15f0f98bf4ff05f0bcbf1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f905eb0e0209f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd009fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0de460ae00ef1010e07e00ef1020e04e00ef1030e00e0de460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000a15f80a10002900f0c78005eb0a035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d00af1200abaf1600f7ff496af4ff0600a5ee00af1010a5be00af1020a58e00af1030a55e00af1040a52e00af1050a4fe00af1060a4ce00af1070a49e00af1080a46e00af1090a43e00af10a0a40e00af10b0a3de00af10c0a3ae00af10d0a37e00af10e0a34e000220a7162e70af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46d646baf15f0f98bf4ff05f0ecef1000942f2107c0aad19eb0a0b51d0b2fbf3f40a2b04f1300105f80a104cf6cd41ccf6cc41a3fb011747d31bf1010140d004fb1326ff08b6fbf7f405eb0a0204f13001517048f21f51c5f2eb11642ba3fb015135d31bf102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31bf1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb11420af1040a63454fea57330aadabd20ce0f2460ae0f24607e00af1010a05e00af1020a01e00af1030a0aad059f002205f80a20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a4609f0bbfcd4f870c272208df8280078208df8290020204ff0000b1ffa8cf28df82a008df82bb015f80b00002800f0c88005eb0b035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00bf1200bbbf1600f7ff496af4ff0600b5fe004460020887078e70bf1010b58e00bf1020b55e00bf1030b52e00bf1040b4fe00bf1050b4ce00bf1060b49e00bf1070b46e00bf1080b43e00bf1090b40e00bf10a0b3de00bf10b0b3ae00bf10c0b37e00bf10d0b34e00bf10e0b31e00bf10f0b2ee00bf1100b2be00bf1110b28e00bf1120b25e00bf1130b22e00bf1140b1fe00bf1150b1ce00bf1160b19e00bf1170b16e00bf1180b13e00bf1190b10e00bf11a0b0de00bf11b0b0ae00bf11c0b07e00bf11d0b04e00bf11e0b01e00bf11f0b01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d946bbf15f0f98bf4ff05f09c9f1000a42f2107e1aeb0b004fd0b2fbf3f50aa905f1300401f80b404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0b0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020bf1040b73454fea5633add209e0cb4607e00bf1010b04e00bf1020b01e00bf1030bddf8149000220aac04f80b20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06e8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df8870042f2941645f29c140aaa48460e21c2f22006c2f2130409f069f94ff6a42040f6b801cff6ff70c2f200010858a04266d14ff6b020cff6ff700858b0f54d2f5ed14ff6b420cff6ff700858a04257d145f610634ff0000ec2f213034cf6394506f1040c00274ff0ff32634548d8186830f003041ad09e4228bf0c2842d3f11a8c424ff0ff313fd8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e2d12ce00021417191e60421b7f5807f1ed300223d46b5f5007f14d3b5f5806f13d3b5f5006f12d30901b2eb153f4fea1515f0d10ce000219171fef765bf00211172fef71bbc490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006806f1080342f6941c9842c2f2270c4cd142f610674ff0000bc2f2200746f6b9700cf1040e00244ff0ff3a4ff0ff3977453bd83e6836f0030515d0bc4528bf0c2e35d3aceb07039d4233d82346a54288bf2b46f6071cbf1c46ab447b19013803f10407e4d121e00420b4f5807f16d300262546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b6eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea000ad94603e04ff0ff3a4ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834264d14ff69423cff6ff73fb58b3f5333f5cd14ff69823cff6ff73fb58834255d14ff29c5043f21063c2f229004ff0000bc2f2270342f6f935a0f1040ca0f1080e0024634542d81e6836f003071ad09e454ff0ff30049028bf0c2e3ad3aeeb030087424ff0ff3034d82046a74288bf3846f6071cbf0446bb44d819013d00f10403dfd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff00634505d17b4204ea03000490584602e04ff0ff300490064666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b7009f061f9059de05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f88000208df8870020464946524609f08cf80020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac049a2046314608f0bfff28461a21224608f03cfe002088f86401c8f8600105984ef217310a904ff416300b900aa8c0f247018847012088f8660106a800f036f9c8f810004db0bde8f08f0020c871d6e70021417207e700bf2de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff6904a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f09c804ff45c7002f0a6fb002800f0d28051464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff45bafbff35f8f00bf47e8000121b157e8001f4945f8d04fe74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c56d1f8009000684ff6904bccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108009007e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168b94200f09c804ff45c7002f08cfa002800f0f08059464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f51457ff457afbff35f8f00bf46e8000121b156e8001f5145f8d04be74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ce047f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422fd041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94217d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a9eb0501b1fbf0f001b0bde8f08f002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204607f01ffd854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f01f81207887f00301084200f01b81012039464246334600f054fa0446002898f8080018bf06240ee14ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f0f1804ef66c6a4ff29c574ff690480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168514500f09d804ff45c7002f0eff8002800f0be80414600bf4218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff455afbff35f8f47e8000121b157e8001f4945f8d04ae705eb450100eb011090f85d1201b300f513760024304629462a460323009407f0c3fc706840b14bf69b71c0f25d018847706804f0a7fc74603068b475002818bf04f0a0fc0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f058f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104607f0b0fb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009507f056fc606840b14bf69b71c0f25d018847606804f03afc65602068a575002818bf04f033fc00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff690498046ccf2ff05c2f229064ff6ff77cff6ff7900244ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09d804ff45c7001f08cff002800f0958049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff457afbff35f8f00bf46e8000129b156e8001f5945f8d04be7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46faf713fda81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450bcde90612cde9080303e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c7001f090fe002800f0398449464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70999089d01eb410100eb011095f9081000f51376b1f1ff3f01f0030409dd374617f8110fd0bb3068002818bf04f04cfa2fe3307cf0b1707ce0b10799099a002730460323009707f051fa706840b14bf69b71c0f25d018847706804f035fa77603068b775002818bf04f02efa00203060b06030823068002818bf04f025fa00204ff480713060b0603182a978b081092006f11107f174b17434757076b07ca978884240f0db82317da14240f0d782069b411ca3f10b00727e02971e2828bf1e209042b17488bf7076981e84b200270a2c4ff00008c0f0e782092241f221090920039419e030684f46002818bf04f0ecf9b089376001303774b760b081002c18bf4ff00608039cd146ddf814a00aeb0b0082b2a24280f0c782317c80b20429824600f28880aa5c00f1010a4b1c0129337405dd022906d0032970d1f28106e021b9727503e0338943ea02223281a24580f0aa8204296ed015f80a204ff0000c831c8f1c0129377406ddff290bd0032967460dd19a4652e000291cbf378947ea0222328100e072756746a34204d38be2f281a34280f08882022936d8ea5c00f1030acb1c0129337407dd022937d0fe2907d17275a2450cd376e231b9338943ea02223281a24504d36ee2f281a24580f06b8202292fd015f80a20031d41f00407fc29377408ddfd2909d0fe291cbf378947ea0222328103e079b9f28100e072756746a34280f0508209b19a4613e0ea5c00f1050a0520307401e09a466746f189308941ea0221f18128b107f086f80028306000f06a8233897089191a1ffa81fb1ffa8af1621a5a45b8bf93465fea0b4208d03268294410441ffa8bf2faf709fb70893389584481b2994270817ff44faf0025cdf81080d6f800808df82b50707db8f1000f06930df12b0108bf88460f2806d8317d00f00302511ab1fa81f14d09000706d4317e707e814238bf30760fe000bf706840b14bf69b71c0f25d018847706804f002f97760707e30760120f082cdf814a09db1707db57d400714d4002d4ff0000400f0898106984ff6ff7381b2002900f00d8101295ed10020d2e0707d400753d4002478e14ff4803007f015f8002d804600f07081b07d002800f06c81b8f1000f00f068817568002d00f0008130890428c0f0608131680a1812f8043c002b40f0598112f8033c002b40f0548112f8023cff2b40f04f8112f8012cff2a40f04a814ff4803429606860c5f80c802c610028019000f067814bf69b70c0f25d0000f58572284600219047002840f033812969002900f02f8168688c420c46e7d1019a0c468242e3d125e14ff4803006f0c3ff044620e1069a4ff6fe701040a44642426ff0010000bf08eb0005ac78ed7883ea04231cb25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead73787ea430383ea05231fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead737023087ea430309ead5371518023587ea430395d1023000276446069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003f0899ab2824270d1099b4046faf77dfa00286ad141f2210a4ff00009012375e0382006f002ff00285ed00546077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377047f2ab00c0f200007844286247f2b300c0f20000784468624bf69b70c0f25d0045f6e46200f13c0c28460f21c0f27c023823e04740b3284603f069ff4446706841f2210a40b14bf69b71c0f25d018847706803f05cff77604ff000090323b77506980799099a089dddf8108087b23046009706f05eff002c214604463ff455ad084603f044ff50e5756073e6c4f58030b4f5803f444606902f60ef607ff646aecde70799099a002430460323009406f040ff706840b14bf69b71c0f25d018847706803f024ff74603068b475002818bf03f01dff0020387000203060b06030824ff00a0840460bb0bde8f08f287a4006f8d5307c08b302980078e0b10799099a002430460323009406f013ff706840b14bf69b71c0f25d018847706803f0f7fe74603068b475002818bf03f0f0fe00203060b06030824ff00b083068002818bf03f0e5fe00203060b0603082cae702980078e0b10799099a002430460323009406f0e7fe706840b14bf69b71c0f25d018847706803f0cbfe74603068b475002818bf03f0c4fe00203060b06030824ff00608a7e700bf2de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7f3f9002869d006462846fff749fa21462a46fff71dfa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff7d0ba0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22f9f73ffe04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522f9f7fbfd0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522f9f7a5fd4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff764ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff690480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f09c804ff45c7000f03efe002800f0c18041464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff456afbff35f8f46e8000121b156e8001f5945f8d04be7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff7f0fd2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff61d40cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023a6e745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04468002c00f0bd828368002b00f0b98204eb030b4ff000090027002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310ceb0a0300275b451c464ff0000680f09d82a04618f9013b03f07f05bd40002b46ea050610d406f00703012b16dc0bb3012b40f08b82abeb0803082bc0f0868204f10903dee700bfd84580f07f82182f07f107074446dcd978e200bf022b3ad0052b40f07382abeb0803042bc0f06e82631dc7e7d84580f0698294f90130002b04f10203bed55b4580f0608294f90230b3f1ff3f04f10303b4dc5b4580f0568294f90330b3f1ff3f04f10403aadc5b4580f04c8294f90430b3f1ff3f04f10503a0dc5b4580f0428294f90530002b00f13d82a31d96e7d84580f0388294f9013004f1020c002b03f07f0a1ed5dc4580f02d8294f90270e31c07f07f05b7f1ff3f4aeac51a02dde0469c460ee05b4580f01d8294f9037004f1040c07f07f05b7f1ff3f4aea853a33dd9846abeb0c039a4500f20c82f308672b1dd0652b7ff460afbaf1060ffff45caf9cf80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf4ff29c54c2f229040290cde9002132e0044660460e4651461746654600f017fcac4631463a46204637e7dc4580f0db8194f90470631d07f07f05b7f1ff3f4aea455aaddc5b4580f0ce8194f90570002f00f1c98104f1060c4aea077ab1e748f2a3513046c0f24501bff32f8f8847dde900210298ac462768bff35f8f2668bff35f8f33466ff39603b3f1005f07d133684ef66c65ccf2ff05ab4200f0b0804ff45c70654600f079fbdde9002106460298ac46002e3ff4f1ae4ff69043cff6ff7300bff418373384f8709384f8719384f8729384f8739384f8749384f8759384f8769384f8779384f8789384f8799384f87a9384f87b9384f87c9384f87d9384f87e9384f87f9384f8809384f8819384f8829384f8839384f8849384f8859384f8869384f8879384f8889384f8899384f88a9384f88b9384f88c9384f88d9384f88e9384f88f9384f8909384f8919384f8929384f8939384f8949384f8959384f8969384f8979384f8989384f8999384f89a9384f89b9384f89c9384f89d9384f89e9384f89f9384f8a09384f8a19384f8a29384f8a39384f8a49384f8a59384f8a6938ed14ef66c63ccf2ff0333600123b3724ff6ff734ff29c54b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290454e8003fbb427ff43bafbff35f8f00bf44e8006323b154e8003fbb42f8d02fe798f8043098f8057098f80650032b47ea052437dd052b58dc042b78d0052b7ff43daed6f868313bb147f64c67c2f207073f68db1b002b18dcd6f86c3186f86691c6f86c91c6f80093a6f86c936bb10c4648f2a35180461846c0f24501174665468847ac4621463a46404647f64c63c2f207031b6845f69077c0f201073b44c6f868310be6012b3ff4fdad022b00f08780032b7ff403ae174688466546fff724fb03460298ac4641463a46002b3ff4f6ad96f84231002b3ff4f1ad304641f28831a6f8404106f070fc47e0062b4ad0072b7ff4e4ad80464df6db50c0f24a0016460f466446804703465d1ea446394632464046012d3ff6d2ad981eb0fa80f04009fff7dcfba446394632464046c6e5174688466546fff7e8fa03460298ac4641463a46002b3ff4baad96f84231002b3ff4b5adb6f84031a3427ff4b0add6f83c3186f84291002ba6f840913ff4a7ad42f68d411846c0f2440188470298ac4641463a469be5d6f86c31c6f86891002b86f86691c6f86c91c6f80093a6f86c933ff48dad0f4648f2a35104461846c0f24501164665468847ac463946324644e696f84231c6f83891002b3ff478ad0446d6f83c0165468846174686f84291a6f8409120b142f68d41c0f2440188474af273660120002100220023c0f24606b04720463a464146ac4659e54ff2a513c0f2490303b0bde8f04f18477fb50646002806d1fff772fa002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817047f28851c0f20001033079440b22f8f7e6ff0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f8f7aeff0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f8f7fffe1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f8f755fe4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f0eb800c46014600784d2840f0e5804878432840f0e1808878012840f0dd804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f03d10268424500f0a0804ff45c70fff766ff002800f0ae804ff690425146cff6ff728318373283f8705383f8715383f8725383f8735383f8745383f8755383f8765383f8775383f8785383f8795383f87a5383f87b5383f87c5383f87d5383f87e5383f87f5383f8805383f8815383f8825383f8835383f8845383f8855383f8865383f8875383f8885383f8895383f88a5383f88b5383f88c5383f88d5383f88e5383f88f5383f8905383f8915383f8925383f8935383f8945383f8955383f8965383f8975383f8985383f8995383f89a5383f89b5383f89c5383f89d5383f89e5383f89f5383f8a05383f8a15383f8a25383f8a35383f8a45383f8a55383f8a6538ed1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a457ff451afbff35f8f47e8000222b157e8002f4a45f8d046e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff6b922cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff61140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff35f2e0cde901100120cff680704ef66c644ff29c564ff6904bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f03d10168a14200f09b804ff45c70fff74dfb0028c5d059464218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff459afbff35f8f00bf46e8000121b156e8001f5145f8d04de7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff41faf00210025fff778fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff7f4fd0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff72afe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff6bd12cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff750fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef788fa014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef768fa0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef757fa204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd46f25240c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7a5f90028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f7f703ff4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7a3bd00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1f9f7cdfec8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f9bb00278437842ea0325b5f5007f04d94ff0ff301bb0bde8f08f4ef66c6a4ff29c56ccf2ff0ac2f229064ff6ff774ff000084ff0010b0791099008e000bf48f2a3512046c0f24501bff32f8f8847d6f80090bff35f8f3468bff35f8f20466ff39600b0f1005f03d12068504500f0a2804ff45c70fef7d3fb002800f09a8004464ff69040cff6ff7000bf2118373081f8708381f8718381f8728381f8738381f8748381f8758381f8768381f8778381f8788381f8798381f87a8381f87b8381f87c8381f87d8381f87e8381f87f8381f8808381f8818381f8828381f8838381f8848381f8858381f8868381f8878381f8888381f8898381f88a8381f88b8381f88c8381f88d8381f88e8381f88f8381f8908381f8918381f8928381f8938381f8948381f8958381f8968381f8978381f8988381f8998381f89a8381f89b8381f89c8381f89d8381f89e8381f89f8381f8a08381f8a18381f8a28381f8a38381f8a48381f8a58381f8a6838ed1c4f800a084f80ab0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f48457ff450afbff35f8f46e8004028b156e8000f4845f8d045e70024ddf824805db1fdf7fafb0146002c4ff0ff3018bf002902d11bb0bde8f08fb5fa85f040094ff000098df82c908df82d908df82e908df82f908df830908df831908df832908df833908df834908df835908df836908df837908df838908df839908df83a908df83b908df83c908df83d908df83e908df83f908df840908df841908df842908df843908df844908df845908df846908df847908df848908df849908df84a908df84b908df84c908df84d908df84e908df84f908df850908df851908df852908df853908df854908df855908df856908df857908df858908df859908df85a908df85b908df85c908df85d908df85e908df85f908df860908df861908df862908df863908df864908df865908df866908df867908df868908df869908df86a908df86b90bcb1d4f86c21a2b14ff4006304e03f683b44b3f5403f0cd2d718be680136f6d07e68033626f0030609eb060101f11009ede7002d4ff0020a039500f00581ddf81cc0acf102020a2ac0f00081002608eb0a0b9bf801504ff0ff30012d3ff648af9bf802209bf803309bf8047042ea03229bf8053042ea074747ea0361a1f1011212f5803f0a91fff433af9bf808109bf809e0029141ea0e210af10a020497aceb02034f1e9f42bff423afcde905269bf806209bf807300a9e42ea032cb6eb0c07fff416afb9423ff613af18f80a70089147ea052a4feada000ba90e5c07f00705012707fa05f5354240f003830e5c45ea06050d5407994ff6ff75c0f20205b4b3d4f86c0198b317461a0201924fea0e264ff4006200eb0208d8f8083053454bd0d8f800301a44aa4221d800eb0208d8f80830534540d0d8f800301a44aa4216d800eb0208d8f80830534535d0d8f800301a44aa420bd800eb0208d8f8083053452ad0d8f800301a44aa42d3d900bfbcf1000f40f0be8204980a464ff6fc710330c0f2030108404844944600f1100908980599069e00eb010a0398013686424ff0000028bf0120ddf824804fd2aceb0a02092a3ff64caf49e0d8f804000a9a904240f09782d8f80c006045c0f0928236d9089aa0eb0c00824200f28b827ab3029831180198c1f1000cc2199044a1f1010e002208eb02050beb0203287c9e7ab04240f0778296451cd06e7cdf7abe4240f070820ceb0207be1c13d0ae7c187b864240f06782079ef81c07d0e87c5b7b984240f05f8204329142dbd1b446a7e78c46a5e7ddf81cc0a2e7ddf81cc0002800f05082baeb0c004ff0000118bf0120b9f53e3f88bf0121014303980028c1f100003ff43eae00297ff43baed4f86cb1bbf1000f40f08b804ff44030fef75af9002800f02f82834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760222c0f2020600210ae00aeb080209f10101ddf8248071454ff000003ff498ad08eb02050a9218f80200aa786f7805922a7a95f803e095f8049095f805c095f806a0eb7908926a7a40ea0728cde906215cb3012f29d84ff400670beb0705a868404500f0a28028680744b7421dd80beb0705a868404500f0988028680744b74213d80beb0705a868404500f08e8028680744b74209d80beb0705a868404500f0848028680744b742d7d90598cdf810a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a002002930597b9f1000f26d00beb09035bf809105a68514580f09c80eab10beb02005bf80210d0f80490514580f08d80b9f1000f11d00beb09035bf809105a68514580f0878042b10beb02005bf80210d0f804905145d6d377e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f6f7adfe4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f8002311d90beb09004bf809104ff0ff3142608160c260c4f800930be0e868ddf80ce00a9a089f60e010b10268114401604ff000090020b9f1000f7bd00beb09035bf809105a68514522d2002a72d00beb02005bf80210d0f80490514513d2b9f1000f67d00beb09035bf809105a6851450ed2002a5ed00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf80ce00a9addf810a0029b089f00280cbfc4f800c3c0f804c005984ff6ff7668600020c0f20206c5f80880e8604aea0321069bddf81c9047ea032a814202f10a087ff4bdae05f110077818099952464144f346f6f7c0fde968de466868aa68d4f86cb15144e96081424ff0000018bf07464bf82270a3e600204ff400684ff4006703e02f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f6f7dffd4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f800831bb0bde8f08f00281ebf0168114401604ff0ff301bb0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7f1fe002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f86813002974d104464ff41630fdf74ffe014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8681300e00021084601b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7a9fd002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f87812002974d104464ff4163003f0abf8014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8781200e00021084601b0bde8f08f00bf2de9f04f83b04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b029002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c70fdf760fc002800f0c68049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70446fff7ebfd002c18bf002805d102990120487103b0bde8f08fc4f8600101254ff4f07084f8645101904ff420704af61f470090c0f2470700200021002200230026b84740b184f864610298c4f86061457103b0bde8f08f0298057103b0bde8f08f0024cde700bf014640f258304df69f22c2f20000c0f248021047022a3cbf4ff0ff3070472de9f04fadf2dc4d0f460e7849781b9246ea0126b6fa86f14c0922f0010102294ff00201209101f0c385002e0e901097cde90c3601f0bc850220209000200f90209a109b9818995c4078023241ea00251b982092801a854201f2a985022dc1f0a685ddf814753868411e0028396001f09e859e187778032f01f2998596f80080f807a5f1020c119511d1b01c2390ddf80805ddf804b528900c98ddf8009524900df1e00a022f6fd2ddf80c258ee0bcf1020f0df1e00ac1f07a850e98d0f86c01002801f07485f178012901f2708596f8029049ea012450f82410002901f067850a1a910741f063856ff4403140f60f031144cff6fd739942c1f05985104450f8081ca14241f0538550f80c1c0025a1f10113cff6ff75ab42c1f0498550f8043c8b4241f04485c2f54032914201f23f85002801f03c85027812f00b0f41f037850022534601f0cffd002801f03085301d23901198dde93a1ba0f1040c38980d462490ddf81405013180694908289140b1e20809f00701835c012606fa01f119438154a946022f8fd3bcf1000f01f00f85239845f64d5610f9014bc0f246062390acf10107b047012808bf0134601e81b2650800ebd130002c48bf4510b0470128ddf80c05bc4608bf6d422a18b8f1030fcde929b9cde925c25ad0b8f1020f32d0b8f1010f40f0f180bcf1000f01f0df84ddf88c8098f80010012901f2d88400294ff0090508bf0525ac45c1f0d08498f8012098f80300002900f0e18198f8023098f8047098f8056098f8064042ea032e40ea072398f8070098f8082046ea042740ea0226d4e1bcf10e0f41f0b08423984ff6fe71047840784e4644ea00258d422899ddf8909027910e994ff0010800f033824ff6ff72954240f0d681d1f868934ff4a0704ff420764ff4f07b279023e2bcf1060fc1f08b84239e70790630844541f08584bcf1060f30ad19d0062403e000bf0134644513d2305d01381e28f8d93019aceb040152462b4601f080fc002801f06d843898ddf894c004446445ebd3ddf81005002801f03e842498002801f05e84fcf7d4fa002801f0598475792599a81d814241f0538447f65420c2f20700d0f800a0baf1000f01f049849af80c009af80d109af80e209af80f3040ea012040ea024040ea036eaef1810010f1800f4ff00004c1f034849af810109af811209af8133041ea02219af8122041ea024141ea0360a0f1810111f5817f099041f21f84002d00f06b8606364ff0000b00270df1e0090df1c008cdf89ce009e000f1004049f824000137af4204f1010b80f02382f05d5c46411e1e29f0d9f019e91b42462cab01f00bfc002800f0118230992c980f4449f82400e6e708f0fe00042840f08780b8f1040f03d1bcf1070f41f0e683b8f1050f09d1bcf1080fc1f0df832398c0790830844541f0d9830e980024d0f86c71002f01f0d38323984178012901f2ce8390f800e04eea012257f82200002801f0c583c31b980741f0c1836ff440301e1840f60f00cff6fd708642c1f0b783fd1855f8080c904241f0b18355f80c1c0027a1f10110cff6ff77b842c1f0a783002d01f0a48355f8047c8f4241f09f83c3f54033994201f29a83ddf81405806940b1d4080ef00706035d012707fa06f21a430255b8f1040f40f06d812846002230ab01f01ffc0024ddf81015002808bf4ff0ff34239f002918bf002801f051830020389026982899cde902a025984a46019024985b46009701f078fc01f03ebbb8f1080f00f0cc81b8f1060f40f0fb83bcf1100f41f05a83239b00241879597950ea012c1ebf9979da7951ea022101f04e831e785f7846ea0725a945c1f04783a9eb0502944501f242839878da7840ea0229cb45c1f03b832795abeb0905279aa94201f23483ddf81005002801f00a834944299126993802084430440ceb020b03f1080a4fea800807e000bf299809f10109279a814581f0f58228982499269d09fb001e4646114605e000bf0131594506f10406ead26818f8d42a9a9042f5da44081ef80420042525ea060722fa07f7c7f342031af8033025ea8707fb4003f00f0702f00f0c02f0f002269d3a44c00708bf4cea03120ef80420d7e74fea820e98f8022098f80460530087007600002f4ff0000418bf002e01f0d982f145c1f0d682a9eb0e02974201f2d1829b45c1f0ce82abeb0302964201f2c982002900f0828300228ae3012801f2c082d1f86c01002801f0bb8250f82510002901f0b6820a1a910741f0b2826ff4403140f60f031144cff6fd739942c1f0a882104450f8081ca94241f0a28250f80c1c0027a1f10113cff6ff77bb42c1f0988250f8043c8b4241f09382c2f54032914201f28e82002801f08b82027812f00b0f41f086820022534601f01efb002801f07f82ddf81405dde93a6b8069ddf8e090711c4fea5101279138b1ea0804f00701835c08fa01f119438154b9f1000f4ff0000401f06682239991f806c0cb795cea03281ebf91f808a04f7a5aea072501f058828878c97840ea01229642c1f05182b11a884501f24d8223990879497940ea012100208b4538bf01202591abeb01018d424ff0000188bf01210843ddf810154442002901f00f82002841f00c82239e2292f07ab17a000640ea0140717b367b090641ea0641249e0014b1454fea214e00f07484002400f060bf239fc12930ac2fd3287801282cd1bcf1090f2397c1f0d681a5f13f002a902398acf1080600f1080802e0013e01f0ca8118f8010b421e1f2af7d342b2202a13db2a9b03eb400213f81000527840ea0222c12a09d3284623460f4601f088faddf894c039460028e0d14ff0ff3401f0beb9bbf1000f00f03d84abf101054ff000084f4609e000bf454508f10108a4f1010407f1040700f02b8459f828100029f2d40020434684421dd007eb80067268b2f1ff3f18dc5a1c954214d0b268b2f1ff3f11dc9a1c95420dd0f268b2f1ff3f0adcda1c954206d032690433002a00f10400e0d400e00022504630ab2cae009602f03ef80028b8d02c980028c4d04af20d3130a8c0f24e018847bde7bcf10c0f41f09281239e00243279717952ea012025901ebfb379f77953ea072701f085812598b0f5207f01f28081b7f5f07f01f27c81b07a0f281f9001f27781f37a102b229301f27281ddf81005002801f0488173783078f5781b06b47843ea00404fea204c280640ea044000140a90307a737a259d40ea03231846b3eb550f28bf6808b0eb570f28bf78084fea400e4043013b4fea80062698a5f102054ff0000938bf4b46bc1eb3eb550f1d9528bf6b08b3eb540f1a9428bf63085c005b439b001693229b0902102b4ff00003199438bf012323934b1e0ceb00080993a0eb0c0302f0010011440890081a1c90d8075242159004204c460792ca1e20ea880100eb88000692139105900b971e96cdf8508024e0269a4fea550c12f80c30042020ea850723fa07f71f9807f00f07874298bf0746002903f00f0103f0f003229818bf07463b43ed0708bf41ea071302f80c3000bf0b9f0134bc4201f0c380e14339448c42b8bf21460a986fea4102ceeb41017244c94323181a9821eae27101fb01f9621e011b8a421292b8bf114619986fea4102c0eb41010244c94321eae27101fb01f0189028982499ddf870c003fb0010079926900998002288426ff0010a4546279352d10898a8460028c2d02598d14301448a42b8bf11466fea4103ceeb41017344c94321eae37101fb0191b142b0d818eb0205add427980028aad42a988542a7da27985845a4da1a982399a042fff680af1d9823999042fff67baf1298531e53ea000123993ff574af2298c1b210294ff0000138bf01211d98821a9342b8bf1a4619986fea4203c0eb42020344d243189822eae37202fb0202169882424ff0000288bf0122114053e71a980021a042a8bf01212346002c18bf01231940dde9058781f00100179021942ce000bf269e4808315c042424ea080421fa04f4ddf87cb004f00f045c4598bf5c46002b229b18bf1c4601f00f03159d43ea041301f0f001002d08bf44ea01033354ddf8a4b0149d1e9e219c023208f108089445a7f102073ff46fafb91c8a42b8bf11466fea4103ceeb41017344c94321eae37101fb0191b1425dd8a9185bd42798002858d42a98814255da2798584552da1a98239bac46a04229db1d98239b824225dc1298a2f1010b5bea0003239b1ed42298c3b2102b4ff0000307f1010038bf01238345b8bf5846199d6fea4004c5eb40002c44c04320eae470189c00fb0040169ca0424ff0000088bf01200340269e4808315c139d6ff0010a21fa05f41f9d04f00f04ac4298bf2c46002b229b18bf1c4601f00f0301f0f00121435feacc7508bf43ea041131546546ddf8a4b0ddf870c0219c1e9e259b82ea0a01501c19448842b8bf01466fea4100ceeb41017044c94321eae07000fb0090b0423ff675afa818411c3ff571af279800283ff56daf2a988142bff669af27985845bff665af1d9882424ff00000a8bf0120179b1843239b7ff436af22983b46c0b210284ff0000038bf0120ba42b8bf1346199d6fea4304c5eb43032c44db4323eae473189cddf870c003fb0343169ca3424ff0000388bf0123034014e7b8f1070f4ff0000408bfbcf1020f40f05b8723994b4608784978cdf800b040ea0121ddf814050490ddf81005cde902202898249a01900e9801f03dfd00f01bbf26990022c80706d11eeb010003d438444845d8bf0122ac451c9607fb06f6cde917e5199240f25f81ddf810052699b0fa80f0400910438e440022c007cde91d6000bf18f805a05fea1a1101d0012418e0aceb0501012900f0168708eb050999f8010010b1022401460be00429c0f00b8799f8021099f8030051ea002100f003870424b01a814200f2fe861e98cde92145002840f08280481e0af00f0c03284fea0a1a1f9180f0878000251f99ddf8a890ddf88c8011f003046fd01544b5fbf7f01a9200fb175118440eeb010650ea060116d44e4514d2584512d22899249a00fb01207108425cf60702f00f0802f0f002624408bf48ea0a02ddf88c8042541a9a1f99012c49d0681cb0fbf7f101fb1702c8180eeb020650ea060115d44e4513d2584511d22899249a00fb01207108425cf60702f00f0802f0f002624408bf48ea0a02ddf88c8042541a9a1f99022c24d0a81cb0fbf7f101fb1702c8180eeb020450ea04011a9a1f9917d44c4515d2584513d22899249ae60700fb01204fea5401425c02f00f0502f0f002624408bf45ea0a0242541f991a9a00bfdde92105ddf894c0054465450a4480f08f841d9eb242fff447af98e021f003000025279006e000bf27980435a8424a463ff46eaf02eb0508b8fbf7f0914600fb178400eb030b74445bea040015d42a98844212d2299883450fd22898249962080bfb0010e407865c06f00f0106f0f006664408bf41ea0a06865408f10100b0fbf7f1ddf8a4b001fb1702c8180eeb020450ea040114d42a998c4211d258450fd22899249a00fb01206108425ce40702f00f0602f0f002624408bf46ea0a02425408f10200b0fbf7f101fb1702c8180eeb020450ea040114d42a998c4211d258450fd22899249a00fb01206108425ce40702f00f0602f0f002624408bf46ea0a02425408f10300b0fbf7f101fb1702c8180eeb020450ea04013ff586af2a998c42bff482af5845bff47faf2899249a00fb01206108425ce40702f00f0602f0f002624408bf46ea0a0242546de7002265454ff0000408bfb24240f0c985ddf81005002818bf012019990840012840f09a851899ddf870e027f001008c450efb00f240f0d9830120012100f0a7bd01204ff0000b0df1e0090de025998e4540f3e3820124e8e2002002e04ff0000b0120239eddf89ce031790f248f0601f00f0504eae7776f4389246743ff0a96f800c08df8b0700e277278b378f678279111f0200f08bf012705fb07f704fb07f74fead7278df8b1704ff00d0708bf022705fb07f704fb07f74fead7278df8b2704ff00c0708bf032705fb07f704fb07f74fead7278df8b3704ff00b0708bf042705fb07f704fb07f74fead7278df8b4704ff00a0708bf052705fb07f704fb07f74fead7278df8b5704ff0090708bf062705fb07f704fb07f74fead7278df8b6704ff0080708bf072705fb07f704fb07f74fead7278df8b7704ff0070708bf082705fb07f704fb07f74fead7278df8b8704ff0060708bf092705fb07f704fb07f74fead7278df8b9704ff0050708bf0a2705fb07f704fb07f74fead7278df8ba704ff0040708bf0b2705fb07f704fb07f74fead7278df8bb704ff0030708bf0c2705fb07f704fb07f74fead7278df8bc704ff0020708bf0d2705fb07f704fb07f74fead7278df8bd704ff0010708bf0e2705fb07f704fb07f74fead7278df8be704ff0000708bf0f276f436743ff0a00284ff000048df8bf7040f0ad841206300642ea0c41269a40ea034002eb2144abf101070eeb204000234ff001080890cde90aba139707e001f01f000b3801335b45044400f08f8459f82310b1f1ff3ff2dd16939f421bd009eb83004268b2f1ff3f16dc0133bb4212d08268b2f1ff3f0fdc0133bb420bd0c268b2f1ff3f08dc0133bb4204d002690133002ae2d400e00022504630ab2baf009701f026fb00283ff4a0aa2b990029189100f0b6819df8c8009df8c910ddf8a89050ea01272caa159400f098811d979df8cc709df8cd603f0447ea0667099e1d9c9df8c7009df8c61026444fea002c41ea00259df8ca0006eb2747089e9df8cb300004f41b159e40ea0360031406eb204e08eb550017900ceb0100471e1c9525461997f71801f00304f11a0ef1010314930ef102031293189b1a950133219308eb5003001b2590c8072690f8071d9fcde91e430023239008e0229b21981f990133bb420844219000f0498158192293f3d429998842f0d21c990029edd02899249b4ff0000b00fb013c1998032880f094801e981d9f1a9d0028ded0dde91710229b5feacb7403fb010327984fea5b01595c00f0100088ea101ac8b201f00f0108bf01090846002918bf012040ea0a00012815d11beb0e0012d4484510d245081cf80560515c06f00f0706f0f0060e43c00708bf47ea01161d9f0cf805601a9d1e980128a9d00bf101004008185c002cc1b24fea111108bf00f00f01c8b2002818bf012040ea0a00012816d1149810eb0b0012d4484510d245081cf80560515c06f00f0706f0f0060e43c00708bf47ea01161d9f0cf805601a9d1e9802283ff47caf0bf102004008185c002c00f00f01c3b208bf19090846002918bf012040ea0a0001287ff469af129810eb0b003ff564af4845bff461af43081cf80340515c04f00f0504f0f0040c43c00708bf45ea01141a9d0cf803404fe7219907e025980bf1040b584501f102013ff462af279811f8013c00f0100088ea101ad8b200230f2888bf012343ea0a03012b0eeb0b031ad1002b18d44b4516d25f0800091cf80760105cc1465feace7806f00f0506f0f006c846ddf8a89046ea00062caa08bf45ea00160cf8076011f8010c10f00f00054618bf012545ea0a05012d1bd15f1c19d44f4517d27d081cf80560105c6446f446c646ddf8988006f00f0747ea0017b8f1000ff046e646a44606f0f00608bf46ea0007675508780025c0b20f2888bf012545ea0a05012d16d19f1c14d44f4512d27d0800091cf80560105c1446239a06f00f0706f0f0060643002a224608bf47ea00160cf80560087810f00f00054618bf012545ea0a05012d7ff478af03333ff575af4b45bff472af5b081cf80350105c05f00f06269f46ea001605f0f005002f08bf45ea00060cf803605fe74af20d3130a8c0f24e0188479df8c4009df8c510dde90aba159c40ea01200df1e00905e09df8c4009df8c51040ea0120139f169b08e67ff4a3a82699002401449142c8bf012419023b0205fb08f2239243ea0a0241ea0c0102fb01f326995a1e00eb010a00f08d80cdf8989023f0010000214feac4791e9321901f9406e000bf2198611c8142a2f1020273d08b46b9f1000f18bf1146b1fbf8f505fb181605eb0e010aeb060451ea040025d42a98844222d2299881421fd22598dde92637284400fb0730229b249f1e440423750823ea8606289b405d01fb0371f04066088d5d00f00f0705f00f0c05f0f0053d44e40708bf4cea00158d550bf101046ff00100214680ea0b00b9f1000f239b18bf1918b1fbf8f505fb181605eb0e0c0aeb06015cea0100acd42a988142a9d229988445a6d225982844dde9263500fb0530229bf5186e08805d042323ea8505e840289b249d4e080cfb035700f00f03bd5dc90705f00f0c05f0f0052b4408bf4cea0013bb5585e7ddf89890dde91e340bf1020000e00020299ed90700f0f481e2076fea0001239a18bf5018b0fbf8f303fb180203eb0e010aeb020051ea000700f1e2812a9fb84280f0de81b14280f0db81259f3b44279f03fb0793229f3a445708db5d042727ea820223fa02f2289b249f02f00f0601fb03714308cf5cc00707f00f0507f0f007374408bf45ea0217cf54b9e11d9efff70cbc08eb01002590aceb0100239028982499229203fb00102699179a7c08114400eb510a00224ff0010b4ff0000c002700200026002124902990cde926a407e0012600272a9923980131814200f0a581002e40f0a1812598022f455c2a9100f0ed80012f76d0002f40f0ec802e0905f00f00299000f05f812298b042e0d3801b2290299800eb00150001219015e01af80200299900f0f00008440af802000132013e4ff0010ba24224bf00220cf1010cddf898a0002e00f03881f445c0d22898bbf1000f0cfb00aae1d0a01ab0eb560f88bf700850b383080aeb020819d0002708f10101a7eb83036ff0030e01eb0e040ef1040e03eb0e0919f10407e57025716571a571f2d10ef10401ddf870e0279c00e0002110f0030308d0012b08f8015004d04144022b4d7018bf8d70a6eb400602446eb1a242b6d21af80200219900f00f000843013e4ff0000b0af80200afe70026a8e7002d00f0eb802298a842fff46faf401b2290299800eb00160001219011e0b85c299900f0f0000843b8540132013d4ff0010ba24224bf00220cf1010c002d00f0ca80f445bff452af2898bbf1000f0cfb00a7e4d0a4eb020ebeeb550f88bf4fea550ebef1000f25d05fea9e0107eb020912d0002009f10104a0eb81086ff003016318043108eb01000430de701e715e719e71f5d1043100e000211ef0030309d0012b09f8016005d009eb0100022b467018bf8670a5eb4e05724485b1279cddf870e0a242b5d2b85c219900f00f000843013d4ff0000bb854002db2d17be0ddf870e0279c0025a4e7002603272495ffe6249f57ea052777d022982497b842fff4f5aec01b2290299800eb00150001219012e019f80200299900f0f000084309f802000132013f4ff0010ba24224bf00220cf1010c002f4ed0f445bff4d7ae2898bbf1000f0cfb00a9e3d0a01ab0eb570f88bf780848b3830809eb020818d0002608f10101a6eb83036ff0030e01eb0e040ef1040e03eb0e060436e57025716571a571f3d10ef10401ddf870e0279c00e0002110f0030308d0012b08f8015004d04144022b4d7018bf8d70a7eb400702447fb1a242b9d219f80200219900f00f000843013f4ff0000b09f80200002fb3d101e00027a9e70027002689e60026022786e60026012783e600200126002724907ee6ddf8100578b1002038902698289903902498239f4a465b46cde901ca009700f070fb044600e000241cbb209a11980f9902440d98013181424ff0000428bf0124209217d20f911b99891a01293ef65aaa10e00126b7fa87f0229a86f00101400900284ff0000418bf002903d0002adcd000e000241b99209a511a18bf012161ea040000f0010040420df2dc4dbde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe791429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f93b0054600284ff0ff3000f02c821d9f072f40f02882cde90651cde90823faf755fd002800f004814ef66c674ff29c594ff6904a48f2a355ccf2ff07c2f229094ff6ff7bcff6ff7a4ff000080124c0f2450502e0bff32f8fa847d9f80060bff35f8fd9f80000bff35f8f01466ff39601b1f1005f03d10168b94200f0ab804ff45c70fbf759fc002800f0d280514600bf4218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed107608472a0f81cb0a0f81eb0a0f820b0a0f822b0a0f824b0a0f826b0a0f828b0a0f82ab0a0f82cb0a0f82eb0a0f830b0a0f832b0a0f834b0a0f836b0a0f838b0a0f83ab059e8001fb1427ff44aafbff35f8f49e8000121b159e8001fb142f8d03fe7d0f86c111c9d00294ff0ff3000f041816a78012a00f23d81287840ea022751f82700d8b1431a98074ff0ff3040f031816ff4403240f60f061a44cff6fd76b242c0f02781ca1852f8080cb84206d152f80c1ca1f1011010f5803f04d24ff0ff3013b0bde8f08f002a4ff0ff3000f0118152f8047c8f4240f00c81c3f54033994200f207810df138081046002243460024fff756fe0028e1d0e978a878090641ea00401f996b792a7901eb2047a8794fea036b4bea024982060f2300f00f0103eae27202fb01f389225343db0a8df828300e2310f0200f08bf0f2408bf012301fb03f302fb03f34fead3238df829304ff00d0308bf022301fb03f302fb03f34fead3238df82a304ff00c0308bf032301fb03f302fb03f34fead3238df82b304ff00b0308bf042301fb03f302fb03f34fead3238df82c304ff00a0308bf052301fb03f302fb03f34fead3238df82d304ff0090308bf062301fb03f302fb03f34fead3238df82e304ff0080308bf072301fb03f302fb03f34fead3238df82f304ff0070308bf082301fb03f302fb03f34fead3238df830304ff0060308bf092301fb03f302fb03f34fead3238df831304ff0050308bf0a2301fb03f302fb03f34fead3238df832304ff0040308bf0b2301fb03f302fb03f34fead3238df833304ff0030308bf0c2301fb03f302fb03f34fead3238df834304ff0020308bf0d2301fb03f302fb03f34fead3238df835304ff0010308bf0e234b4361435143c0f300105343c90a04900aa806ac099ddb0a8df83710039013cc4fea29468df8363022462b46cde90168009700f01cfcdde91001c21901eb2941a24227eae770b8bf1446a942b8bf0d46844212dd26eaeb718d420edd1e9a12680f2a0ad86b1a1e9d271a05ebc206f080501c31817781b3812860002013b0bde8f08f2de9f04f99b0824600284ff0ff3000f0a382239c082cc0f09f820f4616461d46faf71efb002800f01581229ad17901f10800844240f00e81cde90a171078577891794ef66c684ff29c5bcde90c6540ea0720ccf2ff08c2f2290b4ff6ff79002601250f910e9006e048f2a351c0f24501bff32f8f8847dbf80040bff35f8fdbf80000bff35f8f01466ff39601b1f1005f03d10168414500f0af804ff45c70fbf715fa002800f0d6804ff69041cff6ff714218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800808572a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a905be8001fa1427ff443afbff35f8f00bf4be8000121b15be8001fa142f8d037e7d0f86c21ddf888e00f9d002a4ff0ff3000f0a681012f00f2a3810e9852f82000e0b1811a88074ff0ff3040f099816ff4403340f60f060b44cff6fd76b342c0f08f81571857f8080c0e9a904206d157f80cbcabf1011010f5803f04d24ff0ff3019b0bde8f08f57f8040c58454ff0ff3040f07681c1f540318b4500f27181002f00f06e81bbf1c10fc0f06a8138780128e4d1a8060f2405f00f0604eae070704389246043c00a8df854000e209ef802809ef803209ef804c09ef8053015f0200f08bf012006fb00f004fb00f04fead0208df855004ff00d0008bf022006fb00f004fb00f04fead0208df856004ff00c0008bf032006fb00f004fb00f04fead0208df857004ff00b0008bf042006fb00f004fb00f04fead0208df858004ff00a0008bf052006fb00f004fb00f04fead0208df859004ff0090008bf062006fb00f004fb00f04fead0208df85a004ff0080008bf072006fb00f004fb00f04fead0208df85b004ff0070008bf082006fb00f004fb00f04fead0208df85c004ff0060008bf092006fb00f004fb00f04fead0208df85d004ff0050008bf0a2006fb00f004fb00f04fead0208df85e004ff0040008bf0b2006fb00f004fb00f04fead0208df85f004ff0030008bf0c2006fb00f004fb00f04fead0208df860004ff0020008bf0d2006fb00f004fb00f04fead0208df861004ff0010008bf0e2006fb00f004fb00f04fead0204ff000018df8620008bf0f2171430a9e61430020c90a002e8df8631000f09c801006259940ea084001eb2048180640ea0c400ef1080900140e90c5f30010a7f13f044d46099001e0013e1ad015f8010b411e1f29f8d341b22029fff6fbae04eb400114f81000497840ea0122c12afff4f1ae3846594610abfff716fb0028e3d1e8e60e980a9d20eae07008902498cde9064b0630059004e040440b38013d804659d019f8010b1f28f6d904eb400114f81000497810ac40ea0122c12acdf83c90fff4c8ae384659462346fff7edfa00283ff4c0ae0998dde90b1b0d9e049015a8ddf83890cde9024050465a463346cdf80490cdf8008000f079f9dde91201404401eb0902584528eae871b8bf8346b242a8bf32468b4519dd089eb24216dd249e34680f2c12d8ddf820c0abeb0103a2eb0c0e059a02ebc40622f83410249a611ca6f802c0b380a6f806e01160ddf83c90dde9064ba2e7002019b0bde8f08f00bf2de9f04f87b0149d6c68072c77d824b12f89b94273d0012c6ed1d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fdf7b6fb69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff486afaf89b942f4d0032c3ff480afef89b942eed0042c3ff47aaf2f8ab942e8d0052c3ff474af6f8ab942e2d0062c3ff46eafaf8ab9427ff46aafdae72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f87b00591dde91171ddf84cc00c692cb10c68844200f0948100259ee14f68002f00f0fc8100260021069609e0dde90361daf804703144ddf84cc0b94280f0ee81ddf848a00491daf80040655c2e0901d0012113e07f1a012f00f0e0810c4466780eb102210ae0042fc0f0d881a778e47857ea042600f0d281042100bf0391149915f00f04b1fa81f54fea55151cf804c018bf0124069945ea040e029616f00304ddf81490119e4fea0c188b4600f092800194daf80840b1fbf4f505fb1414109967180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990129069901f1010b5fd0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990229069901f1020b2ed0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050194fc07644604bf0f254446019f3d402c4301f80b40069901f1030b00bf029d6c1e032c2944069107d224e700bf06990bf1040b59453ff41eafdaf808401099bbfbf4f5002705fb14b40c44b4f1ff3fc8bf012707ea0e07012f1ad1ad1918d4944216d29d4214d205fb09056708e40715f807906ff00f04e24604bf0f24c24604ea0904ddf8149044ea0a04ddf848a0ec55daf808400bf10107b7fbf4f505fb147400270c44b4f1ff3fc8bf012707ea0e07012f14d1ad1912d4944210d29d420ed205fb09056708e407ee5d6ff00f04614604bf0f2441463440119e2143e955daf808100bf10204b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e01012914d1ad1912d4944210d29d420ed205fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c55daf808100bf10304b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e0101297ff46bafad193ff568af9442bff465af9d42bff462af05fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c5551e7002f01dd012508e0b7fa87f4109f00256409002fc8bf01252540d1f80880c96801fb08f9b9f1000f58d08e4614994ff0000ab1fa81f461094ff0ff3b0491e907069107e00af1010a0efb08f9ca45abf1010b43d2069954460029129918bf09eb0b04b4fbf8f50e6808f1010705fb18447f0805fb07666708f65d042121ea8407fe4016f00f094e4618bf012604990e43012ed7d1109964185cbf119915eb0105d0d49442ced29d42ccd20599660805fb01081cf8095018f80670129907f00f0907f0f0072f43e40708bf49ea051708f80670d1f80880d1f80ce0b3e707b0bde8f08f00bfb0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f3f753f906f1210506f1280029460722f3f74bf9284621460722f3f746f920465146032207f10905f3f73ff906f11d0049460422f3f739f9f07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f3f70df9a81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f059e60846fcf71fbf00bf2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f3f7c5f8012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f3f7acf8572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f3f795f8312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f3f77ff8462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f3f768f8362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f67320c0f20000784410f80b0041f66d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f7fdffcde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f7deff8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f7dffe284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f78bfe002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f759fe04a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f745fe0020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f72efe352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f70afe04a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f7f7fd002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f7e3fd04a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f7bffd04f14f0051460722f2f7b9fd84f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f26a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2f241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f72bfd84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f2f741fc284641462246c84703b0bde8f08370b50446d0f83c0142f665360d46c0f2440668b948f6e150cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3236000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "04403a00", + "new": "dc443a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "84403a00", + "new": "5c453a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "04403a04", + "new": "dc443a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "4c01635d", + "new": "fe2d93a9", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "155cd97f", + "new": "13f7ac84", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "155cd97f", + "new": "13f7ac84", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/graphics/glyph-wire.ts b/app/graphics/glyph-wire.ts index 970fe821..bfd1c5bd 100644 --- a/app/graphics/glyph-wire.ts +++ b/app/graphics/glyph-wire.ts @@ -1,3 +1,4 @@ +import { encodePresentation } from "./presentation-wire"; /** * Marshals deferred-draw identity (text glyphs and icon images) to the Kotlin * side for the texture-cache pipeline (CFW modes 18/19/20; see @@ -84,6 +85,7 @@ const fwRegistered = new Set(); * unseen ink members' rasters with the Kotlin FwGlyphAtlas as a side effect. */ function prepareFwTextRun(placed: PlacedFwText): boolean { + if (!textureAtlasAvailable()) return false; if (!inRange16(placed.x) || !inRange16(placed.y)) return false; if (placed.glyphs.length === 0 || placed.glyphs.length > 255) return false; let registration: Array<{ cp: number; data: NonNullable> }> | null = null; @@ -152,7 +154,7 @@ function inRange16(v: number): boolean { * in draw order. Returns null when nothing is expressible (or without a native atlas). */ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | null { - if (!textureAtlasAvailable() || draws.length === 0) return null; + if (draws.length === 0) return null; // Pass 1: resolve ids, register unseen rasters, size the buffer. let registration: Map | null = null; @@ -175,7 +177,8 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | (placed.glyph.coverage ? group.aaGlyphs : group.glyphs).push(placed.glyph); } else if (placed.kind === "image") { if (!inRange16(placed.x) || !inRange16(placed.y)) continue; - if (imageId(placed) !== null) bytes += IMAGE_RECORD_BYTES; + if (placed.presentation) bytes += encodePresentation(placed).length; + else if (imageId(placed) !== null) bytes += IMAGE_RECORD_BYTES; } else { const ok = prepareFwTextRun(placed); fwRunOk.set(placed, ok); @@ -207,6 +210,7 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | offset += GLYPH_RECORD_BYTES; } else if (placed.kind === "image") { if (!inRange16(placed.x) || !inRange16(placed.y)) continue; + if (placed.presentation) { const bytes = encodePresentation(placed); new Uint8Array(out.buffer).set(bytes, offset); offset += bytes.length; continue; } const id = imageId(placed); if (id === null) continue; out.setUint8(offset, 1); diff --git a/app/graphics/image.ts b/app/graphics/image.ts index 70028f61..bb725293 100644 --- a/app/graphics/image.ts +++ b/app/graphics/image.ts @@ -73,6 +73,7 @@ export type PlacedGlyph = { * from the moment it is placed. */ export type PlacedImage = { + presentation?: { mode?: "image" | "masked-image"; radius: number; background: number; border: number; depth: number; occlusions?: readonly { x: number; y: number; width: number; height: number }[] }; kind: "image"; source: GrayImage; x: number; @@ -391,6 +392,7 @@ export class GrayImage { hash = mixInt(hash, placed.source.width); hash = mixInt(hash, placed.source.height); hash = mixInt(hash, placed.source.sourceContentHash32()); + if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0]) hash = mixInt(hash, value); } } else { hash = mixInt(hash, 0xf17e); hash = mixInt(hash, placed.font.atlasTag); @@ -501,6 +503,24 @@ export class GrayImage { this.drawList.push({ kind: "fwtext", font, x, y, value: clampByte(value), glyphs }); } + /** Retain the selected row separately from the menu surface for glasses-side composition. */ + drawMenuSelection(source: GrayImage, x: number, y: number, background: number, border: number, radius = 8, depth = 2): void { + this.drawList.push({ kind: "image", source: source.withDrawsBaked(), x, y, + presentation: { radius, background, border, depth } }); + } + + /** Replay an image at stereo depth. Masked images preserve intentional gray8 black (1). */ + drawDepthImage(source: GrayImage, x: number, y: number, depth: number, masked = false): void { + this.drawList.push({ kind: "image", source: source.withDrawsBaked(), x, y, + presentation: { mode: masked ? "masked-image" : "image", radius: 0, background: 0, border: 0, depth } }); + } + + copyPresentationsInto(target: GrayImage, dx: number, dy: number): void { + for (const placed of this.drawList) if (placed.kind === "image" && placed.presentation) { + target.drawList.push({ ...placed, x: placed.x + dx, y: placed.y + dy }); + } + } + /** * Bake this image's deferred draws into its own pixels and clear the list. * Used where later raster must be able to cover earlier draws within the @@ -513,7 +533,8 @@ export class GrayImage { if (placed.kind === "glyph") { rasterizeGlyph(this, placed.font, placed.glyph, placed.x, placed.y, placed.value); } else if (placed.kind === "image") { - this.bitBlt(placed.source, placed.x, placed.y, { transparentZero: true }); + if (placed.presentation) { const one = new GrayImage(this.width, this.height); one.drawList.push(placed); one.bakeDrawsInto(this, 0, 0); } + else this.bitBlt(placed.source, placed.x, placed.y, { transparentZero: true }); } else { placed.font.bakeFwTextRun(this, placed, 0, 0); } @@ -534,7 +555,7 @@ export class GrayImage { const copy = new GrayImage(this.width, this.height, 0); copy.pixels.set(this.pixels); for (const placed of this.drawList) { - if (placed.kind === "image") { + if (placed.kind === "image" && !placed.presentation) { copy.bitBlt(placed.source, placed.x, placed.y, { transparentZero: true }); } } @@ -544,7 +565,10 @@ export class GrayImage { if (value !== 0) pixels[i] = dimValue(value, scale); } for (const placed of this.drawList) { - if (placed.kind !== "image") { + if (placed.kind === "image" && placed.presentation) { + const p = placed.presentation; + copy.drawList.push({ ...placed, source: placed.source.dimmed(factor), presentation: { ...p, background: dimValue(p.background, scale), border: dimValue(p.border, scale) } }); + } else if (placed.kind !== "image") { copy.drawList.push({ ...placed, value: dimValue(placed.value, scale) }); } } @@ -556,11 +580,11 @@ export class GrayImage { * Returns this image unchanged when there are none, otherwise a baked copy * with an empty draw list. */ - withDrawsBaked(): GrayImage { + withDrawsBaked(presentations = true): GrayImage { if (!this.drawList.length) return this; const baked = new GrayImage(this.width, this.height, 0); baked.pixels.set(this.pixels); - this.bakeDrawsInto(baked, 0, 0); + this.bakeDrawsInto(baked, 0, 0, presentations); return baked; } @@ -579,11 +603,28 @@ export class GrayImage { } /** Rasterize this image's deferred draws into target, translated by (dx, dy). */ - bakeDrawsInto(target: GrayImage, dx: number, dy: number): void { + bakeDrawsInto(target: GrayImage, dx: number, dy: number, presentations = true): void { for (const placed of this.drawList) { if (placed.kind === "glyph") { rasterizeGlyph(target, placed.font, placed.glyph, placed.x + dx, placed.y + dy, placed.value); } else if (placed.kind === "image") { + if (placed.presentation) { + if (!presentations) continue; + if (placed.presentation.mode) { + target.bitBlt(placed.source, placed.x + dx, placed.y + dy, { transparentZero: true }); + continue; + } + const { radius, background, border } = placed.presentation; + const fill = new GrayImage(placed.source.width, placed.source.height); + fill.fillRoundedRect(0, 0, fill.width, fill.height, background, radius); + for (let y = 0; y < fill.height; y++) for (let x = 0; x < fill.width; x++) { + const tx = placed.x + dx + x, ty = placed.y + dy + y; + if (tx >= 0 && ty >= 0 && tx < target.width && ty < target.height) { + const i = ty * target.width + tx; target.pixels[i] = Math.max(target.pixels[i], fill.pixels[y * fill.width + x]); + } + } + target.drawRoundedRect(placed.x + dx, placed.y + dy, fill.width, fill.height, border, radius); + } target.bitBlt(placed.source, placed.x + dx, placed.y + dy, { transparentZero: true }); } else { placed.font.bakeFwTextRun(target, placed, dx, dy); diff --git a/app/graphics/plane.ts b/app/graphics/plane.ts index d7527b32..f644fee8 100644 --- a/app/graphics/plane.ts +++ b/app/graphics/plane.ts @@ -1,4 +1,4 @@ -import { GrayImage, type DeferredDraw } from "./image"; +import { GrayImage, type DeferredDraw, type PlacedImage } from "./image"; /** * The unit apps (and the shell) submit to the compositor: instead of one @@ -8,20 +8,17 @@ import { GrayImage, type DeferredDraw } from "./image"; * transparent, 1 is black (the two quantize to the same 4bpp shade, so * reserving 0 costs nothing visible). * - * This representation exists to carry structure the wire pipeline will later - * exploit: a plane's glyph list can become on-glasses display-list references - * (texture cache), and the offset can diverge per lens for stereo depth. For - * now the compositor boundary just flattens (flattenPlanes) and feeds the - * existing incremental-update and screen-preview pipeline. + * Static planes form the incremental screen buffer. Planes with stereo depth + * and retained presentation draws replay from resources in the root display list. */ export type Plane = { shellKey?: number; + depth?: number; dimUnderneath?: number; image: GrayImage; /** * Offset of the plane's top-left within the submitted frame. Applied - * identically to both lenses for now; a per-lens divergence (stereo depth - * for floating overlays) is the planned extension. + * before any per-lens horizontal offset from depth. */ x: number; y: number; @@ -72,8 +69,9 @@ export function flattenPlanes( /** * Flatten planes and also return the frame's deferred draws (glyphs and * images), translated into frame coordinates and in bake order (plane order, - * then each image's draw order). The flattened image has every draw baked in, - * exactly as flattenPlanes produces; the list preserves the draws' identity + * then each image's draw order). Regular draws are baked into the image; + * selected-menu presentation records remain unbaked for root-list replay. + * The list preserves the draws' identity * so the texture-cache pipeline can replay them as on-glasses cached draws * (see graphics/glyph-wire.ts). */ @@ -81,15 +79,54 @@ export function flattenPlanesWithDraws( planes: readonly Plane[], size?: { width: number; height: number }, ): { image: GrayImage; draws: DeferredDraw[] } { - const image = flattenPlanes(planes, size); + const rasters = planes.map(p => p.image.withDrawsBaked(false)); + const image = flattenPlanes(planes.map((plane, i) => ({ ...plane, image: plane.depth ? new GrayImage(plane.image.width, plane.image.height) : rasters[i]! })), size); const draws: DeferredDraw[] = []; - for (const plane of planes) { - for (const placed of plane.image.draws) { - draws.push( - plane.x === 0 && plane.y === 0 - ? placed - : { ...placed, x: placed.x + plane.x, y: placed.y + plane.y }, - ); + for (const [index, plane] of planes.entries()) { + const retained: DeferredDraw[] = []; + if (plane.depth) { + // Keep the whole menu off the screen buffer, including its black background. + const raster = rasters[index]!; + let left = raster.width, top = raster.height, right = -1, bottom = -1; + for (let y = 0; y < raster.height; y++) for (let x = 0; x < raster.width; x++) if (raster.pixels[y*raster.width+x]) { + left = Math.min(left,x); top = Math.min(top,y); right = Math.max(right,x); bottom = Math.max(bottom,y); + } + if (right >= left) { + const crop = new GrayImage(right-left+1,bottom-top+1); + for(let y=0;y d.kind === "image" && d.presentation).map(d => { + const draw = d as PlacedImage; + return { ...draw, presentation: { ...draw.presentation!, depth: draw.presentation!.depth + plane.depth! } }; + })] : plane.image.draws; + for (const placed of planeDraws) { + const translated = { ...placed, x: placed.x + plane.x, y: placed.y + plane.y }; + if (translated.kind === "image" && translated.presentation) { + // Restore opaque pixels from later planes after replaying this row. The screen + // already contains those pixels; rect copies preserve rounded/irregular occlusion. + const occlusions: { x: number; y: number; width: number; height: number }[] = []; + const depth = translated.presentation.depth; + const leftShift = Math.floor(depth / 2), rightShift = -Math.floor((depth + 1) / 2); + const left = Math.max(0, translated.x + Math.min(leftShift, rightShift)); + const right = Math.min(image.width, translated.x + translated.source.width + Math.max(leftShift, rightShift)); + for (let y = Math.max(0, translated.y); y < Math.min(image.height, translated.y + translated.source.height); y++) { + let start = -1; + for (let x = left; x <= right; x++) { + const covered = x < right && planes.some((p, i) => i > index && !p.depth && x >= p.x && y >= p.y && x < p.x + p.image.width && y < p.y + p.image.height && rasters[i]!.pixels[(y-p.y)*p.image.width+x-p.x] !== 0); + if (covered && start < 0) start = x; + if (!covered && start >= 0) { + const previous = occlusions.find(r => r.x === start && r.width === x - start && r.y + r.height === y); + if (previous) previous.height++; else occlusions.push({ x: start, y, width: x-start, height: 1 }); + start = -1; + } + } + } + translated.presentation = { ...translated.presentation, occlusions }; + } + draws.push(translated); } } return { image, draws }; @@ -102,6 +139,6 @@ export function flattenPlanesWithDraws( */ export function planesFingerprint(planes: readonly Plane[]): string { return planes - .map((plane) => `${plane.x},${plane.y}+${plane.image.width}x${plane.image.height}:${plane.image.fingerprint()}`) + .map((plane) => `${plane.depth ?? 0}:${plane.x},${plane.y}+${plane.image.width}x${plane.image.height}:${plane.image.fingerprint()}`) .join("|"); } diff --git a/app/graphics/presentation-wire.ts b/app/graphics/presentation-wire.ts new file mode 100644 index 00000000..0524cc8c --- /dev/null +++ b/app/graphics/presentation-wire.ts @@ -0,0 +1,64 @@ +import type { PlacedImage } from './image' + +/** Bridge record: tag 3 (selection), 4 (image), 5 (gray8-masked image), signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, gray pixels, restore rectangles. */ +export function encodePresentation(draw: PlacedImage): Uint8Array { + const p = draw.presentation! + const { width, height, pixels } = draw.source + if (width < 1 || height < 1 || width > 640 || height > 480 || 5 + Math.ceil(width / 2) * height > 65536) throw new Error('Presentation image exceeds the resource size limit') + if (!Number.isInteger(p.depth) || p.depth < -128 || p.depth > 127) throw new Error('Invalid menu depth') + if ((p.occlusions?.length ?? 0) > 2048) throw new Error('Too many menu occlusion rectangles') + const bytes = new Uint8Array(16 + width * height + (p.occlusions?.length ?? 0) * 8), view = new DataView(bytes.buffer) + bytes[0] = p.mode === "image" ? 4 : p.mode === "masked-image" ? 5 : 3 + view.setInt16(1, draw.x, true); view.setInt16(3, draw.y, true) + view.setUint16(5, width, true); view.setUint16(7, height, true); view.setUint16(9, p.radius, true) + bytes[11] = p.background; bytes[12] = p.border; view.setInt8(13, p.depth) + view.setUint16(14, p.occlusions?.length ?? 0, true) + bytes.set(pixels, 16) + let offset = 16 + pixels.length + for (const rect of p.occlusions ?? []) { + view.setUint16(offset, rect.x, true); view.setUint16(offset + 2, rect.y, true) + view.setUint16(offset + 4, rect.width, true); view.setUint16(offset + 6, rect.height, true); offset += 8 + } + return bytes +} + +export type Selection = { mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } +export function readPresentation(bytes: Uint8Array, offset: number): { selection: Selection; end: number } { + const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), w = v.getUint16(offset + 5, true), h = v.getUint16(offset + 7, true) + const selection: Selection = { mode: bytes[offset] === 4 ? "image" : bytes[offset] === 5 ? "masked-image" : undefined, x: v.getInt16(offset+1,true), y: v.getInt16(offset+3,true), width:w, height:h, + radius:v.getUint16(offset+9,true), background:bytes[offset+11]!, border:bytes[offset+12]!, depth:v.getInt8(offset+13), + pixels:bytes.slice(offset+16,offset+16+w*h), occlusions:[] } + let end=offset+16+w*h + for(let i=0;iMath.min(15,(n+8)>>4), shift=right?-Math.floor((row.depth+1)/2):Math.floor(row.depth/2) + const inside=(x:number,y:number,w:number,h:number,r:number)=>{ + if(x<0||y<0||x>=w||y>=h) return false + r=Math.min(r,Math.floor(w/2),Math.floor(h/2)) + const dx=Math.max(0,2*r-(2*Math.min(x,w-1-x)+1)),dy=Math.max(0,2*r-(2*Math.min(y,h-1-y)+1)) + return dx*dx+dy*dy<=4*r*r + } + for(let yy=0;yy=width||y>=height) continue + const i=y*width+x + if(!row.mode && inside(xx,yy,row.width,row.height,row.radius)) output[i]=!inside(xx-1,yy-1,row.width-2,row.height-2,Math.max(0,row.radius-1))?q(row.border)*16:Math.max(output[i]!,q(row.background)*16) + const value=q(row.pixels[yy*row.width+xx]!) + if(row.mode === "masked-image" ? row.pixels[yy*row.width+xx] !== 0 : value !== 0) output[i]=value*16 + } + for(const r of row.occlusions) for(let yy=r.y;yy=0&&yy>=0&&xx 65536) throw new Error(`Shell surface ${plane.shellKey} exceeds 64 KiB (${w}×${h})`) const cropped = shellCrop(image, left, top, w, h, plane.shellKey!) - layers.push({ image: cropped.image, x: plane.x + left, y: plane.y + top, key: plane.shellKey!, dim: Math.round((plane.dimUnderneath ?? 1) * 256) }) + const selections = plane.image.draws + .filter((d): d is PlacedImage => d.kind === "image" && !!d.presentation) + .map(d => encodePresentation({ ...d, x: d.x + plane.x, y: d.y + plane.y, + presentation: { ...d.presentation!, depth: d.presentation!.depth + (plane.depth ?? 0) } })) + layers.push({ depth: plane.depth ?? 0, selections, image: cropped.image, x: plane.x + left, y: plane.y + top, key: plane.shellKey!, dim: Math.round((plane.dimUnderneath ?? 1) * 256) }) } - const result = new Uint8Array(2 + layers.reduce((n, l) => n + 14 + l.image.pixels.length, 0)) + const result = new Uint8Array(2 + layers.reduce((n, l) => n + 16 + l.image.pixels.length + l.selections.reduce((n, b) => n + b.length, 0), 0)) const view = new DataView(result.buffer); let p = 0 const word = (n: number) => { view.setUint16(p, n, true); p += 2 } word(layers.length) - for (const l of layers) { word(l.key); word(l.x); word(l.y); word(l.image.width); word(l.image.height); word(l.dim); word(0); result.set(l.image.pixels, p); p += l.image.pixels.length } + for (const l of layers) { word(l.key); word(l.x); word(l.y); word(l.image.width); word(l.image.height); word(l.dim); word(l.selections.length); word(l.depth); result.set(l.image.pixels, p); p += l.image.pixels.length; for (const selection of l.selections) { result.set(selection, p); p += selection.length } } return result } diff --git a/app/graphics/surface-compositor.ts b/app/graphics/surface-compositor.ts index e63afba4..769deb36 100644 --- a/app/graphics/surface-compositor.ts +++ b/app/graphics/surface-compositor.ts @@ -1,3 +1,4 @@ +import { presentationRecords, readPresentation, paintPresentation, type Selection } from "./presentation-wire" /** Platform-independent 8bpp surface composition for the local display. */ import type { TextureFrame } from '../g2/texture-planner' export type SurfaceRect = { x: number; y: number; width: number; height: number } @@ -5,7 +6,7 @@ export type SurfaceConfiguration = SurfaceRect & { zOrder: number transparency: 'opaque' | 'color-key' } -type Surface = SurfaceConfiguration & { pixels: Uint8Array; visible: boolean } +type Surface = SurfaceConfiguration & { pixels: Uint8Array; visible: boolean; selections: Selection[] } export class SurfaceCompositor { private readonly surfaces = new Map() @@ -25,7 +26,7 @@ export class SurfaceCompositor { const previous = this.surfaces.get(id) const pixels = previous?.width === options.width && previous.height === options.height ? previous.pixels : new Uint8Array(options.width * options.height) - this.surfaces.set(id, { ...options, pixels, visible: previous?.visible ?? true }) + this.surfaces.set(id, { ...options, pixels, visible: previous?.visible ?? true, selections: previous?.selections ?? [] }) } removeSurface(id: string): void { this.surfaces.delete(id) } setSurfaceVisible(id: string, visible: boolean): void { @@ -45,6 +46,7 @@ export class SurfaceCompositor { || rect.width <= 0 || rect.height <= 0 || pixels.length !== rect.width * rect.height) { throw new Error('Invalid frame buffer or rectangle') } + surface.selections = presentationRecords(_draws) const left = Math.max(0, rect.x), right = Math.min(surface.width, rect.x + rect.width) const top = Math.max(0, rect.y), bottom = Math.min(surface.height, rect.y + rect.height) for (let y = top; y < bottom; y++) { @@ -74,19 +76,25 @@ export class SurfaceCompositor { } } } + const screen = output.slice() + if (!surfaces.some(s => s.zOrder > 1) && (this.shellScene || surfaces.some(s => s.selections.length))) { + for(let i=0;i>4)*16 + for(const surface of surfaces) for(const row of surface.selections) paintPresentation(output,screen,this.width,this.height,{...row,x:row.x+surface.x,y:row.y+surface.y,occlusions:row.occlusions.map(r=>({...r,x:r.x+surface.x,y:r.y+surface.y}))}) + } if (this.shellScene && !surfaces.some(s => s.zOrder > 1)) { const quantize = (v: number) => Math.min(15, (v + 8) >> 4) for (let i=0;i=0 && y+yy>=0 && x+xx=0 && y+yy>=0 && x+xx+shift p === 0), 'blanking') const textures = new IosTexturePlanner(), textured = new SurfaceCompositor(4, 2) @@ -46,6 +48,14 @@ export function runKotlinProtocolSmokeTest(): void { assert(textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length === 0, 'texture reuse') textures.reset() assert((textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length ?? 0) > 0, 'texture reset') + const selectedSurface = new GrayImage(8, 4, 1) + selectedSurface.drawMenuSelection(new GrayImage(4, 2, 255), 1, 1, 16, 48, 0, 2) + const selectedPreview = new SurfaceCompositor(8, 4) + selectedPreview.setShellScene(encodeShellScene([{ image: selectedSurface, x: 0, y: 0, shellKey: 100 }])) + const selectedSnapshot = selectedPreview.compositeFrame() + assert(selectedSnapshot.pixels[10] === 240 && selectedSnapshot.pixels[9] === 0, 'menu selection depth and bridge') + const selectedPlan = new IosTexturePlanner().plan(null, protocol.packGray4(selectedSnapshot.pixels, 8, 4), selectedSnapshot.textures, 1) + assert(!!selectedPlan && selectedPlan.payload[0] === 28 && selectedPlan.resourceCommands.some(c => c[0] === 29), 'menu resource planning') const changed = new Uint8Array(16); changed[0] = 255 assert(buildBoundingBoxPayload(new Uint8Array(16), changed, 8, 4, 1)?.[0] === 3, 'image update') assert(lvglMetrics('/nonexistent/faceclaw-font').length === 0, 'font bridge') diff --git a/app/ui/layers.ts b/app/ui/layers.ts index 36bbf3a9..25272ca5 100644 --- a/app/ui/layers.ts +++ b/app/ui/layers.ts @@ -80,6 +80,7 @@ export interface LayerContext { } export interface Layer { + readonly depth?: number; paintParts?(): Plane[]; readonly paintOverBase?: boolean; /** @@ -284,7 +285,7 @@ export class LayerStack { return canvas; }), ); - const ownPlane: Plane = { image, x: 0, y: 0, shellKey: key, dimUnderneath: layer.dimUnderneath === false ? 1 : layer.dimUnderneath }; + const ownPlane: Plane = { image, x: 0, y: 0, shellKey: key, depth: layer.depth, dimUnderneath: layer.dimUnderneath === false ? 1 : layer.dimUnderneath }; if (index <= 0) { this.lastBaseDim = dimSoFar; return [ownPlane]; diff --git a/app/ui/menu.ts b/app/ui/menu.ts index 04b8b1fd..812e1ded 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -19,6 +19,8 @@ const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15; const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45; export type MenuLayout = { + /** Stereo depth of the menu surface; selected rows add +2. */ + depth?: number; /** Left edge, or "center" to center horizontally on the painted surface. */ x: number | "center"; y: number; @@ -192,6 +194,8 @@ export class MenuLayer implements Layer { private selectedIndex = 0; private scrollRow = 0; + get depth(): number { return this.layout.depth ?? 0; } + get dimUnderneath(): false | number { return this.layout.dimUnderneath ?? false; } @@ -227,7 +231,7 @@ export class MenuLayer implements Layer { const maxHeight = Math.min( this.layout.maxHeight ?? image.height - y - DEFAULT_MENU_Y, image.height - y, - this.layout.squareCorners ? Math.floor(65530 / Math.ceil(width / 2)) : Infinity, + (this.layout.squareCorners || this.depth !== 0) ? Math.floor(65530 / Math.ceil(width / 2)) : Infinity, ); const footerHeight = this.layout.footer ? MENU_FOOTER_GAP + lineStep(font) : 0; const contentHeight = chromeTop + this.items.length * rowHeight + footerHeight + MENU_BODY_PADDING; @@ -266,22 +270,14 @@ export class MenuLayer implements Layer { const rowY = bodyY + (index - this.scrollRow) * rowHeight; const selected = index === this.selectedIndex; const disabled = isMenuItemDisabled(item); - if (selected) { - drawSelectionHighlight( - image, - x + 12, - rowY, - width - 24, - rowHeight - 1, - focused, - 8, - ); - } + const row = selected ? new GrayImage(width - 24, rowHeight - 1, 0) : image; + const textX = selected ? 10 : x + 22; + const textY = selected ? 0 : rowY; if (item.render) { item.render({ - image, - x: x + 22, - y: rowY, + image: row, + x: textX, + y: textY, width: width - 44, height: rowHeight - 3, selected, @@ -290,8 +286,9 @@ export class MenuLayer implements Layer { ctx, }); } else { - image.drawText(font, x + 22, rowY + LIST_ROW_TEXT_INSET, item.label, disabled ? 70 : selected ? 255 : 200); + row.drawText(font, textX, textY + LIST_ROW_TEXT_INSET, item.label, disabled ? 70 : selected ? 255 : 200); } + if (selected) image.drawMenuSelection(row, x + 12, rowY, focused ? MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL : 0, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE, 8, 2); } if (this.items.length > visibleRowCount) { diff --git a/app/ui/shell/chrome-layer.ts b/app/ui/shell/chrome-layer.ts index 88a216c5..8dbc8364 100644 --- a/app/ui/shell/chrome-layer.ts +++ b/app/ui/shell/chrome-layer.ts @@ -228,7 +228,7 @@ export class ShellChromeLayer implements Layer { const canvas = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); this.drawTopBar(canvas, state); const left = sidebarStripVisible(state.focus, state.foregroundAppId) ? SIDEBAR_WIDTH : 0; - parts.push(shellCrop(canvas, left, windowTop(state.foregroundHeightMode, state.foregroundAppId), G2_LENS_WIDTH-left, TOP_BAR_HEIGHT, 2)); + parts.push({ ...shellCrop(canvas, left, windowTop(state.foregroundHeightMode, state.foregroundAppId), G2_LENS_WIDTH-left, TOP_BAR_HEIGHT, 2), depth: -2 }); drawAmbientCards(canvas, parts); return parts; } @@ -288,14 +288,16 @@ export class ShellChromeLayer implements Layer { // the icon drawn inverted. Only the right column touches the separator; // a selected overflow icon gets a self-contained box instead. const sep = SIDEBAR_WIDTH - 1; + // Start beside the app content, leaving the area alongside the top bar open. + const sepTop = Math.max(bandTop, windowTop(state.foregroundHeightMode, state.foregroundAppId) + TOP_BAR_HEIGHT); const selVisible = state.selectedIndex >= this.scrollRow && state.selectedIndex < lastVisible; const selSlot = selVisible ? slotOf(state.selectedIndex) : null; const selTabTop = selSlot && selSlot.column === firstColumn ? selSlot.y - 2 : null; if (selTabTop !== null) { - image.drawLine(sep, bandTop, sep, selTabTop, BORDER_VALUE); + image.drawLine(sep, sepTop, sep, selTabTop, BORDER_VALUE); image.drawLine(sep, selTabTop + iconSize + 4, sep, bandBottom - 1, BORDER_VALUE); } else { - image.drawLine(sep, bandTop, sep, bandBottom - 1, BORDER_VALUE); + image.drawLine(sep, sepTop, sep, bandBottom - 1, BORDER_VALUE); } for (let index = this.scrollRow; index < lastVisible; index++) { @@ -312,13 +314,17 @@ export class ShellChromeLayer implements Layer { // slot, so anything wider would clip at the screen edge. drawSelectionBox(image, left, y - 2, variant.columnWidth, iconSize + 4, focused); } - window.drawIcon(image, x, y, iconSize, focused); + // Paint unselected icons into their own resource so only the replayed copy moves. + const icon = selected ? image : new GrayImage(iconSize, iconSize + 1); + const iconX = selected ? x : 0, iconY = selected ? y : 1; + window.drawIcon(icon, iconX, iconY, iconSize, focused); if (window.attention) { // Black dot on the white focused tab, white dot otherwise. A deferred // image (not a raster fill) so it renders above the icon, which is // itself a deferred draw. - image.drawImage(attentionDot(focused ? SHELL_OPAQUE_BLACK : 255), x + iconSize - 7, y - 1); + icon.drawImage(attentionDot(focused ? SHELL_OPAQUE_BLACK : 255), iconX + iconSize - 7, iconY - 1); } + if (!selected) image.drawDepthImage(icon, x, y - 1, -2); } // Chevrons center over the icon area, which in the one-column variant is diff --git a/app/ui/shell/shell.ts b/app/ui/shell/shell.ts index 692a3dc8..1a37a0e3 100644 --- a/app/ui/shell/shell.ts +++ b/app/ui/shell/shell.ts @@ -233,6 +233,7 @@ class ShellOverlayMenuLayer extends MenuLayer { squareCorners: true, footer, dimUnderneath: CONTEXT_MENU_DIM, + depth: 4, }); } diff --git a/app/ui/window-menu.ts b/app/ui/window-menu.ts index f439bfb6..599691e9 100644 --- a/app/ui/window-menu.ts +++ b/app/ui/window-menu.ts @@ -24,6 +24,7 @@ export const WINDOW_MENU_LAYOUT: MenuLayout = { minHeight: 150, footer: gestureHints([[GESTURE_LONG_PRESS, "system menu"]]), dimUnderneath: CONTEXT_MENU_DIM, + depth: 4, }; export class WindowMenuLayer extends MenuLayer { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt index ce7766a1..d8812a89 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt @@ -1,6 +1,6 @@ package com.faceclaw.app -/** Revision 25 wire grammar, shared by scene planning and the local renderer. */ +/** Revision 26 wire grammar, shared by scene planning and the local renderer. */ object DrawProtocol { const val DRAW = 26 const val ROOT = 27 @@ -15,8 +15,19 @@ object DrawProtocol { const val CURRENT = 65534 fun u16(b: ByteArray, p: Int): Int = (b[p].toInt() and 255) or ((b[p + 1].toInt() and 255) shl 8) fun word(n: Int) = byteArrayOf(n.toByte(), (n ushr 8).toByte()) - fun call(op: Int, args: ByteArray, target: Int? = null): ByteArray = - byteArrayOf(op.toByte(), if (target == null) 0 else 1) + (target?.let { word(it) } ?: byteArrayOf()) + args + fun call(op: Int, args: ByteArray, target: Int? = null, depth: Int? = null): ByteArray { + require(depth == null || depth in -128..127) + val flags = (if (target == null) 0 else 1) or (if (depth == null) 0 else 2) + return byteArrayOf(op.toByte(), flags.toByte()) + (target?.let { word(it) } ?: byteArrayOf()) + + (depth?.let { byteArrayOf(it.toByte()) } ?: byteArrayOf()) + args + } + fun depthOffset(depth: Int, right: Boolean): Int = + if (right) -floorHalf(depth + 1) else floorHalf(depth) + private fun floorHalf(n: Int): Int = if (n < 0) (n - 1) / 2 else n / 2 + fun roundedRect(x: Int, y: Int, width: Int, height: Int, radius: Int, background: Int, border: Int = 16, depth: Int? = null): ByteArray { + require(width in 1..640 && height in 1..480 && radius in 0..65535 && background in 0..15 && border in 0..16) + return call(8, word(x) + word(y) + word(width) + word(height) + word(radius) + byteArrayOf(background.toByte(), border.toByte()), depth = depth) + } fun sequence(calls: List): ByteArray { require(calls.size <= 4096) val out = ByteSink(); out.write(word(calls.size)) @@ -26,8 +37,8 @@ object DrawProtocol { fun message(calls: List) = byteArrayOf(DRAW.toByte()) + sequence(calls) fun displayList(calls: List) = byteArrayOf(LIST.toByte()) + sequence(calls) fun root(id: Int) = byteArrayOf(ROOT.toByte()) + word(id) - fun image(id: Int, x: Int, y: Int, options: Int = 15, target: Int? = null) = - call(4, word(id) + word(x) + word(y) + byteArrayOf(options.toByte()), target) + fun image(id: Int, x: Int, y: Int, options: Int = 15, target: Int? = null, depth: Int? = null) = + call(4, word(id) + word(x) + word(y) + byteArrayOf(options.toByte()), target, depth) fun lut(width: Int, height: Int, factor: Int): ByteArray { val table = ByteArray(8) { i -> (((i * 2 * factor / 256).coerceIn(0, 15) shl 4) or ((i * 2 + 1) * factor / 256).coerceIn(0, 15)).toByte() @@ -60,7 +71,7 @@ object DrawProtocol { flush() return call(1, out.toByteArray(), target) } - /** Internal optimizer formats are translated here; they are never sent to revision 25. */ + /** Internal optimizer formats are translated here; they are never sent to revision 26. */ fun fromOptimized(payload: ByteArray, width: Int = 640, height: Int = 480): List { return when (val mode = payload[0].toInt() and 127) { 8 -> { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt index 25e77715..c7a4c1be 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ScenePlanner.kt @@ -25,18 +25,19 @@ class ScenePlanner(private val cache: ResourceCacheState) { CachedResource(DrawProtocol.rawImage(layer.width, layer.height), keys[i]) } } owned.keys.retainAll(keys.toSet()); pixels.keys.retainAll(keys.toSet()) - cache.pin(surfaces) + val selectedResources = scene.allSelections.map { it.resource } + cache.pin(surfaces + selectedResources) val absent = surfaces.map { cache.resourceId(it) < 0 } - val ids = cache.prepare(surfaces) - check(ids.all { it >= 0 }) { "Shell surfaces exceed the resource budget" } + val prepared = cache.prepare(surfaces + selectedResources) + val ids = prepared.copyOfRange(0, surfaces.size) + val selectedIds = prepared.copyOfRange(surfaces.size, prepared.size) + check(prepared.all { it >= 0 }) { "Shell surfaces exceed the resource budget" } commands.addAll(cache.drainCommands(3600)) - val rootCalls = ArrayList() + val rootCalls = scene.calls(width, height, ids, selectedIds) for ((i, layer) in scene.layers.withIndex()) { val old = if (absent[i]) null else pixels[keys[i]] commands.addAll(DrawProtocol.messages(pixelCalls(old, layer.packed, layer.width, layer.height, ids[i]))) pixels[keys[i]] = layer.packed - if (layer.dim < 256) rootCalls.add(DrawProtocol.lut(width, height, layer.dim)) - rootCalls.add(DrawProtocol.image(ids[i], layer.x, layer.y)) } val base = if (incremental) previous else null val texture = if (textures) TexturePlanner.plan(base, screen, width, height, draws, cache, firstId, multiRect, maxRects) else null @@ -48,7 +49,7 @@ class ScenePlanner(private val cache: ResourceCacheState) { val rootId = cache.prepare(listOf(list))[0] check(rootId >= 0) { "No space for root display list" } commands.addAll(cache.drainCommands(3600)) - cache.pin(surfaces + list) + cache.pin(surfaces + selectedResources + list) val evicted = commands.any { it[0].toInt() == ResourceCacheState.EVICT_MODE } if (evicted) commands.add(0, DrawProtocol.root(DrawProtocol.SCREEN)) if (root != rootId || evicted) commands.add(DrawProtocol.root(rootId)) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt index d9354529..e6c0adc3 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt @@ -1,18 +1,27 @@ package com.faceclaw.app /** Reference interpreter. It uses the firmware's packed rows, clipping, LUT and call grammar. */ -class DisplayListRenderer(private val resources: Map, private val builtin: ((Int, Int) -> BuiltinGlyph)? = null) { +class DisplayListRenderer(private val resources: Map, private val builtin: ((Int, Int) -> BuiltinGlyph)? = null, private val rightLens: Boolean = false) { class BuiltinGlyph(val image: ByteArray, val advance: Int, val x: Int = 0, val y: Int = 0) - class Target(val bytes: ByteArray, val width: Int, val height: Int, val offset: Int = 0) { + class Target(val bytes: ByteArray, val width: Int, val height: Int, val offset: Int = 0, val shiftX: Int = 0) { val stride = (width + 1) / 2 init { require(width > 0 && height > 0 && offset >= 0 && bytes.size - offset >= stride * height) } fun get(x: Int, y: Int) = (bytes[offset + y * stride + x / 2].toInt() ushr (if (x % 2 == 0) 4 else 0)) and 15 - fun put(x: Int, y: Int, v: Int) { + fun shifted(dx: Int) = Target(bytes, width, height, offset, shiftX + dx) + fun put(localX: Int, y: Int, v: Int) { + val x = localX + shiftX if (x !in 0 until width || y !in 0 until height) return val index = offset + y * stride + x / 2; val old = bytes[index].toInt() bytes[index] = (if (x % 2 == 0) (old and 15) or (v shl 4) else (old and 240) or v).toByte() } } + private fun roundedContains(x: Int, y: Int, w: Int, h: Int, radius: Int): Boolean { + if (x !in 0 until w || y !in 0 until h) return false + val r = minOf(radius, w / 2, h / 2) + val dx = maxOf(0, 2 * r - (2 * minOf(x, w - 1 - x) + 1)) + val dy = maxOf(0, 2 * r - (2 * minOf(y, h - 1 - y) + 1)) + return dx * dx + dy * dy <= 4 * r * r + } private class Image(val width: Int, val height: Int, val pixels: IntArray) private fun word(b: ByteArray, p: Int): Int { require(p >= 0 && p + 2 <= b.size); return DrawProtocol.u16(b, p) } private fun signed(b: ByteArray, p: Int) = word(b, p).toShort().toInt() @@ -77,9 +86,10 @@ class DisplayListRenderer(private val resources: Map, private va repeat(count) { val n = word(b, pos); pos += 2; require(n >= 2 && n <= b.size - pos && budget[0]-- > 0) val call = b.copyOfRange(pos, pos + n); pos += n - val flags = call[1].toInt() and 255; require(flags <= 1) + val flags = call[1].toInt() and 255; require(flags <= 3) var t = inherited; var header = 2 - if (flags == 1) { val id = word(call, 2); refs.add(id); t = target(id); header += 2 } + if (flags and 1 != 0) { val id = word(call, 2); refs.add(id); t = target(id).shifted(inherited.shiftX); header += 2 } + if (flags and 2 != 0) { require(header < call.size); t = t.shifted(DrawProtocol.depthOffset(call[header++].toInt(), rightLens)) } val p = call.copyOfRange(header, call.size) when (call[0].toInt()) { 1 -> { @@ -132,9 +142,24 @@ class DisplayListRenderer(private val resources: Map, private va 6 -> { require(p.size == 16); val x = word(p, 0); val y = word(p, 2); val w = word(p, 4); val h = word(p, 6) require(w > 0 && h > 0 && x + w <= t.width && y + h <= t.height) - if (apply) for(yy in y until y + h) for(xx in x until x + w) { val v = t.get(xx, yy) + if (apply) for(yy in y until y + h) for(xx in x until x + w) { + if (xx + t.shiftX !in 0 until t.width) continue + val v = t.get(xx + t.shiftX, yy) t.put(xx, yy, (p[8 + v / 2].toInt() ushr (if(v % 2 == 0) 4 else 0)) and 15) } } + 8 -> { + require(p.size == 12) + val x = signed(p, 0); val y = signed(p, 2); val w = word(p, 4); val h = word(p, 6) + val radius = word(p, 8); val fill = p[10].toInt() and 255; val border = p[11].toInt() and 255 + require(w in 1..640 && h in 1..480 && fill <= 15 && border <= 16) + if (apply) for (yy in 0 until h) for (xx in 0 until w) { + if (!roundedContains(xx, yy, w, h, radius)) continue + val tx = x + xx + t.shiftX; val ty = y + yy + if (tx !in 0 until t.width || ty !in 0 until t.height) continue + val edge = !roundedContains(xx - 1, yy - 1, w - 2, h - 2, maxOf(0, radius - 1)) + t.put(x + xx, ty, if (edge && border < 16) border else maxOf(fill, t.get(tx, ty))) + } + } 7 -> { require(p.size == 2); executeList(word(p, 0), t, screen, apply, stack, budget, refs) } else -> error("Unknown draw opcode") } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt new file mode 100644 index 00000000..c5630483 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt @@ -0,0 +1,56 @@ +package com.faceclaw.app + +/** A retained selection or image, replayed at stereo depth over the screen and shell surfaces. */ +class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val radius: Int, + val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = 3, val mask: List = emptyList()) { + val resource = CachedResource(DrawProtocol.rawImage(width, height, packed)) + val fingerprint = "$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" + fun translated(dx: Int, dy: Int) = MenuSelection(x + dx, y + dy, width, height, radius, background, border, depth, packed, occlusions.map { intArrayOf(it[0] + dx, it[1] + dy, it[2], it[3]) }, kind, mask) + fun calls(id: Int): List { + val image = when (kind) { + 3 -> listOf(DrawProtocol.roundedRect(x, y, width, height, radius, background, border, depth), + DrawProtocol.image(id, x, y, 31, depth = depth)) + 4 -> listOf(DrawProtocol.image(id, x, y, 31, depth = depth)) + // Gray8 zero is transparent but gray8 one is opaque black. Rect copies preserve + // that distinction after packing, including the transparent corners of app menus. + 5 -> mask.map { r -> DrawProtocol.call(2, DrawProtocol.word(id) + + r.flatMap { DrawProtocol.word(it).toList() }.toByteArray() + + DrawProtocol.word(x + r[0]) + DrawProtocol.word(y + r[1]), depth = depth) } + else -> error("Invalid presentation kind") + } + return image + occlusions.map { r -> DrawProtocol.call(2, DrawProtocol.word(DrawProtocol.SCREEN) + r.flatMap { DrawProtocol.word(it).toList() }.toByteArray() + DrawProtocol.word(r[0]) + DrawProtocol.word(r[1])) } + } + companion object { + /** The caller has consumed the presentation tag (3, 4 or 5). Colors cross the bridge in gray8, pixels in gray8 rows. */ + fun read(reader: ByteReader, kind: Int = 3): MenuSelection { + require(kind in 3..5) + require(reader.remaining() >= 15) + val x = reader.getShort().toInt(); val y = reader.getShort().toInt() + val w = reader.getShort().toInt() and 65535; val h = reader.getShort().toInt() and 65535 + val radius = reader.getShort().toInt() and 65535 + val background = BmpUtil.nibbleForGray(reader.get() and 255) + val border = BmpUtil.nibbleForGray(reader.get() and 255) + val depth = reader.get().toByte().toInt() + val count = reader.getShort().toInt() and 65535 + require(count <= 2048) + require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) + val gray = ByteArray(w * h); reader.get(gray) + require(reader.remaining() >= count * 8) + val occlusions = List(count) { IntArray(4) { reader.getShort().toInt() and 65535 } } + val mask = ArrayList() + if (kind == 5) for (yy in 0 until h) { + var start = -1 + for (xx in 0..w) { + val covered = xx < w && gray[yy * w + xx].toInt() != 0 + if (covered && start < 0) start = xx + if (!covered && start >= 0) { + val previous = mask.lastOrNull { it[0] == start && it[2] == xx - start && it[1] + it[3] == yy } + if (previous != null) previous[3]++ else mask.add(intArrayOf(start, yy, xx - start, 1)) + start = -1 + } + } + } + return MenuSelection(x, y, w, h, radius, background, border, depth, BmpUtil.pack4bppFromGray8(gray, w, h), occlusions, kind, mask) + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt index cfb1570e..1338b9af 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt @@ -1,19 +1,29 @@ package com.faceclaw.app /** Immutable shell snapshot. Keys identify writable surfaces across repaints, not their pixels. */ -class ShellScene(val layers: List) { - class Layer(val key: Int, val x: Int, val y: Int, val width: Int, val height: Int, val dim: Int, val packed: ByteArray) - val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${CachedResource(it.packed).hash}" } - fun preview(screenGray: ByteArray, width: Int, height: Int): ByteArray { - val screen = BmpUtil.pack4bppFromGray8(screenGray, width, height) - val output = ByteArray(screen.size); val resources = HashMap(); val calls = ArrayList() - for ((id, layer) in layers.withIndex()) { +class ShellScene(val layers: List, val selections: List = emptyList()) { + class Layer(val key: Int, val x: Int, val y: Int, val width: Int, val height: Int, val dim: Int, val packed: ByteArray, val selections: List = emptyList(), val depth: Int = 0) + val allSelections = selections + layers.flatMap { it.selections } + val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${it.depth},${CachedResource(it.packed).hash},${it.selections.joinToString { row -> row.fingerprint }}" } + selections.joinToString { it.fingerprint } + fun calls(width: Int, height: Int, surfaces: IntArray, selected: IntArray): List { + val calls = ArrayList(); var rowId = 0 + for (row in selections) calls.addAll(row.calls(selected[rowId++])) + for ((index, layer) in layers.withIndex()) { if (layer.dim < 256) calls.add(DrawProtocol.lut(width, height, layer.dim)) - resources[id] = DrawProtocol.rawImage(layer.width, layer.height, layer.packed) - calls.add(DrawProtocol.image(id, layer.x, layer.y)) + calls.add(DrawProtocol.image(surfaces[index], layer.x, layer.y, depth = layer.depth)) + for (row in layer.selections) calls.addAll(row.calls(selected[rowId++])) } - resources[511] = DrawProtocol.displayList(calls) - DisplayListRenderer(resources).render(511, DisplayListRenderer.Target(screen, width, height), DisplayListRenderer.Target(output, width, height)) + return calls + } + fun preview(screenGray: ByteArray, width: Int, height: Int, rightLens: Boolean = false): ByteArray { + val screen = BmpUtil.pack4bppFromGray8(screenGray, width, height) + val output = ByteArray(screen.size); val resources = HashMap() + val surfaces = IntArray(layers.size) { id -> + val layer = layers[id]; resources[id] = DrawProtocol.rawImage(layer.width, layer.height, layer.packed); id + } + val rows = IntArray(allSelections.size) { id -> resources[id + layers.size] = allSelections[id].resource.bytes; id + layers.size } + resources[511] = DrawProtocol.displayList(calls(width, height, surfaces, rows)) + DisplayListRenderer(resources, rightLens = rightLens).render(511, DisplayListRenderer.Target(screen, width, height), DisplayListRenderer.Target(output, width, height)) val target = DisplayListRenderer.Target(output, width, height) return ByteArray(width * height) { (target.get(it % width, it / width) * 16).toByte() } } @@ -23,17 +33,20 @@ class ShellScene(val layers: List) { val count = reader.getShort().toInt() and 65535; require(count <= 64) val layers = ArrayList() repeat(count) { - require(reader.remaining() >= 14) + require(reader.remaining() >= 16) val key = reader.getShort().toInt() and 65535 val x = reader.getShort().toInt(); val y = reader.getShort().toInt() val w = reader.getShort().toInt() and 65535; val h = reader.getShort().toInt() and 65535 val dim = reader.getShort().toInt() and 65535 - val reserved = reader.getShort().toInt(); require(reserved == 0 && dim <= 256) + val selectionCount = reader.getShort().toInt() and 65535; require(selectionCount <= 64 && dim <= 256) + val depth = reader.getShort().toInt(); require(depth in -128..127) require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) val gray = ByteArray(w * h); reader.get(gray) - layers.add(Layer(key, x, y, w, h, dim, BmpUtil.pack4bppFromGray8(gray, w, h))) + val selections = List(selectionCount) { MenuSelection.read(reader, reader.get().toInt()) } + layers.add(Layer(key, x, y, w, h, dim, BmpUtil.pack4bppFromGray8(gray, w, h), selections, depth)) } require(reader.remaining() == 0) + require(layers.sumOf { it.selections.size } + layers.size < 511) require(layers.map { it.key }.toSet().size == layers.size) return ShellScene(layers) } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index e9284a03..bc70d8d7 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -50,6 +50,7 @@ class SurfaceCompositor { var out: MutableList = ArrayList() while ((cursor.remaining() >= 1)) { var kind: Int = (cursor.get() and 0xff) + if (kind in 3..5) { out.add(ScreenDraw.image(0, 0, 0).also { it.selection = MenuSelection.read(cursor, kind) }); continue } if (((kind == ScreenDraw.KIND_GLYPH) && (cursor.remaining() >= 11))) { var fontId: Int = (cursor.getShort().toInt() and 0xffff) var encoding: Int = cursor.getInt() @@ -106,6 +107,7 @@ class SurfaceCompositor { * raster comes from ImageAtlas under imageId. */ class ScreenDraw { + @JvmField var selection: MenuSelection? = null companion object { const val KIND_GLYPH: Int = 0 @@ -609,6 +611,7 @@ class SurfaceCompositor { var fingerprint: StringBuilder = StringBuilder() fingerprint.append(screenWidth).append('x').append(screenHeight) var draws: MutableList = ArrayList() + val selections = ArrayList() for (surface in ordered) { if (!surface.visible || (shellScene != null && surface.id == "shell")) { continue @@ -616,6 +619,8 @@ class SurfaceCompositor { blendLocked(gray, surface) var dim: Int = dimForLocked(surface) for (draw in surface.draws) { + val selected = draw.selection + if (selected != null) { selections.add(selected.translated(surface.x, surface.y)); continue } if (((dim < 256) && (draw.kind == ScreenDraw.KIND_IMAGE))) { continue } @@ -656,8 +661,8 @@ class SurfaceCompositor { fingerprint.append(":dim").append(dim) } } - val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene.EMPTY else shellScene ?: ShellScene.EMPTY - val preview = if (shellScene != null) scene.preview(gray, screenWidth, screenHeight) else gray + val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene.EMPTY else ShellScene(shellScene?.layers ?: emptyList(), selections) + val preview = if (shellScene != null || selections.isNotEmpty()) scene.preview(gray, screenWidth, screenHeight) else gray return Composite(preview, screenWidth, screenHeight, fingerprint.append("|shell:").append(scene.fingerprint).toString(), nextCompositeSeq++, draws.toTypedArray()).also { it.screenGray = gray; it.shellScene = scene } } diff --git a/tests/compass-texture-cache.test.cjs b/tests/compass-texture-cache.test.cjs index 694f2083..08e36e12 100644 --- a/tests/compass-texture-cache.test.cjs +++ b/tests/compass-texture-cache.test.cjs @@ -156,7 +156,7 @@ test('the background registers once and uses a nine-byte image reference on late return 1; } } } } }, }); - const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas }); + const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas, './presentation-wire': load('app/graphics/presentation-wire.ts') }); const background = compass.createCompassBackground(576, 260, 256, 193.25, 98, 140, 1); for (const heading of [0, 1, 2, 45, 90]) { const image = background.clone(); diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt index b694b83c..86bf698e 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt @@ -34,7 +34,86 @@ class DisplayListTest { 2 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(1))))) assertFails { DisplayListRenderer(cyclic).render(1,target,target) } } - private class Glasses { + @Test fun roundedRectsAndNestedOddNegativeDepthMatchFirmwareOnBothLenses() { + val resources = mapOf( + 40 to hex("0404000200f00f0ff0"), + 41 to hex("0202000f00080202010001000c0008000300040a0a000402022800050004001f"), + 42 to hex("02010005000702fd2900")) + val screen = hex("012345601234560112345601234560122345601234560123345601234560123445601234560123455601234f60123456601234560123456001234560123456011234560123456012234560123456012334560123456012344560123456012345") + val expected = listOf("01234560123456011aaaaaaaaaa56012aa45644444aa0123a4564444456a1234a564f44f564a2345a6444fff644a3456a4444456444a4560aa44456444aa56011aaaaaaaaaa56012234560123456012334560123456012344560123456012345", "012345601234560112aaaaaaaaaa60122aa56444445aa1233a5644444564a2344a644f44f644a3455a4444ff6444a4566a4444564444a5600aa44564444aa60112aaaaaaaaaa6012234560123456012334560123456012344560123456012345") + for (right in listOf(false, true)) { + val output = ByteArray(screen.size) + DisplayListRenderer(resources, rightLens = right).render(42, DisplayListRenderer.Target(screen,16,12), DisplayListRenderer.Target(output,16,12)) + assertContentEquals(hex(expected[if(right) 1 else 0]), output) + } + for (depth in -128..127) { + assertEquals(kotlin.math.floor(depth / 2.0).toInt(), DrawProtocol.depthOffset(depth, false)) + assertEquals(-kotlin.math.floor((depth + 1) / 2.0).toInt(), DrawProtocol.depthOffset(depth, true)) + } + } + @Test fun roundedFillPreservesBrighterTextAndDepthClipsWithoutNibbleDamage() { + val pixels = ByteArray(32) { 0x11 }; pixels[13] = 0xf1.toByte() + val target = DisplayListRenderer.Target(pixels,8,8) + val fill = DrawProtocol.roundedRect(-1,0,8,8,2,6,16,2) + DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(fill)),target) + assertEquals(15,target.get(2,3)); assertEquals(6,target.get(3,3)); assertEquals(1,target.get(0,0)) + val bbox = DrawProtocol.call(1,hex("00000002010f10"),depth=-1) + DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(bbox)),target) + assertEquals(15,target.get(0,0));assertEquals(1,target.get(7,0)) + val before=pixels.copyOf() + assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(byteArrayOf(8,2))),target) } + assertContentEquals(before,pixels) + } + @Test fun selectedMenuResourcesStayOutOfScreenAndReplayAtDepthTwo() { + val planner=ScenePlanner(ResourceCacheState()); val left=Glasses(); val right=Glasses(true) + val app=ByteArray(640*480/2) { 0x11 } + fun row(x:Int) = MenuSelection(x,8,8,4,1,4,9,2,hex("00ff0000000000000000000000000000")) + val scene=ShellScene(emptyList(),listOf(row(10))) + val first=planner.plan(app,640,480,null,scene,1);left.apply(first.commands);right.apply(first.commands) + assertContentEquals(app,left.screen);assertContentEquals(app,right.screen) + val l=DisplayListRenderer.Target(left.composition,640,480);val r=DisplayListRenderer.Target(right.composition,640,480) + assertEquals(15,l.get(13,8));assertEquals(15,r.get(11,8));assertEquals(1,l.get(9,8)) + val moved=planner.plan(app,640,480,null,ShellScene(emptyList(),listOf(row(20))),1) + assertFalse(moved.commands.any { it[0].toInt()==26 || it[0].toInt()==29 }) + left.apply(moved.commands);assertContentEquals(app,left.screen) + left.apply(planner.plan(app,640,480,null,ShellScene.EMPTY,1).commands) + assertContentEquals(app,left.composition) + } + @Test fun contextMenusAndSidebarDepthReplayOnBothLensesWithoutBakedCopies() { + fun record(kind: Int, x: Int, y: Int, w: Int, h: Int, depth: Int, gray: ByteArray): MenuSelection { + val bytes = DrawProtocol.word(x) + DrawProtocol.word(y) + DrawProtocol.word(w) + DrawProtocol.word(h) + + DrawProtocol.word(0) + byteArrayOf(16, 48, depth.toByte()) + DrawProtocol.word(0) + gray + return MenuSelection.read(ArrayByteReader(bytes), kind) + } + val menu = record(5, 10, 10, 8, 8, 4, ByteArray(64) { if (it == 0) 0 else 1 }) + val selected = record(3, 12, 12, 4, 2, 6, ByteArray(8) { -1 }) + val icon = record(4, 30, 10, 2, 2, -2, ByteArray(4) { -1 }) + val app = ByteArray(640 * 480 / 2) { 0x66 } + val planner = ScenePlanner(ResourceCacheState()) + val scene = ShellScene(emptyList(), listOf(menu, selected, icon)) + val plan = planner.plan(app, 640, 480, null, scene, 1) + for (right in listOf(false, true)) { + val glasses = Glasses(right); glasses.apply(plan.commands) + assertContentEquals(app, glasses.screen) + val output = DisplayListRenderer.Target(glasses.composition,640,480) + val shift = if (right) -2 else 2 + assertEquals(6, output.get(10 + shift,10)) // transparent corner + assertEquals(0, output.get(11 + shift,10)) // opaque black stays opaque + assertEquals(15, output.get(12 + (if (right) -3 else 3),12)) + assertEquals(15, output.get(30 + (if (right) 1 else -1),10)) + assertEquals(6, output.get(if (right) 30 else 31,10)) // no unshifted icon + val preview = scene.preview(ByteArray(640*480) { 96 },640,480,right) + assertContentEquals(glasses.composition, BmpUtil.pack4bppFromGray8(preview,640,480)) + } + // The shell uses an independently owned surface with its own depth. + val shell = ShellScene(listOf(ShellScene.Layer(1,10,10,8,8,256,ByteArray(32),listOf(selected),4))) + val left = shell.preview(ByteArray(640*480) { 96 },640,480) + val right = shell.preview(ByteArray(640*480) { 96 },640,480,true) + assertEquals(0,left[10*640+12].toInt()); assertEquals(96,left[10*640+10].toInt()) + assertEquals(0,right[10*640+8].toInt()); assertEquals(96,right[10*640+16].toInt()) + } + + private class Glasses(val right: Boolean = false) { val resources=mutableMapOf(); val screen=ByteArray(640*480/2);val composition=ByteArray(screen.size) var root=65535 fun apply(commands: List) { @@ -46,9 +125,9 @@ class DisplayListTest { } } 22 -> repeat(DrawProtocol.u16(b,1)) { resources.remove(DrawProtocol.u16(b,3+it*2)) } 29 -> repeat(DrawProtocol.u16(b,1)) { val p=3+it*6;resources.getOrPut(DrawProtocol.u16(b,p)) { DrawProtocol.rawImage(DrawProtocol.u16(b,p+2),DrawProtocol.u16(b,p+4)) } } - 26 -> DisplayListRenderer(resources).execute(b.copyOfRange(1,b.size),DisplayListRenderer.Target(screen,640,480)) + 26 -> DisplayListRenderer(resources, rightLens = right).execute(b.copyOfRange(1,b.size),DisplayListRenderer.Target(screen,640,480)) 27 -> root=DrawProtocol.u16(b,1) - 28 -> DisplayListRenderer(resources).render(root,DisplayListRenderer.Target(screen,640,480),DisplayListRenderer.Target(composition,640,480)) + 28 -> DisplayListRenderer(resources, rightLens = right).render(root,DisplayListRenderer.Target(screen,640,480),DisplayListRenderer.Target(composition,640,480)) else -> error("legacy command ${b[0]}") } } diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs new file mode 100644 index 00000000..4abe3feb --- /dev/null +++ b/tests/menu-display-list.test.cjs @@ -0,0 +1,110 @@ +const test=require('node:test'); +const assert=require('node:assert/strict'); +const fs=require('node:fs'); +const vm=require('node:vm'); +const ts=require('typescript'); +const graphics=require('../.test-build/app/graphics/image.js'); +const planes=require('../.test-build/app/graphics/plane.js'); +const wire=require('../.test-build/app/graphics/presentation-wire.js'); +const {encodeShellScene}=require('../.test-build/app/graphics/shell-scene.js'); +const {SurfaceCompositor}=require('../.test-build/app/graphics/surface-compositor.js'); +function load(file,modules) { + const context={exports:{},require:name=>{assert.ok(name in modules, name);return modules[name];}}; + vm.runInNewContext(ts.transpileModule(fs.readFileSync(file,'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2020}}).outputText,context); + return context.exports; +} +const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4, + drawText:(image,x,y,text,value)=>{for(let i=0;ifont}, + '../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{}, + './metrics':require('../.test-build/app/ui/metrics.js'), +}); +const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}}); +function menu() { + const layer=new MenuLayer(null,[{label:'FIRST',onSelect(){}},{label:'SECOND',onSelect(){}}],{x:0,y:0,width:80,minHeight:70,maxHeight:80,squareCorners:true}); + const context={stack:{getBaseSize:()=>({width:80,height:80}),isFocused:()=>true}}; + return {layer,paint:()=>layer.paint(context,()=>new graphics.GrayImage(80,80)),context}; +} +test('menu retains the selected text and rounded highlight at depth +2',async()=>{ + const m=menu(),image=m.paint(),row=image.draws.find(d=>d.presentation); + assert.equal(row.presentation.depth,2);assert.equal(row.presentation.radius,8); + assert.ok(row.source.pixels.some(v=>v===255));assert.ok(!image.withDrawsBaked(false).pixels.some(v=>v===255)); + const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0}]); + const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.equal(records.length,1); + const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'}); + c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws)); + const screen=flat.image.pixels.slice(),preview=c.composite(); + assert.ok(preview.some(v=>v===240));assert.deepEqual(flat.image.pixels,screen); + await m.layer.handleInput({type:'scroll-down'},m.context); + const next=m.paint().draws.find(d=>d.presentation);assert.ok(next.y>row.y);assert.equal(next.presentation.depth,2); +}); +test('shell menu selection survives serialization and is not baked into its surface',()=>{ + const image=menu().paint(),bytes=encodeShellScene([{image,x:0,y:0,shellKey:7}]); + assert.equal(new DataView(bytes.buffer).getUint16(14,true),1); + const c=new SurfaceCompositor(80,80);c.setShellScene(bytes);assert.ok(c.composite().some(v=>v===240)); +}); +test('later opaque planes occlude a replayed selection without erasing its visible part',()=>{ + const image=menu().paint(),row=image.draws.find(d=>d.presentation),cover=new graphics.GrayImage(10,8,1); + const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0},{image:cover,x:row.x+10,y:row.y+2}]); + const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.ok(records[0].occlusions.length); + const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'}); + c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws)); + const preview=c.composite(); + for(let y=row.y+2;yv===240)); +}); + +const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{ + '../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'./gestures':{}, +}); +test('context menu surface uses +4 and selected row +6 without changing the app screen',()=>{ + const base=new graphics.GrayImage(100,90,96); + const stack=new LayerStack({paint:()=>base},noopLayerActions,{width:100,height:90}); + stack.push(new MenuLayer(null,[{label:'FIRST',onSelect(){}}],{x:10,y:8,width:80,minHeight:70,maxHeight:70,depth:4})); + const frame=planes.flattenPlanesWithDraws(stack.paint()); + assert.deepEqual(frame.image.pixels,base.pixels); + const records=wire.presentationRecords(prepareFrameDraws(frame.draws)); + assert.deepEqual(records.map(r=>r.depth),[4,6]);assert.equal(records[0].mode,'masked-image'); + const c=new SurfaceCompositor(100,90);c.configureSurface('app',{x:0,y:0,width:100,height:90,zOrder:0,transparency:'opaque'}); + c.submitSurfaceFrame('app',frame.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(frame.draws)); + const preview=c.composite(); + assert.equal(preview[45*100+10],96); // old left edge has no baked menu + assert.equal(preview[45*100+13],0); // shifted opaque black interior + assert.equal(preview[8*100+12],96); // transparent rounded corner + assert.ok(preview.some(v=>v===240)); + stack.pop();const closed=planes.flattenPlanesWithDraws(stack.paint()); + c.submitSurfaceFrame('app',closed.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(closed.draws)); + assert.deepEqual(c.composite(),base.pixels); +}); +test('system menu bridge shifts its surface +4 and selected row +6',()=>{ + const image=menu().paint(),bytes=encodeShellScene([{image,x:8,y:0,shellKey:7,depth:4}]); + const view=new DataView(bytes.buffer),w=view.getUint16(8,true),h=view.getUint16(10,true); + assert.equal(view.getInt16(16,true),4); + assert.equal(wire.readPresentation(bytes,18+w*h).selection.depth,6); + const c=new SurfaceCompositor(100,80);c.setShellScene(bytes);const preview=c.composite(); + assert.equal(preview[40*100+8],0);assert.equal(preview[40*100+10],80); +}); +test('unselected sidebar icons retain -2 depth through shell cropping, including attention badges',()=>{ + const shellScene=require('../.test-build/app/graphics/shell-scene.js'); + const {ShellChromeLayer}=load('app/ui/shell/chrome-layer.ts',{ + '../../graphics/shell-scene':shellScene,'../../graphics/image':graphics, + '../../graphics/ui-fonts':{getDefaultSmallFont:()=>font,getDefaultMediumFont:()=>font}, + '../../graphics/textwrap':{},'./ambient-cards':{},'../../graphics/battery':{}, + '../../native/notification-icons':{},'../../native/phone-battery':{},'../../util/render-freshness':{}, + '../../graphics/icons':{},'../dashboard-settings':{},'../clock-format':{},'../../graphics/bdffont':{}, + '../layers':{LayerStack},'../menu':{scrollToKeepSelectionVisible:()=>0},'../metrics':{}, + './geometry':{MIN_WINDOW_HEIGHT:280,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24}, + }); + const state={selectedIndex:0,focus:'sidebar',windows:[0,1,2].map(n=>({attention:n===1,drawIcon:(image,x,y)=>image.fillRect(x,y,4,4,240)}))}; + const chrome=new ShellChromeLayer(()=>state),image=new graphics.GrayImage(640,480); + chrome.drawSidebar(image,state); + assert.deepEqual(Array.from(image.draws.filter(d=>d.presentation),d=>d.presentation.depth),[-2,-2]); + const crop=shellScene.shellCrop(image,0,0,64,280,1),bytes=encodeShellScene([crop]); + const c=new SurfaceCompositor(640,480);c.setShellScene(bytes);const preview=c.composite(); + assert.equal(preview[34*640+30],240); // selected icon stays at its original x + assert.equal(preview[74*640+29],240); // unselected icon moves left by one + assert.equal(preview[74*640+33],0); // no baked copy at the original right edge + state.selectedIndex=1;const next=new graphics.GrayImage(640,480);chrome.drawSidebar(next,state); + assert.equal(next.draws.filter(d=>d.presentation).length,2); +}); diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index d09aeb88..4b1159f2 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -142,6 +142,10 @@ test('Music settings keeps toggles and selection when a new app arrives and supp const font = BdfFont.parse(source('app/fonts/terminus/ter-u20n.bdf')); class RecordingImage extends graphics.GrayImage { texts = []; + drawMenuSelection(source, x, y, ...args) { + this.texts.push(...source.texts.map(t => ({ ...t, x: t.x + x, y: t.y + y }))); + super.drawMenuSelection(source, x, y, ...args); + } drawText(font, x, y, text, value) { this.texts.push({ x, y, text }); super.drawText(font, x, y, text, value); } } const deps = { diff --git a/tests/notification-filter.test.cjs b/tests/notification-filter.test.cjs index 3e77ac5d..93505eeb 100644 --- a/tests/notification-filter.test.cjs +++ b/tests/notification-filter.test.cjs @@ -58,6 +58,10 @@ function ui(fontSize = 12) { const font = BdfFont.parse(source(`app/fonts/terminus/ter-u${fontSize}n.bdf`)); class RecordingImage extends graphics.GrayImage { texts = []; + drawMenuSelection(source, x, y, ...args) { + this.texts.push(...source.texts.map(t => ({ ...t, x: t.x + x, y: t.y + y }))); + super.drawMenuSelection(source, x, y, ...args); + } drawText(font, x, y, text, value) { this.texts.push({ x, y, text }); super.drawText(font, x, y, text, value); diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 57e77a20..05e62fc8 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -25,6 +25,9 @@ "../app/g2/flash-prompt-protocol.ts", "../app/graphics/surface-compositor.ts", "../app/graphics/image.ts", + "../app/graphics/plane.ts", + "../app/graphics/shell-scene.ts", + "../app/ui/metrics.ts", "../app/phone-ui/phone-gestures.ts", "../app/g2/firmware-compat.ts", "../app/g2/glasses-hardware-identity.ts", From 44eddedc0167c8658a1636dd7aa14f87d06731eb Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 11:54:45 -0700 Subject: [PATCH 05/27] Add script for collecting CPU profile information --- .gitignore | 3 + package.json | 1 + scripts/profile-android.cjs | 304 +++++++++++++++++++++++++++++++++ scripts/profile-android.md | 105 ++++++++++++ tests/profile-android.test.cjs | 68 ++++++++ 5 files changed, 481 insertions(+) create mode 100644 scripts/profile-android.cjs create mode 100644 scripts/profile-android.md create mode 100644 tests/profile-android.test.cjs diff --git a/.gitignore b/.gitignore index 9331ae0a..977b7b65 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ platforms/ # Release APKs from scripts/release.sh dist/ +# CPU captures and source maps pulled from the installed app +profiles/ + # Logs logs *.log diff --git a/package.json b/package.json index 81a0f3ac..12869539 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "private": false, "scripts": { "input": "node scripts/faceclaw-input.cjs", + "profile:android": "node scripts/profile-android.cjs", "native:android": "node scripts/kotlin-build.cjs android", "native:ios": "node scripts/kotlin-build.cjs ios", "test:kotlin": "bash scripts/test-kotlin.sh", diff --git a/scripts/profile-android.cjs b/scripts/profile-android.cjs new file mode 100644 index 00000000..1db1d30c --- /dev/null +++ b/scripts/profile-android.cjs @@ -0,0 +1,304 @@ +#!/usr/bin/env node +'use strict'; + +// Host-side only: ART samples the process; V8 samples each JS isolate over CDP. +const fs = require('node:fs'); +const path = require('node:path'); +const { execFileSync } = require('node:child_process'); +const { SourceMap } = require('node:module'); + +const HELP = `Usage: npm run profile:android -- [options] + + --device SERIAL ADB device (or ANDROID_SERIAL; required if ambiguous) + --seconds N Recording duration, 1–300 (default: 10) + --mode all|js|art V8 TypeScript/JS, ART Java/Kotlin, or both (default: all) + --interval N Sampling interval in microseconds, 100–1000000 (default: 1000) + --out DIRECTORY New output directory (default: profiles/) + --package ID App package (default: com.faceclaw.app) + --no-source-maps Keep only generated JS locations + +Requires Node 22+, adb, and an already running debug build. No rebuild or restart. +Reproduce the workload while recording. Ctrl-C stops and saves early. +Disconnect other debuggers/profilers first. See scripts/profile-android.md. +`; + +function parseArgs(args, env = process.env) { + const options = { device: env.ANDROID_SERIAL, seconds: 10, mode: 'all', interval: 1000, + package: 'com.faceclaw.app', sourceMaps: true }; + for (let i = 0; i < args.length; i++) { + const arg = args[i]; + if (arg === '--help' || arg === '-h') return { help: true }; + if (arg === '--no-source-maps') { options.sourceMaps = false; continue; } + if (!['--device', '--seconds', '--mode', '--interval', '--out', '--package'].includes(arg)) { + throw new Error(`Unknown option: ${arg}`); + } + const value = args[++i]; + if (!value || value.startsWith('--')) throw new Error(`Missing value for ${arg}`); + options[arg.slice(2)] = ['--seconds', '--interval'].includes(arg) ? Number(value) : value; + } + if (!Number.isFinite(options.seconds) || options.seconds < 1 || options.seconds > 300) throw new Error('--seconds must be between 1 and 300.'); + if (!Number.isInteger(options.interval) || options.interval < 100 || options.interval > 1000000) throw new Error('--interval must be an integer between 100 and 1000000.'); + if (!['all', 'js', 'art'].includes(options.mode)) throw new Error('--mode must be all, js, or art.'); + // ADB shell joins arguments into a remote shell command. Keep all interpolated + // remote paths and package names restricted, even though execFile uses no shell. + if (!/^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+$/.test(options.package)) throw new Error('Invalid Android package ID.'); + return options; +} + +class Inspector { + constructor(socket) { + this.socket = socket; + this.nextId = 0; + this.pending = new Map(); + this.onEvent = () => {}; + socket.addEventListener('message', ({ data }) => { + const message = JSON.parse(data); + if (!message.id) { this.onEvent(message); return; } + const pending = this.pending.get(message.id); + if (!pending) return; + this.pending.delete(message.id); + clearTimeout(pending.timer); + if (message.error) pending.reject(new Error(`${pending.method}: ${message.error.message}`)); + else pending.resolve(message.result); + }); + const disconnected = () => { + for (const pending of this.pending.values()) { + clearTimeout(pending.timer); + pending.reject(new Error('NativeScript inspector disconnected.')); + } + this.pending.clear(); + }; + socket.addEventListener('close', disconnected); + socket.addEventListener('error', disconnected); + } + + static async connect(port) { + const socket = new WebSocket(`ws://127.0.0.1:${port}`); + const inspector = new Inspector(socket); + await new Promise((resolve, reject) => { + const timer = setTimeout(() => { socket.close(); reject(new Error('Inspector connection timed out. Is this a running NativeScript debug build?')); }, 10000); + socket.addEventListener('open', () => { clearTimeout(timer); resolve(); }, { once: true }); + socket.addEventListener('error', () => { clearTimeout(timer); reject(new Error('Cannot connect to NativeScript inspector. Use a running debug build.')); }, { once: true }); + }); + return inspector; + } + + call(method, params = {}, sessionId) { + if (this.socket.readyState !== WebSocket.OPEN) return Promise.reject(new Error('Inspector is not connected.')); + const id = ++this.nextId; + return new Promise((resolve, reject) => { + const timer = setTimeout(() => { + this.pending.delete(id); + reject(new Error(`${method} timed out${sessionId ? ` (${sessionId})` : ''}.`)); + }, 10000); + this.pending.set(id, { resolve, reject, timer, method }); + this.socket.send(JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) })); + }); + } + + close() { this.socket.close(); } +} + +function remapProfile(profile, maps) { + const mapped = structuredClone(profile); + let mappedNodes = 0; + for (const node of mapped.nodes) { + const frame = node.callFrame; + const map = maps.get(frame.url); + if (!map || frame.lineNumber < 0 || frame.columnNumber < 0) continue; + const entry = map.findEntry(frame.lineNumber, frame.columnNumber); + if (!entry.originalSource || entry.originalLine === undefined) continue; + frame.url = entry.originalSource; + frame.lineNumber = entry.originalLine; + frame.columnNumber = entry.originalColumn; + if (entry.name) frame.functionName = entry.name; + // V8's generated line ticks no longer describe this source file. Keep them + // in the raw profile, but don't show misleading line counts in the mapped one. + delete node.positionTicks; + mappedNodes++; + } + return { profile: mapped, mappedNodes }; +} + +function traceSummary(buffer) { + const end = buffer.indexOf('*end\n'); + if (end < 0 || buffer.subarray(0, 8).toString() !== '*version') throw new Error('ART did not produce a valid method trace.'); + const header = buffer.subarray(0, end).toString(); + const methods = header.split('*methods\n')[1]?.trim().split('\n') || []; + return { bytes: buffer.length, overflow: header.includes('data-file-overflow=true'), + methods: methods.length, + faceclawMethods: methods.filter(line => line.includes('\tcom.faceclaw.')).length, + kotlinMethods: methods.filter(line => /\.kt(?:\t|$)/.test(line)).length }; +} + +async function record(options) { + if (typeof WebSocket === 'undefined') throw new Error('Node 22+ is required (built-in WebSocket).'); + const adb = (...args) => execFileSync('adb', [...(options.device ? ['-s', options.device] : []), ...args], + { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, timeout: 30000, stdio: ['ignore', 'pipe', 'pipe'] }); + if (!options.device) { + const devices = adb('devices').split('\n').filter(line => /\tdevice\s*$/.test(line)).map(line => line.split('\t')[0]); + if (devices.length !== 1) throw new Error(`Found ${devices.length} ADB devices. Select one with --device SERIAL.`); + options.device = devices[0]; + } + const pids = adb('shell', 'pidof', options.package).trim().split(/\s+/); + if (pids.length !== 1 || !/^\d+$/.test(pids[0])) throw new Error('Start Faceclaw before profiling; expected one app process.'); + const pid = pids[0]; + try { adb('shell', 'run-as', options.package, 'id'); } + catch { throw new Error('Profiling requires an installed debug build (run-as failed). Build with ./build.sh --env.sourceMap=source-map.'); } + const stamp = new Date().toISOString().replace(/[:.]/g, '-'); + const output = path.resolve(options.out || path.join('profiles', stamp)); + fs.mkdirSync(path.dirname(output), { recursive: true }); + fs.mkdirSync(output); // Refuse to overwrite an earlier capture. + const remoteTrace = `/data/local/tmp/faceclaw-${stamp}-${process.pid}.trace`; + const summary = { device: options.device, package: options.package, pid, mode: options.mode, + intervalUs: options.interval, requestedSeconds: options.seconds, startedAt: new Date().toISOString(), + profiles: [], warnings: [] }; + const warn = message => { summary.warnings.push(message); console.error(`Warning: ${message}`); }; + let port, inspector, artStarted = false, stopping = false, interrupted = false, wake; + const targets = new Map(); + const stopEarly = () => { interrupted = true; if (wake) wake(); }; + process.on('SIGINT', stopEarly); + process.on('SIGTERM', stopEarly); + let failure; + + async function startTarget(sessionId, title) { + const key = sessionId || 'main'; + if (targets.has(key) || stopping) return; + const target = { sessionId, title, key, started: false }; + targets.set(key, target); + target.ready = (async () => { + await inspector.call('Profiler.enable', {}, sessionId); + await inspector.call('Profiler.setSamplingInterval', { interval: options.interval }, sessionId); + await inspector.call('Profiler.start', {}, sessionId); + target.started = true; + target.startedAt = new Date().toISOString(); + console.log(`V8 recording: ${title}`); + })().catch(error => { warn(`Cannot profile ${title}: ${error.message}`); }); + await target.ready; + } + + try { + if (options.mode !== 'art') { + port = adb('forward', 'tcp:0', `localabstract:${options.package}-inspectorServer`).trim(); + if (!/^\d+$/.test(port)) throw new Error('ADB did not allocate an inspector port.'); + inspector = await Inspector.connect(port); + inspector.onEvent = message => { + if (message.method === 'Target.attachedToTarget') { + const { sessionId, targetInfo } = message.params; + if (targetInfo.type === 'worker') void startTarget(sessionId, targetInfo.url || targetInfo.title); + } else if (message.method === 'Target.detachedFromTarget') { + const target = targets.get(message.params.sessionId); + if (target) { target.detached = true; warn(`Worker exited before its profile could be saved: ${target.title}`); } + } + }; + await startTarget(undefined, 'main'); + if (!targets.get('main').started) throw new Error('Main V8 profiler failed to start.'); + try { + await inspector.call('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: false, flatten: true }); + await Promise.all([...targets.values()].map(target => target.ready)); + } catch (error) { warn(`Worker discovery unavailable; main V8 profile still active: ${error.message}`); } + } + if (options.mode !== 'js') { + const result = adb('shell', 'am', 'profile', 'start', '--sampling', String(options.interval), pid, remoteTrace); + if (/error|exception|failed/i.test(result)) throw new Error(result.trim()); + artStarted = true; + console.log('ART recording: Java/Kotlin across the app process'); + } + console.log(`Reproduce the workload now (${options.seconds}s; Ctrl-C saves early).`); + if (!interrupted) await new Promise(resolve => { + const timer = setTimeout(resolve, options.seconds * 1000); + wake = () => { clearTimeout(timer); resolve(); }; + }); + } catch (error) { failure = error; } + finally { + stopping = true; + // Stop every profiler before pulling maps/files. Failures in one profiler + // must not prevent the others from stopping or their data from being saved. + if (artStarted) { + try { adb('shell', 'am', 'profile', 'stop', pid); } + catch (error) { warn(`Could not stop ART: ${error.message}. Run adb -s ${options.device} shell am profile stop ${pid}`); } + } + await Promise.all([...targets.values()].map(async target => { + await target.ready; + if (!target.started || target.detached) return; + try { + const { profile } = await inspector.call('Profiler.stop', {}, target.sessionId); + if (!Array.isArray(profile?.nodes)) throw new Error('Inspector returned no CPU profile.'); + const name = `js-${target.key.replace(/[^A-Za-z0-9_-]/g, '_')}`; + fs.writeFileSync(path.join(output, `${name}.raw.cpuprofile`), JSON.stringify(profile)); + target.profile = profile; + summary.profiles.push({ name, title: target.title, startedAt: target.startedAt, + samples: profile.samples?.length || 0, nodes: profile.nodes.length }); + } catch (error) { warn(`Could not save ${target.title}: ${error.message}`); } + })); + inspector?.close(); + if (port) { + try { adb('forward', '--remove', `tcp:${port}`); } + catch (error) { warn(`Could not remove ADB forward tcp:${port}: ${error.message}`); } + } + process.removeListener('SIGINT', stopEarly); + process.removeListener('SIGTERM', stopEarly); + } + + summary.stoppedAt = new Date().toISOString(); + summary.interrupted = interrupted; + if (artStarted) { + try { + const file = path.join(output, 'java-kotlin.trace'); + adb('pull', remoteTrace, file); + summary.art = traceSummary(fs.readFileSync(file)); + if (summary.art.overflow) warn('ART trace buffer overflowed. Use a shorter capture or a larger --interval.'); + adb('shell', 'rm', remoteTrace); + } catch (error) { warn(`Could not retrieve ART trace (left at ${remoteTrace}): ${error.message}`); } + } + + if (options.sourceMaps && summary.profiles.length) { + // Use maps from the installed app, never a potentially mismatched local build. + const maps = new Map(); + const urls = new Set([...targets.values()].flatMap(target => target.profile?.nodes.map(node => node.callFrame.url) || [])); + for (const url of urls) { + const prefix = `file:///data/data/${options.package}/files/app/`; + const alternate = `file:///data/user/0/${options.package}/files/app/`; + const relative = url.startsWith(prefix) ? url.slice(prefix.length) : url.startsWith(alternate) ? url.slice(alternate.length) : ''; + if (!/^[A-Za-z0-9_.-]+\.(?:m?js)$/.test(relative)) continue; + try { + let payload; + try { payload = adb('exec-out', 'run-as', options.package, 'cat', `files/app/${relative}.map`); } + catch { + const source = adb('exec-out', 'run-as', options.package, 'cat', `files/app/${relative}`); + const inline = source.match(/sourceMappingURL=data:application\/json[^,\n]*;base64,([A-Za-z0-9+/=]+)/); + if (!inline) throw new Error('no external or inline map'); + payload = Buffer.from(inline[1], 'base64').toString('utf8'); + } + maps.set(url, new SourceMap(JSON.parse(payload))); + fs.mkdirSync(path.join(output, 'source-maps'), { recursive: true }); + fs.writeFileSync(path.join(output, 'source-maps', `${relative}.map`), payload); + } catch (error) { warn(`Source map unavailable for ${relative}: ${error.message}. Generated locations remain usable.`); } + } + for (const target of targets.values()) { + if (!target.profile) continue; + const name = `js-${target.key.replace(/[^A-Za-z0-9_-]/g, '_')}`; + const mapped = remapProfile(target.profile, maps); + fs.writeFileSync(path.join(output, `${name}.cpuprofile`), JSON.stringify(mapped.profile)); + summary.profiles.find(item => item.name === name).mappedNodes = mapped.mappedNodes; + } + } + if (failure) summary.error = failure.message; + fs.writeFileSync(path.join(output, 'capture.json'), JSON.stringify(summary, null, 2) + '\n'); + console.log(`Saved ${output}`); + for (const profile of summary.profiles) console.log(` ${profile.name}: ${profile.samples} samples, ${profile.mappedNodes || 0} source-mapped nodes`); + if (summary.art) console.log(` ART: ${summary.art.methods} methods (${summary.art.faceclawMethods} Faceclaw, ${summary.art.kotlinMethods} with Kotlin source)`); + if (failure) throw failure; + if ((options.mode !== 'js' && !summary.art) || (options.mode !== 'art' && !summary.profiles.length)) throw new Error('Capture incomplete; see capture.json.'); + return summary; +} + +if (require.main === module) { + Promise.resolve().then(() => { + const options = parseArgs(process.argv.slice(2)); + if (options.help) console.log(HELP); + else return record(options); + }).catch(error => { console.error(`Profiling failed: ${error.message}`); process.exitCode = 1; }); +} + +module.exports = { parseArgs, Inspector, remapProfile, traceSummary, record }; diff --git a/scripts/profile-android.md b/scripts/profile-android.md new file mode 100644 index 00000000..fb4a7414 --- /dev/null +++ b/scripts/profile-android.md @@ -0,0 +1,105 @@ +# Android CPU profiling + +Faceclaw can capture all three languages without adding instrumentation to the +app: Android Runtime (ART) sampling for Java/Kotlin, and V8 sampling for the +TypeScript compiled to JavaScript. The host script attaches to a running debug +build, records for a bounded duration, stops the profilers, and saves their files. +Nothing runs in the app when a capture is not active. + +## Record + +Use Node 22+ and `adb` on your PATH. Install and launch a **debug** build first. +For a new build, external source maps make capture extraction faster: + +```sh +./build_and_run.sh --env.sourceMap=source-map +adb devices -l +npm run profile:android -- --device SERIAL --seconds 15 +``` + +An existing debug build works too; the script also handles inline source maps. +No rebuild, app restart, Android Studio, root, or additional npm dependencies are +needed to record. Release APKs are not supported by this command. + +Reproduce the slow operation after the command prints `Reproduce the workload +now`. Ctrl-C stops and saves early. Disconnect Chrome/NativeScript debuggers and +Android Studio CPU recordings first; this command needs exclusive profiler use. +If USB and wireless ADB both point to the same phone, select one with `--device`. +`ANDROID_SERIAL` also works, or omit the device when exactly one is connected. + +```sh +# Java/Kotlin only, all threads in the app process +npm run profile:android -- --device SERIAL --mode art --seconds 15 + +# TypeScript/JavaScript only: main isolate and live NativeScript workers +npm run profile:android -- --device SERIAL --mode js --seconds 15 + +# Less frequent sampling (microseconds), with a named output directory +npm run profile:android -- --device SERIAL --interval 5000 --out profiles/scrolling +``` + +Default interval is 1,000 microseconds (1 ms); default duration is 10 seconds. +The output directory must not already exist. Captures go under git-ignored +`profiles/` by default. `--no-source-maps` skips source-map extraction. + +## Read the results + +| File | Contents | Viewer | +| --- | --- | --- | +| `java-kotlin.trace` | Sampled managed stacks across app threads, with Java and Kotlin method names | Android Studio Profiler: import/open a trace | +| `js-main.cpuprofile` | Main V8 isolate, locations mapped back to TypeScript where available | Chrome DevTools Performance: load profile, or [Speedscope](https://www.speedscope.app/) | +| `js-NS_WORKER_*.cpuprofile` | One profile per attached NativeScript worker | Same CPU-profile viewers | +| `*.raw.cpuprofile` | Original V8 profile with generated bundle locations and line ticks | Same CPU-profile viewers | +| `capture.json` | Worker names, capture parameters, sample counts, mapped-node counts, warnings | Text editor | +| `source-maps/` | Maps copied from the installed application, including embedded sources when available | Retained for interpreting the capture | + +Use flame charts and bottom-up views to find expensive stacks. The worker URL in +`capture.json` identifies which app each numbered worker belongs to. Only raw +profiles are written with `--no-source-maps`; otherwise both versions are saved, +even when some locations cannot be mapped. Maps come from the installed app, +so a different local checkout cannot silently mislabel its frames. + +## Coverage and interpretation + +* **Java and Kotlin:** ART samples all managed threads in the app process, + including shared Kotlin code packaged by `@faceclaw/kotlin`. Inlined Kotlin + functions may appear as their callers. This is sampling, not an exact count + of every method invocation. +* **TypeScript:** V8 samples the main isolate and workers already running or + created during recording. Workers must survive until capture stops to return + their profiles; exited workers are reported as warnings. Older NativeScript + runtimes without worker auto-attach can still capture the main isolate. +* **Separate runtimes:** These are overlapping captures, not a single stitched + cross-language call tree. Starts/stops have a small skew. V8 may show time + inside a native bridge call; inspect ART to see the Java/Kotlin side. Embedded + WebView JavaScript and native C/C++ stacks are outside this command's coverage. +* **Overhead:** Profiling changes timing, especially with both profilers active. + Use separate `--mode js` / `--mode art` runs and larger intervals when needed. + Keep the existing frame timings for end-to-end latency. Idle/background + workers can return very few samples; exercise the code you want to measure. +* **Failures:** Raw profiles are saved before source mapping. `capture.json` + reports partial captures and ART buffer overflow. On overflow, shorten the + capture or increase the interval. Missing maps leave generated JS locations + usable; build with `--env.sourceMap=source-map` for TypeScript locations. + +On normal completion, Ctrl-C, or a handled capture error, the script attempts to +stop every profiler it started and removes its own ADB forwarding. A killed host +process or disconnected phone can prevent cleanup. Reconnect and stop ART with +`adb -s SERIAL shell am profile stop com.faceclaw.app`; restart the app if V8 +profiling remains active. A failed pull leaves the trace at the device path +printed in the warning for manual recovery. + +## Verified setup + +Verified on a Pixel 7a running Android 16, with Faceclaw 0.7.2 and this checkout's +NativeScript Android 9.1.1 runtime. A 10-second capture produced Java/Kotlin +method data, a TypeScript-mapped main profile, and profiles for terminal and +Flappy Bird workers (Flappy was idle). No APK changes were required. + +The implementation uses Android's `am profile start --sampling` / `stop` and +NativeScript's ADB-forwarded `PACKAGE-inspectorServer` WebSocket, with CDP +`Profiler` commands and flattened `Target.setAutoAttach` worker sessions. + +References: [Android sampled method tracing](https://developer.android.com/studio/profile/generate-trace-logs), +[NativeScript debugging and profiling](https://docs.nativescript.org/guide/debugging), +[V8 inspector CPU profiling protocol](https://chromedevtools.github.io/devtools-protocol/tot/Profiler/). diff --git a/tests/profile-android.test.cjs b/tests/profile-android.test.cjs new file mode 100644 index 00000000..57d9816c --- /dev/null +++ b/tests/profile-android.test.cjs @@ -0,0 +1,68 @@ +'use strict'; +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { SourceMap } = require('node:module'); +const { parseArgs, remapProfile, traceSummary, Inspector } = require('../scripts/profile-android.cjs'); + +test('profiling CLI validates remote shell arguments and sampling limits', () => { + assert.equal(parseArgs([], {}).mode, 'all'); + assert.equal(parseArgs([], { ANDROID_SERIAL: 'usb-device' }).device, 'usb-device'); + for (const args of [ + ['--package', 'com.faceclaw.app;id'], ['--package', '../app'], + ['--seconds', 'NaN'], ['--seconds', '0'], ['--seconds', '301'], + ['--interval', '1'], ['--interval', '100.5'], ['--mode', 'native'], ['--device'], + ]) assert.throws(() => parseArgs(args, {})); +}); + +test('source mapping keeps V8 sample structure and raw locations intact', () => { + const map = new SourceMap({ version: 3, sources: ['webpack://faceclaw/app/example.ts'], + names: ['originalName'], mappings: 'AASEA', sourcesContent: [''] }); + const raw = { nodes: [{ id: 1, callFrame: { url: 'bundle.mjs', functionName: 'minified', + lineNumber: 0, columnNumber: 0 }, hitCount: 2, positionTicks: [{ line: 1, ticks: 2 }] }, + { id: 2, callFrame: { url: '', functionName: '(idle)', lineNumber: -1, columnNumber: -1 } }], + samples: [1, 2, 1], timeDeltas: [1000, 1500, 2000], startTime: 123, endTime: 4623 }; + const result = remapProfile(raw, new Map([['bundle.mjs', map]])); + assert.equal(result.mappedNodes, 1); + assert.deepEqual(result.profile.nodes[0].callFrame, { url: 'webpack://faceclaw/app/example.ts', + functionName: 'originalName', lineNumber: 9, columnNumber: 2 }); + assert.equal(result.profile.nodes[0].positionTicks, undefined); + assert.equal(raw.nodes[0].callFrame.url, 'bundle.mjs'); + assert.ok(raw.nodes[0].positionTicks); + assert.deepEqual(result.profile.samples, raw.samples); + assert.deepEqual(result.profile.timeDeltas, raw.timeDeltas); + assert.deepEqual(result.profile.nodes[1], raw.nodes[1]); +}); + +test('ART validation detects overflow and recognizes Kotlin source names', () => { + const trace = Buffer.from('*version\n3\ndata-file-overflow=true\n*methods\n' + + '0x4\tcom.faceclaw.Example\tfoo\t()V\tExample.kt\n' + + '0x8\tandroid.Example\tbar\t()V\tExample.java\n*end\nSLOW'); + assert.deepEqual(traceSummary(trace), { bytes: trace.length, overflow: true, methods: 2, faceclawMethods: 1, kotlinMethods: 1 }); + assert.throws(() => traceSummary(Buffer.from('Permission denied'))); +}); + +test('CDP routes worker sessions and handles out-of-order replies and disconnects', async () => { + class Socket extends EventTarget { + readyState = WebSocket.OPEN; + sent = []; + send(data) { this.sent.push(JSON.parse(data)); } + receive(data) { this.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(data) })); } + close() { this.readyState = WebSocket.CLOSED; this.dispatchEvent(new Event('close')); } + } + const socket = new Socket(); + const inspector = new Inspector(socket); + const main = inspector.call('Profiler.stop'); + const worker = inspector.call('Profiler.stop', {}, 'NS_WORKER_1'); + assert.equal(socket.sent[1].sessionId, 'NS_WORKER_1'); + socket.receive({ id: 2, sessionId: 'NS_WORKER_1', result: { worker: true } }); + socket.receive({ id: 1, result: { main: true } }); + assert.deepEqual(await worker, { worker: true }); + assert.deepEqual(await main, { main: true }); + const failed = inspector.call('Profiler.start'); + socket.receive({ id: 3, error: { message: 'already started' } }); + await assert.rejects(failed, /already started/); + const disconnected = inspector.call('Profiler.stop'); + inspector.close(); + await assert.rejects(disconnected, /disconnected/); + await assert.rejects(inspector.call('Profiler.stop'), /not connected/); +}); From 9560f3ac8da53f34ad66bb4bde85f59fdfb2155d Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 14:19:23 -0700 Subject: [PATCH 06/27] Phone CPU usage optimization --- .../faceclaw/app/FaceclawBleCommunicator.java | 15 +-- .../app/FaceclawPreviewCompositor.java | 2 +- .../com/faceclaw/app/FaceclawRemoteInput.java | 21 +++- App_Resources/iOS/src/FaceclawRemoteInput.h | 1 + App_Resources/iOS/src/FaceclawRemoteInput.m | 16 +++ app/apps/flappy/flappy-app.worker.ts | 24 ++--- app/g2/dashboard-controller.ts | 40 +++++--- app/graphics/image.ts | 4 +- app/native/faceclaw-communicator.ts | 9 -- app/native/remote-input.ios.ts | 5 +- app/native/remote-input.ts | 6 +- app/phone-ui/main-page.ts | 4 + app/remote/service.ts | 41 ++++---- .../FaceclawBleCommunicatorListener.kt | 2 - .../app/g2protocol/BleImageOptimizer.kt | 22 ++--- .../faceclaw/app/g2protocol/TexturePlanner.kt | 97 ++++++++++--------- .../com/faceclaw/app/graphics/ImageAtlas.kt | 2 +- .../app/graphics/SurfaceCompositor.kt | 15 ++- .../kotlin/com/faceclaw/app/util/BmpUtil.kt | 50 +++++----- .../com/faceclaw/app/DisplayListTest.kt | 38 ++++++++ .../com/faceclaw/app/PreviewPackingTest.kt | 67 +++++++++++++ .../com/faceclaw/app/ResourceCacheTest.kt | 45 +++++++++ .../kotlin/com/faceclaw/app/RleEncoderTest.kt | 65 +++++++++++++ tests/phone-preview.test.cjs | 86 ++++++++++++++++ tests/remote-input-native.cjs | 13 ++- tests/remote-service.test.cjs | 83 ++++++++++++++++ 26 files changed, 606 insertions(+), 167 deletions(-) create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/PreviewPackingTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RleEncoderTest.kt create mode 100644 tests/phone-preview.test.cjs create mode 100644 tests/remote-service.test.cjs diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java index 05d7bfc0..cbed7e39 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java @@ -258,7 +258,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { // included in the newer composite). private long lastStoredCompositeSeq; - private final SurfaceCompositor compositor = new SurfaceCompositor(); + // Wire submissions need screenGray + the shell scene, never preview pixels. + // Preview/screenshot/recording callers render those explicitly on demand. + private final SurfaceCompositor compositor = new SurfaceCompositor(false); // Phone-side model of the CFW's 192 KiB resource cache. // Reset whenever the image pipeline / EvenHub session is torn down: the @@ -4025,17 +4027,6 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private void logLine(String line) { Log.i(TAG, line); - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - mainHandler.post(() -> { - try { - current.onLog(line); - } catch (Throwable t) { - Log.w(TAG, "listener onLog failed", t); - } - }); } private static String timestamp(long elapsedMs) { diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java index b0304992..e0351588 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java @@ -111,7 +111,7 @@ public final class FaceclawPreviewCompositor { int frameId, java.nio.ByteBuffer glyphs ) { - compositor.applyAndComposite( + compositor.submitSurface( surfaceId, new AndroidByteReader(pixels8bpp), rectX, rectY, rectWidth, rectHeight, contentFingerprint, glyphs == null ? null : new AndroidByteReader(glyphs)); FrameTimings.getInstance().finishFrame(frameId, "composited (preview-only, no glasses)"); diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java index 1b602978..a44f47c9 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java @@ -1,5 +1,7 @@ package com.faceclaw.app; +import android.os.Handler; +import android.os.Looper; import java.io.ByteArrayOutputStream; import java.net.InetAddress; import java.net.NetworkInterface; @@ -13,7 +15,7 @@ import java.security.MessageDigest; import java.security.SecureRandom; import org.json.JSONObject; -/** Explicit-address, bounded, one-request-per-connection input port. JS polls on its own thread. */ +/** Explicit-address, bounded input port. Complete requests notify JS on the main thread. */ public final class FaceclawRemoteInput { private static final FaceclawRemoteInput INSTANCE = new FaceclawRemoteInput(); public static FaceclawRemoteInput getInstance() { return INSTANCE; } @@ -22,6 +24,22 @@ public final class FaceclawRemoteInput { private String pending, reply; private long nextId, requestId; private long deadline; + private final Handler mainHandler = new Handler(Looper.getMainLooper()); + private Runnable requestListener; + + public synchronized void setRequestListener(Runnable listener) { requestListener = listener; } + + private void notifyRequestReady(long id) { + // Called with this monitor held; posting avoids entering JS on the socket thread. + mainHandler.post(() -> { + Runnable callback; + synchronized (this) { + if (requestId != id || pending == null || System.currentTimeMillis() >= deadline) return; + callback = requestListener; + } + if (callback != null) callback.run(); + }); + } public synchronized String start(int port) { return startAddress(port, "127.0.0.1"); } public synchronized String startAddress(int port, String address) { @@ -81,6 +99,7 @@ public final class FaceclawRemoteInput { reply = null; pending = new JSONObject().put("id", requestId).put("expiresAt", deadline) .put("body", text).toString(); + notifyRequestReady(requestId); while (reply == null && server == listener && System.currentTimeMillis() < deadline) { wait(Math.max(1, deadline - System.currentTimeMillis())); } diff --git a/App_Resources/iOS/src/FaceclawRemoteInput.h b/App_Resources/iOS/src/FaceclawRemoteInput.h index dbbce5e0..4a5708f4 100644 --- a/App_Resources/iOS/src/FaceclawRemoteInput.h +++ b/App_Resources/iOS/src/FaceclawRemoteInput.h @@ -5,6 +5,7 @@ - (NSString *)start:(int)port; - (NSString *)start:(int)port address:(NSString *)address; - (void)stop; +- (void)setRequestListener:(void (^)(void))listener; - (NSString *)nextRequest; - (void)complete:(long long)identifier response:(NSString *)response; - (NSString *)randomSecret; diff --git a/App_Resources/iOS/src/FaceclawRemoteInput.m b/App_Resources/iOS/src/FaceclawRemoteInput.m index 0c1c46af..b7e73446 100644 --- a/App_Resources/iOS/src/FaceclawRemoteInput.m +++ b/App_Resources/iOS/src/FaceclawRemoteInput.m @@ -17,6 +17,7 @@ long long _nextId, _requestId; NSTimeInterval _deadline; NSString *_pending, *_reply; + void (^_requestListener)(void); } + (instancetype)shared { static FaceclawRemoteInput *instance; static dispatch_once_t once; @@ -65,6 +66,20 @@ NSString *result = NSDate.date.timeIntervalSince1970 < _deadline ? _pending : nil; _pending = nil; [_condition unlock]; return result; } +- (void)setRequestListener:(void (^)(void))listener { + [_condition lock]; _requestListener = [listener copy]; [_condition unlock]; +} +- (void)notifyRequestReady:(long long)identifier { + // Dispatch from under the condition lock; invoke JS only on the main thread, + // outside the lock, and discard notifications invalidated by stop/timeout. + dispatch_async(dispatch_get_main_queue(), ^{ + [self->_condition lock]; + void (^callback)(void) = self->_requestId == identifier && self->_pending && + NSDate.date.timeIntervalSince1970 < self->_deadline ? self->_requestListener : nil; + [self->_condition unlock]; + if (callback) callback(); + }); +} - (void)complete:(long long)identifier response:(NSString *)response { [_condition lock]; if (_requestId == identifier && NSDate.date.timeIntervalSince1970 < _deadline) { _reply = response; [_condition signal]; } @@ -104,6 +119,7 @@ _requestId = ++_nextId; _deadline = NSDate.date.timeIntervalSince1970 + 5; _reply = nil; NSData *json = [NSJSONSerialization dataWithJSONObject:@{@"id":@(_requestId), @"expiresAt":@(_deadline * 1000), @"body":text} options:0 error:nil]; _pending = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]; + [self notifyRequestReady:_requestId]; while (!_reply && generation == _generation && NSDate.date.timeIntervalSince1970 < _deadline) [_condition waitUntilDate:[NSDate dateWithTimeIntervalSince1970:_deadline]]; NSString *reply = _reply ?: @"{\"ok\":false,\"error\":\"timeout\",\"message\":\"Faceclaw did not respond in time.\"}"; diff --git a/app/apps/flappy/flappy-app.worker.ts b/app/apps/flappy/flappy-app.worker.ts index d3cf5cce..c0e91451 100644 --- a/app/apps/flappy/flappy-app.worker.ts +++ b/app/apps/flappy/flappy-app.worker.ts @@ -761,17 +761,19 @@ function renderAndSubmit(window: FlappyWindow, inputFrameId: number): void { } const { image, draws } = frameTimings.span(frameId, "flatten", () => flattenPlanesWithDraws(planes)); const buffer = frameTimings.span(frameId, "to8bpp", () => image.to8bppBuffer()); - communicator.submitSurfaceFrame( - buffer.buffer, - window.surfaceId, - 0, - 0, - image.width, - image.height, - fingerprint, - paintMs, - frameId, - frameTimings.span(frameId, "prepareFrameDraws", () => prepareFrameDraws(draws)), + frameTimings.span(frameId, "submitSurfaceFrame", () => + communicator.submitSurfaceFrame( + buffer.buffer, + window.surfaceId, + 0, + 0, + image.width, + image.height, + fingerprint, + paintMs, + frameId, + frameTimings.span(frameId, "prepareFrameDraws", () => prepareFrameDraws(draws)), + ) ); window.lastSubmittedFingerprint = fingerprint; } catch (error) { diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 9c431239..3db547e3 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -268,7 +268,6 @@ class DashboardController { private lockSurfaceConfigured = false; private lastLockScreenEnabled = lockScreenEnabledSetting.get(); private offState: (() => void) | null = null; - private offLog: (() => void) | null = null; private offRing: (() => void) | null = null; private offBattery: (() => void) | null = null; private offSilentMode: (() => void) | null = null; @@ -1327,9 +1326,6 @@ class DashboardController { ring: ringAddress, }); this.communicator = communicator; - this.offLog = communicator.onLog((line) => { - this.appendLog(line); - }); this.offState = communicator.onStateChange((state) => { if (state.phase !== "connected") resetRingInputFilter(); if (state.phase === "unpaired") { @@ -1542,8 +1538,6 @@ class DashboardController { const message = this.formatError(error); this.offState?.(); this.offState = null; - this.offLog?.(); - this.offLog = null; this.offRing?.(); this.offRing = null; this.offBattery?.(); @@ -1682,8 +1676,6 @@ class DashboardController { this.clearDashboardTimer(); this.offState?.(); this.offState = null; - this.offLog?.(); - this.offLog = null; this.offRing?.(); this.offRing = null; this.offBattery?.(); @@ -2593,7 +2585,7 @@ class DashboardController { } private appendLog(line: string): void { - console.log(`[${formatTimestamp(new Date())}] ${line}`); + //console.log(`[${formatTimestamp(new Date())}] ${line}`); } private setDisplayPreview(preview: ImageSource | null): void { @@ -2610,6 +2602,22 @@ class DashboardController { */ private previewTrailingTimer: ReturnType | null = null; private lastRecordCaptureAtMs = 0; + private phonePreviewVisible: (() => boolean) | null = null; + + /** The main page owns the mirror; other phone pages must not keep it rendering. */ + attachPhonePreview(isVisible: () => boolean): () => void { + this.phonePreviewVisible = isVisible; + this.lastConnectedPreviewUpdateAtMs = 0; + this.updateCompositePreview(); + return () => { + if (this.phonePreviewVisible !== isVisible) return; + this.phonePreviewVisible = null; + if (this.previewTrailingTimer) { + clearTimeout(this.previewTrailingTimer); + this.previewTrailingTimer = null; + } + }; + } /** * Refresh the preview now if the floor allows, otherwise once the floor @@ -2617,6 +2625,7 @@ class DashboardController { * of waiting for the safety-net poll. */ private schedulePreviewUpdate(): void { + if (!this.phonePreviewVisible && !this.screenRecordingActive) return; if (this.previewTrailingTimer) return; const wait = this.lastConnectedPreviewUpdateAtMs + CONNECTED_PREVIEW_MIN_UPDATE_MS - Date.now(); if (wait <= 0) { @@ -2644,6 +2653,13 @@ class DashboardController { return; } this.lastConnectedPreviewUpdateAtMs = now; + // A user-requested GIF is an independent consumer, including while the + // phone is asleep or another page/app is foregrounded. + if (this.screenRecordingActive && now - this.lastRecordCaptureAtMs >= RECORDING_MIN_CAPTURE_MS) { + this.lastRecordCaptureAtMs = now; + display.recordScreenFrame(); + } + if (!this.phonePreviewVisible?.()) return; // The connected foreground service intentionally keeps this controller // alive after the phone UI is backgrounded. Do not keep constructing // 640x480 Android Bitmaps for a window that cannot display them: besides @@ -2652,10 +2668,8 @@ class DashboardController { if (global.isAndroid) { const activity = Application.android.foregroundActivity; if (!activity || !activity.hasWindowFocus()) return; - } - if (this.screenRecordingActive && now - this.lastRecordCaptureAtMs >= RECORDING_MIN_CAPTURE_MS) { - this.lastRecordCaptureAtMs = now; - display.recordScreenFrame(); + const power = activity.getSystemService(android.content.Context.POWER_SERVICE) as android.os.PowerManager; + if (!power?.isInteractive()) return; } const preview = display.getCompositePreview(previewColorSetting.get() === "green"); if (preview) { diff --git a/app/graphics/image.ts b/app/graphics/image.ts index bb725293..05f7125d 100644 --- a/app/graphics/image.ts +++ b/app/graphics/image.ts @@ -149,7 +149,9 @@ export class GrayImage { this.width = width; this.height = height; this.pixels = new Uint8Array(width * height); - this.clear(fill); + if (fill !== 0) { + this.clear(fill); + } } get draws(): readonly DeferredDraw[] { diff --git a/app/native/faceclaw-communicator.ts b/app/native/faceclaw-communicator.ts index bd4f2bcc..5d36a3f7 100644 --- a/app/native/faceclaw-communicator.ts +++ b/app/native/faceclaw-communicator.ts @@ -137,7 +137,6 @@ export class FaceclawCommunicatorBridge { // does not race against finishes that land before the wait starts. private readonly finishedFrameOutcomes = new Map(); private readonly frameFinishedWaiters = new Map void>>(); - private readonly logListeners = new Set<(line: string) => void>(); private readonly stateListeners = new Set<(state: CommunicatorState) => void>(); private readonly ringListeners = new Set<(event: RawInputEvent) => void>(); private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>(); @@ -161,9 +160,6 @@ export class FaceclawCommunicatorBridge { addresses.ring ?? "", ); this.listenerProxy = new com.faceclaw.app.FaceclawBleCommunicatorListener({ - onLog: (line: string) => { - this.emitAsync(this.logListeners, String(line)); - }, onStateChange: (phase: string, status: string) => { const state = { phase: String(phase) as CommunicatorPhase, @@ -293,11 +289,6 @@ export class FaceclawCommunicatorBridge { return result; } - onLog(listener: (line: string) => void): () => void { - this.logListeners.add(listener); - return () => this.logListeners.delete(listener); - } - onStateChange(listener: (state: CommunicatorState) => void): () => void { this.stateListeners.add(listener); return () => this.stateListeners.delete(listener); diff --git a/app/native/remote-input.ios.ts b/app/native/remote-input.ios.ts index d20e9e5c..511cd41c 100644 --- a/app/native/remote-input.ios.ts +++ b/app/native/remote-input.ios.ts @@ -1,9 +1,10 @@ import { createListenerPool, type InterfaceAddress } from '../remote/listeners'; declare const FaceclawRemoteInput: any; -export function remoteNative() { +export function remoteNative(onRequestReady: () => void) { return createListenerPool(() => { const native = FaceclawRemoteInput.alloc().init(); - return { start: (port, address) => String(native.startAddress(port, address)), stop: () => native.stop(), + native.setRequestListener(onRequestReady); + return { start: (port, address) => String(native.startAddress(port, address)), stop: () => { native.setRequestListener(null); native.stop(); }, nextRequest: () => native.nextRequest(), complete: (id, response) => native.completeResponse(id, response) }; }); } diff --git a/app/native/remote-input.ts b/app/native/remote-input.ts index 8650ef07..0be486be 100644 --- a/app/native/remote-input.ts +++ b/app/native/remote-input.ts @@ -1,10 +1,12 @@ import { createListenerPool, type InterfaceAddress } from '../remote/listeners'; import { Utils } from '@nativescript/core'; declare const com: any; -export function remoteNative() { +export function remoteNative(onRequestReady: () => void) { return createListenerPool(() => { const native = new com.faceclaw.app.FaceclawRemoteInput(); - return { start: (port, address) => String(native.startAddress(port, address)), stop: () => native.stop(), + const ready = new java.lang.Runnable({ run: onRequestReady }); + native.setRequestListener(ready); + return { start: (port, address) => String(native.startAddress(port, address)), stop: () => { native.setRequestListener(null); native.stop(); }, nextRequest: () => native.nextRequest(), complete: (id, response) => native.complete(id, response) }; }); } diff --git a/app/phone-ui/main-page.ts b/app/phone-ui/main-page.ts index 244b6d05..b22a42d5 100644 --- a/app/phone-ui/main-page.ts +++ b/app/phone-ui/main-page.ts @@ -15,6 +15,7 @@ type MainPageState = { model: MainViewModel propertyChangeHandler: (args: EventData & { propertyName?: string }) => void orientationHandler: () => void + detachPreview: () => void } function getPageState(page: Page): MainPageState | undefined { @@ -32,6 +33,7 @@ function cleanupPage(page: Page): void { return } state.model.off(Observable.propertyChangeEvent, state.propertyChangeHandler) + state.detachPreview() Application.off(Application.orientationChangedEvent, state.orientationHandler) // navigatingTo builds a fresh model each visit; drop the old one's // controller/settings subscriptions or every navigation leaks a listener. @@ -130,6 +132,8 @@ export function loaded(args: EventData) { const state: MainPageState = { model, + detachPreview: dashboardController.attachPhonePreview(() => + page.isLoaded && !model.displayPreviewMessage && (!isAndroid || !!page.android?.isShown())), orientationHandler: () => { setTimeout(() => { model.refreshLayoutMetrics() diff --git a/app/remote/service.ts b/app/remote/service.ts index 02e64c5b..2c324229 100644 --- a/app/remote/service.ts +++ b/app/remote/service.ts @@ -10,17 +10,33 @@ export function remoteInputStatus(): string { return status; } export function remoteInterfaceSelection(): string { return getStringSetting(INTERFACE_STORAGE_KEY, 'tailscale'); } export function selectRemoteInterface(value: string): void { setStringSetting(INTERFACE_STORAGE_KEY, value); } -/** Owned by the main controller. Native socket work never enters a JS isolate. */ +/** Owned by the main controller. Native sockets notify JS only for complete requests. */ export function startRemoteInput(host: RemoteHost): () => void { - const native = remoteNative(); - let timer: ReturnType | null = null; + const native = remoteNative(() => { void drain(); }); let busy = false; + let stopped = false; let networkTimer: ReturnType | null = null; + // A notification while handling another request is covered by the next drain + // iteration. No timer or native bridge calls are needed while sockets are idle. + const drain = async () => { + if (busy || stopped) return; + busy = true; + try { + while (!stopped) { + const raw = native.nextRequest(); + if (!raw) break; + const request = JSON.parse(String(raw)); + if (Date.now() >= request.expiresAt) continue; + let reply; + try { reply = await handleRequest(request.body, remoteTokens, host); } + catch { reply = { ok: false, error: 'failed', message: 'Request failed.' }; } + if (!stopped) native.complete(request.id, JSON.stringify(reply)); + } + } finally { busy = false; } + }; const sync = () => { if (!remoteTokens.list().length) { native.stop(); - if (timer !== null) clearInterval(timer); - timer = null; if (networkTimer !== null) clearInterval(networkTimer); networkTimer = null; status = 'No tokens; listener stopped.'; @@ -34,21 +50,8 @@ export function startRemoteInput(host: RemoteHost): () => void { if (failure) status += `\n${failure}`; // Reconcile after VPN reconnects/address changes; unchanged sockets stay open. if (networkTimer === null) networkTimer = setInterval(sync, 3000); - if (timer !== null) return; - timer = setInterval(() => { - if (busy) return; - const raw = native.nextRequest(); - if (!raw) return; - const request = JSON.parse(String(raw)); - if (Date.now() >= request.expiresAt) return; - busy = true; - void handleRequest(request.body, remoteTokens, host) - .then(reply => native.complete(request.id, JSON.stringify(reply))) - .catch(() => native.complete(request.id, JSON.stringify({ ok: false, error: 'failed', message: 'Request failed.' }))) - .finally(() => { busy = false; }); - }, 15); }; sync(); const off = onSettingsStoreChanged(key => { if (key === TOKEN_STORAGE_KEY || key === INTERFACE_STORAGE_KEY) sync(); }); - return () => { off(); if (timer !== null) clearInterval(timer); if (networkTimer !== null) clearInterval(networkTimer); native.stop(); }; + return () => { stopped = true; off(); if (networkTimer !== null) clearInterval(networkTimer); native.stop(); }; } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleCommunicatorListener.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleCommunicatorListener.kt index b972112e..106b41ee 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleCommunicatorListener.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleCommunicatorListener.kt @@ -1,8 +1,6 @@ package com.faceclaw.app interface FaceclawBleCommunicatorListener { - fun onLog(line: String?): Unit - fun onStateChange(phase: String?, status: String?): Unit fun onRingEvent( diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt index 0e06f6c8..2eeb86b3 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt @@ -574,16 +574,20 @@ class BleImageOptimizer { */ @JvmStatic fun rleEncode(pix: ByteArray): ByteArray { - var n: Int = (pix.size * 2) - var out: ByteArray = ByteArray(n) + val n = pix.size * 2 + val out = ByteArray(n) var o: Int = 0 var i: Int = 0 while ((i < n)) { - var v: Int = nibbleAt(pix, i) - var j: Int = (i + 1) - while (((j < n) && (nibbleAt(pix, j) == v))) { - j++ - } + val first = pix[i ushr 1].toInt() and 255 + val v = if (i and 1 == 0) first ushr 4 else first and 15 + // Start at a byte boundary, consuming the known low nibble + // first if the previous run ended halfway through a byte. + var j = i + (i and 1) + val pair = ((v shl 4) or v).toByte() + while (j < n && pix[j ushr 1] == pair) j += 2 + // A final high nibble can match even when its low nibble doesn't. + if (j < n && (pix[j ushr 1].toInt() and 240) == v shl 4) j++ var run: Int = (j - i) while ((run > 0)) { var c: Int = minOf(run, 0xffff) @@ -607,10 +611,6 @@ class BleImageOptimizer { return out.copyOf(o) } - private fun nibbleAt(pix: ByteArray, i: Int): Int { - var b: Int = (pix[(i shr 1)] and 0xff) - return (if (((i and 1) != 0)) (b and 0x0f) else (b shr 4)) - } } constructor() {} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt index 48057a2b..fb1b2cd1 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt @@ -591,35 +591,26 @@ class TexturePlanner { left: Int, top: Int, ): Boolean { - run { - var row: Int = 0 - while ((row < atlas.height)) { - var y: Int = (top + row) - if (((y < 0) || (y >= height))) { - row++ - continue + val pixels = atlas.nibbles + val imageWidth = atlas.width + val startX = maxOf(0, left) + val endX = minOf(width, left + imageWidth) + val endY = minOf(height, top + atlas.height) + var y = maxOf(0, top) + while (y < endY) { + var src = (y - top) * imageWidth + startX - left + val dstRow = y * stride + var x = startX + while (x < endX) { + val source = pixels[src++].toInt() and 255 + if (source != 0) { + val byte = packed[dstRow + (x ushr 1)].toInt() and 255 + val actual = if (x and 1 == 0) byte ushr 4 else byte and 15 + if (actual != source) return false } - run { - var col: Int = 0 - while ((col < atlas.width)) { - var source: Int = atlas.nibbleAt(col, row) - if ((source == 0)) { - col++ - continue - } - var x: Int = (left + col) - if (((x < 0) || (x >= width))) { - col++ - continue - } - if ((nibbleAt(packed, stride, x, y) != source)) { - return false - } - col++ - } - } - row++ + x++ } + y++ } return true } @@ -661,29 +652,39 @@ class TexturePlanner { } } } else { - var atlas: ImageAtlas.Entry = sel.imageAtlas!! - run { - var row: Int = 0 - while ((row < atlas.height)) { - var y: Int = (sel.draw.y + row) - if (((y < 0) || (y >= height))) { - row++ - continue - } - run { - var col: Int = 0 - while ((col < atlas.width)) { - if ((atlas.nibbleAt(col, row) == 0)) { - col++ - continue - } - punchPixel(packed, stride, width, (sel.gx + col), y) - col++ - } - } - row++ + punchImage(packed, stride, width, height, sel.imageAtlas!!, sel.gx, sel.draw.y) + } + } + + /** Clear only visible nonzero image pixels, preserving the neighboring nibble. */ + private fun punchImage( + packed: ByteArray, + stride: Int, + width: Int, + height: Int, + atlas: ImageAtlas.Entry, + left: Int, + top: Int, + ) { + val pixels = atlas.nibbles + val imageWidth = atlas.width + val startX = maxOf(0, left) + val endX = minOf(width, left + imageWidth) + val endY = minOf(height, top + atlas.height) + var y = maxOf(0, top) + while (y < endY) { + var src = (y - top) * imageWidth + startX - left + val dstRow = y * stride + var x = startX + while (x < endX) { + if (pixels[src++].toInt() != 0) { + val index = dstRow + (x ushr 1) + val mask = if (x and 1 == 0) 15 else 240 + packed[index] = (packed[index].toInt() and mask).toByte() } + x++ } + y++ } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt index 2a8b21e7..8acc7d00 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt @@ -93,7 +93,7 @@ class ImageAtlas { /** The 4bpp value the mode-13 draw would write at (col, row); 0 = skipped. */ fun nibbleAt(col: Int, row: Int): Int { - return (nibbles[((row * width) + col)] and 0xff) + return nibbles[row * width + col].toInt() and 255 } private fun encodeCachedImage(): ByteArray { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index bc70d8d7..21f937ee 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -2,6 +2,7 @@ package com.faceclaw.app import kotlin.jvm.JvmField import kotlin.jvm.JvmStatic +import kotlin.jvm.JvmOverloads /** * Retained-surface compositor: the phone-side model of what is on the glasses screen. @@ -30,7 +31,7 @@ import kotlin.jvm.JvmStatic * atomically under an internal lock, and each composite carries a monotonic sequence number so * callers can detect when a composite was superseded by a concurrent one before being acted on. */ -class SurfaceCompositor { +class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFrames: Boolean = true) { companion object { const val TRANSPARENCY_OPAQUE: Int = 0 @@ -206,7 +207,11 @@ class SurfaceCompositor { class Composite { @JvmField var screenGray: ByteArray @JvmField var shellScene: ShellScene = ShellScene.EMPTY - /** Full-screen 8bpp grayscale pixels, screenWidth*screenHeight bytes. */ + /** + * Full-screen preview pixels. When includePreviewInFrames is false, + * submitted composites alias screenGray here; use previewComposite() + * for the shell/selection-rendered preview, screenshots or recording. + */ @JvmField val gray: ByteArray @JvmField val width: Int @@ -573,7 +578,7 @@ class SurfaceCompositor { return null } val seq = nextCompositeSeq - val result = compositeLocked() + val result = compositeLocked(includePreview = true) nextCompositeSeq = seq return result } @@ -594,7 +599,7 @@ class SurfaceCompositor { return gray } - private fun compositeLocked(): Composite { + private fun compositeLocked(includePreview: Boolean = includePreviewInFrames): Composite { var gray: ByteArray = ByteArray((screenWidth * screenHeight)) if (blanked) { return Composite( @@ -662,7 +667,7 @@ class SurfaceCompositor { } } val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene.EMPTY else ShellScene(shellScene?.layers ?: emptyList(), selections) - val preview = if (shellScene != null || selections.isNotEmpty()) scene.preview(gray, screenWidth, screenHeight) else gray + val preview = if (includePreview && (shellScene != null || selections.isNotEmpty())) scene.preview(gray, screenWidth, screenHeight) else gray return Composite(preview, screenWidth, screenHeight, fingerprint.append("|shell:").append(scene.fingerprint).toString(), nextCompositeSeq++, draws.toTypedArray()).also { it.screenGray = gray; it.shellScene = scene } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt index 1e3636db..b4815df1 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt @@ -13,7 +13,7 @@ class BmpUtil { } private val GRAY_TO_NIBBLE = - ByteArray(256) { v -> if (v == 0) 0 else minOf(15, (v + 8) shr 4).toByte() } + IntArray(256) { v -> minOf(15, (v + 8) shr 4) } /** * The 4bpp level an 8-bit gray value packs to. Public so the resource-cache planner computes @@ -22,7 +22,7 @@ class BmpUtil { */ @JvmStatic fun nibbleForGray(gray: Int): Int { - return (GRAY_TO_NIBBLE[(gray and 0xff)] and 0xff) + return GRAY_TO_NIBBLE[gray and 0xff] } /** @@ -37,32 +37,34 @@ class BmpUtil { if (((width <= 0) || (height <= 0))) { return ByteArray(0) } - var stride: Int = ((width + 1) shr 1) - var out: ByteArray = ByteArray((stride * height)) + val stride = (width + 1) ushr 1 + val out = ByteArray(stride * height) if (((gray8 == null) || (gray8.size < (width * height)))) { return out } - var pairs: Int = (width shr 1) - var src: Int = 0 - var dst: Int = 0 - run { - var y: Int = 0 - while ((y < height)) { - run { - var i: Int = 0 - while ((i < pairs)) { - out[dst++] = - (((GRAY_TO_NIBBLE[(gray8[src] and 0xff)] shl 4) or - (GRAY_TO_NIBBLE[(gray8[(src + 1)] and 0xff)] and 0xff))) - .toByte() - src += 2 - i++ - } + // Work with Ints: Byte.and / Byte.shl in ByteSink.kt are ordinary + // function calls, not Kotlin intrinsics. Avoid four calls per pair + // even in an interpreted/debug ART build, and load the LUT once. + val levels = GRAY_TO_NIBBLE + var src = 0 + var dst = 0 + if (width and 1 == 0) { + // No row padding: the common 640x480 frame is one linear loop. + while (dst < out.size) { + out[dst++] = ((levels[gray8[src].toInt() and 255] shl 4) or + levels[gray8[src + 1].toInt() and 255]).toByte() + src += 2 + } + } else { + repeat(height) { + val end = src + width - 1 + while (src < end) { + out[dst++] = ((levels[gray8[src].toInt() and 255] shl 4) or + levels[gray8[src + 1].toInt() and 255]).toByte() + src += 2 } - if (((width and 1) != 0)) { - out[dst++] = ((GRAY_TO_NIBBLE[(gray8[src++] and 0xff)] shl 4)).toByte() - } - y++ + // Pad each odd-width row with a zero low nibble. + out[dst++] = (levels[gray8[src++].toInt() and 255] shl 4).toByte() } } return out diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt index 86bf698e..e5177b95 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt @@ -1,9 +1,47 @@ package com.faceclaw.app import kotlin.test.* +import kotlin.random.Random class DisplayListTest { private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray() + @Test fun screenCopyPreservesOffsetsClippingPaddingAndAliasing() { + val random = Random(42) + val renderer = DisplayListRenderer(emptyMap()) + for (sourceWidth in listOf(1, 2, 3, 7, 8, 640)) for (destinationWidth in listOf(1, 2, 3, 7, 8, 640)) { + for (shared in listOf(false, true)) for (shift in listOf(-3, 0, 2)) { + val sourceHeight = random.nextInt(1, 5); val destinationHeight = random.nextInt(1, 5) + val sourceOffset = random.nextInt(4); val destinationOffset = random.nextInt(4) + val size = maxOf(sourceOffset + (sourceWidth + 1) / 2 * sourceHeight, + destinationOffset + (destinationWidth + 1) / 2 * destinationHeight) + 3 + val source = random.nextBytes(size) + val destination = if (shared) source else random.nextBytes(size) + val expectedSource = source.copyOf() + val expectedDestination = if (shared) expectedSource else destination.copyOf() + // Original per-pixel semantics, including cascading writes when + // views alias and ignoring shiftX when reading the source. + val referenceSource = DisplayListRenderer.Target(expectedSource, sourceWidth, sourceHeight, sourceOffset, 5) + val referenceDestination = DisplayListRenderer.Target(expectedDestination, destinationWidth, destinationHeight, destinationOffset, shift) + for (y in 0 until sourceHeight) for (x in 0 until sourceWidth) + referenceDestination.put(x, y, referenceSource.get(x, y)) + assertEquals(emptySet(), renderer.render(DrawProtocol.SCREEN, + DisplayListRenderer.Target(source, sourceWidth, sourceHeight, sourceOffset, 5), + DisplayListRenderer.Target(destination, destinationWidth, destinationHeight, destinationOffset, shift))) + assertContentEquals(expectedDestination, destination, "$sourceWidth/$destinationWidth shared=$shared shift=$shift") + assertContentEquals(expectedSource, source) + } + } + val source = random.nextBytes(640 * 480 / 2) + val destination = ByteArray(source.size) + renderer.render(DrawProtocol.SCREEN, DisplayListRenderer.Target(source,640,480), DisplayListRenderer.Target(destination,640,480)) + assertContentEquals(source, destination) + } + @Test fun invalidGraphDoesNotCopyScreenIntoComposition() { + val screen = hex("12345678"); val composition = hex("9abcdef0") + val resources = mapOf(1 to DrawProtocol.displayList(listOf(byteArrayOf(99,0)))) + assertFails { DisplayListRenderer(resources).render(1, DisplayListRenderer.Target(screen,8,1), DisplayListRenderer.Target(composition,8,1)) } + assertContentEquals(hex("9abcdef0"), composition) + } @Test fun oddPixelsRawRleClippingFontsNestedListsAndLut() { val raw = DrawProtocol.rawImage(3, 3, hex("123045607890")) val font = ByteArray(197); font[0]=1; font[67]=193.toByte(); hex("0801011f").copyInto(font,193) diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/PreviewPackingTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/PreviewPackingTest.kt new file mode 100644 index 00000000..7d197217 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/PreviewPackingTest.kt @@ -0,0 +1,67 @@ +package com.faceclaw.app + +import kotlin.test.* + +class PreviewPackingTest { + private fun level(value: Byte): Int = minOf(15, ((value.toInt() and 255) + 8) / 16) + + @Test + fun everyPairOfGrayValuesHasTheSameWireEncoding() { + val pixels = ByteArray(65536 * 2) { if (it % 2 == 0) (it / 512).toByte() else (it / 2).toByte() } + val packed = BmpUtil.pack4bppFromGray8(pixels, 512, 256) + for (i in packed.indices) { + assertEquals((level(pixels[i * 2]) * 16 + level(pixels[i * 2 + 1])).toByte(), packed[i], "pair $i") + } + for (v in 0..255) assertEquals(level(v.toByte()), BmpUtil.nibbleForGray(v)) + } + + @Test + fun oddWidthsPadEveryRowAndIgnoreTrailingInput() { + for (width in listOf(1, 3, 5, 639, 641)) { + val height = 7 + val pixels = ByteArray(width * height + 13) { (it * 73 + 19).toByte() } + val stride = (width + 1) / 2 + val packed = BmpUtil.pack4bppFromGray8(pixels, width, height) + assertEquals(stride * height, packed.size) + for (y in 0 until height) { + for (x in 0 until width) { + val byte = packed[y * stride + x / 2].toInt() and 255 + assertEquals(level(pixels[y * width + x]), if (x % 2 == 0) byte / 16 else byte % 16) + } + assertEquals(0, packed[(y + 1) * stride - 1].toInt() and 15) + } + } + assertContentEquals(ByteArray(4), BmpUtil.pack4bppFromGray8(null, 3, 2)) + assertContentEquals(ByteArray(4), BmpUtil.pack4bppFromGray8(ByteArray(5) { -1 }, 3, 2)) + assertTrue(BmpUtil.pack4bppFromGray8(null, 0, 2).isEmpty()) + } + + @Test + fun wireFramesSkipPreviewButExplicitReadbackIncludesLatestShellAndPixels() { + val compositor = SurfaceCompositor(false) + compositor.configureScreen(3, 2) + compositor.configureSurface("app", 0, 0, 3, 2, 0, SurfaceCompositor.TRANSPARENCY_OPAQUE) + // One white 2x1 shell layer at (0,0), with no dimming or selection. + val header = listOf(1, 1, 0, 0, 2, 1, 256, 0, 0).flatMap { listOf(it.toByte(), (it shr 8).toByte()) }.toByteArray() + compositor.setShellScene(ArrayByteReader(header + byteArrayOf(-16, -16))) + val wire = compositor.applyAndComposite("app", ArrayByteReader(ByteArray(6) { 32 }), 0, 0, 3, 2, "first") + assertSame(wire.screenGray, wire.gray) // ShellScene.preview allocates its own pixels. + assertContentEquals(ByteArray(6) { 32 }, wire.screenGray) + assertEquals(1, wire.shellScene.layers.size) + val preview = assertNotNull(compositor.previewComposite()) + assertContentEquals(byteArrayOf(-16, -16, 32, 32, 32, 32), preview.gray) + assertEquals(wire.fingerprint, preview.fingerprint) + assertContentEquals(wire.screenGray, preview.screenGray) + + // Updates while hidden retain the newest frame. Preview reads don't + // consume the wire sequence or affect the next submitted frame. + val newer = compositor.applyAndComposite("app", ArrayByteReader(ByteArray(6) { 64 }), 0, 0, 3, 2, "second") + assertEquals(wire.seq + 1, newer.seq) + assertSame(newer.screenGray, newer.gray) + assertContentEquals(byteArrayOf(-16, -16, 64, 64, 64, 64), compositor.previewComposite()!!.gray) + compositor.setBlanked(true) + assertContentEquals(ByteArray(6), compositor.previewComposite()!!.gray) + compositor.setBlanked(false) + assertContentEquals(byteArrayOf(-16, -16, 64, 64, 64, 64), compositor.previewComposite()!!.gray) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt index 2666890b..44c84e9c 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResourceCacheTest.kt @@ -126,6 +126,51 @@ class ResourceCacheTest { assertNull(TexturePlanner.plan(null, ByteArray(packed.size), 8, 4, draws, cache, 1, true, 8, testPlatform())) } + @Test fun imagePixelLoopsPreserveClippingTransparencyAndNeighborNibbles() { + val width = 12 + val height = 8 + for (imageWidth in listOf(3, 4, 5, 9)) { + val imageHeight = 5 + val pixels = ByteArray(imageWidth * imageHeight) { i -> + if (i % 3 == 0) 0 else (((i % 15) + 1) * 16).toByte() + } + val id = ImageAtlas.ensure("pixel-loop-$imageWidth", imageWidth, imageHeight, ArrayByteReader(pixels)) + for (left in listOf(-1, 0, 1, 2, 10, 11, 14)) for (top in listOf(-1, 0, 1, 7, 9)) { + val gray = ByteArray(width * height) { ((it % 15 + 1) * 16).toByte() } + val visibleInk = ArrayList() + for (row in 0 until imageHeight) for (col in 0 until imageWidth) { + val x = left + col; val y = top + row; val value = pixels[row * imageWidth + col] + if (x in 0 until width && y in 0 until height && value.toInt() != 0) { + gray[y * width + x] = value + visibleInk.add(y * width + x) + } + } + val expected = BmpUtil.pack4bppFromGray8(gray, width, height) + val draws = arrayOf(SurfaceCompositor.ScreenDraw.image(id, left, top)) + val plan = TexturePlanner.plan(null, expected, width, height, draws, ResourceCacheState(), 1, true, 8, testPlatform()) + if (left < 0 || top < 0 || left >= width || top >= height) { + assertNull(plan) // The wire format cannot replay negative image origins. + continue + } + val result = assertNotNull(plan, "$imageWidth at $left,$top") + assertEquals(1, result.drawnImages) + val actual = ByteArray(expected.size) { 0x55 } + DisplayListRenderer(uploaded(result.resourceCommands)).execute( + DrawProtocol.sequence(DrawProtocol.fromOptimized(result.payload, width, height)), + DisplayListRenderer.Target(actual, width, height)) + assertContentEquals(expected, actual, "$imageWidth at $left,$top") + + // A conflicting visible ink pixel must reject the cached draw. + if (visibleInk.isNotEmpty()) { + val offset = visibleInk.first() + gray[offset] = 0 + assertNull(TexturePlanner.plan(null, BmpUtil.pack4bppFromGray8(gray, width, height), + width, height, draws, ResourceCacheState(), 1, true, 8, testPlatform())) + } + } + } + } + private fun registerFont(key: String, encodings: List, size: Int = 2): Int { val out = ByteSink(); val name = key.encodeToByteArray() out.write(name.size); out.write(name, 0, name.size); out.write(size) diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RleEncoderTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RleEncoderTest.kt new file mode 100644 index 00000000..6893b422 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RleEncoderTest.kt @@ -0,0 +1,65 @@ +package com.faceclaw.app + +import kotlin.random.Random +import kotlin.test.* + +class RleEncoderTest { + /** Deliberately simple per-pixel reference, independent of the byte scan. */ + private fun reference(packed: ByteArray): ByteArray { + val output = ArrayList() + var color = -1 + var count = 0 + fun flush() { + while (count > 0) { + val n = minOf(count, 65535) + when { + n <= 15 -> output.add((n * 16 + color).toByte()) + n <= 255 -> { output.add(color.toByte()); output.add(n.toByte()) } + else -> { output.add(color.toByte()); output.add(0); output.add(n.toByte()); output.add((n / 256).toByte()) } + } + count -= n + } + } + for (byte in packed) for (pixel in listOf((byte.toInt() and 255) / 16, byte.toInt() and 15)) { + if (pixel != color) { flush(); color = pixel } + count++ + } + flush() + return output.toByteArray() + } + + @Test fun allTwoByteInputsPreserveExactTokensAcrossNibbleBoundaries() { + for (value in 0..65535) { + val packed = byteArrayOf((value / 256).toByte(), value.toByte()) + assertContentEquals(reference(packed), BleImageOptimizer.rleEncode(packed), "input $value") + } + assertContentEquals(ByteArray(0), BleImageOptimizer.rleEncode(ByteArray(0))) + } + + @Test fun longRunsAndEveryTokenBoundaryAtBothNibbleAlignments() { + for (length in listOf(1, 2, 14, 15, 16, 254, 255, 256, 65534, 65535, 65536, 131070, 131071)) { + for (prefix in 0..1) for (color in listOf(0, 7, 15)) { + val values = List(prefix) { (color + 1) % 16 } + List(length) { color } + listOf((color + 2) % 16) + val packed = ByteArray((values.size + 1) / 2) { i -> + (values[i * 2] * 16 + (values.getOrNull(i * 2 + 1) ?: 0)).toByte() + } + assertContentEquals(reference(packed), BleImageOptimizer.rleEncode(packed), "$prefix/$length/$color") + } + } + } + + @Test fun noiseAndMixedRunsPreserveExactWireOutput() { + val random = Random(123) + repeat(100) { + val data = random.nextBytes(random.nextInt(1, 4096)) + assertContentEquals(reference(data), BleImageOptimizer.rleEncode(data)) + repeat(20) { + val start = random.nextInt(data.size) + data.fill((random.nextInt(16) * 17).toByte(), start, minOf(data.size, start + random.nextInt(1, 200))) + } + assertContentEquals(reference(data), BleImageOptimizer.rleEncode(data)) + } + val screen = ByteArray(640 * 480 / 2) { 0x77 } + assertContentEquals(reference(screen), BleImageOptimizer.rleEncode(screen)) + } +} diff --git a/tests/phone-preview.test.cjs b/tests/phone-preview.test.cjs new file mode 100644 index 00000000..71a5709d --- /dev/null +++ b/tests/phone-preview.test.cjs @@ -0,0 +1,86 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const vm = require('node:vm'); +const ts = require('typescript'); + +// Exercise the controller's real methods without starting BLE or the app shell. +function harness() { + const source = ts.createSourceFile('controller.ts', fs.readFileSync('app/g2/dashboard-controller.ts', 'utf8'), ts.ScriptTarget.Latest, true); + const controller = source.statements.find(node => ts.isClassDeclaration(node) && node.name.text === 'DashboardController'); + const names = ['attachPhonePreview', 'schedulePreviewUpdate', 'updateCompositePreview']; + const methods = names.map(name => controller.members.find(node => node.name?.getText(source) === name).getText(source)); + let now = 1000, focus = true, interactive = true, activityPresent = true, previews = 0, records = 0; + const timers = new Map(); + const activity = { hasWindowFocus: () => focus, getSystemService: () => ({ isInteractive: () => interactive }) }; + const context = { exports: {}, global: { isAndroid: true }, + Application: { android: { get foregroundActivity() { return activityPresent ? activity : null; } } }, + android: { content: { Context: { POWER_SERVICE: 'power' } } }, + Date: { now: () => now }, CONNECTED_PREVIEW_MIN_UPDATE_MS: 100, RECORDING_MIN_CAPTURE_MS: 200, + previewColorSetting: { get: () => 'green' }, + setTimeout: fn => { const id = timers.size + 1; timers.set(id, fn); return id; }, + clearTimeout: id => timers.delete(id), + }; + vm.runInNewContext(ts.transpileModule(`export class Harness { ${methods.join('\n')} }`, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText, context); + const instance = new context.exports.Harness(); + Object.assign(instance, { lastConnectedPreviewUpdateAtMs: 0, lastRecordCaptureAtMs: 0, + phonePreviewVisible: null, previewTrailingTimer: null, screenRecordingActive: false, + display: { getCompositePreview: () => { previews++; return {}; }, recordScreenFrame: () => records++ }, + setDisplayPreview() {}, + }); + return { instance, timers, previews: () => previews, records: () => records, + tick: (ms = 1000) => { now += ms; instance.updateCompositePreview(); }, + focus: value => { focus = value; }, interactive: value => { interactive = value; }, + activity: value => { activityPresent = value; } }; +} + +test('phone preview skips hidden pages, background activity and screen off; resumes with latest frame', () => { + const h = harness(); + h.tick(); + assert.equal(h.previews(), 0); + let shown = true; + const detach = h.instance.attachPhonePreview(() => shown); + assert.equal(h.previews(), 1); + shown = false; h.tick(); + shown = true; h.focus(false); h.tick(); + h.focus(true); h.interactive(false); h.tick(); + h.interactive(true); h.activity(false); h.tick(); + assert.equal(h.previews(), 1); + h.activity(true); h.tick(); + assert.equal(h.previews(), 2); + detach(); h.tick(); + assert.equal(h.previews(), 2); +}); + +test('explicit GIF recording continues without rendering a hidden phone bitmap', () => { + const h = harness(); + h.instance.screenRecordingActive = true; + h.instance.attachPhonePreview(() => true); + h.interactive(false); + h.tick(); h.tick(100); h.tick(100); + assert.equal(h.records(), 3); + assert.equal(h.previews(), 1); + h.instance.phonePreviewVisible = null; + h.tick(); + assert.equal(h.records(), 4); + h.instance.screenRecordingActive = false; + h.tick(); + assert.equal(h.records(), 4); +}); + +test('page detach cancels trailing previews and cannot detach a newer page', () => { + const h = harness(); + const oldDetach = h.instance.attachPhonePreview(() => true); + const newDetach = h.instance.attachPhonePreview(() => true); + oldDetach(); + h.tick(); + assert.equal(h.previews(), 3); + h.instance.schedulePreviewUpdate(); + assert.equal(h.timers.size, 1); + newDetach(); + assert.equal(h.timers.size, 0); + h.instance.schedulePreviewUpdate(); + assert.equal(h.timers.size, 0); +}); diff --git a/tests/remote-input-native.cjs b/tests/remote-input-native.cjs index 392215aa..d39d1f43 100644 --- a/tests/remote-input-native.cjs +++ b/tests/remote-input-native.cjs @@ -21,17 +21,20 @@ int main(int argc, const char **argv) { @autoreleasepool { NSString *failure = [server start:atoi(argv[1])]; if (failure.length) return 3; puts("READY"); fflush(stdout); - for (;;) { @autoreleasepool { + __weak FaceclawRemoteInput *weakServer = server; + [server setRequestListener:^{ @autoreleasepool { + FaceclawRemoteInput *server = weakServer; + if (![NSThread isMainThread]) exit(4); NSString *raw = [server nextRequest]; if (raw) { NSDictionary *request = [NSJSONSerialization JSONObjectWithData:[raw dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; NSDictionary *body = [NSJSONSerialization JSONObjectWithData:[request[@"body"] dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; - if ([body[@"text"] isEqual:@"stop"]) { [server stop]; usleep(300000); puts("STOPPED"); fflush(stdout); return 0; } + if ([body[@"text"] isEqual:@"stop"]) { [server stop]; usleep(300000); puts("STOPPED"); fflush(stdout); exit(0); } NSData *reply = [NSJSONSerialization dataWithJSONObject:@{@"ok":@YES, @"echo":body ?: @{}} options:0 error:nil]; [server complete:[request[@"id"] longLongValue] response:[[NSString alloc] initWithData:reply encoding:NSUTF8StringEncoding]]; } - usleep(1000); - }} + }}]; + [[NSRunLoop mainRunLoop] run]; }} `); const binary = path.join(directory, 'probe'); @@ -66,7 +69,7 @@ int main(int argc, const char **argv) { @autoreleasepool { await send(options, { action: 'input', gesture: 'click' }); await assert.rejects(send(options, { action: 'text', text: 'stop' })); assert.equal(await exited, 0); - console.log('Native socket probe passed: crypto, framing, UTF-8, multiple connections, shutdown.'); + console.log('Native socket probe passed: crypto, framing, UTF-8, main-thread request notifications, multiple connections, shutdown.'); } finally { child.kill(); } } main().catch(error => { console.error(error); process.exitCode = 1; }).finally(() => fs.rmSync(directory, { recursive: true, force: true })); diff --git a/tests/remote-service.test.cjs b/tests/remote-service.test.cjs new file mode 100644 index 00000000..3d7d75ba --- /dev/null +++ b/tests/remote-service.test.cjs @@ -0,0 +1,83 @@ +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const vm = require('node:vm'); +const ts = require('typescript'); + +function fixture() { + let ready, changed, tokens = [{}], polls = 0, active = 0, maxActive = 0; + const queue = [], replies = [], timers = new Map(), handled = []; + const native = { + start() {}, addresses: () => ['127.0.0.1'], stop: () => { queue.length = 0; }, + nextRequest() { polls++; return queue.length ? JSON.stringify(queue.shift()) : null; }, + complete: (id, response) => replies.push({ id, ...JSON.parse(response) }), + }; + let handle = async body => ({ ok: true, body }); + const modules = { + '../native/settings-store': { getStringSetting: (_k, d) => d, setStringSetting() {}, + onSettingsStoreChanged: cb => { changed = cb; return () => { changed = null; }; } }, + '../native/remote-input': { remoteNative: cb => { ready = cb; return native; }, remoteInterfaces: () => [], + randomTokenSecret() {}, tokenHash() {} }, + './listeners': require('../.test-build/app/remote/listeners.js'), + './protocol': { TokenStore: class { list() { return tokens; } }, REMOTE_PORT: 8791, + handleRequest: async body => { + handled.push(body); active++; maxActive = Math.max(maxActive, active); + try { return await handle(body); } finally { active--; } + } }, + }; + const context = { exports: {}, require: id => modules[id], + setInterval: (fn, ms) => { timers.set(fn, ms); return fn; }, clearInterval: id => timers.delete(id) }; + vm.runInNewContext(ts.transpileModule(fs.readFileSync('app/remote/service.ts', 'utf8'), { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText, context); + const stop = context.exports.startRemoteInput({}); + return { stop, timers, replies, handled, get polls() { return polls; }, get maxActive() { return maxActive; }, + setHandle: fn => { handle = fn; }, + notify: () => ready(), enqueue: (id, expiresAt = Date.now() + 5000) => queue.push({ id, body: id, expiresAt }), + tokens: value => { tokens = value; changed('remoteInput.tokens.v1'); }, + }; +} +const settle = () => new Promise(resolve => setImmediate(resolve)); + +test('idle remote sockets do not poll native requests, including network reconciliation', () => { + const f = fixture(); + assert.deepEqual([...f.timers.values()], [3000]); + for (let i = 0; i < 100; i++) for (const tick of f.timers.keys()) tick(); + assert.equal(f.polls, 0); + f.stop(); assert.equal(f.timers.size, 0); +}); + +test('request notifications drain serially without losing wakeups while busy', async () => { + const f = fixture(); let release; + f.setHandle(body => body === 'a' ? new Promise(resolve => { release = resolve; }) : { ok: true }); + f.enqueue('a'); f.notify(); + f.enqueue('b'); f.notify(); f.enqueue('c'); f.notify(); + assert.deepEqual(f.handled, ['a']); + release({ ok: true }); await settle(); + assert.deepEqual(f.handled, ['a', 'b', 'c']); + assert.deepEqual(f.replies.map(r => r.id), ['a', 'b', 'c']); + assert.equal(f.maxActive, 1); + const idlePolls = f.polls; await settle(); assert.equal(f.polls, idlePolls); + f.stop(); +}); + +test('expired requests and failed handlers do not prevent queued requests from draining', async () => { + const f = fixture(); f.setHandle(body => { if (body === 'bad') throw Error('test'); return { ok: true }; }); + f.enqueue('expired', 0); f.enqueue('bad'); f.enqueue('good'); f.notify(); await settle(); + assert.deepEqual(f.handled, ['bad', 'good']); + assert.equal(f.replies[0].error, 'failed'); assert.equal(f.replies[1].ok, true); + f.stop(); +}); + +test('token removal and service shutdown stop dispatch, and re-enabling tokens resumes it', async () => { + const f = fixture(); + f.enqueue('removed'); f.tokens([]); f.notify(); await settle(); + assert.deepEqual(f.handled, []); assert.equal(f.timers.size, 0); + f.tokens([{}]); f.enqueue('resumed'); f.notify(); await settle(); + assert.deepEqual(f.handled, ['resumed']); + let release; f.setHandle(() => new Promise(resolve => { release = resolve; })); + f.enqueue('in-flight'); f.notify(); f.stop(); + f.enqueue('late'); f.notify(); release({ ok: true }); await settle(); + assert.deepEqual(f.replies.map(r => r.id), ['resumed']); + assert.deepEqual(f.handled, ['resumed', 'in-flight']); +}); From 2e4d20e1300a3f2ee06ca624920f86daf782aa0a Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 14:56:54 -0700 Subject: [PATCH 07/27] Clean up unused worker threads for closed apps; other performance optimizations --- .../com/faceclaw/app/PreviewBitmapUtil.java | 27 +++- app/apps/blocks/blocks-app.worker.ts | 7 + app/apps/flappy/flappy-app.worker.ts | 7 + app/apps/freecell/freecell-app.worker.ts | 7 + app/apps/glanceboard/configuration.ts | 11 ++ .../minesweeper/minesweeper-app.worker.ts | 7 + app/apps/navigate/navigate-app.worker.ts | 7 + app/apps/pinball/pinball-app.worker.ts | 7 + app/apps/roam/roam-app.worker.ts | 7 + app/apps/terminal/background.ts | 8 + app/apps/terminal/terminal-app.worker.ts | 32 +++- app/g2/dashboard-controller.ts | 1 + app/g2/ios-preview-controller.ts | 1 + app/native/settings-store.ios.ts | 6 + app/native/settings-store.ts | 7 + app/ui/shell/worker-lifecycle.ts | 7 + app/ui/shell/worker-window.ts | 50 +++++++ .../app/graphics/DisplayListRenderer.kt | 32 +++- tests/terminal-activity.test.cjs | 1 + tests/worker-lifecycle.test.cjs | 141 ++++++++++++++++++ 20 files changed, 360 insertions(+), 13 deletions(-) create mode 100644 app/apps/glanceboard/configuration.ts create mode 100644 app/apps/terminal/background.ts create mode 100644 app/ui/shell/worker-lifecycle.ts create mode 100644 tests/worker-lifecycle.test.cjs diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java b/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java index 4b599d67..2a37ad7d 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java @@ -12,8 +12,29 @@ import java.nio.ByteBuffer; * JS/Java bridge, where it used to cost ~150ms per preview. */ public final class PreviewBitmapUtil { + private static int[] cachedLut; + private static long cachedGammaBits; + private static boolean cachedGreen; + private PreviewBitmapUtil() {} + /** Reuse the current preview palette; rebuild only when gamma or color changes. */ + private static synchronized int[] lookupTable(double brightenGamma, boolean green) { + long gammaBits = Double.doubleToLongBits(brightenGamma); + if (cachedLut != null && cachedGammaBits == gammaBits && cachedGreen == green) { + return cachedLut; + } + int[] lut = new int[256]; + for (int g = 0; g < 256; g++) { + int v = (int) Math.max(0, Math.min(255, Math.round(255 * Math.pow(g / 255.0, brightenGamma)))); + lut[g] = green ? (0xff000000 | (v << 8)) : (0xff000000 | (v << 16) | (v << 8) | v); + } + cachedGammaBits = gammaBits; + cachedGreen = green; + cachedLut = lut; + return lut; + } + public static Bitmap fromGray(ByteBuffer gray, int width, int height, double brightenGamma) { return fromGray(gray, width, height, brightenGamma, false); } @@ -23,11 +44,7 @@ public final class PreviewBitmapUtil { if (gray == null || width <= 0 || height <= 0 || gray.remaining() < width * height) { throw new IllegalArgumentException("invalid gray preview buffer"); } - int[] lut = new int[256]; - for (int g = 0; g < 256; g++) { - int v = (int) Math.max(0, Math.min(255, Math.round(255 * Math.pow(g / 255.0, brightenGamma)))); - lut[g] = green ? (0xff000000 | (v << 8)) : (0xff000000 | (v << 16) | (v << 8) | v); - } + int[] lut = lookupTable(brightenGamma, green); byte[] bytes = new byte[width * height]; gray.get(bytes); int[] colors = new int[width * height]; diff --git a/app/apps/blocks/blocks-app.worker.ts b/app/apps/blocks/blocks-app.worker.ts index 67566f92..b17adaf0 100644 --- a/app/apps/blocks/blocks-app.worker.ts +++ b/app/apps/blocks/blocks-app.worker.ts @@ -11,6 +11,7 @@ * focus, tap-then-hold opens the window menu. */ import "@nativescript/core/globals"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -187,6 +188,12 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + post({ type: "worker-idle" }); + break; + case "shutdown": + finishWorkerShutdown(); + break; case "open-window": { const window: BlocksWindow = { windowId: message.windowId, diff --git a/app/apps/flappy/flappy-app.worker.ts b/app/apps/flappy/flappy-app.worker.ts index c0e91451..d880c239 100644 --- a/app/apps/flappy/flappy-app.worker.ts +++ b/app/apps/flappy/flappy-app.worker.ts @@ -25,6 +25,7 @@ * focus to the sidebar) pauses, as does backgrounding or screen-off. */ import "@nativescript/core/globals"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -180,6 +181,12 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + post({ type: "worker-idle" }); + break; + case "shutdown": + finishWorkerShutdown(); + break; case "open-window": { const window: FlappyWindow = { windowId: message.windowId, diff --git a/app/apps/freecell/freecell-app.worker.ts b/app/apps/freecell/freecell-app.worker.ts index f829dfc8..ae4f2dc0 100644 --- a/app/apps/freecell/freecell-app.worker.ts +++ b/app/apps/freecell/freecell-app.worker.ts @@ -18,6 +18,7 @@ * Safe cards auto-play to the foundations after every move. */ import "@nativescript/core/globals"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -144,6 +145,12 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + post({ type: "worker-idle" }); + break; + case "shutdown": + finishWorkerShutdown(); + break; case "open-window": { const window: FreecellWindow = { windowId: message.windowId, diff --git a/app/apps/glanceboard/configuration.ts b/app/apps/glanceboard/configuration.ts new file mode 100644 index 00000000..a783df47 --- /dev/null +++ b/app/apps/glanceboard/configuration.ts @@ -0,0 +1,11 @@ +import { getStringSetting } from "../../native/settings-store"; +import { QUADRANT_LAYOUT, SIX_SLOT_LAYOUT } from "./layout"; + +/** Configuration-only query usable by workers without loading widget/UI modules. */ +export function isTerminalWidgetConfigured(): boolean { + const layout = getStringSetting("glanceboard.layout", "2x2") === "2x3" ? SIX_SLOT_LAYOUT : QUADRANT_LAYOUT; + // Both layouts store their slots under the original quadrants key. None + // of the default slots needs a worker, so absent keys cannot retain one. + return layout.slots.some((_, index) => + getStringSetting(`glanceboard.${QUADRANT_LAYOUT.id}.slot.${index}`, "none") === "terminal"); +} diff --git a/app/apps/minesweeper/minesweeper-app.worker.ts b/app/apps/minesweeper/minesweeper-app.worker.ts index dcb4189d..ebc22c9f 100644 --- a/app/apps/minesweeper/minesweeper-app.worker.ts +++ b/app/apps/minesweeper/minesweeper-app.worker.ts @@ -18,6 +18,7 @@ * launches. */ import "@nativescript/core/globals"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -152,6 +153,12 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + post({ type: "worker-idle" }); + break; + case "shutdown": + finishWorkerShutdown(); + break; case "open-window": { const window: MinesweeperWindow = { windowId: message.windowId, diff --git a/app/apps/navigate/navigate-app.worker.ts b/app/apps/navigate/navigate-app.worker.ts index 0acefbc9..5bfa6194 100644 --- a/app/apps/navigate/navigate-app.worker.ts +++ b/app/apps/navigate/navigate-app.worker.ts @@ -7,6 +7,7 @@ * guidance text (right pane) updates per GPS fix and ships as small deltas. */ import "@nativescript/core/globals"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -275,6 +276,12 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + post({ type: "worker-idle" }); + break; + case "shutdown": + finishWorkerShutdown(); + break; case "navigation-sensors": handleNavigationSensorEvent(message.event); break; diff --git a/app/apps/pinball/pinball-app.worker.ts b/app/apps/pinball/pinball-app.worker.ts index 23abb009..80c4b1b4 100644 --- a/app/apps/pinball/pinball-app.worker.ts +++ b/app/apps/pinball/pinball-app.worker.ts @@ -21,6 +21,7 @@ * sidebar) pauses, as does backgrounding or screen-off. */ import "@nativescript/core/globals"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -290,6 +291,12 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + post({ type: "worker-idle" }); + break; + case "shutdown": + finishWorkerShutdown(); + break; case "open-window": { const window: PinballWindow = { windowId: message.windowId, diff --git a/app/apps/roam/roam-app.worker.ts b/app/apps/roam/roam-app.worker.ts index f35d09b3..5ec556eb 100644 --- a/app/apps/roam/roam-app.worker.ts +++ b/app/apps/roam/roam-app.worker.ts @@ -8,6 +8,7 @@ * menu, via the phone app's text editor. */ import "@nativescript/core/globals"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, singlePlane, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -165,6 +166,12 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + post({ type: "worker-idle" }); + break; + case "shutdown": + finishWorkerShutdown(); + break; case "open-window": window = { windowId: message.windowId, diff --git a/app/apps/terminal/background.ts b/app/apps/terminal/background.ts new file mode 100644 index 00000000..73e74aaa --- /dev/null +++ b/app/apps/terminal/background.ts @@ -0,0 +1,8 @@ +import { isTerminalWidgetConfigured } from "../glanceboard/configuration"; +import { loadConnections, parseConnectionString } from "./connections"; + +/** Keep session-list connections alive for a configured widget, even while it is hidden. */ +export function hasTerminalBackgroundWork(): boolean { + return isTerminalWidgetConfigured() && + loadConnections().some(connection => connection.enabled && parseConnectionString(connection.url) !== null); +} diff --git a/app/apps/terminal/terminal-app.worker.ts b/app/apps/terminal/terminal-app.worker.ts index cf914747..29c112ce 100644 --- a/app/apps/terminal/terminal-app.worker.ts +++ b/app/apps/terminal/terminal-app.worker.ts @@ -31,6 +31,8 @@ * re-attach snapshot resyncs contents and scrollback only once it's needed. */ import "@nativescript/core/globals"; +import { hasTerminalBackgroundWork } from "./background"; +import { finishWorkerShutdown } from "../../ui/shell/worker-lifecycle"; import { GrayImage, type UiFont } from "../../graphics/image"; import { flattenPlanesWithDraws, planesFingerprint, type Plane } from "../../graphics/plane"; import { prepareFrameDraws } from "../../graphics/glyph-wire"; @@ -311,6 +313,14 @@ post({ type: "worker-ready" }); global.onmessage = (event: { data: WorkerAppMessage }) => { const message = event.data; switch (message.type) { + case "check-idle": + reportIdle(); + break; + case "shutdown": + for (const control of controls.values()) stopControl(control); + controls.clear(); + finishWorkerShutdown(); + break; case "open-window": openWindow(message.windowId, message.surfaceId, message.title, message.viewport); break; @@ -424,12 +434,17 @@ global.onmessage = (event: { data: WorkerAppMessage }) => { // toggles edited in the Settings app, the Add-connection draft typed on the // phone). onSettingsStoreChanged((key) => { + if (key.startsWith("glanceboard.")) { + reportIdle(); + return; + } if (!key.startsWith("terminal.")) return; switch (key) { case TERMINAL_CONNECTIONS_KEY: // Only once the app has actually been opened. if (controlsInitialized) syncControlsFromSettings(); renderHubWindows(); + reportIdle(); return; case NEW_CONNECTION_DRAFT_KEY: // Live keystrokes from the phone editor; repaint the add screen. @@ -438,7 +453,7 @@ onSettingsStoreChanged((key) => { case "terminal.autoReconnect": if (!terminalAutoReconnectSetting.get()) { cancelPendingReconnects(); - } else if (windows.size > 0) { + } else if (windows.size > 0 || hasTerminalBackgroundWork()) { for (const control of controls.values()) { if ((control.state?.phase ?? "idle") === "failed") scheduleControlReconnect(control); } @@ -450,6 +465,10 @@ onSettingsStoreChanged((key) => { } }); +function reportIdle(): void { + if (windows.size === 0 && !hasTerminalBackgroundWork()) post({ type: "worker-idle" }); +} + /** Cancel scheduled retries (auto-reconnect turned off); stale views stay marked. */ function cancelPendingReconnects(): void { for (const control of controls.values()) { @@ -521,8 +540,8 @@ function closeWindow(windowId: string): void { windows.delete(windowId); windowIconActivity.delete(windowId); updateHubAnimation(); - // Auto-reconnect only runs while at least one terminal window is open. - if (windows.size === 0) { + // A configured widget owns the control connections after the last window closes. + if (windows.size === 0 && !hasTerminalBackgroundWork()) { for (const control of controls.values()) { cancelControlReconnect(control); } @@ -676,19 +695,18 @@ function noteSessionListRecency(control: ControlConnection, state: G2MirrorState /** * Retry a control connection after a backoff delay. The delay doubles per * scheduled attempt and resets when a connection reaches "connected" (or on - * a manual Connect). No-op when auto-reconnect is off, no terminal window is - * open, or the connection was disabled/removed meanwhile. + * a manual Connect). Windows and a configured widget can both own the client. */ function scheduleControlReconnect(control: ControlConnection): void { if (control.reconnectTimer) return; if (!terminalAutoReconnectSetting.get()) return; - if (windows.size === 0) return; + if (windows.size === 0 && !hasTerminalBackgroundWork()) return; if (!control.config.enabled) return; const delayMs = control.reconnectDelayMs; control.reconnectDelayMs = Math.min(control.reconnectDelayMs * 2, RECONNECT_MAX_DELAY_MS); control.reconnectTimer = setTimeout(() => { control.reconnectTimer = null; - if (!terminalAutoReconnectSetting.get() || windows.size === 0) return; + if (!terminalAutoReconnectSetting.get() || (windows.size === 0 && !hasTerminalBackgroundWork())) return; if (controls.get(control.config.id) !== control || !control.config.enabled) return; if ((control.state?.phase ?? "idle") === "failed") startControl(control); }, delayMs); diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 3db547e3..a1d0bde9 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -2228,6 +2228,7 @@ class DashboardController { const host = new WorkerAppHost({ appId, worker: createWorker(), + onStopping: () => { if (this.appHosts.get(appId) === host) this.appHosts.delete(appId); }, configureSurface: (surfaceId, visible, heightMode) => this.configureWindowSurface(surfaceId, visible, heightMode), setSurfaceVisible: (surfaceId, visible) => this.setWindowSurfaceVisible(surfaceId, visible), diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts index 14246b00..644723a8 100644 --- a/app/g2/ios-preview-controller.ts +++ b/app/g2/ios-preview-controller.ts @@ -503,6 +503,7 @@ export class IosPreviewController { ? new IosNavigationSensors(event => worker.postMessage({ type: 'navigation-sensors', event })) : undefined const host = new WorkerAppHost({ appId, worker, navigationSensors, + onStopping: () => { if (this.appHosts.get(appId) === host) this.appHosts.delete(appId) }, playBuzzerSequence: payload => this.actions.playBuzzerSequence(payload), openUrl: url => { void Utils.openUrl(url) }, configureSurface: async (id, visible, heightMode) => { diff --git a/app/native/settings-store.ios.ts b/app/native/settings-store.ios.ts index 7ffd322f..84d49add 100644 --- a/app/native/settings-store.ios.ts +++ b/app/native/settings-store.ios.ts @@ -18,6 +18,12 @@ function markChanged(key: string): void { } let pollTimer: ReturnType | null = null const listeners = new Set<(key: string) => void>() +export function disposeSettingsStore(): void { + listeners.clear() + if (pollTimer !== null) clearInterval(pollTimer) + pollTimer = null + observed.clear() +} function changed(key: string): void { setTimeout(() => { for (const listener of [...listeners]) listener(key) }, 0) } diff --git a/app/native/settings-store.ts b/app/native/settings-store.ts index e738f410..3f3f43da 100644 --- a/app/native/settings-store.ts +++ b/app/native/settings-store.ts @@ -14,6 +14,13 @@ let javaInstance: any = null; let retainedListenerProxy: any = null; const changeListeners = new Set<(key: string) => void>(); +/** Release this isolate's native observer before its worker is terminated. */ +export function disposeSettingsStore(): void { + changeListeners.clear(); + if (retainedListenerProxy !== null) getJava().unregisterListener(retainedListenerProxy); + retainedListenerProxy = null; +} + function getJava(): any { if (javaInstance === null) { const context = Utils.android?.getApplicationContext?.(); diff --git a/app/ui/shell/worker-lifecycle.ts b/app/ui/shell/worker-lifecycle.ts new file mode 100644 index 00000000..f89bbdef --- /dev/null +++ b/app/ui/shell/worker-lifecycle.ts @@ -0,0 +1,7 @@ +import { disposeSettingsStore } from "../../native/settings-store"; + +/** Called on the worker after its windows and app-owned resources are closed. */ +export function finishWorkerShutdown(): void { + disposeSettingsStore(); + global.postMessage({ type: "worker-stopped" }); +} diff --git a/app/ui/shell/worker-window.ts b/app/ui/shell/worker-window.ts index adf510b5..1657644d 100644 --- a/app/ui/shell/worker-window.ts +++ b/app/ui/shell/worker-window.ts @@ -15,6 +15,10 @@ import { publishWorkerState } from "./worker-state"; * worker→Java directly on Android; iOS posts baked frames to the main host. */ export type WorkerAppMessage = + /** Last host window closed: report worker-idle unless background work still owns the worker. */ + | { type: "check-idle" } + /** Release app-wide resources, then acknowledge with worker-stopped. */ + | { type: "shutdown" } | { type: "navigation-sensors"; event: NavigationSensorEvent } | { type: "open-window"; windowId: string; surfaceId: string; title: string; viewport: { width: number; height: number } } | { type: "resize-window"; windowId: string; viewport: { width: number; height: number } } @@ -34,6 +38,8 @@ export type WorkerAppMessage = | { type: "tool-call"; callId: string; windowId: string; name: string; args: unknown }; export type WorkerAppReply = + | { type: "worker-idle" } + | { type: "worker-stopped" } | { type: "buzzer-sequence"; payload: number[] } | { type: "navigation-sensors"; request: NavigationSensorRequest } | { type: "open-url"; url: string } @@ -182,6 +188,8 @@ export type WorkerWindowSpec = { export type WorkerAppHostOptions = { appId: string; worker: Worker; + /** Drop this host from the app cache as soon as shutdown begins. */ + onStopping?: () => void; navigationSensors?: { handle(request: NavigationSensorRequest): void; stop(): void }; openUrl?: (url: string) => void; playBuzzerSequence?: (payload: Uint8Array) => Promise | void; @@ -236,12 +244,23 @@ export class WorkerAppHost { */ private workerReady = false; private readonly queuedMessages: WorkerAppMessage[] = []; + private stopping = false; + private terminated = false; + private shutdownTimer: ReturnType | null = null; + private readonly publishedStateKeys = new Set(); constructor(private readonly options: WorkerAppHostOptions) { options.worker.onmessage = (event: MessageEvent) => { const message = event.data as WorkerAppReply | undefined; if (!message) return; + if (this.stopping) { + if (message.type === "worker-stopped") this.terminate(); + return; + } switch (message.type) { + case "worker-idle": + if (!this.openWindows.size) this.shutdown(); + break; case "buzzer-sequence": if (this.openWindows.size) { void Promise.resolve(this.options.playBuzzerSequence?.(new Uint8Array(message.payload))) @@ -357,6 +376,7 @@ export class WorkerAppHost { // Titles are informational for now (sidebar shows icons only). break; case "publish-state": + this.publishedStateKeys.add(message.key); publishWorkerState(message.key, message.state); break; case "set-tools": @@ -392,8 +412,33 @@ export class WorkerAppHost { return this.openWindows.size; } + private shutdown(): void { + if (this.stopping) return; + this.stopping = true; + this.options.onStopping?.(); + this.queuedMessages.length = 0; + this.options.navigationSensors?.stop(); + shell.setTrayIcon(this.options.appId, null); + for (const key of this.publishedStateKeys) publishWorkerState(key, undefined); + this.publishedStateKeys.clear(); + // The idle reply follows all close-window cleanup. Allow the worker to + // release app-wide native subscriptions/sockets before killing its isolate. + this.shutdownTimer = setTimeout(() => this.terminate(), 5000); + this.options.worker.postMessage({ type: "shutdown" } satisfies WorkerAppMessage); + } + + private terminate(): void { + if (this.terminated) return; + this.terminated = true; + if (this.shutdownTimer !== null) clearTimeout(this.shutdownTimer); + this.shutdownTimer = null; + this.options.worker.terminate(); + } + /** Open a window of this app and register it with the shell. */ openWindow(spec: WorkerWindowSpec): ShellWindow { + if (this.stopping) throw new Error(`Worker ${this.options.appId} is shutting down`); + let closed = false; const surfaceId = `window:${spec.windowId}`; const heightMode = spec.heightMode ?? "min"; this.openWindows.add(spec.windowId); @@ -419,6 +464,8 @@ export class WorkerAppHost { hasAppMenu: () => this.windowGestures.get(spec.windowId)?.hasAppMenu ?? false, claimsLongPress: () => this.windowGestures.get(spec.windowId)?.claimsLongPress ?? false, close: () => { + if (closed) return; + closed = true; this.openWindows.delete(spec.windowId); if (!this.openWindows.size) this.options.navigationSensors?.stop(); this.windowGestures.delete(spec.windowId); @@ -428,6 +475,7 @@ export class WorkerAppHost { this.failPendingToolCallsFor(spec.windowId); this.post({ type: "close-window", windowId: spec.windowId }); this.options.removeSurface(surfaceId); + if (!this.openWindows.size) this.post({ type: "check-idle" }); }, drawIcon: windowIcon(spec.icon, spec.iconLetter, spec.iconGlyph, () => this.windowIconActivity.get(spec.windowId) ?? "idle"), handleInput: (event, frameId) => { @@ -473,6 +521,7 @@ export class WorkerAppHost { void this.options .configureSurface(surfaceId, false, heightMode) .then(() => { + if (closed || this.stopping) return; if (spec.focus) { shell.focusWindow(spec.windowId); } @@ -511,6 +560,7 @@ export class WorkerAppHost { } private post(message: WorkerAppMessage): void { + if (this.stopping) return; if (!this.workerReady) { this.queuedMessages.push(message); return; diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt index e6c0adc3..68c8f60e 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt @@ -63,11 +63,41 @@ class DisplayListRenderer(private val resources: Map, private va target.put(x + i % image.width, y + i / image.width, source * (options and 15) / 15) } } + private fun copyScreen(screen: Target, composition: Target) { + val source = screen.bytes + val destination = composition.bytes + // Shared backing arrays can overlap and the pixel loop intentionally reads + // earlier writes. Keep that behavior, as well as shifted target clipping. + if (source === destination || composition.shiftX != 0) { + for (y in 0 until screen.height) for (x in 0 until screen.width) composition.put(x, y, screen.get(x, y)) + return + } + val width = minOf(screen.width, composition.width) + val height = minOf(screen.height, composition.height) + val sourceStride = screen.stride + val destinationStride = composition.stride + var src = screen.offset + var dst = composition.offset + if (screen.width == composition.width && width and 1 == 0) { + source.copyInto(destination, dst, src, src + sourceStride * height) + return + } + val pairs = width / 2 + for (y in 0 until height) { + source.copyInto(destination, dst, src, src + pairs) + // The last pixel of an odd-width row shares a byte with padding or + // an untouched destination pixel; preserve that low nibble. + if (width and 1 != 0) destination[dst + pairs] = + ((source[src + pairs].toInt() and 240) or (destination[dst + pairs].toInt() and 15)).toByte() + src += sourceStride + dst += destinationStride + } + } /** Validate the whole graph before changing any pixels. Resource writes remain call-scoped. */ fun render(root: Int, screen: Target, composition: Target): Set { val references = mutableSetOf() for (apply in listOf(false, true)) { - if (apply) for (y in 0 until screen.height) for (x in 0 until screen.width) composition.put(x, y, screen.get(x, y)) + if (apply) copyScreen(screen, composition) if (root != DrawProtocol.SCREEN) executeList(root, composition, screen, apply, mutableListOf(), intArrayOf(4096), references) } return references diff --git a/tests/terminal-activity.test.cjs b/tests/terminal-activity.test.cjs index f558380c..78a5be77 100644 --- a/tests/terminal-activity.test.cjs +++ b/tests/terminal-activity.test.cjs @@ -29,6 +29,7 @@ function worker() { scheduleRender() { renderCount++; }, renderAndSubmit() {}, maybeReconnectView() {}, // Glanceboard publication is outside the sidebar activity fixture. publishSessionsSnapshot() {}, + hasTerminalBackgroundWork: () => false, controlsInitialized: true, controls: new Map(), TERMINAL_TOOLS: [], getTerminalFontConfig: () => ({ cellWidth: 6, cellHeight: 12 }), }; diff --git a/tests/worker-lifecycle.test.cjs b/tests/worker-lifecycle.test.cjs new file mode 100644 index 00000000..cf483106 --- /dev/null +++ b/tests/worker-lifecycle.test.cjs @@ -0,0 +1,141 @@ +const { test } = require('node:test'); +const assert = require('node:assert/strict'); +const { loader } = require('./helpers/load-typescript.cjs'); +const flush = () => new Promise(resolve => setImmediate(resolve)); + +function fixture() { + const sent = [], stopped = [], removed = [], focused = [], timers = new Map(), published = []; + let kills = 0, resolveSurface; + const worker = { postMessage: message => sent.push(message), terminate: () => kills++ }; + const shellWindows = new Map(); + const load = loader({ global: {}, setTimeout: (fn, ms) => { timers.set(fn, ms); return fn; }, clearTimeout: fn => timers.delete(fn) }, { + '../../graphics/image': {}, './chrome-layer': { windowIcon() {} }, + '../../assistant/tool-registry': { toolRegistry: { removeAppTools() {} } }, + './geometry': { appViewportSize: () => ({ width: 576, height: 288 }) }, + '../../native/frame-timings': {}, './worker-state': { publishWorkerState: (...args) => published.push(args) }, + './shell': { shell: { registerWindow: w => shellWindows.set(w.windowId, w), setTrayIcon() {}, + focusWindow: id => focused.push(id), isWindowFocused: () => false } }, + }); + const { WorkerAppHost } = load('app/ui/shell/worker-window.ts'); + const host = new WorkerAppHost({ appId: 'game', worker, onStopping: () => stopped.push(host), + configureSurface: () => new Promise(resolve => { resolveSurface = resolve; }), + setSurfaceVisible() {}, removeSurface: id => removed.push(id), requestShellRender() {} }); + return { host, sent, stopped, timers, removed, focused, published, get kills() { return kills; }, + ready: () => worker.onmessage({ data: { type: 'worker-ready' } }), + reply: data => worker.onmessage({ data }), + open: id => host.openWindow({ windowId: id, title: id, focus: true }), + surfaceReady: () => resolveSurface(), + }; +} + +test('last window drains close cleanup, then exits the worker and releases its cached host', () => { + const f = fixture(); f.ready(); const a = f.open('a'), b = f.open('b'); + a.close(); assert.equal(f.sent.some(m => m.type === 'check-idle'), false); + b.close(); assert.deepEqual(f.sent.slice(-2).map(m => m.type), ['close-window', 'check-idle']); + f.reply({ type: 'publish-state', key: 'test', state: 1 }); + f.reply({ type: 'worker-idle' }); + assert.equal(f.stopped.length, 1); assert.equal(f.kills, 0); + assert.equal(f.sent.at(-1).type, 'shutdown'); + assert.deepEqual(f.published.at(-1), ['test', undefined]); + f.reply({ type: 'open-window-request', windowId: 'late', title: 'late' }); + assert.equal(f.host.windowCount(), 0); + f.reply({ type: 'worker-stopped' }); f.reply({ type: 'worker-stopped' }); + assert.equal(f.kills, 1); assert.equal(f.timers.size, 0); + assert.throws(() => f.open('reopen'), /shutting down/); +}); + +test('closing before worker-ready still delivers open/close/idle in order', async () => { + const f = fixture(); f.open('loading').close(); assert.equal(f.sent.length, 0); + f.ready(); assert.deepEqual(f.sent.map(m => m.type), ['open-window', 'close-window', 'check-idle']); + f.surfaceReady(); await flush(); assert.deepEqual(f.focused, []); + f.reply({ type: 'worker-idle' }); f.reply({ type: 'worker-stopped' }); assert.equal(f.kills, 1); +}); + +test('a late idle report cannot kill a reopened window, and background ownership can end later', () => { + const f = fixture(); f.ready(); f.open('first').close(); + // A background worker does not report idle while it still owns connections. + assert.equal(f.stopped.length, 0); + const reopened = f.open('second'); f.reply({ type: 'worker-idle' }); + assert.equal(f.stopped.length, 0); + reopened.close(); f.reply({ type: 'worker-idle' }); + assert.equal(f.stopped.length, 1); + for (const timeout of [...f.timers.keys()]) timeout(); + assert.equal(f.kills, 1, 'a hung shutdown cannot leave the thread alive'); +}); + +test('Terminal stays alive only for a configured visible-layout widget and an enabled valid connection', () => { + const settings = new Map(); + const load = loader({}, { '../../native/settings-store': { + getStringSetting: (key, fallback) => settings.get(key) ?? fallback, + } }); + const { hasTerminalBackgroundWork } = load('app/apps/terminal/background.ts'); + settings.set('terminal.connections', JSON.stringify([{ id: 'test', url: 'g2mirror://token@localhost', enabled: true }])); + assert.equal(hasTerminalBackgroundWork(), false); + settings.set('glanceboard.quadrants.slot.1', 'terminal'); assert.equal(hasTerminalBackgroundWork(), true); + settings.set('glanceboard.enabled', false); assert.equal(hasTerminalBackgroundWork(), true, 'configured cards also appear in the Glanceboard app'); + settings.delete('glanceboard.quadrants.slot.1'); settings.set('glanceboard.quadrants.slot.5', 'terminal'); + assert.equal(hasTerminalBackgroundWork(), false); + settings.set('glanceboard.layout', '2x3'); assert.equal(hasTerminalBackgroundWork(), true); + for (const connections of [[], [{ id: 'test', url: 'invalid' }], [{ id: 'test', url: 'g2mirror://token@localhost', enabled: false }]]) { + settings.set('terminal.connections', JSON.stringify(connections)); assert.equal(hasTerminalBackgroundWork(), false); + } +}); + +test('worker shutdown unregisters the isolate settings observer before acknowledging', () => { + const calls = []; + const { finishWorkerShutdown } = loader({ global: { postMessage: message => calls.push(message.type) } }, { + '../../native/settings-store': { disposeSettingsStore: () => calls.push('dispose') }, + })('app/ui/shell/worker-lifecycle.ts'); + finishWorkerShutdown(); assert.deepEqual(calls, ['dispose', 'worker-stopped']); +}); + +test('every app worker answers idle checks and shutdown; Terminal releases controls only on shutdown', () => { + const fs = require('node:fs'), vm = require('node:vm'), ts = require('typescript'); + for (const app of ['blocks', 'flappy', 'freecell', 'minesweeper', 'navigate', 'pinball', 'roam', 'terminal']) { + const path = `app/apps/${app}/${app}-app.worker.ts`; + const source = ts.createSourceFile(path, fs.readFileSync(path, 'utf8'), ts.ScriptTarget.Latest, true); + const statements = source.statements.filter(s => + ts.isExpressionStatement(s) && ts.isBinaryExpression(s.expression) && s.expression.left.getText(source) === 'global.onmessage' || + app === 'terminal' && ts.isFunctionDeclaration(s) && s.name?.text === 'reportIdle' || + app === 'terminal' && ts.isExpressionStatement(s) && ts.isCallExpression(s.expression) && s.expression.expression.getText(source) === 'onSettingsStoreChanged'); + const messages = [], cleanup = []; let background = true, changed; + const context = { global: {}, windows: new Map(), controls: new Map([['one', 1], ['two', 2]]), + post: message => messages.push(message.type), hasTerminalBackgroundWork: () => background, + finishWorkerShutdown: () => cleanup.push('shutdown'), stopControl: value => cleanup.push(value), + onSettingsStoreChanged: callback => { changed = callback; }, + }; + vm.runInNewContext(ts.transpileModule(statements.map(s => s.getText(source)).join('\n'), { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText, context); + context.global.onmessage({ data: { type: 'check-idle' } }); + if (app === 'terminal') { + assert.deepEqual(messages, []); assert.equal(context.controls.size, 2); + background = false; changed('glanceboard.quadrants.slot.1'); + } + assert.deepEqual(messages, ['worker-idle'], app); + assert.deepEqual(cleanup, [], 'idle reports must not tear down a concurrently reopened app'); + context.global.onmessage({ data: { type: 'shutdown' } }); + assert.deepEqual(cleanup, app === 'terminal' ? [1, 2, 'shutdown'] : ['shutdown']); + if (app === 'terminal') assert.equal(context.controls.size, 0); + } +}); + +test('both controllers remove only the retiring host and create a fresh worker on relaunch', () => { + const fs = require('node:fs'), vm = require('node:vm'), ts = require('typescript'); + for (const platform of ['dashboard', 'ios-preview']) { + const path = `app/g2/${platform}-controller.ts`; + const source = ts.createSourceFile(path, fs.readFileSync(path, 'utf8'), ts.ScriptTarget.Latest, true); + const controller = source.statements.find(s => ts.isClassDeclaration(s) && s.name.text.endsWith('Controller')); + const method = controller.members.find(s => s.name?.getText(source) === 'ensureWorkerHost'); + const context = { exports: {}, WorkerAppHost: class { constructor(options) { this.options = options; } } }; + vm.runInNewContext(ts.transpileModule(`export class Controller { ${method.getText(source)} }`, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText, context); + const host = new context.exports.Controller(); host.appHosts = new Map(); + const first = host.ensureWorkerHost('flappy', () => ({})); + assert.equal(host.ensureWorkerHost('flappy', assert.fail), first); + first.options.onStopping(); assert.equal(host.appHosts.size, 0); + const next = host.ensureWorkerHost('flappy', () => ({})); assert.notEqual(next, first); + first.options.onStopping(); assert.equal(host.appHosts.get('flappy'), next); + } +}); From 306accf06da76f6fc194e0ba8846e44a282a69e4 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 15:15:31 -0700 Subject: [PATCH 08/27] Move Nightscout "Always show in top bar" setting earlier in the form so it's harder to miss --- app/apps/nightscout/nightscout.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/apps/nightscout/nightscout.ts b/app/apps/nightscout/nightscout.ts index 8a0878da..675a07f8 100644 --- a/app/apps/nightscout/nightscout.ts +++ b/app/apps/nightscout/nightscout.ts @@ -420,11 +420,11 @@ export function nightscoutMenuItems(): MenuItem[] { openSettingsSubMenu(ctx, "Nightscout settings", [ textSettingMenuItem(nightscoutSiteUrlSetting), textSettingMenuItem(nightscoutApiTokenSetting), + toggleSettingMenuItem(nightscoutAlwaysShowInTopBarSetting), textSettingMenuItem(nightscoutMaxCannulaAgeSetting), textSettingMenuItem(nightscoutCartridgeLowSetting), textSettingMenuItem(nightscoutBatteryLowSetting), textSettingMenuItem(nightscoutMaxLoopAgeSetting), - toggleSettingMenuItem(nightscoutAlwaysShowInTopBarSetting), ]); }, }, From ea9bfae6affd74b4ee3c937dcd3806f7e62ed9fe Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 16:27:04 -0700 Subject: [PATCH 09/27] Refactor: g2flash protocol doesn't have so many magic numbers --- .../faceclaw/app/FaceclawBleCommunicator.java | 14 ++--- app/g2/ble-image-optimizer.ts | 5 +- app/g2/cfw-message-type.ts | 36 ++++++++++++ app/g2/cfw-transport.ts | 1 + app/g2/draw-protocol.ts | 11 ++-- app/g2/glasses-session.ts | 13 +++-- app/native/kotlin-protocol-smoke.ios.ts | 7 ++- app/ui/sound-effects.ts | 5 +- .../app/g2protocol/BleImageOptimizer.kt | 6 +- .../faceclaw/app/g2protocol/BleProtocol.kt | 3 +- .../faceclaw/app/g2protocol/CfwMessageType.kt | 38 +++++++++++++ .../faceclaw/app/g2protocol/CfwTransport.kt | 1 + .../faceclaw/app/g2protocol/DrawCallType.kt | 11 ++++ .../com/faceclaw/app/g2protocol/DrawFlags.kt | 21 +++++++ .../faceclaw/app/g2protocol/DrawProtocol.kt | 57 ++++++++++--------- .../app/g2protocol/ResourceCacheState.kt | 7 ++- .../faceclaw/app/g2protocol/ResourceFlags.kt | 10 ++++ .../faceclaw/app/g2protocol/TexturePlanner.kt | 14 ++--- .../app/graphics/DisplayListRenderer.kt | 48 ++++++++-------- .../faceclaw/app/graphics/MenuSelection.kt | 8 +-- tests/ios-app-host.test.cjs | 2 +- .../com/faceclaw/app/DisplayListTest.kt | 12 ++-- 22 files changed, 231 insertions(+), 99 deletions(-) create mode 100644 app/g2/cfw-message-type.ts create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageType.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawFlags.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceFlags.kt diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java index cbed7e39..c7aeef55 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java @@ -779,7 +779,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { // would compress even a random payload if we reused it across the run. byte[] payload = new byte[benchmarkMessageSize]; benchmarkRandom.nextBytes(payload); - payload[0] = 7; // CFW diagnostic-control mode... + payload[0] = CfwMessageTypeKt.CFW_MSG_DIAGNOSTICS; // CFW diagnostic-control mode... payload[1] = (byte) 0x7f; // ...with an unused sub-op: acked, no effect OutboundMessage message = messageBuilder.imagePayload( "bandwidth", @@ -859,7 +859,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { /** Request one CFW ambient-light report (image-handler mode 16 op 0). */ public void queryAmbientLight() { synchronized (lock) { - enqueueAmbientLightControlLocked(new byte[] { (byte) 16, (byte) 0 }, "als query", false); + enqueueAmbientLightControlLocked(new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_AMBIENT_LIGHT, (byte) 0 }, "als query", false); } interruptibleSleep.interrupt(); } @@ -877,7 +877,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { int heartbeatMs, boolean bindToLease) { byte[] payload = enable ? new byte[] { - (byte) 16, + (byte) CfwMessageTypeKt.CFW_MSG_AMBIENT_LIGHT, (byte) 1, (byte) (bindToLease ? 1 : 0), (byte) (intervalMs & 0xff), @@ -887,7 +887,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { (byte) (heartbeatMs & 0xff), (byte) ((heartbeatMs >> 8) & 0xff), } - : new byte[] { (byte) 16, (byte) 2 }; + : new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_AMBIENT_LIGHT, (byte) 2 }; synchronized (lock) { clearMessagesOfKindLocked("als-control"); enqueueAmbientLightControlLocked(payload, "als polling " + (enable ? "start" : "stop"), true); @@ -2887,7 +2887,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { private void enqueueFirmwareDebugFlagsLocked() { boolean show = firmwareDebugFlagsEnabled; int sub = show ? 2 : 1; - byte[] payload = new byte[] { (byte) 7, (byte) sub }; + byte[] payload = new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_DIAGNOSTICS, (byte) sub }; OutboundMessage message = messageBuilder.imagePayload( DASHBOARD_TILE, nextMapSessionId(), payload, "fw-debug-flags " + (show ? "show" : "hide"), @@ -2905,14 +2905,14 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { int sentState = enable ? 1 : 0; byte[] payload = enable ? new byte[] { - (byte) 10, + (byte) CfwMessageTypeKt.CFW_MSG_COMPASS, (byte) 2, (byte) (COMPASS_REPORT_INTERVAL_MS & 0xff), (byte) ((COMPASS_REPORT_INTERVAL_MS >> 8) & 0xff), (byte) (COMPASS_MIN_CHANGE_DEGREES & 0xff), (byte) ((COMPASS_MIN_CHANGE_DEGREES >> 8) & 0xff), } - : new byte[] { (byte) 10, (byte) 0 }; + : new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_COMPASS, (byte) 0 }; OutboundMessage message = messageBuilder.imagePayload( "compass-control", DASHBOARD_TILE, diff --git a/app/g2/ble-image-optimizer.ts b/app/g2/ble-image-optimizer.ts index b874b53a..8ae18607 100644 --- a/app/g2/ble-image-optimizer.ts +++ b/app/g2/ble-image-optimizer.ts @@ -1,3 +1,4 @@ +import { CFW_MSG_BOUNDING_BOX } from "./cfw-message-type"; import { concat, rle4 } from './ble-protocol' /** Android BleImageOptimizer's mode-3 changed rectangle. Coordinates are in @@ -29,7 +30,7 @@ export function buildBoundingBoxPayload(previous: Uint8Array | null, next: Uint8 const start = (top + y) * stride + left / 2 region.set(next.subarray(start, start + regionStride), y * regionStride) } - return concat(new Uint8Array([3, left / 4, top / 2, boxWidth / 4, boxHeight / 2, + return concat(new Uint8Array([CFW_MSG_BOUNDING_BOX, left / 4, top / 2, boxWidth / 4, boxHeight / 2, frameId & 255, (frameId >>> 8) & 255]), rle4(region)) } @@ -41,7 +42,7 @@ export function buildFullFrameBands(packed: Uint8Array, width: number, height: n let id = firstId for (let top = 0; top < height; top += 64) { const rows = Math.min(64, height - top) - bands.push(concat(new Uint8Array([3, 0, top / 2, width / 4, rows / 2, id & 255, id >>> 8]), + bands.push(concat(new Uint8Array([CFW_MSG_BOUNDING_BOX, 0, top / 2, width / 4, rows / 2, id & 255, id >>> 8]), rle4(packed.subarray(top * width / 2, (top + rows) * width / 2)))) id = id >= 0xfffe ? 1 : id + 1 } diff --git a/app/g2/cfw-message-type.ts b/app/g2/cfw-message-type.ts new file mode 100644 index 00000000..550fd658 --- /dev/null +++ b/app/g2/cfw-message-type.ts @@ -0,0 +1,36 @@ +/** Message IDs and header flags mirror g2flash/patches/zlib_glue.c. */ +/** Retired wire ID; used internally by the phone optimizer. */ +export const CFW_MSG_BOUNDING_BOX = 3 +export const CFW_MSG_BUZZER = 5 +/** Retired wire ID; used internally by the phone optimizer. */ +export const CFW_MSG_FULL_FRAME = 6 +export const CFW_MSG_DIAGNOSTICS = 7 +/** Retired wire ID; used internally by the phone optimizer. */ +export const CFW_MSG_MULTI_SEGMENT = 8 +/** Retired wire ID; used internally by the phone optimizer. */ +export const CFW_MSG_RECT_COPY = 9 +export const CFW_MSG_COMPASS = 10 +export const CFW_MSG_CLEANUP = 11 +export const CFW_MSG_RETIRED_12 = 12 +export const CFW_MSG_RETIRED_13 = 13 +export const CFW_MSG_RETIRED_14 = 14 +/** Retired wire ID; used internally by the phone optimizer. */ +export const CFW_MSG_STOCK_FONT_STRING = 15 +export const CFW_MSG_AMBIENT_LIGHT = 16 +export const CFW_MSG_RING_BATTERY = 17 +export const CFW_MSG_RETIRED_CACHE_WRITE = 18 +/** Retired wire ID; used internally by the phone optimizer. */ +export const CFW_MSG_CACHED_IMAGE = 19 +/** Retired wire ID; used internally by the phone optimizer. */ +export const CFW_MSG_CACHED_TEXT = 20 +export const CFW_MSG_UPLOAD_RESOURCE = 21 +export const CFW_MSG_EVICT_RESOURCE = 22 +export const CFW_MSG_PANEL_READ = 23 +export const CFW_MSG_PANEL_WRITE = 24 +export const CFW_MSG_PANEL_PATTERN = 25 +export const CFW_MSG_DRAW_CALLS = 26 +export const CFW_MSG_SET_ROOT_DISPLAY_LIST = 27 +export const CFW_MSG_PRESENT = 28 +export const CFW_MSG_CREATE_SURFACE = 29 +export const CFW_MSG_TYPE_MASK = 127 +export const CFW_MSG_FLAG_LENSES_DIFFER = 128 diff --git a/app/g2/cfw-transport.ts b/app/g2/cfw-transport.ts index 922e0c20..8f6dd234 100644 --- a/app/g2/cfw-transport.ts +++ b/app/g2/cfw-transport.ts @@ -1,6 +1,7 @@ import { concat, crc16, SID } from './ble-protocol' declare const require: (name: string) => any +/** Mirrors CFW_MESSAGE_MAX in g2flash/patches/message_transport.h. */ export const CFW_MAX_MESSAGE = 65535 export type CfwAck = { nack: boolean; streamId: number; messageId: number; lens: number; size: number; checksum: number } const u16 = (data: Uint8Array, offset: number) => data[offset] | (data[offset + 1] << 8) diff --git a/app/g2/draw-protocol.ts b/app/g2/draw-protocol.ts index 1774b9be..4f5c3de1 100644 --- a/app/g2/draw-protocol.ts +++ b/app/g2/draw-protocol.ts @@ -1,14 +1,15 @@ +import { CFW_MSG_BOUNDING_BOX, CFW_MSG_DRAW_CALLS, CFW_MSG_FULL_FRAME, CFW_MSG_MULTI_SEGMENT, CFW_MSG_TYPE_MASK } from "./cfw-message-type"; /** Adapter for raster-only senders; optimized legacy layouts remain internal to the phone. */ export function drawMessages(payload: Uint8Array, width = 640, height = 480): Uint8Array[] { const word = (v: number) => [v & 255, (v >>> 8) & 255] - const mode = payload[0] & 127 + const mode = payload[0] & CFW_MSG_TYPE_MASK let calls: Uint8Array[] - if (mode === 8) { + if (mode === CFW_MSG_MULTI_SEGMENT) { const output: Uint8Array[] = []; let p=2 for(let i=0;i new Uint8Array([26,1,0,...word(call.length),...call])) + return calls.map(call => new Uint8Array([CFW_MSG_DRAW_CALLS,1,0,...word(call.length),...call])) } diff --git a/app/g2/glasses-session.ts b/app/g2/glasses-session.ts index 850d0327..fce88f76 100644 --- a/app/g2/glasses-session.ts +++ b/app/g2/glasses-session.ts @@ -1,3 +1,4 @@ +import { CFW_MSG_CLEANUP, CFW_MSG_COMPASS, CFW_MSG_EVICT_RESOURCE, CFW_MSG_FULL_FRAME, CFW_MSG_PRESENT } from "./cfw-message-type"; import { drawMessages } from './draw-protocol' import { setBrightness } from './brightness-protocol' import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client' @@ -481,7 +482,7 @@ export class GlassesSession { const enabled = !this.compassStopping && this.compassWanted if (this.compassSent === enabled) return // Same CFW mode 10, 100 ms report interval and zero minimum change as Android. - await this.requestCfw('left', new Uint8Array(enabled ? [10, 2, 100, 0, 0, 0] : [10, 0])) + await this.requestCfw('left', new Uint8Array(enabled ? [CFW_MSG_COMPASS, 2, 100, 0, 0, 0] : [CFW_MSG_COMPASS, 0])) if (generation === this.generation) this.compassSent = enabled }).catch(error => { if (generation === this.generation) this.fail(error, true) }) this.compassWork = work @@ -497,7 +498,7 @@ export class GlassesSession { this.timer = setTimeout(() => { this.timer = null; void this.pump() }, delay) } private canSendDisplay(): boolean { - if (this.displaySending?.commands[this.displaySending.offset][0] === 22 && this.cfwPending.length) return false + if (this.displaySending?.commands[this.displaySending.offset][0] === CFW_MSG_EVICT_RESOURCE && this.cfwPending.length) return false // Also bound completed frames retained behind a missing/out-of-order ACK. return this.displayInFlight < DISPLAY_WINDOW_SIZE && !!(this.displaySending || (this.latest && !this.charging && this.displayFrames.length < DISPLAY_WINDOW_SIZE)) @@ -520,12 +521,12 @@ export class GlassesSession { this.log(`Display textures (${texturePlan.resourceCommands.length} resource commands, cache=${texturePlan.usedBytes}B)`) } else { const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId) - const payload = delta ?? protocol.concat(new Uint8Array([6]), protocol.rle4(packed)) + const payload = delta ?? protocol.concat(new Uint8Array([CFW_MSG_FULL_FRAME]), protocol.rle4(packed)) if (delta) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 commands = payload.length <= CFW_MAX_MESSAGE - 16 ? [payload] : buildFullFrameBands(packed, 640, 480, this.nextImageFrameId) if (payload.length > CFW_MAX_MESSAGE - 16) for (const _ of commands) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 - commands = [...commands.flatMap(command => drawMessages(command)), new Uint8Array([28])] + commands = [...commands.flatMap(command => drawMessages(command)), new Uint8Array([CFW_MSG_PRESENT])] this.log(`Display ${delta ? 'bbox' : 'full'} (${commands.length} CFW commands)`) } this.displaySending = { packed, commands, offset: 0, pending: 0 } @@ -533,7 +534,7 @@ export class GlassesSession { } const frame = this.displaySending // Drain earlier commands before evicting: recovery may replay any unresolved draw/upload. - if (frame.commands[frame.offset][0] === 22 && this.cfwPending.length) return + if (frame.commands[frame.offset][0] === CFW_MSG_EVICT_RESOURCE && this.cfwPending.length) return const payload = frame.commands[frame.offset++] frame.pending++; this.displayInFlight++ if (frame.offset >= frame.commands.length) this.displaySending = null @@ -634,7 +635,7 @@ export class GlassesSession { this.update('disconnecting', 'Disconnecting…'); this.reset() try { if (cleanup) { - await this.requestCfw('left', new Uint8Array([11])) + await this.requestCfw('left', new Uint8Array([CFW_MSG_CLEANUP])) } } catch (error) { this.log(`Disconnect cleanup: ${this.message(error)}`) } finally { this.reset(); this.closeLinks(); this.update('disconnected', 'Preview only') } diff --git a/app/native/kotlin-protocol-smoke.ios.ts b/app/native/kotlin-protocol-smoke.ios.ts index 1662c88a..f2221d5b 100644 --- a/app/native/kotlin-protocol-smoke.ios.ts +++ b/app/native/kotlin-protocol-smoke.ios.ts @@ -1,3 +1,4 @@ +import { CFW_MSG_BOUNDING_BOX, CFW_MSG_CREATE_SURFACE, CFW_MSG_PRESENT, CFW_MSG_UPLOAD_RESOURCE } from "../g2/cfw-message-type"; import { GrayImage } from "../graphics/image" import { encodeShellScene } from "../graphics/shell-scene" import { decodeImageBytes } from './image-bytes.ios' @@ -44,7 +45,7 @@ export function runKotlinProtocolSmokeTest(): void { textured.submitSurfaceFrame('icon', white, { x: 0, y: 0, width: 2, height: 2 }, draw.buffer) const snapshot = textured.compositeFrame(), packed = protocol.packGray4(snapshot.pixels, 4, 2) const cold = textures.plan(null, packed, snapshot.textures, 1) - assert(!!cold && cold.resourceCommands.some(command => command[0] === 21) && cold.payload[0] === 28, 'texture upload and draw') + assert(!!cold && cold.resourceCommands.some(command => command[0] === CFW_MSG_UPLOAD_RESOURCE) && cold.payload[0] === CFW_MSG_PRESENT, 'texture upload and draw') assert(textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length === 0, 'texture reuse') textures.reset() assert((textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length ?? 0) > 0, 'texture reset') @@ -55,9 +56,9 @@ export function runKotlinProtocolSmokeTest(): void { const selectedSnapshot = selectedPreview.compositeFrame() assert(selectedSnapshot.pixels[10] === 240 && selectedSnapshot.pixels[9] === 0, 'menu selection depth and bridge') const selectedPlan = new IosTexturePlanner().plan(null, protocol.packGray4(selectedSnapshot.pixels, 8, 4), selectedSnapshot.textures, 1) - assert(!!selectedPlan && selectedPlan.payload[0] === 28 && selectedPlan.resourceCommands.some(c => c[0] === 29), 'menu resource planning') + assert(!!selectedPlan && selectedPlan.payload[0] === CFW_MSG_PRESENT && selectedPlan.resourceCommands.some(c => c[0] === CFW_MSG_CREATE_SURFACE), 'menu resource planning') const changed = new Uint8Array(16); changed[0] = 255 - assert(buildBoundingBoxPayload(new Uint8Array(16), changed, 8, 4, 1)?.[0] === 3, 'image update') + assert(buildBoundingBoxPayload(new Uint8Array(16), changed, 8, 4, 1)?.[0] === CFW_MSG_BOUNDING_BOX, 'image update') assert(lvglMetrics('/nonexistent/faceclaw-font').length === 0, 'font bridge') const compass = protocol.decodeCompassInput({ sid: 8, flag: 1, command: 15, magic: 0, payload: new Uint8Array([8, 15, 16, 0, 82, 3, 8, 231, 2, 162, 6, 12, 67, 77, 1, 3, 2, 3, 140, 0, 152, 186, 220, 254]) }) diff --git a/app/ui/sound-effects.ts b/app/ui/sound-effects.ts index 091b0861..bd127c4e 100644 --- a/app/ui/sound-effects.ts +++ b/app/ui/sound-effects.ts @@ -1,3 +1,4 @@ +import { CFW_MSG_BUZZER } from "../g2/cfw-message-type"; /** * Sound-effect catalog for the CFW buzzer tone sequencer (load_image_z mode 5 * kind 4). Ported from g2-kit-unofficial/examples/tunes.ts. @@ -19,14 +20,14 @@ export type Step = { freq: number; duty?: number; ms: number }; /** One or more phrases; each phrase is one sequencer message. */ export type Effect = Step[] | Step[][]; -/** Firmware cap: steps per mode-5 kind-4 message. */ +/** Mirrors CFW_SEQ_MAX in g2flash/patches/cfw_context.h. */ export const CFW_SEQ_MAX = 48; /** Build the wire buffer: [5][4][nSteps][ freqLo,freqHi,duty,msLo,msHi ]*n. */ export function buildSoundSequencePayload(steps: Step[]): Uint8Array { const count = Math.min(steps.length, CFW_SEQ_MAX); const out = new Uint8Array(3 + count * 5); - out[0] = 0x05; + out[0] = CFW_MSG_BUZZER; out[1] = 0x04; out[2] = count; for (let index = 0; index < count; index++) { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt index 2eeb86b3..ef4731fc 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt @@ -277,7 +277,7 @@ class BleImageOptimizer { } var compressed: ByteArray = rleEncode(region) var out: ByteArray = ByteArray((7 + compressed.size)) - out[0] = 3 + out[0] = CFW_MSG_BOUNDING_BOX.toByte() out[1] = ((left / 4)).toByte() out[2] = ((top / 2)).toByte() out[3] = ((boxWidth / 4)).toByte() @@ -369,7 +369,7 @@ class BleImageOptimizer { fid = (if ((fid >= 0xfffe)) 1 else (fid + 1)) } var out: ByteArray = ByteArray(total) - out[0] = 8 + out[0] = CFW_MSG_MULTI_SEGMENT.toByte() out[1] = (rects.size).toByte() var pos: Int = 2 for (sub in subs) { @@ -553,7 +553,7 @@ class BleImageOptimizer { } var z: ByteArray = rleEncode(packed) var out: ByteArray = ByteArray((z.size + 1)) - out[0] = 6 + out[0] = CFW_MSG_FULL_FRAME.toByte() z.copyInto(out, 1, 0, 0 + z.size) return out } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleProtocol.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleProtocol.kt index f8dd8058..cea67b83 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleProtocol.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleProtocol.kt @@ -89,7 +89,8 @@ class BleProtocol { const val FACECLAW_WEAR_OP_QUERY: Int = 7 - const val CFW_IMAGE_MODE_CLEANUP: Int = 11 + /** Mirrors g2flash/patches/zlib_glue.c. */ + const val CFW_IMAGE_MODE_CLEANUP: Int = CFW_MSG_CLEANUP private const val FACECLAW_WAKE_EVENT: Int = 1 diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageType.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageType.kt new file mode 100644 index 00000000..c07eee5c --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageType.kt @@ -0,0 +1,38 @@ +package com.faceclaw.app + +/** Message IDs and header flags mirror g2flash/patches/zlib_glue.c. */ +/** Retired wire ID; used internally by the phone optimizer. */ +const val CFW_MSG_BOUNDING_BOX = 3 +const val CFW_MSG_BUZZER = 5 +/** Retired wire ID; used internally by the phone optimizer. */ +const val CFW_MSG_FULL_FRAME = 6 +const val CFW_MSG_DIAGNOSTICS = 7 +/** Retired wire ID; used internally by the phone optimizer. */ +const val CFW_MSG_MULTI_SEGMENT = 8 +/** Retired wire ID; used internally by the phone optimizer. */ +const val CFW_MSG_RECT_COPY = 9 +const val CFW_MSG_COMPASS = 10 +const val CFW_MSG_CLEANUP = 11 +const val CFW_MSG_RETIRED_12 = 12 +const val CFW_MSG_RETIRED_13 = 13 +const val CFW_MSG_RETIRED_14 = 14 +/** Retired wire ID; used internally by the phone optimizer. */ +const val CFW_MSG_STOCK_FONT_STRING = 15 +const val CFW_MSG_AMBIENT_LIGHT = 16 +const val CFW_MSG_RING_BATTERY = 17 +const val CFW_MSG_RETIRED_CACHE_WRITE = 18 +/** Retired wire ID; used internally by the phone optimizer. */ +const val CFW_MSG_CACHED_IMAGE = 19 +/** Retired wire ID; used internally by the phone optimizer. */ +const val CFW_MSG_CACHED_TEXT = 20 +const val CFW_MSG_UPLOAD_RESOURCE = 21 +const val CFW_MSG_EVICT_RESOURCE = 22 +const val CFW_MSG_PANEL_READ = 23 +const val CFW_MSG_PANEL_WRITE = 24 +const val CFW_MSG_PANEL_PATTERN = 25 +const val CFW_MSG_DRAW_CALLS = 26 +const val CFW_MSG_SET_ROOT_DISPLAY_LIST = 27 +const val CFW_MSG_PRESENT = 28 +const val CFW_MSG_CREATE_SURFACE = 29 +const val CFW_MSG_TYPE_MASK = 127 +const val CFW_MSG_FLAG_LENSES_DIFFER = 128 diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwTransport.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwTransport.kt index 0ce887fd..75d47d36 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwTransport.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwTransport.kt @@ -48,6 +48,7 @@ class CfwTransport(private val platform: ProtocolPlatform) { } companion object { + /** Mirrors g2flash/patches/message_transport.h. */ const val SID = 0xf0 const val BOTH = 3 const val MAX_MESSAGE = 65535 diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt new file mode 100644 index 00000000..f8045e86 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt @@ -0,0 +1,11 @@ +package com.faceclaw.app + +/** Draw-call wire IDs. Keep names and values in sync with cfw_draw_op in g2flash/patches/display_list.c. */ +const val DRAW_OP_BOUNDING_BOX = 1 +const val DRAW_OP_RECT_COPY = 2 +const val DRAW_OP_STOCK_FONT_STRING = 3 +const val DRAW_OP_IMAGE = 4 +const val DRAW_OP_TEXT = 5 +const val DRAW_OP_REMAP_COLORS = 6 +const val DRAW_OP_DISPLAY_LIST = 7 +const val DRAW_OP_ROUNDED_RECT = 8 diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawFlags.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawFlags.kt new file mode 100644 index 00000000..d2694afd --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawFlags.kt @@ -0,0 +1,21 @@ +package com.faceclaw.app + +/** + * Draw-call flags, bounding-box flags, and the border sentinel mirror g2flash/patches/display_list.c. + * Image/text options mirror g2flash/patches/texture_draw.h. + */ +/** Common draw-call header bits. */ +const val DRAW_FLAG_RESOURCE_TARGET = 1 +const val DRAW_FLAG_DEPTH = 2 +const val DRAW_FLAGS_MASK = DRAW_FLAG_RESOURCE_TARGET or DRAW_FLAG_DEPTH + +/** Bounding-box payload flag: u16 coordinates/sizes instead of aligned compact units. */ +const val DRAW_BBOX_FLAG_U16 = 1 + +/** Image/text options. */ +const val CFW_TEXTURE_OPT_BRIGHTNESS_MASK = 15 +const val CFW_TEXTURE_OPT_TRANSPARENT = 16 +const val CFW_TEXTURE_OPT_INVERSE = 32 + +/** Rounded-rectangle border sentinel, not a color or flag bit. */ +const val DRAW_ROUNDED_RECT_NO_BORDER = 16 diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt index d8812a89..3546b093 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt @@ -2,31 +2,36 @@ package com.faceclaw.app /** Revision 26 wire grammar, shared by scene planning and the local renderer. */ object DrawProtocol { - const val DRAW = 26 - const val ROOT = 27 - const val PRESENT = 28 - const val CREATE = 29 - const val IMAGE = 0 - const val FONT = 1 - const val LIST = 2 - const val LARGE = 4 - const val RLE = 8 + /** Mirrors g2flash/patches/zlib_glue.c. */ + const val DRAW = CFW_MSG_DRAW_CALLS + const val ROOT = CFW_MSG_SET_ROOT_DISPLAY_LIST + const val PRESENT = CFW_MSG_PRESENT + const val CREATE = CFW_MSG_CREATE_SURFACE + + /** Mirrors g2flash/patches/resource_cache.h. */ + const val IMAGE = CFW_RESOURCE_TYPE_IMAGE + const val FONT = CFW_RESOURCE_TYPE_FONT + const val LIST = CFW_RESOURCE_TYPE_DISPLAY_LIST + const val LARGE = CFW_RESOURCE_FLAG_LARGE + const val RLE = CFW_RESOURCE_FLAG_RLE + + /** Mirrors g2flash/patches/display_list.c. */ const val SCREEN = 65535 const val CURRENT = 65534 fun u16(b: ByteArray, p: Int): Int = (b[p].toInt() and 255) or ((b[p + 1].toInt() and 255) shl 8) fun word(n: Int) = byteArrayOf(n.toByte(), (n ushr 8).toByte()) fun call(op: Int, args: ByteArray, target: Int? = null, depth: Int? = null): ByteArray { require(depth == null || depth in -128..127) - val flags = (if (target == null) 0 else 1) or (if (depth == null) 0 else 2) + val flags = (if (target == null) 0 else DRAW_FLAG_RESOURCE_TARGET) or (if (depth == null) 0 else DRAW_FLAG_DEPTH) return byteArrayOf(op.toByte(), flags.toByte()) + (target?.let { word(it) } ?: byteArrayOf()) + (depth?.let { byteArrayOf(it.toByte()) } ?: byteArrayOf()) + args } fun depthOffset(depth: Int, right: Boolean): Int = if (right) -floorHalf(depth + 1) else floorHalf(depth) private fun floorHalf(n: Int): Int = if (n < 0) (n - 1) / 2 else n / 2 - fun roundedRect(x: Int, y: Int, width: Int, height: Int, radius: Int, background: Int, border: Int = 16, depth: Int? = null): ByteArray { - require(width in 1..640 && height in 1..480 && radius in 0..65535 && background in 0..15 && border in 0..16) - return call(8, word(x) + word(y) + word(width) + word(height) + word(radius) + byteArrayOf(background.toByte(), border.toByte()), depth = depth) + fun roundedRect(x: Int, y: Int, width: Int, height: Int, radius: Int, background: Int, border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null): ByteArray { + require(width in 1..640 && height in 1..480 && radius in 0..65535 && background in 0..15 && border in 0..DRAW_ROUNDED_RECT_NO_BORDER) + return call(DRAW_OP_ROUNDED_RECT, word(x) + word(y) + word(width) + word(height) + word(radius) + byteArrayOf(background.toByte(), border.toByte()), depth = depth) } fun sequence(calls: List): ByteArray { require(calls.size <= 4096) @@ -37,13 +42,13 @@ object DrawProtocol { fun message(calls: List) = byteArrayOf(DRAW.toByte()) + sequence(calls) fun displayList(calls: List) = byteArrayOf(LIST.toByte()) + sequence(calls) fun root(id: Int) = byteArrayOf(ROOT.toByte()) + word(id) - fun image(id: Int, x: Int, y: Int, options: Int = 15, target: Int? = null, depth: Int? = null) = - call(4, word(id) + word(x) + word(y) + byteArrayOf(options.toByte()), target, depth) + fun image(id: Int, x: Int, y: Int, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK, target: Int? = null, depth: Int? = null) = + call(DRAW_OP_IMAGE, word(id) + word(x) + word(y) + byteArrayOf(options.toByte()), target, depth) fun lut(width: Int, height: Int, factor: Int): ByteArray { val table = ByteArray(8) { i -> (((i * 2 * factor / 256).coerceIn(0, 15) shl 4) or ((i * 2 + 1) * factor / 256).coerceIn(0, 15)).toByte() } - return call(6, word(0) + word(0) + word(width) + word(height) + table) + return call(DRAW_OP_REMAP_COLORS, word(0) + word(0) + word(width) + word(height) + table) } fun rawImage(width: Int, height: Int, pixels: ByteArray = ByteArray(((width + 1) / 2) * height)): ByteArray { require(width in 1..640 && height in 1..480 && pixels.size == ((width + 1) / 2) * height) @@ -55,7 +60,7 @@ object DrawProtocol { fun bbox(packed: ByteArray, stride: Int, x: Int, y: Int, width: Int, height: Int, target: Int? = null): ByteArray { val compact = x % 4 == 0 && y % 2 == 0 && width % 4 == 0 && height % 2 == 0 && x / 4 < 256 && y / 2 < 256 && width / 4 < 256 && height / 2 < 256 val header = if (compact) byteArrayOf(0, (x / 4).toByte(), (y / 2).toByte(), (width / 4).toByte(), (height / 2).toByte()) - else byteArrayOf(1) + word(x) + word(y) + word(width) + word(height) + else byteArrayOf(DRAW_BBOX_FLAG_U16.toByte()) + word(x) + word(y) + word(width) + word(height) val out = ByteSink(); out.write(header) var color = -1; var count = 0 fun flush() { @@ -69,22 +74,22 @@ object DrawProtocol { count++ } flush() - return call(1, out.toByteArray(), target) + return call(DRAW_OP_BOUNDING_BOX, out.toByteArray(), target) } /** Internal optimizer formats are translated here; they are never sent to revision 26. */ fun fromOptimized(payload: ByteArray, width: Int = 640, height: Int = 480): List { - return when (val mode = payload[0].toInt() and 127) { - 8 -> { + return when (val mode = payload[0].toInt() and CFW_MSG_TYPE_MASK) { + CFW_MSG_MULTI_SEGMENT -> { val result = ArrayList(); var pos = 2 repeat(payload[1].toInt() and 255) { val n = u16(payload, pos); pos += 2; result.addAll(fromOptimized(payload.copyOfRange(pos, pos + n), width, height)); pos += n } require(pos == payload.size); result } - 3 -> listOf(call(1, byteArrayOf(0) + payload.copyOfRange(1, 5) + payload.copyOfRange(7, payload.size))) - 6 -> listOf(call(1, byteArrayOf(1) + word(0) + word(0) + word(width) + word(height) + payload.copyOfRange(1, payload.size))) - 15 -> listOf(call(3, payload.copyOfRange(1, payload.size))) - 19 -> listOf(call(4, payload.copyOfRange(1, payload.size))) - 20 -> listOf(call(5, payload.copyOfRange(1, payload.size))) - 9 -> listOf(call(2, word(CURRENT) + payload.copyOfRange(1, 9) + payload.copyOfRange(9, 13))) + CFW_MSG_BOUNDING_BOX -> listOf(call(DRAW_OP_BOUNDING_BOX, byteArrayOf(0) + payload.copyOfRange(1, 5) + payload.copyOfRange(7, payload.size))) + CFW_MSG_FULL_FRAME -> listOf(call(DRAW_OP_BOUNDING_BOX, byteArrayOf(DRAW_BBOX_FLAG_U16.toByte()) + word(0) + word(0) + word(width) + word(height) + payload.copyOfRange(1, payload.size))) + CFW_MSG_STOCK_FONT_STRING -> listOf(call(DRAW_OP_STOCK_FONT_STRING, payload.copyOfRange(1, payload.size))) + CFW_MSG_CACHED_IMAGE -> listOf(call(DRAW_OP_IMAGE, payload.copyOfRange(1, payload.size))) + CFW_MSG_CACHED_TEXT -> listOf(call(DRAW_OP_TEXT, payload.copyOfRange(1, payload.size))) + CFW_MSG_RECT_COPY -> listOf(call(DRAW_OP_RECT_COPY, word(CURRENT) + payload.copyOfRange(1, 9) + payload.copyOfRange(9, 13))) else -> error("Unsupported internal draw format $mode") } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt index b9bccf6b..c9d4e670 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt @@ -20,14 +20,17 @@ class CachedResource @JvmOverloads constructor(bytes: ByteArray, val owner: Stri */ class ResourceCacheState { companion object { + /** Mirrors g2flash/patches/resource_cache.h. */ const val CACHE_SIZE = 196608 const val RESOURCE_COUNT = 512 const val TABLE_BYTES = RESOURCE_COUNT * 4 const val ARENA_BYTES = CACHE_SIZE - TABLE_BYTES const val MAX_RESOURCE_SIZE = 65536 const val BLOCK_HEADER_BYTES = 16 - const val UPLOAD_MODE = 21 - const val EVICT_MODE = 22 + + /** Mirrors g2flash/patches/zlib_glue.c. */ + const val UPLOAD_MODE = CFW_MSG_UPLOAD_RESOURCE + const val EVICT_MODE = CFW_MSG_EVICT_RESOURCE fun allocationBytes(size: Int): Int = BLOCK_HEADER_BYTES + ((size + 3) and -4) } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceFlags.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceFlags.kt new file mode 100644 index 00000000..e5f34ea8 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceFlags.kt @@ -0,0 +1,10 @@ +package com.faceclaw.app + +/** Resource header types and flags; mirrored in g2flash/patches/resource_cache.h. */ +const val CFW_RESOURCE_TYPE_IMAGE = 0 +const val CFW_RESOURCE_TYPE_FONT = 1 +const val CFW_RESOURCE_TYPE_DISPLAY_LIST = 2 +const val CFW_RESOURCE_TYPE_MASK = 3 +const val CFW_RESOURCE_FLAG_LARGE = 4 +const val CFW_RESOURCE_FLAG_RLE = 8 +const val CFW_RESOURCE_IMAGE_FLAGS_MASK = CFW_RESOURCE_FLAG_LARGE or CFW_RESOURCE_FLAG_RLE diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt index fb1b2cd1..e132ac2e 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt @@ -47,7 +47,7 @@ class TexturePlanner { private const val MAX_ADJUST_BYTES: Int = 4 /** Options: identity LUT (top 15) + transparent, for mode-19 image draws. */ - private const val IMAGE_DRAW_OPTIONS: Int = 0x1f + private const val IMAGE_DRAW_OPTIONS: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT /** * Plan a cached-draw update. previous is the delta base (the frame the shadow currently @@ -368,12 +368,12 @@ class TexturePlanner { continue } var sub: ByteArray = ByteArray((7 + bytesToLastInk)) - sub[0] = 15 + sub[0] = CFW_MSG_STOCK_FONT_STRING.toByte() sub[1] = ((startX and 0xff)).toByte() sub[2] = (((startX shr 8) and 0xff)).toByte() sub[3] = ((draw.y and 0xff)).toByte() sub[4] = (((draw.y shr 8) and 0xff)).toByte() - sub[5] = ((top or 0x10)).toByte() + sub[5] = ((top or CFW_TEXTURE_OPT_TRANSPARENT)).toByte() sub[6] = (bytesToLastInk).toByte() var pos: Int = 7 run { @@ -718,7 +718,7 @@ class TexturePlanner { /** Mode-19 cached-image draw: [19][resourceId u16][x u16][y u16][options u8]. */ @JvmStatic private fun encodeImageDraw(sel: Selected): ByteArray = byteArrayOf( - 19, sel.resourceId.toByte(), (sel.resourceId ushr 8).toByte(), + CFW_MSG_CACHED_IMAGE.toByte(), sel.resourceId.toByte(), (sel.resourceId ushr 8).toByte(), sel.draw.x.toByte(), (sel.draw.x ushr 8).toByte(), sel.draw.y.toByte(), (sel.draw.y ushr 8).toByte(), IMAGE_DRAW_OPTIONS.toByte(), ) @@ -781,14 +781,14 @@ class TexturePlanner { if (!runGlyphs.isEmpty()) { var stringBytes: ByteArray = string.toByteArray() val run = ByteArray(9 + stringBytes.size) - run[0] = 20 + run[0] = CFW_MSG_CACHED_TEXT.toByte() run[1] = fontResource.toByte() run[2] = (fontResource ushr 8).toByte() run[3] = first.gx.toByte() run[4] = (first.gx ushr 8).toByte() run[5] = first.draw.y.toByte() run[6] = (first.draw.y ushr 8).toByte() - run[7] = (first.top or 0x10).toByte() + run[7] = (first.top or CFW_TEXTURE_OPT_TRANSPARENT).toByte() run[8] = stringBytes.size.toByte() stringBytes.copyInto(run, 9) outRuns.add(run) @@ -825,7 +825,7 @@ class TexturePlanner { total += (2 + sub.size) } var out: ByteArray = ByteArray(total) - out[0] = 8 + out[0] = CFW_MSG_MULTI_SEGMENT.toByte() out[1] = (subs.size).toByte() var pos: Int = 2 for (sub in subs) { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt index 68c8f60e..2166d3a5 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt @@ -39,28 +39,28 @@ class DisplayListRenderer(private val resources: Map, private va } private fun image(b: ByteArray, start: Int = 0): Image { require(start in b.indices); val flags = b[start].toInt() and 255 - require(flags and 12 == flags) - val header = if (flags and 4 != 0) 5 else 3 + require(flags and CFW_RESOURCE_IMAGE_FLAGS_MASK == flags) + val header = if (flags and CFW_RESOURCE_FLAG_LARGE != 0) 5 else 3 require(b.size - start >= header) val w = if (header == 5) word(b, start + 1) else b[start + 1].toInt() and 255 val h = if (header == 5) word(b, start + 3) else b[start + 2].toInt() and 255 require(w in 1..640 && h in 1..480) - val pixels = if (flags and 8 != 0) decodeRle(b, start + header, w * h, false) + val pixels = if (flags and CFW_RESOURCE_FLAG_RLE != 0) decodeRle(b, start + header, w * h, false) else { val t = Target(b, w, h, start + header); IntArray(w * h) { t.get(it % w, it / w) } } return Image(w, h, pixels) } private fun target(id: Int): Target { - val b = resource(id); require(b.isNotEmpty() && b[0].toInt() and 11 == 0) + val b = resource(id); require(b.isNotEmpty() && b[0].toInt() and (CFW_RESOURCE_TYPE_MASK or CFW_RESOURCE_FLAG_RLE) == 0) image(b) // Validate the complete raw image before exposing a write target. - return if (b[0].toInt() and 4 != 0) Target(b, word(b, 1), word(b, 3), 5) + return if (b[0].toInt() and CFW_RESOURCE_FLAG_LARGE != 0) Target(b, word(b, 1), word(b, 3), 5) else Target(b, b[1].toInt() and 255, b[2].toInt() and 255, 3) } private fun draw(image: Image, target: Target, x: Int, y: Int, options: Int, apply: Boolean) { if (!apply) return for (i in image.pixels.indices) { - val v = image.pixels[i]; if (v == 0 && options and 16 != 0) continue - val source = if (options and 32 != 0) 15 - v else v - target.put(x + i % image.width, y + i / image.width, source * (options and 15) / 15) + val v = image.pixels[i]; if (v == 0 && options and CFW_TEXTURE_OPT_TRANSPARENT != 0) continue + val source = if (options and CFW_TEXTURE_OPT_INVERSE != 0) 15 - v else v + target.put(x + i % image.width, y + i / image.width, source * (options and CFW_TEXTURE_OPT_BRIGHTNESS_MASK) / 15) } } private fun copyScreen(screen: Target, composition: Target) { @@ -108,7 +108,7 @@ class DisplayListRenderer(private val resources: Map, private va return references } private fun executeList(id: Int, t: Target, screen: Target, apply: Boolean, stack: MutableList, budget: IntArray, refs: MutableSet) { - require(stack.size < 8 && id !in stack); val b = resource(id); require(b.size >= 3 && b[0].toInt() == 2) + require(stack.size < 8 && id !in stack); val b = resource(id); require(b.size >= 3 && b[0].toInt() == CFW_RESOURCE_TYPE_DISPLAY_LIST) refs.add(id); stack.add(id); executeSequence(b.copyOfRange(1, b.size), t, screen, apply, stack, budget, refs); stack.removeAt(stack.lastIndex) } private fun executeSequence(b: ByteArray, inherited: Target, screen: Target, apply: Boolean, stack: MutableList, budget: IntArray, refs: MutableSet) { @@ -116,14 +116,14 @@ class DisplayListRenderer(private val resources: Map, private va repeat(count) { val n = word(b, pos); pos += 2; require(n >= 2 && n <= b.size - pos && budget[0]-- > 0) val call = b.copyOfRange(pos, pos + n); pos += n - val flags = call[1].toInt() and 255; require(flags <= 3) + val flags = call[1].toInt() and 255; require(flags and DRAW_FLAGS_MASK.inv() == 0) var t = inherited; var header = 2 - if (flags and 1 != 0) { val id = word(call, 2); refs.add(id); t = target(id).shifted(inherited.shiftX); header += 2 } - if (flags and 2 != 0) { require(header < call.size); t = t.shifted(DrawProtocol.depthOffset(call[header++].toInt(), rightLens)) } + if (flags and DRAW_FLAG_RESOURCE_TARGET != 0) { val id = word(call, 2); refs.add(id); t = target(id).shifted(inherited.shiftX); header += 2 } + if (flags and DRAW_FLAG_DEPTH != 0) { require(header < call.size); t = t.shifted(DrawProtocol.depthOffset(call[header++].toInt(), rightLens)) } val p = call.copyOfRange(header, call.size) when (call[0].toInt()) { - 1 -> { - require(p.isNotEmpty() && p[0].toInt() in 0..1); val wide = p[0].toInt() == 1 + DRAW_OP_BOUNDING_BOX -> { + require(p.isNotEmpty() && (p[0].toInt() and 255) and DRAW_BBOX_FLAG_U16.inv() == 0); val wide = p[0].toInt() and DRAW_BBOX_FLAG_U16 != 0 require(p.size >= if (wide) 9 else 5) val x = if (wide) word(p, 1) else (p[1].toInt() and 255) * 4 val y = if (wide) word(p, 3) else (p[2].toInt() and 255) * 2 @@ -133,7 +133,7 @@ class DisplayListRenderer(private val resources: Map, private va val pixels = decodeRle(p, if (wide) 9 else 5, w * h, true) if (apply) for (i in pixels.indices) t.put(x + i % w, y + i / w, pixels[i]) } - 2 -> { + DRAW_OP_RECT_COPY -> { require(p.size == 14); val id = word(p, 0) val src = when(id) { DrawProtocol.SCREEN -> screen; DrawProtocol.CURRENT -> t; else -> { refs.add(id); target(id) } } val x = word(p, 2); val y = word(p, 4); val w = word(p, 6); val h = word(p, 8) @@ -142,7 +142,7 @@ class DisplayListRenderer(private val resources: Map, private va if (apply) { val copy = IntArray(w * h) { src.get(x + it % w, y + it / w) } for (i in copy.indices) t.put(dx + i % w, dy + i / w, copy[i]) } } - 3 -> { + DRAW_OP_STOCK_FONT_STRING -> { require(p.size >= 6 && p.size == 6 + (p[5].toInt() and 255)) val text = p.copyOfRange(6, p.size).decodeToString(throwOnInvalidSequence = true) val cps = ArrayList(); var i = 0 @@ -156,12 +156,12 @@ class DisplayListRenderer(private val resources: Map, private va draw(image(g.image), t, x + g.x, y + g.y, p[4].toInt() and 255, apply); x += g.advance } } - 4, 5 -> { - val font = call[0].toInt() == 5; require(if(font) p.size >= 8 && p.size == 8 + (p[7].toInt() and 255) else p.size == 7) + DRAW_OP_IMAGE, DRAW_OP_TEXT -> { + val font = call[0].toInt() == DRAW_OP_TEXT; require(if(font) p.size >= 8 && p.size == 8 + (p[7].toInt() and 255) else p.size == 7) val id = word(p, 0); refs.add(id); val data = resource(id) var x = signed(p, 2); val y = signed(p, 4); val options = p[6].toInt() and 255 if (!font) draw(image(data), t, x, y, options, apply) - else { require(data.size >= 193 && data[0].toInt() == 1) + else { require(data.size >= 193 && data[0].toInt() == CFW_RESOURCE_TYPE_FONT) for (j in 8 until p.size) { val ch = p[j].toInt() and 255 if(ch in 1..31) { x += ch - 11; continue }; require(ch in 32..127) val offset = word(data, 1 + (ch - 32) * 2); require(offset >= 193) @@ -169,7 +169,7 @@ class DisplayListRenderer(private val resources: Map, private va } } } - 6 -> { + DRAW_OP_REMAP_COLORS -> { require(p.size == 16); val x = word(p, 0); val y = word(p, 2); val w = word(p, 4); val h = word(p, 6) require(w > 0 && h > 0 && x + w <= t.width && y + h <= t.height) if (apply) for(yy in y until y + h) for(xx in x until x + w) { @@ -177,20 +177,20 @@ class DisplayListRenderer(private val resources: Map, private va val v = t.get(xx + t.shiftX, yy) t.put(xx, yy, (p[8 + v / 2].toInt() ushr (if(v % 2 == 0) 4 else 0)) and 15) } } - 8 -> { + DRAW_OP_ROUNDED_RECT -> { require(p.size == 12) val x = signed(p, 0); val y = signed(p, 2); val w = word(p, 4); val h = word(p, 6) val radius = word(p, 8); val fill = p[10].toInt() and 255; val border = p[11].toInt() and 255 - require(w in 1..640 && h in 1..480 && fill <= 15 && border <= 16) + require(w in 1..640 && h in 1..480 && fill <= 15 && border <= DRAW_ROUNDED_RECT_NO_BORDER) if (apply) for (yy in 0 until h) for (xx in 0 until w) { if (!roundedContains(xx, yy, w, h, radius)) continue val tx = x + xx + t.shiftX; val ty = y + yy if (tx !in 0 until t.width || ty !in 0 until t.height) continue val edge = !roundedContains(xx - 1, yy - 1, w - 2, h - 2, maxOf(0, radius - 1)) - t.put(x + xx, ty, if (edge && border < 16) border else maxOf(fill, t.get(tx, ty))) + t.put(x + xx, ty, if (edge && border < DRAW_ROUNDED_RECT_NO_BORDER) border else maxOf(fill, t.get(tx, ty))) } } - 7 -> { require(p.size == 2); executeList(word(p, 0), t, screen, apply, stack, budget, refs) } + DRAW_OP_DISPLAY_LIST -> { require(p.size == 2); executeList(word(p, 0), t, screen, apply, stack, budget, refs) } else -> error("Unknown draw opcode") } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt index c5630483..5a6c3e6b 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt @@ -9,16 +9,16 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val fun calls(id: Int): List { val image = when (kind) { 3 -> listOf(DrawProtocol.roundedRect(x, y, width, height, radius, background, border, depth), - DrawProtocol.image(id, x, y, 31, depth = depth)) - 4 -> listOf(DrawProtocol.image(id, x, y, 31, depth = depth)) + DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) + 4 -> listOf(DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) // Gray8 zero is transparent but gray8 one is opaque black. Rect copies preserve // that distinction after packing, including the transparent corners of app menus. - 5 -> mask.map { r -> DrawProtocol.call(2, DrawProtocol.word(id) + + 5 -> mask.map { r -> DrawProtocol.call(DRAW_OP_RECT_COPY, DrawProtocol.word(id) + r.flatMap { DrawProtocol.word(it).toList() }.toByteArray() + DrawProtocol.word(x + r[0]) + DrawProtocol.word(y + r[1]), depth = depth) } else -> error("Invalid presentation kind") } - return image + occlusions.map { r -> DrawProtocol.call(2, DrawProtocol.word(DrawProtocol.SCREEN) + r.flatMap { DrawProtocol.word(it).toList() }.toByteArray() + DrawProtocol.word(r[0]) + DrawProtocol.word(r[1])) } + return image + occlusions.map { r -> DrawProtocol.call(DRAW_OP_RECT_COPY, DrawProtocol.word(DrawProtocol.SCREEN) + r.flatMap { DrawProtocol.word(it).toList() }.toByteArray() + DrawProtocol.word(r[0]) + DrawProtocol.word(r[1])) } } companion object { /** The caller has consumed the presentation tag (3, 4 or 5). Colors cross the bridge in gray8, pixels in gray8 rows. */ diff --git a/tests/ios-app-host.test.cjs b/tests/ios-app-host.test.cjs index 2547a4a4..1a3b69cd 100644 --- a/tests/ios-app-host.test.cjs +++ b/tests/ios-app-host.test.cjs @@ -419,7 +419,7 @@ test('iOS compositor rejects missing and removed surfaces before crossing into K test('iOS welcome sound waits for a new acknowledged frame and is consumed once', async () => { let pending = true; - const played = [], sounds = load('app/ui/sound-effects.ts', {}); + const played = [], sounds = load('app/ui/sound-effects.ts', { require: name => { assert.equal(name, '../g2/cfw-message-type'); return load('app/g2/cfw-message-type.ts', {}); } }); const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', { require: id => ({ '../phone-ui/onboarding-state': { isWelcomeSoundPending: () => pending, setWelcomeSoundPending: value => { pending = value; } }, diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt index e5177b95..385ba448 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt @@ -48,8 +48,8 @@ class DisplayListTest { val resources = mutableMapOf(10 to raw, 11 to hex("0802024f"), 12 to font) val nested = listOf(DrawProtocol.image(11, -1, 0), DrawProtocol.bbox(hex("0c000000"), 2, 1, 0, 1, 1, 10)) resources[20]=DrawProtocol.displayList(nested) - val calls = listOf(DrawProtocol.call(7,DrawProtocol.word(20)), DrawProtocol.image(10,3,1), - DrawProtocol.call(5,hex("0c00070003000f0141")), DrawProtocol.lut(8,4,128)) + val calls = listOf(DrawProtocol.call(DRAW_OP_DISPLAY_LIST,DrawProtocol.word(20)), DrawProtocol.image(10,3,1), + DrawProtocol.call(DRAW_OP_TEXT,hex("0c00070003000f0141")), DrawProtocol.lut(8,4,128)) resources[21]=DrawProtocol.displayList(calls) val screen=hex("123456789abcdef0123456789abcdef0"); val output=ByteArray(16) val renderer=DisplayListRenderer(resources) @@ -62,14 +62,14 @@ class DisplayListTest { } @Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() { val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1) - val copy=DrawProtocol.call(2,hex("feff000000000600010002000000")) + val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff000000000600010002000000")) DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(copy)),target) assertContentEquals(hex("12123456"),screen) val valid=DrawProtocol.bbox(hex("ffffffff"),4,0,0,8,1) assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(valid,byteArrayOf(99,0))),target) } assertContentEquals(hex("12123456"),screen) - val cyclic=mapOf(1 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(2)))), - 2 to DrawProtocol.displayList(listOf(DrawProtocol.call(7,DrawProtocol.word(1))))) + val cyclic=mapOf(1 to DrawProtocol.displayList(listOf(DrawProtocol.call(DRAW_OP_DISPLAY_LIST,DrawProtocol.word(2)))), + 2 to DrawProtocol.displayList(listOf(DrawProtocol.call(DRAW_OP_DISPLAY_LIST,DrawProtocol.word(1))))) assertFails { DisplayListRenderer(cyclic).render(1,target,target) } } @Test fun roundedRectsAndNestedOddNegativeDepthMatchFirmwareOnBothLenses() { @@ -95,7 +95,7 @@ class DisplayListTest { val fill = DrawProtocol.roundedRect(-1,0,8,8,2,6,16,2) DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(fill)),target) assertEquals(15,target.get(2,3)); assertEquals(6,target.get(3,3)); assertEquals(1,target.get(0,0)) - val bbox = DrawProtocol.call(1,hex("00000002010f10"),depth=-1) + val bbox = DrawProtocol.call(DRAW_OP_BOUNDING_BOX,hex("00000002010f10"),depth=-1) DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(bbox)),target) assertEquals(15,target.get(0,0));assertEquals(1,target.get(7,0)) val before=pixels.copyOf() From f9724ddcabbebc7d497698c1e418ca01557d1caa Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 17:26:09 -0700 Subject: [PATCH 10/27] Convert remaining Java to Kotlin --- App_Resources/Android/app.gradle | 2 +- .../com/faceclaw/app/AndroidNoiseEffects.java | 59 - .../com/faceclaw/app/AndroidNoiseEffects.kt | 67 + .../faceclaw/app/FaceclawAlarmActivity.java | 181 - .../com/faceclaw/app/FaceclawAlarmActivity.kt | 179 + .../faceclaw/app/FaceclawAlarmReceiver.java | 27 - .../com/faceclaw/app/FaceclawAlarmReceiver.kt | 26 + .../app/FaceclawAlarmRescheduleReceiver.java | 34 - .../app/FaceclawAlarmRescheduleReceiver.kt | 28 + .../faceclaw/app/FaceclawAlarmService.java | 649 --- .../com/faceclaw/app/FaceclawAlarmService.kt | 629 +++ .../java/com/faceclaw/app/FaceclawAlarms.java | 620 --- .../java/com/faceclaw/app/FaceclawAlarms.kt | 647 +++ .../faceclaw/app/FaceclawAudioTranscoder.java | 242 - .../faceclaw/app/FaceclawAudioTranscoder.kt | 236 + .../faceclaw/app/FaceclawBleCommunicator.java | 4100 ----------------- .../faceclaw/app/FaceclawBleCommunicator.kt | 4072 ++++++++++++++++ .../com/faceclaw/app/FaceclawBleManager.java | 558 --- .../com/faceclaw/app/FaceclawBleManager.kt | 539 +++ .../app/FaceclawCalendarProvider.java | 98 - .../faceclaw/app/FaceclawCalendarProvider.kt | 96 + .../faceclaw/app/FaceclawCaptionEngine.java | 446 -- .../com/faceclaw/app/FaceclawCaptionEngine.kt | 456 ++ .../app/FaceclawConversationStore.java | 778 ---- .../faceclaw/app/FaceclawConversationStore.kt | 790 ++++ .../faceclaw/app/FaceclawDeviceDiscovery.java | 386 -- .../faceclaw/app/FaceclawDeviceDiscovery.kt | 372 ++ .../faceclaw/app/FaceclawDeviceInfoProbe.java | 619 --- .../faceclaw/app/FaceclawDeviceInfoProbe.kt | 629 +++ .../com/faceclaw/app/FaceclawDiarizer.java | 262 -- .../java/com/faceclaw/app/FaceclawDiarizer.kt | 260 ++ .../faceclaw/app/FaceclawEvenAppDetector.java | 87 - .../faceclaw/app/FaceclawEvenAppDetector.kt | 90 + .../app/FaceclawEvenHubDocumentStart.java | 50 - .../app/FaceclawEvenHubDocumentStart.kt | 50 + .../faceclaw/app/FaceclawEvenHubJsBridge.java | 34 - .../faceclaw/app/FaceclawEvenHubJsBridge.kt | 26 + ...WebView.java => FaceclawEvenHubWebView.kt} | 19 +- .../app/FaceclawEvenHubWebViewClient.java | 172 - .../app/FaceclawEvenHubWebViewClient.kt | 158 + ...ost.java => FaceclawEvenHubWebViewHost.kt} | 149 +- .../faceclaw/app/FaceclawFirmwareFlasher.java | 695 --- .../faceclaw/app/FaceclawFirmwareFlasher.kt | 707 +++ .../app/FaceclawFlashPromptCommunicator.java | 546 --- .../app/FaceclawFlashPromptCommunicator.kt | 566 +++ .../app/FaceclawForegroundService.java | 142 - .../faceclaw/app/FaceclawForegroundService.kt | 141 + .../java/com/faceclaw/app/FaceclawHttp.java | 42 - .../java/com/faceclaw/app/FaceclawHttp.kt | 47 + .../com/faceclaw/app/FaceclawLc3Decoder.java | 117 - .../com/faceclaw/app/FaceclawLc3Decoder.kt | 130 + .../com/faceclaw/app/FaceclawLlamaRunner.java | 122 - .../com/faceclaw/app/FaceclawLlamaRunner.kt | 133 + .../app/FaceclawLocationProvider.java | 196 - .../faceclaw/app/FaceclawLocationProvider.kt | 188 + .../faceclaw/app/FaceclawLocationTracker.java | 188 - .../faceclaw/app/FaceclawLocationTracker.kt | 184 + .../faceclaw/app/FaceclawMediaBrowser.java | 321 -- .../com/faceclaw/app/FaceclawMediaBrowser.kt | 316 ++ .../faceclaw/app/FaceclawMediaController.java | 576 --- .../faceclaw/app/FaceclawMediaController.kt | 577 +++ ...eclawMediaNotificationListenerService.java | 657 --- ...aceclawMediaNotificationListenerService.kt | 662 +++ .../faceclaw/app/FaceclawModelDownloader.java | 187 - .../faceclaw/app/FaceclawModelDownloader.kt | 198 + .../app/FaceclawPreviewCompositor.java | 198 - .../faceclaw/app/FaceclawPreviewCompositor.kt | 199 + .../com/faceclaw/app/FaceclawQrScanner.java | 81 - .../com/faceclaw/app/FaceclawQrScanner.kt | 74 + .../com/faceclaw/app/FaceclawRemoteInput.java | 143 - .../com/faceclaw/app/FaceclawRemoteInput.kt | 152 + .../faceclaw/app/FaceclawResourceUsage.java | 68 - .../com/faceclaw/app/FaceclawResourceUsage.kt | 72 + .../com/faceclaw/app/FaceclawSettings.java | 121 - .../java/com/faceclaw/app/FaceclawSettings.kt | 112 + .../app/FaceclawSettingsPortReceiver.java | 141 - .../app/FaceclawSettingsPortReceiver.kt | 146 + .../com/faceclaw/app/FaceclawSpeakerId.java | 111 - .../com/faceclaw/app/FaceclawSpeakerId.kt | 116 + .../com/faceclaw/app/FaceclawSseRequest.java | 145 - .../com/faceclaw/app/FaceclawSseRequest.kt | 156 + .../app/FaceclawSystemStatusIconProvider.java | 193 - .../app/FaceclawSystemStatusIconProvider.kt | 193 + .../faceclaw/app/FaceclawVoiceController.java | 1162 ----- .../faceclaw/app/FaceclawVoiceController.kt | 1186 +++++ .../com/faceclaw/app/FaceclawWearBridge.java | 391 -- .../com/faceclaw/app/FaceclawWearBridge.kt | 386 ++ .../app/FaceclawWearListenerService.java | 26 - .../app/FaceclawWearListenerService.kt | 24 + .../com/faceclaw/app/FaceclawWebSocket.java | 151 - .../com/faceclaw/app/FaceclawWebSocket.kt | 156 + .../com/faceclaw/app/FontFileRenderer.java | 537 --- .../java/com/faceclaw/app/FontFileRenderer.kt | 574 +++ .../java/com/faceclaw/app/FrameTimings.java | 567 --- .../java/com/faceclaw/app/FrameTimings.kt | 554 +++ .../com/faceclaw/app/GifScreenRecorder.java | 26 - .../com/faceclaw/app/GifScreenRecorder.kt | 27 + .../java/com/faceclaw/app/IconRenderer.java | 185 - .../java/com/faceclaw/app/IconRenderer.kt | 196 + .../com/faceclaw/app/ImageFileLoader.java | 229 - .../java/com/faceclaw/app/ImageFileLoader.kt | 246 + .../com/faceclaw/app/PreviewBitmapUtil.java | 56 - .../com/faceclaw/app/PreviewBitmapUtil.kt | 61 + .../java/com/faceclaw/app/ScreenshotUtil.java | 45 - .../java/com/faceclaw/app/ScreenshotUtil.kt | 49 + .../faceclaw/app/util/InterruptibleSleep.java | 48 - .../faceclaw/app/util/InterruptibleSleep.kt | 48 + CLAUDE.md | 9 +- app/apps/timer/timer-engine.ts | 2 +- app/g2/dashboard-controller.ts | 7 +- app/native/asr-model.ts | 2 +- app/native/frame-timings.ts | 2 +- native/kotlin/README.md | 17 +- native/kotlin/android-java-boundaries.json | 114 - native/kotlin/migrated-java-sources.json | 314 +- tests/kotlin-build.test.cjs | 2 +- tests/music-settings.test.cjs | 118 +- wear/PROTOCOL.md | 2 +- 118 files changed, 18381 insertions(+), 18119 deletions(-) delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt rename App_Resources/Android/src/main/java/com/faceclaw/app/{FaceclawEvenHubWebView.java => FaceclawEvenHubWebView.kt} (78%) delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt rename App_Resources/Android/src/main/java/com/faceclaw/app/{FaceclawEvenHubWebViewHost.java => FaceclawEvenHubWebViewHost.kt} (56%) delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.java create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt diff --git a/App_Resources/Android/app.gradle b/App_Resources/Android/app.gradle index 832823ad..65d42a3c 100644 --- a/App_Resources/Android/app.gradle +++ b/App_Resources/Android/app.gradle @@ -296,7 +296,7 @@ def removeLegacyKotlinBridgeSource = tasks.register("removeLegacyKotlinBridgeSou // Explicit, reviewed source moves: never infer deletions from class names. def migrations = new groovy.json.JsonSlurper().parse(file("$rootDir/../../native/kotlin/migrated-java-sources.json")) migrations.each { migration -> - if (!file("$rootDir/../../native/kotlin/${migration.kotlin}").isFile()) { + if (!file("$rootDir/../../${migration.kotlin}").isFile()) { throw new GradleException("Missing Kotlin replacement: ${migration.kotlin}") } delete file("$projectDir/src/main/java/${migration.java}") diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.java b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.java deleted file mode 100644 index 72757990..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.faceclaw.app; - -import android.media.audiofx.*; -import java.util.ArrayList; - -/** Android AudioRecord effect attachment; PCM processing lives in shared Kotlin. */ -public final class AndroidNoiseEffects { - /** Whether this Android build ships the built-in capture noise suppressor. */ - public static boolean platformSuppressorAvailable() { - try { - return NoiseSuppressor.isAvailable(); - } catch (Throwable t) { - return false; - } - } - - /** Short engine name for the UI. */ - public static String engineDescription() { - return "spectral (phone DSP)"; - } - - /** - * Attach the platform's built-in capture-effect chain (NoiseSuppressor, - * AcousticEchoCanceler, AutomaticGainControl — whichever this Android - * build provides) to a phone AudioRecord session. Only applicable when the - * phone itself captures the audio; the BLE glasses stream must go through - * {@link #process(byte[])} instead. The caller keeps the returned effects - * for the life of the recording and release()s them with it. - */ - public static AudioEffect[] attachPlatformEffects(int audioSessionId) { - ArrayList effects = new ArrayList<>(); - try { - if (NoiseSuppressor.isAvailable()) { - NoiseSuppressor ns = NoiseSuppressor.create(audioSessionId); - if (ns != null) { - ns.setEnabled(true); - effects.add(ns); - } - } - if (AcousticEchoCanceler.isAvailable()) { - AcousticEchoCanceler aec = AcousticEchoCanceler.create(audioSessionId); - if (aec != null) { - aec.setEnabled(true); - effects.add(aec); - } - } - if (AutomaticGainControl.isAvailable()) { - AutomaticGainControl agc = AutomaticGainControl.create(audioSessionId); - if (agc != null) { - agc.setEnabled(true); - effects.add(agc); - } - } - } catch (Throwable t) { - // A missing effect just means this tier is unavailable. - } - return effects.toArray(new AudioEffect[0]); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.kt new file mode 100644 index 00000000..a8db0cb5 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.kt @@ -0,0 +1,67 @@ +package com.faceclaw.app + +import android.media.audiofx.AcousticEchoCanceler +import android.media.audiofx.AudioEffect +import android.media.audiofx.AutomaticGainControl +import android.media.audiofx.NoiseSuppressor +import java.util.ArrayList + +/** Android AudioRecord effect attachment; PCM processing lives in shared Kotlin. */ +class AndroidNoiseEffects { + companion object { + /** Whether this Android build ships the built-in capture noise suppressor. */ + @JvmStatic + fun platformSuppressorAvailable(): Boolean { + return try { + NoiseSuppressor.isAvailable() + } catch (t: Throwable) { + false + } + } + + /** Short engine name for the UI. */ + @JvmStatic + fun engineDescription(): String { + return "spectral (phone DSP)" + } + + /** + * Attach the platform's built-in capture-effect chain (NoiseSuppressor, + * AcousticEchoCanceler, AutomaticGainControl — whichever this Android + * build provides) to a phone AudioRecord session. Only applicable when the + * phone itself captures the audio; the BLE glasses stream must go through + * {@link #process(byte[])} instead. The caller keeps the returned effects + * for the life of the recording and release()s them with it. + */ + @JvmStatic + fun attachPlatformEffects(audioSessionId: Int): Array { + val effects = ArrayList() + try { + if (NoiseSuppressor.isAvailable()) { + val ns = NoiseSuppressor.create(audioSessionId) + if (ns != null) { + ns.setEnabled(true) + effects.add(ns) + } + } + if (AcousticEchoCanceler.isAvailable()) { + val aec = AcousticEchoCanceler.create(audioSessionId) + if (aec != null) { + aec.setEnabled(true) + effects.add(aec) + } + } + if (AutomaticGainControl.isAvailable()) { + val agc = AutomaticGainControl.create(audioSessionId) + if (agc != null) { + agc.setEnabled(true) + effects.add(agc) + } + } + } catch (t: Throwable) { + // A missing effect just means this tier is unavailable. + } + return effects.toTypedArray() + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.java deleted file mode 100644 index d490ed5d..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.faceclaw.app; - -import android.app.Activity; -import android.app.KeyguardManager; -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.Typeface; -import android.os.Build; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.View; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; - -import java.text.DateFormat; -import java.util.Date; -import java.util.List; - -/** - * The phone's ringing screen: shown over the lock screen by the alarm - * notification's full-screen intent (or by tapping the notification). Pure - * Java, so it works with the JavaScript side asleep or gone. Snooze and - * Dismiss go to the service, which journals them for the engine. - */ -public class FaceclawAlarmActivity extends Activity { - private final Handler handler = new Handler(Looper.getMainLooper()); - private TextView titleView; - private TextView textView; - private TextView timeView; - private Button snoozeButton; - private long itemId; - - private final Runnable poll = new Runnable() { - @Override - public void run() { - List items = FaceclawAlarmService.snapshot(); - if (items.isEmpty()) { - finish(); - return; - } - FaceclawAlarmService.Ringing shown = null; - for (FaceclawAlarmService.Ringing item : items) { - if (item.id == itemId) { - shown = item; - } - } - if (shown == null) { - shown = items.get(0); - itemId = shown.id; - } - render(shown, items.size()); - handler.postDelayed(this, 1000); - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - showOverLockScreen(); - itemId = getIntent() == null ? 0 : getIntent().getLongExtra(FaceclawAlarms.EXTRA_ID, 0); - setContentView(buildLayout()); - } - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - setIntent(intent); - itemId = intent == null ? 0 : intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0); - } - - @Override - protected void onResume() { - super.onResume(); - handler.post(poll); - } - - @Override - protected void onPause() { - handler.removeCallbacks(poll); - super.onPause(); - } - - private void showOverLockScreen() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { - setShowWhenLocked(true); - setTurnScreenOn(true); - KeyguardManager keyguard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); - if (keyguard != null) { - keyguard.requestDismissKeyguard(this, null); - } - } else { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED - | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON - | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); - } - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - - private View buildLayout() { - LinearLayout root = new LinearLayout(this); - root.setOrientation(LinearLayout.VERTICAL); - root.setGravity(Gravity.CENTER); - root.setBackgroundColor(Color.BLACK); - int pad = dp(32); - root.setPadding(pad, pad, pad, pad); - - timeView = new TextView(this); - timeView.setTextColor(Color.WHITE); - timeView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 64); - timeView.setTypeface(Typeface.DEFAULT_BOLD); - timeView.setGravity(Gravity.CENTER); - root.addView(timeView, wrap()); - - titleView = new TextView(this); - titleView.setTextColor(Color.WHITE); - titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28); - titleView.setGravity(Gravity.CENTER); - titleView.setPadding(0, dp(16), 0, 0); - root.addView(titleView, wrap()); - - textView = new TextView(this); - textView.setTextColor(Color.LTGRAY); - textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); - textView.setGravity(Gravity.CENTER); - textView.setPadding(0, dp(8), 0, dp(40)); - root.addView(textView, wrap()); - - snoozeButton = new Button(this); - snoozeButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); - snoozeButton.setOnClickListener(view -> act(FaceclawAlarmService.ACTION_SNOOZE)); - root.addView(snoozeButton, button()); - - Button dismissButton = new Button(this); - dismissButton.setText("Dismiss"); - dismissButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); - dismissButton.setOnClickListener(view -> act(FaceclawAlarmService.ACTION_DISMISS)); - root.addView(dismissButton, button()); - return root; - } - - private void render(FaceclawAlarmService.Ringing item, int count) { - timeView.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date())); - titleView.setText(count > 1 ? item.title + " (+" + (count - 1) + " more)" : item.title); - String status = item.silenced ? "Not answered" : item.escalated ? "" : "Ringing on the glasses"; - textView.setText(item.text.isEmpty() ? status : status.isEmpty() ? item.text : item.text + "\n" + status); - snoozeButton.setText(FaceclawAlarms.KIND_TIMER.equals(item.kind) - ? "+" + item.snoozeMinutes + " min" - : "Snooze " + item.snoozeMinutes + " min"); - } - - /** Apply the action to every ringing item (one tap silences the phone). */ - private void act(String action) { - for (FaceclawAlarmService.Ringing item : FaceclawAlarmService.snapshot()) { - Intent intent = new Intent(this, FaceclawAlarmService.class) - .setAction(action) - .putExtra(FaceclawAlarms.EXTRA_ID, item.id); - startService(intent); - } - finish(); - } - - private LinearLayout.LayoutParams wrap() { - return new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - } - - private LinearLayout.LayoutParams button() { - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, dp(64)); - params.topMargin = dp(12); - return params; - } - - private int dp(int value) { - return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics())); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.kt new file mode 100644 index 00000000..3aab1c35 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.kt @@ -0,0 +1,179 @@ +package com.faceclaw.app + +import android.app.Activity +import android.app.KeyguardManager +import android.content.Context +import android.content.Intent +import android.graphics.Color +import android.graphics.Typeface +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.util.TypedValue +import android.view.Gravity +import android.view.View +import android.view.WindowManager +import android.widget.Button +import android.widget.LinearLayout +import android.widget.TextView + +import java.text.DateFormat +import java.util.Date + +/** + * The phone's ringing screen: shown over the lock screen by the alarm + * notification's full-screen intent (or by tapping the notification). Pure + * Java, so it works with the JavaScript side asleep or gone. Snooze and + * Dismiss go to the service, which journals them for the engine. + */ +class FaceclawAlarmActivity : Activity() { + private val handler = Handler(Looper.getMainLooper()) + private var titleView: TextView? = null + private var textView: TextView? = null + private var timeView: TextView? = null + private var snoozeButton: Button? = null + private var itemId: Long = 0 + + private val poll: Runnable = object : Runnable { + override fun run() { + val items = FaceclawAlarmService.snapshot() + if (items.isEmpty()) { + finish() + return + } + var shown: FaceclawAlarmService.Ringing? = null + for (item in items) { + if (item.id == itemId) { + shown = item + } + } + if (shown == null) { + shown = items[0] + itemId = shown.id + } + render(shown, items.size) + handler.postDelayed(this, 1000) + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + showOverLockScreen() + itemId = if (intent == null) 0 else intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0) + setContentView(buildLayout()) + } + + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + setIntent(intent) + itemId = if (intent == null) 0 else intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0) + } + + override fun onResume() { + super.onResume() + handler.post(poll) + } + + override fun onPause() { + handler.removeCallbacks(poll) + super.onPause() + } + + private fun showOverLockScreen() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + setShowWhenLocked(true) + setTurnScreenOn(true) + val keyguard = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager? + keyguard?.requestDismissKeyguard(this, null) + } else { + @Suppress("DEPRECATION") + window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON + or WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD) + } + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + + private fun buildLayout(): View { + val root = LinearLayout(this) + root.orientation = LinearLayout.VERTICAL + root.gravity = Gravity.CENTER + root.setBackgroundColor(Color.BLACK) + val pad = dp(32) + root.setPadding(pad, pad, pad, pad) + + val time = TextView(this) + time.setTextColor(Color.WHITE) + time.setTextSize(TypedValue.COMPLEX_UNIT_SP, 64f) + time.typeface = Typeface.DEFAULT_BOLD + time.gravity = Gravity.CENTER + root.addView(time, wrap()) + timeView = time + + val title = TextView(this) + title.setTextColor(Color.WHITE) + title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28f) + title.gravity = Gravity.CENTER + title.setPadding(0, dp(16), 0, 0) + root.addView(title, wrap()) + titleView = title + + val text = TextView(this) + text.setTextColor(Color.LTGRAY) + text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f) + text.gravity = Gravity.CENTER + text.setPadding(0, dp(8), 0, dp(40)) + root.addView(text, wrap()) + textView = text + + val snooze = Button(this) + snooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f) + snooze.setOnClickListener { act(FaceclawAlarmService.ACTION_SNOOZE) } + root.addView(snooze, button()) + snoozeButton = snooze + + val dismissButton = Button(this) + dismissButton.text = "Dismiss" + dismissButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20f) + dismissButton.setOnClickListener { act(FaceclawAlarmService.ACTION_DISMISS) } + root.addView(dismissButton, button()) + return root + } + + private fun render(item: FaceclawAlarmService.Ringing, count: Int) { + timeView!!.text = DateFormat.getTimeInstance(DateFormat.SHORT).format(Date()) + titleView!!.text = if (count > 1) item.title + " (+" + (count - 1) + " more)" else item.title + val status = if (item.silenced) "Not answered" else if (item.escalated) "" else "Ringing on the glasses" + textView!!.text = if (item.text.isEmpty()) status else if (status.isEmpty()) item.text else item.text + "\n" + status + snoozeButton!!.text = if (FaceclawAlarms.KIND_TIMER == item.kind) + "+" + item.snoozeMinutes + " min" + else + "Snooze " + item.snoozeMinutes + " min" + } + + /** Apply the action to every ringing item (one tap silences the phone). */ + private fun act(action: String) { + for (item in FaceclawAlarmService.snapshot()) { + val intent = Intent(this, FaceclawAlarmService::class.java) + .setAction(action) + .putExtra(FaceclawAlarms.EXTRA_ID, item.id) + startService(intent) + } + finish() + } + + private fun wrap(): LinearLayout.LayoutParams { + return LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT) + } + + private fun button(): LinearLayout.LayoutParams { + val params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, dp(64)) + params.topMargin = dp(12) + return params + } + + private fun dp(value: Int): Int { + return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value.toFloat(), resources.displayMetrics)) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.java deleted file mode 100644 index b8d44514..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.faceclaw.app; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -/** The AlarmManager target: an item came due, start the ringing service. */ -public class FaceclawAlarmReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - if (intent == null || !FaceclawAlarms.ACTION_EXPIRE.equals(intent.getAction())) { - return; - } - long id = intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0); - if (id == 0) { - return; - } - FaceclawAlarmService.ring( - context.getApplicationContext(), - id, - intent.getStringExtra(FaceclawAlarms.EXTRA_TITLE), - intent.getStringExtra(FaceclawAlarms.EXTRA_TEXT), - intent.getStringExtra(FaceclawAlarms.EXTRA_KIND), - intent.getIntExtra(FaceclawAlarms.EXTRA_SNOOZE_MINUTES, 10) - ); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.kt new file mode 100644 index 00000000..c884bbf1 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.kt @@ -0,0 +1,26 @@ +package com.faceclaw.app + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent + +/** The AlarmManager target: an item came due, start the ringing service. */ +class FaceclawAlarmReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent?) { + if (intent == null || FaceclawAlarms.ACTION_EXPIRE != intent.action) { + return + } + val id = intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0) + if (id == 0L) { + return + } + FaceclawAlarmService.ring( + context.applicationContext, + id, + intent.getStringExtra(FaceclawAlarms.EXTRA_TITLE), + intent.getStringExtra(FaceclawAlarms.EXTRA_TEXT), + intent.getStringExtra(FaceclawAlarms.EXTRA_KIND), + intent.getIntExtra(FaceclawAlarms.EXTRA_SNOOZE_MINUTES, 10) + ) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.java deleted file mode 100644 index 4d7ed1b9..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.faceclaw.app; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -/** - * Re-arms the persisted alarm schedule when the system would otherwise have - * dropped it: after a reboot (AlarmManager alarms do not survive one), a - * package update, or a wall-clock / time-zone change. Runs without the - * JavaScript side; only the device-protected schedule file is needed. - */ -public class FaceclawAlarmRescheduleReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent == null ? null : intent.getAction(); - if (action == null) { - return; - } - switch (action) { - case Intent.ACTION_BOOT_COMPLETED: - case Intent.ACTION_LOCKED_BOOT_COMPLETED: - case Intent.ACTION_MY_PACKAGE_REPLACED: - case Intent.ACTION_TIME_CHANGED: - case Intent.ACTION_TIMEZONE_CHANGED: - case "android.intent.action.QUICKBOOT_POWERON": - case "com.htc.intent.action.QUICKBOOT_POWERON": - FaceclawAlarms.rescheduleAll(context, action); - break; - default: - break; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.kt new file mode 100644 index 00000000..d591704a --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.kt @@ -0,0 +1,28 @@ +package com.faceclaw.app + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent + +/** + * Re-arms the persisted alarm schedule when the system would otherwise have + * dropped it: after a reboot (AlarmManager alarms do not survive one), a + * package update, or a wall-clock / time-zone change. Runs without the + * JavaScript side; only the device-protected schedule file is needed. + */ +class FaceclawAlarmRescheduleReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent?) { + val action = intent?.action ?: return + when (action) { + Intent.ACTION_BOOT_COMPLETED, + Intent.ACTION_LOCKED_BOOT_COMPLETED, + Intent.ACTION_MY_PACKAGE_REPLACED, + Intent.ACTION_TIME_CHANGED, + Intent.ACTION_TIMEZONE_CHANGED, + "android.intent.action.QUICKBOOT_POWERON", + "com.htc.intent.action.QUICKBOOT_POWERON" -> + FaceclawAlarms.rescheduleAll(context, action) + else -> {} + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.java deleted file mode 100644 index a9cac015..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.java +++ /dev/null @@ -1,649 +0,0 @@ -package com.faceclaw.app; - -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ServiceInfo; -import android.media.AudioAttributes; -import android.media.AudioFocusRequest; -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.media.RingtoneManager; -import android.net.Uri; -import android.os.Build; -import android.os.Handler; -import android.os.IBinder; -import android.os.Looper; -import android.os.PowerManager; -import android.os.VibrationEffect; -import android.os.Vibrator; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * The ringing foreground service. One instance carries every item currently - * ringing. Each item starts silent on the phone (a heads-up / lock-screen - * notification only, the glasses do the ringing) and escalates to phone - * sound and vibration when the glasses cannot carry it: not connected, not - * on a head, charging, no delivery confirmation from the JS side within a - * few seconds, or no acknowledgement within 30 seconds of delivery. Sound - * uses the alarm stream, so media volume, the ringer switch and (unless set - * to total silence) Do Not Disturb do not silence it. - */ -public class FaceclawAlarmService extends Service { - public static final String CHANNEL_ID = "faceclaw-alarms"; - static final String ACTION_RING = "com.faceclaw.app.action.ALARM_RING"; - static final String ACTION_DELIVERED = "com.faceclaw.app.action.ALARM_DELIVERED"; - static final String ACTION_DISMISS = "com.faceclaw.app.action.ALARM_DISMISS"; - static final String ACTION_SNOOZE = "com.faceclaw.app.action.ALARM_SNOOZE"; - /** Stop an item quietly (acknowledged on the glasses / cancelled by the engine). */ - static final String ACTION_STOP_ITEM = "com.faceclaw.app.action.ALARM_STOP_ITEM"; - - /** How long to wait for the JS side to confirm the glasses are showing the item. */ - static final long DELIVERY_WAIT_MS = 5_000L; - /** How long after delivery to the glasses before the phone joins in. */ - static final long ACK_WAIT_MS = 30_000L; - /** Sound and vibration stop after this; the notification stays. */ - static final long AUTO_SILENCE_MS = 10 * 60_000L; - /** Alarm-stream level (fraction of max) used when the wearer has it muted. */ - static final float MUTED_VOLUME_FRACTION = 0.6f; - - static final class Ringing { - final long id; - final String title; - final String text; - final String kind; - final int snoozeMinutes; - final long ringAtMs; - long deliveredAtMs; - boolean escalated; - boolean silenced; - - Ringing(long id, String title, String text, String kind, int snoozeMinutes) { - this.id = id; - this.title = title == null || title.trim().isEmpty() ? "Alarm" : title; - this.text = text == null ? "" : text; - this.kind = kind == null ? FaceclawAlarms.KIND_ALARM : kind; - this.snoozeMinutes = Math.max(1, snoozeMinutes); - this.ringAtMs = System.currentTimeMillis(); - } - } - - /** Ringing items, oldest first; static so the activity can read them. */ - private static final Map ringing = Collections.synchronizedMap(new LinkedHashMap<>()); - /** - * Signals that arrived before the ring intent was processed (the JS - * engine fires, launches its window and reports delivery on the same - * main thread the service's onStartCommand queues behind), keyed by id - * with their arrival time. Consumed by startRinging. - */ - private static final Map deliveredEarly = Collections.synchronizedMap(new LinkedHashMap<>()); - private static final Map stoppedEarly = Collections.synchronizedMap(new LinkedHashMap<>()); - private static final long EARLY_SIGNAL_MAX_AGE_MS = 15_000L; - - private final Handler handler = new Handler(Looper.getMainLooper()); - private MediaPlayer player; - private Vibrator vibrator; - private PowerManager.WakeLock wakeLock; - private AudioManager audioManager; - private AudioFocusRequest focusRequest; - private int restoreAlarmVolume = -1; - private long foregroundId; - - // ------------------------------------------------------------------ - // Static entry points - - public static void ring(Context context, long id, String title, String text, String kind, int snoozeMinutes) { - Context appContext = context.getApplicationContext(); - Intent intent = new Intent(appContext, FaceclawAlarmService.class) - .setAction(ACTION_RING) - .putExtra(FaceclawAlarms.EXTRA_ID, id) - .putExtra(FaceclawAlarms.EXTRA_TITLE, title) - .putExtra(FaceclawAlarms.EXTRA_TEXT, text) - .putExtra(FaceclawAlarms.EXTRA_KIND, kind) - .putExtra(FaceclawAlarms.EXTRA_SNOOZE_MINUTES, snoozeMinutes); - FaceclawAlarms.startServiceCompat(appContext, intent); - } - - public static void delivered(Context context, long id) { - if (!ringing.containsKey(id)) { - deliveredEarly.put(id, System.currentTimeMillis()); - return; - } - Context appContext = context.getApplicationContext(); - appContext.startService(new Intent(appContext, FaceclawAlarmService.class) - .setAction(ACTION_DELIVERED) - .putExtra(FaceclawAlarms.EXTRA_ID, id)); - } - - public static void stopItem(Context context, long id) { - if (!ringing.containsKey(id)) { - stoppedEarly.put(id, System.currentTimeMillis()); - return; - } - Context appContext = context.getApplicationContext(); - appContext.startService(new Intent(appContext, FaceclawAlarmService.class) - .setAction(ACTION_STOP_ITEM) - .putExtra(FaceclawAlarms.EXTRA_ID, id)); - } - - public static boolean isRinging(long id) { - return ringing.containsKey(id); - } - - public static boolean isAnythingRinging() { - return !ringing.isEmpty(); - } - - static List snapshot() { - synchronized (ringing) { - return new ArrayList<>(ringing.values()); - } - } - - static PendingIntent actionIntent(Context appContext, String action, long id) { - Intent intent = new Intent(appContext, FaceclawAlarmService.class) - .setAction(action) - .putExtra(FaceclawAlarms.EXTRA_ID, id); - int flags = PendingIntent.FLAG_UPDATE_CURRENT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - flags |= PendingIntent.FLAG_IMMUTABLE; - } - int code = FaceclawAlarms.requestCode(id) ^ action.hashCode(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - return PendingIntent.getForegroundService(appContext, code, intent, flags); - } - return PendingIntent.getService(appContext, code, intent, flags); - } - - // ------------------------------------------------------------------ - // Service lifecycle - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - String action = intent == null ? null : intent.getAction(); - long id = intent == null ? 0 : intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0); - if (action == null) { - // Restarted by the system with nothing to do. - finishIfIdle(); - return START_NOT_STICKY; - } - switch (action) { - case ACTION_RING: - startRinging(new Ringing( - id, - intent.getStringExtra(FaceclawAlarms.EXTRA_TITLE), - intent.getStringExtra(FaceclawAlarms.EXTRA_TEXT), - intent.getStringExtra(FaceclawAlarms.EXTRA_KIND), - intent.getIntExtra(FaceclawAlarms.EXTRA_SNOOZE_MINUTES, 10) - )); - break; - case ACTION_DELIVERED: - markDelivered(id); - break; - case ACTION_DISMISS: - dismiss(id); - break; - case ACTION_SNOOZE: - snooze(id); - break; - case ACTION_STOP_ITEM: - stopItemQuietly(id, "acknowledged"); - break; - default: - break; - } - finishIfIdle(); - return START_NOT_STICKY; - } - - @Override - public void onDestroy() { - handler.removeCallbacksAndMessages(null); - stopSound(); - releaseWakeLock(); - super.onDestroy(); - } - - // ------------------------------------------------------------------ - // Ringing - - private void startRinging(Ringing item) { - if (item.id == 0) { - return; - } - ensureChannel(); - Ringing existing = ringing.get(item.id); - if (existing != null) { - // The engine's JS timeout and the AlarmManager alarm both fired: one ring. - showNotification(existing); - return; - } - if (takeEarlySignal(stoppedEarly, item.id)) { - // Acknowledged or cancelled before this intent was processed. - FaceclawAlarms.log(this, "ring " + item.id + " already acknowledged"); - return; - } - ringing.put(item.id, item); - FaceclawAlarms.log(this, "ring " + item.kind + " " + item.id + " (" + FaceclawAlarms.glassesStatusDescription() + ")"); - acquireWakeLock(); - showNotification(item); - if (!FaceclawAlarms.glassesCanCarryAlarm()) { - escalate(item, FaceclawAlarms.glassesStatusDescription()); - return; - } - if (takeEarlySignal(deliveredEarly, item.id)) { - markDelivered(item.id); - return; - } - // The glasses could carry it: give the JS side a moment to confirm - // they are actually showing it, then hold for the acknowledgement. - handler.postDelayed(() -> { - Ringing current = ringing.get(item.id); - if (current != null && !current.escalated && current.deliveredAtMs == 0) { - escalate(current, "not delivered to the glasses"); - } - }, DELIVERY_WAIT_MS); - } - - /** Consume an early signal for the id; stale entries are dropped. */ - private static boolean takeEarlySignal(Map signals, long id) { - Long at = signals.remove(id); - long now = System.currentTimeMillis(); - synchronized (signals) { - signals.values().removeIf(stamp -> now - stamp > EARLY_SIGNAL_MAX_AGE_MS); - } - return at != null && now - at <= EARLY_SIGNAL_MAX_AGE_MS; - } - - private void markDelivered(long id) { - Ringing item = ringing.get(id); - if (item == null || item.deliveredAtMs != 0) { - return; - } - item.deliveredAtMs = System.currentTimeMillis(); - FaceclawAlarms.log(this, "delivered " + id + " to glasses"); - handler.postDelayed(() -> { - Ringing current = ringing.get(id); - if (current != null && !current.escalated) { - escalate(current, "not acknowledged on the glasses"); - } - }, ACK_WAIT_MS); - } - - private void escalate(Ringing item, String reason) { - if (item.escalated) { - return; - } - item.escalated = true; - FaceclawAlarms.log(this, "phone sound for " + item.id + ": " + reason); - showNotification(item); - startSound(); - handler.postDelayed(() -> { - Ringing current = ringing.get(item.id); - if (current != null && current.escalated && !current.silenced) { - current.silenced = true; - FaceclawAlarms.log(this, "auto-silenced " + current.id); - showNotification(current); - syncSound(); - } - }, AUTO_SILENCE_MS); - } - - private void dismiss(long id) { - Ringing item = ringing.get(id); - if (item == null) { - return; - } - FaceclawAlarms.recordPhoneAction(this, id, "dismiss", 0); - removeItem(item); - // Also drop the schedule entry (a one-off is over; the engine re-arms repeats). - FaceclawAlarms.cancel(this, id); - } - - private void snooze(long id) { - Ringing item = ringing.get(id); - if (item == null) { - return; - } - int minutes = item.snoozeMinutes; - FaceclawAlarms.recordPhoneAction(this, id, "snooze", minutes); - removeItem(item); - // Re-arm on the phone directly so the snooze holds even with the JS - // side gone; the engine replays the journal and lands on the same id. - FaceclawAlarms.schedule( - this, - id, - System.currentTimeMillis() + minutes * 60_000L, - item.title, - item.text, - item.kind, - minutes - ); - } - - private void stopItemQuietly(long id, String reason) { - Ringing item = ringing.get(id); - if (item == null) { - return; - } - FaceclawAlarms.log(this, reason + " " + id); - removeItem(item); - } - - private void removeItem(Ringing item) { - ringing.remove(item.id); - NotificationManager manager = getSystemService(NotificationManager.class); - if (manager != null) { - manager.cancel(notificationId(item.id)); - } - syncSound(); - if (item.id == foregroundId) { - promoteAnotherToForeground(); - } - } - - private void finishIfIdle() { - if (!ringing.isEmpty()) { - return; - } - handler.removeCallbacksAndMessages(null); - stopSound(); - releaseWakeLock(); - stopForeground(STOP_FOREGROUND_REMOVE); - stopSelf(); - } - - // ------------------------------------------------------------------ - // Notification (the phone's silent display of the alarm) - - private void showNotification(Ringing item) { - Notification notification = buildNotification(item); - if (foregroundId == 0 || foregroundId == item.id || !ringing.containsKey(foregroundId)) { - foregroundId = item.id; - startForegroundCompat(notificationId(item.id), notification); - } else { - NotificationManager manager = getSystemService(NotificationManager.class); - if (manager != null) { - manager.notify(notificationId(item.id), notification); - } - } - } - - private void promoteAnotherToForeground() { - List items = snapshot(); - if (items.isEmpty()) { - foregroundId = 0; - return; - } - Ringing next = items.get(0); - foregroundId = next.id; - startForegroundCompat(notificationId(next.id), buildNotification(next)); - } - - private void startForegroundCompat(int id, Notification notification) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - startForeground(id, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK); - } else { - startForeground(id, notification); - } - } - - private Notification buildNotification(Ringing item) { - Intent activity = new Intent(this, FaceclawAlarmActivity.class) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP) - .putExtra(FaceclawAlarms.EXTRA_ID, item.id); - int flags = PendingIntent.FLAG_UPDATE_CURRENT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - flags |= PendingIntent.FLAG_IMMUTABLE; - } - PendingIntent open = PendingIntent.getActivity(this, FaceclawAlarms.requestCode(item.id), activity, flags); - - String status; - if (item.silenced) { - status = "Not answered"; - } else if (item.escalated) { - status = "Ringing"; - } else { - status = "Ringing on the glasses"; - } - String text = item.text.isEmpty() ? status : item.text + " · " + status; - - Notification.Builder builder = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - ? new Notification.Builder(this, CHANNEL_ID) - : new Notification.Builder(this).setPriority(Notification.PRIORITY_MAX); - builder.setContentTitle(item.title) - .setContentText(text) - .setSmallIcon(getApplicationInfo().icon) - .setContentIntent(open) - .setFullScreenIntent(open, true) - .setCategory(Notification.CATEGORY_ALARM) - .setVisibility(Notification.VISIBILITY_PUBLIC) - .setOngoing(true) - .setAutoCancel(false) - .setOnlyAlertOnce(true) - .setWhen(item.ringAtMs) - .setShowWhen(true) - .addAction(new Notification.Action.Builder( - null, - FaceclawAlarms.KIND_TIMER.equals(item.kind) ? "+" + item.snoozeMinutes + " min" : "Snooze " + item.snoozeMinutes + " min", - actionIntent(this, ACTION_SNOOZE, item.id)).build()) - .addAction(new Notification.Action.Builder( - null, - "Dismiss", - actionIntent(this, ACTION_DISMISS, item.id)).build()); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - // Pre-channel: the builder controls sound, and we want none. - builder.setSound(null).setVibrate(null); - } - return builder.build(); - } - - private void ensureChannel() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - return; - } - NotificationManager manager = getSystemService(NotificationManager.class); - if (manager == null) { - return; - } - NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "Alarms", NotificationManager.IMPORTANCE_HIGH); - channel.setDescription("Timers and alarms going off. Silent here: the sound is played by the alarm itself."); - // The service plays the sound itself (on the alarm stream) so the - // notification stays silent and vibration-free on purpose. - channel.setSound(null, null); - channel.enableVibration(false); - channel.setBypassDnd(true); - channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); - manager.createNotificationChannel(channel); - } - - private static int notificationId(long id) { - return 0x41000000 | (FaceclawAlarms.requestCode(id) & 0x00ffffff); - } - - // ------------------------------------------------------------------ - // Sound and vibration (only while some item is escalated and not yet silenced) - - private void syncSound() { - boolean wanted = false; - for (Ringing item : snapshot()) { - if (item.escalated && !item.silenced) { - wanted = true; - break; - } - } - if (wanted) { - startSound(); - } else { - stopSound(); - } - } - - private void startSound() { - if (player != null) { - return; - } - audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); - AudioAttributes attributes = new AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) - .build(); - raiseMutedAlarmVolume(); - requestAudioFocus(attributes); - Uri tone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); - if (tone == null) { - tone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); - } - try { - MediaPlayer created = new MediaPlayer(); - created.setAudioAttributes(attributes); - created.setDataSource(this, tone); - created.setLooping(true); - created.prepare(); - created.start(); - player = created; - } catch (Exception error) { - FaceclawAlarms.log(this, "alarm sound failed: " + error.getMessage()); - player = null; - } - startVibration(); - } - - private void stopSound() { - if (player != null) { - try { - player.stop(); - } catch (RuntimeException ignored) { - // Already stopped. - } - player.release(); - player = null; - } - if (vibrator != null) { - vibrator.cancel(); - vibrator = null; - } - abandonAudioFocus(); - restoreAlarmVolume(); - } - - /** - * A muted alarm stream is the one thing that would keep an alarm clock - * silent; raise it for the duration of the ring and put it back after. - */ - private void raiseMutedAlarmVolume() { - if (audioManager == null) { - return; - } - try { - int current = audioManager.getStreamVolume(AudioManager.STREAM_ALARM); - int max = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM); - if (current == 0 && max > 0) { - restoreAlarmVolume = current; - audioManager.setStreamVolume(AudioManager.STREAM_ALARM, Math.max(1, Math.round(max * MUTED_VOLUME_FRACTION)), 0); - } - } catch (RuntimeException error) { - FaceclawAlarms.log(this, "alarm volume change failed: " + error.getMessage()); - } - } - - private void restoreAlarmVolume() { - if (audioManager == null || restoreAlarmVolume < 0) { - return; - } - try { - audioManager.setStreamVolume(AudioManager.STREAM_ALARM, restoreAlarmVolume, 0); - } catch (RuntimeException ignored) { - // Best effort. - } - restoreAlarmVolume = -1; - } - - private void requestAudioFocus(AudioAttributes attributes) { - if (audioManager == null) { - return; - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - focusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT) - .setAudioAttributes(attributes) - .build(); - audioManager.requestAudioFocus(focusRequest); - } else { - audioManager.requestAudioFocus(null, AudioManager.STREAM_ALARM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT); - } - } - - private void abandonAudioFocus() { - if (audioManager == null) { - return; - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - if (focusRequest != null) { - audioManager.abandonAudioFocusRequest(focusRequest); - focusRequest = null; - } - } else { - audioManager.abandonAudioFocus(null); - } - } - - private void startVibration() { - Vibrator device = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); - if (device == null || !device.hasVibrator()) { - return; - } - vibrator = device; - long[] pattern = {0, 600, 400, 600, 1200}; - AudioAttributes attributes = new AudioAttributes.Builder() - .setUsage(AudioAttributes.USAGE_ALARM) - .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) - .build(); - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - device.vibrate(VibrationEffect.createWaveform(pattern, 0), attributes); - } else { - device.vibrate(pattern, 0, attributes); - } - } catch (RuntimeException error) { - FaceclawAlarms.log(this, "vibration failed: " + error.getMessage()); - } - } - - // ------------------------------------------------------------------ - // Wake lock - - private void acquireWakeLock() { - if (wakeLock != null && wakeLock.isHeld()) { - return; - } - PowerManager power = (PowerManager) getSystemService(Context.POWER_SERVICE); - if (power == null) { - return; - } - wakeLock = power.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "faceclaw:alarm"); - // Bounded: sound auto-silences at AUTO_SILENCE_MS, and a stuck lock - // past that would only drain the battery. - wakeLock.acquire(AUTO_SILENCE_MS + ACK_WAIT_MS + DELIVERY_WAIT_MS + 10_000L); - } - - private void releaseWakeLock() { - if (wakeLock != null && wakeLock.isHeld()) { - wakeLock.release(); - } - wakeLock = null; - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt new file mode 100644 index 00000000..65ea4dd2 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt @@ -0,0 +1,629 @@ +package com.faceclaw.app + +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.app.Service +import android.content.Context +import android.content.Intent +import android.content.pm.ServiceInfo +import android.media.AudioAttributes +import android.media.AudioFocusRequest +import android.media.AudioManager +import android.media.MediaPlayer +import android.media.RingtoneManager +import android.net.Uri +import android.os.Build +import android.os.Handler +import android.os.IBinder +import android.os.Looper +import android.os.PowerManager +import android.os.VibrationEffect +import android.os.Vibrator + +import java.util.ArrayList +import java.util.Collections +import java.util.LinkedHashMap + +/** + * The ringing foreground service. One instance carries every item currently + * ringing. Each item starts silent on the phone (a heads-up / lock-screen + * notification only, the glasses do the ringing) and escalates to phone + * sound and vibration when the glasses cannot carry it: not connected, not + * on a head, charging, no delivery confirmation from the JS side within a + * few seconds, or no acknowledgement within 30 seconds of delivery. Sound + * uses the alarm stream, so media volume, the ringer switch and (unless set + * to total silence) Do Not Disturb do not silence it. + */ +class FaceclawAlarmService : Service() { + internal class Ringing( + @JvmField val id: Long, + title: String?, + text: String?, + kind: String?, + snoozeMinutes: Int + ) { + @JvmField val title: String = if (title == null || title.trim().isEmpty()) "Alarm" else title + @JvmField val text: String = text ?: "" + @JvmField val kind: String = kind ?: FaceclawAlarms.KIND_ALARM + @JvmField val snoozeMinutes: Int = Math.max(1, snoozeMinutes) + @JvmField val ringAtMs: Long = System.currentTimeMillis() + @JvmField var deliveredAtMs: Long = 0 + @JvmField var escalated: Boolean = false + @JvmField var silenced: Boolean = false + } + + companion object { + const val CHANNEL_ID = "faceclaw-alarms" + internal const val ACTION_RING = "com.faceclaw.app.action.ALARM_RING" + internal const val ACTION_DELIVERED = "com.faceclaw.app.action.ALARM_DELIVERED" + internal const val ACTION_DISMISS = "com.faceclaw.app.action.ALARM_DISMISS" + internal const val ACTION_SNOOZE = "com.faceclaw.app.action.ALARM_SNOOZE" + /** Stop an item quietly (acknowledged on the glasses / cancelled by the engine). */ + internal const val ACTION_STOP_ITEM = "com.faceclaw.app.action.ALARM_STOP_ITEM" + + /** How long to wait for the JS side to confirm the glasses are showing the item. */ + internal const val DELIVERY_WAIT_MS = 5_000L + /** How long after delivery to the glasses before the phone joins in. */ + internal const val ACK_WAIT_MS = 30_000L + /** Sound and vibration stop after this; the notification stays. */ + internal const val AUTO_SILENCE_MS = 10 * 60_000L + /** Alarm-stream level (fraction of max) used when the wearer has it muted. */ + internal const val MUTED_VOLUME_FRACTION = 0.6f + + /** Ringing items, oldest first; static so the activity can read them. */ + private val ringing: MutableMap = Collections.synchronizedMap(LinkedHashMap()) + /** + * Signals that arrived before the ring intent was processed (the JS + * engine fires, launches its window and reports delivery on the same + * main thread the service's onStartCommand queues behind), keyed by id + * with their arrival time. Consumed by startRinging. + */ + private val deliveredEarly: MutableMap = Collections.synchronizedMap(LinkedHashMap()) + private val stoppedEarly: MutableMap = Collections.synchronizedMap(LinkedHashMap()) + private const val EARLY_SIGNAL_MAX_AGE_MS = 15_000L + + // ------------------------------------------------------------------ + // Static entry points + + @JvmStatic + fun ring(context: Context, id: Long, title: String?, text: String?, kind: String?, snoozeMinutes: Int) { + val appContext = context.applicationContext + val intent = Intent(appContext, FaceclawAlarmService::class.java) + .setAction(ACTION_RING) + .putExtra(FaceclawAlarms.EXTRA_ID, id) + .putExtra(FaceclawAlarms.EXTRA_TITLE, title) + .putExtra(FaceclawAlarms.EXTRA_TEXT, text) + .putExtra(FaceclawAlarms.EXTRA_KIND, kind) + .putExtra(FaceclawAlarms.EXTRA_SNOOZE_MINUTES, snoozeMinutes) + FaceclawAlarms.startServiceCompat(appContext, intent) + } + + @JvmStatic + fun delivered(context: Context, id: Long) { + if (!ringing.containsKey(id)) { + deliveredEarly[id] = System.currentTimeMillis() + return + } + val appContext = context.applicationContext + appContext.startService(Intent(appContext, FaceclawAlarmService::class.java) + .setAction(ACTION_DELIVERED) + .putExtra(FaceclawAlarms.EXTRA_ID, id)) + } + + @JvmStatic + fun stopItem(context: Context, id: Long) { + if (!ringing.containsKey(id)) { + stoppedEarly[id] = System.currentTimeMillis() + return + } + val appContext = context.applicationContext + appContext.startService(Intent(appContext, FaceclawAlarmService::class.java) + .setAction(ACTION_STOP_ITEM) + .putExtra(FaceclawAlarms.EXTRA_ID, id)) + } + + @JvmStatic + fun isRinging(id: Long): Boolean { + return ringing.containsKey(id) + } + + @JvmStatic + fun isAnythingRinging(): Boolean { + return !ringing.isEmpty() + } + + @JvmStatic + internal fun snapshot(): List { + synchronized(ringing) { + return ArrayList(ringing.values) + } + } + + @JvmStatic + internal fun actionIntent(appContext: Context, action: String, id: Long): PendingIntent { + val intent = Intent(appContext, FaceclawAlarmService::class.java) + .setAction(action) + .putExtra(FaceclawAlarms.EXTRA_ID, id) + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags = flags or PendingIntent.FLAG_IMMUTABLE + } + val code = FaceclawAlarms.requestCode(id) xor action.hashCode() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + return PendingIntent.getForegroundService(appContext, code, intent, flags) + } + return PendingIntent.getService(appContext, code, intent, flags) + } + + /** Consume an early signal for the id; stale entries are dropped. */ + private fun takeEarlySignal(signals: MutableMap, id: Long): Boolean { + val at = signals.remove(id) + val now = System.currentTimeMillis() + synchronized(signals) { + signals.values.removeIf { stamp -> now - stamp > EARLY_SIGNAL_MAX_AGE_MS } + } + return at != null && now - at <= EARLY_SIGNAL_MAX_AGE_MS + } + + private fun notificationId(id: Long): Int { + return 0x41000000 or (FaceclawAlarms.requestCode(id) and 0x00ffffff) + } + } + + private val handler = Handler(Looper.getMainLooper()) + private var player: MediaPlayer? = null + private var vibrator: Vibrator? = null + private var wakeLock: PowerManager.WakeLock? = null + private var audioManager: AudioManager? = null + private var focusRequest: AudioFocusRequest? = null + private var restoreAlarmVolume = -1 + private var foregroundId: Long = 0 + + // ------------------------------------------------------------------ + // Service lifecycle + + override fun onBind(intent: Intent?): IBinder? { + return null + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + val action = intent?.action + val id = if (intent == null) 0L else intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0) + if (action == null) { + // Restarted by the system with nothing to do. + finishIfIdle() + return START_NOT_STICKY + } + when (action) { + ACTION_RING -> + startRinging(Ringing( + id, + intent!!.getStringExtra(FaceclawAlarms.EXTRA_TITLE), + intent.getStringExtra(FaceclawAlarms.EXTRA_TEXT), + intent.getStringExtra(FaceclawAlarms.EXTRA_KIND), + intent.getIntExtra(FaceclawAlarms.EXTRA_SNOOZE_MINUTES, 10) + )) + ACTION_DELIVERED -> + markDelivered(id) + ACTION_DISMISS -> + dismiss(id) + ACTION_SNOOZE -> + snooze(id) + ACTION_STOP_ITEM -> + stopItemQuietly(id, "acknowledged") + else -> {} + } + finishIfIdle() + return START_NOT_STICKY + } + + override fun onDestroy() { + handler.removeCallbacksAndMessages(null) + stopSound() + releaseWakeLock() + super.onDestroy() + } + + // ------------------------------------------------------------------ + // Ringing + + private fun startRinging(item: Ringing) { + if (item.id == 0L) { + return + } + ensureChannel() + val existing = ringing[item.id] + if (existing != null) { + // The engine's JS timeout and the AlarmManager alarm both fired: one ring. + showNotification(existing) + return + } + if (takeEarlySignal(stoppedEarly, item.id)) { + // Acknowledged or cancelled before this intent was processed. + FaceclawAlarms.log(this, "ring " + item.id + " already acknowledged") + return + } + ringing[item.id] = item + FaceclawAlarms.log(this, "ring " + item.kind + " " + item.id + " (" + FaceclawAlarms.glassesStatusDescription() + ")") + acquireWakeLock() + showNotification(item) + if (!FaceclawAlarms.glassesCanCarryAlarm()) { + escalate(item, FaceclawAlarms.glassesStatusDescription()) + return + } + if (takeEarlySignal(deliveredEarly, item.id)) { + markDelivered(item.id) + return + } + // The glasses could carry it: give the JS side a moment to confirm + // they are actually showing it, then hold for the acknowledgement. + handler.postDelayed({ + val current = ringing[item.id] + if (current != null && !current.escalated && current.deliveredAtMs == 0L) { + escalate(current, "not delivered to the glasses") + } + }, DELIVERY_WAIT_MS) + } + + private fun markDelivered(id: Long) { + val item = ringing[id] + if (item == null || item.deliveredAtMs != 0L) { + return + } + item.deliveredAtMs = System.currentTimeMillis() + FaceclawAlarms.log(this, "delivered $id to glasses") + handler.postDelayed({ + val current = ringing[id] + if (current != null && !current.escalated) { + escalate(current, "not acknowledged on the glasses") + } + }, ACK_WAIT_MS) + } + + private fun escalate(item: Ringing, reason: String) { + if (item.escalated) { + return + } + item.escalated = true + FaceclawAlarms.log(this, "phone sound for " + item.id + ": " + reason) + showNotification(item) + startSound() + handler.postDelayed({ + val current = ringing[item.id] + if (current != null && current.escalated && !current.silenced) { + current.silenced = true + FaceclawAlarms.log(this, "auto-silenced " + current.id) + showNotification(current) + syncSound() + } + }, AUTO_SILENCE_MS) + } + + private fun dismiss(id: Long) { + val item = ringing[id] ?: return + FaceclawAlarms.recordPhoneAction(this, id, "dismiss", 0) + removeItem(item) + // Also drop the schedule entry (a one-off is over; the engine re-arms repeats). + FaceclawAlarms.cancel(this, id) + } + + private fun snooze(id: Long) { + val item = ringing[id] ?: return + val minutes = item.snoozeMinutes + FaceclawAlarms.recordPhoneAction(this, id, "snooze", minutes) + removeItem(item) + // Re-arm on the phone directly so the snooze holds even with the JS + // side gone; the engine replays the journal and lands on the same id. + FaceclawAlarms.schedule( + this, + id, + System.currentTimeMillis() + minutes * 60_000L, + item.title, + item.text, + item.kind, + minutes + ) + } + + private fun stopItemQuietly(id: Long, reason: String) { + val item = ringing[id] ?: return + FaceclawAlarms.log(this, "$reason $id") + removeItem(item) + } + + private fun removeItem(item: Ringing) { + ringing.remove(item.id) + val manager = getSystemService(NotificationManager::class.java) + manager?.cancel(notificationId(item.id)) + syncSound() + if (item.id == foregroundId) { + promoteAnotherToForeground() + } + } + + private fun finishIfIdle() { + if (!ringing.isEmpty()) { + return + } + handler.removeCallbacksAndMessages(null) + stopSound() + releaseWakeLock() + stopForeground(STOP_FOREGROUND_REMOVE) + stopSelf() + } + + // ------------------------------------------------------------------ + // Notification (the phone's silent display of the alarm) + + private fun showNotification(item: Ringing) { + val notification = buildNotification(item) + if (foregroundId == 0L || foregroundId == item.id || !ringing.containsKey(foregroundId)) { + foregroundId = item.id + startForegroundCompat(notificationId(item.id), notification) + } else { + val manager = getSystemService(NotificationManager::class.java) + manager?.notify(notificationId(item.id), notification) + } + } + + private fun promoteAnotherToForeground() { + val items = snapshot() + if (items.isEmpty()) { + foregroundId = 0 + return + } + val next = items[0] + foregroundId = next.id + startForegroundCompat(notificationId(next.id), buildNotification(next)) + } + + private fun startForegroundCompat(id: Int, notification: Notification) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(id, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK) + } else { + startForeground(id, notification) + } + } + + private fun buildNotification(item: Ringing): Notification { + val activity = Intent(this, FaceclawAlarmActivity::class.java) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP) + .putExtra(FaceclawAlarms.EXTRA_ID, item.id) + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags = flags or PendingIntent.FLAG_IMMUTABLE + } + val open = PendingIntent.getActivity(this, FaceclawAlarms.requestCode(item.id), activity, flags) + + val status: String = if (item.silenced) { + "Not answered" + } else if (item.escalated) { + "Ringing" + } else { + "Ringing on the glasses" + } + val text = if (item.text.isEmpty()) status else item.text + " · " + status + + val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + Notification.Builder(this, CHANNEL_ID) + else + Notification.Builder(this).setPriority(Notification.PRIORITY_MAX) + builder.setContentTitle(item.title) + .setContentText(text) + .setSmallIcon(applicationInfo.icon) + .setContentIntent(open) + .setFullScreenIntent(open, true) + .setCategory(Notification.CATEGORY_ALARM) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .setOngoing(true) + .setAutoCancel(false) + .setOnlyAlertOnce(true) + .setWhen(item.ringAtMs) + .setShowWhen(true) + .addAction(Notification.Action.Builder( + null, + if (FaceclawAlarms.KIND_TIMER == item.kind) "+" + item.snoozeMinutes + " min" else "Snooze " + item.snoozeMinutes + " min", + actionIntent(this, ACTION_SNOOZE, item.id)).build()) + .addAction(Notification.Action.Builder( + null, + "Dismiss", + actionIntent(this, ACTION_DISMISS, item.id)).build()) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + // Pre-channel: the builder controls sound, and we want none. + builder.setSound(null).setVibrate(null) + } + return builder.build() + } + + private fun ensureChannel() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + return + } + val manager = getSystemService(NotificationManager::class.java) ?: return + val channel = NotificationChannel(CHANNEL_ID, "Alarms", NotificationManager.IMPORTANCE_HIGH) + channel.description = "Timers and alarms going off. Silent here: the sound is played by the alarm itself." + // The service plays the sound itself (on the alarm stream) so the + // notification stays silent and vibration-free on purpose. + channel.setSound(null, null) + channel.enableVibration(false) + channel.setBypassDnd(true) + channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC + manager.createNotificationChannel(channel) + } + + // ------------------------------------------------------------------ + // Sound and vibration (only while some item is escalated and not yet silenced) + + private fun syncSound() { + var wanted = false + for (item in snapshot()) { + if (item.escalated && !item.silenced) { + wanted = true + break + } + } + if (wanted) { + startSound() + } else { + stopSound() + } + } + + private fun startSound() { + if (player != null) { + return + } + audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager? + val attributes = AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .build() + raiseMutedAlarmVolume() + requestAudioFocus(attributes) + var tone: Uri? = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM) + if (tone == null) { + tone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE) + } + try { + val created = MediaPlayer() + created.setAudioAttributes(attributes) + created.setDataSource(this, tone!!) + created.isLooping = true + created.prepare() + created.start() + player = created + } catch (error: Exception) { + FaceclawAlarms.log(this, "alarm sound failed: " + error.message) + player = null + } + startVibration() + } + + private fun stopSound() { + val current = player + if (current != null) { + try { + current.stop() + } catch (ignored: RuntimeException) { + // Already stopped. + } + current.release() + player = null + } + val device = vibrator + if (device != null) { + device.cancel() + vibrator = null + } + abandonAudioFocus() + restoreAlarmVolume() + } + + /** + * A muted alarm stream is the one thing that would keep an alarm clock + * silent; raise it for the duration of the ring and put it back after. + */ + private fun raiseMutedAlarmVolume() { + val manager = audioManager ?: return + try { + val current = manager.getStreamVolume(AudioManager.STREAM_ALARM) + val max = manager.getStreamMaxVolume(AudioManager.STREAM_ALARM) + if (current == 0 && max > 0) { + restoreAlarmVolume = current + manager.setStreamVolume(AudioManager.STREAM_ALARM, Math.max(1, Math.round(max * MUTED_VOLUME_FRACTION)), 0) + } + } catch (error: RuntimeException) { + FaceclawAlarms.log(this, "alarm volume change failed: " + error.message) + } + } + + private fun restoreAlarmVolume() { + val manager = audioManager + if (manager == null || restoreAlarmVolume < 0) { + return + } + try { + manager.setStreamVolume(AudioManager.STREAM_ALARM, restoreAlarmVolume, 0) + } catch (ignored: RuntimeException) { + // Best effort. + } + restoreAlarmVolume = -1 + } + + private fun requestAudioFocus(attributes: AudioAttributes) { + val manager = audioManager ?: return + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val request = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT) + .setAudioAttributes(attributes) + .build() + focusRequest = request + manager.requestAudioFocus(request) + } else { + @Suppress("DEPRECATION") + manager.requestAudioFocus(null, AudioManager.STREAM_ALARM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT) + } + } + + private fun abandonAudioFocus() { + val manager = audioManager ?: return + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val request = focusRequest + if (request != null) { + manager.abandonAudioFocusRequest(request) + focusRequest = null + } + } else { + @Suppress("DEPRECATION") + manager.abandonAudioFocus(null) + } + } + + private fun startVibration() { + val device = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator? + if (device == null || !device.hasVibrator()) { + return + } + vibrator = device + val pattern = longArrayOf(0, 600, 400, 600, 1200) + val attributes = AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_ALARM) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .build() + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + device.vibrate(VibrationEffect.createWaveform(pattern, 0), attributes) + } else { + @Suppress("DEPRECATION") + device.vibrate(pattern, 0, attributes) + } + } catch (error: RuntimeException) { + FaceclawAlarms.log(this, "vibration failed: " + error.message) + } + } + + // ------------------------------------------------------------------ + // Wake lock + + private fun acquireWakeLock() { + val held = wakeLock + if (held != null && held.isHeld) { + return + } + val power = getSystemService(Context.POWER_SERVICE) as PowerManager? ?: return + val lock = power.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "faceclaw:alarm") + wakeLock = lock + // Bounded: sound auto-silences at AUTO_SILENCE_MS, and a stuck lock + // past that would only drain the battery. + lock.acquire(AUTO_SILENCE_MS + ACK_WAIT_MS + DELIVERY_WAIT_MS + 10_000L) + } + + private fun releaseWakeLock() { + val lock = wakeLock + if (lock != null && lock.isHeld) { + lock.release() + } + wakeLock = null + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.java deleted file mode 100644 index 3dd2b0f1..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.java +++ /dev/null @@ -1,620 +0,0 @@ -package com.faceclaw.app; - -import android.app.ActivityManager; -import android.app.AlarmManager; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.media.AudioManager; -import android.net.Uri; -import android.os.Build; -import android.os.Handler; -import android.os.Looper; -import android.os.PowerManager; -import android.provider.Settings; - -import androidx.core.content.ContextCompat; - -import com.tns.NativeScriptActivity; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Locale; - -/** - * The phone side of the Timers app's alarms and countdown timers, built to - * ring without the JavaScript side: scheduling through AlarmManager's alarm - * clock API, a persisted schedule (in device-protected storage) that the - * reschedule receiver replays after reboots and time changes, the hand-off - * to the ringing foreground service, and a journal of what the wearer did - * on the phone (dismiss / snooze) for the JS engine to replay when it is - * next awake. Also the reliability self-check the UI surfaces. - * - * Ids are the JS engine's item ids (a millisecond epoch times 100 plus a - * serial), shared between timers and alarms; `kind` tells the two apart for - * wording only. - */ -public final class FaceclawAlarms { - public static final String ACTION_EXPIRE = "com.faceclaw.app.action.ALARM_EXPIRE"; - static final String EXTRA_ID = "id"; - static final String EXTRA_TITLE = "title"; - static final String EXTRA_TEXT = "text"; - static final String EXTRA_KIND = "kind"; - static final String EXTRA_SNOOZE_MINUTES = "snoozeMinutes"; - - public static final String KIND_TIMER = "timer"; - public static final String KIND_ALARM = "alarm"; - - private static final String PREFS_NAME = "faceclaw-alarms"; - private static final String KEY_SCHEDULED = "scheduled"; - private static final String KEY_JOURNAL = "journal"; - private static final String KEY_LOG = "log"; - private static final int LOG_LINES = 60; - - /** - * A schedule entry found already past due (after a reboot, or when the - * process was asleep) rings if it is at most this late; older ones are - * dropped as missed. Matches the JS engine's grace window. - */ - static final long LATE_GRACE_MS = 5 * 60_000L; - /** A glasses status report older than this is not trusted (the JS side is probably gone). */ - static final long GLASSES_STATUS_MAX_AGE_MS = 3 * 60_000L; - - private static volatile boolean glassesConnected; - private static volatile boolean glassesWorn; - private static volatile boolean glassesCharging; - private static volatile long glassesStatusAtMs; - - private static volatile FaceclawAlarmListener listener; - private static final Handler mainHandler = new Handler(Looper.getMainLooper()); - - private FaceclawAlarms() {} - - // ------------------------------------------------------------------ - // Storage - - /** - * Device-protected storage, so the schedule is readable before the first - * unlock after a reboot (the reschedule receiver may run then on some - * devices) and survives credential-encrypted storage being unavailable. - */ - static SharedPreferences prefs(Context context) { - Context base = context.getApplicationContext(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - base = base.createDeviceProtectedStorageContext(); - } - return base.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - } - - private static synchronized JSONArray readArray(Context context, String key) { - String raw = prefs(context).getString(key, "[]"); - try { - return new JSONArray(raw); - } catch (JSONException error) { - return new JSONArray(); - } - } - - private static synchronized void writeArray(Context context, String key, JSONArray array) { - prefs(context).edit().putString(key, array.toString()).apply(); - } - - static JSONObject findScheduled(Context context, long id) { - JSONArray scheduled = readArray(context, KEY_SCHEDULED); - for (int index = 0; index < scheduled.length(); index++) { - JSONObject entry = scheduled.optJSONObject(index); - if (entry != null && entry.optLong("id") == id) { - return entry; - } - } - return null; - } - - private static synchronized void putScheduled(Context context, JSONObject entry) { - JSONArray scheduled = readArray(context, KEY_SCHEDULED); - JSONArray next = new JSONArray(); - long id = entry.optLong("id"); - for (int index = 0; index < scheduled.length(); index++) { - JSONObject existing = scheduled.optJSONObject(index); - if (existing != null && existing.optLong("id") != id) { - next.put(existing); - } - } - next.put(entry); - writeArray(context, KEY_SCHEDULED, next); - } - - private static synchronized void removeScheduled(Context context, long id) { - JSONArray scheduled = readArray(context, KEY_SCHEDULED); - JSONArray next = new JSONArray(); - for (int index = 0; index < scheduled.length(); index++) { - JSONObject existing = scheduled.optJSONObject(index); - if (existing != null && existing.optLong("id") != id) { - next.put(existing); - } - } - writeArray(context, KEY_SCHEDULED, next); - } - - // ------------------------------------------------------------------ - // Scheduling - - /** - * Schedule (or move) the phone alarm for an item. Idempotent: the same id - * always maps to the same PendingIntent, so a reschedule replaces rather - * than duplicates. setAlarmClock is exact, fires through Doze and battery - * savers, and shows the system's alarm indicator; the fallbacks only run - * where it is unavailable. - */ - public static void schedule( - Context context, - long id, - long triggerAtMs, - String title, - String text, - String kind, - int snoozeMinutes - ) { - Context appContext = context.getApplicationContext(); - JSONObject entry = new JSONObject(); - try { - entry.put("id", id); - entry.put("at", triggerAtMs); - entry.put("title", title == null ? "" : title); - entry.put("text", text == null ? "" : text); - entry.put("kind", kind == null ? KIND_ALARM : kind); - entry.put("snoozeMinutes", snoozeMinutes); - } catch (JSONException ignored) { - return; - } - putScheduled(appContext, entry); - armAlarm(appContext, entry); - } - - private static void armAlarm(Context appContext, JSONObject entry) { - AlarmManager manager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); - if (manager == null) { - return; - } - long id = entry.optLong("id"); - long triggerAt = Math.max(System.currentTimeMillis(), entry.optLong("at")); - PendingIntent fire = expiryPendingIntent(appContext, entry); - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - AlarmManager.AlarmClockInfo info = new AlarmManager.AlarmClockInfo(triggerAt, showIntent(appContext, id)); - manager.setAlarmClock(info, fire); - } else { - manager.setExact(AlarmManager.RTC_WAKEUP, triggerAt, fire); - } - } catch (SecurityException error) { - // Exact-alarm access revoked (Android 12/13 without USE_EXACT_ALARM - // honoured): the inexact alarm is still a wake-up, just a late one. - log(appContext, "exact alarm refused for " + id + ": " + error.getMessage()); - manager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAt, fire); - } - } - - /** Cancel the phone alarm for an item, stop it if ringing, and forget it. */ - public static void cancel(Context context, long id) { - Context appContext = context.getApplicationContext(); - AlarmManager manager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); - if (manager != null) { - JSONObject entry = new JSONObject(); - try { - entry.put("id", id); - } catch (JSONException ignored) { - // unreachable for a numeric put - } - manager.cancel(expiryPendingIntent(appContext, entry)); - } - removeScheduled(appContext, id); - FaceclawAlarmService.stopItem(appContext, id); - } - - /** - * Replay the persisted schedule into AlarmManager: after a reboot (alarms - * are wiped), a package update, or a wall-clock / time-zone change. Entries - * already due ring now if inside the grace window, else are dropped. - */ - public static void rescheduleAll(Context context, String reason) { - Context appContext = context.getApplicationContext(); - JSONArray scheduled = readArray(appContext, KEY_SCHEDULED); - long now = System.currentTimeMillis(); - int armed = 0; - for (int index = 0; index < scheduled.length(); index++) { - JSONObject entry = scheduled.optJSONObject(index); - if (entry == null) { - continue; - } - long at = entry.optLong("at"); - if (at <= now) { - if (now - at <= LATE_GRACE_MS) { - ringEntry(appContext, entry); - } else { - log(appContext, "missed " + entry.optString("kind") + " " + entry.optLong("id") + " (" + reason + ")"); - removeScheduled(appContext, entry.optLong("id")); - } - continue; - } - armAlarm(appContext, entry); - armed++; - } - log(appContext, "rescheduled " + armed + " (" + reason + ")"); - } - - /** - * The schedule and AlarmManager can disagree (a force-stop clears alarms - * but not the file, an OEM killer drops them). True when the soonest - * stored entry is not what the system reports as the next alarm clock. - */ - public static boolean scheduleLooksStale(Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return false; - } - Context appContext = context.getApplicationContext(); - JSONArray scheduled = readArray(appContext, KEY_SCHEDULED); - long now = System.currentTimeMillis(); - long soonest = Long.MAX_VALUE; - for (int index = 0; index < scheduled.length(); index++) { - JSONObject entry = scheduled.optJSONObject(index); - if (entry != null && entry.optLong("at") > now) { - soonest = Math.min(soonest, entry.optLong("at")); - } - } - if (soonest == Long.MAX_VALUE) { - return false; - } - AlarmManager manager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); - if (manager == null) { - return false; - } - AlarmManager.AlarmClockInfo next = manager.getNextAlarmClock(); - // Another app's alarm may legitimately be sooner; only a later (or - // absent) system alarm proves ours is missing. - return next == null || next.getTriggerTime() > soonest + 1000; - } - - // ------------------------------------------------------------------ - // Ringing - - /** An item came due: hand it to the ringing service (idempotent per id). */ - static void ringEntry(Context appContext, JSONObject entry) { - FaceclawAlarmService.ring( - appContext, - entry.optLong("id"), - entry.optString("title"), - entry.optString("text"), - entry.optString("kind", KIND_ALARM), - entry.optInt("snoozeMinutes", 10) - ); - } - - /** The JS engine's own expiry path; the service deduplicates against the alarm's. */ - public static void ring(Context context, long id, String title, String text, String kind, int snoozeMinutes) { - Context appContext = context.getApplicationContext(); - AlarmManager manager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); - if (manager != null) { - JSONObject probe = new JSONObject(); - try { - probe.put("id", id); - } catch (JSONException ignored) { - // unreachable for a numeric put - } - manager.cancel(expiryPendingIntent(appContext, probe)); - } - FaceclawAlarmService.ring(appContext, id, title, text, kind, snoozeMinutes); - } - - /** The glasses are showing the ringing item; the acknowledgement clock starts now. */ - public static void deliveredToGlasses(Context context, long id) { - FaceclawAlarmService.delivered(context.getApplicationContext(), id); - } - - /** The wearer dismissed or snoozed it on the glasses: the phone side goes quiet. */ - public static void acknowledge(Context context, long id) { - Context appContext = context.getApplicationContext(); - removeScheduled(appContext, id); - FaceclawAlarmService.stopItem(appContext, id); - } - - // ------------------------------------------------------------------ - // Glasses status (pushed by the JS side; in-memory, so a dead process reads as "no glasses") - - public static void setGlassesStatus(boolean connected, boolean worn, boolean charging) { - glassesConnected = connected; - glassesWorn = worn; - glassesCharging = charging; - glassesStatusAtMs = System.currentTimeMillis(); - } - - /** True only when a fresh report says the glasses are connected, on a head, and not charging. */ - static boolean glassesCanCarryAlarm() { - long age = System.currentTimeMillis() - glassesStatusAtMs; - if (glassesStatusAtMs == 0 || age > GLASSES_STATUS_MAX_AGE_MS) { - return false; - } - return glassesConnected && glassesWorn && !glassesCharging; - } - - static String glassesStatusDescription() { - if (glassesStatusAtMs == 0) { - return "no glasses status"; - } - long age = System.currentTimeMillis() - glassesStatusAtMs; - if (age > GLASSES_STATUS_MAX_AGE_MS) { - return "glasses status stale"; - } - if (!glassesConnected) { - return "glasses not connected"; - } - if (glassesCharging) { - return "glasses charging"; - } - if (!glassesWorn) { - return "glasses not worn"; - } - return "glasses worn"; - } - - // ------------------------------------------------------------------ - // Phone actions -> JS - - public static void setListener(FaceclawAlarmListener newListener) { - listener = newListener; - } - - /** - * Record a dismiss / snooze done on the phone. Delivered live to the JS - * listener when one is registered, and journaled regardless so a JS side - * that was asleep or gone can catch up on its next boot. - */ - static void recordPhoneAction(Context context, long id, String action, int minutes) { - Context appContext = context.getApplicationContext(); - JSONObject event = new JSONObject(); - try { - event.put("id", id); - event.put("action", action); - event.put("minutes", minutes); - event.put("at", System.currentTimeMillis()); - } catch (JSONException ignored) { - return; - } - synchronized (FaceclawAlarms.class) { - JSONArray journal = readArray(appContext, KEY_JOURNAL); - journal.put(event); - writeArray(appContext, KEY_JOURNAL, journal); - } - log(appContext, "phone " + action + " " + id + (minutes > 0 ? " (" + minutes + " min)" : "")); - final FaceclawAlarmListener current = listener; - if (current != null) { - mainHandler.post(() -> { - try { - current.onPhoneAction(id, action, minutes); - } catch (RuntimeException error) { - log(appContext, "listener failed: " + error.getMessage()); - } - }); - } - } - - /** Hand the journal to the JS side (as a JSON array) and clear it. */ - public static synchronized String drainJournal(Context context) { - Context appContext = context.getApplicationContext(); - JSONArray journal = readArray(appContext, KEY_JOURNAL); - writeArray(appContext, KEY_JOURNAL, new JSONArray()); - return journal.toString(); - } - - // ------------------------------------------------------------------ - // Reliability self-check - - /** - * Conditions under which the phone may fail to ring, as a JSON array of - * {code, message, fixable}, most serious first. Empty when everything is - * in order. The UI shows these before the wearer relies on an alarm. - */ - public static String checkReliability(Context context) { - Context appContext = context.getApplicationContext(); - JSONArray issues = new JSONArray(); - NotificationManager notifications = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE); - AlarmManager alarms = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && alarms != null && !alarms.canScheduleExactAlarms()) { - addIssue(issues, "exact-alarm", "Exact alarms are not allowed for Faceclaw, so alarms may ring late.", true); - } - if (notifications != null && !notifications.areNotificationsEnabled()) { - addIssue(issues, "notifications", "Notifications are turned off for Faceclaw, so the phone cannot show or sound an alarm.", true); - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notifications != null) { - NotificationChannel channel = notifications.getNotificationChannel(FaceclawAlarmService.CHANNEL_ID); - if (channel != null && channel.getImportance() == NotificationManager.IMPORTANCE_NONE) { - addIssue(issues, "alarm-channel", "The Alarms notification category is blocked, so the phone cannot show an alarm.", true); - } - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && notifications != null && !notifications.canUseFullScreenIntent()) { - addIssue(issues, "full-screen", "Full-screen alarms are not allowed, so a ringing alarm will not take over the lock screen.", true); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && notifications != null) { - int filter = notifications.getCurrentInterruptionFilter(); - if (filter == NotificationManager.INTERRUPTION_FILTER_NONE) { - addIssue(issues, "dnd-total", "Do Not Disturb is set to total silence, which silences alarms too.", true); - } else if (filter == NotificationManager.INTERRUPTION_FILTER_PRIORITY) { - try { - NotificationManager.Policy policy = notifications.getNotificationPolicy(); - if (policy != null && (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS) == 0) { - addIssue(issues, "dnd-alarms", "Do Not Disturb does not allow alarms, so the phone will stay silent.", true); - } - } catch (SecurityException ignored) { - // No notification-policy access: cannot inspect the exceptions. - } - } - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); - if (activityManager != null && activityManager.isBackgroundRestricted()) { - addIssue(issues, "background-restricted", "Background usage is restricted for Faceclaw, which blocks alarms while the app is not open.", true); - } - } - PowerManager power = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); - if (power != null && !power.isIgnoringBatteryOptimizations(appContext.getPackageName())) { - addIssue(issues, "battery-optimized", "Battery optimization is on for Faceclaw; some phones delay alarms because of it.", true); - } - AudioManager audio = (AudioManager) appContext.getSystemService(Context.AUDIO_SERVICE); - if (audio != null && audio.getStreamVolume(AudioManager.STREAM_ALARM) == 0) { - addIssue(issues, "alarm-volume", "The phone's alarm volume is muted; Faceclaw raises it while ringing, but check it.", true); - } - String maker = Build.MANUFACTURER == null ? "" : Build.MANUFACTURER.toLowerCase(Locale.ROOT); - if (maker.contains("xiaomi") || maker.contains("huawei") || maker.contains("oppo") || maker.contains("vivo") - || maker.contains("oneplus") || maker.contains("realme") || maker.contains("meizu") || maker.contains("asus")) { - addIssue(issues, "oem-killer", "This phone maker is known to stop background apps; allow Faceclaw to auto-start and run unrestricted (see dontkillmyapp.com).", true); - } - if (scheduleLooksStale(appContext)) { - addIssue(issues, "schedule-stale", "The system lost Faceclaw's next alarm (the app may have been force-stopped); it was re-armed.", false); - rescheduleAll(appContext, "self-check"); - } - return issues.toString(); - } - - private static void addIssue(JSONArray issues, String code, String message, boolean fixable) { - JSONObject issue = new JSONObject(); - try { - issue.put("code", code); - issue.put("message", message); - issue.put("fixable", fixable); - } catch (JSONException ignored) { - return; - } - issues.put(issue); - } - - /** Open the system screen where the issue can be fixed. */ - public static void openReliabilityFix(Context context, String code) { - Context appContext = context.getApplicationContext(); - String pkg = appContext.getPackageName(); - Intent intent; - switch (code == null ? "" : code) { - case "exact-alarm": - intent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S - ? new Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM, Uri.parse("package:" + pkg)) - : appDetails(pkg); - break; - case "notifications": - case "alarm-channel": - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) - .putExtra(Settings.EXTRA_APP_PACKAGE, pkg); - if ("alarm-channel".equals(code)) { - intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) - .putExtra(Settings.EXTRA_APP_PACKAGE, pkg) - .putExtra(Settings.EXTRA_CHANNEL_ID, FaceclawAlarmService.CHANNEL_ID); - } - } else { - intent = appDetails(pkg); - } - break; - case "full-screen": - intent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE - ? new Intent(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT, Uri.parse("package:" + pkg)) - : appDetails(pkg); - break; - case "dnd-total": - case "dnd-alarms": - intent = new Intent(Settings.ACTION_SOUND_SETTINGS); - break; - case "battery-optimized": - intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + pkg)); - break; - case "alarm-volume": - intent = new Intent(Settings.ACTION_SOUND_SETTINGS); - break; - default: - intent = appDetails(pkg); - break; - } - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - try { - appContext.startActivity(intent); - } catch (RuntimeException error) { - Intent fallback = appDetails(pkg).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - try { - appContext.startActivity(fallback); - } catch (RuntimeException ignored) { - // No settings activity at all; nothing more to do. - } - } - } - - private static Intent appDetails(String pkg) { - return new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + pkg)); - } - - // ------------------------------------------------------------------ - // Diagnostics log - - static synchronized void log(Context context, String line) { - Context appContext = context.getApplicationContext(); - JSONArray log = readArray(appContext, KEY_LOG); - JSONArray next = new JSONArray(); - int start = Math.max(0, log.length() - (LOG_LINES - 1)); - for (int index = start; index < log.length(); index++) { - next.put(log.optString(index)); - } - next.put(System.currentTimeMillis() + " " + line); - writeArray(appContext, KEY_LOG, next); - } - - /** The ring / miss / action log, newest last, one line per entry. */ - public static String readLog(Context context) { - JSONArray log = readArray(context.getApplicationContext(), KEY_LOG); - StringBuilder out = new StringBuilder(); - for (int index = 0; index < log.length(); index++) { - if (index > 0) { - out.append('\n'); - } - out.append(log.optString(index)); - } - return out.toString(); - } - - // ------------------------------------------------------------------ - // Intents - - private static PendingIntent expiryPendingIntent(Context appContext, JSONObject entry) { - Intent intent = new Intent(appContext, FaceclawAlarmReceiver.class); - intent.setAction(ACTION_EXPIRE); - long id = entry.optLong("id"); - intent.putExtra(EXTRA_ID, id); - intent.putExtra(EXTRA_TITLE, entry.optString("title")); - intent.putExtra(EXTRA_TEXT, entry.optString("text")); - intent.putExtra(EXTRA_KIND, entry.optString("kind", KIND_ALARM)); - intent.putExtra(EXTRA_SNOOZE_MINUTES, entry.optInt("snoozeMinutes", 10)); - int flags = PendingIntent.FLAG_UPDATE_CURRENT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - flags |= PendingIntent.FLAG_IMMUTABLE; - } - return PendingIntent.getBroadcast(appContext, requestCode(id), intent, flags); - } - - /** What the system's alarm indicator opens: the app. */ - private static PendingIntent showIntent(Context appContext, long id) { - Intent intent = new Intent(appContext, NativeScriptActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - int flags = PendingIntent.FLAG_UPDATE_CURRENT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - flags |= PendingIntent.FLAG_IMMUTABLE; - } - return PendingIntent.getActivity(appContext, requestCode(id), intent, flags); - } - - static int requestCode(long id) { - return (int) (id ^ (id >>> 32)) & 0x7fffffff; - } - - static void startServiceCompat(Context appContext, Intent intent) { - ContextCompat.startForegroundService(appContext, intent); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt new file mode 100644 index 00000000..43ffcfc1 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt @@ -0,0 +1,647 @@ +package com.faceclaw.app + +import android.app.ActivityManager +import android.app.AlarmManager +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.media.AudioManager +import android.net.Uri +import android.os.Build +import android.os.Handler +import android.os.Looper +import android.os.PowerManager +import android.provider.Settings + +import androidx.core.content.ContextCompat + +import com.tns.NativeScriptActivity + +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject + +import java.util.Locale + +/** + * The phone side of the Timers app's alarms and countdown timers, built to + * ring without the JavaScript side: scheduling through AlarmManager's alarm + * clock API, a persisted schedule (in device-protected storage) that the + * reschedule receiver replays after reboots and time changes, the hand-off + * to the ringing foreground service, and a journal of what the wearer did + * on the phone (dismiss / snooze) for the JS engine to replay when it is + * next awake. Also the reliability self-check the UI surfaces. + * + * Ids are the JS engine's item ids (a millisecond epoch times 100 plus a + * serial), shared between timers and alarms; `kind` tells the two apart for + * wording only. + */ +class FaceclawAlarms private constructor() { + companion object { + const val ACTION_EXPIRE = "com.faceclaw.app.action.ALARM_EXPIRE" + internal const val EXTRA_ID = "id" + internal const val EXTRA_TITLE = "title" + internal const val EXTRA_TEXT = "text" + internal const val EXTRA_KIND = "kind" + internal const val EXTRA_SNOOZE_MINUTES = "snoozeMinutes" + + const val KIND_TIMER = "timer" + const val KIND_ALARM = "alarm" + + private const val PREFS_NAME = "faceclaw-alarms" + private const val KEY_SCHEDULED = "scheduled" + private const val KEY_JOURNAL = "journal" + private const val KEY_LOG = "log" + private const val LOG_LINES = 60 + + /** + * A schedule entry found already past due (after a reboot, or when the + * process was asleep) rings if it is at most this late; older ones are + * dropped as missed. Matches the JS engine's grace window. + */ + internal const val LATE_GRACE_MS = 5 * 60_000L + /** A glasses status report older than this is not trusted (the JS side is probably gone). */ + internal const val GLASSES_STATUS_MAX_AGE_MS = 3 * 60_000L + + @Volatile + private var glassesConnected = false + @Volatile + private var glassesWorn = false + @Volatile + private var glassesCharging = false + @Volatile + private var glassesStatusAtMs = 0L + + @Volatile + private var listener: FaceclawAlarmListener? = null + private val mainHandler = Handler(Looper.getMainLooper()) + + // ------------------------------------------------------------------ + // Storage + + /** + * Device-protected storage, so the schedule is readable before the first + * unlock after a reboot (the reschedule receiver may run then on some + * devices) and survives credential-encrypted storage being unavailable. + */ + @JvmStatic + internal fun prefs(context: Context): SharedPreferences { + var base = context.applicationContext + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + base = base.createDeviceProtectedStorageContext() + } + return base.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + } + + // The Java statics were `synchronized`, i.e. locked on the class object; + // the explicit blocks below keep that single monitor. + private fun readArray(context: Context, key: String): JSONArray { + synchronized(FaceclawAlarms::class.java) { + val raw = prefs(context).getString(key, "[]") + return try { + JSONArray(raw) + } catch (error: JSONException) { + JSONArray() + } + } + } + + private fun writeArray(context: Context, key: String, array: JSONArray) { + synchronized(FaceclawAlarms::class.java) { + prefs(context).edit().putString(key, array.toString()).apply() + } + } + + @JvmStatic + internal fun findScheduled(context: Context, id: Long): JSONObject? { + val scheduled = readArray(context, KEY_SCHEDULED) + for (index in 0 until scheduled.length()) { + val entry = scheduled.optJSONObject(index) + if (entry != null && entry.optLong("id") == id) { + return entry + } + } + return null + } + + private fun putScheduled(context: Context, entry: JSONObject) { + synchronized(FaceclawAlarms::class.java) { + val scheduled = readArray(context, KEY_SCHEDULED) + val next = JSONArray() + val id = entry.optLong("id") + for (index in 0 until scheduled.length()) { + val existing = scheduled.optJSONObject(index) + if (existing != null && existing.optLong("id") != id) { + next.put(existing) + } + } + next.put(entry) + writeArray(context, KEY_SCHEDULED, next) + } + } + + private fun removeScheduled(context: Context, id: Long) { + synchronized(FaceclawAlarms::class.java) { + val scheduled = readArray(context, KEY_SCHEDULED) + val next = JSONArray() + for (index in 0 until scheduled.length()) { + val existing = scheduled.optJSONObject(index) + if (existing != null && existing.optLong("id") != id) { + next.put(existing) + } + } + writeArray(context, KEY_SCHEDULED, next) + } + } + + // ------------------------------------------------------------------ + // Scheduling + + /** + * Schedule (or move) the phone alarm for an item. Idempotent: the same id + * always maps to the same PendingIntent, so a reschedule replaces rather + * than duplicates. setAlarmClock is exact, fires through Doze and battery + * savers, and shows the system's alarm indicator; the fallbacks only run + * where it is unavailable. + */ + @JvmStatic + fun schedule( + context: Context, + id: Long, + triggerAtMs: Long, + title: String?, + text: String?, + kind: String?, + snoozeMinutes: Int + ) { + val appContext = context.applicationContext + val entry = JSONObject() + try { + entry.put("id", id) + entry.put("at", triggerAtMs) + entry.put("title", title ?: "") + entry.put("text", text ?: "") + entry.put("kind", kind ?: KIND_ALARM) + entry.put("snoozeMinutes", snoozeMinutes) + } catch (ignored: JSONException) { + return + } + putScheduled(appContext, entry) + armAlarm(appContext, entry) + } + + private fun armAlarm(appContext: Context, entry: JSONObject) { + val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? + ?: return + val id = entry.optLong("id") + val triggerAt = Math.max(System.currentTimeMillis(), entry.optLong("at")) + val fire = expiryPendingIntent(appContext, entry) + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + val info = AlarmManager.AlarmClockInfo(triggerAt, showIntent(appContext, id)) + manager.setAlarmClock(info, fire) + } else { + manager.setExact(AlarmManager.RTC_WAKEUP, triggerAt, fire) + } + } catch (error: SecurityException) { + // Exact-alarm access revoked (Android 12/13 without USE_EXACT_ALARM + // honoured): the inexact alarm is still a wake-up, just a late one. + log(appContext, "exact alarm refused for " + id + ": " + error.message) + manager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAt, fire) + } + } + + /** Cancel the phone alarm for an item, stop it if ringing, and forget it. */ + @JvmStatic + fun cancel(context: Context, id: Long) { + val appContext = context.applicationContext + val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? + if (manager != null) { + val entry = JSONObject() + try { + entry.put("id", id) + } catch (ignored: JSONException) { + // unreachable for a numeric put + } + manager.cancel(expiryPendingIntent(appContext, entry)) + } + removeScheduled(appContext, id) + FaceclawAlarmService.stopItem(appContext, id) + } + + /** + * Replay the persisted schedule into AlarmManager: after a reboot (alarms + * are wiped), a package update, or a wall-clock / time-zone change. Entries + * already due ring now if inside the grace window, else are dropped. + */ + @JvmStatic + fun rescheduleAll(context: Context, reason: String?) { + val appContext = context.applicationContext + val scheduled = readArray(appContext, KEY_SCHEDULED) + val now = System.currentTimeMillis() + var armed = 0 + for (index in 0 until scheduled.length()) { + val entry = scheduled.optJSONObject(index) ?: continue + val at = entry.optLong("at") + if (at <= now) { + if (now - at <= LATE_GRACE_MS) { + ringEntry(appContext, entry) + } else { + log(appContext, "missed " + entry.optString("kind") + " " + entry.optLong("id") + " (" + reason + ")") + removeScheduled(appContext, entry.optLong("id")) + } + continue + } + armAlarm(appContext, entry) + armed++ + } + log(appContext, "rescheduled $armed ($reason)") + } + + /** + * The schedule and AlarmManager can disagree (a force-stop clears alarms + * but not the file, an OEM killer drops them). True when the soonest + * stored entry is not what the system reports as the next alarm clock. + */ + @JvmStatic + fun scheduleLooksStale(context: Context): Boolean { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + return false + } + val appContext = context.applicationContext + val scheduled = readArray(appContext, KEY_SCHEDULED) + val now = System.currentTimeMillis() + var soonest = Long.MAX_VALUE + for (index in 0 until scheduled.length()) { + val entry = scheduled.optJSONObject(index) + if (entry != null && entry.optLong("at") > now) { + soonest = Math.min(soonest, entry.optLong("at")) + } + } + if (soonest == Long.MAX_VALUE) { + return false + } + val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? + ?: return false + val next = manager.nextAlarmClock + // Another app's alarm may legitimately be sooner; only a later (or + // absent) system alarm proves ours is missing. + return next == null || next.triggerTime > soonest + 1000 + } + + // ------------------------------------------------------------------ + // Ringing + + /** An item came due: hand it to the ringing service (idempotent per id). */ + @JvmStatic + internal fun ringEntry(appContext: Context, entry: JSONObject) { + FaceclawAlarmService.ring( + appContext, + entry.optLong("id"), + entry.optString("title"), + entry.optString("text"), + entry.optString("kind", KIND_ALARM), + entry.optInt("snoozeMinutes", 10) + ) + } + + /** The JS engine's own expiry path; the service deduplicates against the alarm's. */ + @JvmStatic + fun ring(context: Context, id: Long, title: String?, text: String?, kind: String?, snoozeMinutes: Int) { + val appContext = context.applicationContext + val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? + if (manager != null) { + val probe = JSONObject() + try { + probe.put("id", id) + } catch (ignored: JSONException) { + // unreachable for a numeric put + } + manager.cancel(expiryPendingIntent(appContext, probe)) + } + FaceclawAlarmService.ring(appContext, id, title, text, kind, snoozeMinutes) + } + + /** The glasses are showing the ringing item; the acknowledgement clock starts now. */ + @JvmStatic + fun deliveredToGlasses(context: Context, id: Long) { + FaceclawAlarmService.delivered(context.applicationContext, id) + } + + /** The wearer dismissed or snoozed it on the glasses: the phone side goes quiet. */ + @JvmStatic + fun acknowledge(context: Context, id: Long) { + val appContext = context.applicationContext + removeScheduled(appContext, id) + FaceclawAlarmService.stopItem(appContext, id) + } + + // ------------------------------------------------------------------ + // Glasses status (pushed by the JS side; in-memory, so a dead process reads as "no glasses") + + @JvmStatic + fun setGlassesStatus(connected: Boolean, worn: Boolean, charging: Boolean) { + glassesConnected = connected + glassesWorn = worn + glassesCharging = charging + glassesStatusAtMs = System.currentTimeMillis() + } + + /** True only when a fresh report says the glasses are connected, on a head, and not charging. */ + @JvmStatic + internal fun glassesCanCarryAlarm(): Boolean { + val age = System.currentTimeMillis() - glassesStatusAtMs + if (glassesStatusAtMs == 0L || age > GLASSES_STATUS_MAX_AGE_MS) { + return false + } + return glassesConnected && glassesWorn && !glassesCharging + } + + @JvmStatic + internal fun glassesStatusDescription(): String { + if (glassesStatusAtMs == 0L) { + return "no glasses status" + } + val age = System.currentTimeMillis() - glassesStatusAtMs + if (age > GLASSES_STATUS_MAX_AGE_MS) { + return "glasses status stale" + } + if (!glassesConnected) { + return "glasses not connected" + } + if (glassesCharging) { + return "glasses charging" + } + if (!glassesWorn) { + return "glasses not worn" + } + return "glasses worn" + } + + // ------------------------------------------------------------------ + // Phone actions -> JS + + @JvmStatic + fun setListener(newListener: FaceclawAlarmListener?) { + listener = newListener + } + + /** + * Record a dismiss / snooze done on the phone. Delivered live to the JS + * listener when one is registered, and journaled regardless so a JS side + * that was asleep or gone can catch up on its next boot. + */ + @JvmStatic + internal fun recordPhoneAction(context: Context, id: Long, action: String, minutes: Int) { + val appContext = context.applicationContext + val event = JSONObject() + try { + event.put("id", id) + event.put("action", action) + event.put("minutes", minutes) + event.put("at", System.currentTimeMillis()) + } catch (ignored: JSONException) { + return + } + synchronized(FaceclawAlarms::class.java) { + val journal = readArray(appContext, KEY_JOURNAL) + journal.put(event) + writeArray(appContext, KEY_JOURNAL, journal) + } + log(appContext, "phone " + action + " " + id + (if (minutes > 0) " ($minutes min)" else "")) + val current = listener + if (current != null) { + mainHandler.post { + try { + current.onPhoneAction(id, action, minutes) + } catch (error: RuntimeException) { + log(appContext, "listener failed: " + error.message) + } + } + } + } + + /** Hand the journal to the JS side (as a JSON array) and clear it. */ + @JvmStatic + fun drainJournal(context: Context): String { + synchronized(FaceclawAlarms::class.java) { + val appContext = context.applicationContext + val journal = readArray(appContext, KEY_JOURNAL) + writeArray(appContext, KEY_JOURNAL, JSONArray()) + return journal.toString() + } + } + + // ------------------------------------------------------------------ + // Reliability self-check + + /** + * Conditions under which the phone may fail to ring, as a JSON array of + * {code, message, fixable}, most serious first. Empty when everything is + * in order. The UI shows these before the wearer relies on an alarm. + */ + @JvmStatic + fun checkReliability(context: Context): String { + val appContext = context.applicationContext + val issues = JSONArray() + val notifications = appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager? + val alarms = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && alarms != null && !alarms.canScheduleExactAlarms()) { + addIssue(issues, "exact-alarm", "Exact alarms are not allowed for Faceclaw, so alarms may ring late.", true) + } + if (notifications != null && !notifications.areNotificationsEnabled()) { + addIssue(issues, "notifications", "Notifications are turned off for Faceclaw, so the phone cannot show or sound an alarm.", true) + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notifications != null) { + val channel = notifications.getNotificationChannel(FaceclawAlarmService.CHANNEL_ID) + if (channel != null && channel.importance == NotificationManager.IMPORTANCE_NONE) { + addIssue(issues, "alarm-channel", "The Alarms notification category is blocked, so the phone cannot show an alarm.", true) + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && notifications != null && !notifications.canUseFullScreenIntent()) { + addIssue(issues, "full-screen", "Full-screen alarms are not allowed, so a ringing alarm will not take over the lock screen.", true) + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && notifications != null) { + val filter = notifications.currentInterruptionFilter + if (filter == NotificationManager.INTERRUPTION_FILTER_NONE) { + addIssue(issues, "dnd-total", "Do Not Disturb is set to total silence, which silences alarms too.", true) + } else if (filter == NotificationManager.INTERRUPTION_FILTER_PRIORITY) { + try { + val policy = notifications.notificationPolicy + if (policy != null && (policy.priorityCategories and NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS) == 0) { + addIssue(issues, "dnd-alarms", "Do Not Disturb does not allow alarms, so the phone will stay silent.", true) + } + } catch (ignored: SecurityException) { + // No notification-policy access: cannot inspect the exceptions. + } + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val activityManager = appContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager? + if (activityManager != null && activityManager.isBackgroundRestricted) { + addIssue(issues, "background-restricted", "Background usage is restricted for Faceclaw, which blocks alarms while the app is not open.", true) + } + } + val power = appContext.getSystemService(Context.POWER_SERVICE) as PowerManager? + if (power != null && !power.isIgnoringBatteryOptimizations(appContext.packageName)) { + addIssue(issues, "battery-optimized", "Battery optimization is on for Faceclaw; some phones delay alarms because of it.", true) + } + val audio = appContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager? + if (audio != null && audio.getStreamVolume(AudioManager.STREAM_ALARM) == 0) { + addIssue(issues, "alarm-volume", "The phone's alarm volume is muted; Faceclaw raises it while ringing, but check it.", true) + } + val maker = if (Build.MANUFACTURER == null) "" else Build.MANUFACTURER.lowercase(Locale.ROOT) + if (maker.contains("xiaomi") || maker.contains("huawei") || maker.contains("oppo") || maker.contains("vivo") + || maker.contains("oneplus") || maker.contains("realme") || maker.contains("meizu") || maker.contains("asus")) { + addIssue(issues, "oem-killer", "This phone maker is known to stop background apps; allow Faceclaw to auto-start and run unrestricted (see dontkillmyapp.com).", true) + } + if (scheduleLooksStale(appContext)) { + addIssue(issues, "schedule-stale", "The system lost Faceclaw's next alarm (the app may have been force-stopped); it was re-armed.", false) + rescheduleAll(appContext, "self-check") + } + return issues.toString() + } + + private fun addIssue(issues: JSONArray, code: String, message: String, fixable: Boolean) { + val issue = JSONObject() + try { + issue.put("code", code) + issue.put("message", message) + issue.put("fixable", fixable) + } catch (ignored: JSONException) { + return + } + issues.put(issue) + } + + /** Open the system screen where the issue can be fixed. */ + @JvmStatic + fun openReliabilityFix(context: Context, code: String?) { + val appContext = context.applicationContext + val pkg = appContext.packageName + var intent: Intent + when (code ?: "") { + "exact-alarm" -> + intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) + Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM, Uri.parse("package:$pkg")) + else + appDetails(pkg) + "notifications", "alarm-channel" -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS) + .putExtra(Settings.EXTRA_APP_PACKAGE, pkg) + if ("alarm-channel" == code) { + intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + .putExtra(Settings.EXTRA_APP_PACKAGE, pkg) + .putExtra(Settings.EXTRA_CHANNEL_ID, FaceclawAlarmService.CHANNEL_ID) + } + } else { + intent = appDetails(pkg) + } + } + "full-screen" -> + intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + Intent(Settings.ACTION_MANAGE_APP_USE_FULL_SCREEN_INTENT, Uri.parse("package:$pkg")) + else + appDetails(pkg) + "dnd-total", "dnd-alarms" -> + intent = Intent(Settings.ACTION_SOUND_SETTINGS) + "battery-optimized" -> + intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:$pkg")) + "alarm-volume" -> + intent = Intent(Settings.ACTION_SOUND_SETTINGS) + else -> + intent = appDetails(pkg) + } + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + try { + appContext.startActivity(intent) + } catch (error: RuntimeException) { + val fallback = appDetails(pkg).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + try { + appContext.startActivity(fallback) + } catch (ignored: RuntimeException) { + // No settings activity at all; nothing more to do. + } + } + } + + private fun appDetails(pkg: String): Intent { + return Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:$pkg")) + } + + // ------------------------------------------------------------------ + // Diagnostics log + + @JvmStatic + internal fun log(context: Context, line: String) { + synchronized(FaceclawAlarms::class.java) { + val appContext = context.applicationContext + val log = readArray(appContext, KEY_LOG) + val next = JSONArray() + val start = Math.max(0, log.length() - (LOG_LINES - 1)) + for (index in start until log.length()) { + next.put(log.optString(index)) + } + next.put(System.currentTimeMillis().toString() + " " + line) + writeArray(appContext, KEY_LOG, next) + } + } + + /** The ring / miss / action log, newest last, one line per entry. */ + @JvmStatic + fun readLog(context: Context): String { + val log = readArray(context.applicationContext, KEY_LOG) + val out = StringBuilder() + for (index in 0 until log.length()) { + if (index > 0) { + out.append('\n') + } + out.append(log.optString(index)) + } + return out.toString() + } + + // ------------------------------------------------------------------ + // Intents + + private fun expiryPendingIntent(appContext: Context, entry: JSONObject): PendingIntent { + val intent = Intent(appContext, FaceclawAlarmReceiver::class.java) + intent.action = ACTION_EXPIRE + val id = entry.optLong("id") + intent.putExtra(EXTRA_ID, id) + intent.putExtra(EXTRA_TITLE, entry.optString("title")) + intent.putExtra(EXTRA_TEXT, entry.optString("text")) + intent.putExtra(EXTRA_KIND, entry.optString("kind", KIND_ALARM)) + intent.putExtra(EXTRA_SNOOZE_MINUTES, entry.optInt("snoozeMinutes", 10)) + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags = flags or PendingIntent.FLAG_IMMUTABLE + } + return PendingIntent.getBroadcast(appContext, requestCode(id), intent, flags) + } + + /** What the system's alarm indicator opens: the app. */ + private fun showIntent(appContext: Context, id: Long): PendingIntent { + val intent = Intent(appContext, NativeScriptActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags = flags or PendingIntent.FLAG_IMMUTABLE + } + return PendingIntent.getActivity(appContext, requestCode(id), intent, flags) + } + + @JvmStatic + internal fun requestCode(id: Long): Int { + return (id xor (id ushr 32)).toInt() and 0x7fffffff + } + + @JvmStatic + internal fun startServiceCompat(appContext: Context, intent: Intent) { + ContextCompat.startForegroundService(appContext, intent) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.java deleted file mode 100644 index 0aab2ff6..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.faceclaw.app; - -import android.media.MediaCodec; -import android.media.MediaCodecInfo; -import android.media.MediaFormat; -import android.media.MediaMuxer; -import android.util.Log; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -/** - * Transcodes a 16-bit PCM WAV conversation recording into AAC-LC in an M4A - * container, cutting speech recordings to roughly a tenth of their WAV size. - * Runs on its own thread; the source WAV is deleted on success when requested. - */ -public class FaceclawAudioTranscoder { - private static final String TAG = "FaceclawTranscode"; - private static final long CODEC_TIMEOUT_US = 10_000; - - public interface Listener { - void onDone(String outputPath, long outputBytes); - - void onError(String message); - } - - private final String wavPath; - private final String outputPath; - private final int bitrateBps; - private final boolean deleteSourceOnSuccess; - private final Listener listener; - - public FaceclawAudioTranscoder( - String wavPath, - String outputPath, - int bitrateBps, - boolean deleteSourceOnSuccess, - Listener listener) { - this.wavPath = wavPath; - this.outputPath = outputPath; - this.bitrateBps = bitrateBps > 0 ? bitrateBps : 32_000; - this.deleteSourceOnSuccess = deleteSourceOnSuccess; - this.listener = listener; - } - - public void start() { - Thread thread = new Thread(this::run, "FaceclawTranscode"); - thread.setPriority(Thread.MIN_PRIORITY); - thread.start(); - } - - private void run() { - try { - transcode(); - long size = new File(outputPath).length(); - if (deleteSourceOnSuccess) { - new File(wavPath).delete(); - } - if (listener != null) { - listener.onDone(outputPath, size); - } - } catch (Throwable t) { - Log.w(TAG, "transcode failed for " + wavPath, t); - new File(outputPath).delete(); - if (listener != null) { - listener.onError(t.getMessage() == null ? t.toString() : t.getMessage()); - } - } - } - - private void transcode() throws IOException { - WavInfo wav = readWavHeader(wavPath); - MediaFormat format = MediaFormat.createAudioFormat( - MediaFormat.MIMETYPE_AUDIO_AAC, wav.sampleRate, wav.channels); - format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC); - format.setInteger(MediaFormat.KEY_BIT_RATE, bitrateBps); - format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 16 * 1024); - - MediaCodec codec = MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_AUDIO_AAC); - MediaMuxer muxer = null; - FileInputStream input = null; - try { - codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); - codec.start(); - muxer = new MediaMuxer(outputPath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); - input = new FileInputStream(wavPath); - long skipped = 0; - while (skipped < wav.dataOffset) { - long step = input.skip(wav.dataOffset - skipped); - if (step <= 0) { - throw new IOException("could not seek past WAV header"); - } - skipped += step; - } - - MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); - byte[] chunk = new byte[8192]; - int track = -1; - boolean muxerStarted = false; - boolean inputDone = false; - boolean outputDone = false; - long remaining = wav.dataBytes; - long presentationUs = 0; - long bytesPerSecond = (long) wav.sampleRate * wav.channels * 2; - - while (!outputDone) { - if (!inputDone) { - int inIndex = codec.dequeueInputBuffer(CODEC_TIMEOUT_US); - if (inIndex >= 0) { - ByteBuffer inBuf = codec.getInputBuffer(inIndex); - int wanted = (int) Math.min(chunk.length, Math.min(remaining, inBuf.capacity())); - int read = wanted > 0 ? input.read(chunk, 0, wanted) : -1; - if (read <= 0) { - codec.queueInputBuffer(inIndex, 0, 0, presentationUs, - MediaCodec.BUFFER_FLAG_END_OF_STREAM); - inputDone = true; - } else { - inBuf.clear(); - inBuf.put(chunk, 0, read); - codec.queueInputBuffer(inIndex, 0, read, presentationUs, 0); - remaining -= read; - presentationUs += read * 1_000_000L / bytesPerSecond; - } - } - } - int outIndex = codec.dequeueOutputBuffer(info, CODEC_TIMEOUT_US); - if (outIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) { - track = muxer.addTrack(codec.getOutputFormat()); - muxer.start(); - muxerStarted = true; - } else if (outIndex >= 0) { - if (info.size > 0 && (info.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) == 0) { - if (!muxerStarted) { - throw new IOException("encoder produced data before format"); - } - ByteBuffer outBuf = codec.getOutputBuffer(outIndex); - outBuf.position(info.offset); - outBuf.limit(info.offset + info.size); - muxer.writeSampleData(track, outBuf, info); - } - codec.releaseOutputBuffer(outIndex, false); - if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) { - outputDone = true; - } - } - } - } finally { - if (input != null) { - try { - input.close(); - } catch (IOException ignored) { - } - } - try { - codec.stop(); - } catch (Throwable ignored) { - } - codec.release(); - if (muxer != null) { - try { - muxer.stop(); - } catch (Throwable ignored) { - } - muxer.release(); - } - } - } - - private static final class WavInfo { - int sampleRate; - int channels; - long dataOffset; - long dataBytes; - } - - /** Minimal RIFF walk: locates fmt and data chunks, 16-bit PCM only. */ - private static WavInfo readWavHeader(String path) throws IOException { - try (FileInputStream in = new FileInputStream(path)) { - byte[] head = new byte[12]; - if (in.read(head) != 12 || head[0] != 'R' || head[1] != 'I' || head[8] != 'W') { - throw new IOException("not a WAV file"); - } - WavInfo info = new WavInfo(); - long offset = 12; - byte[] chunkHead = new byte[8]; - while (in.read(chunkHead) == 8) { - ByteBuffer b = ByteBuffer.wrap(chunkHead).order(ByteOrder.LITTLE_ENDIAN); - int id = b.getInt(); - long size = b.getInt() & 0xffffffffL; - offset += 8; - if (id == 0x20746d66) { // "fmt " - byte[] fmt = new byte[(int) Math.min(size, 16)]; - if (in.read(fmt) != fmt.length) { - throw new IOException("truncated fmt chunk"); - } - ByteBuffer f = ByteBuffer.wrap(fmt).order(ByteOrder.LITTLE_ENDIAN); - int audioFormat = f.getShort(); - info.channels = f.getShort(); - info.sampleRate = f.getInt(); - f.getInt(); - f.getShort(); - int bits = f.getShort(); - if (audioFormat != 1 || bits != 16) { - throw new IOException("only 16-bit PCM WAV is supported"); - } - long skip = size - fmt.length; - while (skip > 0) { - long step = in.skip(skip); - if (step <= 0) { - break; - } - skip -= step; - } - offset += size; - } else if (id == 0x61746164) { // "data" - info.dataOffset = offset; - // A zero size means the header was never patched (crash - // mid-recording); recover the length from the file size. - info.dataBytes = size > 0 ? size : new File(path).length() - offset; - break; - } else { - long skip = size; - while (skip > 0) { - long step = in.skip(skip); - if (step <= 0) { - break; - } - skip -= step; - } - offset += size; - } - } - if (info.sampleRate == 0 || info.dataOffset == 0) { - throw new IOException("missing fmt or data chunk"); - } - return info; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt new file mode 100644 index 00000000..1ffe9d16 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt @@ -0,0 +1,236 @@ +package com.faceclaw.app + +import android.media.MediaCodec +import android.media.MediaCodecInfo +import android.media.MediaFormat +import android.media.MediaMuxer +import android.util.Log + +import java.io.File +import java.io.FileInputStream +import java.io.IOException +import java.nio.ByteBuffer +import java.nio.ByteOrder + +/** + * Transcodes a 16-bit PCM WAV conversation recording into AAC-LC in an M4A + * container, cutting speech recordings to roughly a tenth of their WAV size. + * Runs on its own thread; the source WAV is deleted on success when requested. + */ +class FaceclawAudioTranscoder( + private val wavPath: String?, + private val outputPath: String?, + bitrateBps: Int, + private val deleteSourceOnSuccess: Boolean, + private val listener: Listener? +) { + companion object { + private const val TAG = "FaceclawTranscode" + private const val CODEC_TIMEOUT_US: Long = 10_000 + + /** Minimal RIFF walk: locates fmt and data chunks, 16-bit PCM only. */ + @JvmStatic + @Throws(IOException::class) + private fun readWavHeader(path: String?): WavInfo { + FileInputStream(path).use { `in` -> + val head = ByteArray(12) + if (`in`.read(head) != 12 || head[0] != 'R'.code.toByte() || head[1] != 'I'.code.toByte() || head[8] != 'W'.code.toByte()) { + throw IOException("not a WAV file") + } + val info = WavInfo() + var offset: Long = 12 + val chunkHead = ByteArray(8) + while (`in`.read(chunkHead) == 8) { + val b = ByteBuffer.wrap(chunkHead).order(ByteOrder.LITTLE_ENDIAN) + val id = b.getInt() + val size = b.getInt().toLong() and 0xffffffffL + offset += 8 + if (id == 0x20746d66) { // "fmt " + val fmt = ByteArray(Math.min(size, 16L).toInt()) + if (`in`.read(fmt) != fmt.size) { + throw IOException("truncated fmt chunk") + } + val f = ByteBuffer.wrap(fmt).order(ByteOrder.LITTLE_ENDIAN) + val audioFormat = f.getShort().toInt() + info.channels = f.getShort().toInt() + info.sampleRate = f.getInt() + f.getInt() + f.getShort() + val bits = f.getShort().toInt() + if (audioFormat != 1 || bits != 16) { + throw IOException("only 16-bit PCM WAV is supported") + } + var skip = size - fmt.size + while (skip > 0) { + val step = `in`.skip(skip) + if (step <= 0) { + break + } + skip -= step + } + offset += size + } else if (id == 0x61746164) { // "data" + info.dataOffset = offset + // A zero size means the header was never patched (crash + // mid-recording); recover the length from the file size. + info.dataBytes = if (size > 0) size else File(path).length() - offset + break + } else { + var skip = size + while (skip > 0) { + val step = `in`.skip(skip) + if (step <= 0) { + break + } + skip -= step + } + offset += size + } + } + if (info.sampleRate == 0 || info.dataOffset == 0L) { + throw IOException("missing fmt or data chunk") + } + return info + } + } + } + + interface Listener { + fun onDone(outputPath: String?, outputBytes: Long) + + fun onError(message: String?) + } + + private val bitrateBps: Int = if (bitrateBps > 0) bitrateBps else 32_000 + + fun start() { + val thread = Thread(Runnable { run() }, "FaceclawTranscode") + thread.priority = Thread.MIN_PRIORITY + thread.start() + } + + private fun run() { + try { + transcode() + val size = File(outputPath).length() + if (deleteSourceOnSuccess) { + File(wavPath).delete() + } + if (listener != null) { + listener.onDone(outputPath, size) + } + } catch (t: Throwable) { + Log.w(TAG, "transcode failed for $wavPath", t) + File(outputPath).delete() + if (listener != null) { + listener.onError(if (t.message == null) t.toString() else t.message) + } + } + } + + @Throws(IOException::class) + private fun transcode() { + val wav = readWavHeader(wavPath) + val format = MediaFormat.createAudioFormat( + MediaFormat.MIMETYPE_AUDIO_AAC, wav.sampleRate, wav.channels) + format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC) + format.setInteger(MediaFormat.KEY_BIT_RATE, bitrateBps) + format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 16 * 1024) + + val codec = MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_AUDIO_AAC) + var muxer: MediaMuxer? = null + var input: FileInputStream? = null + try { + codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE) + codec.start() + muxer = MediaMuxer(outputPath!!, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4) + input = FileInputStream(wavPath) + var skipped: Long = 0 + while (skipped < wav.dataOffset) { + val step = input.skip(wav.dataOffset - skipped) + if (step <= 0) { + throw IOException("could not seek past WAV header") + } + skipped += step + } + + val info = MediaCodec.BufferInfo() + val chunk = ByteArray(8192) + var track = -1 + var muxerStarted = false + var inputDone = false + var outputDone = false + var remaining = wav.dataBytes + var presentationUs: Long = 0 + val bytesPerSecond = wav.sampleRate.toLong() * wav.channels * 2 + + while (!outputDone) { + if (!inputDone) { + val inIndex = codec.dequeueInputBuffer(CODEC_TIMEOUT_US) + if (inIndex >= 0) { + val inBuf = codec.getInputBuffer(inIndex)!! + val wanted = Math.min(chunk.size.toLong(), Math.min(remaining, inBuf.capacity().toLong())).toInt() + val read = if (wanted > 0) input.read(chunk, 0, wanted) else -1 + if (read <= 0) { + codec.queueInputBuffer(inIndex, 0, 0, presentationUs, + MediaCodec.BUFFER_FLAG_END_OF_STREAM) + inputDone = true + } else { + inBuf.clear() + inBuf.put(chunk, 0, read) + codec.queueInputBuffer(inIndex, 0, read, presentationUs, 0) + remaining -= read.toLong() + presentationUs += read * 1_000_000L / bytesPerSecond + } + } + } + val outIndex = codec.dequeueOutputBuffer(info, CODEC_TIMEOUT_US) + if (outIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) { + track = muxer.addTrack(codec.outputFormat) + muxer.start() + muxerStarted = true + } else if (outIndex >= 0) { + if (info.size > 0 && (info.flags and MediaCodec.BUFFER_FLAG_CODEC_CONFIG) == 0) { + if (!muxerStarted) { + throw IOException("encoder produced data before format") + } + val outBuf = codec.getOutputBuffer(outIndex)!! + outBuf.position(info.offset) + outBuf.limit(info.offset + info.size) + muxer.writeSampleData(track, outBuf, info) + } + codec.releaseOutputBuffer(outIndex, false) + if ((info.flags and MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) { + outputDone = true + } + } + } + } finally { + if (input != null) { + try { + input.close() + } catch (ignored: IOException) { + } + } + try { + codec.stop() + } catch (ignored: Throwable) { + } + codec.release() + if (muxer != null) { + try { + muxer.stop() + } catch (ignored: Throwable) { + } + muxer.release() + } + } + } + + private class WavInfo { + var sampleRate = 0 + var channels = 0 + var dataOffset: Long = 0 + var dataBytes: Long = 0 + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java deleted file mode 100644 index c7aeef55..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ /dev/null @@ -1,4100 +0,0 @@ -package com.faceclaw.app; - -import android.annotation.SuppressLint; -import android.bluetooth.BluetoothGatt; -import android.bluetooth.BluetoothGattCharacteristic; -import android.app.KeyguardManager; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Handler; -import android.os.Looper; -import android.os.PowerManager; -import android.os.SystemClock; -import android.util.Log; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.nio.charset.StandardCharsets; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Random; - -@SuppressLint("MissingPermission") -public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { - private static final String TAG = "FaceclawComm"; - - // Local metadata for custom-command bookkeeping, not an EvenHub container. - // Submitted frames supply pixel geometry; the stock layout only captures input. - private static final BleProtocol.ImageTileOptions DASHBOARD_TILE = - new BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288); - - private static final String G2_SCREEN_WAKE_LOCK_TAG = "Faceclaw:G2Screen"; - private static final long FACECLAW_WAKE_LEASE_RENEW_MS = 45_000; - private static final long FACECLAW_WAKE_CONTROL_WAIT_MS = 1_500; - private static final long CFW_CLEANUP_WAIT_MS = 4_000; - private static final int COMPASS_REPORT_INTERVAL_MS = 100; - private static final int COMPASS_MIN_CHANGE_DEGREES = 0; - - private final Context appContext; - private final PowerManager powerManager; - private final KeyguardManager keyguardManager; - private final FaceclawBleManager bleManager; - private final InterruptibleSleep interruptibleSleep = new InterruptibleSleep(); - private final Object lock = new Object(); - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private final String rightAddress; - private final String leftAddress; - private final String ringAddress; - - private volatile FaceclawBleCommunicatorListener listener; - private final java.util.List imuListeners = - new java.util.concurrent.CopyOnWriteArrayList<>(); - /** A compass subscriber plus the Looper it registered from (see addCompassListener). */ - private static final class CompassSubscription { - final FaceclawCompassListener listener; - final Handler handler; - - CompassSubscription(FaceclawCompassListener listener, Handler handler) { - this.listener = listener; - this.handler = handler; - } - } - - private final java.util.List compassSubscriptions = - new java.util.concurrent.CopyOnWriteArrayList<>(); - private final java.util.List ambientLightListeners = - new java.util.concurrent.CopyOnWriteArrayList<>(); - private final java.util.List micStatusListeners = - new java.util.concurrent.CopyOnWriteArrayList<>(); - private volatile Thread workerThread; - private volatile boolean running; - private volatile boolean userDisconnectRequested; - // Set when a connect attempt failed while an arm's Android bond is gone: - // retrying is pointless until the user re-pairs, so the worker loop parks - // instead of redialing. Cleared by start() (a fresh explicit connect). - private volatile boolean reconnectHalted; - - private String phase = "disconnected"; - private String status = "Disconnected."; - - private boolean rightConnected; - private boolean leftConnected; - private boolean ringConnected; - private boolean ringNotificationsReady; - private boolean sessionReady; - private boolean fixedLayoutCreated; - private boolean shutdownRequested; - // CFW firmware-debug-flags overlay (mode 7). Desired value pushed from TS; the - // sub-op last sent this session (-1 = not yet), reset on (re)connect so the - // overlay state is re-asserted on every reconnect and whenever the value changes. - private volatile boolean firmwareDebugFlagsEnabled; - private int firmwareDebugFlagsLastSent = -1; - // Desired CFW mode-10 compass state. It survives reconnects; lastSent is - // reset with each session so an open Compass window is re-asserted. - /** - * Who currently wants the stock compass running (the Compass window, the - * Navigate worker, ...). The magnetometer is one shared resource, so it - * stays on while any owner holds it and is released when the last lets go; - * this keeps one app's release from silently switching off another's feed. - */ - private final java.util.Set compassOwners = new java.util.HashSet<>(); - private int compassControlLastSent = -1; - // Whether the glasses-side compass may still be running: set when an enable - // is enqueued, cleared only when a disable is acked. Drives the forced - // disable sent ahead of an EvenHub shutdown/suspend, since a pending - // disable can be wiped by the shutdown's queue flush and the retry loop - // does not run while shutdownRequested (magnetometer left on = battery drain). - private boolean compassMaybeOn; - private boolean startupProbePending; - // Desired ownership of CFW's fail-open stock-wake lease (dashboard launch - // and Even AI foreground takeover). This survives a transport reconnect; - // the lease itself is volatile firmware state and is re-acquired once both - // arms are ready. - private boolean faceclawWakeLeaseEnabled; - private long lastFaceclawWakeLeaseQueuedAtMs; - private int faceclawWakeControlGeneration; - private int faceclawWakeControlSentCount; - private long lastFaceclawFramebufferLeaseQueuedAtMs; - private int faceclawFramebufferControlGeneration; - private int faceclawFramebufferControlSentCount; - private int faceclawWakePendingNonce = -1; - /** - * The last firmware-info read said the glasses run Faceclaw's custom - * firmware. Gates the private modes (cleanup, resource cache, ...) so stock - * or third-party firmware never sees them; the TS side checks the actual - * revision and disconnects on a mismatch, so no per-feature gating is - * needed here. - */ - private boolean customFirmwareDetected; - private boolean cfwCleanupDelivered; - private int lastCfwCleanupAckMagic; - - private long reconnectAfterMs; - private long ringReconnectAfterMs; - private long lastAckAtMs; - private long lastIncomingAtMs; - private long lastHeartbeatSentAtMs; - private long lastHeartbeatAckedAtMs; - private long lastConnectionOrInputAtMs; - private long lastBatteryRefreshAtMs; - private long imageRetryAfterMs; - private long lastSessionReadyAtMs; - private long lastEvenAppConflictAtMs; - private int consecutiveAckTimeouts; - private int lastAudioControlAckMagic = 0; - - private ConnectionOptions connectionOptions = new ConnectionOptions(); - private final BleMagicPool magicPool = new BleMagicPool(AndroidProtocolPlatform.INSTANCE); - private MessageBuilder messageBuilder = new MessageBuilder(magicPool); - private int nextTransportSeq = 0x40; - private int nextMapSessionId = 0; - private int nextImageUpdateId = 1; - // Wire frame id for mode-3 deltas (CFW reorder/skip/dup diagnostic). uint16, - // advanced by 1 per emitted delta; kept in [1, 0xfffe] to avoid the CFW's - // 0xffff "empty" sentinel. - private int nextImageFrameId = 1; - private int lastShutdownAckMagic = 0; - private long lastShutdownExitAtMs = 0; - private int headsetBattery = -1; - private int headsetCharging = -1; - private int ringBattery = -1; - private int ringCharging = -1; - // Silent mode: 1 = on, 0 = off, -1 = not yet known. See updateSilentModeLocked. - private int silentMode = -1; - private int wearState = -1; - private int phoneLockState = -1; - private long lastPhoneLockCheckAtMs; - private boolean phoneLockReceiverRegistered; - private boolean audioCaptureActive; - private boolean firmwareInfoQueried; - // Glasses are in the charging case: nobody is wearing them, so display - // communication pauses and only battery polls flow (see driveSession). - private boolean chargingMode; - private volatile FaceclawAudioPacketListener audioPacketListener; - private PowerManager.WakeLock g2ScreenWakeLock; - - // BLE bandwidth benchmark (Developer app). Streams no-op image payloads - // (CFW mode 7 with an unused sub-op: parsed, acked, and discarded — stock - // firmware likewise ignores unknown image modes) for a fixed duration with - // a selectable message size and pipeline window, then reports throughput. - // While active, desired-frame sends are held back and heartbeats are - // satisfied by the benchmark's own acks, so the stream is the only image - // traffic. All state below is guarded by `lock`; results are read with - // getBandwidthBenchmarkStatus() and survive until the next run starts. - private boolean benchmarkActive; - private boolean benchmarkAborted; - private final Random benchmarkRandom = new Random(); - private int benchmarkMessageSize; - private int benchmarkWindowSize; - private int benchmarkDurationMs; - private int benchmarkLinkMode; - private boolean benchmarkLinkPending; - private long benchmarkReadyAtMs; - private long benchmarkStartAtMs; // first benchmark write; 0 until then - private long benchmarkDeadlineAtMs; // start + duration; MAX_VALUE until first write - private long benchmarkLastAckAtMs; - private long benchmarkEndAtMs; // 0 while running; set when the run drains - private int benchmarkMessagesSent; - private int benchmarkMessagesAcked; - private int benchmarkTimeouts; - private long benchmarkPayloadBytesAcked; - private long benchmarkWireBytesAcked; - // A timed-out benchmark message aborts the run, but its already-in-flight - // peers still time out one by one; keep the window comfortably below - // MAX_CONSECUTIVE_ACK_TIMEOUTS so a dead run can't escalate into a - // transport-failure reconnect all by itself. - private static final int BENCHMARK_MAX_WINDOW = 6; - - private final BroadcastReceiver phoneLockReceiver = new BroadcastReceiver() { - @Override public void onReceive(Context context, Intent intent) { - emitPhoneLockStateIfChanged(true); - interruptibleSleep.interrupt(); - } - }; - - private String displayedFingerprint = ""; - // The frame the firmware shadow will hold once the current image pipeline - // drains: the most recently ENQUEUED image (headerless packed 4bpp, see - // BmpUtil.pack4bppFromGray8), which is the correct base for the next delta - // when frames are pipelined. Set at enqueue; cleared whenever the image - // pipeline is cleared (clearAllMessagesLocked / clearMessagesOfKindLocked - // "image"), so it is only ever read while it holds a valid current-session base. - private byte[] lastEnqueuedPacked = new byte[0]; - private int lastEnqueuedWidth; - private int lastEnqueuedHeight; - private String lastEnqueuedFingerprint = ""; - private final Map imageUpdateStats = new HashMap<>(); - - private final Object desiredTilesLock = new Object(); - private String desiredFingerprint = ""; - // Headerless packed 4bpp frame (see BmpUtil.pack4bppFromGray8) plus its - // pixel dimensions. - private byte[] desiredPacked = new byte[0]; - private int desiredWidth; - private int desiredHeight; - private int desiredPaintMs; - private int desiredFrameId; - // Screen-space deferred draws (glyphs + images) whose pixels are baked - // into desiredPacked; the resource-cache planner may replay them as - // on-glasses cached draws. - private SurfaceCompositor.ScreenDraw[] desiredDraws = new SurfaceCompositor.ScreenDraw[0]; - // (frame, reason) of the last "waiting to send" line, so a frame that - // stalls for seconds records one line per state change (see - // noteImageStallLocked). Send-loop thread only. - private int stallFrameId; - private String stallReason = ""; - // Highest compositor sequence stored as the desired frame; composites that - // lost a store race to a newer one are discarded (their content is already - // included in the newer composite). - private long lastStoredCompositeSeq; - - // Wire submissions need screenGray + the shell scene, never preview pixels. - // Preview/screenshot/recording callers render those explicitly on demand. - private final SurfaceCompositor compositor = new SurfaceCompositor(false); - - // Phone-side model of the CFW's 192 KiB resource cache. - // Reset whenever the image pipeline / EvenHub session is torn down: the - // firmware frees the cache with the fb lease, and after any resync the - // cheap safe assumption is an empty cache (glyphs re-upload lazily). - private final ResourceCacheState resourceCache = new ResourceCacheState(); - private final ScenePlanner scenePlanner = new ScenePlanner(resourceCache); - private ShellScene desiredShellScene = ShellScene.Companion.getEMPTY(); - - private final ArrayDeque pendingMessages = new ArrayDeque<>(); - private final CfwTransport[] cfwTransports = { new CfwTransport(AndroidProtocolPlatform.INSTANCE), new CfwTransport(AndroidProtocolPlatform.INSTANCE) }; - private final ArrayDeque inFlightMessages = new ArrayDeque<>(); - private OutboundMessage prewrittenMessage; - private List prewrittenFrames = Collections.emptyList(); - - public FaceclawBleCommunicator(Context context, String rightAddress, String leftAddress, String ringAddress) { - this.appContext = context.getApplicationContext(); - FrameTimings.getInstance().init(appContext); - this.powerManager = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); - this.keyguardManager = (KeyguardManager) appContext.getSystemService(Context.KEYGUARD_SERVICE); - this.bleManager = new FaceclawBleManager(appContext); - this.bleManager.setListener(this); - this.rightAddress = requireAddress("rightAddress", rightAddress); - this.leftAddress = requireAddress("leftAddress", leftAddress); - this.ringAddress = ringAddress == null ? "" : ringAddress.trim(); - IntentFilter phoneLockFilter = new IntentFilter(); - phoneLockFilter.addAction(Intent.ACTION_SCREEN_ON); - phoneLockFilter.addAction(Intent.ACTION_SCREEN_OFF); - phoneLockFilter.addAction(Intent.ACTION_USER_PRESENT); - appContext.registerReceiver(phoneLockReceiver, phoneLockFilter); - phoneLockReceiverRegistered = true; - } - - - public void setListener(FaceclawBleCommunicatorListener listener) { - this.listener = listener; - emitState(); - emitPhoneLockStateIfChanged(true); - } - - public void start() { - synchronized (lock) { - if (running) { - return; - } - running = true; - userDisconnectRequested = false; - reconnectHalted = false; - shutdownRequested = false; - activeInstance = this; - workerThread = new Thread(this, "FaceclawBleCommunicator"); - workerThread.start(); - } - } - - public void disconnect() { - /* On the normal path DashboardController already sent mode 11 after - * quiescing its producers. Also cover direct/early close callers here; - * a successful cleanup must remain the final BLE message. Older CFWs - * fall back to the standalone framebuffer-lease release. */ - if (!cfwCleanupDelivered && !sendCfwCleanup()) { - releaseFaceclawFramebufferLease(); - } - Thread threadToJoin; - synchronized (lock) { - userDisconnectRequested = true; - running = false; - audioCaptureActive = false; - audioPacketListener = null; - threadToJoin = workerThread; - } - setStateDisplay("disconnecting", "Disconnecting..."); - interruptibleSleep.interrupt(); - if (threadToJoin != null) { - threadToJoin.interrupt(); - try { - threadToJoin.join(5_000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - synchronized (lock) { - workerThread = null; - resetSessionStateLocked(); - clearAllMessagesLocked("disconnect"); - // Unknown until the next connection's first push or settings poll. - silentMode = -1; - } - bleManager.disconnect(rightAddress); - bleManager.disconnect(leftAddress); - if (hasRingAddress()) { - bleManager.disconnect(ringAddress); - } - bleManager.close(); - releaseG2ScreenWakeLock(); - setStateDisplay("disconnected", "Disconnected."); - } - - public void close() { - if (activeInstance == this) { - activeInstance = null; - } - disconnect(); - for (CfwTransport transport : cfwTransports) transport.close(); - if (phoneLockReceiverRegistered) { - phoneLockReceiverRegistered = false; - appContext.unregisterReceiver(phoneLockReceiver); - } - } - - public void setG2ScreenOn(boolean screenOn) { - mainHandler.post(() -> updateG2ScreenWakeLock(screenOn)); - } - - public void setFirmwareDebugFlags(boolean enabled) { - // Just record it; the drive loop emits the mode-7 control message when the - // display path is ready and idle, and re-emits when this value changes. - firmwareDebugFlagsEnabled = enabled; - } - - public boolean startG2AudioCapture(FaceclawAudioPacketListener listener) { - if (listener == null) { - throw new IllegalArgumentException("listener is required"); - } - int magic; - synchronized (lock) { - if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { - logLine("skip G2 mic enable; EvenHub display path not ready"); - return false; - } - audioPacketListener = listener; - OutboundMessage message = createAudioControlMessageLocked(true); - magic = message.magic; - pendingMessages.addFirst(message); - logLine("queue G2 mic enable"); - } - interruptibleSleep.interrupt(); - return waitForAudioControlAck(magic, "enable"); - } - - public void stopG2AudioCapture() { - int magic = 0; - synchronized (lock) { - audioPacketListener = null; - audioCaptureActive = false; - clearMessagesOfKindLocked("audio-control"); - if (running && sessionReady) { - OutboundMessage message = createAudioControlMessageLocked(false); - magic = message.magic; - pendingMessages.addFirst(message); - logLine("queue G2 mic disable"); - } - } - interruptibleSleep.interrupt(); - if (magic != 0) { - waitForAudioControlAck(magic, "disable"); - } - } - - public boolean isSessionReady() { - synchronized (lock) { - return running && sessionReady; - } - } - - /** - * Whether the glasses mic is enabled right now. The enable lives in the - * current EvenHub session, so it dies with a transport drop, the charging - * case, or a suspend — silently, from the phone's point of view. Callers - * that track a capture across those events must check this rather than - * assume their earlier enable still holds. - */ - public boolean isAudioCaptureActive() { - synchronized (lock) { - return running && sessionReady && !shutdownRequested && audioCaptureActive; - } - } - - /** - * Acquire/renew or release CFW's volatile wake-takeover lease on both - * arms. Delivery (not a protocol ACK) is awaited so a caller can ensure - * the fail-open firmware policy is installed before relying on wakeword - * interception or suspending EvenHub. - */ - public boolean setFaceclawWakeLeaseEnabled(boolean enabled) { - int generation; - synchronized (lock) { - faceclawWakeLeaseEnabled = enabled; - if (!running || !sessionReady) { - return !enabled; - } - generation = enqueueFaceclawWakeControlLocked( - enabled ? BleProtocol.FACECLAW_WAKE_OP_ACQUIRE : BleProtocol.FACECLAW_WAKE_OP_RELEASE, - 0, - true - ); - if (!enabled) { - faceclawWakePendingNonce = -1; - } - } - interruptibleSleep.interrupt(); - return waitForFaceclawWakeControlDelivery(generation, FACECLAW_WAKE_CONTROL_WAIT_MS); - } - - /** - * Wait until the recreated layout and retained compositor frame have both - * landed. If this wake came from CFW's deferred double tap, READY - * is then sent to both arms to cancel their stock-dashboard fallback. - */ - public boolean awaitEvenHubSessionReady(int timeoutMs) { - long deadline = SystemClock.elapsedRealtime() + Math.max(0, timeoutMs); - int readyGeneration = 0; - synchronized (lock) { - while (running && sessionReady) { - boolean frameReady = false; - synchronized (desiredTilesLock) { - frameReady = !desiredFingerprint.isEmpty() - && desiredFingerprint.equals(displayedFingerprint); - } - if (!shutdownRequested && fixedLayoutCreated && frameReady) { - if (faceclawWakePendingNonce >= 0) { - readyGeneration = enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_READY, - faceclawWakePendingNonce, - true - ); - faceclawWakePendingNonce = -1; - } - break; - } - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - return false; - } - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return false; - } - } - if (!running || !sessionReady) { - return false; - } - } - if (readyGeneration != 0) { - interruptibleSleep.interrupt(); - if (!waitForFaceclawWakeControlDelivery(readyGeneration, FACECLAW_WAKE_CONTROL_WAIT_MS)) { - logLine("wake READY delivery not confirmed before fallback deadline"); - } - } - return true; - } - - /** - * Enable or disable the IMU (accelerometer) report stream. Fire-and-forget: - * the control message is queued ahead of other traffic; readings arrive via - * registered FaceclawImuListeners. reportFrq is the requested sample rate - * (ignored on disable). - */ - public void setImuReportEnabled(boolean enable, int reportFrq) { - synchronized (lock) { - if (!running || !sessionReady) { - logLine("skip IMU " + (enable ? "enable" : "disable") + "; session not ready"); - return; - } - clearMessagesOfKindLocked("imu-control"); - OutboundMessage message = messageBuilder.enableOrDisableImu(enable, reportFrq); - message.onTimeout = () -> logLine("IMU control ack timeout"); - pendingMessages.addFirst(message); - logLine("queue IMU " + (enable ? "enable freq=" + reportFrq : "disable")); - } - interruptibleSleep.interrupt(); - } - - /** - * Enable/disable the stock compass through CFW image-handler mode 10. The - * desired state is retained across reconnects; headings arrive through - * stock sid-0x08 navigation notifications and FaceclawCompassListeners. - */ - public void setCompassEnabled(boolean enable) { - setCompassEnabled("compass", enable); - } - - /** - * As above, on behalf of a named owner. The compass runs while at least - * one owner has enabled it; an owner disabling it only takes effect once - * no other owner still wants it. - */ - public void setCompassEnabled(String owner, boolean enable) { - synchronized (lock) { - boolean before = !compassOwners.isEmpty(); - if (enable) { - compassOwners.add(owner); - } else { - compassOwners.remove(owner); - } - boolean wanted = !compassOwners.isEmpty(); - if (wanted == before && compassControlLastSent == (wanted ? 1 : 0)) { - logLine("compass " + (enable ? "enable" : "disable") + " by " + owner - + "; state unchanged (owners=" + compassOwners + ")"); - return; - } - compassControlLastSent = -1; - clearMessagesOfKindLocked("compass-control"); - if (running && sessionReady && !shutdownRequested && fixedLayoutCreated) { - enqueueCompassControlLocked(true, wanted); - } else { - logLine("defer compass " + (enable ? "enable" : "disable") + "; display path not ready"); - } - } - interruptibleSleep.interrupt(); - } - - /** - * Set the lens brightness. Fire-and-forget, like the IMU control: the - * message is queued ahead of other traffic and any not-yet-sent brightness - * message is superseded. When autoAdjust is true the ambient-light sensor - * drives brightness and brightnessLevel is ignored; otherwise - * brightnessLevel (0-100) is applied directly. - */ - public void setBrightness(boolean autoAdjust, int brightnessLevel) { - synchronized (lock) { - if (!running || !sessionReady) { - logLine("skip brightness set; session not ready"); - return; - } - clearMessagesOfKindLocked("brightness-control"); - OutboundMessage message = messageBuilder.setBrightness(autoAdjust, brightnessLevel); - message.onTimeout = () -> logLine("brightness control ack timeout"); - pendingMessages.addFirst(message); - logLine("queue brightness " + (autoAdjust ? "auto" : "level=" + brightnessLevel)); - } - interruptibleSleep.interrupt(); - } - - /** - * Enable the stock wear detector, then ask CFW to emit its current cached - * state. The queue order matters: the query must run after the setting is - * applied, including on a fresh install where wear detection was disabled. - */ - public void enableWearDetectionAndRequestState() { - synchronized (lock) { - if (!running || !sessionReady) { - logLine("skip wear detector setup; session not ready"); - return; - } - clearMessagesOfKindLocked("wear-detection-control"); - clearMessagesOfKindLocked("wear-query-control"); - OutboundMessage queryLeft = messageBuilder.faceclawWearQuery(true); - OutboundMessage queryRight = messageBuilder.faceclawWearQuery(false); - OutboundMessage enable = messageBuilder.setWearDetection(true); - enable.onTimeout = () -> logLine("wear detection enable ack timeout"); - pendingMessages.addFirst(queryLeft); - pendingMessages.addFirst(queryRight); - pendingMessages.addFirst(enable); - logLine("queue wear detection enable + current-state query"); - } - interruptibleSleep.interrupt(); - } - - /** - * Start the BLE bandwidth benchmark: stream messageSize-byte no-op image - * payloads for durationMs, keeping up to windowSize messages awaiting ack - * at once, then leave the results for getBandwidthBenchmarkStatus(). - * Returns false when a run is already active or the image path is not - * ready. The duration clock starts at the first benchmark write, so - * traffic already queued ahead of the run doesn't count against it. - */ - public boolean startBandwidthBenchmark(int messageSize, int windowSize, int durationMs) { - return startBandwidthBenchmarkWithLinkMode(messageSize, windowSize, durationMs, 0); - } - - // 0: current link; 1: re-request HIGH; 2: request 2M; 3: both. - public boolean startBandwidthBenchmarkWithLinkMode(int messageSize, int windowSize, - int durationMs, int linkMode) { - synchronized (lock) { - if (benchmarkActive || !running || !sessionReady || !fixedLayoutCreated - || shutdownRequested || chargingMode) { - logLine("skip bandwidth benchmark; already running or image path not ready"); - return false; - } - benchmarkMessageSize = Math.max(2, Math.min(messageSize, ConnectionOptions.IMAGE_FRAGMENT_SIZE)); - benchmarkWindowSize = Math.max(1, Math.min(windowSize, BENCHMARK_MAX_WINDOW)); - benchmarkDurationMs = Math.max(1_000, durationMs); - benchmarkLinkMode = linkMode & 3; - benchmarkLinkPending = true; - benchmarkReadyAtMs = Long.MAX_VALUE; - benchmarkStartAtMs = 0; - benchmarkDeadlineAtMs = Long.MAX_VALUE; - benchmarkLastAckAtMs = 0; - benchmarkEndAtMs = 0; - benchmarkMessagesSent = 0; - benchmarkMessagesAcked = 0; - benchmarkTimeouts = 0; - benchmarkPayloadBytesAcked = 0; - benchmarkWireBytesAcked = 0; - benchmarkAborted = false; - benchmarkActive = true; - logLine("bandwidth benchmark start: size=" + benchmarkMessageSize - + "B window=" + benchmarkWindowSize + " duration=" + benchmarkDurationMs - + "ms linkMode=" + benchmarkLinkMode); - } - interruptibleSleep.interrupt(); - return true; - } - - /** - * Cancel an in-progress benchmark (benchmark page closed). Queued no-op - * messages are dropped; in-flight ones drain through their normal acks. - */ - public void cancelBandwidthBenchmark() { - synchronized (lock) { - if (!benchmarkActive) { - return; - } - clearMessagesOfKindLocked("bandwidth"); - finishBenchmarkLocked(true, "cancelled"); - } - interruptibleSleep.interrupt(); - } - - /** Status/results of the current or most recent benchmark run, as JSON. */ - public String getBandwidthBenchmarkStatus() { - synchronized (lock) { - String state = benchmarkActive - ? (benchmarkStartAtMs == 0 ? "starting" : "running") - : (benchmarkEndAtMs != 0 ? "done" : "idle"); - long end = benchmarkActive ? SystemClock.elapsedRealtime() : benchmarkEndAtMs; - long elapsed = benchmarkStartAtMs == 0 ? 0 : Math.max(0, end - benchmarkStartAtMs); - try { - org.json.JSONObject status = new org.json.JSONObject(); - status.put("state", state); - status.put("messageSize", benchmarkMessageSize); - status.put("windowSize", benchmarkWindowSize); - status.put("linkMode", benchmarkLinkMode); - status.put("elapsedMs", elapsed); - status.put("messagesSent", benchmarkMessagesSent); - status.put("messagesAcked", benchmarkMessagesAcked); - status.put("timeouts", benchmarkTimeouts); - status.put("payloadBytesAcked", benchmarkPayloadBytesAcked); - status.put("wireBytesAcked", benchmarkWireBytesAcked); - status.put("aborted", benchmarkAborted); - return status.toString(); - } catch (org.json.JSONException e) { - return "{\"state\":\"idle\"}"; - } - } - } - - /** Pending + in-flight benchmark no-op messages. */ - private int benchmarkOutstandingLocked() { - int count = 0; - for (OutboundMessage message : pendingMessages) { - if ("bandwidth".equals(message.kind)) count++; - } - for (OutboundMessage message : inFlightMessages) { - if ("bandwidth".equals(message.kind)) count++; - } - return count; - } - - /** - * Keep the benchmark stream fed: top the pending queue up so the send - * window never starves, stop enqueueing once the run expires (or a message - * times out), and finish the run when the last outstanding message drains. - */ - private void maintainBenchmarkLocked(long now) { - if (!sessionReady || !fixedLayoutCreated || shutdownRequested) { - finishBenchmarkLocked(true, "session no longer ready"); - return; - } - if (benchmarkLinkPending || now < benchmarkReadyAtMs) { - return; - } - if (benchmarkAborted || now >= benchmarkDeadlineAtMs) { - // The run is over: drop queued-but-unsent no-ops (sending them - // would stretch the run past its deadline) and finish once the - // in-flight tail has acked or timed out. - Iterator pendingIterator = pendingMessages.iterator(); - while (pendingIterator.hasNext()) { - OutboundMessage queued = pendingIterator.next(); - if ("bandwidth".equals(queued.kind)) { - pendingIterator.remove(); - magicPool.release(queued.sid, queued.magic, queued.label, "benchmark over"); - } - } - if (benchmarkOutstandingLocked() == 0) { - finishBenchmarkLocked(false, "complete"); - } - return; - } - // One more than the window so a fresh message is always ready to write - // the moment an ack frees a slot. - for (int outstanding = benchmarkOutstandingLocked(); outstanding <= benchmarkWindowSize; outstanding++) { - enqueueBenchmarkMessageLocked(); - } - } - - private void finishBenchmarkLocked(boolean aborted, String reason) { - if (!benchmarkActive) { - return; - } - benchmarkActive = false; - benchmarkAborted |= aborted; - // Prefer the last ack as the end time so drain lag after the deadline - // doesn't dilute the throughput figure. - benchmarkEndAtMs = benchmarkLastAckAtMs != 0 ? benchmarkLastAckAtMs : SystemClock.elapsedRealtime(); - logLine("bandwidth benchmark " + (benchmarkAborted ? "aborted" : "finished") + " (" + reason + "): " - + benchmarkMessagesAcked + "/" + benchmarkMessagesSent + " acked, " - + benchmarkPayloadBytesAcked + "B payload, " + benchmarkTimeouts + " timeouts"); - } - - private void enqueueBenchmarkMessageLocked() { - // Fresh bytes per message: the transport's persistent compression history - // would compress even a random payload if we reused it across the run. - byte[] payload = new byte[benchmarkMessageSize]; - benchmarkRandom.nextBytes(payload); - payload[0] = CfwMessageTypeKt.CFW_MSG_DIAGNOSTICS; // CFW diagnostic-control mode... - payload[1] = (byte) 0x7f; // ...with an unused sub-op: acked, no effect - OutboundMessage message = messageBuilder.imagePayload( - "bandwidth", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - "bandwidth no-op " + payload.length + "B", - connectionOptions.sendImagesToLeft); - final int payloadBytes = payload.length; - // Logical custom-message bytes; excludes length tag and packet framing. - final int wireBytes = message.message.length; - message.onSent = () -> { - benchmarkMessagesSent++; - if (benchmarkStartAtMs == 0) { - benchmarkStartAtMs = SystemClock.elapsedRealtime(); - benchmarkDeadlineAtMs = benchmarkStartAtMs + benchmarkDurationMs; - } - }; - message.onAck = () -> { - long ackedAtMs = SystemClock.elapsedRealtime(); - benchmarkMessagesAcked++; - benchmarkPayloadBytesAcked += payloadBytes; - benchmarkWireBytesAcked += wireBytes; - benchmarkLastAckAtMs = ackedAtMs; - // No-op payloads ride the image path, so the firmware resets its - // heartbeat timer on them just like real image messages. - lastHeartbeatAckedAtMs = ackedAtMs; - }; - message.onTimeout = () -> { - benchmarkTimeouts++; - benchmarkAborted = true; - logLine("bandwidth benchmark ack timeout"); - }; - pendingMessages.addLast(message); - } - - public void addImuListener(FaceclawImuListener listener) { - if (listener != null) { - imuListeners.add(listener); - } - } - - public void removeImuListener(FaceclawImuListener listener) { - if (listener != null) { - imuListeners.remove(listener); - } - } - - public void addAmbientLightListener(FaceclawAmbientLightListener listener) { - if (listener != null) { - ambientLightListeners.add(listener); - } - } - - public void removeAmbientLightListener(FaceclawAmbientLightListener listener) { - if (listener != null) { - ambientLightListeners.remove(listener); - } - } - - private void emitAmbientLight(byte[] body) { - if (ambientLightListeners.isEmpty()) { - return; - } - byte[] copy = java.util.Arrays.copyOf(body, body.length); - mainHandler.post(() -> { - for (FaceclawAmbientLightListener alsListener : ambientLightListeners) { - try { - alsListener.onAmbientLight(copy); - } catch (Throwable t) { - Log.w(TAG, "ambient light listener failed", t); - } - } - }); - } - - /** Request one CFW ambient-light report (image-handler mode 16 op 0). */ - public void queryAmbientLight() { - synchronized (lock) { - enqueueAmbientLightControlLocked(new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_AMBIENT_LIGHT, (byte) 0 }, "als query", false); - } - interruptibleSleep.interrupt(); - } - - /** - * Start or stop CFW passive light-sensor polling (image-handler mode 16 - * ops 1/2). While polling, the firmware reads its OPT3001 every intervalMs - * (clamped 100..5000 by the firmware), never steps the panel brightness - * itself, and pushes a field-105 report when the reading moved by at least - * minDelta or heartbeatMs elapsed. bindToLease stops polling automatically - * when the Faceclaw framebuffer lease is released or lapses. Starting is - * idempotent and re-opens the sensor if the stock firmware closed it. - */ - public void setAmbientLightPolling(boolean enable, int intervalMs, int minDelta, - int heartbeatMs, boolean bindToLease) { - byte[] payload = enable - ? new byte[] { - (byte) CfwMessageTypeKt.CFW_MSG_AMBIENT_LIGHT, - (byte) 1, - (byte) (bindToLease ? 1 : 0), - (byte) (intervalMs & 0xff), - (byte) ((intervalMs >> 8) & 0xff), - (byte) (minDelta & 0xff), - (byte) ((minDelta >> 8) & 0xff), - (byte) (heartbeatMs & 0xff), - (byte) ((heartbeatMs >> 8) & 0xff), - } - : new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_AMBIENT_LIGHT, (byte) 2 }; - synchronized (lock) { - clearMessagesOfKindLocked("als-control"); - enqueueAmbientLightControlLocked(payload, "als polling " + (enable ? "start" : "stop"), true); - } - interruptibleSleep.interrupt(); - } - - private void enqueueAmbientLightControlLocked(byte[] payload, String label, boolean priority) { - if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { - logLine("skip " + label + "; display path not ready"); - return; - } - OutboundMessage message = messageBuilder.imagePayload( - "als-control", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - label, - connectionOptions.sendImagesToLeft); - message.onTimeout = () -> logLine(label + " ack timeout"); - if (priority) pendingMessages.addFirst(message); - else pendingMessages.addLast(message); - logLine("queue " + label); - } - - public void addMicStatusListener(FaceclawMicStatusListener listener) { - if (listener != null) { - micStatusListeners.add(listener); - } - } - - public void removeMicStatusListener(FaceclawMicStatusListener listener) { - if (listener != null) { - micStatusListeners.remove(listener); - } - } - - private void emitMicStatus(byte[] body, String address) { - if (micStatusListeners.isEmpty()) { - return; - } - String arm = address.equalsIgnoreCase(leftAddress) ? "L" - : address.equalsIgnoreCase(rightAddress) ? "R" : "?"; - byte[] copy = java.util.Arrays.copyOf(body, body.length); - mainHandler.post(() -> { - for (FaceclawMicStatusListener micListener : micStatusListeners) { - try { - micListener.onMicStatus(copy, arm); - } catch (Throwable t) { - Log.w(TAG, "mic status listener failed", t); - } - } - }); - } - - /** - * Queue a CFW mic_control record (['M','C',ver,op,...]) as a settings - * field-103 write to both temples, or to a single one. Fire-and-forget: - * the firmware answers with a field-104 status notify per temple, which - * arrives through addMicStatusListener. - */ - public void sendFaceclawMicControl(byte[] record, String label, boolean rightTemple, boolean leftTemple) { - if (record == null || record.length < 4) { - return; - } - synchronized (lock) { - if (!running || !sessionReady) { - logLine("skip mic control (" + label + "); session not ready"); - return; - } - if (rightTemple) { - pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, false)); - } - if (leftTemple) { - pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, true)); - } - logLine("queue mic control " + label); - } - interruptibleSleep.interrupt(); - } - - /** - * Forward render-characteristic audio packets to the listener WITHOUT - * sending the stock EvenHub audio-control enable. Used for the CFW - * mic_control streaming path, where capture is armed through settings - * field 103 and the temples emit 'SM' frames on the same characteristic - * that stock mono LC3 uses. Returns false when no session is up. - */ - public boolean startG2AudioForwarding(FaceclawAudioPacketListener listener) { - if (listener == null) { - throw new IllegalArgumentException("listener is required"); - } - synchronized (lock) { - if (!running || !sessionReady || shutdownRequested) { - logLine("skip G2 audio forwarding; session not ready"); - return false; - } - audioPacketListener = listener; - audioCaptureActive = true; - logLine("G2 audio forwarding enabled"); - } - return true; - } - - public void stopG2AudioForwarding() { - synchronized (lock) { - audioPacketListener = null; - audioCaptureActive = false; - logLine("G2 audio forwarding disabled"); - } - } - - /** - * Subscribe to compass events. Callbacks are delivered on the Looper of - * the thread that registered (falling back to the main thread), so app - * worker isolates can listen without a cross-thread hop into their JS. - */ - public void addCompassListener(FaceclawCompassListener listener) { - if (listener == null) { - return; - } - Looper looper = Looper.myLooper(); - Handler handler = looper != null ? new Handler(looper) : mainHandler; - compassSubscriptions.add(new CompassSubscription(listener, handler)); - } - - public void removeCompassListener(FaceclawCompassListener listener) { - if (listener == null) { - return; - } - for (CompassSubscription subscription : compassSubscriptions) { - if (subscription.listener == listener) { - compassSubscriptions.remove(subscription); - } - } - } - - - // The most recently started communicator; lets app worker threads submit - // surface frames without holding a cross-isolate reference to the bridge - // object (JS wrappers do not cross isolates, but the Java instance does). - private static volatile FaceclawBleCommunicator activeInstance; - - public static FaceclawBleCommunicator getActive() { - return activeInstance; - } - - /** Set the compositor's output frame size. Call before configuring surfaces. */ - public void configureCompositorScreen(int width, int height) { - compositor.configureScreen(width, height); - } - - /** - * The current composited screen as a phone-UI preview bitmap, or null - * before any surface has been configured. Built from the compositor so - * the preview reflects every surface (chrome + whichever app is - * foreground), including worker-app frames the TS side never sees. - */ - public android.graphics.Bitmap getCompositePreviewBitmap(double brightenGamma) { - return getCompositePreviewBitmap(brightenGamma, false); - } - - /** As above; `green` renders the preview green-on-black (Settings > Phone display > Preview color). */ - public android.graphics.Bitmap getCompositePreviewBitmap(double brightenGamma, boolean green) { - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return null; - } - return PreviewBitmapUtil.fromGray( - java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green); - } - - /** Save the current composite as a 4-bit grayscale PNG; returns the path or "". */ - public String saveCompositePngScreenshot() throws java.io.IOException { - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return ""; - } - return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height); - } - - /** - * Save the current composite cropped to the given screen rect (the region - * the shell says is actually occupied). The rect is clamped to the screen; - * a degenerate rect falls back to the full screen. - */ - public String saveCompositePngScreenshot(int cropX, int cropY, int cropWidth, int cropHeight) - throws java.io.IOException { - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return ""; - } - int x = Math.max(0, cropX); - int y = Math.max(0, cropY); - int width = Math.min(composite.width - x, cropWidth - (x - cropX)); - int height = Math.min(composite.height - y, cropHeight - (y - cropY)); - if (width <= 0 || height <= 0 || (x == 0 && y == 0 && width == composite.width && height == composite.height)) { - return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height); - } - byte[] cropped = new byte[width * height]; - for (int row = 0; row < height; row++) { - System.arraycopy(composite.gray, (y + row) * composite.width + x, cropped, row * width, width); - } - return ScreenshotUtil.savePngScreenshot(appContext, cropped, width, height); - } - - // Active animated-GIF screen recording, or null when idle. Frames are - // pushed by recordScreenFrame(), which the TS side calls at each - // phone-preview flush. - private volatile GifScreenRecorder screenRecorder; - - /** Begin collecting composite frames for an animated-GIF screen recording. */ - public void startScreenRecording() { - screenRecorder = new GifScreenRecorder(); - } - - /** Capture the current composite into the active recording; no-op when idle. */ - public void recordScreenFrame() { - GifScreenRecorder recorder = screenRecorder; - if (recorder == null) { - return; - } - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return; - } - recorder.addFrame(composite.gray, composite.width, composite.height, System.currentTimeMillis()); - } - - /** Finish the recording and save it as an animated GIF; returns the path or "". */ - public String stopScreenRecording() throws java.io.IOException { - GifScreenRecorder recorder = screenRecorder; - screenRecorder = null; - if (recorder == null) { - return ""; - } - if (recorder.isOverflowed()) { - logLine("screen recording hit its frame cap; the tail was dropped"); - } - return recorder.save(appContext); - } - - /** - * Show or hide a compositor surface, immediately submitting the resulting - * frame. Recompositing here (rather than waiting for the next surface - * update) is what makes a just-foregrounded window's retained frame - * actually appear — otherwise a static window (e.g. the terminal hub) whose - * frame landed while briefly hidden would stay blank until its next repaint. - */ - public void setSurfaceVisible(String id, boolean visible) { - // Its own frame: this recomposite is a real screen update with real - // latency, and without one it would show up in other frames' logs only - // as an anonymous "superseded by frame#0". - int frameId = FrameTimings.getInstance().startFrame( - "compositor:visible " + id + "=" + visible); - compositor.setSurfaceVisible(id, visible); - SurfaceCompositor.Composite composite = compositor.composite(); - byte[] packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height); - storeDesiredComposite(composite, packed, 0, frameId); - } - - /** - * Blank (screen off) or unblank the composited output, immediately - * submitting the resulting frame. Retained surface state is untouched, so - * unblanking restores the previous screen content without repaints. - */ - public void setScreenBlanked(boolean blanked) { - int frameId = FrameTimings.getInstance().startFrame( - "compositor:" + (blanked ? "blank" : "unblank")); - compositor.setBlanked(blanked); - SurfaceCompositor.Composite composite = compositor.composite(); - byte[] packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height); - storeDesiredComposite(composite, packed, 0, frameId); - } - - /** - * Create or reconfigure a compositor surface. transparency is one of the - * SurfaceCompositor.TRANSPARENCY_* constants. Geometry changes take effect - * when the next frame is submitted. - */ - public void configureSurface(String id, int x, int y, int width, int height, int zOrder, int transparency) { - compositor.configureSurface(id, x, y, width, height, zOrder, transparency); - } - - public void removeSurface(String id) { - compositor.removeSurface(id); - } - - /** Stage an immutable shell snapshot alongside the retained app screen. */ - public void submitShellScene(java.nio.ByteBuffer bytes, int paintMs, int frameId) { - compositor.setShellScene(new AndroidByteReader(bytes)); - SurfaceCompositor.Composite composite = compositor.composite(); - storeDesiredComposite(composite, BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height), paintMs, frameId); - } - - /** Legacy compositor dimming for callers without a shell scene. */ - public void setUnderlayDim(int belowZOrder, int factor256) { - compositor.setUnderlayDim(belowZOrder, factor256); - } - - /** - * Apply an update to one compositor surface and submit the recomposited - * screen as the desired frame. The update covers the rect (rectX, rectY, - * rectWidth, rectHeight) in surface-local coordinates; contentFingerprint - * identifies the surface's full content after the update. - * - * pixels8bpp arrives as a ByteBuffer because NativeScript marshals a JS - * ArrayBuffer to one without the per-element bridge copy that a byte[] - * parameter would need (~150ms for a full frame). - */ - public void submitSurfaceFrame( - java.nio.ByteBuffer pixels8bpp, - String surfaceId, - int rectX, - int rectY, - int rectWidth, - int rectHeight, - String contentFingerprint, - int paintMs, - int frameId - ) { - submitSurfaceFrame(pixels8bpp, surfaceId, rectX, rectY, rectWidth, rectHeight, - contentFingerprint, paintMs, frameId, null); - } - - /** - * As above, with the frame's glyph draws (see SurfaceCompositor's glyph - * overload for the buffer format): the surface's full text content as - * structured draws, letting the resource-cache planner ship glyphs as - * on-glasses cached draws instead of pixels. Null when the submitter has - * no glyph metadata; the pixels alone remain fully correct. - */ - public void submitSurfaceFrame( - java.nio.ByteBuffer pixels8bpp, - String surfaceId, - int rectX, - int rectY, - int rectWidth, - int rectHeight, - String contentFingerprint, - int paintMs, - int frameId, - java.nio.ByteBuffer glyphs - ) { - Log.i(TAG, "Received an updated frame for surface " + surfaceId); - FrameTimings.getInstance().log(frameId, "surface " + surfaceId + " updated rect=" - + rectWidth + "x" + rectHeight + "+" + rectX + "+" + rectY - + (glyphs == null ? " (no glyph draws)" : "")); - FrameTimings.getInstance().spanStart(frameId, "composite"); - SurfaceCompositor.Composite composite = compositor.applyAndComposite( - surfaceId, new AndroidByteReader(pixels8bpp), rectX, rectY, rectWidth, rectHeight, contentFingerprint, - glyphs == null ? null : new AndroidByteReader(glyphs)); - FrameTimings.getInstance().spanEnd(frameId, "composite"); - // Pack the composited 8bpp buffer down to the headerless 4bpp frame - // format the wire planners consume; BMP framing is added later only for - // the uncompressed fallback. - FrameTimings.getInstance().spanStart(frameId, "pack-4bpp"); - byte[] packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height); - FrameTimings.getInstance().spanEnd(frameId, "pack-4bpp"); - storeDesiredComposite(composite, packed, paintMs, frameId); - } - - /** Store a composite as the desired frame unless a newer one won the race. */ - private void storeDesiredComposite(SurfaceCompositor.Composite composite, byte[] packed, int paintMs, int frameId) { - int supersededFrameId = 0; - boolean stale = false; - synchronized (desiredTilesLock) { - if (composite.seq <= lastStoredCompositeSeq) { - // A concurrent submission composited after us and stored first; - // its composite already includes this surface update. - stale = true; - } else { - lastStoredCompositeSeq = composite.seq; - supersededFrameId = desiredFrameId; - desiredPacked = packed; - desiredWidth = composite.width; - desiredHeight = composite.height; - desiredFingerprint = composite.fingerprint; - desiredPaintMs = paintMs; - desiredFrameId = frameId; - desiredDraws = composite.draws; - desiredShellScene = composite.shellScene; - } - } - if (stale) { - finishFrame(frameId, "discarded: composite superseded before store"); - return; - } - if (supersededFrameId != 0 && supersededFrameId != frameId) { - finishFrame(supersededFrameId, "discarded: superseded by frame#" + frameId + " before send"); - } - FrameTimings.getInstance().log(frameId, "image submitted as desired frame"); - interruptibleSleep.interrupt(); - } - - /** - * Play a tone sequence via CFW load_image_z mode 5 kind 4. The payload is - * the complete wire buffer ([5][4][nSteps][freqLo,freqHi,duty,msLo,msHi]*n, - * up to 48 steps), built on the TS side; it rides the arbitrary-payload - * image path like the other mode-5 controls. - */ - public void playBuzzerSequence(java.nio.ByteBuffer payload) { - synchronized (lock) { - if (!running || !sessionReady || !fixedLayoutCreated) { - logLine("skip buzzer sequence; session not ready"); - return; - } - byte[] bytes = new byte[payload == null ? 0 : payload.remaining()]; - if (payload != null) { - payload.get(bytes); - } - if (bytes.length < 3) { - logLine("skip buzzer sequence; empty payload"); - return; - } - OutboundMessage message = messageBuilder.imagePayload( - DASHBOARD_TILE, - nextMapSessionId(), - bytes, - "buzzer sequence " + bytes.length + "B", - connectionOptions.sendImagesToLeft - ); - message.onTimeout = () -> { - handleTransportFailure("buzzer sequence ack timeout"); - }; - pendingMessages.addLast(message); - logLine("queue " + message.label); - } - interruptibleSleep.interrupt(); - } - - public boolean sendShutdown(int exitMode) { - return sendShutdownInternal(exitMode, true); - } - - /** - * Send CFW image-handler mode 11 after quiescing normal traffic. A successful - * return means the cleanup was ACKed and no later Faceclaw message should be - * emitted before closing BLE. Unsupported/older CFWs return false so callers - * can use the legacy shutdown-and-lease-release path. - */ - public boolean sendCfwCleanup() { - int magic; - synchronized (lock) { - if (cfwCleanupDelivered) { - return true; - } - if (!customFirmwareDetected || !running || !sessionReady - || shutdownRequested || !fixedLayoutCreated) { - logLine("skip CFW cleanup; mode 11 unavailable or image path not ready"); - return false; - } - - /* Stop auto-renewals, heartbeats, image generation, and control - * retries, then discard everything that has not reached BLE yet. */ - shutdownRequested = true; - lastCfwCleanupAckMagic = 0; - clearPendingMessagesLocked("CFW cleanup requested"); - logLine("quiescing transport for CFW cleanup"); - } - interruptibleSleep.interrupt(); - - /* WINDOW_SIZE can exceed one, so merely appending cleanup would allow it - * to overlap previously-written image fragments. Wait until all of those - * ACK or time out; shutdownRequested prevents the drive loop from adding - * any fresh automatic traffic meanwhile. */ - long drainDeadline = SystemClock.elapsedRealtime() + CFW_CLEANUP_WAIT_MS; - synchronized (lock) { - while (running && sessionReady && !inFlightMessages.isEmpty()) { - long remaining = drainDeadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) break; - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - if (!running || !sessionReady || !inFlightMessages.isEmpty()) { - shutdownRequested = false; - logLine("CFW cleanup could not drain prior traffic"); - return false; - } - - /* External producers are expected to be stopped by the caller, but - * clear once more at the barrier so cleanup is definitely last. */ - clearPendingMessagesLocked("CFW cleanup barrier"); - OutboundMessage message = messageBuilder.cfwCleanup( - DASHBOARD_TILE, - nextMapSessionId(), - connectionOptions.sendImagesToLeft - ); - magic = message.magic; - message.onAck = () -> { - lastCfwCleanupAckMagic = message.magic; - cfwCleanupDelivered = true; - compassMaybeOn = false; - faceclawWakeLeaseEnabled = false; - logLine("CFW cleanup completed"); - }; - message.onTimeout = () -> logLine("CFW cleanup ack timeout"); - pendingMessages.addLast(message); - logLine("queue CFW cleanup"); - } - interruptibleSleep.interrupt(); - - long deadline = SystemClock.elapsedRealtime() + CFW_CLEANUP_WAIT_MS; - synchronized (lock) { - while (running - && sessionReady - && lastCfwCleanupAckMagic != magic - && hasPendingOrInflightMagicLocked(magic)) { - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) break; - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - boolean acked = lastCfwCleanupAckMagic == magic; - if (!acked) shutdownRequested = false; - return acked; - } - } - - /** - * End the EvenHub page while retaining both arm GATT connections and all - * notification subscriptions. A missed ACK is intentionally non-fatal: - * reconnecting Bluetooth here would defeat the power-saving mode. - */ - public boolean suspendEvenHubSession() { - // Ending the plugin task releases the fb lease, which frees the - // on-glasses resource cache; forget it phone-side either way (a lost - // ack may still have taken effect). - synchronized (lock) { - resourceCache.reset(); - } - if (sendShutdownInternal(0, false)) { - return true; - } - synchronized (lock) { - // A shutdown ACK can be lost even though the command took effect. - // If the transport remains intentionally quiesced, callers still - // need to remember to run the resume path on the next wake. - return running && sessionReady && shutdownRequested; - } - } - - /** - * Start a fresh EvenHub plugin task on the existing BLE transport, then let - * the session driver create the layout, warm up the image path, and send - * the desired frame. - */ - public boolean resumeEvenHubSession() { - int claimGeneration = 0; - synchronized (lock) { - if (!running || !sessionReady || chargingMode) { - logLine("skip EvenHub resume; transport not ready"); - return false; - } - if (!shutdownRequested) { - return true; - } - if (faceclawWakePendingNonce >= 0 - && hasPendingOrInflightKindLocked("wake-lease-control")) { - claimGeneration = faceclawWakeControlGeneration; - } - logLine("replaying session prelude for EvenHub resume"); - } - - // A custom double-tap wake has only a short unclaimed fail-open - // deadline. Let the worker put CLAIM on both arms before the direct - // prelude write begins. - if (claimGeneration != 0) { - waitForFaceclawWakeControlDelivery(claimGeneration, 500); - } - - try { - // Empty-name Cmd=9 tears down the whole plugin task, not just its - // image container. Re-run the launch prelude before Cmd=0 CREATE. - sendPrelude(true); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - handleTransportFailure("EvenHub resume prelude interrupted"); - return false; - } catch (Throwable t) { - logLine("EvenHub resume prelude failed: " + safeMessage(t)); - handleTransportFailure("EvenHub resume prelude failed"); - return false; - } - - synchronized (lock) { - if (!running || !sessionReady || chargingMode) { - return false; - } - shutdownRequested = false; - fixedLayoutCreated = false; - startupProbePending = false; - audioCaptureActive = false; - clearAllMessagesPreservingWakeLeaseLocked("EvenHub resume"); - displayedFingerprint = ""; - imageRetryAfterMs = 0; - lastHeartbeatSentAtMs = 0; - lastHeartbeatAckedAtMs = 0; - logLine("EvenHub session resume requested"); - } - interruptibleSleep.interrupt(); - return true; - } - - private boolean sendShutdownInternal(int exitMode, boolean reconnectOnTimeout) { - int magic; - long startedAtMs = SystemClock.elapsedRealtime(); - synchronized (lock) { - if (!running || !sessionReady) { - logLine("skip shutdown; session not ready"); - return false; - } - if (shutdownRequested) { - return true; - } - shutdownRequested = true; - // Magic values wrap, so an ACK from a much older suspend must not - // satisfy this request after enough sleep/wake cycles. - lastShutdownAckMagic = 0; - clearPendingMessagesLocked("shutdown requested"); - OutboundMessage message = messageBuilder.shutdown(exitMode); - magic = message.magic; - message.onAck = () -> { - lastShutdownAckMagic = message.magic; - fixedLayoutCreated = false; - displayedFingerprint = ""; - }; - message.onTimeout = () -> { - if (reconnectOnTimeout) { - handleTransportFailure("shutdown ack timeout"); - } else { - logLine("EvenHub shutdown ack timeout; keeping BLE connected"); - } - }; - pendingMessages.addFirst(message); - logLine("queue shutdown"); - // The stock compass keeps the magnetometer sampling independently of - // the plugin task, so ending the page does not stop it. Force a - // disable ahead of the shutdown command whenever it may be running: - // this also covers a disable that was wiped by the queue flush above - // or whose ack was lost, and the charging-mode/exit paths where the - // Compass window never got a chance to release it. - if (compassMaybeOn && fixedLayoutCreated) { - enqueueCompassControlLocked(true, false); - } - } - interruptibleSleep.interrupt(); - - long ackDeadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + 500; - synchronized (lock) { - while (running - && sessionReady - && lastShutdownAckMagic != magic - && lastShutdownExitAtMs < startedAtMs - && hasPendingOrInflightMagicLocked(magic)) { - long remaining = ackDeadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - boolean acked = lastShutdownAckMagic == magic; - if (acked) { - long exitDeadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + 500; - while (running && sessionReady && lastShutdownExitAtMs < startedAtMs) { - long remaining = exitDeadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - } - return acked || lastShutdownExitAtMs >= startedAtMs; - } - } - - private boolean waitForAudioControlAck(int magic, String operation) { - long deadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + ConnectionOptions.WRITE_TIMEOUT_MS + 500; - synchronized (lock) { - while (running && sessionReady && lastAudioControlAckMagic != magic && hasPendingOrInflightMagicLocked(magic)) { - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - boolean acked = lastAudioControlAckMagic == magic; - if (!acked) { - if ("enable".equals(operation)) { - audioPacketListener = null; - audioCaptureActive = false; - } - logLine("G2 mic " + operation + " ack timeout"); - } - return acked; - } - } - - - @Override public void run() { - logLine(String.format(Locale.US, "communicator start R=%s L=%s ring=%s", rightAddress, leftAddress, ringAddress)); - while (true) { - try { - if (!running) { - Log.w(TAG, "Exiting event looop"); - break; - } - emitPhoneLockStateIfChanged(false); - if (!sessionReady) { - if (reconnectHalted) { - interruptibleSleep.sleep(ConnectionOptions.IDLE_SLEEP_MS); - continue; - } - long now = SystemClock.elapsedRealtime(); - if (now < reconnectAfterMs) { - interruptibleSleep.sleep(Math.min(ConnectionOptions.IDLE_SLEEP_MS, reconnectAfterMs - now)); - continue; - } - Log.w(TAG, "Attempting to connect"); - connectLoopOnce(); - continue; - } - - if (shouldAttemptRingConnect()) { - tryConnectRing("retry"); - continue; - } - - long sleepMs = driveSession(); - if (sleepMs > 0) { - interruptibleSleep.sleep(sleepMs); - } - } catch (Throwable t) { - logLine("communicator loop error: " + safeMessage(t)); - handleTransportFailure("loop error"); - } - } - logLine("communicator stop"); - } - - @Override public void onNotification(String address, String characteristicUuid, byte[] data) { - if (address == null || characteristicUuid == null || data == null) { - return; - } - String uuid = characteristicUuid.toLowerCase(Locale.US); - if (isDirectRingNotification(address, uuid)) { - handleDirectRingNotification(uuid, data); - return; - } - if (BleProtocol.RENDER_NOTIFY_UUID.equals(uuid)) { - handleRenderNotification(address, data); - return; - } - if (!BleProtocol.NOTIFY_CHAR_UUID.equals(uuid)) { - return; - } - if (data.length >= 7 && (data[6] & 255) == CfwTransport.SID) { - CfwTransport.Ack[] acks = CfwTransport.parseAcks(data); - if (acks == null) return; - synchronized (lock) { - lastIncomingAtMs = SystemClock.elapsedRealtime(); - for (CfwTransport.Ack ack : acks) { - for (OutboundMessage message : inFlightMessages) { - String ingress = message.isLeftArmMessage ? leftAddress : rightAddress; - if (message.sid == CfwTransport.SID && address.equalsIgnoreCase(ingress) && message.magic == ack.streamId) { - message.acceptCfwAck(ack); - Log.i(TAG, "CFW " + (ack.nack ? "NACK" : "ACK") + " id=" + ack.streamId - + " ordinal=" + ack.messageId + " lens=" + ack.lens + " txseq=" + (data[2] & 255) - + " redundant=" + (ack != acks[0]) - + " size=" + ack.size + " crc=" + ack.checksum - + " expected=" + message.message.length + "/" + message.cfwChecksum - + " ackedLenses=" + message.cfwAckLenses - + " ageMs=" + (lastIncomingAtMs - message.sentAtMs)); - message.ackPayload = Arrays.copyOf(data, data.length); - break; - } - } - } - drainCfwAcknowledgementsLocked(); - } - interruptibleSleep.interrupt(); - return; - } - Log.d(TAG, "onNotification: address=" + address + " characteristicUuid=" + characteristicUuid + " data.length=" + data.length); - BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(data); - int decodedWearState = BleProtocol.parseWearState(frame); - BleProtocol.CompassEvent compassEvent = address.equalsIgnoreCase(rightAddress) - ? BleProtocol.parseCompassEvent(frame) - : null; - boolean emitWearState = false; - G2Event event = null; - synchronized (lock) { - lastIncomingAtMs = SystemClock.elapsedRealtime(); - if (decodedWearState >= 0 && decodedWearState != wearState) { - wearState = decodedWearState; - emitWearState = true; - } - boolean faceclawWakeNotification = false; - if (shutdownRequested - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING - && address.equalsIgnoreCase(rightAddress)) { - int wakeNonce = BleProtocol.parseFaceclawWakeEvent(frame.pb); - if (wakeNonce >= 0) { - faceclawWakePendingNonce = wakeNonce; - enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_CLAIM, - wakeNonce, - true - ); - faceclawWakeNotification = true; - lastConnectionOrInputAtMs = lastIncomingAtMs; - // The event type says which gesture woke the glasses: TS - // gives a head-up the Glanceboard and a double tap the - // regular UI. The claim handshake is the same for both. - boolean headUp = BleProtocol.parseFaceclawWakeEventCode(frame.pb) - == BleProtocol.FACECLAW_WAKE_EVENT_HEAD_UP; - event = new G2Event( - "display-wake", - "", - headUp ? BleProtocol.EVENT_HEAD_UP : BleProtocol.EVENT_DOUBLE_CLICK, - 0, - 0 - ); - logLine("claimed deferred dashboard wake nonce=" + wakeNonce - + (headUp ? " (head-up)" : "")); - } - } - if (!faceclawWakeNotification - && shutdownRequested - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING - && address.equalsIgnoreCase(rightAddress)) { - // CFW idle-gesture forwarding (firmware revision 2+): with no - // EvenHub page the stock display thread drops taps, long - // presses and releases; the CFW reports them on the settings - // sid while our wake lease is held. Deliver them as the - // sys-events a live page would have produced, so TS treats a - // sleep-time tap or hold exactly like one during soft sleep - // (the Glanceboard). - BleProtocol.FaceclawGestureEvent gesture = BleProtocol.parseFaceclawGestureEvent(frame.pb); - if (gesture != null) { - lastConnectionOrInputAtMs = lastIncomingAtMs; - event = new G2Event("sys-event", "", gesture.eventType, gesture.eventSource, 0); - logLine("idle gesture forwarded by CFW: type=" + gesture.eventType - + " source=" + gesture.eventSource); - } - } - if (!faceclawWakeNotification - && event == null - && shutdownRequested - && address.equalsIgnoreCase(rightAddress) - && BleProtocol.isDisplayWakeStateChange(frame)) { - // With no EvenHub page, ring/arm double-taps are handled by the - // stock display lifecycle and surface only as this state ping. - // Translate it back into an input event so TS can wake the shell - // and recreate the page. - event = new G2Event( - "display-wake", - "", - BleProtocol.EVENT_DOUBLE_CLICK, - 0, - 0 - ); - } - if (!faceclawWakeNotification - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING) { - // Mode-17 query notifications; settings READs are handled by - // createBatteryQueryMessageLocked so headset/ring update together. - if (address.equalsIgnoreCase(rightAddress) - && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { - BleProtocol.RingBatterySnapshot ring = BleProtocol.parseRingBattery(frame.pb); - if (ring != null) { - ringBattery = ring.battery; - ringCharging = ring.charging; - emitBatteryState(headsetBattery, headsetCharging); - } - } - // CFW mic status (field 104) rides both standalone pushes and - // settings read acks, from each temple on its own link. - byte[] micStatus = BleProtocol.parseFaceclawMicStatus(frame.pb); - if (micStatus != null) { - emitMicStatus(micStatus, address); - } - } - if (!faceclawWakeNotification - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING) { - // CFW ambient-light report (field 105) from the master temple. - byte[] alsReport = BleProtocol.parseFaceclawAlsReport(frame.pb); - if (alsReport != null) { - emitAmbientLight(alsReport); - } - } - if (!faceclawWakeNotification - && decodedWearState < 0 - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING) { - // Device-initiated settings push. It carries a magic the glasses - // chose, so it would otherwise fall through to resolveAckLocked, - // match nothing, and be logged as an unexpected ack. - int pushedSilentMode = BleProtocol.parseSilentModePush(frame.pb); - if (pushedSilentMode >= 0) { - updateSilentModeLocked(pushedSilentMode > 0); - return; - } - } - if (!faceclawWakeNotification - && decodedWearState < 0 - && frame.ok - && frame.msgSeq >= 0 - && frame.flag != BleProtocol.FLAG_NOTIFY - && frame.flag != BleProtocol.FLAG_NOTIFY_ALT) { - lastAckAtMs = lastIncomingAtMs; - resolveAckLocked(frame.sid, frame.msgSeq, frame.pb); - } - if (!faceclawWakeNotification - && event == null - && frame.ok - && address.equalsIgnoreCase(rightAddress) - && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { - event = G2Event.decode(frame); - if (event != null - && "sys-event".equals(event.kind) - && event.eventType == BleProtocol.EVENT_HEAD_UP) { - // CFW forwards the IMU head-up while our page is on screen - // (soft sleep). Surface it as the same wake-only input the - // deferred head-up wake produces from a dark display. - event = new G2Event("display-wake", "", BleProtocol.EVENT_HEAD_UP, event.eventSource, 0); - logLine("head-up forwarded by CFW while page on screen"); - } - if (event != null) { - // Pure IMU samples arrive continuously; don't let them count - // as user input (which would starve battery polling). - boolean pureImuSample = "sys-event".equals(event.kind) - && event.eventType == BleProtocol.EVENT_IMU_DATA_REPORT; - if (!pureImuSample) { - lastConnectionOrInputAtMs = lastIncomingAtMs; - } - if ("list-click".equals(event.kind) || "text-click".equals(event.kind)) { - // Container-routed touchpad input reached us, so the - // firmware is dispatching input: silent mode is off, - // whether or not its end-of-silent push arrived. - updateSilentModeLocked(false); - } - if ("sys-event".equals(event.kind)) { - if (event.eventType == BleProtocol.EVENT_FOREGROUND_EXIT || event.eventType == BleProtocol.EVENT_ABNORMAL_EXIT || event.eventType == BleProtocol.EVENT_SYSTEM_EXIT) { - if (shutdownRequested) { - lastShutdownExitAtMs = SystemClock.elapsedRealtime(); - } - fixedLayoutCreated = false; - displayedFingerprint = ""; - clearAllMessagesLocked("firmware exit event"); - } - } - } - } - } - interruptibleSleep.interrupt(); - if (emitWearState) { - logLine(decodedWearState > 0 ? "wear state ON_HEAD" : "wear state OFF_HEAD"); - emitWearState(decodedWearState > 0); - } - if (compassEvent != null) { - emitCompassEvent(compassEvent); - } - if (event != null) { - if (event.hasImu) { - emitImuData(event.imuX, event.imuY, event.imuZ, event.eventSource); - } - // A standalone IMU_DATA_REPORT is a sensor sample, not a gesture: - // deliver it only to IMU listeners, skipping the input pipeline (and - // its per-frame latency bookkeeping) to avoid flooding it. - boolean pureImuSample = "sys-event".equals(event.kind) - && event.eventType == BleProtocol.EVENT_IMU_DATA_REPORT; - if (!pureImuSample) { - int frameId = FrameTimings.getInstance().startFrame( - "input:" + event.kind + " type=" + event.eventType + " src=" + event.eventSource); - FrameTimings.getInstance().log(frameId, "input event decoded from BLE notification"); - emitRingEvent(event, frameId); - } - } - } - - private void handleDirectRingNotification(String characteristicUuid, byte[] data) { - FaceclawRingEventDecoder.DirectRingEvent decoded = FaceclawRingEventDecoder.decode(data); - if (decoded == null) { - Log.d(TAG, "direct ring notify ignored: characteristicUuid=" + characteristicUuid + " raw=" + hex(data)); - return; - } - - G2Event event = decoded.event; - long arrivalMs = SystemClock.elapsedRealtime(); - synchronized (lock) { - lastIncomingAtMs = arrivalMs; - lastConnectionOrInputAtMs = arrivalMs; - } - logLine("direct ring " + decoded.label + " " + decoded.detail + " raw=" + hex(data)); - int frameId = FrameTimings.getInstance().startFrame("input:ring:" + decoded.label); - FrameTimings.getInstance().log(frameId, "input event decoded from direct ring notification"); - emitRingEvent(event, frameId); - interruptibleSleep.interrupt(); - } - - private void handleRenderNotification(String address, byte[] data) { - FaceclawAudioPacketListener listenerToCall; - long arrivalMs = SystemClock.elapsedRealtime(); - synchronized (lock) { - lastIncomingAtMs = arrivalMs; - listenerToCall = audioCaptureActive ? audioPacketListener : null; - } - if (listenerToCall == null) { - return; - } - String arm = address.equalsIgnoreCase(leftAddress) ? "L" : address.equalsIgnoreCase(rightAddress) ? "R" : "?"; - try { - listenerToCall.onAudioPacket(Arrays.copyOf(data, data.length), arm, arrivalMs); - } catch (Throwable t) { - logLine("G2 mic packet listener failed: " + safeMessage(t)); - } - } - - @Override public void onConnectionStateChange(String address, boolean connected) { - synchronized (lock) { - if (address == null) { - return; - } - if (isConfiguredRingAddress(address)) { - ringConnected = connected; - ringNotificationsReady = false; - if (!connected) { - ringReconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RING_RECONNECT_DELAY_MS; - } - logLine(connected ? "direct ring BLE connected" : "direct ring BLE disconnected"); - return; - } - if (address.equalsIgnoreCase(rightAddress)) { - rightConnected = connected; - } else if (address.equalsIgnoreCase(leftAddress)) { - leftConnected = connected; - } else { - return; - } - if (!connected) { - sessionReady = false; - fixedLayoutCreated = false; - startupProbePending = false; - chargingMode = false; - audioCaptureActive = false; - audioPacketListener = null; - clearAllMessagesLocked("connection lost"); - displayedFingerprint = ""; - if (!reconnectHalted) { - reconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RECONNECT_DELAY_MS; - } - } - } - interruptibleSleep.interrupt(); - if (connected) { - setStateDisplay("connected", "Connected."); - } else if (!reconnectHalted) { - // While parked on a missing bond, keep the "unpaired" display: this - // callback is just the teardown of the arm that did connect. - setStateDisplay("connecting", "Connecting to the glasses..."); - } - } - - private void connectLoopOnce() throws InterruptedException { - setStateDisplay("connecting", "Connecting to the glasses..."); - try { - connectArm(rightAddress, true); - connectArm(leftAddress, true); - if (!sleepDuringConnectSettling(800)) { - return; - } - authenticateArms(); - sendPrelude(); - - synchronized (lock) { - sessionReady = true; - // A fresh transport prelude always starts an active EvenHub - // lifecycle, even if the previous connection dropped while - // its page was intentionally suspended. - shutdownRequested = false; - fixedLayoutCreated = false; - clearAllMessagesLocked("session ready"); - displayedFingerprint = ""; - lastAckAtMs = SystemClock.elapsedRealtime(); - lastIncomingAtMs = lastAckAtMs; - lastConnectionOrInputAtMs = lastAckAtMs; - lastSessionReadyAtMs = lastAckAtMs; - lastBatteryRefreshAtMs = 0; - imageRetryAfterMs = 0; - lastHeartbeatSentAtMs = 0; - lastHeartbeatAckedAtMs = 0; - consecutiveAckTimeouts = 0; - lastAudioControlAckMagic = 0; - audioCaptureActive = false; - faceclawWakePendingNonce = -1; - cfwCleanupDelivered = false; - for (CfwTransport transport : cfwTransports) transport.reset(); - lastCfwCleanupAckMagic = 0; - lastFaceclawWakeLeaseQueuedAtMs = 0; - lastFaceclawFramebufferLeaseQueuedAtMs = 0; - enqueueFaceclawFramebufferControlLocked( - BleProtocol.FACECLAW_FB_OP_ACQUIRE, - true - ); - if (faceclawWakeLeaseEnabled) { - enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, - 0, - true - ); - } - } - setStateDisplay("connected", "Connected."); - logLine("session ready"); - synchronized (lock) { - // Query settings promptly on the first session so firmware - // version/extension (and battery) arrive without waiting for - // the input-quiet battery poll. The settings response doubles as - // the firmware-compatibility check surfaced during onboarding. - if (!firmwareInfoQueried) { - firmwareInfoQueried = true; - lastBatteryRefreshAtMs = SystemClock.elapsedRealtime(); - pendingMessages.addLast(createBatteryQueryMessageLocked()); - logLine("queue settings query for firmware info"); - } - } - tryConnectRing("initial"); - } catch (Throwable t) { - logLine("connect failed: " + safeMessage(t)); - String unpairedArm = firstUnpairedArm(); - if (unpairedArm != null) { - handleUnpairedFailure(unpairedArm); - } else { - handleTransportFailure("connect failed"); - } - } - } - - private boolean sleepDuringConnectSettling(long delayMs) throws InterruptedException { - long deadline = SystemClock.elapsedRealtime() + delayMs; - synchronized (lock) { - while (running && !userDisconnectRequested) { - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - return true; - } - lock.wait(Math.min(remaining, 100)); - } - return false; - } - } - - private void connectArm(String address, boolean enableRenderNotify) { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw new IllegalStateException("connect failed: " + address); - } - // requestConnectionPriority has no callback in this Android compile target, so there is - // no reliable completion point to keep it in the global GATT operation pipeline. But it's - // important enough for performance that we call it anyways. - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH); - - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS); - - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw new IllegalStateException("discoverServices failed: " + address); - } - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - throw new IllegalStateException("enableNotifications failed: " + address + " " + BleProtocol.NOTIFY_CHAR_UUID); - } - if (enableRenderNotify) { - bleManager.enableNotifications(address, BleProtocol.RENDER_NOTIFY_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS); - } - synchronized (lock) { - if (address.equalsIgnoreCase(rightAddress)) { - rightConnected = true; - } else if (address.equalsIgnoreCase(leftAddress)) { - leftConnected = true; - } - } - } - - private boolean shouldAttemptRingConnect() { - if (!hasRingAddress()) { - return false; - } - long now = SystemClock.elapsedRealtime(); - synchronized (lock) { - return running - && sessionReady - && !ringNotificationsReady - && now >= ringReconnectAfterMs - && pendingMessages.isEmpty() - && inFlightMessages.isEmpty(); - } - } - - private void tryConnectRing(String reason) { - if (!hasRingAddress()) { - return; - } - try { - connectRing(); - } catch (Throwable t) { - synchronized (lock) { - ringConnected = false; - ringNotificationsReady = false; - ringReconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RING_RECONNECT_DELAY_MS; - } - logLine("direct ring connect failed (" + reason + "): " + safeMessage(t)); - } - } - - private void connectRing() { - logLine("connecting direct ring " + ringAddress); - if (!bleManager.connect(ringAddress, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw new IllegalStateException("connect failed: " + ringAddress); - } - - bleManager.requestConnectionPriority(ringAddress, BluetoothGatt.CONNECTION_PRIORITY_HIGH); - bleManager.requestMtu(ringAddress, ConnectionOptions.RING_DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS); - - if (!bleManager.discoverServices(ringAddress, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw new IllegalStateException("discoverServices failed: " + ringAddress); - } - - boolean phoneNotify = enableRingNotification(BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID); - boolean dataNotify = enableRingNotification(BleProtocol.R1_NOTIFY_CHAR_UUID); - if (!phoneNotify && !dataNotify) { - throw new IllegalStateException("no R1 notify characteristic subscribed"); - } - - synchronized (lock) { - ringConnected = true; - ringNotificationsReady = true; - ringReconnectAfterMs = 0; - } - logLine("direct ring ready phoneNotify=" + phoneNotify + " dataNotify=" + dataNotify); - } - - private boolean enableRingNotification(String characteristicUuid) { - try { - return bleManager.enableNotifications( - ringAddress, - characteristicUuid, - true, - ConnectionOptions.DESCRIPTOR_TIMEOUT_MS - ); - } catch (Throwable t) { - Log.d(TAG, "direct ring notify subscribe skipped: " + characteristicUuid + " " + safeMessage(t)); - return false; - } - } - - /** - * Complete the sid-0x80 security-auth exchange on both freshly opened arm - * connections. Firmware 2.2.9 answers no queries until it completes over an - * encrypted link and closes unauthenticated links after ~30 s (see - * ../notes/ble-connections-2.2.9.md); on an unbonded phone the exchange is - * also what triggers SMP pairing. Deliberately soft: on timeout we log and - * continue rather than fail the connect — the custom firmware's response - * behavior is not yet hardware-verified, and on stock firmware an - * unanswered auth just means the prelude fails exactly as it did before. - * A pairing prompt accepted after our window still bonds at the OS level, - * so the next reconnect attempt authenticates promptly. - */ - private void authenticateArms() throws InterruptedException { - OutboundMessage right = messageBuilder.securityAuth(false); - OutboundMessage left = messageBuilder.securityAuth(true); - long now = SystemClock.elapsedRealtime(); - for (OutboundMessage message : new OutboundMessage[] {right, left}) { - message.onAck = () -> { - }; - message.onTimeout = () -> { - }; - message.sentAtMs = now; - writeMessage(message); - } - long deadline = SystemClock.elapsedRealtime() + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS; - while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { - synchronized (lock) { - if (!running || userDisconnectRequested || inFlightMessages.isEmpty()) { - break; - } - } - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - interruptibleSleep.sleep(Math.min(remaining, 100)); - } - synchronized (lock) { - if (!inFlightMessages.isEmpty()) { - clearInFlightMessagesLocked("security auth timeout"); - logLine("security auth not acknowledged; continuing (2.2.9 stock requires it; older/custom firmware may not answer)"); - return; - } - } - boolean rightOk = BleProtocol.isAuthenticationSuccess(right.ackPayload, right.magic); - boolean leftOk = BleProtocol.isAuthenticationSuccess(left.ackPayload, left.magic); - logLine("security auth R=" + (rightOk ? "ok" : "unconfirmed") + " L=" + (leftOk ? "ok" : "unconfirmed")); - } - - private void sendPrelude() throws InterruptedException { - sendPrelude(false); - } - - private void sendPrelude(boolean preserveWakeLeaseControls) throws InterruptedException { - synchronized (lock) { - if (preserveWakeLeaseControls) { - clearAllMessagesPreservingWakeLeaseLocked("prelude"); - } else { - clearAllMessagesLocked("prelude"); - } - } - long now = SystemClock.elapsedRealtime(); - OutboundMessage prelude = messageBuilder.prelude(); - prelude.onAck = () -> { - }; - prelude.onTimeout = () -> { - handleTransportFailure("ack timeout"); - }; - prelude.sentAtMs = now; - writeMessage(prelude); - - long deadline = SystemClock.elapsedRealtime() + ConnectionOptions.PRELUDE_TIMEOUT_MS; - while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { - synchronized (lock) { - if (!running || userDisconnectRequested || inFlightMessages.isEmpty()) { - break; - } - } - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - interruptibleSleep.sleep(Math.min(remaining, 100)); - } - synchronized (lock) { - if (!inFlightMessages.isEmpty()) { - clearInFlightMessagesLocked("prelude timeout"); - throw new IllegalStateException("prelude ack timeout"); - } - } - } - - private long driveSession() { - //Log.d(TAG, "driveSession called (pendingMessages.size=" + pendingMessages.size() + " inFlightMessages.size=" + inFlightMessages.size() + ")"); - while (true) { - // Run on the sender thread, outside `lock`: Bluetooth API calls can - // wait on the global GATT lock, and callbacks need the session lock. - // Keep negotiation outside the timed stream. A fixed settling period - // is only an experiment boundary; HCI must confirm actual parameters. - int linkMode = -1; - String[] benchmarkAddresses = null; - synchronized (lock) { - if (benchmarkActive && benchmarkLinkPending) { - benchmarkLinkPending = false; - linkMode = benchmarkLinkMode; - benchmarkAddresses = new String[] {leftAddress, rightAddress}; - } - } - if (benchmarkAddresses != null) { - for (String address : benchmarkAddresses) { - try { - bleManager.prepareBenchmarkLink(address, linkMode); - } catch (RuntimeException error) { - logLine("benchmark link request failed: " + safeMessage(error)); - } - } - synchronized (lock) { - // Cancellation/new-run races leave the new run pending; its - // own preparation will replace this deadline before sending. - benchmarkReadyAtMs = SystemClock.elapsedRealtime() + 1_000; - } - } - OutboundMessage messageToWrite = null; - OutboundMessage messageToPrewrite = null; - long now = SystemClock.elapsedRealtime(); - - maybeFinishNoChangeDesiredFrame(); - - synchronized (lock) { - drainCfwAcknowledgementsLocked(); - if (cfwCleanupDelivered) { - /* Successful mode 11 must be the last Faceclaw write. Drop - * anything a late external producer attempted to enqueue - * while DashboardController was closing the transport. */ - clearPendingMessagesLocked("after CFW cleanup"); - return 250; - } - if (sessionReady - && now - lastFaceclawFramebufferLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS - && !hasPendingOrInflightKindLocked("framebuffer-lease-control")) { - enqueueFaceclawFramebufferControlLocked( - BleProtocol.FACECLAW_FB_OP_ACQUIRE, - false - ); - } - if (faceclawWakeLeaseEnabled - && sessionReady - && now - lastFaceclawWakeLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS - && !hasPendingOrInflightKindLocked("wake-lease-control")) { - enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, - 0, - false - ); - } - if (!inFlightMessages.isEmpty()) { - OutboundMessage oldest = inFlightMessages.peekFirst(); - List replay = CfwMessageWindow.replayWindow(inFlightMessages, now); - if (!replay.isEmpty()) { - logLine("CFW recovery: replay " + replay.size() - + " unresolved message(s) from id=" + replay.get(0).magic); - for (OutboundMessage candidate : replay) { - if (candidate.cfwRetries >= CfwMessageWindow.MAX_RETRIES) { - handleTransportFailure("CFW recovery retry limit"); - return 0; - } - logLine("CFW replay id=" + candidate.magic + " label=" + candidate.label - + " cause=" + (candidate.cfwRetryPending ? "NACK" - : candidate.cfwAckLenses == CfwTransport.BOTH ? "ordered tail" : "missing ACK") - + " ackedLenses=" + candidate.cfwAckLenses - + " ageMs=" + (now - candidate.sentAtMs)); - inFlightMessages.remove(candidate); - magicPool.release(candidate.sid, candidate.magic, candidate.label, "CFW replay"); - candidate.prepareCfwReplay(magicPool.allocate()); - } - for (int i = replay.size() - 1; i >= 0; --i) pendingMessages.addFirst(replay.get(i)); - return 0; - } - if (oldest != null && oldest.ackDeadlineAtMs <= now) { - Log.i(TAG, "message timed out: " + oldest.label); - inFlightMessages.removeFirst(); - logLine("message timed out: " + oldest.label + " sid=" + oldest.sid - + " id=" + oldest.magic + " ackedLenses=" + oldest.cfwAckLenses - + " ageMs=" + (now - oldest.sentAtMs)); - magicPool.release(oldest.sid, oldest.magic, oldest.label, "timeout"); - if (oldest.sid == CfwTransport.SID) - cfwTransports[oldest.isLeftArmMessage ? 0 : 1].reset(); - handleAckTimeoutLocked(oldest); - return 0; - } - if (connectionOptions.WINDOW_SIZE <= 1 - && sessionReady - && prewrittenMessage == null - && !pendingMessages.isEmpty() - && canPrewriteCandidate(pendingMessages.peekFirst()) - && !shouldBlockPrewriteForHeartbeatLocked(now)) { - // Only the serial (window==1) path pre-sends the all-but-last - // packet; with a real window we just send the next message fully. - messageToPrewrite = pendingMessages.peekFirst(); - } - } - - if (chargingMode) { - // Glasses are in the case: no display traffic, only battery - // polls (which also detect the end of charging). - finishDesiredFrameLocked("discarded: glasses charging"); - if (sessionReady && inFlightMessages.isEmpty() && !pendingMessages.isEmpty()) { - messageToWrite = pendingMessages.removeFirst(); - Log.i(TAG, "sending pending message (charging): " + messageToWrite.label); - } else if (sessionReady && pendingMessages.isEmpty() && inFlightMessages.isEmpty() - && now - lastBatteryRefreshAtMs >= ConnectionOptions.CHARGING_BATTERY_POLL_MS) { - Log.i(TAG, "Writing charging-mode battery poll"); - messageToWrite = createBatteryQueryMessageLocked(); - lastBatteryRefreshAtMs = now; - } else { - return 1_000; - } - } else { - if (messageToPrewrite == null - && !shutdownRequested - && !fixedLayoutCreated - && pendingMessages.isEmpty() - && inFlightMessages.isEmpty()) { - Log.i(TAG, "enqueueing create layout"); - enqueueCreateLayoutLocked(); - } else if (messageToPrewrite != null) { - // Prewrite outside the lock; the logical message remains pending until - // its final BLE frame is sent after the current protocol ACK. - } - if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated - && (firmwareDebugFlagsEnabled ? 2 : 1) != firmwareDebugFlagsLastSent - && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { - Log.i(TAG, "enqueueing firmware debug flags " + (firmwareDebugFlagsEnabled ? "show" : "hide")); - enqueueFirmwareDebugFlagsLocked(); - } - - if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated - && (compassOwners.isEmpty() ? 0 : 1) != compassControlLastSent - && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { - boolean wanted = !compassOwners.isEmpty(); - Log.i(TAG, "enqueueing compass " + (wanted ? "enable" : "disable")); - enqueueCompassControlLocked(false, wanted); - } - - if (benchmarkActive) { - maintainBenchmarkLocked(now); - } - - // Up to WINDOW_SIZE messages may be in flight at once (full - // pipelining); a slot frees when an ack arrives. An active - // bandwidth benchmark measures its own selected window instead. - boolean windowHasRoom = inFlightMessages.size() - < Math.max(1, benchmarkActive ? benchmarkWindowSize : connectionOptions.WINDOW_SIZE); - // A frame ready to send right now: don't inject a fresh - // heartbeat in front of it (the image's own ack resets the - // firmware heartbeat timer, so the heartbeat is redundant). - // "Ready" covers both a fresh composite still to be planned - // and a planned image already queued but not yet written -- - // enqueueing sets lastEnqueuedFingerprint, so testing only - // the desired fingerprint left the queued-but-unwritten - // window unprotected and a heartbeat that came due there - // cost the frame a full ack round trip (measured 124ms on - // frame#232 of the 2026-08-20 02:27 capture). - // A benchmark run counts as image traffic here for the same - // reason: its acks reset the firmware heartbeat timer, so a - // fresh heartbeat in front of it is redundant. - boolean imageWaiting = !shutdownRequested && fixedLayoutCreated - && !hasPendingOrInflightKindLocked("heartbeat") - && (benchmarkActive - || (now >= imageRetryAfterMs - && (hasPendingImageLocked() - || !getDesiredFingerprint().equals(lastEnqueuedFingerprint)))); - noteImageStallLocked(now, windowHasRoom); - if (messageToPrewrite == null && handleHeartbeat(imageWaiting)) { - return ConnectionOptions.IDLE_SLEEP_MS; - } - - if (messageToPrewrite == null && sessionReady && windowHasRoom && !pendingMessages.isEmpty() - && CfwMessageWindow.canSend(inFlightMessages, pendingMessages.peekFirst())) { - messageToWrite = pendingMessages.removeFirst(); - Log.i(TAG, "sending pending message: " + messageToWrite.label); - } else if (messageToPrewrite == null && !shutdownRequested && !benchmarkActive - && fixedLayoutCreated - && windowHasRoom && !hasPendingImageLocked() - && now >= imageRetryAfterMs - && !getDesiredFingerprint().equals(lastEnqueuedFingerprint)) { - // Enqueue the next frame's delta against lastEnqueuedPacked - // (what the shadow will be), so it can pipeline behind an - // image still awaiting its ack. - Log.i(TAG, "Enqueued image update"); - enqueueDesiredImageLocked(); - return 0; - } else if (messageToPrewrite == null && shouldPollBatteryLocked(now)) { - Log.i(TAG, "Writing battery query"); - messageToWrite = createBatteryQueryMessageLocked(); - lastBatteryRefreshAtMs = now; - } else if (messageToPrewrite == null && (!pendingMessages.isEmpty() || !inFlightMessages.isEmpty())) { - return ConnectionOptions.IDLE_SLEEP_MS; - } else if (messageToPrewrite == null) { - return 250; - } - } - } - - if (messageToPrewrite != null) { - if (prewriteMessage(messageToPrewrite)) { - return 0; - } - return ConnectionOptions.IDLE_SLEEP_MS; - } - - if (!writeMessage(messageToWrite)) { - synchronized (lock) { - if (removePreparedMessageLocked(messageToWrite) || messageToWrite.magic == 0) { - handleTransportFailure("write failed"); - } - } - return 0; - } - } - } - - /** - * If the desired image already matches what the glasses display, nothing will - * ever be enqueued for it, so finish its frame now (otherwise the TS side - * would block on it until its backpressure timeout). - */ - private void maybeFinishNoChangeDesiredFrame() { - int frameIdToFinish = 0; - synchronized (lock) { - synchronized (desiredTilesLock) { - if (desiredFrameId != 0 && !lastEnqueuedFingerprint.isEmpty() && desiredFingerprint.equals(lastEnqueuedFingerprint)) { - frameIdToFinish = desiredFrameId; - desiredFrameId = 0; - } - } - } - if (frameIdToFinish != 0) { - finishFrame(frameIdToFinish, "discarded: no change from displayed image"); - } - } - - private boolean shouldBlockPrewriteForHeartbeatLocked(long now) { - if (shutdownRequested || !fixedLayoutCreated) { - return false; - } - return hasPendingOrInflightKindLocked("heartbeat") - || now - lastHeartbeatAckedAtMs >= ConnectionOptions.HEARTBEAT_READY_MS; - } - - private boolean canPrewriteCandidate(OutboundMessage message) { - if (message == null || message.sid == CfwTransport.SID || !message.isLeftArmMessage) { - return false; - } - if (!"image".equals(message.kind)) { - return false; - } - return message.message.length + 2 > 232; - } - - private boolean handleHeartbeat(boolean imageWaiting) { - long now = SystemClock.elapsedRealtime(); - boolean heartbeatEligible = !shutdownRequested && fixedLayoutCreated; - boolean heartbeatPending = heartbeatEligible && hasPendingOrInflightKindLocked("heartbeat"); - long heartbeatElapsedMs = now - lastHeartbeatAckedAtMs; - boolean heartbeatReady = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS; - boolean heartbeatUrgent = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_URGENT_MS; - boolean heartbeatBlocksLeftWrites = heartbeatReady || heartbeatPending; - - if (heartbeatReady && !heartbeatPending && inFlightMessages.isEmpty()) { - if (imageWaiting && !heartbeatUrgent) { - // Defer to the waiting frame: sending it now satisfies the - // firmware heartbeat deadline (its ack resets the timer), and - // the heartbeat still fires once we reach the URGENT threshold - // if rendering goes quiet again. Preserves the pending-heartbeat - // inter-lens-sync invariant below (that path is untouched). - return false; - } - Log.i(TAG, "Writing heartbeat"); - OutboundMessage heartbeatMessage = createHeartbeatMessage(); - lastHeartbeatSentAtMs = now; - writeMessage(heartbeatMessage); - return true; - } else if (heartbeatUrgent) { - return true; - } else if (heartbeatPending) { - // Don't send other message types while a heartbeat is pending because that - // can lead to inter-lens sync issues - return true; - } - - return false; - } - - private OutboundMessage createHeartbeatMessage() { - OutboundMessage message = messageBuilder.heartbeat(); - message.onAck = () -> { - synchronized (lock) { - lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime(); - } - }; - message.onTimeout = () -> { - // If a heartbeat fails to ack and we're over the heartbeat deadline, assume the connection is failed and reconnect. - // Otherwise ignore it, which will cause a retransmission attempt. - boolean isPastDeadline; - synchronized (lock) { - isPastDeadline = SystemClock.elapsedRealtime() - lastHeartbeatSentAtMs >= ConnectionOptions.HEARTBEAT_FAILURE_DEADLINE_MS; - } - if (isPastDeadline) { - handleTransportFailure("heartbeat ack timeout"); - } - }; - return message; - } - - - private boolean writeMessage(OutboundMessage message) { - long now = SystemClock.elapsedRealtime(); - message.writeStartedAtMs = now; - message.sentAtMs = now; - message.ackDeadlineAtMs = now + message.ackTimeoutMs + ConnectionOptions.WRITE_TIMEOUT_MS; - if (message.magic != 0) { - synchronized (lock) { - inFlightMessages.addLast(message); - } - } - if (message.imageUpdateId > 0 && message.imageMessageNumber == 1) { - synchronized(lock) { - BleImageOptimizer.ImageUpdateStats stats = imageUpdateStats.get(message.imageUpdateId); - if (stats != null && stats.firstWriteStartedAtMs <= 0) { - stats.firstWriteStartedAtMs = now; - } - } - } - - String writeAddress = message.isLeftArmMessage ? leftAddress : rightAddress; - List frames; - if (prewrittenMessage != null && prewrittenMessage != message) { - if (!spoilPrewrittenMessage("before " + message.label)) { - return false; - } - } - if (prewrittenMessage == message) { - frames = Collections.singletonList(prewrittenFrames.get(prewrittenFrames.size() - 1)); - prewrittenMessage = null; - prewrittenFrames = Collections.emptyList(); - } else if (message.sid == CfwTransport.SID) { - if (message.cfwRetries > 0) cfwTransports[message.isLeftArmMessage ? 0 : 1].reset(); - frames = cfwTransports[message.isLeftArmMessage ? 0 : 1].encode( - message.message, message.magic, CfwTransport.BOTH, - bleManager.getNegotiatedMtu(writeAddress)); - } else { - frames = BleProtocol.framePb( - message.message, - message.sid, - message.flag, - nextTransportSeq++ - ); - } - boolean result = bleManager.writeFrames( - writeAddress, - BleProtocol.WRITE_CHAR_UUID, - frames, - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS - ); - - synchronized (lock) { - long sentAtMs = SystemClock.elapsedRealtime(); - message.sentAtMs = sentAtMs; - message.ackDeadlineAtMs = sentAtMs + message.ackTimeoutMs; - logImageUpdateSendLandmarkLocked(message); - if (result && message.onSent != null) { - message.onSent.run(); - lock.notifyAll(); - } - } - - if (!result && message.sid == CfwTransport.SID) - cfwTransports[message.isLeftArmMessage ? 0 : 1].reset(); - return result; - } - - private boolean prewriteMessage(OutboundMessage message) { - if (prewrittenMessage == message) { - return true; - } - if (prewrittenMessage != null && !spoilPrewrittenMessage("before prewrite " + message.label)) { - return false; - } - if (!canPrewriteCandidate(message)) { - return false; - } - - List frames = BleProtocol.framePb( - message.message, - message.sid, - message.flag, - nextTransportSeq++ - ); - if (frames.size() <= 1) { - return false; - } - - String writeAddress = message.isLeftArmMessage ? leftAddress : rightAddress; - List prefixFrames = frames.subList(0, frames.size() - 1); - boolean result = bleManager.writeFrames( - writeAddress, - BleProtocol.WRITE_CHAR_UUID, - prefixFrames, - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS - ); - if (!result) { - return false; - } - - prewrittenMessage = message; - prewrittenFrames = new ArrayList<>(frames); - logLine("prewrote " + message.label + " frames=" + prefixFrames.size() + "/" + frames.size()); - return true; - } - - private boolean spoilPrewrittenMessage(String reason) { - if (prewrittenMessage == null || prewrittenFrames.isEmpty()) { - prewrittenMessage = null; - prewrittenFrames = Collections.emptyList(); - return true; - } - OutboundMessage message = prewrittenMessage; - byte[] finalFrame = Arrays.copyOf( - prewrittenFrames.get(prewrittenFrames.size() - 1), - prewrittenFrames.get(prewrittenFrames.size() - 1).length - ); - if (finalFrame.length > 8) { - finalFrame[finalFrame.length - 1] ^= (byte) 0xff; - } - prewrittenMessage = null; - prewrittenFrames = Collections.emptyList(); - - String writeAddress = message.isLeftArmMessage ? leftAddress : rightAddress; - logLine("spoiling prewritten " + message.label + ": " + reason); - return bleManager.writeFrames( - writeAddress, - BleProtocol.WRITE_CHAR_UUID, - Collections.singletonList(finalFrame), - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS - ); - } - - private boolean removePreparedMessageLocked(OutboundMessage message) { - if (message == null || message.magic == 0) { - return false; - } - Iterator iterator = inFlightMessages.iterator(); - while (iterator.hasNext()) { - if (iterator.next() == message) { - iterator.remove(); - magicPool.release(message.sid, message.magic, message.label, "write failed"); - return true; - } - } - return false; - } - - - /** Also drain on the worker: a clear/timeout may have removed a blocking - * head since the last notification. Fully ACKed controls must never reach - * the generic timeout path just because no further BLE reply arrived. */ - private void drainCfwAcknowledgementsLocked() { - while (true) { - OutboundMessage first = CfwMessageWindow.acknowledgedHead(inFlightMessages); - if (first == null) return; - lastAckAtMs = SystemClock.elapsedRealtime(); - resolveAckLocked(first, first.ackPayload); - } - } - - private void resolveAckLocked(int sid, int magic, byte[] pb) { - Iterator iterator = inFlightMessages.iterator(); - while (iterator.hasNext()) { - OutboundMessage message = iterator.next(); - if (message.sid == sid && message.magic == magic) { - resolveAckLocked(message, pb); - return; - } - } - recordUnexpectedAckLocked(sid, magic); - } - - private void resolveAckLocked(OutboundMessage message, byte[] pb) { - Log.i(TAG, "Got ACK for " + message.label + "(sid=" + message.sid + ", id=" + message.magic + ")"); - inFlightMessages.remove(message); - message.ackPayload = pb == null ? new byte[0] : Arrays.copyOf(pb, pb.length); - magicPool.release(message.sid, message.magic, message.label, "ack"); - if (message.onAck != null) { - message.onAck.run(); - } - consecutiveAckTimeouts = 0; - // onAck may have just satisfied a waiter blocked on lock.wait() (e.g. - // awaitEvenHubSessionReady polling fixedLayoutCreated/displayedFingerprint - // after a create-layout or image ack). Without this, that waiter only - // notices on its own up-to-100ms poll tick, adding avoidable latency to - // every EvenHub wake. Always called with lock held (see call site). - lock.notifyAll(); - } - - private void logImageUpdateSendLandmarkLocked(OutboundMessage message) { - if (message.imageUpdateId <= 0) { - return; - } - BleImageOptimizer.ImageUpdateStats stats = imageUpdateStats.get(message.imageUpdateId); - int frameId = stats == null ? 0 : stats.frameId; - if (message.imageMessageNumber == 1) { - if (stats != null && stats.firstWriteStartedAtMs <= 0) { - stats.firstWriteStartedAtMs = message.writeStartedAtMs > 0 ? message.writeStartedAtMs : message.sentAtMs; - } - FrameTimings.getInstance().log(frameId, "first bluetooth packet sent"); - logImageUpdateLandmarkLocked("first bluetooth message sent", message, message.sentAtMs); - } - if (message.imageMessageNumber == message.imageMessageCount) { - FrameTimings.getInstance().log(frameId, - "last bluetooth packet sent (message " + message.imageMessageNumber + "/" + message.imageMessageCount + ")"); - logImageUpdateLandmarkLocked("last bluetooth message sent", message, message.sentAtMs); - } - } - - private void logImageUpdateAckLandmarkLocked(OutboundMessage message) { - if (message.imageUpdateId <= 0 || message.imageMessageNumber != message.imageMessageCount) { - return; - } - long ackedAtMs = SystemClock.elapsedRealtime(); - FaceclawBleManager.recordDisplayFrameSent(); - BleImageOptimizer.ImageUpdateStats stats = imageUpdateStats.remove(message.imageUpdateId); - if (stats != null && stats.firstWriteStartedAtMs > 0) { - emitFrameMetrics(stats.paintMs, (int) Math.max(0, ackedAtMs - stats.firstWriteStartedAtMs), stats.tileCount); - } - if (stats != null) { - finishFrame(stats.frameId, "sent"); - } - logImageUpdateLandmarkLocked("last bluetooth message acked", message, ackedAtMs); - } - - /** Remove the stats entry for an image update that will not complete, finishing its frame. */ - private void discardImageUpdateStatsLocked(int imageUpdateId, String reason) { - if (imageUpdateId <= 0) { - return; - } - BleImageOptimizer.ImageUpdateStats stats = imageUpdateStats.remove(imageUpdateId); - if (stats != null) { - finishFrame(stats.frameId, "discarded: " + reason); - } - } - - private void logImageUpdateLandmarkLocked(String event, OutboundMessage message, long elapsedMs) { - logLine("image update#" + message.imageUpdateId + " " + event - + " at " + timestamp(elapsedMs) - + " message=" + message.imageMessageNumber + "/" + message.imageMessageCount - + " label=" + message.label); - } - - private void enqueueCreateLayoutLocked() { - // New session: re-assert the firmware-debug-flags overlay once - // the layout is ready (the mode-7 send is gated on this having reset). - firmwareDebugFlagsLastSent = -1; - OutboundMessage message = messageBuilder.createLayout(); - message.onAck = () -> { - startupProbePending = false; - clearMessagesOfKindLocked("startup-text-probe"); - fixedLayoutCreated = true; - displayedFingerprint = ""; - }; - message.onTimeout = () -> { - if (startupProbePending) { - logLine("create layout timed out while startup text probe is pending"); - if (hasPendingOrInflightKindLocked("startup-text-probe")) { - return; - } - startupProbePending = false; - } - handleTransportFailure("ack timeout"); - }; - pendingMessages.addLast(message); - logLine("queue create layout"); - } - - private void enqueueStartupProbeLocked() { - enqueueCreateLayoutLocked(); - - OutboundMessage message = messageBuilder.startupTextProbe(); - message.onAck = () -> { - startupProbePending = false; - clearMessagesOfKindLocked("create-layout"); - fixedLayoutCreated = true; - displayedFingerprint = ""; - logLine("existing dashboard layout accepted text probe"); - }; - message.onTimeout = () -> { - startupProbePending = false; - if (hasPendingOrInflightKindLocked("create-layout")) { - return; - } - handleTransportFailure("ack timeout"); - }; - pendingMessages.addLast(message); - startupProbePending = true; - logLine("queue startup text probe"); - } - - /** - * Send the CFW mode-7 diagnostic-flag control op through the private stream: - * [7][2] to show the on-glasses debug-flag overlay, [7][1] to hide it. Uses the - * arbitrary-payload custom path (no bmp/dedup/frame-timing interaction). - */ - private void enqueueFirmwareDebugFlagsLocked() { - boolean show = firmwareDebugFlagsEnabled; - int sub = show ? 2 : 1; - byte[] payload = new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_DIAGNOSTICS, (byte) sub }; - OutboundMessage message = messageBuilder.imagePayload( - DASHBOARD_TILE, nextMapSessionId(), payload, - "fw-debug-flags " + (show ? "show" : "hide"), - connectionOptions.sendImagesToLeft); - pendingMessages.addLast(message); - firmwareDebugFlagsLastSent = sub; - logLine("queue firmware debug flags " + (show ? "show" : "hide")); - } - - /** - * Send CFW image-handler mode 10. Enable uses the configurable form - * [10][2][interval-ms LE16][minimum-change-degrees LE16]; disable remains [10][0]. - */ - private void enqueueCompassControlLocked(boolean priority, boolean enable) { - int sentState = enable ? 1 : 0; - byte[] payload = enable - ? new byte[] { - (byte) CfwMessageTypeKt.CFW_MSG_COMPASS, - (byte) 2, - (byte) (COMPASS_REPORT_INTERVAL_MS & 0xff), - (byte) ((COMPASS_REPORT_INTERVAL_MS >> 8) & 0xff), - (byte) (COMPASS_MIN_CHANGE_DEGREES & 0xff), - (byte) ((COMPASS_MIN_CHANGE_DEGREES >> 8) & 0xff), - } - : new byte[] { (byte) CfwMessageTypeKt.CFW_MSG_COMPASS, (byte) 0 }; - OutboundMessage message = messageBuilder.imagePayload( - "compass-control", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - "compass " + (enable ? "enable" : "disable"), - connectionOptions.sendImagesToLeft); - message.onTimeout = () -> { - compassControlLastSent = -1; - logLine("compass control ack timeout"); - }; - if (enable) { - compassMaybeOn = true; - } else { - message.onAck = () -> compassMaybeOn = false; - } - if (priority) pendingMessages.addFirst(message); - else pendingMessages.addLast(message); - compassControlLastSent = sentState; - logLine("queue " + message.label); - } - - private void enqueueDesiredImageLocked() { - String fingerprint = getDesiredFingerprint(); - byte[] packed; - int width; - int height; - int paintMs; - int frameId; - SurfaceCompositor.ScreenDraw[] draws; - ShellScene scene; - synchronized (desiredTilesLock) { - packed = desiredPacked; - width = desiredWidth; - height = desiredHeight; - paintMs = desiredPaintMs; - frameId = desiredFrameId; - draws = desiredDraws; - scene = desiredShellScene; - desiredFrameId = 0; - } - if (packed == null) { - packed = new byte[0]; - } - if (customFirmwareDetected && packed.length > 0) { - ScenePlanner.Plan rendered = scenePlanner.plan(packed, width, height, draws, scene, nextImageFrameId, - connectionOptions.TEXTURE_CACHE_FRAMES, connectionOptions.INCREMENTAL_FRAMES, - connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS); - nextImageFrameId = rendered.getNextFid(); - List commands = rendered.getCommands(); - for (int i = 0; i < commands.size() - 1; i++) enqueueResourceCommandLocked(commands.get(i)); - BleImageOptimizer.TileImagePlan plan = new BleImageOptimizer.TileImagePlan( - 0, DASHBOARD_TILE, packed, width, height, nextMapSessionId(), commands.get(commands.size() - 1)); - finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId); - return; - } - - FrameTimings.getInstance().spanStart(frameId, "compress-and-plan"); - // Incremental (mode 3 bounding box) update against the last ENQUEUED frame - // (the base the firmware shadow will hold when this update is applied). - // lastEnqueuedPacked is cleared whenever the image pipeline is cleared, so - // a non-empty value means the display base is trusted. - byte[] incrementalPayload = null; - String incrementalLog = null; - if (connectionOptions.INCREMENTAL_FRAMES && lastEnqueuedPacked.length > 0 - && lastEnqueuedWidth == width && lastEnqueuedHeight == height) { - int baseFid = nextImageFrameId; - BleImageOptimizer.IncrementalPlan single = - BleImageOptimizer.buildIncrementalImagePayload(lastEnqueuedPacked, packed, width, height, baseFid); - if (single != null) { - incrementalPayload = single.payload; - // advance only when a delta is actually emitted, so consecutive - // deltas carry consecutive ids (CFW skip/reorder detection) - nextImageFrameId = nextImageFrameId >= 0xfffe ? 1 : nextImageFrameId + 1; - incrementalLog = "incremental update bbox=" - + ((single.payload[3] & 0xff) * 4) + "x" + ((single.payload[4] & 0xff) * 2) - + "+" + ((single.payload[1] & 0xff) * 4) + "+" + ((single.payload[2] & 0xff) * 2) - + " changed=" + single.changedBytes + "/" + single.boxBytes + "B" - + " clusters=" + single.clusterCount; - - // When the bounding box spans multiple clusters or is sizeable, try - // splitting into tight rects (CFW mode-8). Only replace the single - // box if the multi-rect message is actually smaller on the wire. - if (connectionOptions.MULTI_RECT_FRAMES - && (single.clusterCount > 1 || single.payload.length > ConnectionOptions.MULTI_RECT_MIN_PAYLOAD)) { - BleImageOptimizer.MultiRectPlan multi = BleImageOptimizer.buildMultiRectImagePayload( - lastEnqueuedPacked, packed, width, height, baseFid, ConnectionOptions.MULTI_RECT_MAX_RECTS); - if (multi != null && multi.payload.length < single.payload.length) { - incrementalPayload = multi.payload; - nextImageFrameId = multi.nextFid; // rectCount fids consumed - incrementalLog = "multi-rect update n=" + multi.rectCount - + " covered=" + multi.coveredBytes + "B" - + " payload=" + multi.payload.length + "B (vs bbox " + single.payload.length + "B)"; - } - } - } - } - BleImageOptimizer.TileImagePlan plan = incrementalPayload != null - ? new BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packed, width, height, nextMapSessionId(), incrementalPayload) - : new BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packed, width, height, nextMapSessionId()); - FrameTimings.getInstance().spanEnd(frameId, "compress-and-plan"); - if (incrementalLog != null) { - FrameTimings.getInstance().log(frameId, incrementalLog); - } - finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId); - } - - /** Queue complete private commands, advance the delta base, and retain frame/ACK bookkeeping. */ - private void finishEnqueueDesiredImageLocked( - BleImageOptimizer.TileImagePlan plan, String fingerprint, int paintMs, int frameId) { - int updateId = nextImageUpdateId++; - List commands = new ArrayList<>(); - if (plan.payload.length <= CfwTransport.MAX_MESSAGE) { - commands.add(plan.payload); - } else { - // A noisy full frame can exceed the stream record limit. Repaint it - // with independently decodable RLE bands below the decoded-message limit. - commands.addAll(BleImageOptimizer.encodeFullFrameBands( - plan.packed, plan.width, plan.height, nextImageFrameId)); - for (int i = 0; i < commands.size(); i++) { - nextImageFrameId = nextImageFrameId >= 0xfffe ? 1 : nextImageFrameId + 1; - } - } - int messageCount = commands.size(); - imageUpdateStats.put(updateId, new BleImageOptimizer.ImageUpdateStats(paintMs, 1, frameId)); - for (int i = 0; i < commands.size(); i++) { - enqueueCustomImageLocked(plan, commands.get(i), fingerprint, updateId, i + 1, messageCount); - } - // This frame is now the base for the next delta (it will be the firmware - // shadow once applied), even though it hasn't been acked yet — that is what - // lets the next frame pipeline behind it. plan.packed is the full frame; - // frames are immutable by convention, so referencing it is safe. - lastEnqueuedPacked = plan.packed; - lastEnqueuedWidth = plan.width; - lastEnqueuedHeight = plan.height; - lastEnqueuedFingerprint = fingerprint; - - FrameTimings.getInstance().log(frameId, "queued image update#" + updateId - + " messages=" + messageCount + " payload=" + plan.payload.length + "B"); - logLine("queue image update#" + updateId + " fingerprint=" + fingerprint - + " messages=" + messageCount); - } - - /** - * Enqueue one resource eviction/upload command ahead of the image message that - * references its glyphs (the transport is FIFO, so no ack round trip is - * needed before use). A timeout means the on-glasses cache state is - * unknown; forget everything phone-side (glyphs re-upload lazily) and let - * the accompanying image update's own timeout drive the frame resync. - */ - private void enqueueResourceCommandLocked(byte[] payload) { - OutboundMessage message = messageBuilder.imagePayload( - "resources", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - "resource command " + payload.length + "B", - connectionOptions.sendImagesToLeft); - message.onTimeout = () -> { - resourceCache.reset(); - logLine("resource command ack timeout; resource cache state reset"); - }; - pendingMessages.addLast(message); - logLine("queue " + message.label); - } - - private void enqueueCustomImageLocked( - BleImageOptimizer.TileImagePlan plan, - byte[] payload, - String fingerprint, - int updateId, - int messageNumber, - int messageCount - ) { - OutboundMessage message = messageBuilder.customMessage("image", payload, - "image " + plan.tile.name + "#" + messageNumber, plan.tileIndex, connectionOptions.sendImagesToLeft); - message.setImageUpdatePosition(updateId, messageNumber, messageCount); - message.onAck = () -> { - imageRetryAfterMs = 0; - // Firmware >= 2.2.4.34 resets its heartbeat timer when it receives - // image messages (not just heartbeats), so an acked image fragment - // satisfies the heartbeat deadline and heartbeats stop contending - // with active rendering. - lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime(); - logImageUpdateAckLandmarkLocked(message); - boolean imageStillInFlight = false; - for (OutboundMessage inFlight : inFlightMessages) { - if ("image".equals(inFlight.kind)) { - imageStillInFlight = true; - break; - } - } - if (!imageStillInFlight) { - boolean imageStillQueued = false; - for (OutboundMessage queued : pendingMessages) { - if ("image".equals(queued.kind)) { - imageStillQueued = true; - break; - } - } - if (!imageStillQueued) { - displayedFingerprint = fingerprint; - } - } - }; - message.onTimeout = () -> { - discardImageUpdateStatsLocked(message.imageUpdateId, "image ack timeout (will retry)"); - clearMessagesOfKindLocked("image"); - displayedFingerprint = ""; - imageRetryAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.IMAGE_RETRY_DELAY_MS; - }; - pendingMessages.addLast(message); - } - - private OutboundMessage createAudioControlMessageLocked(boolean enable) { - OutboundMessage message = messageBuilder.enableOrDisableMic(enable); - message.onAck = () -> { - lastAudioControlAckMagic = message.magic; - audioCaptureActive = message.label != null && message.label.contains("enable"); - logLine(audioCaptureActive ? "G2 mic enabled" : "G2 mic disabled"); - }; - message.onTimeout = () -> { - handleTransportFailure("audio control ack timeout"); - }; - return message; - } - - private boolean shouldPollBatteryLocked(long now) { - return !shutdownRequested - && sessionReady - && pendingMessages.isEmpty() - && inFlightMessages.isEmpty() - && now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS - && (lastBatteryRefreshAtMs == 0 || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS); - } - - private OutboundMessage createBatteryQueryMessageLocked() { - OutboundMessage message = messageBuilder.batteryQuery(); - message.onAck = () -> { - BleProtocol.RingBatterySnapshot ring = BleProtocol.parseRingBattery(message.ackPayload); - // Old firmware and missing/malformed extensions must clear any prior reading. - ringBattery = ring == null ? -1 : ring.battery; - ringCharging = ring == null ? -1 : ring.charging; - BleProtocol.BatterySnapshot snapshot = BleProtocol.parseSettingsBattery(message.ackPayload); - if (snapshot != null) { - headsetBattery = snapshot.battery; - headsetCharging = snapshot.charging; - emitBatteryState(headsetBattery, headsetCharging); - if (snapshot.silentMode >= 0) { - // Backstop for the push in onNotification: the firmware is - // confirmed to push silent-mode-on, but the off transition is - // not, so re-read the authoritative value on every poll. - updateSilentModeLocked(snapshot.silentMode > 0); - } - updateChargingModeLocked(snapshot.charging > 0, snapshot.battery); - } - BleProtocol.FirmwareInfo firmwareInfo = BleProtocol.parseSettingsFirmwareInfo(message.ackPayload); - if (firmwareInfo != null) { - customFirmwareDetected = firmwareInfo.isFaceclawFirmware(); - emitFirmwareInfo(firmwareInfo); - } - }; - message.onTimeout = () -> { - logLine("Battery query timed out"); - }; - return message; - } - - /** - * Track silent mode, which the wearer toggles by long-pressing both - * touchpads at once. While it is on the firmware refuses input events and - * app launches and powers the display down, so the glasses look dead even - * though the BLE session is healthy; the phone UI says so explicitly. - */ - private void updateSilentModeLocked(boolean silent) { - int next = silent ? 1 : 0; - if (silentMode == next) { - return; - } - silentMode = next; - logLine(silent ? "glasses entered silent mode" : "glasses left silent mode"); - emitSilentMode(silent); - } - - /** - * Track whether the glasses are in the charging case. Charging means nobody - * is wearing them: display communication pauses (no heartbeats, so the - * firmware tears down its EvenHub context on its own) and only battery polls - * continue. When charging stops, tear the transport down and let the normal - * reconnect loop rebuild the session, layout, and first frame. - */ - private void updateChargingModeLocked(boolean charging, int battery) { - if (charging == chargingMode) { - if (chargingMode) { - setStateDisplay("charging", chargingStatusText(battery)); - } - return; - } - if (charging) { - chargingMode = true; - clearAllMessagesLocked("glasses charging"); - fixedLayoutCreated = false; - startupProbePending = false; - displayedFingerprint = ""; - finishDesiredFrameLocked("discarded: glasses charging"); - logLine("glasses are charging; pausing display communication"); - setStateDisplay("charging", chargingStatusText(battery)); - } else { - chargingMode = false; - logLine("glasses removed from charger; reconnecting"); - handleTransportFailure("charging ended"); - } - } - - private static String chargingStatusText(int battery) { - return battery >= 0 - ? "Glasses charging. Battery " + battery + "%." - : "Glasses charging."; - } - - /** - * Record, into the frame that is waiting, why it did not go out on this - * pass of the send loop. Without this the export shows a bare multi-second - * jump between "image submitted as desired frame" and the first BLE - * packet, with no hint whether we were blocked on a heartbeat, the - * BLE window, or another message queued ahead. Deduped on (frame, reason), - * so a frame stalled for seconds gets one line per state change rather - * than one per loop pass. - */ - private void noteImageStallLocked(long now, boolean windowHasRoom) { - int frameId; - synchronized (desiredTilesLock) { - frameId = desiredFrameId; - } - String reason; - if (frameId != 0 && !getDesiredFingerprint().equals(lastEnqueuedFingerprint)) { - reason = describeEnqueueBlockerLocked(now, windowHasRoom); - } else { - // Nothing waiting to be planned; an already-planned image may still - // be queued behind other traffic. - OutboundMessage queuedImage = firstPendingImageLocked(); - frameId = queuedImage == null ? 0 : imageUpdateFrameIdLocked(queuedImage.imageUpdateId); - reason = queuedImage == null ? null : describeWriteBlockerLocked(now, windowHasRoom, queuedImage); - } - if (frameId == 0 || reason == null) { - stallFrameId = 0; - stallReason = ""; - return; - } - if (frameId == stallFrameId && reason.equals(stallReason)) { - return; - } - stallFrameId = frameId; - stallReason = reason; - FrameTimings.getInstance().log(frameId, "waiting to send: " + reason); - } - - /** Why the desired composite has not been turned into wire messages yet, or null. */ - private String describeEnqueueBlockerLocked(long now, boolean windowHasRoom) { - if (shutdownRequested) { - return "shutdown requested"; - } - if (!sessionReady) { - return "BLE session not ready"; - } - if (!fixedLayoutCreated) { - return "display layout not created yet"; - } - if (now < imageRetryAfterMs) { - return "image retry backoff (" + (imageRetryAfterMs - now) + "ms left)"; - } - if (hasPendingImageLocked()) { - return "an earlier image is still queued"; - } - if (!windowHasRoom) { - return "BLE window full (" + inFlightMessages.size() + " message(s) in flight)"; - } - if (hasPendingOrInflightKindLocked("heartbeat")) { - return "heartbeat in flight"; - } - if (!pendingMessages.isEmpty()) { - return pendingMessages.size() + " message(s) queued ahead, next " - + pendingMessages.peekFirst().label; - } - return null; - } - - /** Why a planned image message has not been written to BLE yet, or null. */ - private String describeWriteBlockerLocked(long now, boolean windowHasRoom, OutboundMessage queuedImage) { - if (!sessionReady) { - return "BLE session not ready"; - } - if (!windowHasRoom) { - return "BLE window full (" + inFlightMessages.size() + " message(s) in flight)"; - } - if (hasPendingOrInflightKindLocked("heartbeat")) { - return "heartbeat in flight"; - } - // handleHeartbeat is a barrier: while one is due it holds back every - // other write, so a frame queued at the wrong moment waits a heartbeat - // round trip. Reported explicitly because it is otherwise invisible -- - // heartbeats belong to no frame. - long heartbeatElapsedMs = now - lastHeartbeatAckedAtMs; - if (fixedLayoutCreated && !shutdownRequested - && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS) { - return "heartbeat due (" + heartbeatElapsedMs + "ms since the last one acked)"; - } - OutboundMessage head = pendingMessages.peekFirst(); - if (head != null && head != queuedImage) { - return "queued behind " + head.label; - } - return null; - } - - private OutboundMessage firstPendingImageLocked() { - for (OutboundMessage message : pendingMessages) { - if (message.imageUpdateId > 0) { - return message; - } - } - return null; - } - - private int imageUpdateFrameIdLocked(int imageUpdateId) { - BleImageOptimizer.ImageUpdateStats stats = imageUpdateStats.get(imageUpdateId); - return stats == null ? 0 : stats.frameId; - } - - private void finishDesiredFrameLocked(String outcome) { - int frameIdToFinish; - synchronized (desiredTilesLock) { - frameIdToFinish = desiredFrameId; - desiredFrameId = 0; - } - finishFrame(frameIdToFinish, outcome); - } - - private boolean hasPendingOrInflightKindLocked(String kind) { - for (OutboundMessage queued : pendingMessages) { - if (kind.equals(queued.kind)) { - return true; - } - } - for (OutboundMessage inFlight : inFlightMessages) { - if (kind.equals(inFlight.kind)) { - return true; - } - } - return false; - } - - private boolean hasPendingOrInflightMagicLocked(int magic) { - for (OutboundMessage queued : pendingMessages) { - if (queued.magic == magic) { - return true; - } - } - for (OutboundMessage inFlight : inFlightMessages) { - if (inFlight.magic == magic) { - return true; - } - } - return false; - } - - private boolean hasPendingMagicLocked(int sid, int magic) { - for (OutboundMessage queued : pendingMessages) { - if (queued.sid == sid && queued.magic == magic) { - return true; - } - } - return false; - } - - private void handleAckTimeoutLocked(OutboundMessage message) { - consecutiveAckTimeouts += 1; - - if (message.onTimeout != null) { - message.onTimeout.run(); - } - - if (consecutiveAckTimeouts > ConnectionOptions.MAX_CONSECUTIVE_ACK_TIMEOUTS) { - handleTransportFailure("too many ack timeouts"); - } - } - - /** - * Replace any stale lease control with one right-arm and one left-arm - * fire-and-forget write. With priority=true the right arm is sent first so - * CLAIM reaches the lens that originated the deferred wake immediately. - */ - private int enqueueFaceclawWakeControlLocked(int operation, int nonce, boolean priority) { - clearMessagesOfKindLocked("wake-lease-control"); - final int generation = ++faceclawWakeControlGeneration; - faceclawWakeControlSentCount = 0; - if (operation == BleProtocol.FACECLAW_WAKE_OP_ACQUIRE) { - lastFaceclawWakeLeaseQueuedAtMs = SystemClock.elapsedRealtime(); - } - MessageCallback onSent = () -> { - if (faceclawWakeControlGeneration == generation) { - faceclawWakeControlSentCount += 1; - } - }; - OutboundMessage right = messageBuilder.faceclawWakeControl(operation, nonce, false); - OutboundMessage left = messageBuilder.faceclawWakeControl(operation, nonce, true); - right.onSent = onSent; - left.onSent = onSent; - if (priority) { - pendingMessages.addFirst(left); - pendingMessages.addFirst(right); - } else { - pendingMessages.addLast(right); - pendingMessages.addLast(left); - } - logLine("queue " + right.label + " + L"); - return generation; - } - - private boolean waitForFaceclawWakeControlDelivery(int generation, long timeoutMs) { - long deadline = SystemClock.elapsedRealtime() + Math.max(0, timeoutMs); - synchronized (lock) { - while (running - && sessionReady - && faceclawWakeControlGeneration == generation - && faceclawWakeControlSentCount < 2) { - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - return faceclawWakeControlGeneration == generation - && faceclawWakeControlSentCount >= 2; - } - } - - /** - * Acquire/renew or release CFW's independent direct-framebuffer repaint - * guard on both arms. It is separate from the optional idle-wake lease: - * every Faceclaw display session needs this guard while its EvenHub layout - * contains swipe-capturing stock widgets. - */ - private int enqueueFaceclawFramebufferControlLocked(int operation, boolean priority) { - clearMessagesOfKindLocked("framebuffer-lease-control"); - final int generation = ++faceclawFramebufferControlGeneration; - faceclawFramebufferControlSentCount = 0; - if (operation == BleProtocol.FACECLAW_FB_OP_ACQUIRE) { - lastFaceclawFramebufferLeaseQueuedAtMs = SystemClock.elapsedRealtime(); - } - MessageCallback onSent = () -> { - if (faceclawFramebufferControlGeneration == generation) { - faceclawFramebufferControlSentCount += 1; - } - }; - OutboundMessage right = messageBuilder.faceclawFramebufferControl(operation, false); - OutboundMessage left = messageBuilder.faceclawFramebufferControl(operation, true); - right.onSent = onSent; - left.onSent = onSent; - if (priority) { - pendingMessages.addFirst(left); - pendingMessages.addFirst(right); - } else { - pendingMessages.addLast(right); - pendingMessages.addLast(left); - } - logLine("queue " + right.label + " + L"); - return generation; - } - - private boolean waitForFaceclawFramebufferControlDelivery(int generation, long timeoutMs) { - long deadline = SystemClock.elapsedRealtime() + Math.max(0, timeoutMs); - synchronized (lock) { - while (running - && sessionReady - && faceclawFramebufferControlGeneration == generation - && faceclawFramebufferControlSentCount < 2) { - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - try { - lock.wait(Math.min(remaining, 100)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - return faceclawFramebufferControlGeneration == generation - && faceclawFramebufferControlSentCount >= 2; - } - } - - private boolean releaseFaceclawFramebufferLease() { - int generation; - synchronized (lock) { - if (!running || !sessionReady) { - return true; - } - generation = enqueueFaceclawFramebufferControlLocked( - BleProtocol.FACECLAW_FB_OP_RELEASE, - true - ); - } - interruptibleSleep.interrupt(); - return waitForFaceclawFramebufferControlDelivery( - generation, - FACECLAW_WAKE_CONTROL_WAIT_MS - ); - } - - private void clearMessagesOfKindLocked(String kind) { - Iterator pendingIterator = pendingMessages.iterator(); - while (pendingIterator.hasNext()) { - OutboundMessage message = pendingIterator.next(); - if (kind.equals(message.kind)) { - pendingIterator.remove(); - discardPrewriteIfMatchesLocked(message); - if ("image".equals(kind)) { - discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared (" + kind + ")"); - } - magicPool.release(message.sid, message.magic, message.label, "cleared pending " + kind); - } - } - Iterator inFlightIterator = inFlightMessages.iterator(); - while (inFlightIterator.hasNext()) { - OutboundMessage message = inFlightIterator.next(); - if (kind.equals(message.kind)) { - inFlightIterator.remove(); - if ("image".equals(kind)) { - discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared (" + kind + ")"); - } - magicPool.release(message.sid, message.magic, message.label, "cleared inflight " + kind); - } - } - if ("image".equals(kind)) { - // The image pipeline was flushed (e.g. ack timeout -> keyframe resync): - // drop the pipelined delta base so the next image is a full keyframe. - lastEnqueuedPacked = new byte[0]; - lastEnqueuedFingerprint = ""; - } - } - - private void clearAllMessagesLocked(String reason) { - clearPendingMessagesLocked(reason); - clearInFlightMessagesLocked(reason); - // The image pipeline is gone: drop the pipelined delta base so the next - // image is a full keyframe rather than a delta onto a stale base. - lastEnqueuedPacked = new byte[0]; - lastEnqueuedFingerprint = ""; - // Queued resource commands (if any) were dropped with the rest, and the - // session churn behind a full clear may have freed the on-glasses - // cache; forget it phone-side so glyphs re-upload lazily. - resourceCache.reset(); - } - - /** - * A custom wake queues CLAIM before NativeScript asks for a resume. Keep - * that private control while flushing stale EvenHub traffic around the - * direct prelude write. - */ - private void clearAllMessagesPreservingWakeLeaseLocked(String reason) { - Iterator pendingIterator = pendingMessages.iterator(); - while (pendingIterator.hasNext()) { - OutboundMessage message = pendingIterator.next(); - if ("wake-lease-control".equals(message.kind)) { - continue; - } - pendingIterator.remove(); - discardPrewriteIfMatchesLocked(message); - discardImageUpdateStatsLocked( - message.imageUpdateId, - "pending messages cleared: " + reason - ); - magicPool.release( - message.sid, - message.magic, - message.label, - "cleared pending: " + reason - ); - } - clearInFlightMessagesLocked(reason); - lastEnqueuedPacked = new byte[0]; - lastEnqueuedFingerprint = ""; - resourceCache.reset(); - } - - /** Any image update whose fragments are still queued (not yet sent). */ - private boolean hasPendingImageLocked() { - for (OutboundMessage message : pendingMessages) { - if ("image".equals(message.kind)) { - return true; - } - } - return false; - } - - private void clearPendingMessagesLocked(String reason) { - while (!pendingMessages.isEmpty()) { - var message = pendingMessages.removeFirst(); - discardPrewriteIfMatchesLocked(message); - discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared: " + reason); - magicPool.release(message.sid, message.magic, message.label, "cleared pending: " + reason); - } - } - - private void clearInFlightMessagesLocked(String reason) { - while (!inFlightMessages.isEmpty()) { - var message = inFlightMessages.removeFirst(); - discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared: " + reason); - magicPool.release(message.sid, message.magic, message.label, "cleared inflight: " + reason); - } - } - - private void discardPrewriteIfMatchesLocked(OutboundMessage message) { - if (message != null && message == prewrittenMessage) { - prewrittenMessage = null; - prewrittenFrames = Collections.emptyList(); - } - } - - private void recordUnexpectedAckLocked(int sid, int magic) { - if (magic < BleMagicPool.MIN_MAGIC || magic > BleMagicPool.MAX_MAGIC) { - return; - } - BleMagicPool.ReleaseRecord previous = magicPool.getReleaseRecord(sid, magic); - if (previous == null) { - String pendingNote = hasPendingMagicLocked(sid, magic) ? " while that magic is only pending locally" : ""; - logLine("unexpected ACK sid=" + sid + " magic=" + magic + pendingNote - + "; possible Even app BLE contention"); - return; - } - if ("timeout".equals(previous.reason)) { - logLine("late ACK after timeout sid=" + sid + " magic=" + magic - + " label=" + previous.label - + "; ACK timeout may be too short"); - return; - } - if ("ack".equals(previous.reason)) { - logLine("duplicate ACK for already-acked message sid=" + sid + " magic=" + magic - + " label=" + previous.label - + "; possible Even app BLE contention"); - return; - } - logLine("late ACK for released message sid=" + sid + " magic=" + magic - + " label=" + previous.label - + " release=" + previous.reason); - } - - /** The address of a configured arm Android no longer holds a bond for, or null. */ - private String firstUnpairedArm() { - if (!bleManager.isBonded(rightAddress)) return rightAddress; - if (!bleManager.isBonded(leftAddress)) return leftAddress; - return null; - } - - /** - * A connect failure while an arm's bond is missing (the pairing was - * forgotten in Android settings, or the address was typed in by hand and - * never paired) will repeat forever, so instead of scheduling a retry, - * park the worker loop and tell the user to re-pair. Only an explicit - * connect (which builds a fresh communicator) starts a new attempt. - */ - private void handleUnpairedFailure(String address) { - Log.e(TAG, "Connect failed and " + address + " is not paired; suspending reconnect"); - synchronized (lock) { - reconnectHalted = true; - sessionReady = false; - fixedLayoutCreated = false; - startupProbePending = false; - shutdownRequested = false; - chargingMode = false; - imageRetryAfterMs = 0; - displayedFingerprint = ""; - faceclawWakePendingNonce = -1; - lastFaceclawWakeLeaseQueuedAtMs = 0; - faceclawWakeControlSentCount = 0; - clearAllMessagesLocked("arm not paired: " + address); - reconnectAfterMs = Long.MAX_VALUE; - bleManager.disconnect(rightAddress); - bleManager.disconnect(leftAddress); - } - if (!userDisconnectRequested) { - setStateDisplay( - "unpaired", - "The glasses (" + address + ") are not paired with this phone." - + " Use \"Pair glasses\" to pair them again, then connect." - ); - } - interruptibleSleep.interrupt(); - } - - private void handleTransportFailure(String reason) { - Log.e(TAG, "Transport failure: "+reason); - synchronized (lock) { - maybeEmitEvenAppConflictLocked(reason); - finishBenchmarkLocked(true, "transport failure"); - sessionReady = false; - fixedLayoutCreated = false; - startupProbePending = false; - shutdownRequested = false; - chargingMode = false; - imageRetryAfterMs = 0; - displayedFingerprint = ""; - faceclawWakePendingNonce = -1; - lastFaceclawWakeLeaseQueuedAtMs = 0; - faceclawWakeControlSentCount = 0; - clearAllMessagesLocked("transport failure: " + reason); - reconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RECONNECT_DELAY_MS; - bleManager.disconnect(rightAddress); - bleManager.disconnect(leftAddress); - } - if (!userDisconnectRequested) { - setStateDisplay("retrying", reason == null || reason.isEmpty() ? "Reconnecting..." : "Reconnecting after " + reason); - } - interruptibleSleep.interrupt(); - } - - private void resetSessionStateLocked() { - ringBattery = -1; - ringCharging = -1; - sessionReady = false; - shutdownRequested = false; - fixedLayoutCreated = false; - chargingMode = false; - rightConnected = false; - leftConnected = false; - ringConnected = false; - ringNotificationsReady = false; - reconnectAfterMs = 0; - reconnectHalted = false; - ringReconnectAfterMs = 0; - lastAckAtMs = 0; - lastIncomingAtMs = 0; - lastHeartbeatSentAtMs = 0; - lastSessionReadyAtMs = 0; - consecutiveAckTimeouts = 0; - lastAudioControlAckMagic = 0; - audioCaptureActive = false; - audioPacketListener = null; - compassControlLastSent = -1; - // A dead transport orphans any glasses-side compass state; the fresh - // session re-asserts the desired state once its layout is ready. - compassMaybeOn = false; - faceclawWakePendingNonce = -1; - lastFaceclawWakeLeaseQueuedAtMs = 0; - faceclawWakeControlSentCount = 0; - cfwCleanupDelivered = false; - for (CfwTransport transport : cfwTransports) transport.reset(); - lastCfwCleanupAckMagic = 0; - wearState = -1; - displayedFingerprint = ""; - // Deliberately not clearing silentMode: it is a property of the glasses, - // not of our session, and silent mode blocks app launches, so it can be - // the very cause of the session teardown that got us here. - } - - private void emitRingEvent(G2Event event, int frameId) { - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - FrameTimings.getInstance().finishFrame(frameId, "discarded: no listener attached"); - return; - } - final String containerNameSnapshot = event.containerName == null ? "" : event.containerName; - mainHandler.post(() -> { - FrameTimings.getInstance().log(frameId, "dispatching input event on main thread"); - try { - current.onRingEvent(event.kind, containerNameSnapshot, event.eventType, event.eventSource, event.systemExitReasonCode, frameId, - event.ringTick, event.ringType, event.ringAux, event.ringSpeed); - } catch (Throwable t) { - Log.w(TAG, "listener onRingEvent failed", t); - FrameTimings.getInstance().finishFrame(frameId, "discarded: listener onRingEvent failed"); - } - }); - } - - /** Finish a frame owned by the communicator and tell the TS side, which may be awaiting it. */ - private void finishFrame(int frameId, String outcome) { - if (frameId <= 0) { - return; - } - FrameTimings.getInstance().finishFrame(frameId, outcome); - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - mainHandler.post(() -> { - try { - current.onFrameFinished(frameId, outcome); - } catch (Throwable t) { - Log.w(TAG, "listener onFrameFinished failed", t); - } - }); - } - - private void emitImuData(double x, double y, double z, int eventSource) { - if (imuListeners.isEmpty()) { - return; - } - mainHandler.post(() -> { - for (FaceclawImuListener imuListener : imuListeners) { - try { - imuListener.onImuData(x, y, z, eventSource); - } catch (Throwable t) { - Log.w(TAG, "listener onImuData failed", t); - } - } - }); - } - - private void emitCompassEvent(BleProtocol.CompassEvent event) { - if (event.diagnosticFlags >= 0) { - String[] sources = { "unknown", "GRV", "GMRV", "RV" }; - Log.i("FaceclawCompass", "heading=" + event.headingDegrees - + " magneticAccuracy=" + event.magneticAccuracy - + " magneticAnomalies=" + event.magneticAnomalies - + " orientationSource=" + sources[event.orientationSource] - + " flags=0x" + Integer.toHexString(event.diagnosticFlags) - + " sampleTimeMs=" + event.sampleTimeMs); - } - for (CompassSubscription subscription : compassSubscriptions) { - subscription.handler.post(() -> { - try { - subscription.listener.onCompassEvent(event.command, event.headingDegrees, - event.magneticAccuracy, event.magneticAnomalies, event.orientationSource, - event.diagnosticFlags, event.sampleTimeMs); - } catch (Throwable t) { - Log.w(TAG, "listener onCompassEvent failed", t); - } - }); - } - } - - private void emitSilentMode(boolean silent) { - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - mainHandler.post(() -> { - try { - current.onSilentMode(silent); - } catch (Throwable t) { - Log.w(TAG, "listener onSilentMode failed", t); - } - }); - } - - private void emitWearState(boolean wearing) { - final FaceclawBleCommunicatorListener current = listener; - if (current == null) return; - mainHandler.post(() -> { - try { - current.onWearState(wearing); - } catch (Throwable t) { - Log.w(TAG, "listener onWearState failed", t); - } - }); - } - - private void emitPhoneLockStateIfChanged(boolean force) { - final boolean locked; - synchronized (lock) { - long now = SystemClock.elapsedRealtime(); - if (!force && now - lastPhoneLockCheckAtMs < 1_000) return; - lastPhoneLockCheckAtMs = now; - locked = keyguardManager != null && keyguardManager.isDeviceLocked(); - int value = locked ? 1 : 0; - if (!force && value == phoneLockState) return; - phoneLockState = value; - } - final FaceclawBleCommunicatorListener current = listener; - if (current == null) return; - mainHandler.post(() -> { - try { - current.onPhoneLockState(locked); - } catch (Throwable t) { - Log.w(TAG, "listener onPhoneLockState failed", t); - } - }); - } - - private void emitBatteryState(int headsetBattery, int headsetCharging) { - final int reportedRingBattery = ringBattery; - final int reportedRingCharging = ringCharging; - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - mainHandler.post(() -> { - try { - current.onBatteryState(headsetBattery, headsetCharging, reportedRingBattery, reportedRingCharging); - } catch (Throwable t) { - Log.w(TAG, "listener onBatteryState failed", t); - } - }); - } - - private void emitFirmwareInfo(BleProtocol.FirmwareInfo info) { - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - mainHandler.post(() -> { - try { - current.onFirmwareInfo(info.leftVersion, info.rightVersion, info.extension); - } catch (Throwable t) { - Log.w(TAG, "listener onFirmwareInfo failed", t); - } - }); - } - - private void emitFrameMetrics(int paintMs, int transmitMs, int tileCount) { - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - mainHandler.post(() -> { - try { - current.onFrameMetrics(paintMs, transmitMs, tileCount); - } catch (Throwable t) { - Log.w(TAG, "listener onFrameMetrics failed", t); - } - }); - } - - private void maybeEmitEvenAppConflictLocked(String reason) { - if (!"write failed".equals(reason)) { - return; - } - long now = SystemClock.elapsedRealtime(); - if (lastSessionReadyAtMs <= 0 || now - lastSessionReadyAtMs > ConnectionOptions.EVEN_APP_WRITE_FAILURE_WINDOW_MS) { - return; - } - if (lastEvenAppConflictAtMs > 0 && now - lastEvenAppConflictAtMs < 60_000) { - return; - } - if (!FaceclawEvenAppDetector.isEvenNotificationActive(appContext)) { - return; - } - lastEvenAppConflictAtMs = now; - emitEvenAppConflict("The Even Realities app still appears to be running. It can hold the glasses BLE link and cause Faceclaw write failures. Open its app settings and force stop it, then reconnect Faceclaw."); - } - - private void emitEvenAppConflict(String message) { - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - final String messageSnapshot = message == null ? "" : message; - mainHandler.post(() -> { - try { - current.onEvenAppConflict(messageSnapshot); - } catch (Throwable t) { - Log.w(TAG, "listener onEvenAppConflict failed", t); - } - }); - } - - private void setStateDisplay(String nextPhase, String nextStatus) { - synchronized (lock) { - phase = nextPhase; - status = nextStatus; - } - emitState(); - } - - private void emitState() { - final FaceclawBleCommunicatorListener current = listener; - if (current == null) { - return; - } - final String phaseSnapshot; - final String statusSnapshot; - synchronized (lock) { - phaseSnapshot = phase; - statusSnapshot = status; - } - mainHandler.post(() -> { - try { - current.onStateChange(phaseSnapshot, statusSnapshot); - } catch (Throwable t) { - Log.w(TAG, "listener onStateChange failed", t); - } - }); - } - - private void updateG2ScreenWakeLock(boolean screenOn) { - if (screenOn) { - if (g2ScreenWakeLock == null) { - g2ScreenWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, G2_SCREEN_WAKE_LOCK_TAG); - g2ScreenWakeLock.setReferenceCounted(false); - } - if (!g2ScreenWakeLock.isHeld()) { - g2ScreenWakeLock.acquire(); - logLine("G2 screen wake lock acquired"); - } - return; - } - releaseG2ScreenWakeLock(); - } - - private void releaseG2ScreenWakeLock() { - if (g2ScreenWakeLock != null && g2ScreenWakeLock.isHeld()) { - g2ScreenWakeLock.release(); - logLine("G2 screen wake lock released"); - } - } - - private void logLine(String line) { - Log.i(TAG, line); - } - - private static String timestamp(long elapsedMs) { - long wallMs = System.currentTimeMillis(); - return String.format(Locale.US, "%tF %tT.%tL elapsed=%dms", wallMs, wallMs, wallMs, elapsedMs); - } - - private int nextMapSessionId() { - int id = nextMapSessionId; - int increment = connectionOptions.skipSessionIds ? 2 : 1; - nextMapSessionId = (nextMapSessionId + increment) & 0xff; - return id; - } - - private static String requireAddress(String name, String address) { - if (address == null || address.trim().isEmpty()) { - throw new IllegalArgumentException(name + " is required"); - } - return address.trim(); - } - - private boolean hasRingAddress() { - return ringAddress != null && !ringAddress.trim().isEmpty(); - } - - private boolean isConfiguredRingAddress(String address) { - return hasRingAddress() && address != null && address.equalsIgnoreCase(ringAddress); - } - - private boolean isDirectRingNotification(String address, String characteristicUuid) { - if (!isConfiguredRingAddress(address) || characteristicUuid == null) { - return false; - } - return BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID.equals(characteristicUuid) - || BleProtocol.R1_NOTIFY_CHAR_UUID.equals(characteristicUuid); - } - - private static String hex(byte[] data) { - if (data == null || data.length == 0) { - return ""; - } - char[] out = new char[data.length * 2]; - char[] digits = "0123456789abcdef".toCharArray(); - for (int i = 0; i < data.length; i++) { - int value = data[i] & 0xff; - out[i * 2] = digits[value >>> 4]; - out[i * 2 + 1] = digits[value & 0x0f]; - } - return new String(out); - } - - private static String safeMessage(Throwable t) { - if (t == null) { - return "unknown"; - } - StringWriter writer = new StringWriter(); - t.printStackTrace(new PrintWriter(writer)); - String trace = writer.toString(); - if (!trace.trim().isEmpty()) { - return trace; - } - String message = t.getMessage(); - return message == null || message.trim().isEmpty() ? String.valueOf(t) : message; - } - - private String getDesiredFingerprint() { - synchronized (desiredTilesLock) { - return desiredFingerprint; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt new file mode 100644 index 00000000..97e8d343 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt @@ -0,0 +1,4072 @@ +package com.faceclaw.app + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothGatt +import android.app.KeyguardManager +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.Handler +import android.os.Looper +import android.os.PowerManager +import android.os.SystemClock +import android.util.Log + +import java.io.PrintWriter +import java.io.StringWriter +import java.util.ArrayDeque +import java.util.ArrayList +import java.util.Arrays +import java.util.Collections +import java.util.HashMap +import java.util.Locale +import java.util.Random + +@SuppressLint("MissingPermission") +class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddress: String?, ringAddress: String?) : FaceclawBleListener, Runnable { + companion object { + private const val TAG = "FaceclawComm" + + // Local metadata for custom-command bookkeeping, not an EvenHub container. + // Submitted frames supply pixel geometry; the stock layout only captures input. + private val DASHBOARD_TILE: BleProtocol.ImageTileOptions = + BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288) + + private const val G2_SCREEN_WAKE_LOCK_TAG = "Faceclaw:G2Screen" + private const val FACECLAW_WAKE_LEASE_RENEW_MS = 45_000L + private const val FACECLAW_WAKE_CONTROL_WAIT_MS = 1_500L + private const val CFW_CLEANUP_WAIT_MS = 4_000L + private const val COMPASS_REPORT_INTERVAL_MS = 100 + private const val COMPASS_MIN_CHANGE_DEGREES = 0 + + // A timed-out benchmark message aborts the run, but its already-in-flight + // peers still time out one by one; keep the window comfortably below + // MAX_CONSECUTIVE_ACK_TIMEOUTS so a dead run can't escalate into a + // transport-failure reconnect all by itself. + private const val BENCHMARK_MAX_WINDOW = 6 + + // The most recently started communicator; lets app worker threads submit + // surface frames without holding a cross-isolate reference to the bridge + // object (JS wrappers do not cross isolates, but the Java instance does). + @Volatile private var activeInstance: FaceclawBleCommunicator? = null + + @JvmStatic + fun getActive(): FaceclawBleCommunicator? { + return activeInstance + } + + private fun chargingStatusText(battery: Int): String { + return if (battery >= 0) + "Glasses charging. Battery $battery%." + else + "Glasses charging." + } + + private fun timestamp(elapsedMs: Long): String { + val wallMs = System.currentTimeMillis() + return String.format(Locale.US, "%tF %tT.%tL elapsed=%dms", wallMs, wallMs, wallMs, elapsedMs) + } + + private fun requireAddress(name: String, address: String?): String { + if (address == null || address.trim().isEmpty()) { + throw IllegalArgumentException("$name is required") + } + return address.trim() + } + + private fun hex(data: ByteArray?): String { + if (data == null || data.isEmpty()) { + return "" + } + val out = CharArray(data.size * 2) + val digits = "0123456789abcdef".toCharArray() + for (i in data.indices) { + val value = data[i].toInt() and 0xff + out[i * 2] = digits[value ushr 4] + out[i * 2 + 1] = digits[value and 0x0f] + } + return String(out) + } + + private fun safeMessage(t: Throwable?): String { + if (t == null) { + return "unknown" + } + val writer = StringWriter() + t.printStackTrace(PrintWriter(writer)) + val trace = writer.toString() + if (trace.trim().isNotEmpty()) { + return trace + } + val message = t.message + return if (message == null || message.trim().isEmpty()) t.toString() else message + } + } + + private val appContext: Context = context.applicationContext + init { + FrameTimings.getInstance().init(appContext) + } + private val powerManager: PowerManager = appContext.getSystemService(Context.POWER_SERVICE) as PowerManager + private val keyguardManager: KeyguardManager? = appContext.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager? + private val bleManager: FaceclawBleManager = FaceclawBleManager(appContext) + private val interruptibleSleep = InterruptibleSleep() + private val lock = java.lang.Object() + private val mainHandler = Handler(Looper.getMainLooper()) + private val rightAddress: String = requireAddress("rightAddress", rightAddress) + private val leftAddress: String = requireAddress("leftAddress", leftAddress) + private val ringAddress: String = ringAddress?.trim() ?: "" + + @Volatile private var listener: FaceclawBleCommunicatorListener? = null + private val imuListeners: MutableList = + java.util.concurrent.CopyOnWriteArrayList() + /** A compass subscriber plus the Looper it registered from (see addCompassListener). */ + private class CompassSubscription( + @JvmField val listener: FaceclawCompassListener, + @JvmField val handler: Handler, + ) + + private val compassSubscriptions: MutableList = + java.util.concurrent.CopyOnWriteArrayList() + private val ambientLightListeners: MutableList = + java.util.concurrent.CopyOnWriteArrayList() + private val micStatusListeners: MutableList = + java.util.concurrent.CopyOnWriteArrayList() + @Volatile private var workerThread: Thread? = null + @Volatile private var running = false + @Volatile private var userDisconnectRequested = false + // Set when a connect attempt failed while an arm's Android bond is gone: + // retrying is pointless until the user re-pairs, so the worker loop parks + // instead of redialing. Cleared by start() (a fresh explicit connect). + @Volatile private var reconnectHalted = false + + private var phase = "disconnected" + private var status = "Disconnected." + + private var rightConnected = false + private var leftConnected = false + private var ringConnected = false + private var ringNotificationsReady = false + private var sessionReady = false + private var fixedLayoutCreated = false + private var shutdownRequested = false + // CFW firmware-debug-flags overlay (mode 7). Desired value pushed from TS; the + // sub-op last sent this session (-1 = not yet), reset on (re)connect so the + // overlay state is re-asserted on every reconnect and whenever the value changes. + @Volatile private var firmwareDebugFlagsEnabled = false + private var firmwareDebugFlagsLastSent = -1 + // Desired CFW mode-10 compass state. It survives reconnects; lastSent is + // reset with each session so an open Compass window is re-asserted. + /** + * Who currently wants the stock compass running (the Compass window, the + * Navigate worker, ...). The magnetometer is one shared resource, so it + * stays on while any owner holds it and is released when the last lets go; + * this keeps one app's release from silently switching off another's feed. + */ + private val compassOwners: MutableSet = HashSet() + private var compassControlLastSent = -1 + // Whether the glasses-side compass may still be running: set when an enable + // is enqueued, cleared only when a disable is acked. Drives the forced + // disable sent ahead of an EvenHub shutdown/suspend, since a pending + // disable can be wiped by the shutdown's queue flush and the retry loop + // does not run while shutdownRequested (magnetometer left on = battery drain). + private var compassMaybeOn = false + private var startupProbePending = false + // Desired ownership of CFW's fail-open stock-wake lease (dashboard launch + // and Even AI foreground takeover). This survives a transport reconnect; + // the lease itself is volatile firmware state and is re-acquired once both + // arms are ready. + private var faceclawWakeLeaseEnabled = false + private var lastFaceclawWakeLeaseQueuedAtMs = 0L + private var faceclawWakeControlGeneration = 0 + private var faceclawWakeControlSentCount = 0 + private var lastFaceclawFramebufferLeaseQueuedAtMs = 0L + private var faceclawFramebufferControlGeneration = 0 + private var faceclawFramebufferControlSentCount = 0 + private var faceclawWakePendingNonce = -1 + /** + * The last firmware-info read said the glasses run Faceclaw's custom + * firmware. Gates the private modes (cleanup, resource cache, ...) so stock + * or third-party firmware never sees them; the TS side checks the actual + * revision and disconnects on a mismatch, so no per-feature gating is + * needed here. + */ + private var customFirmwareDetected = false + private var cfwCleanupDelivered = false + private var lastCfwCleanupAckMagic = 0 + + private var reconnectAfterMs = 0L + private var ringReconnectAfterMs = 0L + private var lastAckAtMs = 0L + private var lastIncomingAtMs = 0L + private var lastHeartbeatSentAtMs = 0L + private var lastHeartbeatAckedAtMs = 0L + private var lastConnectionOrInputAtMs = 0L + private var lastBatteryRefreshAtMs = 0L + private var imageRetryAfterMs = 0L + private var lastSessionReadyAtMs = 0L + private var lastEvenAppConflictAtMs = 0L + private var consecutiveAckTimeouts = 0 + private var lastAudioControlAckMagic = 0 + + private val connectionOptions = ConnectionOptions() + private val magicPool = BleMagicPool(AndroidProtocolPlatform) + private val messageBuilder = MessageBuilder(magicPool) + private var nextTransportSeq = 0x40 + private var nextMapSessionId = 0 + private var nextImageUpdateId = 1 + // Wire frame id for mode-3 deltas (CFW reorder/skip/dup diagnostic). uint16, + // advanced by 1 per emitted delta; kept in [1, 0xfffe] to avoid the CFW's + // 0xffff "empty" sentinel. + private var nextImageFrameId = 1 + private var lastShutdownAckMagic = 0 + private var lastShutdownExitAtMs = 0L + private var headsetBattery = -1 + private var headsetCharging = -1 + private var ringBattery = -1 + private var ringCharging = -1 + // Silent mode: 1 = on, 0 = off, -1 = not yet known. See updateSilentModeLocked. + private var silentMode = -1 + private var wearState = -1 + private var phoneLockState = -1 + private var lastPhoneLockCheckAtMs = 0L + private var phoneLockReceiverRegistered = false + private var audioCaptureActive = false + private var firmwareInfoQueried = false + // Glasses are in the charging case: nobody is wearing them, so display + // communication pauses and only battery polls flow (see driveSession). + private var chargingMode = false + @Volatile private var audioPacketListener: FaceclawAudioPacketListener? = null + private var g2ScreenWakeLock: PowerManager.WakeLock? = null + + // BLE bandwidth benchmark (Developer app). Streams no-op image payloads + // (CFW mode 7 with an unused sub-op: parsed, acked, and discarded — stock + // firmware likewise ignores unknown image modes) for a fixed duration with + // a selectable message size and pipeline window, then reports throughput. + // While active, desired-frame sends are held back and heartbeats are + // satisfied by the benchmark's own acks, so the stream is the only image + // traffic. All state below is guarded by `lock`; results are read with + // getBandwidthBenchmarkStatus() and survive until the next run starts. + private var benchmarkActive = false + private var benchmarkAborted = false + private val benchmarkRandom = Random() + private var benchmarkMessageSize = 0 + private var benchmarkWindowSize = 0 + private var benchmarkDurationMs = 0 + private var benchmarkLinkMode = 0 + private var benchmarkLinkPending = false + private var benchmarkReadyAtMs = 0L + private var benchmarkStartAtMs = 0L // first benchmark write; 0 until then + private var benchmarkDeadlineAtMs = 0L // start + duration; MAX_VALUE until first write + private var benchmarkLastAckAtMs = 0L + private var benchmarkEndAtMs = 0L // 0 while running; set when the run drains + private var benchmarkMessagesSent = 0 + private var benchmarkMessagesAcked = 0 + private var benchmarkTimeouts = 0 + private var benchmarkPayloadBytesAcked = 0L + private var benchmarkWireBytesAcked = 0L + + private val phoneLockReceiver: BroadcastReceiver = object : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + emitPhoneLockStateIfChanged(true) + interruptibleSleep.interrupt() + } + } + + private var displayedFingerprint = "" + // The frame the firmware shadow will hold once the current image pipeline + // drains: the most recently ENQUEUED image (headerless packed 4bpp, see + // BmpUtil.pack4bppFromGray8), which is the correct base for the next delta + // when frames are pipelined. Set at enqueue; cleared whenever the image + // pipeline is cleared (clearAllMessagesLocked / clearMessagesOfKindLocked + // "image"), so it is only ever read while it holds a valid current-session base. + private var lastEnqueuedPacked: ByteArray = ByteArray(0) + private var lastEnqueuedWidth = 0 + private var lastEnqueuedHeight = 0 + private var lastEnqueuedFingerprint = "" + private val imageUpdateStats: MutableMap = HashMap() + + private val desiredTilesLock = Any() + private var desiredFingerprint = "" + // Headerless packed 4bpp frame (see BmpUtil.pack4bppFromGray8) plus its + // pixel dimensions. + private var desiredPacked: ByteArray? = ByteArray(0) + private var desiredWidth = 0 + private var desiredHeight = 0 + private var desiredPaintMs = 0 + private var desiredFrameId = 0 + // Screen-space deferred draws (glyphs + images) whose pixels are baked + // into desiredPacked; the resource-cache planner may replay them as + // on-glasses cached draws. + private var desiredDraws: Array? = arrayOf() + // (frame, reason) of the last "waiting to send" line, so a frame that + // stalls for seconds records one line per state change (see + // noteImageStallLocked). Send-loop thread only. + private var stallFrameId = 0 + private var stallReason = "" + // Highest compositor sequence stored as the desired frame; composites that + // lost a store race to a newer one are discarded (their content is already + // included in the newer composite). + private var lastStoredCompositeSeq = 0L + + // Wire submissions need screenGray + the shell scene, never preview pixels. + // Preview/screenshot/recording callers render those explicitly on demand. + private val compositor = SurfaceCompositor(false) + + // Phone-side model of the CFW's 192 KiB resource cache. + // Reset whenever the image pipeline / EvenHub session is torn down: the + // firmware frees the cache with the fb lease, and after any resync the + // cheap safe assumption is an empty cache (glyphs re-upload lazily). + private val resourceCache = ResourceCacheState() + private val scenePlanner = ScenePlanner(resourceCache) + private var desiredShellScene: ShellScene = ShellScene.EMPTY + + private val pendingMessages = ArrayDeque() + private val cfwTransports = arrayOf(CfwTransport(AndroidProtocolPlatform), CfwTransport(AndroidProtocolPlatform)) + private val inFlightMessages = ArrayDeque() + private var prewrittenMessage: OutboundMessage? = null + private var prewrittenFrames: List = Collections.emptyList() + + // Active animated-GIF screen recording, or null when idle. Frames are + // pushed by recordScreenFrame(), which the TS side calls at each + // phone-preview flush. + @Volatile private var screenRecorder: GifScreenRecorder? = null + + init { + bleManager.setListener(this) + val phoneLockFilter = IntentFilter() + phoneLockFilter.addAction(Intent.ACTION_SCREEN_ON) + phoneLockFilter.addAction(Intent.ACTION_SCREEN_OFF) + phoneLockFilter.addAction(Intent.ACTION_USER_PRESENT) + appContext.registerReceiver(phoneLockReceiver, phoneLockFilter) + phoneLockReceiverRegistered = true + } + + + fun setListener(listener: FaceclawBleCommunicatorListener?) { + this.listener = listener + emitState() + emitPhoneLockStateIfChanged(true) + } + + fun start() { + synchronized(lock) { + if (running) { + return + } + running = true + userDisconnectRequested = false + reconnectHalted = false + shutdownRequested = false + activeInstance = this + val thread = Thread(this, "FaceclawBleCommunicator") + workerThread = thread + thread.start() + } + } + + fun disconnect() { + /* On the normal path DashboardController already sent mode 11 after + * quiescing its producers. Also cover direct/early close callers here; + * a successful cleanup must remain the final BLE message. Older CFWs + * fall back to the standalone framebuffer-lease release. */ + if (!cfwCleanupDelivered && !sendCfwCleanup()) { + releaseFaceclawFramebufferLease() + } + val threadToJoin: Thread? + synchronized(lock) { + userDisconnectRequested = true + running = false + audioCaptureActive = false + audioPacketListener = null + threadToJoin = workerThread + } + setStateDisplay("disconnecting", "Disconnecting...") + interruptibleSleep.interrupt() + if (threadToJoin != null) { + threadToJoin.interrupt() + try { + threadToJoin.join(5_000) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + } + } + synchronized(lock) { + workerThread = null + resetSessionStateLocked() + clearAllMessagesLocked("disconnect") + // Unknown until the next connection's first push or settings poll. + silentMode = -1 + } + bleManager.disconnect(rightAddress) + bleManager.disconnect(leftAddress) + if (hasRingAddress()) { + bleManager.disconnect(ringAddress) + } + bleManager.close() + releaseG2ScreenWakeLock() + setStateDisplay("disconnected", "Disconnected.") + } + + fun close() { + if (activeInstance === this) { + activeInstance = null + } + disconnect() + for (transport in cfwTransports) transport.close() + if (phoneLockReceiverRegistered) { + phoneLockReceiverRegistered = false + appContext.unregisterReceiver(phoneLockReceiver) + } + } + + fun setG2ScreenOn(screenOn: Boolean) { + mainHandler.post { updateG2ScreenWakeLock(screenOn) } + } + + fun setFirmwareDebugFlags(enabled: Boolean) { + // Just record it; the drive loop emits the mode-7 control message when the + // display path is ready and idle, and re-emits when this value changes. + firmwareDebugFlagsEnabled = enabled + } + + fun startG2AudioCapture(listener: FaceclawAudioPacketListener?): Boolean { + if (listener == null) { + throw IllegalArgumentException("listener is required") + } + var magic = 0 + synchronized(lock) { + if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { + logLine("skip G2 mic enable; EvenHub display path not ready") + return false + } + audioPacketListener = listener + val message = createAudioControlMessageLocked(true) + magic = message.magic + pendingMessages.addFirst(message) + logLine("queue G2 mic enable") + } + interruptibleSleep.interrupt() + return waitForAudioControlAck(magic, "enable") + } + + fun stopG2AudioCapture() { + var magic = 0 + synchronized(lock) { + audioPacketListener = null + audioCaptureActive = false + clearMessagesOfKindLocked("audio-control") + if (running && sessionReady) { + val message = createAudioControlMessageLocked(false) + magic = message.magic + pendingMessages.addFirst(message) + logLine("queue G2 mic disable") + } + } + interruptibleSleep.interrupt() + if (magic != 0) { + waitForAudioControlAck(magic, "disable") + } + } + + fun isSessionReady(): Boolean { + synchronized(lock) { + return running && sessionReady + } + } + + /** + * Whether the glasses mic is enabled right now. The enable lives in the + * current EvenHub session, so it dies with a transport drop, the charging + * case, or a suspend — silently, from the phone's point of view. Callers + * that track a capture across those events must check this rather than + * assume their earlier enable still holds. + */ + fun isAudioCaptureActive(): Boolean { + synchronized(lock) { + return running && sessionReady && !shutdownRequested && audioCaptureActive + } + } + + /** + * Acquire/renew or release CFW's volatile wake-takeover lease on both + * arms. Delivery (not a protocol ACK) is awaited so a caller can ensure + * the fail-open firmware policy is installed before relying on wakeword + * interception or suspending EvenHub. + */ + fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean { + val generation: Int + synchronized(lock) { + faceclawWakeLeaseEnabled = enabled + if (!running || !sessionReady) { + return !enabled + } + generation = enqueueFaceclawWakeControlLocked( + if (enabled) BleProtocol.FACECLAW_WAKE_OP_ACQUIRE else BleProtocol.FACECLAW_WAKE_OP_RELEASE, + 0, + true + ) + if (!enabled) { + faceclawWakePendingNonce = -1 + } + } + interruptibleSleep.interrupt() + return waitForFaceclawWakeControlDelivery(generation, FACECLAW_WAKE_CONTROL_WAIT_MS) + } + + /** + * Wait until the recreated layout and retained compositor frame have both + * landed. If this wake came from CFW's deferred double tap, READY + * is then sent to both arms to cancel their stock-dashboard fallback. + */ + fun awaitEvenHubSessionReady(timeoutMs: Int): Boolean { + val deadline = SystemClock.elapsedRealtime() + Math.max(0, timeoutMs) + var readyGeneration = 0 + synchronized(lock) { + while (running && sessionReady) { + var frameReady = false + synchronized(desiredTilesLock) { + frameReady = desiredFingerprint.isNotEmpty() + && desiredFingerprint == displayedFingerprint + } + if (!shutdownRequested && fixedLayoutCreated && frameReady) { + if (faceclawWakePendingNonce >= 0) { + readyGeneration = enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_READY, + faceclawWakePendingNonce, + true + ) + faceclawWakePendingNonce = -1 + } + break + } + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + return false + } + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + return false + } + } + if (!running || !sessionReady) { + return false + } + } + if (readyGeneration != 0) { + interruptibleSleep.interrupt() + if (!waitForFaceclawWakeControlDelivery(readyGeneration, FACECLAW_WAKE_CONTROL_WAIT_MS)) { + logLine("wake READY delivery not confirmed before fallback deadline") + } + } + return true + } + + /** + * Enable or disable the IMU (accelerometer) report stream. Fire-and-forget: + * the control message is queued ahead of other traffic; readings arrive via + * registered FaceclawImuListeners. reportFrq is the requested sample rate + * (ignored on disable). + */ + fun setImuReportEnabled(enable: Boolean, reportFrq: Int) { + synchronized(lock) { + if (!running || !sessionReady) { + logLine("skip IMU " + (if (enable) "enable" else "disable") + "; session not ready") + return + } + clearMessagesOfKindLocked("imu-control") + val message = messageBuilder.enableOrDisableImu(enable, reportFrq) + message.onTimeout = MessageCallback { logLine("IMU control ack timeout") } + pendingMessages.addFirst(message) + logLine("queue IMU " + (if (enable) "enable freq=$reportFrq" else "disable")) + } + interruptibleSleep.interrupt() + } + + /** + * Enable/disable the stock compass through CFW image-handler mode 10. The + * desired state is retained across reconnects; headings arrive through + * stock sid-0x08 navigation notifications and FaceclawCompassListeners. + */ + fun setCompassEnabled(enable: Boolean) { + setCompassEnabled("compass", enable) + } + + /** + * As above, on behalf of a named owner. The compass runs while at least + * one owner has enabled it; an owner disabling it only takes effect once + * no other owner still wants it. + */ + fun setCompassEnabled(owner: String?, enable: Boolean) { + synchronized(lock) { + val before = compassOwners.isNotEmpty() + if (enable) { + compassOwners.add(owner) + } else { + compassOwners.remove(owner) + } + val wanted = compassOwners.isNotEmpty() + if (wanted == before && compassControlLastSent == (if (wanted) 1 else 0)) { + logLine("compass " + (if (enable) "enable" else "disable") + " by " + owner + + "; state unchanged (owners=" + compassOwners + ")") + return + } + compassControlLastSent = -1 + clearMessagesOfKindLocked("compass-control") + if (running && sessionReady && !shutdownRequested && fixedLayoutCreated) { + enqueueCompassControlLocked(true, wanted) + } else { + logLine("defer compass " + (if (enable) "enable" else "disable") + "; display path not ready") + } + } + interruptibleSleep.interrupt() + } + + /** + * Set the lens brightness. Fire-and-forget, like the IMU control: the + * message is queued ahead of other traffic and any not-yet-sent brightness + * message is superseded. When autoAdjust is true the ambient-light sensor + * drives brightness and brightnessLevel is ignored; otherwise + * brightnessLevel (0-100) is applied directly. + */ + fun setBrightness(autoAdjust: Boolean, brightnessLevel: Int) { + synchronized(lock) { + if (!running || !sessionReady) { + logLine("skip brightness set; session not ready") + return + } + clearMessagesOfKindLocked("brightness-control") + val message = messageBuilder.setBrightness(autoAdjust, brightnessLevel) + message.onTimeout = MessageCallback { logLine("brightness control ack timeout") } + pendingMessages.addFirst(message) + logLine("queue brightness " + (if (autoAdjust) "auto" else "level=$brightnessLevel")) + } + interruptibleSleep.interrupt() + } + + /** + * Enable the stock wear detector, then ask CFW to emit its current cached + * state. The queue order matters: the query must run after the setting is + * applied, including on a fresh install where wear detection was disabled. + */ + fun enableWearDetectionAndRequestState() { + synchronized(lock) { + if (!running || !sessionReady) { + logLine("skip wear detector setup; session not ready") + return + } + clearMessagesOfKindLocked("wear-detection-control") + clearMessagesOfKindLocked("wear-query-control") + val queryLeft = messageBuilder.faceclawWearQuery(true) + val queryRight = messageBuilder.faceclawWearQuery(false) + val enable = messageBuilder.setWearDetection(true) + enable.onTimeout = MessageCallback { logLine("wear detection enable ack timeout") } + pendingMessages.addFirst(queryLeft) + pendingMessages.addFirst(queryRight) + pendingMessages.addFirst(enable) + logLine("queue wear detection enable + current-state query") + } + interruptibleSleep.interrupt() + } + + /** + * Start the BLE bandwidth benchmark: stream messageSize-byte no-op image + * payloads for durationMs, keeping up to windowSize messages awaiting ack + * at once, then leave the results for getBandwidthBenchmarkStatus(). + * Returns false when a run is already active or the image path is not + * ready. The duration clock starts at the first benchmark write, so + * traffic already queued ahead of the run doesn't count against it. + */ + fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean { + return startBandwidthBenchmarkWithLinkMode(messageSize, windowSize, durationMs, 0) + } + + // 0: current link; 1: re-request HIGH; 2: request 2M; 3: both. + fun startBandwidthBenchmarkWithLinkMode(messageSize: Int, windowSize: Int, + durationMs: Int, linkMode: Int): Boolean { + synchronized(lock) { + if (benchmarkActive || !running || !sessionReady || !fixedLayoutCreated + || shutdownRequested || chargingMode) { + logLine("skip bandwidth benchmark; already running or image path not ready") + return false + } + benchmarkMessageSize = Math.max(2, Math.min(messageSize, ConnectionOptions.IMAGE_FRAGMENT_SIZE)) + benchmarkWindowSize = Math.max(1, Math.min(windowSize, BENCHMARK_MAX_WINDOW)) + benchmarkDurationMs = Math.max(1_000, durationMs) + benchmarkLinkMode = linkMode and 3 + benchmarkLinkPending = true + benchmarkReadyAtMs = Long.MAX_VALUE + benchmarkStartAtMs = 0 + benchmarkDeadlineAtMs = Long.MAX_VALUE + benchmarkLastAckAtMs = 0 + benchmarkEndAtMs = 0 + benchmarkMessagesSent = 0 + benchmarkMessagesAcked = 0 + benchmarkTimeouts = 0 + benchmarkPayloadBytesAcked = 0 + benchmarkWireBytesAcked = 0 + benchmarkAborted = false + benchmarkActive = true + logLine("bandwidth benchmark start: size=" + benchmarkMessageSize + + "B window=" + benchmarkWindowSize + " duration=" + benchmarkDurationMs + + "ms linkMode=" + benchmarkLinkMode) + } + interruptibleSleep.interrupt() + return true + } + + /** + * Cancel an in-progress benchmark (benchmark page closed). Queued no-op + * messages are dropped; in-flight ones drain through their normal acks. + */ + fun cancelBandwidthBenchmark() { + synchronized(lock) { + if (!benchmarkActive) { + return + } + clearMessagesOfKindLocked("bandwidth") + finishBenchmarkLocked(true, "cancelled") + } + interruptibleSleep.interrupt() + } + + /** Status/results of the current or most recent benchmark run, as JSON. */ + fun getBandwidthBenchmarkStatus(): String { + synchronized(lock) { + val state = if (benchmarkActive) + (if (benchmarkStartAtMs == 0L) "starting" else "running") + else + (if (benchmarkEndAtMs != 0L) "done" else "idle") + val end = if (benchmarkActive) SystemClock.elapsedRealtime() else benchmarkEndAtMs + val elapsed = if (benchmarkStartAtMs == 0L) 0L else Math.max(0L, end - benchmarkStartAtMs) + try { + val status = org.json.JSONObject() + status.put("state", state) + status.put("messageSize", benchmarkMessageSize) + status.put("windowSize", benchmarkWindowSize) + status.put("linkMode", benchmarkLinkMode) + status.put("elapsedMs", elapsed) + status.put("messagesSent", benchmarkMessagesSent) + status.put("messagesAcked", benchmarkMessagesAcked) + status.put("timeouts", benchmarkTimeouts) + status.put("payloadBytesAcked", benchmarkPayloadBytesAcked) + status.put("wireBytesAcked", benchmarkWireBytesAcked) + status.put("aborted", benchmarkAborted) + return status.toString() + } catch (e: org.json.JSONException) { + return "{\"state\":\"idle\"}" + } + } + } + + /** Pending + in-flight benchmark no-op messages. */ + private fun benchmarkOutstandingLocked(): Int { + var count = 0 + for (message in pendingMessages) { + if ("bandwidth" == message.kind) count++ + } + for (message in inFlightMessages) { + if ("bandwidth" == message.kind) count++ + } + return count + } + + /** + * Keep the benchmark stream fed: top the pending queue up so the send + * window never starves, stop enqueueing once the run expires (or a message + * times out), and finish the run when the last outstanding message drains. + */ + private fun maintainBenchmarkLocked(now: Long) { + if (!sessionReady || !fixedLayoutCreated || shutdownRequested) { + finishBenchmarkLocked(true, "session no longer ready") + return + } + if (benchmarkLinkPending || now < benchmarkReadyAtMs) { + return + } + if (benchmarkAborted || now >= benchmarkDeadlineAtMs) { + // The run is over: drop queued-but-unsent no-ops (sending them + // would stretch the run past its deadline) and finish once the + // in-flight tail has acked or timed out. + val pendingIterator = pendingMessages.iterator() + while (pendingIterator.hasNext()) { + val queued = pendingIterator.next() + if ("bandwidth" == queued.kind) { + pendingIterator.remove() + magicPool.release(queued.sid, queued.magic, queued.label, "benchmark over") + } + } + if (benchmarkOutstandingLocked() == 0) { + finishBenchmarkLocked(false, "complete") + } + return + } + // One more than the window so a fresh message is always ready to write + // the moment an ack frees a slot. + var outstanding = benchmarkOutstandingLocked() + while (outstanding <= benchmarkWindowSize) { + enqueueBenchmarkMessageLocked() + outstanding++ + } + } + + private fun finishBenchmarkLocked(aborted: Boolean, reason: String) { + if (!benchmarkActive) { + return + } + benchmarkActive = false + benchmarkAborted = benchmarkAborted or aborted + // Prefer the last ack as the end time so drain lag after the deadline + // doesn't dilute the throughput figure. + benchmarkEndAtMs = if (benchmarkLastAckAtMs != 0L) benchmarkLastAckAtMs else SystemClock.elapsedRealtime() + logLine("bandwidth benchmark " + (if (benchmarkAborted) "aborted" else "finished") + " (" + reason + "): " + + benchmarkMessagesAcked + "/" + benchmarkMessagesSent + " acked, " + + benchmarkPayloadBytesAcked + "B payload, " + benchmarkTimeouts + " timeouts") + } + + private fun enqueueBenchmarkMessageLocked() { + // Fresh bytes per message: the transport's persistent compression history + // would compress even a random payload if we reused it across the run. + val payload = ByteArray(benchmarkMessageSize) + benchmarkRandom.nextBytes(payload) + payload[0] = CFW_MSG_DIAGNOSTICS.toByte() // CFW diagnostic-control mode... + payload[1] = 0x7f.toByte() // ...with an unused sub-op: acked, no effect + val message = messageBuilder.imagePayload( + "bandwidth", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + "bandwidth no-op " + payload.size + "B", + connectionOptions.sendImagesToLeft) + val payloadBytes = payload.size + // Logical custom-message bytes; excludes length tag and packet framing. + val wireBytes = message.message.size + message.onSent = MessageCallback { + benchmarkMessagesSent++ + if (benchmarkStartAtMs == 0L) { + benchmarkStartAtMs = SystemClock.elapsedRealtime() + benchmarkDeadlineAtMs = benchmarkStartAtMs + benchmarkDurationMs + } + } + message.onAck = MessageCallback { + val ackedAtMs = SystemClock.elapsedRealtime() + benchmarkMessagesAcked++ + benchmarkPayloadBytesAcked += payloadBytes + benchmarkWireBytesAcked += wireBytes + benchmarkLastAckAtMs = ackedAtMs + // No-op payloads ride the image path, so the firmware resets its + // heartbeat timer on them just like real image messages. + lastHeartbeatAckedAtMs = ackedAtMs + } + message.onTimeout = MessageCallback { + benchmarkTimeouts++ + benchmarkAborted = true + logLine("bandwidth benchmark ack timeout") + } + pendingMessages.addLast(message) + } + + fun addImuListener(listener: FaceclawImuListener?) { + if (listener != null) { + imuListeners.add(listener) + } + } + + fun removeImuListener(listener: FaceclawImuListener?) { + if (listener != null) { + imuListeners.remove(listener) + } + } + + fun addAmbientLightListener(listener: FaceclawAmbientLightListener?) { + if (listener != null) { + ambientLightListeners.add(listener) + } + } + + fun removeAmbientLightListener(listener: FaceclawAmbientLightListener?) { + if (listener != null) { + ambientLightListeners.remove(listener) + } + } + + private fun emitAmbientLight(body: ByteArray) { + if (ambientLightListeners.isEmpty()) { + return + } + val copy = Arrays.copyOf(body, body.size) + mainHandler.post { + for (alsListener in ambientLightListeners) { + try { + alsListener.onAmbientLight(copy) + } catch (t: Throwable) { + Log.w(TAG, "ambient light listener failed", t) + } + } + } + } + + /** Request one CFW ambient-light report (image-handler mode 16 op 0). */ + fun queryAmbientLight() { + synchronized(lock) { + enqueueAmbientLightControlLocked(byteArrayOf(CFW_MSG_AMBIENT_LIGHT.toByte(), 0.toByte()), "als query", false) + } + interruptibleSleep.interrupt() + } + + /** + * Start or stop CFW passive light-sensor polling (image-handler mode 16 + * ops 1/2). While polling, the firmware reads its OPT3001 every intervalMs + * (clamped 100..5000 by the firmware), never steps the panel brightness + * itself, and pushes a field-105 report when the reading moved by at least + * minDelta or heartbeatMs elapsed. bindToLease stops polling automatically + * when the Faceclaw framebuffer lease is released or lapses. Starting is + * idempotent and re-opens the sensor if the stock firmware closed it. + */ + fun setAmbientLightPolling(enable: Boolean, intervalMs: Int, minDelta: Int, + heartbeatMs: Int, bindToLease: Boolean) { + val payload = if (enable) + byteArrayOf( + CFW_MSG_AMBIENT_LIGHT.toByte(), + 1.toByte(), + (if (bindToLease) 1 else 0).toByte(), + (intervalMs and 0xff).toByte(), + ((intervalMs shr 8) and 0xff).toByte(), + (minDelta and 0xff).toByte(), + ((minDelta shr 8) and 0xff).toByte(), + (heartbeatMs and 0xff).toByte(), + ((heartbeatMs shr 8) and 0xff).toByte(), + ) + else + byteArrayOf(CFW_MSG_AMBIENT_LIGHT.toByte(), 2.toByte()) + synchronized(lock) { + clearMessagesOfKindLocked("als-control") + enqueueAmbientLightControlLocked(payload, "als polling " + (if (enable) "start" else "stop"), true) + } + interruptibleSleep.interrupt() + } + + private fun enqueueAmbientLightControlLocked(payload: ByteArray, label: String, priority: Boolean) { + if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { + logLine("skip $label; display path not ready") + return + } + val message = messageBuilder.imagePayload( + "als-control", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + label, + connectionOptions.sendImagesToLeft) + message.onTimeout = MessageCallback { logLine("$label ack timeout") } + if (priority) pendingMessages.addFirst(message) + else pendingMessages.addLast(message) + logLine("queue $label") + } + + fun addMicStatusListener(listener: FaceclawMicStatusListener?) { + if (listener != null) { + micStatusListeners.add(listener) + } + } + + fun removeMicStatusListener(listener: FaceclawMicStatusListener?) { + if (listener != null) { + micStatusListeners.remove(listener) + } + } + + private fun emitMicStatus(body: ByteArray, address: String) { + if (micStatusListeners.isEmpty()) { + return + } + val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" + else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?" + val copy = Arrays.copyOf(body, body.size) + mainHandler.post { + for (micListener in micStatusListeners) { + try { + micListener.onMicStatus(copy, arm) + } catch (t: Throwable) { + Log.w(TAG, "mic status listener failed", t) + } + } + } + } + + /** + * Queue a CFW mic_control record (['M','C',ver,op,...]) as a settings + * field-103 write to both temples, or to a single one. Fire-and-forget: + * the firmware answers with a field-104 status notify per temple, which + * arrives through addMicStatusListener. + */ + fun sendFaceclawMicControl(record: ByteArray?, label: String, rightTemple: Boolean, leftTemple: Boolean) { + if (record == null || record.size < 4) { + return + } + synchronized(lock) { + if (!running || !sessionReady) { + logLine("skip mic control ($label); session not ready") + return + } + if (rightTemple) { + pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, false)) + } + if (leftTemple) { + pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, true)) + } + logLine("queue mic control $label") + } + interruptibleSleep.interrupt() + } + + /** + * Forward render-characteristic audio packets to the listener WITHOUT + * sending the stock EvenHub audio-control enable. Used for the CFW + * mic_control streaming path, where capture is armed through settings + * field 103 and the temples emit 'SM' frames on the same characteristic + * that stock mono LC3 uses. Returns false when no session is up. + */ + fun startG2AudioForwarding(listener: FaceclawAudioPacketListener?): Boolean { + if (listener == null) { + throw IllegalArgumentException("listener is required") + } + synchronized(lock) { + if (!running || !sessionReady || shutdownRequested) { + logLine("skip G2 audio forwarding; session not ready") + return false + } + audioPacketListener = listener + audioCaptureActive = true + logLine("G2 audio forwarding enabled") + } + return true + } + + fun stopG2AudioForwarding() { + synchronized(lock) { + audioPacketListener = null + audioCaptureActive = false + logLine("G2 audio forwarding disabled") + } + } + + /** + * Subscribe to compass events. Callbacks are delivered on the Looper of + * the thread that registered (falling back to the main thread), so app + * worker isolates can listen without a cross-thread hop into their JS. + */ + fun addCompassListener(listener: FaceclawCompassListener?) { + if (listener == null) { + return + } + val looper = Looper.myLooper() + val handler = if (looper != null) Handler(looper) else mainHandler + compassSubscriptions.add(CompassSubscription(listener, handler)) + } + + fun removeCompassListener(listener: FaceclawCompassListener?) { + if (listener == null) { + return + } + for (subscription in compassSubscriptions) { + if (subscription.listener === listener) { + compassSubscriptions.remove(subscription) + } + } + } + + /** Set the compositor's output frame size. Call before configuring surfaces. */ + fun configureCompositorScreen(width: Int, height: Int) { + compositor.configureScreen(width, height) + } + + /** + * The current composited screen as a phone-UI preview bitmap, or null + * before any surface has been configured. Built from the compositor so + * the preview reflects every surface (chrome + whichever app is + * foreground), including worker-app frames the TS side never sees. + */ + fun getCompositePreviewBitmap(brightenGamma: Double): android.graphics.Bitmap? { + return getCompositePreviewBitmap(brightenGamma, false) + } + + /** As above; `green` renders the preview green-on-black (Settings > Phone display > Preview color). */ + fun getCompositePreviewBitmap(brightenGamma: Double, green: Boolean): android.graphics.Bitmap? { + val composite = compositor.previewComposite() ?: return null + return PreviewBitmapUtil.fromGray( + java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green) + } + + /** Save the current composite as a 4-bit grayscale PNG; returns the path or "". */ + @Throws(java.io.IOException::class) + fun saveCompositePngScreenshot(): String { + val composite = compositor.previewComposite() ?: return "" + return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height) + } + + /** + * Save the current composite cropped to the given screen rect (the region + * the shell says is actually occupied). The rect is clamped to the screen; + * a degenerate rect falls back to the full screen. + */ + @Throws(java.io.IOException::class) + fun saveCompositePngScreenshot(cropX: Int, cropY: Int, cropWidth: Int, cropHeight: Int): String { + val composite = compositor.previewComposite() ?: return "" + val x = Math.max(0, cropX) + val y = Math.max(0, cropY) + val width = Math.min(composite.width - x, cropWidth - (x - cropX)) + val height = Math.min(composite.height - y, cropHeight - (y - cropY)) + if (width <= 0 || height <= 0 || (x == 0 && y == 0 && width == composite.width && height == composite.height)) { + return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height) + } + val cropped = ByteArray(width * height) + for (row in 0 until height) { + System.arraycopy(composite.gray, (y + row) * composite.width + x, cropped, row * width, width) + } + return ScreenshotUtil.savePngScreenshot(appContext, cropped, width, height) + } + + /** Begin collecting composite frames for an animated-GIF screen recording. */ + fun startScreenRecording() { + screenRecorder = GifScreenRecorder() + } + + /** Capture the current composite into the active recording; no-op when idle. */ + fun recordScreenFrame() { + val recorder = screenRecorder ?: return + val composite = compositor.previewComposite() ?: return + recorder.addFrame(composite.gray, composite.width, composite.height, System.currentTimeMillis()) + } + + /** Finish the recording and save it as an animated GIF; returns the path or "". */ + @Throws(java.io.IOException::class) + fun stopScreenRecording(): String { + val recorder = screenRecorder + screenRecorder = null + if (recorder == null) { + return "" + } + if (recorder.isOverflowed()) { + logLine("screen recording hit its frame cap; the tail was dropped") + } + return recorder.save(appContext) + } + + /** + * Show or hide a compositor surface, immediately submitting the resulting + * frame. Recompositing here (rather than waiting for the next surface + * update) is what makes a just-foregrounded window's retained frame + * actually appear — otherwise a static window (e.g. the terminal hub) whose + * frame landed while briefly hidden would stay blank until its next repaint. + */ + fun setSurfaceVisible(id: String, visible: Boolean) { + // Its own frame: this recomposite is a real screen update with real + // latency, and without one it would show up in other frames' logs only + // as an anonymous "superseded by frame#0". + val frameId = FrameTimings.getInstance().startFrame( + "compositor:visible $id=$visible") + compositor.setSurfaceVisible(id, visible) + val composite = compositor.composite() + val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) + storeDesiredComposite(composite, packed, 0, frameId) + } + + /** + * Blank (screen off) or unblank the composited output, immediately + * submitting the resulting frame. Retained surface state is untouched, so + * unblanking restores the previous screen content without repaints. + */ + fun setScreenBlanked(blanked: Boolean) { + val frameId = FrameTimings.getInstance().startFrame( + "compositor:" + (if (blanked) "blank" else "unblank")) + compositor.setBlanked(blanked) + val composite = compositor.composite() + val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) + storeDesiredComposite(composite, packed, 0, frameId) + } + + /** + * Create or reconfigure a compositor surface. transparency is one of the + * SurfaceCompositor.TRANSPARENCY_* constants. Geometry changes take effect + * when the next frame is submitted. + */ + fun configureSurface(id: String?, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) { + compositor.configureSurface(id, x, y, width, height, zOrder, transparency) + } + + fun removeSurface(id: String) { + compositor.removeSurface(id) + } + + /** Stage an immutable shell snapshot alongside the retained app screen. */ + fun submitShellScene(bytes: java.nio.ByteBuffer, paintMs: Int, frameId: Int) { + compositor.setShellScene(AndroidByteReader(bytes)) + val composite = compositor.composite() + storeDesiredComposite(composite, BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height), paintMs, frameId) + } + + /** Legacy compositor dimming for callers without a shell scene. */ + fun setUnderlayDim(belowZOrder: Int, factor256: Int) { + compositor.setUnderlayDim(belowZOrder, factor256) + } + + /** + * Apply an update to one compositor surface and submit the recomposited + * screen as the desired frame. The update covers the rect (rectX, rectY, + * rectWidth, rectHeight) in surface-local coordinates; contentFingerprint + * identifies the surface's full content after the update. + * + * pixels8bpp arrives as a ByteBuffer because NativeScript marshals a JS + * ArrayBuffer to one without the per-element bridge copy that a byte[] + * parameter would need (~150ms for a full frame). + */ + fun submitSurfaceFrame( + pixels8bpp: java.nio.ByteBuffer, + surfaceId: String, + rectX: Int, + rectY: Int, + rectWidth: Int, + rectHeight: Int, + contentFingerprint: String?, + paintMs: Int, + frameId: Int + ) { + submitSurfaceFrame(pixels8bpp, surfaceId, rectX, rectY, rectWidth, rectHeight, + contentFingerprint, paintMs, frameId, null) + } + + /** + * As above, with the frame's glyph draws (see SurfaceCompositor's glyph + * overload for the buffer format): the surface's full text content as + * structured draws, letting the resource-cache planner ship glyphs as + * on-glasses cached draws instead of pixels. Null when the submitter has + * no glyph metadata; the pixels alone remain fully correct. + */ + fun submitSurfaceFrame( + pixels8bpp: java.nio.ByteBuffer, + surfaceId: String, + rectX: Int, + rectY: Int, + rectWidth: Int, + rectHeight: Int, + contentFingerprint: String?, + paintMs: Int, + frameId: Int, + glyphs: java.nio.ByteBuffer? + ) { + Log.i(TAG, "Received an updated frame for surface $surfaceId") + FrameTimings.getInstance().log(frameId, "surface " + surfaceId + " updated rect=" + + rectWidth + "x" + rectHeight + "+" + rectX + "+" + rectY + + (if (glyphs == null) " (no glyph draws)" else "")) + FrameTimings.getInstance().spanStart(frameId, "composite") + val composite = compositor.applyAndComposite( + surfaceId, AndroidByteReader(pixels8bpp), rectX, rectY, rectWidth, rectHeight, contentFingerprint, + if (glyphs == null) null else AndroidByteReader(glyphs)) + FrameTimings.getInstance().spanEnd(frameId, "composite") + // Pack the composited 8bpp buffer down to the headerless 4bpp frame + // format the wire planners consume; BMP framing is added later only for + // the uncompressed fallback. + FrameTimings.getInstance().spanStart(frameId, "pack-4bpp") + val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) + FrameTimings.getInstance().spanEnd(frameId, "pack-4bpp") + storeDesiredComposite(composite, packed, paintMs, frameId) + } + + /** Store a composite as the desired frame unless a newer one won the race. */ + private fun storeDesiredComposite(composite: SurfaceCompositor.Composite, packed: ByteArray, paintMs: Int, frameId: Int) { + var supersededFrameId = 0 + var stale = false + synchronized(desiredTilesLock) { + if (composite.seq <= lastStoredCompositeSeq) { + // A concurrent submission composited after us and stored first; + // its composite already includes this surface update. + stale = true + } else { + lastStoredCompositeSeq = composite.seq + supersededFrameId = desiredFrameId + desiredPacked = packed + desiredWidth = composite.width + desiredHeight = composite.height + desiredFingerprint = composite.fingerprint + desiredPaintMs = paintMs + desiredFrameId = frameId + desiredDraws = composite.draws + desiredShellScene = composite.shellScene + } + } + if (stale) { + finishFrame(frameId, "discarded: composite superseded before store") + return + } + if (supersededFrameId != 0 && supersededFrameId != frameId) { + finishFrame(supersededFrameId, "discarded: superseded by frame#$frameId before send") + } + FrameTimings.getInstance().log(frameId, "image submitted as desired frame") + interruptibleSleep.interrupt() + } + + /** + * Play a tone sequence via CFW load_image_z mode 5 kind 4. The payload is + * the complete wire buffer ([5][4][nSteps][freqLo,freqHi,duty,msLo,msHi]*n, + * up to 48 steps), built on the TS side; it rides the arbitrary-payload + * image path like the other mode-5 controls. + */ + fun playBuzzerSequence(payload: java.nio.ByteBuffer?) { + synchronized(lock) { + if (!running || !sessionReady || !fixedLayoutCreated) { + logLine("skip buzzer sequence; session not ready") + return + } + val bytes = ByteArray(if (payload == null) 0 else payload.remaining()) + if (payload != null) { + payload.get(bytes) + } + if (bytes.size < 3) { + logLine("skip buzzer sequence; empty payload") + return + } + val message = messageBuilder.imagePayload( + DASHBOARD_TILE, + nextMapSessionId(), + bytes, + "buzzer sequence " + bytes.size + "B", + connectionOptions.sendImagesToLeft + ) + message.onTimeout = MessageCallback { + handleTransportFailure("buzzer sequence ack timeout") + } + pendingMessages.addLast(message) + logLine("queue " + message.label) + } + interruptibleSleep.interrupt() + } + + fun sendShutdown(exitMode: Int): Boolean { + return sendShutdownInternal(exitMode, true) + } + + /** + * Send CFW image-handler mode 11 after quiescing normal traffic. A successful + * return means the cleanup was ACKed and no later Faceclaw message should be + * emitted before closing BLE. Unsupported/older CFWs return false so callers + * can use the legacy shutdown-and-lease-release path. + */ + fun sendCfwCleanup(): Boolean { + val magic: Int + synchronized(lock) { + if (cfwCleanupDelivered) { + return true + } + if (!customFirmwareDetected || !running || !sessionReady + || shutdownRequested || !fixedLayoutCreated) { + logLine("skip CFW cleanup; mode 11 unavailable or image path not ready") + return false + } + + /* Stop auto-renewals, heartbeats, image generation, and control + * retries, then discard everything that has not reached BLE yet. */ + shutdownRequested = true + lastCfwCleanupAckMagic = 0 + clearPendingMessagesLocked("CFW cleanup requested") + logLine("quiescing transport for CFW cleanup") + } + interruptibleSleep.interrupt() + + /* WINDOW_SIZE can exceed one, so merely appending cleanup would allow it + * to overlap previously-written image fragments. Wait until all of those + * ACK or time out; shutdownRequested prevents the drive loop from adding + * any fresh automatic traffic meanwhile. */ + val drainDeadline = SystemClock.elapsedRealtime() + CFW_CLEANUP_WAIT_MS + synchronized(lock) { + while (running && sessionReady && !inFlightMessages.isEmpty()) { + val remaining = drainDeadline - SystemClock.elapsedRealtime() + if (remaining <= 0) break + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + break + } + } + if (!running || !sessionReady || !inFlightMessages.isEmpty()) { + shutdownRequested = false + logLine("CFW cleanup could not drain prior traffic") + return false + } + + /* External producers are expected to be stopped by the caller, but + * clear once more at the barrier so cleanup is definitely last. */ + clearPendingMessagesLocked("CFW cleanup barrier") + val message = messageBuilder.cfwCleanup( + DASHBOARD_TILE, + nextMapSessionId(), + connectionOptions.sendImagesToLeft + ) + magic = message.magic + message.onAck = MessageCallback { + lastCfwCleanupAckMagic = message.magic + cfwCleanupDelivered = true + compassMaybeOn = false + faceclawWakeLeaseEnabled = false + logLine("CFW cleanup completed") + } + message.onTimeout = MessageCallback { logLine("CFW cleanup ack timeout") } + pendingMessages.addLast(message) + logLine("queue CFW cleanup") + } + interruptibleSleep.interrupt() + + val deadline = SystemClock.elapsedRealtime() + CFW_CLEANUP_WAIT_MS + synchronized(lock) { + while (running + && sessionReady + && lastCfwCleanupAckMagic != magic + && hasPendingOrInflightMagicLocked(magic)) { + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) break + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + break + } + } + val acked = lastCfwCleanupAckMagic == magic + if (!acked) shutdownRequested = false + return acked + } + } + + /** + * End the EvenHub page while retaining both arm GATT connections and all + * notification subscriptions. A missed ACK is intentionally non-fatal: + * reconnecting Bluetooth here would defeat the power-saving mode. + */ + fun suspendEvenHubSession(): Boolean { + // Ending the plugin task releases the fb lease, which frees the + // on-glasses resource cache; forget it phone-side either way (a lost + // ack may still have taken effect). + synchronized(lock) { + resourceCache.reset() + } + if (sendShutdownInternal(0, false)) { + return true + } + synchronized(lock) { + // A shutdown ACK can be lost even though the command took effect. + // If the transport remains intentionally quiesced, callers still + // need to remember to run the resume path on the next wake. + return running && sessionReady && shutdownRequested + } + } + + /** + * Start a fresh EvenHub plugin task on the existing BLE transport, then let + * the session driver create the layout, warm up the image path, and send + * the desired frame. + */ + fun resumeEvenHubSession(): Boolean { + var claimGeneration = 0 + synchronized(lock) { + if (!running || !sessionReady || chargingMode) { + logLine("skip EvenHub resume; transport not ready") + return false + } + if (!shutdownRequested) { + return true + } + if (faceclawWakePendingNonce >= 0 + && hasPendingOrInflightKindLocked("wake-lease-control")) { + claimGeneration = faceclawWakeControlGeneration + } + logLine("replaying session prelude for EvenHub resume") + } + + // A custom double-tap wake has only a short unclaimed fail-open + // deadline. Let the worker put CLAIM on both arms before the direct + // prelude write begins. + if (claimGeneration != 0) { + waitForFaceclawWakeControlDelivery(claimGeneration, 500) + } + + try { + // Empty-name Cmd=9 tears down the whole plugin task, not just its + // image container. Re-run the launch prelude before Cmd=0 CREATE. + sendPrelude(true) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + handleTransportFailure("EvenHub resume prelude interrupted") + return false + } catch (t: Throwable) { + logLine("EvenHub resume prelude failed: " + safeMessage(t)) + handleTransportFailure("EvenHub resume prelude failed") + return false + } + + synchronized(lock) { + if (!running || !sessionReady || chargingMode) { + return false + } + shutdownRequested = false + fixedLayoutCreated = false + startupProbePending = false + audioCaptureActive = false + clearAllMessagesPreservingWakeLeaseLocked("EvenHub resume") + displayedFingerprint = "" + imageRetryAfterMs = 0 + lastHeartbeatSentAtMs = 0 + lastHeartbeatAckedAtMs = 0 + logLine("EvenHub session resume requested") + } + interruptibleSleep.interrupt() + return true + } + + private fun sendShutdownInternal(exitMode: Int, reconnectOnTimeout: Boolean): Boolean { + val magic: Int + val startedAtMs = SystemClock.elapsedRealtime() + synchronized(lock) { + if (!running || !sessionReady) { + logLine("skip shutdown; session not ready") + return false + } + if (shutdownRequested) { + return true + } + shutdownRequested = true + // Magic values wrap, so an ACK from a much older suspend must not + // satisfy this request after enough sleep/wake cycles. + lastShutdownAckMagic = 0 + clearPendingMessagesLocked("shutdown requested") + val message = messageBuilder.shutdown(exitMode) + magic = message.magic + message.onAck = MessageCallback { + lastShutdownAckMagic = message.magic + fixedLayoutCreated = false + displayedFingerprint = "" + } + message.onTimeout = MessageCallback { + if (reconnectOnTimeout) { + handleTransportFailure("shutdown ack timeout") + } else { + logLine("EvenHub shutdown ack timeout; keeping BLE connected") + } + } + pendingMessages.addFirst(message) + logLine("queue shutdown") + // The stock compass keeps the magnetometer sampling independently of + // the plugin task, so ending the page does not stop it. Force a + // disable ahead of the shutdown command whenever it may be running: + // this also covers a disable that was wiped by the queue flush above + // or whose ack was lost, and the charging-mode/exit paths where the + // Compass window never got a chance to release it. + if (compassMaybeOn && fixedLayoutCreated) { + enqueueCompassControlLocked(true, false) + } + } + interruptibleSleep.interrupt() + + val ackDeadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + 500 + synchronized(lock) { + while (running + && sessionReady + && lastShutdownAckMagic != magic + && lastShutdownExitAtMs < startedAtMs + && hasPendingOrInflightMagicLocked(magic)) { + val remaining = ackDeadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + break + } + } + val acked = lastShutdownAckMagic == magic + if (acked) { + val exitDeadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + 500 + while (running && sessionReady && lastShutdownExitAtMs < startedAtMs) { + val remaining = exitDeadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + break + } + } + } + return acked || lastShutdownExitAtMs >= startedAtMs + } + } + + private fun waitForAudioControlAck(magic: Int, operation: String): Boolean { + val deadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + ConnectionOptions.WRITE_TIMEOUT_MS + 500 + synchronized(lock) { + while (running && sessionReady && lastAudioControlAckMagic != magic && hasPendingOrInflightMagicLocked(magic)) { + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + break + } + } + val acked = lastAudioControlAckMagic == magic + if (!acked) { + if ("enable" == operation) { + audioPacketListener = null + audioCaptureActive = false + } + logLine("G2 mic $operation ack timeout") + } + return acked + } + } + + + override fun run() { + logLine(String.format(Locale.US, "communicator start R=%s L=%s ring=%s", rightAddress, leftAddress, ringAddress)) + while (true) { + try { + if (!running) { + Log.w(TAG, "Exiting event looop") + break + } + emitPhoneLockStateIfChanged(false) + if (!sessionReady) { + if (reconnectHalted) { + interruptibleSleep.sleep(ConnectionOptions.IDLE_SLEEP_MS.toLong()) + continue + } + val now = SystemClock.elapsedRealtime() + if (now < reconnectAfterMs) { + interruptibleSleep.sleep(Math.min(ConnectionOptions.IDLE_SLEEP_MS.toLong(), reconnectAfterMs - now)) + continue + } + Log.w(TAG, "Attempting to connect") + connectLoopOnce() + continue + } + + if (shouldAttemptRingConnect()) { + tryConnectRing("retry") + continue + } + + val sleepMs = driveSession() + if (sleepMs > 0) { + interruptibleSleep.sleep(sleepMs) + } + } catch (t: Throwable) { + logLine("communicator loop error: " + safeMessage(t)) + handleTransportFailure("loop error") + } + } + logLine("communicator stop") + } + + override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { + if (address == null || characteristicUuid == null || data == null) { + return + } + val uuid = characteristicUuid.lowercase(Locale.US) + if (isDirectRingNotification(address, uuid)) { + handleDirectRingNotification(uuid, data) + return + } + if (BleProtocol.RENDER_NOTIFY_UUID == uuid) { + handleRenderNotification(address, data) + return + } + if (BleProtocol.NOTIFY_CHAR_UUID != uuid) { + return + } + if (data.size >= 7 && (data[6].toInt() and 255) == CfwTransport.SID) { + val acks = CfwTransport.parseAcks(data) ?: return + synchronized(lock) { + lastIncomingAtMs = SystemClock.elapsedRealtime() + for (ack in acks) { + for (message in inFlightMessages) { + val ingress = if (message.isLeftArmMessage) leftAddress else rightAddress + if (message.sid == CfwTransport.SID && address.equals(ingress, ignoreCase = true) && message.magic == ack.streamId) { + message.acceptCfwAck(ack) + Log.i(TAG, "CFW " + (if (ack.nack) "NACK" else "ACK") + " id=" + ack.streamId + + " ordinal=" + ack.messageId + " lens=" + ack.lens + " txseq=" + (data[2].toInt() and 255) + + " redundant=" + (ack !== acks[0]) + + " size=" + ack.size + " crc=" + ack.checksum + + " expected=" + message.message.size + "/" + message.cfwChecksum + + " ackedLenses=" + message.cfwAckLenses + + " ageMs=" + (lastIncomingAtMs - message.sentAtMs)) + message.ackPayload = Arrays.copyOf(data, data.size) + break + } + } + } + drainCfwAcknowledgementsLocked() + } + interruptibleSleep.interrupt() + return + } + Log.d(TAG, "onNotification: address=" + address + " characteristicUuid=" + characteristicUuid + " data.length=" + data.size) + val frame = BleProtocol.parseFrame(data) + val decodedWearState = BleProtocol.parseWearState(frame) + val compassEvent = if (address.equals(rightAddress, ignoreCase = true)) + BleProtocol.parseCompassEvent(frame) + else + null + var emitWearState = false + var event: G2Event? = null + synchronized(lock) { + lastIncomingAtMs = SystemClock.elapsedRealtime() + if (decodedWearState >= 0 && decodedWearState != wearState) { + wearState = decodedWearState + emitWearState = true + } + var faceclawWakeNotification = false + if (shutdownRequested + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING + && address.equals(rightAddress, ignoreCase = true)) { + val wakeNonce = BleProtocol.parseFaceclawWakeEvent(frame.pb) + if (wakeNonce >= 0) { + faceclawWakePendingNonce = wakeNonce + enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_CLAIM, + wakeNonce, + true + ) + faceclawWakeNotification = true + lastConnectionOrInputAtMs = lastIncomingAtMs + // The event type says which gesture woke the glasses: TS + // gives a head-up the Glanceboard and a double tap the + // regular UI. The claim handshake is the same for both. + val headUp = BleProtocol.parseFaceclawWakeEventCode(frame.pb) == + BleProtocol.FACECLAW_WAKE_EVENT_HEAD_UP + event = G2Event( + "display-wake", + "", + if (headUp) BleProtocol.EVENT_HEAD_UP else BleProtocol.EVENT_DOUBLE_CLICK, + 0, + 0 + ) + logLine("claimed deferred dashboard wake nonce=" + wakeNonce + + (if (headUp) " (head-up)" else "")) + } + } + if (!faceclawWakeNotification + && shutdownRequested + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING + && address.equals(rightAddress, ignoreCase = true)) { + // CFW idle-gesture forwarding (firmware revision 2+): with no + // EvenHub page the stock display thread drops taps, long + // presses and releases; the CFW reports them on the settings + // sid while our wake lease is held. Deliver them as the + // sys-events a live page would have produced, so TS treats a + // sleep-time tap or hold exactly like one during soft sleep + // (the Glanceboard). + val gesture = BleProtocol.parseFaceclawGestureEvent(frame.pb) + if (gesture != null) { + lastConnectionOrInputAtMs = lastIncomingAtMs + event = G2Event("sys-event", "", gesture.eventType, gesture.eventSource, 0) + logLine("idle gesture forwarded by CFW: type=" + gesture.eventType + + " source=" + gesture.eventSource) + } + } + if (!faceclawWakeNotification + && event == null + && shutdownRequested + && address.equals(rightAddress, ignoreCase = true) + && BleProtocol.isDisplayWakeStateChange(frame)) { + // With no EvenHub page, ring/arm double-taps are handled by the + // stock display lifecycle and surface only as this state ping. + // Translate it back into an input event so TS can wake the shell + // and recreate the page. + event = G2Event( + "display-wake", + "", + BleProtocol.EVENT_DOUBLE_CLICK, + 0, + 0 + ) + } + if (!faceclawWakeNotification + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING) { + // Mode-17 query notifications; settings READs are handled by + // createBatteryQueryMessageLocked so headset/ring update together. + if (address.equals(rightAddress, ignoreCase = true) + && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { + val ring = BleProtocol.parseRingBattery(frame.pb) + if (ring != null) { + ringBattery = ring.battery + ringCharging = ring.charging + emitBatteryState(headsetBattery, headsetCharging) + } + } + // CFW mic status (field 104) rides both standalone pushes and + // settings read acks, from each temple on its own link. + val micStatus = BleProtocol.parseFaceclawMicStatus(frame.pb) + if (micStatus != null) { + emitMicStatus(micStatus, address) + } + } + if (!faceclawWakeNotification + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING) { + // CFW ambient-light report (field 105) from the master temple. + val alsReport = BleProtocol.parseFaceclawAlsReport(frame.pb) + if (alsReport != null) { + emitAmbientLight(alsReport) + } + } + if (!faceclawWakeNotification + && decodedWearState < 0 + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING) { + // Device-initiated settings push. It carries a magic the glasses + // chose, so it would otherwise fall through to resolveAckLocked, + // match nothing, and be logged as an unexpected ack. + val pushedSilentMode = BleProtocol.parseSilentModePush(frame.pb) + if (pushedSilentMode >= 0) { + updateSilentModeLocked(pushedSilentMode > 0) + return + } + } + if (!faceclawWakeNotification + && decodedWearState < 0 + && frame.ok + && frame.msgSeq >= 0 + && frame.flag != BleProtocol.FLAG_NOTIFY + && frame.flag != BleProtocol.FLAG_NOTIFY_ALT) { + lastAckAtMs = lastIncomingAtMs + resolveAckLocked(frame.sid, frame.msgSeq, frame.pb) + } + if (!faceclawWakeNotification + && event == null + && frame.ok + && address.equals(rightAddress, ignoreCase = true) + && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { + var decoded = G2Event.decode(frame) + if (decoded != null + && "sys-event" == decoded.kind + && decoded.eventType == BleProtocol.EVENT_HEAD_UP) { + // CFW forwards the IMU head-up while our page is on screen + // (soft sleep). Surface it as the same wake-only input the + // deferred head-up wake produces from a dark display. + decoded = G2Event("display-wake", "", BleProtocol.EVENT_HEAD_UP, decoded.eventSource, 0) + logLine("head-up forwarded by CFW while page on screen") + } + event = decoded + if (decoded != null) { + // Pure IMU samples arrive continuously; don't let them count + // as user input (which would starve battery polling). + val pureImuSample = "sys-event" == decoded.kind + && decoded.eventType == BleProtocol.EVENT_IMU_DATA_REPORT + if (!pureImuSample) { + lastConnectionOrInputAtMs = lastIncomingAtMs + } + if ("list-click" == decoded.kind || "text-click" == decoded.kind) { + // Container-routed touchpad input reached us, so the + // firmware is dispatching input: silent mode is off, + // whether or not its end-of-silent push arrived. + updateSilentModeLocked(false) + } + if ("sys-event" == decoded.kind) { + if (decoded.eventType == BleProtocol.EVENT_FOREGROUND_EXIT || decoded.eventType == BleProtocol.EVENT_ABNORMAL_EXIT || decoded.eventType == BleProtocol.EVENT_SYSTEM_EXIT) { + if (shutdownRequested) { + lastShutdownExitAtMs = SystemClock.elapsedRealtime() + } + fixedLayoutCreated = false + displayedFingerprint = "" + clearAllMessagesLocked("firmware exit event") + } + } + } + } + } + interruptibleSleep.interrupt() + if (emitWearState) { + logLine(if (decodedWearState > 0) "wear state ON_HEAD" else "wear state OFF_HEAD") + emitWearState(decodedWearState > 0) + } + if (compassEvent != null) { + emitCompassEvent(compassEvent) + } + val finalEvent = event + if (finalEvent != null) { + if (finalEvent.hasImu) { + emitImuData(finalEvent.imuX, finalEvent.imuY, finalEvent.imuZ, finalEvent.eventSource) + } + // A standalone IMU_DATA_REPORT is a sensor sample, not a gesture: + // deliver it only to IMU listeners, skipping the input pipeline (and + // its per-frame latency bookkeeping) to avoid flooding it. + val pureImuSample = "sys-event" == finalEvent.kind + && finalEvent.eventType == BleProtocol.EVENT_IMU_DATA_REPORT + if (!pureImuSample) { + val frameId = FrameTimings.getInstance().startFrame( + "input:" + finalEvent.kind + " type=" + finalEvent.eventType + " src=" + finalEvent.eventSource) + FrameTimings.getInstance().log(frameId, "input event decoded from BLE notification") + emitRingEvent(finalEvent, frameId) + } + } + } + + private fun handleDirectRingNotification(characteristicUuid: String, data: ByteArray) { + val decoded = FaceclawRingEventDecoder.decode(data) + if (decoded == null) { + Log.d(TAG, "direct ring notify ignored: characteristicUuid=" + characteristicUuid + " raw=" + hex(data)) + return + } + + val event = decoded.event + val arrivalMs = SystemClock.elapsedRealtime() + synchronized(lock) { + lastIncomingAtMs = arrivalMs + lastConnectionOrInputAtMs = arrivalMs + } + logLine("direct ring " + decoded.label + " " + decoded.detail + " raw=" + hex(data)) + val frameId = FrameTimings.getInstance().startFrame("input:ring:" + decoded.label) + FrameTimings.getInstance().log(frameId, "input event decoded from direct ring notification") + emitRingEvent(event, frameId) + interruptibleSleep.interrupt() + } + + private fun handleRenderNotification(address: String, data: ByteArray) { + val listenerToCall: FaceclawAudioPacketListener? + val arrivalMs = SystemClock.elapsedRealtime() + synchronized(lock) { + lastIncomingAtMs = arrivalMs + listenerToCall = if (audioCaptureActive) audioPacketListener else null + } + if (listenerToCall == null) { + return + } + val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?" + try { + listenerToCall.onAudioPacket(Arrays.copyOf(data, data.size), arm, arrivalMs) + } catch (t: Throwable) { + logLine("G2 mic packet listener failed: " + safeMessage(t)) + } + } + + override fun onConnectionStateChange(address: String?, connected: Boolean) { + synchronized(lock) { + if (address == null) { + return + } + if (isConfiguredRingAddress(address)) { + ringConnected = connected + ringNotificationsReady = false + if (!connected) { + ringReconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RING_RECONNECT_DELAY_MS + } + logLine(if (connected) "direct ring BLE connected" else "direct ring BLE disconnected") + return + } + if (address.equals(rightAddress, ignoreCase = true)) { + rightConnected = connected + } else if (address.equals(leftAddress, ignoreCase = true)) { + leftConnected = connected + } else { + return + } + if (!connected) { + sessionReady = false + fixedLayoutCreated = false + startupProbePending = false + chargingMode = false + audioCaptureActive = false + audioPacketListener = null + clearAllMessagesLocked("connection lost") + displayedFingerprint = "" + if (!reconnectHalted) { + reconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RECONNECT_DELAY_MS + } + } + } + interruptibleSleep.interrupt() + if (connected) { + setStateDisplay("connected", "Connected.") + } else if (!reconnectHalted) { + // While parked on a missing bond, keep the "unpaired" display: this + // callback is just the teardown of the arm that did connect. + setStateDisplay("connecting", "Connecting to the glasses...") + } + } + + @Throws(InterruptedException::class) + private fun connectLoopOnce() { + setStateDisplay("connecting", "Connecting to the glasses...") + try { + connectArm(rightAddress, true) + connectArm(leftAddress, true) + if (!sleepDuringConnectSettling(800)) { + return + } + authenticateArms() + sendPrelude() + + synchronized(lock) { + sessionReady = true + // A fresh transport prelude always starts an active EvenHub + // lifecycle, even if the previous connection dropped while + // its page was intentionally suspended. + shutdownRequested = false + fixedLayoutCreated = false + clearAllMessagesLocked("session ready") + displayedFingerprint = "" + lastAckAtMs = SystemClock.elapsedRealtime() + lastIncomingAtMs = lastAckAtMs + lastConnectionOrInputAtMs = lastAckAtMs + lastSessionReadyAtMs = lastAckAtMs + lastBatteryRefreshAtMs = 0 + imageRetryAfterMs = 0 + lastHeartbeatSentAtMs = 0 + lastHeartbeatAckedAtMs = 0 + consecutiveAckTimeouts = 0 + lastAudioControlAckMagic = 0 + audioCaptureActive = false + faceclawWakePendingNonce = -1 + cfwCleanupDelivered = false + for (transport in cfwTransports) transport.reset() + lastCfwCleanupAckMagic = 0 + lastFaceclawWakeLeaseQueuedAtMs = 0 + lastFaceclawFramebufferLeaseQueuedAtMs = 0 + enqueueFaceclawFramebufferControlLocked( + BleProtocol.FACECLAW_FB_OP_ACQUIRE, + true + ) + if (faceclawWakeLeaseEnabled) { + enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, + 0, + true + ) + } + } + setStateDisplay("connected", "Connected.") + logLine("session ready") + synchronized(lock) { + // Query settings promptly on the first session so firmware + // version/extension (and battery) arrive without waiting for + // the input-quiet battery poll. The settings response doubles as + // the firmware-compatibility check surfaced during onboarding. + if (!firmwareInfoQueried) { + firmwareInfoQueried = true + lastBatteryRefreshAtMs = SystemClock.elapsedRealtime() + pendingMessages.addLast(createBatteryQueryMessageLocked()) + logLine("queue settings query for firmware info") + } + } + tryConnectRing("initial") + } catch (t: Throwable) { + logLine("connect failed: " + safeMessage(t)) + val unpairedArm = firstUnpairedArm() + if (unpairedArm != null) { + handleUnpairedFailure(unpairedArm) + } else { + handleTransportFailure("connect failed") + } + } + } + + @Throws(InterruptedException::class) + private fun sleepDuringConnectSettling(delayMs: Long): Boolean { + val deadline = SystemClock.elapsedRealtime() + delayMs + synchronized(lock) { + while (running && !userDisconnectRequested) { + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + return true + } + lock.wait(Math.min(remaining, 100L)) + } + return false + } + } + + private fun connectArm(address: String, enableRenderNotify: Boolean) { + if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { + throw IllegalStateException("connect failed: $address") + } + // requestConnectionPriority has no callback in this Android compile target, so there is + // no reliable completion point to keep it in the global GATT operation pipeline. But it's + // important enough for performance that we call it anyways. + bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) + + bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) + + if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { + throw IllegalStateException("discoverServices failed: $address") + } + if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { + throw IllegalStateException("enableNotifications failed: " + address + " " + BleProtocol.NOTIFY_CHAR_UUID) + } + if (enableRenderNotify) { + bleManager.enableNotifications(address, BleProtocol.RENDER_NOTIFY_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS) + } + synchronized(lock) { + if (address.equals(rightAddress, ignoreCase = true)) { + rightConnected = true + } else if (address.equals(leftAddress, ignoreCase = true)) { + leftConnected = true + } + } + } + + private fun shouldAttemptRingConnect(): Boolean { + if (!hasRingAddress()) { + return false + } + val now = SystemClock.elapsedRealtime() + synchronized(lock) { + return running + && sessionReady + && !ringNotificationsReady + && now >= ringReconnectAfterMs + && pendingMessages.isEmpty() + && inFlightMessages.isEmpty() + } + } + + private fun tryConnectRing(reason: String) { + if (!hasRingAddress()) { + return + } + try { + connectRing() + } catch (t: Throwable) { + synchronized(lock) { + ringConnected = false + ringNotificationsReady = false + ringReconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RING_RECONNECT_DELAY_MS + } + logLine("direct ring connect failed (" + reason + "): " + safeMessage(t)) + } + } + + private fun connectRing() { + logLine("connecting direct ring $ringAddress") + if (!bleManager.connect(ringAddress, ConnectionOptions.CONNECT_TIMEOUT_MS)) { + throw IllegalStateException("connect failed: $ringAddress") + } + + bleManager.requestConnectionPriority(ringAddress, BluetoothGatt.CONNECTION_PRIORITY_HIGH) + bleManager.requestMtu(ringAddress, ConnectionOptions.RING_DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) + + if (!bleManager.discoverServices(ringAddress, ConnectionOptions.SERVICES_TIMEOUT_MS)) { + throw IllegalStateException("discoverServices failed: $ringAddress") + } + + val phoneNotify = enableRingNotification(BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID) + val dataNotify = enableRingNotification(BleProtocol.R1_NOTIFY_CHAR_UUID) + if (!phoneNotify && !dataNotify) { + throw IllegalStateException("no R1 notify characteristic subscribed") + } + + synchronized(lock) { + ringConnected = true + ringNotificationsReady = true + ringReconnectAfterMs = 0 + } + logLine("direct ring ready phoneNotify=$phoneNotify dataNotify=$dataNotify") + } + + private fun enableRingNotification(characteristicUuid: String): Boolean { + try { + return bleManager.enableNotifications( + ringAddress, + characteristicUuid, + true, + ConnectionOptions.DESCRIPTOR_TIMEOUT_MS + ) + } catch (t: Throwable) { + Log.d(TAG, "direct ring notify subscribe skipped: " + characteristicUuid + " " + safeMessage(t)) + return false + } + } + + /** + * Complete the sid-0x80 security-auth exchange on both freshly opened arm + * connections. Firmware 2.2.9 answers no queries until it completes over an + * encrypted link and closes unauthenticated links after ~30 s (see + * ../notes/ble-connections-2.2.9.md); on an unbonded phone the exchange is + * also what triggers SMP pairing. Deliberately soft: on timeout we log and + * continue rather than fail the connect — the custom firmware's response + * behavior is not yet hardware-verified, and on stock firmware an + * unanswered auth just means the prelude fails exactly as it did before. + * A pairing prompt accepted after our window still bonds at the OS level, + * so the next reconnect attempt authenticates promptly. + */ + @Throws(InterruptedException::class) + private fun authenticateArms() { + val right = messageBuilder.securityAuth(false) + val left = messageBuilder.securityAuth(true) + val now = SystemClock.elapsedRealtime() + for (message in arrayOf(right, left)) { + message.onAck = MessageCallback { + } + message.onTimeout = MessageCallback { + } + message.sentAtMs = now + writeMessage(message) + } + val deadline = SystemClock.elapsedRealtime() + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS + while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { + synchronized(lock) { + if (!running || userDisconnectRequested || inFlightMessages.isEmpty()) { + break + } + } + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + interruptibleSleep.sleep(Math.min(remaining, 100L)) + } + synchronized(lock) { + if (!inFlightMessages.isEmpty()) { + clearInFlightMessagesLocked("security auth timeout") + logLine("security auth not acknowledged; continuing (2.2.9 stock requires it; older/custom firmware may not answer)") + return + } + } + val rightOk = BleProtocol.isAuthenticationSuccess(right.ackPayload, right.magic) + val leftOk = BleProtocol.isAuthenticationSuccess(left.ackPayload, left.magic) + logLine("security auth R=" + (if (rightOk) "ok" else "unconfirmed") + " L=" + (if (leftOk) "ok" else "unconfirmed")) + } + + @Throws(InterruptedException::class) + private fun sendPrelude() { + sendPrelude(false) + } + + @Throws(InterruptedException::class) + private fun sendPrelude(preserveWakeLeaseControls: Boolean) { + synchronized(lock) { + if (preserveWakeLeaseControls) { + clearAllMessagesPreservingWakeLeaseLocked("prelude") + } else { + clearAllMessagesLocked("prelude") + } + } + val now = SystemClock.elapsedRealtime() + val prelude = messageBuilder.prelude() + prelude.onAck = MessageCallback { + } + prelude.onTimeout = MessageCallback { + handleTransportFailure("ack timeout") + } + prelude.sentAtMs = now + writeMessage(prelude) + + val deadline = SystemClock.elapsedRealtime() + ConnectionOptions.PRELUDE_TIMEOUT_MS + while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { + synchronized(lock) { + if (!running || userDisconnectRequested || inFlightMessages.isEmpty()) { + break + } + } + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + interruptibleSleep.sleep(Math.min(remaining, 100L)) + } + synchronized(lock) { + if (!inFlightMessages.isEmpty()) { + clearInFlightMessagesLocked("prelude timeout") + throw IllegalStateException("prelude ack timeout") + } + } + } + + private fun driveSession(): Long { + //Log.d(TAG, "driveSession called (pendingMessages.size=" + pendingMessages.size() + " inFlightMessages.size=" + inFlightMessages.size() + ")"); + while (true) { + // Run on the sender thread, outside `lock`: Bluetooth API calls can + // wait on the global GATT lock, and callbacks need the session lock. + // Keep negotiation outside the timed stream. A fixed settling period + // is only an experiment boundary; HCI must confirm actual parameters. + var linkMode = -1 + var benchmarkAddresses: Array? = null + synchronized(lock) { + if (benchmarkActive && benchmarkLinkPending) { + benchmarkLinkPending = false + linkMode = benchmarkLinkMode + benchmarkAddresses = arrayOf(leftAddress, rightAddress) + } + } + val addressesToPrepare = benchmarkAddresses + if (addressesToPrepare != null) { + for (address in addressesToPrepare) { + try { + bleManager.prepareBenchmarkLink(address, linkMode) + } catch (error: RuntimeException) { + logLine("benchmark link request failed: " + safeMessage(error)) + } + } + synchronized(lock) { + // Cancellation/new-run races leave the new run pending; its + // own preparation will replace this deadline before sending. + benchmarkReadyAtMs = SystemClock.elapsedRealtime() + 1_000 + } + } + var messageToWrite: OutboundMessage? = null + var messageToPrewrite: OutboundMessage? = null + val now = SystemClock.elapsedRealtime() + + maybeFinishNoChangeDesiredFrame() + + synchronized(lock) { + drainCfwAcknowledgementsLocked() + if (cfwCleanupDelivered) { + /* Successful mode 11 must be the last Faceclaw write. Drop + * anything a late external producer attempted to enqueue + * while DashboardController was closing the transport. */ + clearPendingMessagesLocked("after CFW cleanup") + return 250 + } + if (sessionReady + && now - lastFaceclawFramebufferLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS + && !hasPendingOrInflightKindLocked("framebuffer-lease-control")) { + enqueueFaceclawFramebufferControlLocked( + BleProtocol.FACECLAW_FB_OP_ACQUIRE, + false + ) + } + if (faceclawWakeLeaseEnabled + && sessionReady + && now - lastFaceclawWakeLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS + && !hasPendingOrInflightKindLocked("wake-lease-control")) { + enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, + 0, + false + ) + } + if (!inFlightMessages.isEmpty()) { + val oldest = inFlightMessages.peekFirst() + val replay = CfwMessageWindow.replayWindow(inFlightMessages, now) + if (!replay.isEmpty()) { + logLine("CFW recovery: replay " + replay.size + + " unresolved message(s) from id=" + replay[0].magic) + for (candidate in replay) { + if (candidate.cfwRetries >= CfwMessageWindow.MAX_RETRIES) { + handleTransportFailure("CFW recovery retry limit") + return 0 + } + logLine("CFW replay id=" + candidate.magic + " label=" + candidate.label + + " cause=" + (if (candidate.cfwRetryPending) "NACK" + else if (candidate.cfwAckLenses == CfwTransport.BOTH) "ordered tail" else "missing ACK") + + " ackedLenses=" + candidate.cfwAckLenses + + " ageMs=" + (now - candidate.sentAtMs)) + inFlightMessages.remove(candidate) + magicPool.release(candidate.sid, candidate.magic, candidate.label, "CFW replay") + candidate.prepareCfwReplay(magicPool.allocate()) + } + for (i in replay.indices.reversed()) pendingMessages.addFirst(replay[i]) + return 0 + } + if (oldest != null && oldest.ackDeadlineAtMs <= now) { + Log.i(TAG, "message timed out: " + oldest.label) + inFlightMessages.removeFirst() + logLine("message timed out: " + oldest.label + " sid=" + oldest.sid + + " id=" + oldest.magic + " ackedLenses=" + oldest.cfwAckLenses + + " ageMs=" + (now - oldest.sentAtMs)) + magicPool.release(oldest.sid, oldest.magic, oldest.label, "timeout") + if (oldest.sid == CfwTransport.SID) + cfwTransports[if (oldest.isLeftArmMessage) 0 else 1].reset() + handleAckTimeoutLocked(oldest) + return 0 + } + if (connectionOptions.WINDOW_SIZE <= 1 + && sessionReady + && prewrittenMessage == null + && !pendingMessages.isEmpty() + && canPrewriteCandidate(pendingMessages.peekFirst()) + && !shouldBlockPrewriteForHeartbeatLocked(now)) { + // Only the serial (window==1) path pre-sends the all-but-last + // packet; with a real window we just send the next message fully. + messageToPrewrite = pendingMessages.peekFirst() + } + } + + if (chargingMode) { + // Glasses are in the case: no display traffic, only battery + // polls (which also detect the end of charging). + finishDesiredFrameLocked("discarded: glasses charging") + if (sessionReady && inFlightMessages.isEmpty() && !pendingMessages.isEmpty()) { + messageToWrite = pendingMessages.removeFirst() + Log.i(TAG, "sending pending message (charging): " + messageToWrite!!.label) + } else if (sessionReady && pendingMessages.isEmpty() && inFlightMessages.isEmpty() + && now - lastBatteryRefreshAtMs >= ConnectionOptions.CHARGING_BATTERY_POLL_MS) { + Log.i(TAG, "Writing charging-mode battery poll") + messageToWrite = createBatteryQueryMessageLocked() + lastBatteryRefreshAtMs = now + } else { + return 1_000 + } + } else { + if (messageToPrewrite == null + && !shutdownRequested + && !fixedLayoutCreated + && pendingMessages.isEmpty() + && inFlightMessages.isEmpty()) { + Log.i(TAG, "enqueueing create layout") + enqueueCreateLayoutLocked() + } else if (messageToPrewrite != null) { + // Prewrite outside the lock; the logical message remains pending until + // its final BLE frame is sent after the current protocol ACK. + } + if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated + && (if (firmwareDebugFlagsEnabled) 2 else 1) != firmwareDebugFlagsLastSent + && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { + Log.i(TAG, "enqueueing firmware debug flags " + (if (firmwareDebugFlagsEnabled) "show" else "hide")) + enqueueFirmwareDebugFlagsLocked() + } + + if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated + && (if (compassOwners.isEmpty()) 0 else 1) != compassControlLastSent + && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { + val wanted = compassOwners.isNotEmpty() + Log.i(TAG, "enqueueing compass " + (if (wanted) "enable" else "disable")) + enqueueCompassControlLocked(false, wanted) + } + + if (benchmarkActive) { + maintainBenchmarkLocked(now) + } + + // Up to WINDOW_SIZE messages may be in flight at once (full + // pipelining); a slot frees when an ack arrives. An active + // bandwidth benchmark measures its own selected window instead. + val windowHasRoom = inFlightMessages.size < + Math.max(1, if (benchmarkActive) benchmarkWindowSize else connectionOptions.WINDOW_SIZE) + // A frame ready to send right now: don't inject a fresh + // heartbeat in front of it (the image's own ack resets the + // firmware heartbeat timer, so the heartbeat is redundant). + // "Ready" covers both a fresh composite still to be planned + // and a planned image already queued but not yet written -- + // enqueueing sets lastEnqueuedFingerprint, so testing only + // the desired fingerprint left the queued-but-unwritten + // window unprotected and a heartbeat that came due there + // cost the frame a full ack round trip (measured 124ms on + // frame#232 of the 2026-08-20 02:27 capture). + // A benchmark run counts as image traffic here for the same + // reason: its acks reset the firmware heartbeat timer, so a + // fresh heartbeat in front of it is redundant. + val imageWaiting = !shutdownRequested && fixedLayoutCreated + && !hasPendingOrInflightKindLocked("heartbeat") + && (benchmarkActive + || (now >= imageRetryAfterMs + && (hasPendingImageLocked() + || getDesiredFingerprint() != lastEnqueuedFingerprint))) + noteImageStallLocked(now, windowHasRoom) + if (messageToPrewrite == null && handleHeartbeat(imageWaiting)) { + return ConnectionOptions.IDLE_SLEEP_MS.toLong() + } + + if (messageToPrewrite == null && sessionReady && windowHasRoom && !pendingMessages.isEmpty() + && CfwMessageWindow.canSend(inFlightMessages, pendingMessages.peekFirst()!!)) { + messageToWrite = pendingMessages.removeFirst() + Log.i(TAG, "sending pending message: " + messageToWrite!!.label) + } else if (messageToPrewrite == null && !shutdownRequested && !benchmarkActive + && fixedLayoutCreated + && windowHasRoom && !hasPendingImageLocked() + && now >= imageRetryAfterMs + && getDesiredFingerprint() != lastEnqueuedFingerprint) { + // Enqueue the next frame's delta against lastEnqueuedPacked + // (what the shadow will be), so it can pipeline behind an + // image still awaiting its ack. + Log.i(TAG, "Enqueued image update") + enqueueDesiredImageLocked() + return 0 + } else if (messageToPrewrite == null && shouldPollBatteryLocked(now)) { + Log.i(TAG, "Writing battery query") + messageToWrite = createBatteryQueryMessageLocked() + lastBatteryRefreshAtMs = now + } else if (messageToPrewrite == null && (!pendingMessages.isEmpty() || !inFlightMessages.isEmpty())) { + return ConnectionOptions.IDLE_SLEEP_MS.toLong() + } else if (messageToPrewrite == null) { + return 250 + } + } + } + + val prewrite = messageToPrewrite + if (prewrite != null) { + if (prewriteMessage(prewrite)) { + return 0 + } + return ConnectionOptions.IDLE_SLEEP_MS.toLong() + } + + val write = messageToWrite!! + if (!writeMessage(write)) { + synchronized(lock) { + if (removePreparedMessageLocked(write) || write.magic == 0) { + handleTransportFailure("write failed") + } + } + return 0 + } + } + } + + /** + * If the desired image already matches what the glasses display, nothing will + * ever be enqueued for it, so finish its frame now (otherwise the TS side + * would block on it until its backpressure timeout). + */ + private fun maybeFinishNoChangeDesiredFrame() { + var frameIdToFinish = 0 + synchronized(lock) { + synchronized(desiredTilesLock) { + if (desiredFrameId != 0 && lastEnqueuedFingerprint.isNotEmpty() && desiredFingerprint == lastEnqueuedFingerprint) { + frameIdToFinish = desiredFrameId + desiredFrameId = 0 + } + } + } + if (frameIdToFinish != 0) { + finishFrame(frameIdToFinish, "discarded: no change from displayed image") + } + } + + private fun shouldBlockPrewriteForHeartbeatLocked(now: Long): Boolean { + if (shutdownRequested || !fixedLayoutCreated) { + return false + } + return hasPendingOrInflightKindLocked("heartbeat") + || now - lastHeartbeatAckedAtMs >= ConnectionOptions.HEARTBEAT_READY_MS + } + + private fun canPrewriteCandidate(message: OutboundMessage?): Boolean { + if (message == null || message.sid == CfwTransport.SID || !message.isLeftArmMessage) { + return false + } + if ("image" != message.kind) { + return false + } + return message.message.size + 2 > 232 + } + + private fun handleHeartbeat(imageWaiting: Boolean): Boolean { + val now = SystemClock.elapsedRealtime() + val heartbeatEligible = !shutdownRequested && fixedLayoutCreated + val heartbeatPending = heartbeatEligible && hasPendingOrInflightKindLocked("heartbeat") + val heartbeatElapsedMs = now - lastHeartbeatAckedAtMs + val heartbeatReady = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS + val heartbeatUrgent = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_URGENT_MS + val heartbeatBlocksLeftWrites = heartbeatReady || heartbeatPending + + if (heartbeatReady && !heartbeatPending && inFlightMessages.isEmpty()) { + if (imageWaiting && !heartbeatUrgent) { + // Defer to the waiting frame: sending it now satisfies the + // firmware heartbeat deadline (its ack resets the timer), and + // the heartbeat still fires once we reach the URGENT threshold + // if rendering goes quiet again. Preserves the pending-heartbeat + // inter-lens-sync invariant below (that path is untouched). + return false + } + Log.i(TAG, "Writing heartbeat") + val heartbeatMessage = createHeartbeatMessage() + lastHeartbeatSentAtMs = now + writeMessage(heartbeatMessage) + return true + } else if (heartbeatUrgent) { + return true + } else if (heartbeatPending) { + // Don't send other message types while a heartbeat is pending because that + // can lead to inter-lens sync issues + return true + } + + return false + } + + private fun createHeartbeatMessage(): OutboundMessage { + val message = messageBuilder.heartbeat() + message.onAck = MessageCallback { + synchronized(lock) { + lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime() + } + } + message.onTimeout = MessageCallback { + // If a heartbeat fails to ack and we're over the heartbeat deadline, assume the connection is failed and reconnect. + // Otherwise ignore it, which will cause a retransmission attempt. + val isPastDeadline: Boolean + synchronized(lock) { + isPastDeadline = SystemClock.elapsedRealtime() - lastHeartbeatSentAtMs >= ConnectionOptions.HEARTBEAT_FAILURE_DEADLINE_MS + } + if (isPastDeadline) { + handleTransportFailure("heartbeat ack timeout") + } + } + return message + } + + + private fun writeMessage(message: OutboundMessage): Boolean { + val now = SystemClock.elapsedRealtime() + message.writeStartedAtMs = now + message.sentAtMs = now + message.ackDeadlineAtMs = now + message.ackTimeoutMs + ConnectionOptions.WRITE_TIMEOUT_MS + if (message.magic != 0) { + synchronized(lock) { + inFlightMessages.addLast(message) + } + } + if (message.imageUpdateId > 0 && message.imageMessageNumber == 1) { + synchronized(lock) { + val stats = imageUpdateStats[message.imageUpdateId] + if (stats != null && stats.firstWriteStartedAtMs <= 0) { + stats.firstWriteStartedAtMs = now + } + } + } + + val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress + val frames: List + if (prewrittenMessage != null && prewrittenMessage !== message) { + if (!spoilPrewrittenMessage("before " + message.label)) { + return false + } + } + if (prewrittenMessage === message) { + frames = Collections.singletonList(prewrittenFrames[prewrittenFrames.size - 1]) + prewrittenMessage = null + prewrittenFrames = Collections.emptyList() + } else if (message.sid == CfwTransport.SID) { + if (message.cfwRetries > 0) cfwTransports[if (message.isLeftArmMessage) 0 else 1].reset() + frames = cfwTransports[if (message.isLeftArmMessage) 0 else 1].encode( + message.message, message.magic, CfwTransport.BOTH, + bleManager.getNegotiatedMtu(writeAddress)) + } else { + frames = BleProtocol.framePb( + message.message, + message.sid, + message.flag, + nextTransportSeq++ + ) + } + val result = bleManager.writeFrames( + writeAddress, + BleProtocol.WRITE_CHAR_UUID, + frames, + AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), + ConnectionOptions.WRITE_TIMEOUT_MS + ) + + synchronized(lock) { + val sentAtMs = SystemClock.elapsedRealtime() + message.sentAtMs = sentAtMs + message.ackDeadlineAtMs = sentAtMs + message.ackTimeoutMs + logImageUpdateSendLandmarkLocked(message) + val onSent = message.onSent + if (result && onSent != null) { + onSent.run() + lock.notifyAll() + } + } + + if (!result && message.sid == CfwTransport.SID) + cfwTransports[if (message.isLeftArmMessage) 0 else 1].reset() + return result + } + + private fun prewriteMessage(message: OutboundMessage): Boolean { + if (prewrittenMessage === message) { + return true + } + if (prewrittenMessage != null && !spoilPrewrittenMessage("before prewrite " + message.label)) { + return false + } + if (!canPrewriteCandidate(message)) { + return false + } + + val frames: List = BleProtocol.framePb( + message.message, + message.sid, + message.flag, + nextTransportSeq++ + ) + if (frames.size <= 1) { + return false + } + + val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress + val prefixFrames = frames.subList(0, frames.size - 1) + val result = bleManager.writeFrames( + writeAddress, + BleProtocol.WRITE_CHAR_UUID, + prefixFrames, + AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), + ConnectionOptions.WRITE_TIMEOUT_MS + ) + if (!result) { + return false + } + + prewrittenMessage = message + prewrittenFrames = ArrayList(frames) + logLine("prewrote " + message.label + " frames=" + prefixFrames.size + "/" + frames.size) + return true + } + + private fun spoilPrewrittenMessage(reason: String): Boolean { + val message = prewrittenMessage + if (message == null || prewrittenFrames.isEmpty()) { + prewrittenMessage = null + prewrittenFrames = Collections.emptyList() + return true + } + val finalFrame = Arrays.copyOf( + prewrittenFrames[prewrittenFrames.size - 1], + prewrittenFrames[prewrittenFrames.size - 1].size + ) + if (finalFrame.size > 8) { + finalFrame[finalFrame.size - 1] = (finalFrame[finalFrame.size - 1].toInt() xor 0xff).toByte() + } + prewrittenMessage = null + prewrittenFrames = Collections.emptyList() + + val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress + logLine("spoiling prewritten " + message.label + ": " + reason) + return bleManager.writeFrames( + writeAddress, + BleProtocol.WRITE_CHAR_UUID, + Collections.singletonList(finalFrame), + AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), + ConnectionOptions.WRITE_TIMEOUT_MS + ) + } + + private fun removePreparedMessageLocked(message: OutboundMessage?): Boolean { + if (message == null || message.magic == 0) { + return false + } + val iterator = inFlightMessages.iterator() + while (iterator.hasNext()) { + if (iterator.next() === message) { + iterator.remove() + magicPool.release(message.sid, message.magic, message.label, "write failed") + return true + } + } + return false + } + + + /** Also drain on the worker: a clear/timeout may have removed a blocking + * head since the last notification. Fully ACKed controls must never reach + * the generic timeout path just because no further BLE reply arrived. */ + private fun drainCfwAcknowledgementsLocked() { + while (true) { + val first = CfwMessageWindow.acknowledgedHead(inFlightMessages) ?: return + lastAckAtMs = SystemClock.elapsedRealtime() + resolveAckLocked(first, first.ackPayload) + } + } + + private fun resolveAckLocked(sid: Int, magic: Int, pb: ByteArray?) { + val iterator = inFlightMessages.iterator() + while (iterator.hasNext()) { + val message = iterator.next() + if (message.sid == sid && message.magic == magic) { + resolveAckLocked(message, pb) + return + } + } + recordUnexpectedAckLocked(sid, magic) + } + + private fun resolveAckLocked(message: OutboundMessage, pb: ByteArray?) { + Log.i(TAG, "Got ACK for " + message.label + "(sid=" + message.sid + ", id=" + message.magic + ")") + inFlightMessages.remove(message) + message.ackPayload = if (pb == null) ByteArray(0) else Arrays.copyOf(pb, pb.size) + magicPool.release(message.sid, message.magic, message.label, "ack") + val onAck = message.onAck + if (onAck != null) { + onAck.run() + } + consecutiveAckTimeouts = 0 + // onAck may have just satisfied a waiter blocked on lock.wait() (e.g. + // awaitEvenHubSessionReady polling fixedLayoutCreated/displayedFingerprint + // after a create-layout or image ack). Without this, that waiter only + // notices on its own up-to-100ms poll tick, adding avoidable latency to + // every EvenHub wake. Always called with lock held (see call site). + lock.notifyAll() + } + + private fun logImageUpdateSendLandmarkLocked(message: OutboundMessage) { + if (message.imageUpdateId <= 0) { + return + } + val stats = imageUpdateStats[message.imageUpdateId] + val frameId = if (stats == null) 0 else stats.frameId + if (message.imageMessageNumber == 1) { + if (stats != null && stats.firstWriteStartedAtMs <= 0) { + stats.firstWriteStartedAtMs = if (message.writeStartedAtMs > 0) message.writeStartedAtMs else message.sentAtMs + } + FrameTimings.getInstance().log(frameId, "first bluetooth packet sent") + logImageUpdateLandmarkLocked("first bluetooth message sent", message, message.sentAtMs) + } + if (message.imageMessageNumber == message.imageMessageCount) { + FrameTimings.getInstance().log(frameId, + "last bluetooth packet sent (message " + message.imageMessageNumber + "/" + message.imageMessageCount + ")") + logImageUpdateLandmarkLocked("last bluetooth message sent", message, message.sentAtMs) + } + } + + private fun logImageUpdateAckLandmarkLocked(message: OutboundMessage) { + if (message.imageUpdateId <= 0 || message.imageMessageNumber != message.imageMessageCount) { + return + } + val ackedAtMs = SystemClock.elapsedRealtime() + FaceclawBleManager.recordDisplayFrameSent() + val stats = imageUpdateStats.remove(message.imageUpdateId) + if (stats != null && stats.firstWriteStartedAtMs > 0) { + emitFrameMetrics(stats.paintMs, Math.max(0L, ackedAtMs - stats.firstWriteStartedAtMs).toInt(), stats.tileCount) + } + if (stats != null) { + finishFrame(stats.frameId, "sent") + } + logImageUpdateLandmarkLocked("last bluetooth message acked", message, ackedAtMs) + } + + /** Remove the stats entry for an image update that will not complete, finishing its frame. */ + private fun discardImageUpdateStatsLocked(imageUpdateId: Int, reason: String) { + if (imageUpdateId <= 0) { + return + } + val stats = imageUpdateStats.remove(imageUpdateId) + if (stats != null) { + finishFrame(stats.frameId, "discarded: $reason") + } + } + + private fun logImageUpdateLandmarkLocked(event: String, message: OutboundMessage, elapsedMs: Long) { + logLine("image update#" + message.imageUpdateId + " " + event + + " at " + timestamp(elapsedMs) + + " message=" + message.imageMessageNumber + "/" + message.imageMessageCount + + " label=" + message.label) + } + + private fun enqueueCreateLayoutLocked() { + // New session: re-assert the firmware-debug-flags overlay once + // the layout is ready (the mode-7 send is gated on this having reset). + firmwareDebugFlagsLastSent = -1 + val message = messageBuilder.createLayout() + message.onAck = MessageCallback { + startupProbePending = false + clearMessagesOfKindLocked("startup-text-probe") + fixedLayoutCreated = true + displayedFingerprint = "" + } + message.onTimeout = MessageCallback { + if (startupProbePending) { + logLine("create layout timed out while startup text probe is pending") + if (hasPendingOrInflightKindLocked("startup-text-probe")) { + return@MessageCallback + } + startupProbePending = false + } + handleTransportFailure("ack timeout") + } + pendingMessages.addLast(message) + logLine("queue create layout") + } + + private fun enqueueStartupProbeLocked() { + enqueueCreateLayoutLocked() + + val message = messageBuilder.startupTextProbe() + message.onAck = MessageCallback { + startupProbePending = false + clearMessagesOfKindLocked("create-layout") + fixedLayoutCreated = true + displayedFingerprint = "" + logLine("existing dashboard layout accepted text probe") + } + message.onTimeout = MessageCallback { + startupProbePending = false + if (hasPendingOrInflightKindLocked("create-layout")) { + return@MessageCallback + } + handleTransportFailure("ack timeout") + } + pendingMessages.addLast(message) + startupProbePending = true + logLine("queue startup text probe") + } + + /** + * Send the CFW mode-7 diagnostic-flag control op through the private stream: + * [7][2] to show the on-glasses debug-flag overlay, [7][1] to hide it. Uses the + * arbitrary-payload custom path (no bmp/dedup/frame-timing interaction). + */ + private fun enqueueFirmwareDebugFlagsLocked() { + val show = firmwareDebugFlagsEnabled + val sub = if (show) 2 else 1 + val payload = byteArrayOf(CFW_MSG_DIAGNOSTICS.toByte(), sub.toByte()) + val message = messageBuilder.imagePayload( + DASHBOARD_TILE, nextMapSessionId(), payload, + "fw-debug-flags " + (if (show) "show" else "hide"), + connectionOptions.sendImagesToLeft) + pendingMessages.addLast(message) + firmwareDebugFlagsLastSent = sub + logLine("queue firmware debug flags " + (if (show) "show" else "hide")) + } + + /** + * Send CFW image-handler mode 10. Enable uses the configurable form + * [10][2][interval-ms LE16][minimum-change-degrees LE16]; disable remains [10][0]. + */ + private fun enqueueCompassControlLocked(priority: Boolean, enable: Boolean) { + val sentState = if (enable) 1 else 0 + val payload = if (enable) + byteArrayOf( + CFW_MSG_COMPASS.toByte(), + 2.toByte(), + (COMPASS_REPORT_INTERVAL_MS and 0xff).toByte(), + ((COMPASS_REPORT_INTERVAL_MS shr 8) and 0xff).toByte(), + (COMPASS_MIN_CHANGE_DEGREES and 0xff).toByte(), + ((COMPASS_MIN_CHANGE_DEGREES shr 8) and 0xff).toByte(), + ) + else + byteArrayOf(CFW_MSG_COMPASS.toByte(), 0.toByte()) + val message = messageBuilder.imagePayload( + "compass-control", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + "compass " + (if (enable) "enable" else "disable"), + connectionOptions.sendImagesToLeft) + message.onTimeout = MessageCallback { + compassControlLastSent = -1 + logLine("compass control ack timeout") + } + if (enable) { + compassMaybeOn = true + } else { + message.onAck = MessageCallback { compassMaybeOn = false } + } + if (priority) pendingMessages.addFirst(message) + else pendingMessages.addLast(message) + compassControlLastSent = sentState + logLine("queue " + message.label) + } + + private fun enqueueDesiredImageLocked() { + val fingerprint = getDesiredFingerprint() + val packedSnapshot: ByteArray? + val width: Int + val height: Int + val paintMs: Int + val frameId: Int + val draws: Array? + val scene: ShellScene + synchronized(desiredTilesLock) { + packedSnapshot = desiredPacked + width = desiredWidth + height = desiredHeight + paintMs = desiredPaintMs + frameId = desiredFrameId + draws = desiredDraws + scene = desiredShellScene + desiredFrameId = 0 + } + val packedFrame: ByteArray = packedSnapshot ?: ByteArray(0) + if (customFirmwareDetected && packedFrame.size > 0) { + val rendered = scenePlanner.plan(packedFrame, width, height, draws, scene, nextImageFrameId, + connectionOptions.TEXTURE_CACHE_FRAMES, connectionOptions.INCREMENTAL_FRAMES, + connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS) + nextImageFrameId = rendered.nextFid + val commands = rendered.commands + for (i in 0 until commands.size - 1) enqueueResourceCommandLocked(commands[i]) + val plan = BleImageOptimizer.TileImagePlan( + 0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId(), commands[commands.size - 1]) + finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId) + return + } + + FrameTimings.getInstance().spanStart(frameId, "compress-and-plan") + // Incremental (mode 3 bounding box) update against the last ENQUEUED frame + // (the base the firmware shadow will hold when this update is applied). + // lastEnqueuedPacked is cleared whenever the image pipeline is cleared, so + // a non-empty value means the display base is trusted. + var incrementalPayload: ByteArray? = null + var incrementalLog: String? = null + if (connectionOptions.INCREMENTAL_FRAMES && lastEnqueuedPacked.size > 0 + && lastEnqueuedWidth == width && lastEnqueuedHeight == height) { + val baseFid = nextImageFrameId + val single = + BleImageOptimizer.buildIncrementalImagePayload(lastEnqueuedPacked, packedFrame, width, height, baseFid) + if (single != null) { + incrementalPayload = single.payload + // advance only when a delta is actually emitted, so consecutive + // deltas carry consecutive ids (CFW skip/reorder detection) + nextImageFrameId = if (nextImageFrameId >= 0xfffe) 1 else nextImageFrameId + 1 + incrementalLog = "incremental update bbox=" + + ((single.payload[3].toInt() and 0xff) * 4) + "x" + ((single.payload[4].toInt() and 0xff) * 2) + + "+" + ((single.payload[1].toInt() and 0xff) * 4) + "+" + ((single.payload[2].toInt() and 0xff) * 2) + + " changed=" + single.changedBytes + "/" + single.boxBytes + "B" + + " clusters=" + single.clusterCount + + // When the bounding box spans multiple clusters or is sizeable, try + // splitting into tight rects (CFW mode-8). Only replace the single + // box if the multi-rect message is actually smaller on the wire. + if (connectionOptions.MULTI_RECT_FRAMES + && (single.clusterCount > 1 || single.payload.size > ConnectionOptions.MULTI_RECT_MIN_PAYLOAD)) { + val multi = BleImageOptimizer.buildMultiRectImagePayload( + lastEnqueuedPacked, packedFrame, width, height, baseFid, ConnectionOptions.MULTI_RECT_MAX_RECTS) + if (multi != null && multi.payload.size < single.payload.size) { + incrementalPayload = multi.payload + nextImageFrameId = multi.nextFid // rectCount fids consumed + incrementalLog = "multi-rect update n=" + multi.rectCount + + " covered=" + multi.coveredBytes + "B" + + " payload=" + multi.payload.size + "B (vs bbox " + single.payload.size + "B)" + } + } + } + } + val plan = if (incrementalPayload != null) + BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId(), incrementalPayload) + else + BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId()) + FrameTimings.getInstance().spanEnd(frameId, "compress-and-plan") + if (incrementalLog != null) { + FrameTimings.getInstance().log(frameId, incrementalLog) + } + finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId) + } + + /** Queue complete private commands, advance the delta base, and retain frame/ACK bookkeeping. */ + private fun finishEnqueueDesiredImageLocked( + plan: BleImageOptimizer.TileImagePlan, fingerprint: String, paintMs: Int, frameId: Int) { + val updateId = nextImageUpdateId++ + val commands: MutableList = ArrayList() + if (plan.payload.size <= CfwTransport.MAX_MESSAGE) { + commands.add(plan.payload) + } else { + // A noisy full frame can exceed the stream record limit. Repaint it + // with independently decodable RLE bands below the decoded-message limit. + commands.addAll(BleImageOptimizer.encodeFullFrameBands( + plan.packed!!, plan.width, plan.height, nextImageFrameId)) + for (i in 0 until commands.size) { + nextImageFrameId = if (nextImageFrameId >= 0xfffe) 1 else nextImageFrameId + 1 + } + } + val messageCount = commands.size + imageUpdateStats[updateId] = BleImageOptimizer.ImageUpdateStats(paintMs, 1, frameId) + for (i in 0 until commands.size) { + enqueueCustomImageLocked(plan, commands[i], fingerprint, updateId, i + 1, messageCount) + } + // This frame is now the base for the next delta (it will be the firmware + // shadow once applied), even though it hasn't been acked yet — that is what + // lets the next frame pipeline behind it. plan.packed is the full frame; + // frames are immutable by convention, so referencing it is safe. + lastEnqueuedPacked = plan.packed!! + lastEnqueuedWidth = plan.width + lastEnqueuedHeight = plan.height + lastEnqueuedFingerprint = fingerprint + + FrameTimings.getInstance().log(frameId, "queued image update#" + updateId + + " messages=" + messageCount + " payload=" + plan.payload.size + "B") + logLine("queue image update#" + updateId + " fingerprint=" + fingerprint + + " messages=" + messageCount) + } + + /** + * Enqueue one resource eviction/upload command ahead of the image message that + * references its glyphs (the transport is FIFO, so no ack round trip is + * needed before use). A timeout means the on-glasses cache state is + * unknown; forget everything phone-side (glyphs re-upload lazily) and let + * the accompanying image update's own timeout drive the frame resync. + */ + private fun enqueueResourceCommandLocked(payload: ByteArray) { + val message = messageBuilder.imagePayload( + "resources", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + "resource command " + payload.size + "B", + connectionOptions.sendImagesToLeft) + message.onTimeout = MessageCallback { + resourceCache.reset() + logLine("resource command ack timeout; resource cache state reset") + } + pendingMessages.addLast(message) + logLine("queue " + message.label) + } + + private fun enqueueCustomImageLocked( + plan: BleImageOptimizer.TileImagePlan, + payload: ByteArray, + fingerprint: String, + updateId: Int, + messageNumber: Int, + messageCount: Int + ) { + val message = messageBuilder.customMessage("image", payload, + "image " + plan.tile.name + "#" + messageNumber, plan.tileIndex, connectionOptions.sendImagesToLeft) + message.setImageUpdatePosition(updateId, messageNumber, messageCount) + message.onAck = MessageCallback { + imageRetryAfterMs = 0 + // Firmware >= 2.2.4.34 resets its heartbeat timer when it receives + // image messages (not just heartbeats), so an acked image fragment + // satisfies the heartbeat deadline and heartbeats stop contending + // with active rendering. + lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime() + logImageUpdateAckLandmarkLocked(message) + var imageStillInFlight = false + for (inFlight in inFlightMessages) { + if ("image" == inFlight.kind) { + imageStillInFlight = true + break + } + } + if (!imageStillInFlight) { + var imageStillQueued = false + for (queued in pendingMessages) { + if ("image" == queued.kind) { + imageStillQueued = true + break + } + } + if (!imageStillQueued) { + displayedFingerprint = fingerprint + } + } + } + message.onTimeout = MessageCallback { + discardImageUpdateStatsLocked(message.imageUpdateId, "image ack timeout (will retry)") + clearMessagesOfKindLocked("image") + displayedFingerprint = "" + imageRetryAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.IMAGE_RETRY_DELAY_MS + } + pendingMessages.addLast(message) + } + + private fun createAudioControlMessageLocked(enable: Boolean): OutboundMessage { + val message = messageBuilder.enableOrDisableMic(enable) + message.onAck = MessageCallback { + lastAudioControlAckMagic = message.magic + audioCaptureActive = message.label?.contains("enable") == true + logLine(if (audioCaptureActive) "G2 mic enabled" else "G2 mic disabled") + } + message.onTimeout = MessageCallback { + handleTransportFailure("audio control ack timeout") + } + return message + } + + private fun shouldPollBatteryLocked(now: Long): Boolean { + return !shutdownRequested + && sessionReady + && pendingMessages.isEmpty() + && inFlightMessages.isEmpty() + && now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS + && (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS) + } + + private fun createBatteryQueryMessageLocked(): OutboundMessage { + val message = messageBuilder.batteryQuery() + message.onAck = MessageCallback { + val ring = BleProtocol.parseRingBattery(message.ackPayload) + // Old firmware and missing/malformed extensions must clear any prior reading. + ringBattery = if (ring == null) -1 else ring.battery + ringCharging = if (ring == null) -1 else ring.charging + val snapshot = BleProtocol.parseSettingsBattery(message.ackPayload) + if (snapshot != null) { + headsetBattery = snapshot.battery + headsetCharging = snapshot.charging + emitBatteryState(headsetBattery, headsetCharging) + if (snapshot.silentMode >= 0) { + // Backstop for the push in onNotification: the firmware is + // confirmed to push silent-mode-on, but the off transition is + // not, so re-read the authoritative value on every poll. + updateSilentModeLocked(snapshot.silentMode > 0) + } + updateChargingModeLocked(snapshot.charging > 0, snapshot.battery) + } + val firmwareInfo = BleProtocol.parseSettingsFirmwareInfo(message.ackPayload) + if (firmwareInfo != null) { + customFirmwareDetected = firmwareInfo.isFaceclawFirmware() + emitFirmwareInfo(firmwareInfo) + } + } + message.onTimeout = MessageCallback { + logLine("Battery query timed out") + } + return message + } + + /** + * Track silent mode, which the wearer toggles by long-pressing both + * touchpads at once. While it is on the firmware refuses input events and + * app launches and powers the display down, so the glasses look dead even + * though the BLE session is healthy; the phone UI says so explicitly. + */ + private fun updateSilentModeLocked(silent: Boolean) { + val next = if (silent) 1 else 0 + if (silentMode == next) { + return + } + silentMode = next + logLine(if (silent) "glasses entered silent mode" else "glasses left silent mode") + emitSilentMode(silent) + } + + /** + * Track whether the glasses are in the charging case. Charging means nobody + * is wearing them: display communication pauses (no heartbeats, so the + * firmware tears down its EvenHub context on its own) and only battery polls + * continue. When charging stops, tear the transport down and let the normal + * reconnect loop rebuild the session, layout, and first frame. + */ + private fun updateChargingModeLocked(charging: Boolean, battery: Int) { + if (charging == chargingMode) { + if (chargingMode) { + setStateDisplay("charging", chargingStatusText(battery)) + } + return + } + if (charging) { + chargingMode = true + clearAllMessagesLocked("glasses charging") + fixedLayoutCreated = false + startupProbePending = false + displayedFingerprint = "" + finishDesiredFrameLocked("discarded: glasses charging") + logLine("glasses are charging; pausing display communication") + setStateDisplay("charging", chargingStatusText(battery)) + } else { + chargingMode = false + logLine("glasses removed from charger; reconnecting") + handleTransportFailure("charging ended") + } + } + + /** + * Record, into the frame that is waiting, why it did not go out on this + * pass of the send loop. Without this the export shows a bare multi-second + * jump between "image submitted as desired frame" and the first BLE + * packet, with no hint whether we were blocked on a heartbeat, the + * BLE window, or another message queued ahead. Deduped on (frame, reason), + * so a frame stalled for seconds gets one line per state change rather + * than one per loop pass. + */ + private fun noteImageStallLocked(now: Long, windowHasRoom: Boolean) { + var frameId: Int + synchronized(desiredTilesLock) { + frameId = desiredFrameId + } + val reason: String? + if (frameId != 0 && getDesiredFingerprint() != lastEnqueuedFingerprint) { + reason = describeEnqueueBlockerLocked(now, windowHasRoom) + } else { + // Nothing waiting to be planned; an already-planned image may still + // be queued behind other traffic. + val queuedImage = firstPendingImageLocked() + frameId = if (queuedImage == null) 0 else imageUpdateFrameIdLocked(queuedImage.imageUpdateId) + reason = if (queuedImage == null) null else describeWriteBlockerLocked(now, windowHasRoom, queuedImage) + } + if (frameId == 0 || reason == null) { + stallFrameId = 0 + stallReason = "" + return + } + if (frameId == stallFrameId && reason == stallReason) { + return + } + stallFrameId = frameId + stallReason = reason + FrameTimings.getInstance().log(frameId, "waiting to send: $reason") + } + + /** Why the desired composite has not been turned into wire messages yet, or null. */ + private fun describeEnqueueBlockerLocked(now: Long, windowHasRoom: Boolean): String? { + if (shutdownRequested) { + return "shutdown requested" + } + if (!sessionReady) { + return "BLE session not ready" + } + if (!fixedLayoutCreated) { + return "display layout not created yet" + } + if (now < imageRetryAfterMs) { + return "image retry backoff (" + (imageRetryAfterMs - now) + "ms left)" + } + if (hasPendingImageLocked()) { + return "an earlier image is still queued" + } + if (!windowHasRoom) { + return "BLE window full (" + inFlightMessages.size + " message(s) in flight)" + } + if (hasPendingOrInflightKindLocked("heartbeat")) { + return "heartbeat in flight" + } + if (!pendingMessages.isEmpty()) { + return pendingMessages.size.toString() + " message(s) queued ahead, next " + + pendingMessages.peekFirst().label + } + return null + } + + /** Why a planned image message has not been written to BLE yet, or null. */ + private fun describeWriteBlockerLocked(now: Long, windowHasRoom: Boolean, queuedImage: OutboundMessage): String? { + if (!sessionReady) { + return "BLE session not ready" + } + if (!windowHasRoom) { + return "BLE window full (" + inFlightMessages.size + " message(s) in flight)" + } + if (hasPendingOrInflightKindLocked("heartbeat")) { + return "heartbeat in flight" + } + // handleHeartbeat is a barrier: while one is due it holds back every + // other write, so a frame queued at the wrong moment waits a heartbeat + // round trip. Reported explicitly because it is otherwise invisible -- + // heartbeats belong to no frame. + val heartbeatElapsedMs = now - lastHeartbeatAckedAtMs + if (fixedLayoutCreated && !shutdownRequested + && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS) { + return "heartbeat due (" + heartbeatElapsedMs + "ms since the last one acked)" + } + val head = pendingMessages.peekFirst() + if (head != null && head !== queuedImage) { + return "queued behind " + head.label + } + return null + } + + private fun firstPendingImageLocked(): OutboundMessage? { + for (message in pendingMessages) { + if (message.imageUpdateId > 0) { + return message + } + } + return null + } + + private fun imageUpdateFrameIdLocked(imageUpdateId: Int): Int { + val stats = imageUpdateStats[imageUpdateId] + return if (stats == null) 0 else stats.frameId + } + + private fun finishDesiredFrameLocked(outcome: String) { + val frameIdToFinish: Int + synchronized(desiredTilesLock) { + frameIdToFinish = desiredFrameId + desiredFrameId = 0 + } + finishFrame(frameIdToFinish, outcome) + } + + private fun hasPendingOrInflightKindLocked(kind: String): Boolean { + for (queued in pendingMessages) { + if (kind == queued.kind) { + return true + } + } + for (inFlight in inFlightMessages) { + if (kind == inFlight.kind) { + return true + } + } + return false + } + + private fun hasPendingOrInflightMagicLocked(magic: Int): Boolean { + for (queued in pendingMessages) { + if (queued.magic == magic) { + return true + } + } + for (inFlight in inFlightMessages) { + if (inFlight.magic == magic) { + return true + } + } + return false + } + + private fun hasPendingMagicLocked(sid: Int, magic: Int): Boolean { + for (queued in pendingMessages) { + if (queued.sid == sid && queued.magic == magic) { + return true + } + } + return false + } + + private fun handleAckTimeoutLocked(message: OutboundMessage) { + consecutiveAckTimeouts += 1 + + val onTimeout = message.onTimeout + if (onTimeout != null) { + onTimeout.run() + } + + if (consecutiveAckTimeouts > ConnectionOptions.MAX_CONSECUTIVE_ACK_TIMEOUTS) { + handleTransportFailure("too many ack timeouts") + } + } + + /** + * Replace any stale lease control with one right-arm and one left-arm + * fire-and-forget write. With priority=true the right arm is sent first so + * CLAIM reaches the lens that originated the deferred wake immediately. + */ + private fun enqueueFaceclawWakeControlLocked(operation: Int, nonce: Int, priority: Boolean): Int { + clearMessagesOfKindLocked("wake-lease-control") + val generation = ++faceclawWakeControlGeneration + faceclawWakeControlSentCount = 0 + if (operation == BleProtocol.FACECLAW_WAKE_OP_ACQUIRE) { + lastFaceclawWakeLeaseQueuedAtMs = SystemClock.elapsedRealtime() + } + val onSent = MessageCallback { + if (faceclawWakeControlGeneration == generation) { + faceclawWakeControlSentCount += 1 + } + } + val right = messageBuilder.faceclawWakeControl(operation, nonce, false) + val left = messageBuilder.faceclawWakeControl(operation, nonce, true) + right.onSent = onSent + left.onSent = onSent + if (priority) { + pendingMessages.addFirst(left) + pendingMessages.addFirst(right) + } else { + pendingMessages.addLast(right) + pendingMessages.addLast(left) + } + logLine("queue " + right.label + " + L") + return generation + } + + private fun waitForFaceclawWakeControlDelivery(generation: Int, timeoutMs: Long): Boolean { + val deadline = SystemClock.elapsedRealtime() + Math.max(0L, timeoutMs) + synchronized(lock) { + while (running + && sessionReady + && faceclawWakeControlGeneration == generation + && faceclawWakeControlSentCount < 2) { + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + break + } + } + return faceclawWakeControlGeneration == generation + && faceclawWakeControlSentCount >= 2 + } + } + + /** + * Acquire/renew or release CFW's independent direct-framebuffer repaint + * guard on both arms. It is separate from the optional idle-wake lease: + * every Faceclaw display session needs this guard while its EvenHub layout + * contains swipe-capturing stock widgets. + */ + private fun enqueueFaceclawFramebufferControlLocked(operation: Int, priority: Boolean): Int { + clearMessagesOfKindLocked("framebuffer-lease-control") + val generation = ++faceclawFramebufferControlGeneration + faceclawFramebufferControlSentCount = 0 + if (operation == BleProtocol.FACECLAW_FB_OP_ACQUIRE) { + lastFaceclawFramebufferLeaseQueuedAtMs = SystemClock.elapsedRealtime() + } + val onSent = MessageCallback { + if (faceclawFramebufferControlGeneration == generation) { + faceclawFramebufferControlSentCount += 1 + } + } + val right = messageBuilder.faceclawFramebufferControl(operation, false) + val left = messageBuilder.faceclawFramebufferControl(operation, true) + right.onSent = onSent + left.onSent = onSent + if (priority) { + pendingMessages.addFirst(left) + pendingMessages.addFirst(right) + } else { + pendingMessages.addLast(right) + pendingMessages.addLast(left) + } + logLine("queue " + right.label + " + L") + return generation + } + + private fun waitForFaceclawFramebufferControlDelivery(generation: Int, timeoutMs: Long): Boolean { + val deadline = SystemClock.elapsedRealtime() + Math.max(0L, timeoutMs) + synchronized(lock) { + while (running + && sessionReady + && faceclawFramebufferControlGeneration == generation + && faceclawFramebufferControlSentCount < 2) { + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + try { + lock.wait(Math.min(remaining, 100L)) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + break + } + } + return faceclawFramebufferControlGeneration == generation + && faceclawFramebufferControlSentCount >= 2 + } + } + + private fun releaseFaceclawFramebufferLease(): Boolean { + val generation: Int + synchronized(lock) { + if (!running || !sessionReady) { + return true + } + generation = enqueueFaceclawFramebufferControlLocked( + BleProtocol.FACECLAW_FB_OP_RELEASE, + true + ) + } + interruptibleSleep.interrupt() + return waitForFaceclawFramebufferControlDelivery( + generation, + FACECLAW_WAKE_CONTROL_WAIT_MS + ) + } + + private fun clearMessagesOfKindLocked(kind: String) { + val pendingIterator = pendingMessages.iterator() + while (pendingIterator.hasNext()) { + val message = pendingIterator.next() + if (kind == message.kind) { + pendingIterator.remove() + discardPrewriteIfMatchesLocked(message) + if ("image" == kind) { + discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared ($kind)") + } + magicPool.release(message.sid, message.magic, message.label, "cleared pending $kind") + } + } + val inFlightIterator = inFlightMessages.iterator() + while (inFlightIterator.hasNext()) { + val message = inFlightIterator.next() + if (kind == message.kind) { + inFlightIterator.remove() + if ("image" == kind) { + discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared ($kind)") + } + magicPool.release(message.sid, message.magic, message.label, "cleared inflight $kind") + } + } + if ("image" == kind) { + // The image pipeline was flushed (e.g. ack timeout -> keyframe resync): + // drop the pipelined delta base so the next image is a full keyframe. + lastEnqueuedPacked = ByteArray(0) + lastEnqueuedFingerprint = "" + } + } + + private fun clearAllMessagesLocked(reason: String) { + clearPendingMessagesLocked(reason) + clearInFlightMessagesLocked(reason) + // The image pipeline is gone: drop the pipelined delta base so the next + // image is a full keyframe rather than a delta onto a stale base. + lastEnqueuedPacked = ByteArray(0) + lastEnqueuedFingerprint = "" + // Queued resource commands (if any) were dropped with the rest, and the + // session churn behind a full clear may have freed the on-glasses + // cache; forget it phone-side so glyphs re-upload lazily. + resourceCache.reset() + } + + /** + * A custom wake queues CLAIM before NativeScript asks for a resume. Keep + * that private control while flushing stale EvenHub traffic around the + * direct prelude write. + */ + private fun clearAllMessagesPreservingWakeLeaseLocked(reason: String) { + val pendingIterator = pendingMessages.iterator() + while (pendingIterator.hasNext()) { + val message = pendingIterator.next() + if ("wake-lease-control" == message.kind) { + continue + } + pendingIterator.remove() + discardPrewriteIfMatchesLocked(message) + discardImageUpdateStatsLocked( + message.imageUpdateId, + "pending messages cleared: $reason" + ) + magicPool.release( + message.sid, + message.magic, + message.label, + "cleared pending: $reason" + ) + } + clearInFlightMessagesLocked(reason) + lastEnqueuedPacked = ByteArray(0) + lastEnqueuedFingerprint = "" + resourceCache.reset() + } + + /** Any image update whose fragments are still queued (not yet sent). */ + private fun hasPendingImageLocked(): Boolean { + for (message in pendingMessages) { + if ("image" == message.kind) { + return true + } + } + return false + } + + private fun clearPendingMessagesLocked(reason: String) { + while (!pendingMessages.isEmpty()) { + val message = pendingMessages.removeFirst() + discardPrewriteIfMatchesLocked(message) + discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared: $reason") + magicPool.release(message.sid, message.magic, message.label, "cleared pending: $reason") + } + } + + private fun clearInFlightMessagesLocked(reason: String) { + while (!inFlightMessages.isEmpty()) { + val message = inFlightMessages.removeFirst() + discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared: $reason") + magicPool.release(message.sid, message.magic, message.label, "cleared inflight: $reason") + } + } + + private fun discardPrewriteIfMatchesLocked(message: OutboundMessage?) { + if (message != null && message === prewrittenMessage) { + prewrittenMessage = null + prewrittenFrames = Collections.emptyList() + } + } + + private fun recordUnexpectedAckLocked(sid: Int, magic: Int) { + if (magic < BleMagicPool.MIN_MAGIC || magic > BleMagicPool.MAX_MAGIC) { + return + } + val previous = magicPool.getReleaseRecord(sid, magic) + if (previous == null) { + val pendingNote = if (hasPendingMagicLocked(sid, magic)) " while that magic is only pending locally" else "" + logLine("unexpected ACK sid=" + sid + " magic=" + magic + pendingNote + + "; possible Even app BLE contention") + return + } + if ("timeout" == previous.reason) { + logLine("late ACK after timeout sid=" + sid + " magic=" + magic + + " label=" + previous.label + + "; ACK timeout may be too short") + return + } + if ("ack" == previous.reason) { + logLine("duplicate ACK for already-acked message sid=" + sid + " magic=" + magic + + " label=" + previous.label + + "; possible Even app BLE contention") + return + } + logLine("late ACK for released message sid=" + sid + " magic=" + magic + + " label=" + previous.label + + " release=" + previous.reason) + } + + /** The address of a configured arm Android no longer holds a bond for, or null. */ + private fun firstUnpairedArm(): String? { + if (!bleManager.isBonded(rightAddress)) return rightAddress + if (!bleManager.isBonded(leftAddress)) return leftAddress + return null + } + + /** + * A connect failure while an arm's bond is missing (the pairing was + * forgotten in Android settings, or the address was typed in by hand and + * never paired) will repeat forever, so instead of scheduling a retry, + * park the worker loop and tell the user to re-pair. Only an explicit + * connect (which builds a fresh communicator) starts a new attempt. + */ + private fun handleUnpairedFailure(address: String) { + Log.e(TAG, "Connect failed and $address is not paired; suspending reconnect") + synchronized(lock) { + reconnectHalted = true + sessionReady = false + fixedLayoutCreated = false + startupProbePending = false + shutdownRequested = false + chargingMode = false + imageRetryAfterMs = 0 + displayedFingerprint = "" + faceclawWakePendingNonce = -1 + lastFaceclawWakeLeaseQueuedAtMs = 0 + faceclawWakeControlSentCount = 0 + clearAllMessagesLocked("arm not paired: $address") + reconnectAfterMs = Long.MAX_VALUE + bleManager.disconnect(rightAddress) + bleManager.disconnect(leftAddress) + } + if (!userDisconnectRequested) { + setStateDisplay( + "unpaired", + "The glasses (" + address + ") are not paired with this phone." + + " Use \"Pair glasses\" to pair them again, then connect." + ) + } + interruptibleSleep.interrupt() + } + + private fun handleTransportFailure(reason: String?) { + Log.e(TAG, "Transport failure: $reason") + synchronized(lock) { + maybeEmitEvenAppConflictLocked(reason) + finishBenchmarkLocked(true, "transport failure") + sessionReady = false + fixedLayoutCreated = false + startupProbePending = false + shutdownRequested = false + chargingMode = false + imageRetryAfterMs = 0 + displayedFingerprint = "" + faceclawWakePendingNonce = -1 + lastFaceclawWakeLeaseQueuedAtMs = 0 + faceclawWakeControlSentCount = 0 + clearAllMessagesLocked("transport failure: $reason") + reconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RECONNECT_DELAY_MS + bleManager.disconnect(rightAddress) + bleManager.disconnect(leftAddress) + } + if (!userDisconnectRequested) { + setStateDisplay("retrying", if (reason == null || reason.isEmpty()) "Reconnecting..." else "Reconnecting after $reason") + } + interruptibleSleep.interrupt() + } + + private fun resetSessionStateLocked() { + ringBattery = -1 + ringCharging = -1 + sessionReady = false + shutdownRequested = false + fixedLayoutCreated = false + chargingMode = false + rightConnected = false + leftConnected = false + ringConnected = false + ringNotificationsReady = false + reconnectAfterMs = 0 + reconnectHalted = false + ringReconnectAfterMs = 0 + lastAckAtMs = 0 + lastIncomingAtMs = 0 + lastHeartbeatSentAtMs = 0 + lastSessionReadyAtMs = 0 + consecutiveAckTimeouts = 0 + lastAudioControlAckMagic = 0 + audioCaptureActive = false + audioPacketListener = null + compassControlLastSent = -1 + // A dead transport orphans any glasses-side compass state; the fresh + // session re-asserts the desired state once its layout is ready. + compassMaybeOn = false + faceclawWakePendingNonce = -1 + lastFaceclawWakeLeaseQueuedAtMs = 0 + faceclawWakeControlSentCount = 0 + cfwCleanupDelivered = false + for (transport in cfwTransports) transport.reset() + lastCfwCleanupAckMagic = 0 + wearState = -1 + displayedFingerprint = "" + // Deliberately not clearing silentMode: it is a property of the glasses, + // not of our session, and silent mode blocks app launches, so it can be + // the very cause of the session teardown that got us here. + } + + private fun emitRingEvent(event: G2Event, frameId: Int) { + val current = listener + if (current == null) { + FrameTimings.getInstance().finishFrame(frameId, "discarded: no listener attached") + return + } + val containerNameSnapshot = event.containerName + mainHandler.post { + FrameTimings.getInstance().log(frameId, "dispatching input event on main thread") + try { + current.onRingEvent(event.kind, containerNameSnapshot, event.eventType, event.eventSource, event.systemExitReasonCode, frameId, + event.ringTick, event.ringType, event.ringAux, event.ringSpeed) + } catch (t: Throwable) { + Log.w(TAG, "listener onRingEvent failed", t) + FrameTimings.getInstance().finishFrame(frameId, "discarded: listener onRingEvent failed") + } + } + } + + /** Finish a frame owned by the communicator and tell the TS side, which may be awaiting it. */ + private fun finishFrame(frameId: Int, outcome: String) { + if (frameId <= 0) { + return + } + FrameTimings.getInstance().finishFrame(frameId, outcome) + val current = listener ?: return + mainHandler.post { + try { + current.onFrameFinished(frameId, outcome) + } catch (t: Throwable) { + Log.w(TAG, "listener onFrameFinished failed", t) + } + } + } + + private fun emitImuData(x: Double, y: Double, z: Double, eventSource: Int) { + if (imuListeners.isEmpty()) { + return + } + mainHandler.post { + for (imuListener in imuListeners) { + try { + imuListener.onImuData(x, y, z, eventSource) + } catch (t: Throwable) { + Log.w(TAG, "listener onImuData failed", t) + } + } + } + } + + private fun emitCompassEvent(event: BleProtocol.CompassEvent) { + if (event.diagnosticFlags >= 0) { + val sources = arrayOf("unknown", "GRV", "GMRV", "RV") + Log.i("FaceclawCompass", "heading=" + event.headingDegrees + + " magneticAccuracy=" + event.magneticAccuracy + + " magneticAnomalies=" + event.magneticAnomalies + + " orientationSource=" + sources[event.orientationSource] + + " flags=0x" + Integer.toHexString(event.diagnosticFlags) + + " sampleTimeMs=" + event.sampleTimeMs) + } + for (subscription in compassSubscriptions) { + subscription.handler.post { + try { + subscription.listener.onCompassEvent(event.command, event.headingDegrees, + event.magneticAccuracy, event.magneticAnomalies, event.orientationSource, + event.diagnosticFlags, event.sampleTimeMs) + } catch (t: Throwable) { + Log.w(TAG, "listener onCompassEvent failed", t) + } + } + } + } + + private fun emitSilentMode(silent: Boolean) { + val current = listener ?: return + mainHandler.post { + try { + current.onSilentMode(silent) + } catch (t: Throwable) { + Log.w(TAG, "listener onSilentMode failed", t) + } + } + } + + private fun emitWearState(wearing: Boolean) { + val current = listener ?: return + mainHandler.post { + try { + current.onWearState(wearing) + } catch (t: Throwable) { + Log.w(TAG, "listener onWearState failed", t) + } + } + } + + private fun emitPhoneLockStateIfChanged(force: Boolean) { + val locked: Boolean + synchronized(lock) { + val now = SystemClock.elapsedRealtime() + if (!force && now - lastPhoneLockCheckAtMs < 1_000) return + lastPhoneLockCheckAtMs = now + locked = keyguardManager != null && keyguardManager.isDeviceLocked + val value = if (locked) 1 else 0 + if (!force && value == phoneLockState) return + phoneLockState = value + } + val current = listener ?: return + mainHandler.post { + try { + current.onPhoneLockState(locked) + } catch (t: Throwable) { + Log.w(TAG, "listener onPhoneLockState failed", t) + } + } + } + + private fun emitBatteryState(headsetBattery: Int, headsetCharging: Int) { + val reportedRingBattery = ringBattery + val reportedRingCharging = ringCharging + val current = listener ?: return + mainHandler.post { + try { + current.onBatteryState(headsetBattery, headsetCharging, reportedRingBattery, reportedRingCharging) + } catch (t: Throwable) { + Log.w(TAG, "listener onBatteryState failed", t) + } + } + } + + private fun emitFirmwareInfo(info: BleProtocol.FirmwareInfo) { + val current = listener ?: return + mainHandler.post { + try { + current.onFirmwareInfo(info.leftVersion, info.rightVersion, info.extension) + } catch (t: Throwable) { + Log.w(TAG, "listener onFirmwareInfo failed", t) + } + } + } + + private fun emitFrameMetrics(paintMs: Int, transmitMs: Int, tileCount: Int) { + val current = listener ?: return + mainHandler.post { + try { + current.onFrameMetrics(paintMs, transmitMs, tileCount) + } catch (t: Throwable) { + Log.w(TAG, "listener onFrameMetrics failed", t) + } + } + } + + private fun maybeEmitEvenAppConflictLocked(reason: String?) { + if ("write failed" != reason) { + return + } + val now = SystemClock.elapsedRealtime() + if (lastSessionReadyAtMs <= 0 || now - lastSessionReadyAtMs > ConnectionOptions.EVEN_APP_WRITE_FAILURE_WINDOW_MS) { + return + } + if (lastEvenAppConflictAtMs > 0 && now - lastEvenAppConflictAtMs < 60_000) { + return + } + if (!FaceclawEvenAppDetector.isEvenNotificationActive(appContext)) { + return + } + lastEvenAppConflictAtMs = now + emitEvenAppConflict("The Even Realities app still appears to be running. It can hold the glasses BLE link and cause Faceclaw write failures. Open its app settings and force stop it, then reconnect Faceclaw.") + } + + private fun emitEvenAppConflict(message: String?) { + val current = listener ?: return + val messageSnapshot = message ?: "" + mainHandler.post { + try { + current.onEvenAppConflict(messageSnapshot) + } catch (t: Throwable) { + Log.w(TAG, "listener onEvenAppConflict failed", t) + } + } + } + + private fun setStateDisplay(nextPhase: String, nextStatus: String) { + synchronized(lock) { + phase = nextPhase + status = nextStatus + } + emitState() + } + + private fun emitState() { + val current = listener ?: return + val phaseSnapshot: String + val statusSnapshot: String + synchronized(lock) { + phaseSnapshot = phase + statusSnapshot = status + } + mainHandler.post { + try { + current.onStateChange(phaseSnapshot, statusSnapshot) + } catch (t: Throwable) { + Log.w(TAG, "listener onStateChange failed", t) + } + } + } + + private fun updateG2ScreenWakeLock(screenOn: Boolean) { + if (screenOn) { + var wakeLock = g2ScreenWakeLock + if (wakeLock == null) { + wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, G2_SCREEN_WAKE_LOCK_TAG) + wakeLock.setReferenceCounted(false) + g2ScreenWakeLock = wakeLock + } + if (!wakeLock.isHeld) { + wakeLock.acquire() + logLine("G2 screen wake lock acquired") + } + return + } + releaseG2ScreenWakeLock() + } + + private fun releaseG2ScreenWakeLock() { + val wakeLock = g2ScreenWakeLock + if (wakeLock != null && wakeLock.isHeld) { + wakeLock.release() + logLine("G2 screen wake lock released") + } + } + + private fun logLine(line: String) { + Log.i(TAG, line) + } + + private fun nextMapSessionId(): Int { + val id = nextMapSessionId + val increment = if (connectionOptions.skipSessionIds) 2 else 1 + nextMapSessionId = (nextMapSessionId + increment) and 0xff + return id + } + + private fun hasRingAddress(): Boolean { + return ringAddress.trim().isNotEmpty() + } + + private fun isConfiguredRingAddress(address: String?): Boolean { + return hasRingAddress() && address != null && address.equals(ringAddress, ignoreCase = true) + } + + private fun isDirectRingNotification(address: String?, characteristicUuid: String?): Boolean { + if (!isConfiguredRingAddress(address) || characteristicUuid == null) { + return false + } + return BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID == characteristicUuid + || BleProtocol.R1_NOTIFY_CHAR_UUID == characteristicUuid + } + + private fun getDesiredFingerprint(): String { + synchronized(desiredTilesLock) { + return desiredFingerprint + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java deleted file mode 100644 index 7531a50e..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.java +++ /dev/null @@ -1,558 +0,0 @@ -package com.faceclaw.app; - -import android.annotation.SuppressLint; -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothGatt; -import android.bluetooth.BluetoothGattCallback; -import android.bluetooth.BluetoothGattCharacteristic; -import android.bluetooth.BluetoothGattDescriptor; -import android.bluetooth.BluetoothGattService; -import android.bluetooth.BluetoothManager; -import android.bluetooth.BluetoothProfile; -import android.content.Context; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; -import android.util.Log; - -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - -@SuppressLint("MissingPermission") -public class FaceclawBleManager { - private static final String TAG = "FaceclawBle"; - private static final int[] WRITE_RETRY_DELAYS_MS = new int[] {1, 1, 1, 2, 4, 8, 12, 20, 35, 100, 200}; - - private final Context context; - private final BluetoothAdapter bluetoothAdapter; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - - private final ConcurrentHashMap gattClients = new ConcurrentHashMap<>(); - private final Object bluetoothApiLock = new Object(); - - private final ConcurrentHashMap connectLatches = new ConcurrentHashMap<>(); - private final ConcurrentHashMap connectResults = new ConcurrentHashMap<>(); - - private final ConcurrentHashMap servicesLatches = new ConcurrentHashMap<>(); - private final ConcurrentHashMap servicesStatuses = new ConcurrentHashMap<>(); - - private final ConcurrentHashMap mtuLatches = new ConcurrentHashMap<>(); - private final ConcurrentHashMap negotiatedMtus = new ConcurrentHashMap<>(); - private final ConcurrentHashMap mtuStatuses = new ConcurrentHashMap<>(); - - private final ConcurrentHashMap descriptorLatches = new ConcurrentHashMap<>(); - private final ConcurrentHashMap descriptorStatuses = new ConcurrentHashMap<>(); - - private final ConcurrentHashMap writeLatches = new ConcurrentHashMap<>(); - private final ConcurrentHashMap writeStatuses = new ConcurrentHashMap<>(); - - private volatile FaceclawBleListener listener; - - // Process-wide outbound-traffic totals, sampled by the phone UI's BLE - // bandwidth indicator. Static so counts from every manager instance and - // isolate land in the same totals. - private static final AtomicLong outboundMessages = new AtomicLong(); - private static final AtomicLong outboundBytes = new AtomicLong(); - private static final AtomicLong displayFramesSent = new AtomicLong(); - - /** Called by the communicator when a display frame's last message is acked. */ - public static void recordDisplayFrameSent() { - displayFramesSent.incrementAndGet(); - } - - /** Running totals of outbound BLE traffic since process start: [messages, bytes, display frames]. */ - public static long[] sampleOutboundTraffic() { - return new long[] { outboundMessages.get(), outboundBytes.get(), displayFramesSent.get() }; - } - - public FaceclawBleManager(Context context) { - this.context = context.getApplicationContext(); - BluetoothManager bluetoothManager = (BluetoothManager) this.context.getSystemService(Context.BLUETOOTH_SERVICE); - if (bluetoothManager == null || bluetoothManager.getAdapter() == null) { - throw new IllegalStateException("Bluetooth adapter unavailable"); - } - this.bluetoothAdapter = bluetoothManager.getAdapter(); - } - - public void setListener(FaceclawBleListener listener) { - this.listener = listener; - } - - /** - * Whether Android still holds a bond (pairing) for this address. Returns - * true when the state cannot be determined, so callers only act on a - * definite BOND_NONE. - */ - public boolean isBonded(String address) { - if (address == null || address.trim().isEmpty()) { - return true; - } - try { - BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); - return device == null || device.getBondState() != BluetoothDevice.BOND_NONE; - } catch (Throwable t) { - return true; - } - } - - /** - * Android's bond state for this address (BluetoothDevice.BOND_NONE / - * BOND_BONDING / BOND_BONDED), or -1 when it cannot be determined. - * BOND_BONDING covers the whole OS pairing flow, including a pairing - * dialog that is still waiting for the user. - */ - public int getBondState(String address) { - if (address == null || address.trim().isEmpty()) { - return -1; - } - try { - BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); - return device == null ? -1 : device.getBondState(); - } catch (Throwable t) { - return -1; - } - } - - /** Whether a GATT client for this address is open, i.e. no disconnect callback has arrived for it. */ - public boolean isConnected(String address) { - return address != null && gattClients.containsKey(address); - } - - public boolean connect(String address, int timeoutMs) { - if (address == null || address.trim().isEmpty()) { - throw new IllegalArgumentException("address is required"); - } - CountDownLatch latch = new CountDownLatch(1); - connectLatches.put(address, latch); - connectResults.remove(address); - - Object gattLock = gattLock(address); - BluetoothGatt gatt; - synchronized (gattLock) { - BluetoothGatt existing = gattClients.get(address); - if (existing != null) { - connectLatches.remove(address); - return true; - } - - final BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); - if (device == null) { - connectLatches.remove(address); - throw new IllegalArgumentException("remote device not found: " + address); - } - - gatt = device.connectGatt( - context, - false, - gattCallback, - BluetoothDevice.TRANSPORT_LE, - BluetoothDevice.PHY_LE_2M|BluetoothDevice.PHY_LE_1M - ); - if (gatt != null) { - gattClients.put(address, gatt); - } - - if (gatt == null) { - connectLatches.remove(address); - return false; - } - - if (!awaitLatch(latch, timeoutMs)) { - connectLatches.remove(address); - connectResults.remove(address); - gattClients.remove(address, gatt); - negotiatedMtus.remove(address); - gatt.disconnect(); - gatt.close(); - return false; - } - - Boolean connected = connectResults.remove(address); - connectLatches.remove(address); - return Boolean.TRUE.equals(connected); - } - } - - public boolean requestConnectionPriority(String address, int priority) { - synchronized (gattLock(address)) { - BluetoothGatt gatt = requireGatt(address); - return gatt.requestConnectionPriority(priority); - } - } - - /** One-shot benchmark preferences; success is established by callbacks/HCI, not submission. */ - public void prepareBenchmarkLink(String address, int mode) { - synchronized (gattLock(address)) { - BluetoothGatt gatt = requireGatt(address); - if ((mode & 1) != 0) { - boolean accepted = gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH); - Log.i(TAG, "benchmark HIGH address=" + address + " submitted=" + accepted); - } - if ((mode & 2) != 0) { - Log.i(TAG, "benchmark request 2M address=" + address); - gatt.setPreferredPhy(BluetoothDevice.PHY_LE_2M_MASK, - BluetoothDevice.PHY_LE_2M_MASK, BluetoothDevice.PHY_OPTION_NO_PREFERRED); - } - gatt.readPhy(); - } - } - - public int getNegotiatedMtu(String address) { - Integer mtu = negotiatedMtus.get(address); - return mtu == null ? 23 : mtu; - } - - public boolean requestMtu(String address, int mtu, int timeoutMs) { - synchronized (gattLock(address)) { - CountDownLatch latch = new CountDownLatch(1); - mtuLatches.put(address, latch); - mtuStatuses.remove(address); - - BluetoothGatt gatt = requireGatt(address); - boolean started = gatt.requestMtu(mtu); - if (!started) { - mtuLatches.remove(address); - return false; - } - if (!awaitLatch(latch, timeoutMs)) { - mtuLatches.remove(address); - mtuStatuses.remove(address); - return false; - } - Integer status = mtuStatuses.remove(address); - mtuLatches.remove(address); - return status != null && status == BluetoothGatt.GATT_SUCCESS; - } - } - - public boolean discoverServices(String address, int timeoutMs) { - synchronized (gattLock(address)) { - CountDownLatch latch = new CountDownLatch(1); - servicesLatches.put(address, latch); - servicesStatuses.remove(address); - - BluetoothGatt gatt = requireGatt(address); - boolean started = gatt.discoverServices(); - if (!started) { - servicesLatches.remove(address); - return false; - } - if (!awaitLatch(latch, timeoutMs)) { - servicesLatches.remove(address); - servicesStatuses.remove(address); - return false; - } - Integer status = servicesStatuses.remove(address); - servicesLatches.remove(address); - return status != null && status == BluetoothGatt.GATT_SUCCESS; - } - } - - public boolean enableNotifications(String address, String characteristicUuid, boolean enable, int timeoutMs) { - synchronized (gattLock(address)) { - CountDownLatch latch = new CountDownLatch(1); - descriptorLatches.put(address, latch); - descriptorStatuses.remove(address); - - BluetoothGatt gatt = requireGatt(address); - BluetoothGattCharacteristic characteristic = requireCharacteristic(gatt, characteristicUuid); - - boolean notificationSet = gatt.setCharacteristicNotification(characteristic, enable); - if (!notificationSet) { - descriptorLatches.remove(address); - return false; - } - - BluetoothGattDescriptor descriptor = characteristic.getDescriptor(java.util.UUID.fromString(BleProtocol.CCCD_UUID)); - if (descriptor == null) { - descriptorLatches.remove(address); - return true; - } - - descriptor.setValue(enable - ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE - : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); - boolean started = gatt.writeDescriptor(descriptor); - if (!started) { - descriptorLatches.remove(address); - descriptorStatuses.remove(address); - return false; - } - if (!awaitLatch(latch, timeoutMs)) { - descriptorLatches.remove(address); - descriptorStatuses.remove(address); - return false; - } - Integer status = descriptorStatuses.remove(address); - descriptorLatches.remove(address); - return status != null && status == BluetoothGatt.GATT_SUCCESS; - } - } - - public boolean writeFrames( - String address, - String characteristicUuid, - List frames, - int writeType, - int timeoutMs - ) { - if (frames == null || frames.isEmpty()) { - return true; - } - - long startMs = System.currentTimeMillis(); - synchronized (gattLock(address)) { - BluetoothGatt gatt = requireGatt(address); - BluetoothGattCharacteristic characteristic = requireCharacteristic(gatt, characteristicUuid); - - for (int i = 0; i < frames.size(); i++) { - byte[] frame = frames.get(i); - if (!startWrite(gatt, characteristic, address, frame, writeType, timeoutMs)) { - return false; - } - outboundBytes.addAndGet(frame != null ? frame.length : 0); - } - } - outboundMessages.incrementAndGet(); - int totalSize = frames.stream().mapToInt(frame -> frame != null ? frame.length : 0).sum(); - Log.i(TAG, "writeFrames wrote " + frames.size() + " frames totaling " + totalSize + " bytes in " + (System.currentTimeMillis() - startMs) + "ms"); - return true; - } - - private boolean startWrite( - BluetoothGatt gatt, - BluetoothGattCharacteristic characteristic, - String address, - byte[] data, - int writeType, - int timeoutMs - ) { - int retryCount = 0; - while (true) { - CountDownLatch latch = new CountDownLatch(1); - writeLatches.put(address, latch); - writeStatuses.remove(address); - - long currentTime = System.currentTimeMillis(); - int result = gatt.writeCharacteristic(characteristic, data, writeType); - long timeAsleep = System.currentTimeMillis() - currentTime; - //Log.i(TAG, "writeCharacteristic: spent " + timeAsleep + "ms"); - - if (result == android.bluetooth.BluetoothStatusCodes.ERROR_GATT_WRITE_REQUEST_BUSY) { - writeLatches.remove(address, latch); - writeStatuses.remove(address); - if (!sleepBeforeWriteRetry(address, "busy", retryCount++)) { - return false; - } - continue; - } else { - //Log.i(TAG, "writeCharacteristic with writeType=" + writeType + " result=" + result + " retryCount=" + retryCount); - if (result != android.bluetooth.BluetoothStatusCodes.SUCCESS) { - writeLatches.remove(address, latch); - writeStatuses.remove(address); - if (!sleepBeforeWriteRetry(address, "start result=" + result, retryCount++)) { - return false; - } - continue; - } - if (!awaitLatch(latch, timeoutMs)) { - writeLatches.remove(address, latch); - writeStatuses.remove(address); - return false; - } - Integer status = writeStatuses.remove(address); - writeLatches.remove(address); - if (status != null && status == BluetoothGatt.GATT_SUCCESS) { - return true; - } - if (!sleepBeforeWriteRetry(address, "callback status=" + status, retryCount++)) { - return false; - } - } - } - } - - private boolean sleepBeforeWriteRetry(String address, String reason, int retryIndex) { - if (retryIndex >= WRITE_RETRY_DELAYS_MS.length) { - Log.w(TAG, "writeCharacteristic retry exhausted: address=" + address + " reason=" + reason); - return false; - } - int delayMs = WRITE_RETRY_DELAYS_MS[retryIndex]; - Log.w(TAG, "writeCharacteristic retry: address=" + address + " reason=" + reason + " delayMs=" + delayMs); - try { - Thread.sleep(delayMs); - return true; - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return false; - } - } - - public void disconnect(String address) { - Object gattLock = gattLock(address); - synchronized (gattLock) { - BluetoothGatt gatt = gattClients.remove(address); - negotiatedMtus.remove(address); - if (gatt == null) { - return; - } - gatt.disconnect(); - gatt.close(); - } - } - - public void close() { - for (String address : gattClients.keySet()) { - disconnect(address); - } - } - - private BluetoothGatt requireGatt(String address) { - BluetoothGatt gatt = gattClients.get(address); - if (gatt == null) { - throw new IllegalStateException("Not connected: " + address); - } - return gatt; - } - - private BluetoothGattCharacteristic requireCharacteristic(BluetoothGatt gatt, String characteristicUuid) { - UUID target = UUID.fromString(characteristicUuid); - for (BluetoothGattService service : gatt.getServices()) { - BluetoothGattCharacteristic characteristic = service.getCharacteristic(target); - if (characteristic != null) { - return characteristic; - } - } - throw new IllegalStateException("Characteristic not found: " + characteristicUuid); - } - - private boolean awaitLatch(CountDownLatch latch, int timeoutMs) { - try { - return latch.await(timeoutMs, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return false; - } - } - - private Object gattLock(String address) { - // Android's Bluetooth stack has process-wide command-pipeline constraints on some devices. - // Keep every BluetoothGatt API call serialized globally, even for different MAC addresses. - return bluetoothApiLock; - } - - private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() { - @Override - public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { - Log.i(TAG, "onConnectionStateChange: status=" + status + " newState=" + newState); - String address = gatt.getDevice().getAddress(); - - if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) { - connectResults.put(address, true); - CountDownLatch latch = connectLatches.remove(address); - if (latch != null) { - latch.countDown(); - } - dispatchConnectionState(address, true); - return; - } - - if (newState == BluetoothProfile.STATE_DISCONNECTED) { - connectResults.put(address, false); - CountDownLatch latch = connectLatches.remove(address); - if (latch != null) { - latch.countDown(); - } - Object gattLock = gattLock(address); - synchronized (gattLock) { - gattClients.remove(address, gatt); - negotiatedMtus.remove(address); - gatt.close(); - } - dispatchConnectionState(address, false); - } - } - - @Override - public void onServicesDiscovered(BluetoothGatt gatt, int status) { - String address = gatt.getDevice().getAddress(); - servicesStatuses.put(address, status); - CountDownLatch latch = servicesLatches.remove(address); - if (latch != null) { - latch.countDown(); - } - } - - @Override - public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { - String address = gatt.getDevice().getAddress(); - if (status == BluetoothGatt.GATT_SUCCESS) negotiatedMtus.put(address, mtu); - mtuStatuses.put(address, status); - CountDownLatch latch = mtuLatches.remove(address); - if (latch != null) { - latch.countDown(); - } - } - - @Override - public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { - Log.i(TAG, "onPhyRead: address=" + gatt.getDevice().getAddress() - + " txPhy=" + txPhy + " rxPhy=" + rxPhy + " status=" + status); - } - - @Override - public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) { - Log.i(TAG, "onPhyUpdate: address=" + gatt.getDevice().getAddress() - + " txPhy=" + txPhy + " rxPhy=" + rxPhy + " status=" + status); - } - - @Override - public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { - String address = gatt.getDevice().getAddress(); - descriptorStatuses.put(address, status); - CountDownLatch latch = descriptorLatches.remove(address); - if (latch != null) { - latch.countDown(); - } - } - - @Override - public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { - String address = gatt.getDevice().getAddress(); - writeStatuses.put(address, status); - CountDownLatch latch = writeLatches.remove(address); - if (latch != null) { - latch.countDown(); - } - } - - @Override - public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value) { - dispatchNotification(gatt.getDevice().getAddress(), characteristic.getUuid().toString(), value); - } - - @Deprecated - @Override - public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { - dispatchNotification(gatt.getDevice().getAddress(), characteristic.getUuid().toString(), characteristic.getValue()); - } - }; - - private void dispatchConnectionState(String address, boolean connected) { - FaceclawBleListener current = listener; - if (current == null) return; - current.onConnectionStateChange(address, connected); - } - - private void dispatchNotification(String address, String characteristicUuid, byte[] data) { - FaceclawBleListener current = listener; - if (current == null) return; - byte[] copy = data != null ? data.clone() : new byte[0]; - current.onNotification(address, characteristicUuid, copy); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.kt new file mode 100644 index 00000000..2335605f --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.kt @@ -0,0 +1,539 @@ +package com.faceclaw.app + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothAdapter +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothGatt +import android.bluetooth.BluetoothGattCallback +import android.bluetooth.BluetoothGattCharacteristic +import android.bluetooth.BluetoothGattDescriptor +import android.bluetooth.BluetoothGattService +import android.bluetooth.BluetoothManager +import android.bluetooth.BluetoothProfile +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.util.Log + +import java.util.UUID +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicLong + +@SuppressLint("MissingPermission") +class FaceclawBleManager(context: Context) { + companion object { + private const val TAG = "FaceclawBle" + private val WRITE_RETRY_DELAYS_MS = intArrayOf(1, 1, 1, 2, 4, 8, 12, 20, 35, 100, 200) + + // Process-wide outbound-traffic totals, sampled by the phone UI's BLE + // bandwidth indicator. Static so counts from every manager instance and + // isolate land in the same totals. + private val outboundMessages = AtomicLong() + private val outboundBytes = AtomicLong() + private val displayFramesSent = AtomicLong() + + /** Called by the communicator when a display frame's last message is acked. */ + @JvmStatic + fun recordDisplayFrameSent() { + displayFramesSent.incrementAndGet() + } + + /** Running totals of outbound BLE traffic since process start: [messages, bytes, display frames]. */ + @JvmStatic + fun sampleOutboundTraffic(): LongArray { + return longArrayOf(outboundMessages.get(), outboundBytes.get(), displayFramesSent.get()) + } + } + + private val context: Context + private val bluetoothAdapter: BluetoothAdapter + private val mainHandler = Handler(Looper.getMainLooper()) + + private val gattClients = ConcurrentHashMap() + private val bluetoothApiLock = Any() + + private val connectLatches = ConcurrentHashMap() + private val connectResults = ConcurrentHashMap() + + private val servicesLatches = ConcurrentHashMap() + private val servicesStatuses = ConcurrentHashMap() + + private val mtuLatches = ConcurrentHashMap() + private val negotiatedMtus = ConcurrentHashMap() + private val mtuStatuses = ConcurrentHashMap() + + private val descriptorLatches = ConcurrentHashMap() + private val descriptorStatuses = ConcurrentHashMap() + + private val writeLatches = ConcurrentHashMap() + private val writeStatuses = ConcurrentHashMap() + + @Volatile + private var listener: FaceclawBleListener? = null + + init { + this.context = context.applicationContext + val bluetoothManager = this.context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager? + if (bluetoothManager == null || bluetoothManager.adapter == null) { + throw IllegalStateException("Bluetooth adapter unavailable") + } + this.bluetoothAdapter = bluetoothManager.adapter + } + + fun setListener(listener: FaceclawBleListener?) { + this.listener = listener + } + + /** + * Whether Android still holds a bond (pairing) for this address. Returns + * true when the state cannot be determined, so callers only act on a + * definite BOND_NONE. + */ + fun isBonded(address: String?): Boolean { + if (address == null || address.trim().isEmpty()) { + return true + } + try { + val device = bluetoothAdapter.getRemoteDevice(address) + return device == null || device.bondState != BluetoothDevice.BOND_NONE + } catch (t: Throwable) { + return true + } + } + + /** + * Android's bond state for this address (BluetoothDevice.BOND_NONE / + * BOND_BONDING / BOND_BONDED), or -1 when it cannot be determined. + * BOND_BONDING covers the whole OS pairing flow, including a pairing + * dialog that is still waiting for the user. + */ + fun getBondState(address: String?): Int { + if (address == null || address.trim().isEmpty()) { + return -1 + } + try { + val device = bluetoothAdapter.getRemoteDevice(address) + return if (device == null) -1 else device.bondState + } catch (t: Throwable) { + return -1 + } + } + + /** Whether a GATT client for this address is open, i.e. no disconnect callback has arrived for it. */ + fun isConnected(address: String?): Boolean { + return address != null && gattClients.containsKey(address) + } + + fun connect(address: String?, timeoutMs: Int): Boolean { + if (address == null || address.trim().isEmpty()) { + throw IllegalArgumentException("address is required") + } + val latch = CountDownLatch(1) + connectLatches[address] = latch + connectResults.remove(address) + + val gattLock = gattLock(address) + synchronized(gattLock) { + val existing = gattClients[address] + if (existing != null) { + connectLatches.remove(address) + return true + } + + val device = bluetoothAdapter.getRemoteDevice(address) + if (device == null) { + connectLatches.remove(address) + throw IllegalArgumentException("remote device not found: $address") + } + + val gatt: BluetoothGatt? = device.connectGatt( + context, + false, + gattCallback, + BluetoothDevice.TRANSPORT_LE, + BluetoothDevice.PHY_LE_2M or BluetoothDevice.PHY_LE_1M + ) + if (gatt != null) { + gattClients[address] = gatt + } + + if (gatt == null) { + connectLatches.remove(address) + return false + } + + if (!awaitLatch(latch, timeoutMs)) { + connectLatches.remove(address) + connectResults.remove(address) + gattClients.remove(address, gatt) + negotiatedMtus.remove(address) + gatt.disconnect() + gatt.close() + return false + } + + val connected = connectResults.remove(address) + connectLatches.remove(address) + return connected == true + } + } + + fun requestConnectionPriority(address: String, priority: Int): Boolean { + synchronized(gattLock(address)) { + val gatt = requireGatt(address) + return gatt.requestConnectionPriority(priority) + } + } + + /** One-shot benchmark preferences; success is established by callbacks/HCI, not submission. */ + fun prepareBenchmarkLink(address: String, mode: Int) { + synchronized(gattLock(address)) { + val gatt = requireGatt(address) + if ((mode and 1) != 0) { + val accepted = gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH) + Log.i(TAG, "benchmark HIGH address=$address submitted=$accepted") + } + if ((mode and 2) != 0) { + Log.i(TAG, "benchmark request 2M address=$address") + gatt.setPreferredPhy(BluetoothDevice.PHY_LE_2M_MASK, + BluetoothDevice.PHY_LE_2M_MASK, BluetoothDevice.PHY_OPTION_NO_PREFERRED) + } + gatt.readPhy() + } + } + + fun getNegotiatedMtu(address: String): Int { + val mtu = negotiatedMtus[address] + return mtu ?: 23 + } + + fun requestMtu(address: String, mtu: Int, timeoutMs: Int): Boolean { + synchronized(gattLock(address)) { + val latch = CountDownLatch(1) + mtuLatches[address] = latch + mtuStatuses.remove(address) + + val gatt = requireGatt(address) + val started = gatt.requestMtu(mtu) + if (!started) { + mtuLatches.remove(address) + return false + } + if (!awaitLatch(latch, timeoutMs)) { + mtuLatches.remove(address) + mtuStatuses.remove(address) + return false + } + val status = mtuStatuses.remove(address) + mtuLatches.remove(address) + return status != null && status == BluetoothGatt.GATT_SUCCESS + } + } + + fun discoverServices(address: String, timeoutMs: Int): Boolean { + synchronized(gattLock(address)) { + val latch = CountDownLatch(1) + servicesLatches[address] = latch + servicesStatuses.remove(address) + + val gatt = requireGatt(address) + val started = gatt.discoverServices() + if (!started) { + servicesLatches.remove(address) + return false + } + if (!awaitLatch(latch, timeoutMs)) { + servicesLatches.remove(address) + servicesStatuses.remove(address) + return false + } + val status = servicesStatuses.remove(address) + servicesLatches.remove(address) + return status != null && status == BluetoothGatt.GATT_SUCCESS + } + } + + fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean { + synchronized(gattLock(address)) { + val latch = CountDownLatch(1) + descriptorLatches[address] = latch + descriptorStatuses.remove(address) + + val gatt = requireGatt(address) + val characteristic = requireCharacteristic(gatt, characteristicUuid) + + val notificationSet = gatt.setCharacteristicNotification(characteristic, enable) + if (!notificationSet) { + descriptorLatches.remove(address) + return false + } + + val descriptor = characteristic.getDescriptor(java.util.UUID.fromString(BleProtocol.CCCD_UUID)) + if (descriptor == null) { + descriptorLatches.remove(address) + return true + } + + descriptor.value = if (enable) + BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE + else + BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE + val started = gatt.writeDescriptor(descriptor) + if (!started) { + descriptorLatches.remove(address) + descriptorStatuses.remove(address) + return false + } + if (!awaitLatch(latch, timeoutMs)) { + descriptorLatches.remove(address) + descriptorStatuses.remove(address) + return false + } + val status = descriptorStatuses.remove(address) + descriptorLatches.remove(address) + return status != null && status == BluetoothGatt.GATT_SUCCESS + } + } + + fun writeFrames( + address: String, + characteristicUuid: String, + frames: List?, + writeType: Int, + timeoutMs: Int + ): Boolean { + if (frames == null || frames.isEmpty()) { + return true + } + + val startMs = System.currentTimeMillis() + synchronized(gattLock(address)) { + val gatt = requireGatt(address) + val characteristic = requireCharacteristic(gatt, characteristicUuid) + + for (i in frames.indices) { + val frame = frames[i] + if (!startWrite(gatt, characteristic, address, frame, writeType, timeoutMs)) { + return false + } + outboundBytes.addAndGet((frame?.size ?: 0).toLong()) + } + } + outboundMessages.incrementAndGet() + val totalSize = frames.sumOf { frame -> frame?.size ?: 0 } + Log.i(TAG, "writeFrames wrote " + frames.size + " frames totaling " + totalSize + " bytes in " + (System.currentTimeMillis() - startMs) + "ms") + return true + } + + private fun startWrite( + gatt: BluetoothGatt, + characteristic: BluetoothGattCharacteristic, + address: String, + data: ByteArray?, + writeType: Int, + timeoutMs: Int + ): Boolean { + var retryCount = 0 + while (true) { + val latch = CountDownLatch(1) + writeLatches[address] = latch + writeStatuses.remove(address) + + val currentTime = System.currentTimeMillis() + val result = gatt.writeCharacteristic(characteristic, data!!, writeType) + val timeAsleep = System.currentTimeMillis() - currentTime + //Log.i(TAG, "writeCharacteristic: spent " + timeAsleep + "ms"); + + if (result == android.bluetooth.BluetoothStatusCodes.ERROR_GATT_WRITE_REQUEST_BUSY) { + writeLatches.remove(address, latch) + writeStatuses.remove(address) + if (!sleepBeforeWriteRetry(address, "busy", retryCount++)) { + return false + } + continue + } else { + //Log.i(TAG, "writeCharacteristic with writeType=" + writeType + " result=" + result + " retryCount=" + retryCount); + if (result != android.bluetooth.BluetoothStatusCodes.SUCCESS) { + writeLatches.remove(address, latch) + writeStatuses.remove(address) + if (!sleepBeforeWriteRetry(address, "start result=$result", retryCount++)) { + return false + } + continue + } + if (!awaitLatch(latch, timeoutMs)) { + writeLatches.remove(address, latch) + writeStatuses.remove(address) + return false + } + val status = writeStatuses.remove(address) + writeLatches.remove(address) + if (status != null && status == BluetoothGatt.GATT_SUCCESS) { + return true + } + if (!sleepBeforeWriteRetry(address, "callback status=$status", retryCount++)) { + return false + } + } + } + } + + private fun sleepBeforeWriteRetry(address: String, reason: String, retryIndex: Int): Boolean { + if (retryIndex >= WRITE_RETRY_DELAYS_MS.size) { + Log.w(TAG, "writeCharacteristic retry exhausted: address=$address reason=$reason") + return false + } + val delayMs = WRITE_RETRY_DELAYS_MS[retryIndex] + Log.w(TAG, "writeCharacteristic retry: address=$address reason=$reason delayMs=$delayMs") + try { + Thread.sleep(delayMs.toLong()) + return true + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + return false + } + } + + fun disconnect(address: String?) { + val gattLock = gattLock(address) + synchronized(gattLock) { + val gatt = if (address != null) gattClients.remove(address) else null + if (address != null) negotiatedMtus.remove(address) + if (gatt == null) { + return + } + gatt.disconnect() + gatt.close() + } + } + + fun close() { + for (address in gattClients.keys) { + disconnect(address) + } + } + + private fun requireGatt(address: String): BluetoothGatt { + val gatt = gattClients[address] + if (gatt == null) { + throw IllegalStateException("Not connected: $address") + } + return gatt + } + + private fun requireCharacteristic(gatt: BluetoothGatt, characteristicUuid: String): BluetoothGattCharacteristic { + val target = UUID.fromString(characteristicUuid) + for (service: BluetoothGattService in gatt.services) { + val characteristic = service.getCharacteristic(target) + if (characteristic != null) { + return characteristic + } + } + throw IllegalStateException("Characteristic not found: $characteristicUuid") + } + + private fun awaitLatch(latch: CountDownLatch, timeoutMs: Int): Boolean { + try { + return latch.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + return false + } + } + + private fun gattLock(address: String?): Any { + // Android's Bluetooth stack has process-wide command-pipeline constraints on some devices. + // Keep every BluetoothGatt API call serialized globally, even for different MAC addresses. + return bluetoothApiLock + } + + private val gattCallback: BluetoothGattCallback = object : BluetoothGattCallback() { + override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { + Log.i(TAG, "onConnectionStateChange: status=$status newState=$newState") + val address = gatt.device.address + + if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) { + connectResults[address] = true + val latch = connectLatches.remove(address) + latch?.countDown() + dispatchConnectionState(address, true) + return + } + + if (newState == BluetoothProfile.STATE_DISCONNECTED) { + connectResults[address] = false + val latch = connectLatches.remove(address) + latch?.countDown() + val gattLock = gattLock(address) + synchronized(gattLock) { + gattClients.remove(address, gatt) + negotiatedMtus.remove(address) + gatt.close() + } + dispatchConnectionState(address, false) + } + } + + override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { + val address = gatt.device.address + servicesStatuses[address] = status + val latch = servicesLatches.remove(address) + latch?.countDown() + } + + override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) { + val address = gatt.device.address + if (status == BluetoothGatt.GATT_SUCCESS) negotiatedMtus[address] = mtu + mtuStatuses[address] = status + val latch = mtuLatches.remove(address) + latch?.countDown() + } + + override fun onPhyRead(gatt: BluetoothGatt, txPhy: Int, rxPhy: Int, status: Int) { + Log.i(TAG, "onPhyRead: address=" + gatt.device.address + + " txPhy=" + txPhy + " rxPhy=" + rxPhy + " status=" + status) + } + + override fun onPhyUpdate(gatt: BluetoothGatt, txPhy: Int, rxPhy: Int, status: Int) { + Log.i(TAG, "onPhyUpdate: address=" + gatt.device.address + + " txPhy=" + txPhy + " rxPhy=" + rxPhy + " status=" + status) + } + + override fun onDescriptorWrite(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) { + val address = gatt.device.address + descriptorStatuses[address] = status + val latch = descriptorLatches.remove(address) + latch?.countDown() + } + + override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { + val address = gatt.device.address + writeStatuses[address] = status + val latch = writeLatches.remove(address) + latch?.countDown() + } + + override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, value: ByteArray) { + dispatchNotification(gatt.device.address, characteristic.uuid.toString(), value) + } + + @Deprecated("Deprecated in Java") + override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) { + dispatchNotification(gatt.device.address, characteristic.uuid.toString(), characteristic.value) + } + } + + private fun dispatchConnectionState(address: String, connected: Boolean) { + val current = listener ?: return + current.onConnectionStateChange(address, connected) + } + + private fun dispatchNotification(address: String, characteristicUuid: String, data: ByteArray?) { + val current = listener ?: return + val copy = data?.clone() ?: ByteArray(0) + current.onNotification(address, characteristicUuid, copy) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.java deleted file mode 100644 index fbdb25af..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.faceclaw.app; - -import android.content.ContentUris; -import android.content.Context; -import android.database.Cursor; -import android.net.Uri; -import android.provider.CalendarContract; -import android.util.Log; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Reads upcoming events from the Android Calendar provider for the Calendar - * app. Queries the Instances table (rather than Events) so that recurring - * events are expanded into concrete occurrences within the requested window. - * Requires the READ_CALENDAR runtime permission; without it the content - * resolver throws SecurityException and this returns an empty array. - */ -public final class FaceclawCalendarProvider { - private static final String TAG = "FaceclawCalendar"; - - private static final String[] PROJECTION = { - CalendarContract.Instances.EVENT_ID, - CalendarContract.Instances.TITLE, - CalendarContract.Instances.BEGIN, - CalendarContract.Instances.END, - CalendarContract.Instances.ALL_DAY, - CalendarContract.Instances.EVENT_LOCATION, - CalendarContract.Instances.CALENDAR_DISPLAY_NAME, - }; - - private FaceclawCalendarProvider() { - } - - /** - * JSON array of upcoming events starting from now through now+windowMs, - * ordered by start time, capped at maxEvents. Each element carries id, - * title, startMs, endMs, allDay, location, and calendarName. - */ - public static String getUpcomingEventsJson(Context context, int maxEvents, long windowMs) { - if (context == null || maxEvents <= 0) { - return "[]"; - } - long now = System.currentTimeMillis(); - long end = now + Math.max(0L, windowMs); - int limit = Math.min(200, maxEvents); - - Uri.Builder builder = CalendarContract.Instances.CONTENT_URI.buildUpon(); - ContentUris.appendId(builder, now); - ContentUris.appendId(builder, end); - Uri uri = builder.build(); - - JSONArray out = new JSONArray(); - Cursor cursor = null; - try { - cursor = context.getContentResolver().query( - uri, - PROJECTION, - null, - null, - CalendarContract.Instances.BEGIN + " ASC"); - if (cursor != null) { - while (cursor.moveToNext() && out.length() < limit) { - try { - out.put(buildEventJson(cursor)); - } catch (JSONException e) { - Log.w(TAG, "failed to serialize calendar event", e); - } - } - } - } catch (SecurityException e) { - Log.w(TAG, "calendar access denied while reading events", e); - return "[]"; - } catch (Throwable t) { - Log.w(TAG, "failed to read calendar events", t); - return "[]"; - } finally { - if (cursor != null) { - cursor.close(); - } - } - return out.toString(); - } - - private static JSONObject buildEventJson(Cursor cursor) throws JSONException { - JSONObject event = new JSONObject(); - event.put("id", cursor.getLong(0)); - event.put("title", cursor.isNull(1) ? "" : cursor.getString(1)); - event.put("startMs", cursor.getLong(2)); - event.put("endMs", cursor.getLong(3)); - event.put("allDay", cursor.getInt(4) != 0); - event.put("location", cursor.isNull(5) ? "" : cursor.getString(5)); - event.put("calendarName", cursor.isNull(6) ? "" : cursor.getString(6)); - return event; - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.kt new file mode 100644 index 00000000..baa36749 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.kt @@ -0,0 +1,96 @@ +package com.faceclaw.app + +import android.content.ContentUris +import android.content.Context +import android.database.Cursor +import android.provider.CalendarContract +import android.util.Log + +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject + +/** + * Reads upcoming events from the Android Calendar provider for the Calendar + * app. Queries the Instances table (rather than Events) so that recurring + * events are expanded into concrete occurrences within the requested window. + * Requires the READ_CALENDAR runtime permission; without it the content + * resolver throws SecurityException and this returns an empty array. + */ +class FaceclawCalendarProvider private constructor() { + companion object { + private const val TAG = "FaceclawCalendar" + + private val PROJECTION = arrayOf( + CalendarContract.Instances.EVENT_ID, + CalendarContract.Instances.TITLE, + CalendarContract.Instances.BEGIN, + CalendarContract.Instances.END, + CalendarContract.Instances.ALL_DAY, + CalendarContract.Instances.EVENT_LOCATION, + CalendarContract.Instances.CALENDAR_DISPLAY_NAME, + ) + + /** + * JSON array of upcoming events starting from now through now+windowMs, + * ordered by start time, capped at maxEvents. Each element carries id, + * title, startMs, endMs, allDay, location, and calendarName. + */ + @JvmStatic + fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long): String { + if (context == null || maxEvents <= 0) { + return "[]" + } + val now = System.currentTimeMillis() + val end = now + Math.max(0L, windowMs) + val limit = Math.min(200, maxEvents) + + val builder = CalendarContract.Instances.CONTENT_URI.buildUpon() + ContentUris.appendId(builder, now) + ContentUris.appendId(builder, end) + val uri = builder.build() + + val out = JSONArray() + var cursor: Cursor? = null + try { + cursor = context.contentResolver.query( + uri, + PROJECTION, + null, + null, + CalendarContract.Instances.BEGIN + " ASC") + if (cursor != null) { + while (cursor.moveToNext() && out.length() < limit) { + try { + out.put(buildEventJson(cursor)) + } catch (e: JSONException) { + Log.w(TAG, "failed to serialize calendar event", e) + } + } + } + } catch (e: SecurityException) { + Log.w(TAG, "calendar access denied while reading events", e) + return "[]" + } catch (t: Throwable) { + Log.w(TAG, "failed to read calendar events", t) + return "[]" + } finally { + cursor?.close() + } + return out.toString() + } + + @Throws(JSONException::class) + private fun buildEventJson(cursor: Cursor): JSONObject { + val event = JSONObject() + event.put("id", cursor.getLong(0)) + event.put("title", if (cursor.isNull(1)) "" else cursor.getString(1)) + event.put("startMs", cursor.getLong(2)) + event.put("endMs", cursor.getLong(3)) + event.put("allDay", cursor.getInt(4) != 0) + event.put("location", if (cursor.isNull(5)) "" else cursor.getString(5)) + event.put("calendarName", if (cursor.isNull(6)) "" else cursor.getString(6)) + return event + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.java deleted file mode 100644 index 488d2bca..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.java +++ /dev/null @@ -1,446 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import com.k2fsa.sherpa.onnx.FeatureConfig; -import com.k2fsa.sherpa.onnx.OfflineModelConfig; -import com.k2fsa.sherpa.onnx.OfflineMoonshineModelConfig; -import com.k2fsa.sherpa.onnx.OfflineRecognizer; -import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig; -import com.k2fsa.sherpa.onnx.OfflineRecognizerResult; -import com.k2fsa.sherpa.onnx.OfflineStream; - -import java.io.File; -import java.util.ArrayDeque; -import java.util.Arrays; - -/** - * Continuous captioning over the decoded mic PCM: segments speech into - * utterances with an adaptive energy gate, transcribes each utterance with - * the on-device Moonshine model, and attaches a speaker voice-print per - * utterance. PCM is pushed in from the TS side (which owns mic arbitration - * and any beam-direction gating), so this engine has no BLE dependencies. - * - * Utterance boundaries are measured on the sample clock, not the wall clock: - * BLE delivers mic packets in bursts, so elapsed real time overestimates the - * audio heard. The TS side converts startMs/endMs to wall-clock times using - * the engine start timestamp. - */ -public class FaceclawCaptionEngine { - private static final String TAG = "FaceclawCaptions"; - private static final int SAMPLE_RATE = 16000; - private static final int FEATURE_DIM = 80; - private static final int MAX_QUEUE_PACKETS = 200; - - // Segmentation: RMS thresholds relative to a rolling noise floor, in the - // same spirit as FaceclawVoiceController.EndpointDetector but recurring. - private static final double ONSET_FACTOR = 3.0; - private static final double RELEASE_FACTOR = 1.8; - private static final double MIN_RMS = 220.0; - private static final double NOISE_EMA_ALPHA = 0.05; - private static final int PRE_ROLL_MS = 400; - private static final int DEFAULT_SILENCE_MS = 800; - private static final int MIN_UTTERANCE_MS = 350; - private static final int MAX_UTTERANCE_MS = 15000; - // Moonshine v2 fails past ~9.1 s of input; decode long utterances in - // segments cut at the quietest window (mirrors FaceclawVoiceController). - private static final int DECODE_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8; - private static final int CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2; - private static final int CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000; - private static final float NORMALIZE_TARGET_PEAK = 0.9f; - private static final float NORMALIZE_MAX_GAIN = 30f; - // Voice-prints degrade on very long inputs; embed at most the first 10 s. - private static final int EMBED_MAX_SAMPLES = SAMPLE_RATE * 10; - - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private final Object lock = new Object(); - private final Object queueLock = new Object(); - private final ArrayDeque queue = new ArrayDeque<>(); - - private volatile FaceclawCaptionEngineListener listener; - private volatile String asrModelDir; - private volatile String speakerModelPath; - private volatile int silenceMs = DEFAULT_SILENCE_MS; - private Thread workerThread; - private volatile boolean started; - - private OfflineRecognizer recognizer; - private FaceclawSpeakerId speakerId; - - // Segmentation state (worker thread only). - private long totalSamples; - private double noiseFloor; - private boolean inUtterance; - private long utteranceStartSample; - private long silenceRunSamples; - private double utterancePeakRms; - private short[] utterance = new short[SAMPLE_RATE * (MAX_UTTERANCE_MS / 1000)]; - private int utteranceLength; - private final short[] preRoll = new short[SAMPLE_RATE * PRE_ROLL_MS / 1000]; - private int preRollLength; - - public void setListener(FaceclawCaptionEngineListener listener) { - this.listener = listener; - } - - /** Directory holding the Moonshine model files, or null to disable ASR. */ - public void setAsrModelDir(String dir) { - this.asrModelDir = dir; - } - - /** Speaker-embedding ONNX model path, or null to disable voice-prints. */ - public void setSpeakerModelPath(String path) { - this.speakerModelPath = path; - } - - public void setSilenceMs(int ms) { - this.silenceMs = Math.max(200, Math.min(3000, ms)); - } - - public void start() { - synchronized (lock) { - if (started) { - return; - } - started = true; - workerThread = new Thread(this::runLoop, "FaceclawCaptionEngine"); - workerThread.start(); - } - } - - public void stop() { - Thread threadToJoin; - synchronized (lock) { - if (!started) { - return; - } - started = false; - threadToJoin = workerThread; - workerThread = null; - } - synchronized (queueLock) { - queueLock.notifyAll(); - } - if (threadToJoin != null) { - threadToJoin.interrupt(); - if (Thread.currentThread() != threadToJoin) { - try { - threadToJoin.join(2000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - - /** Push decoded 16 kHz mono S16LE PCM (any chunking). */ - public void acceptPcm(byte[] pcm16le) { - if (!started || pcm16le == null || pcm16le.length < 2) { - return; - } - synchronized (queueLock) { - if (queue.size() >= MAX_QUEUE_PACKETS) { - queue.removeFirst(); - } - queue.addLast(pcm16le); - queueLock.notifyAll(); - } - } - - private void runLoop() { - try { - loadModels(); - resetSegmentation(); - while (started && !Thread.currentThread().isInterrupted()) { - byte[] chunk = takeChunk(); - if (chunk == null) { - continue; - } - processChunk(chunk); - } - // Flush a trailing utterance so its text isn't lost on stop. - if (inUtterance && utteranceLength > 0) { - finalizeUtterance(); - } - } catch (Throwable t) { - Log.e(TAG, "caption engine failed", t); - emitStatus("Captions failed: " + t.getMessage()); - } finally { - releaseModels(); - } - } - - private void loadModels() { - String modelDir = asrModelDir; - if (modelDir != null && new File(modelDir, "tokens.txt").exists()) { - emitStatus("Loading caption model..."); - recognizer = new OfflineRecognizer(OfflineRecognizerConfig.builder() - .setFeatureConfig(FeatureConfig.builder() - .setSampleRate(SAMPLE_RATE) - .setFeatureDim(FEATURE_DIM) - .build()) - .setModelConfig(OfflineModelConfig.builder() - .setMoonshine(OfflineMoonshineModelConfig.builder() - .setEncoder(new File(modelDir, "encoder_model.ort").getAbsolutePath()) - .setMergedDecoder(new File(modelDir, "decoder_model_merged.ort").getAbsolutePath()) - .build()) - .setTokens(new File(modelDir, "tokens.txt").getAbsolutePath()) - .setNumThreads(1) - .build()) - .build()); - } else { - recognizer = null; - } - String embedModel = speakerModelPath; - if (embedModel != null && new File(embedModel).exists()) { - speakerId = new FaceclawSpeakerId(embedModel); - speakerId.ensureLoaded(); - } else { - speakerId = null; - } - emitStatus(recognizer != null ? "Captions listening..." : "Captions listening (no ASR model)..."); - } - - private void releaseModels() { - if (recognizer != null) { - recognizer.release(); - recognizer = null; - } - if (speakerId != null) { - speakerId.close(); - speakerId = null; - } - } - - private byte[] takeChunk() { - synchronized (queueLock) { - while (started && queue.isEmpty()) { - try { - queueLock.wait(250); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return null; - } - } - return queue.pollFirst(); - } - } - - private void resetSegmentation() { - totalSamples = 0; - noiseFloor = 0; - inUtterance = false; - utteranceLength = 0; - preRollLength = 0; - silenceRunSamples = 0; - utterancePeakRms = 0; - } - - private void processChunk(byte[] chunk) { - int count = chunk.length / 2; - short[] pcm = new short[count]; - double sumSquares = 0; - for (int i = 0; i < count; i++) { - short s = (short) ((chunk[i * 2] & 0xff) | (chunk[i * 2 + 1] << 8)); - pcm[i] = s; - sumSquares += (double) s * s; - } - double rms = Math.sqrt(sumSquares / Math.max(1, count)); - totalSamples += count; - - if (!inUtterance) { - // Track the noise floor only while idle so speech doesn't raise it. - noiseFloor = noiseFloor == 0 ? rms : noiseFloor * (1 - NOISE_EMA_ALPHA) + rms * NOISE_EMA_ALPHA; - double threshold = Math.max(noiseFloor, MIN_RMS); - if (rms >= threshold * ONSET_FACTOR) { - inUtterance = true; - utteranceLength = 0; - silenceRunSamples = 0; - utterancePeakRms = rms; - appendUtterance(preRoll, preRollLength); - utteranceStartSample = Math.max(0, totalSamples - count - preRollLength); - appendUtterance(pcm, count); - emitSpeechStart(utteranceStartSample * 1000 / SAMPLE_RATE); - } else { - appendPreRoll(pcm, count); - } - return; - } - - appendUtterance(pcm, count); - utterancePeakRms = Math.max(utterancePeakRms, rms); - double threshold = Math.max(noiseFloor, MIN_RMS); - if (rms < threshold * RELEASE_FACTOR) { - silenceRunSamples += count; - } else { - silenceRunSamples = 0; - } - long utteranceMs = (long) utteranceLength * 1000 / SAMPLE_RATE; - boolean silenceEnded = silenceRunSamples * 1000L / SAMPLE_RATE >= silenceMs; - if (silenceEnded || utteranceMs >= MAX_UTTERANCE_MS) { - finalizeUtterance(); - inUtterance = false; - preRollLength = 0; - } - } - - private void appendPreRoll(short[] pcm, int count) { - // Keep the last PRE_ROLL_MS of idle audio so onset consonants survive. - if (count >= preRoll.length) { - System.arraycopy(pcm, count - preRoll.length, preRoll, 0, preRoll.length); - preRollLength = preRoll.length; - return; - } - int keep = Math.min(preRollLength, preRoll.length - count); - System.arraycopy(preRoll, preRollLength - keep, preRoll, 0, keep); - System.arraycopy(pcm, 0, preRoll, keep, count); - preRollLength = keep + count; - } - - private void appendUtterance(short[] pcm, int count) { - int room = utterance.length - utteranceLength; - int copied = Math.min(room, count); - if (copied > 0) { - System.arraycopy(pcm, 0, utterance, utteranceLength, copied); - utteranceLength += copied; - } - } - - private void finalizeUtterance() { - int length = utteranceLength; - long startMs = utteranceStartSample * 1000 / SAMPLE_RATE; - long endMs = (utteranceStartSample + length) * 1000 / SAMPLE_RATE; - if (endMs - startMs < MIN_UTTERANCE_MS) { - return; - } - String text = recognizeUtterance(length); - float[] embedding = embedUtterance(length); - emitUtterance(text, embedding, startMs, endMs, utterancePeakRms); - } - - private String recognizeUtterance(int length) { - if (recognizer == null || length <= 0) { - return ""; - } - StringBuilder joined = new StringBuilder(); - int offset = 0; - while (offset < length) { - int remaining = length - offset; - int segment = Math.min(remaining, DECODE_SEGMENT_MAX_SAMPLES); - if (remaining > DECODE_SEGMENT_MAX_SAMPLES) { - segment = findQuietCut(offset, segment); - } - String part = recognizeRange(offset, segment); - if (part.length() > 0) { - if (joined.length() > 0 && ".,!?;:%)]}".indexOf(part.charAt(0)) < 0) { - joined.append(' '); - } - joined.append(part); - } - offset += segment; - } - return joined.toString().trim(); - } - - /** - * End a decode segment at the center of the quietest window near its end - * so the cut lands between words (same approach as the PTT controller). - */ - private int findQuietCut(int offset, int segment) { - int searchStart = Math.max(0, segment - CUT_SEARCH_SAMPLES); - int win = CUT_WINDOW_SAMPLES; - if (segment - searchStart <= win) { - return segment; - } - double sum = 0; - for (int i = searchStart; i < searchStart + win; i++) { - double s = utterance[offset + i]; - sum += s * s; - } - double best = sum; - int bestStart = searchStart; - for (int start = searchStart + 1; start + win <= segment; start++) { - double dropped = utterance[offset + start - 1]; - double added = utterance[offset + start + win - 1]; - sum += added * added - dropped * dropped; - if (sum < best) { - best = sum; - bestStart = start; - } - } - return bestStart + win / 2; - } - - private String recognizeRange(int offset, int count) { - float[] samples = new float[count]; - float peak = 0f; - for (int i = 0; i < count; i++) { - float v = utterance[offset + i] / 32768.0f; - samples[i] = v; - float a = Math.abs(v); - if (a > peak) { - peak = a; - } - } - if (peak > 0f) { - float gain = Math.min(NORMALIZE_TARGET_PEAK / peak, NORMALIZE_MAX_GAIN); - if (gain > 1f) { - for (int i = 0; i < count; i++) { - samples[i] *= gain; - } - } - } - OfflineStream stream = recognizer.createStream(); - try { - stream.acceptWaveform(samples, SAMPLE_RATE); - recognizer.decode(stream); - OfflineRecognizerResult result = recognizer.getResult(stream); - String raw = result == null ? "" : result.getText(); - return raw == null ? "" : raw.trim(); - } finally { - stream.release(); - } - } - - private float[] embedUtterance(int length) { - FaceclawSpeakerId currentSpeakerId = speakerId; - if (currentSpeakerId == null || length <= 0) { - return null; - } - int count = Math.min(length, EMBED_MAX_SAMPLES); - byte[] le = new byte[count * 2]; - for (int i = 0; i < count; i++) { - short s = utterance[i]; - le[i * 2] = (byte) (s & 0xff); - le[i * 2 + 1] = (byte) ((s >> 8) & 0xff); - } - return currentSpeakerId.embed(le, SAMPLE_RATE); - } - - private void emitUtterance(String text, float[] embedding, long startMs, long endMs, double peakRms) { - FaceclawCaptionEngineListener currentListener = listener; - if (currentListener == null) { - return; - } - float[] embeddingCopy = embedding == null ? null : Arrays.copyOf(embedding, embedding.length); - mainHandler.post(() -> currentListener.onUtterance(text, embeddingCopy, startMs, endMs, peakRms)); - } - - private void emitSpeechStart(long startMs) { - FaceclawCaptionEngineListener currentListener = listener; - if (currentListener == null) { - return; - } - mainHandler.post(() -> currentListener.onSpeechStart(startMs)); - } - - private void emitStatus(String status) { - FaceclawCaptionEngineListener currentListener = listener; - if (currentListener == null) { - return; - } - mainHandler.post(() -> currentListener.onStatus(status)); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt new file mode 100644 index 00000000..c0cc2e04 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt @@ -0,0 +1,456 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.util.Log + +import com.k2fsa.sherpa.onnx.FeatureConfig +import com.k2fsa.sherpa.onnx.OfflineModelConfig +import com.k2fsa.sherpa.onnx.OfflineMoonshineModelConfig +import com.k2fsa.sherpa.onnx.OfflineRecognizer +import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig +import com.k2fsa.sherpa.onnx.OfflineRecognizerResult +import com.k2fsa.sherpa.onnx.OfflineStream + +import java.io.File +import java.util.ArrayDeque +import java.util.Arrays + +/** + * Continuous captioning over the decoded mic PCM: segments speech into + * utterances with an adaptive energy gate, transcribes each utterance with + * the on-device Moonshine model, and attaches a speaker voice-print per + * utterance. PCM is pushed in from the TS side (which owns mic arbitration + * and any beam-direction gating), so this engine has no BLE dependencies. + * + * Utterance boundaries are measured on the sample clock, not the wall clock: + * BLE delivers mic packets in bursts, so elapsed real time overestimates the + * audio heard. The TS side converts startMs/endMs to wall-clock times using + * the engine start timestamp. + */ +class FaceclawCaptionEngine { + companion object { + private const val TAG = "FaceclawCaptions" + private const val SAMPLE_RATE = 16000 + private const val FEATURE_DIM = 80 + private const val MAX_QUEUE_PACKETS = 200 + + // Segmentation: RMS thresholds relative to a rolling noise floor, in the + // same spirit as FaceclawVoiceController.EndpointDetector but recurring. + private const val ONSET_FACTOR = 3.0 + private const val RELEASE_FACTOR = 1.8 + private const val MIN_RMS = 220.0 + private const val NOISE_EMA_ALPHA = 0.05 + private const val PRE_ROLL_MS = 400 + private const val DEFAULT_SILENCE_MS = 800 + private const val MIN_UTTERANCE_MS = 350 + private const val MAX_UTTERANCE_MS = 15000 + // Moonshine v2 fails past ~9.1 s of input; decode long utterances in + // segments cut at the quietest window (mirrors FaceclawVoiceController). + private const val DECODE_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8 + private const val CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2 + private const val CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000 + private const val NORMALIZE_TARGET_PEAK = 0.9f + private const val NORMALIZE_MAX_GAIN = 30f + // Voice-prints degrade on very long inputs; embed at most the first 10 s. + private const val EMBED_MAX_SAMPLES = SAMPLE_RATE * 10 + } + + private val mainHandler = Handler(Looper.getMainLooper()) + private val lock = Any() + private val queueLock = Any() + private val queue = ArrayDeque() + + @Volatile + private var listener: FaceclawCaptionEngineListener? = null + @Volatile + private var asrModelDir: String? = null + @Volatile + private var speakerModelPath: String? = null + @Volatile + private var silenceMs = DEFAULT_SILENCE_MS + private var workerThread: Thread? = null + @Volatile + private var started = false + + private var recognizer: OfflineRecognizer? = null + private var speakerId: FaceclawSpeakerId? = null + + // Segmentation state (worker thread only). + private var totalSamples: Long = 0 + private var noiseFloor = 0.0 + private var inUtterance = false + private var utteranceStartSample: Long = 0 + private var silenceRunSamples: Long = 0 + private var utterancePeakRms = 0.0 + private var utterance = ShortArray(SAMPLE_RATE * (MAX_UTTERANCE_MS / 1000)) + private var utteranceLength = 0 + private val preRoll = ShortArray(SAMPLE_RATE * PRE_ROLL_MS / 1000) + private var preRollLength = 0 + + fun setListener(listener: FaceclawCaptionEngineListener?) { + this.listener = listener + } + + /** Directory holding the Moonshine model files, or null to disable ASR. */ + fun setAsrModelDir(dir: String?) { + this.asrModelDir = dir + } + + /** Speaker-embedding ONNX model path, or null to disable voice-prints. */ + fun setSpeakerModelPath(path: String?) { + this.speakerModelPath = path + } + + fun setSilenceMs(ms: Int) { + this.silenceMs = Math.max(200, Math.min(3000, ms)) + } + + fun start() { + synchronized(lock) { + if (started) { + return + } + started = true + workerThread = Thread(Runnable { runLoop() }, "FaceclawCaptionEngine") + workerThread!!.start() + } + } + + fun stop() { + val threadToJoin: Thread? + synchronized(lock) { + if (!started) { + return + } + started = false + threadToJoin = workerThread + workerThread = null + } + synchronized(queueLock) { + (queueLock as java.lang.Object).notifyAll() + } + if (threadToJoin != null) { + threadToJoin.interrupt() + if (Thread.currentThread() !== threadToJoin) { + try { + threadToJoin.join(2000) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + } + } + } + } + + /** Push decoded 16 kHz mono S16LE PCM (any chunking). */ + fun acceptPcm(pcm16le: ByteArray?) { + if (!started || pcm16le == null || pcm16le.size < 2) { + return + } + synchronized(queueLock) { + if (queue.size >= MAX_QUEUE_PACKETS) { + queue.removeFirst() + } + queue.addLast(pcm16le) + (queueLock as java.lang.Object).notifyAll() + } + } + + private fun runLoop() { + try { + loadModels() + resetSegmentation() + while (started && !Thread.currentThread().isInterrupted) { + val chunk = takeChunk() + if (chunk == null) { + continue + } + processChunk(chunk) + } + // Flush a trailing utterance so its text isn't lost on stop. + if (inUtterance && utteranceLength > 0) { + finalizeUtterance() + } + } catch (t: Throwable) { + Log.e(TAG, "caption engine failed", t) + emitStatus("Captions failed: " + t.message) + } finally { + releaseModels() + } + } + + private fun loadModels() { + val modelDir = asrModelDir + if (modelDir != null && File(modelDir, "tokens.txt").exists()) { + emitStatus("Loading caption model...") + recognizer = OfflineRecognizer(OfflineRecognizerConfig.builder() + .setFeatureConfig(FeatureConfig.builder() + .setSampleRate(SAMPLE_RATE) + .setFeatureDim(FEATURE_DIM) + .build()) + .setModelConfig(OfflineModelConfig.builder() + .setMoonshine(OfflineMoonshineModelConfig.builder() + .setEncoder(File(modelDir, "encoder_model.ort").absolutePath) + .setMergedDecoder(File(modelDir, "decoder_model_merged.ort").absolutePath) + .build()) + .setTokens(File(modelDir, "tokens.txt").absolutePath) + .setNumThreads(1) + .build()) + .build()) + } else { + recognizer = null + } + val embedModel = speakerModelPath + if (embedModel != null && File(embedModel).exists()) { + speakerId = FaceclawSpeakerId(embedModel) + speakerId!!.ensureLoaded() + } else { + speakerId = null + } + emitStatus(if (recognizer != null) "Captions listening..." else "Captions listening (no ASR model)...") + } + + private fun releaseModels() { + if (recognizer != null) { + recognizer!!.release() + recognizer = null + } + if (speakerId != null) { + speakerId!!.close() + speakerId = null + } + } + + private fun takeChunk(): ByteArray? { + synchronized(queueLock) { + while (started && queue.isEmpty()) { + try { + (queueLock as java.lang.Object).wait(250) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + return null + } + } + return queue.pollFirst() + } + } + + private fun resetSegmentation() { + totalSamples = 0 + noiseFloor = 0.0 + inUtterance = false + utteranceLength = 0 + preRollLength = 0 + silenceRunSamples = 0 + utterancePeakRms = 0.0 + } + + private fun processChunk(chunk: ByteArray) { + val count = chunk.size / 2 + val pcm = ShortArray(count) + var sumSquares = 0.0 + for (i in 0 until count) { + val s = ((chunk[i * 2].toInt() and 0xff) or (chunk[i * 2 + 1].toInt() shl 8)).toShort() + pcm[i] = s + sumSquares += s.toDouble() * s + } + val rms = Math.sqrt(sumSquares / Math.max(1, count)) + totalSamples += count.toLong() + + if (!inUtterance) { + // Track the noise floor only while idle so speech doesn't raise it. + noiseFloor = if (noiseFloor == 0.0) rms else noiseFloor * (1 - NOISE_EMA_ALPHA) + rms * NOISE_EMA_ALPHA + val threshold = Math.max(noiseFloor, MIN_RMS) + if (rms >= threshold * ONSET_FACTOR) { + inUtterance = true + utteranceLength = 0 + silenceRunSamples = 0 + utterancePeakRms = rms + appendUtterance(preRoll, preRollLength) + utteranceStartSample = Math.max(0L, totalSamples - count - preRollLength) + appendUtterance(pcm, count) + emitSpeechStart(utteranceStartSample * 1000 / SAMPLE_RATE) + } else { + appendPreRoll(pcm, count) + } + return + } + + appendUtterance(pcm, count) + utterancePeakRms = Math.max(utterancePeakRms, rms) + val threshold = Math.max(noiseFloor, MIN_RMS) + if (rms < threshold * RELEASE_FACTOR) { + silenceRunSamples += count.toLong() + } else { + silenceRunSamples = 0 + } + val utteranceMs = utteranceLength.toLong() * 1000 / SAMPLE_RATE + val silenceEnded = silenceRunSamples * 1000L / SAMPLE_RATE >= silenceMs + if (silenceEnded || utteranceMs >= MAX_UTTERANCE_MS) { + finalizeUtterance() + inUtterance = false + preRollLength = 0 + } + } + + private fun appendPreRoll(pcm: ShortArray, count: Int) { + // Keep the last PRE_ROLL_MS of idle audio so onset consonants survive. + if (count >= preRoll.size) { + System.arraycopy(pcm, count - preRoll.size, preRoll, 0, preRoll.size) + preRollLength = preRoll.size + return + } + val keep = Math.min(preRollLength, preRoll.size - count) + System.arraycopy(preRoll, preRollLength - keep, preRoll, 0, keep) + System.arraycopy(pcm, 0, preRoll, keep, count) + preRollLength = keep + count + } + + private fun appendUtterance(pcm: ShortArray, count: Int) { + val room = utterance.size - utteranceLength + val copied = Math.min(room, count) + if (copied > 0) { + System.arraycopy(pcm, 0, utterance, utteranceLength, copied) + utteranceLength += copied + } + } + + private fun finalizeUtterance() { + val length = utteranceLength + val startMs = utteranceStartSample * 1000 / SAMPLE_RATE + val endMs = (utteranceStartSample + length) * 1000 / SAMPLE_RATE + if (endMs - startMs < MIN_UTTERANCE_MS) { + return + } + val text = recognizeUtterance(length) + val embedding = embedUtterance(length) + emitUtterance(text, embedding, startMs, endMs, utterancePeakRms) + } + + private fun recognizeUtterance(length: Int): String { + if (recognizer == null || length <= 0) { + return "" + } + val joined = StringBuilder() + var offset = 0 + while (offset < length) { + val remaining = length - offset + var segment = Math.min(remaining, DECODE_SEGMENT_MAX_SAMPLES) + if (remaining > DECODE_SEGMENT_MAX_SAMPLES) { + segment = findQuietCut(offset, segment) + } + val part = recognizeRange(offset, segment) + if (part.length > 0) { + if (joined.length > 0 && ".,!?;:%)]}".indexOf(part[0]) < 0) { + joined.append(' ') + } + joined.append(part) + } + offset += segment + } + return joined.toString().trim() + } + + /** + * End a decode segment at the center of the quietest window near its end + * so the cut lands between words (same approach as the PTT controller). + */ + private fun findQuietCut(offset: Int, segment: Int): Int { + val searchStart = Math.max(0, segment - CUT_SEARCH_SAMPLES) + val win = CUT_WINDOW_SAMPLES + if (segment - searchStart <= win) { + return segment + } + var sum = 0.0 + for (i in searchStart until searchStart + win) { + val s = utterance[offset + i].toDouble() + sum += s * s + } + var best = sum + var bestStart = searchStart + var start = searchStart + 1 + while (start + win <= segment) { + val dropped = utterance[offset + start - 1].toDouble() + val added = utterance[offset + start + win - 1].toDouble() + sum += added * added - dropped * dropped + if (sum < best) { + best = sum + bestStart = start + } + start++ + } + return bestStart + win / 2 + } + + private fun recognizeRange(offset: Int, count: Int): String { + val samples = FloatArray(count) + var peak = 0f + for (i in 0 until count) { + val v = utterance[offset + i] / 32768.0f + samples[i] = v + val a = Math.abs(v) + if (a > peak) { + peak = a + } + } + if (peak > 0f) { + val gain = Math.min(NORMALIZE_TARGET_PEAK / peak, NORMALIZE_MAX_GAIN) + if (gain > 1f) { + for (i in 0 until count) { + samples[i] *= gain + } + } + } + val recognizer = this.recognizer!! + val stream: OfflineStream = recognizer.createStream() + try { + stream.acceptWaveform(samples, SAMPLE_RATE) + recognizer.decode(stream) + val result: OfflineRecognizerResult? = recognizer.getResult(stream) + val raw: String? = if (result == null) "" else result.text + return raw?.trim() ?: "" + } finally { + stream.release() + } + } + + private fun embedUtterance(length: Int): FloatArray? { + val currentSpeakerId = speakerId + if (currentSpeakerId == null || length <= 0) { + return null + } + val count = Math.min(length, EMBED_MAX_SAMPLES) + val le = ByteArray(count * 2) + for (i in 0 until count) { + val s = utterance[i].toInt() + le[i * 2] = (s and 0xff).toByte() + le[i * 2 + 1] = ((s shr 8) and 0xff).toByte() + } + return currentSpeakerId.embed(le, SAMPLE_RATE) + } + + private fun emitUtterance(text: String?, embedding: FloatArray?, startMs: Long, endMs: Long, peakRms: Double) { + val currentListener = listener + if (currentListener == null) { + return + } + val embeddingCopy = if (embedding == null) null else Arrays.copyOf(embedding, embedding.size) + mainHandler.post { currentListener.onUtterance(text, embeddingCopy, startMs, endMs, peakRms) } + } + + private fun emitSpeechStart(startMs: Long) { + val currentListener = listener + if (currentListener == null) { + return + } + mainHandler.post { currentListener.onSpeechStart(startMs) } + } + + private fun emitStatus(status: String?) { + val currentListener = listener + if (currentListener == null) { + return + } + mainHandler.post { currentListener.onStatus(status) } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.java deleted file mode 100644 index 38f723fe..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.java +++ /dev/null @@ -1,778 +0,0 @@ -package com.faceclaw.app; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.util.Base64; -import android.util.Log; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.File; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.List; - -/** - * Persistent store for caption sessions, transcript segments, and speaker - * voice profiles, backing the Microphones app and its phone-side review UI. - * All complex values cross the JS bridge as JSON strings; voice-print - * embeddings are float32 LE blobs, exposed as base64. - */ -public class FaceclawConversationStore extends SQLiteOpenHelper { - private static final String TAG = "FaceclawConvStore"; - private static final String DB_NAME = "faceclaw-conversations.db"; - private static final int DB_VERSION = 2; - - private static FaceclawConversationStore instance; - - public static synchronized FaceclawConversationStore getInstance(Context context) { - if (instance == null) { - instance = new FaceclawConversationStore(context.getApplicationContext()); - } - return instance; - } - - private FaceclawConversationStore(Context context) { - super(context, DB_NAME, null, DB_VERSION); - } - - @Override - public void onCreate(SQLiteDatabase db) { - db.execSQL("CREATE TABLE speakers (" - + "id INTEGER PRIMARY KEY AUTOINCREMENT," - + "name TEXT NOT NULL," - + "color TEXT NOT NULL DEFAULT '#4FC3F7'," - + "is_wearer INTEGER NOT NULL DEFAULT 0," - + "embedding BLOB," - + "embedding_count INTEGER NOT NULL DEFAULT 0," - + "created_at INTEGER NOT NULL," - + "last_heard_at INTEGER," - + "tag TEXT," - + "last_recap TEXT," - + "action_items TEXT," - + "facts TEXT," - + "insights_updated_at INTEGER," - + "insights_session_id INTEGER)"); - db.execSQL("CREATE TABLE sessions (" - + "id INTEGER PRIMARY KEY AUTOINCREMENT," - + "started_at INTEGER NOT NULL," - + "ended_at INTEGER," - + "title TEXT," - + "audio_path TEXT," - + "audio_codec TEXT," - + "avg_sentiment REAL," - + "segment_count INTEGER NOT NULL DEFAULT 0)"); - db.execSQL("CREATE TABLE segments (" - + "id INTEGER PRIMARY KEY AUTOINCREMENT," - + "session_id INTEGER NOT NULL," - + "speaker_id INTEGER," - + "started_at INTEGER NOT NULL," - + "ended_at INTEGER NOT NULL," - + "audio_offset_ms INTEGER," - + "text TEXT NOT NULL," - + "lang TEXT," - + "translation TEXT," - + "translation_lang TEXT," - + "sentiment REAL," - + "emotion TEXT," - + "search_meta TEXT," - + "angle INTEGER," - + "embedding BLOB)"); - db.execSQL("CREATE INDEX idx_segments_session ON segments(session_id)"); - db.execSQL("CREATE INDEX idx_segments_speaker ON segments(speaker_id)"); - db.execSQL("CREATE INDEX idx_segments_time ON segments(started_at)"); - db.execSQL("CREATE INDEX idx_sessions_time ON sessions(started_at)"); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if (oldVersion < 2) { - // v2: per-speaker conversation insights (recap of the most recent - // conversation, its action items, and accumulated inferred facts). - db.execSQL("ALTER TABLE speakers ADD COLUMN last_recap TEXT"); - db.execSQL("ALTER TABLE speakers ADD COLUMN action_items TEXT"); - db.execSQL("ALTER TABLE speakers ADD COLUMN facts TEXT"); - db.execSQL("ALTER TABLE speakers ADD COLUMN insights_updated_at INTEGER"); - db.execSQL("ALTER TABLE speakers ADD COLUMN insights_session_id INTEGER"); - } - } - - // ---- sessions ---- - - public long startSession(long startedAtMs, String title) { - ContentValues values = new ContentValues(); - values.put("started_at", startedAtMs); - values.put("title", title == null || title.isEmpty() ? null : title); - return getWritableDatabase().insert("sessions", null, values); - } - - public void endSession(long sessionId, long endedAtMs, String audioPath, String audioCodec, double avgSentiment) { - ContentValues values = new ContentValues(); - values.put("ended_at", endedAtMs); - if (audioPath != null && !audioPath.isEmpty()) { - values.put("audio_path", audioPath); - values.put("audio_codec", audioCodec); - } - values.put("avg_sentiment", avgSentiment); - getWritableDatabase().update("sessions", values, "id=?", new String[]{String.valueOf(sessionId)}); - } - - public void setSessionAudio(long sessionId, String audioPath, String audioCodec) { - ContentValues values = new ContentValues(); - values.put("audio_path", audioPath); - values.put("audio_codec", audioCodec); - getWritableDatabase().update("sessions", values, "id=?", new String[]{String.valueOf(sessionId)}); - } - - public String getSessionAudioPath(long sessionId) { - try (Cursor c = getReadableDatabase().rawQuery( - "SELECT audio_path FROM sessions WHERE id=?", new String[]{String.valueOf(sessionId)})) { - if (c.moveToFirst()) { - return c.isNull(0) ? "" : c.getString(0); - } - } - return ""; - } - - /** - * Sessions, newest first, as JSON. filterJson supports: sinceMs, untilMs, - * speakerId, emotion (matches any segment emotion in the session), query - * (LIKE over title and segment text/search metadata), limit. - */ - public String querySessions(String filterJson) { - try { - JSONObject filter = filterJson == null || filterJson.isEmpty() - ? new JSONObject() : new JSONObject(filterJson); - StringBuilder sql = new StringBuilder( - "SELECT DISTINCT s.id, s.started_at, s.ended_at, s.title, s.audio_path, s.audio_codec," - + " s.avg_sentiment, s.segment_count FROM sessions s"); - List args = new ArrayList<>(); - List where = new ArrayList<>(); - boolean joinSegments = filter.has("speakerId") || filter.has("emotion") || filter.has("query"); - if (joinSegments) { - sql.append(" LEFT JOIN segments g ON g.session_id = s.id"); - } - if (filter.has("sinceMs")) { - where.add("s.started_at >= ?"); - args.add(String.valueOf(filter.getLong("sinceMs"))); - } - if (filter.has("untilMs")) { - where.add("s.started_at <= ?"); - args.add(String.valueOf(filter.getLong("untilMs"))); - } - if (filter.has("speakerId")) { - where.add("g.speaker_id = ?"); - args.add(String.valueOf(filter.getLong("speakerId"))); - } - if (filter.has("emotion")) { - where.add("g.emotion = ?"); - args.add(filter.getString("emotion")); - } - if (filter.has("query")) { - String like = "%" + filter.getString("query") + "%"; - where.add("(s.title LIKE ? OR g.text LIKE ? OR g.search_meta LIKE ?)"); - args.add(like); - args.add(like); - args.add(like); - } - if (!where.isEmpty()) { - sql.append(" WHERE ").append(String.join(" AND ", where)); - } - sql.append(" ORDER BY s.started_at DESC"); - int limit = filter.optInt("limit", 200); - sql.append(" LIMIT ").append(Math.max(1, Math.min(limit, 1000))); - - JSONArray out = new JSONArray(); - try (Cursor c = getReadableDatabase().rawQuery(sql.toString(), args.toArray(new String[0]))) { - while (c.moveToNext()) { - JSONObject row = new JSONObject(); - long id = c.getLong(0); - row.put("id", id); - row.put("startedAt", c.getLong(1)); - row.put("endedAt", c.isNull(2) ? JSONObject.NULL : c.getLong(2)); - row.put("title", c.isNull(3) ? "" : c.getString(3)); - row.put("audioPath", c.isNull(4) ? "" : c.getString(4)); - row.put("audioCodec", c.isNull(5) ? "" : c.getString(5)); - row.put("avgSentiment", c.isNull(6) ? 0 : c.getDouble(6)); - row.put("segmentCount", c.getLong(7)); - row.put("speakers", sessionSpeakersJson(id)); - out.put(row); - } - } - return out.toString(); - } catch (JSONException e) { - Log.w(TAG, "querySessions failed", e); - return "[]"; - } - } - - private JSONArray sessionSpeakersJson(long sessionId) throws JSONException { - JSONArray out = new JSONArray(); - try (Cursor c = getReadableDatabase().rawQuery( - "SELECT DISTINCT p.id, p.name, p.color FROM segments g" - + " JOIN speakers p ON p.id = g.speaker_id WHERE g.session_id=?", - new String[]{String.valueOf(sessionId)})) { - while (c.moveToNext()) { - JSONObject row = new JSONObject(); - row.put("id", c.getLong(0)); - row.put("name", c.getString(1)); - row.put("color", c.getString(2)); - out.put(row); - } - } - return out; - } - - // ---- segments ---- - - /** - * Insert one transcript segment. json fields: sessionId, speakerId?, - * startedAt, endedAt, audioOffsetMs?, text, lang?, translation?, - * translationLang?, sentiment?, emotion?, searchMeta?, angle?, - * embeddingBase64?. Returns the new row id, or -1. - */ - public long insertSegment(String json) { - try { - JSONObject s = new JSONObject(json); - ContentValues values = new ContentValues(); - long sessionId = s.getLong("sessionId"); - values.put("session_id", sessionId); - if (s.has("speakerId")) { - values.put("speaker_id", s.getLong("speakerId")); - } - values.put("started_at", s.getLong("startedAt")); - values.put("ended_at", s.getLong("endedAt")); - if (s.has("audioOffsetMs")) { - values.put("audio_offset_ms", s.getLong("audioOffsetMs")); - } - values.put("text", s.getString("text")); - putOptString(values, s, "lang", "lang"); - putOptString(values, s, "translation", "translation"); - putOptString(values, s, "translationLang", "translation_lang"); - if (s.has("sentiment")) { - values.put("sentiment", s.getDouble("sentiment")); - } - putOptString(values, s, "emotion", "emotion"); - putOptString(values, s, "searchMeta", "search_meta"); - if (s.has("angle")) { - values.put("angle", s.getInt("angle")); - } - if (s.has("embeddingBase64")) { - values.put("embedding", Base64.decode(s.getString("embeddingBase64"), Base64.NO_WRAP)); - } - SQLiteDatabase db = getWritableDatabase(); - long id = db.insert("segments", null, values); - db.execSQL("UPDATE sessions SET segment_count = segment_count + 1 WHERE id=?", - new Object[]{sessionId}); - return id; - } catch (Throwable t) { - Log.w(TAG, "insertSegment failed", t); - return -1; - } - } - - private static void putOptString(ContentValues values, JSONObject s, String jsonKey, String column) - throws JSONException { - if (s.has(jsonKey) && !s.isNull(jsonKey)) { - values.put(column, s.getString(jsonKey)); - } - } - - /** Update mutable fields of a segment (same keys as insertSegment). */ - public void updateSegment(long segmentId, String json) { - try { - JSONObject s = new JSONObject(json); - ContentValues values = new ContentValues(); - if (s.has("speakerId")) { - if (s.isNull("speakerId")) { - values.putNull("speaker_id"); - } else { - values.put("speaker_id", s.getLong("speakerId")); - } - } - if (s.has("text")) { - values.put("text", s.getString("text")); - } - putOptString(values, s, "lang", "lang"); - putOptString(values, s, "translation", "translation"); - putOptString(values, s, "translationLang", "translation_lang"); - if (s.has("sentiment")) { - values.put("sentiment", s.getDouble("sentiment")); - } - putOptString(values, s, "emotion", "emotion"); - putOptString(values, s, "searchMeta", "search_meta"); - if (values.size() > 0) { - getWritableDatabase().update("segments", values, "id=?", - new String[]{String.valueOf(segmentId)}); - } - } catch (Throwable t) { - Log.w(TAG, "updateSegment failed", t); - } - } - - public String querySegments(long sessionId) { - JSONArray out = new JSONArray(); - try (Cursor c = getReadableDatabase().rawQuery( - "SELECT id, speaker_id, started_at, ended_at, audio_offset_ms, text, lang," - + " translation, translation_lang, sentiment, emotion, angle" - + " FROM segments WHERE session_id=? ORDER BY started_at ASC", - new String[]{String.valueOf(sessionId)})) { - while (c.moveToNext()) { - out.put(segmentRowJson(c)); - } - } catch (JSONException e) { - Log.w(TAG, "querySegments failed", e); - } - return out.toString(); - } - - private JSONObject segmentRowJson(Cursor c) throws JSONException { - JSONObject row = new JSONObject(); - row.put("id", c.getLong(0)); - row.put("speakerId", c.isNull(1) ? JSONObject.NULL : c.getLong(1)); - row.put("startedAt", c.getLong(2)); - row.put("endedAt", c.getLong(3)); - row.put("audioOffsetMs", c.isNull(4) ? JSONObject.NULL : c.getLong(4)); - row.put("text", c.getString(5)); - row.put("lang", c.isNull(6) ? "" : c.getString(6)); - row.put("translation", c.isNull(7) ? "" : c.getString(7)); - row.put("translationLang", c.isNull(8) ? "" : c.getString(8)); - row.put("sentiment", c.isNull(9) ? 0 : c.getDouble(9)); - row.put("emotion", c.isNull(10) ? "" : c.getString(10)); - row.put("angle", c.isNull(11) ? JSONObject.NULL : c.getInt(11)); - return row; - } - - /** - * Search segments across sessions. filterJson: query?, emotion?, - * speakerId?, sinceMs?, untilMs?, limit?. Matches text, translation, and - * the sentiment search metadata. - */ - public String searchSegments(String filterJson) { - try { - JSONObject filter = filterJson == null || filterJson.isEmpty() - ? new JSONObject() : new JSONObject(filterJson); - StringBuilder sql = new StringBuilder( - "SELECT id, speaker_id, started_at, ended_at, audio_offset_ms, text, lang," - + " translation, translation_lang, sentiment, emotion, angle, session_id" - + " FROM segments"); - List args = new ArrayList<>(); - List where = new ArrayList<>(); - if (filter.has("query") && !filter.getString("query").isEmpty()) { - String like = "%" + filter.getString("query") + "%"; - where.add("(text LIKE ? OR translation LIKE ? OR search_meta LIKE ?)"); - args.add(like); - args.add(like); - args.add(like); - } - if (filter.has("emotion")) { - where.add("emotion = ?"); - args.add(filter.getString("emotion")); - } - if (filter.has("speakerId")) { - where.add("speaker_id = ?"); - args.add(String.valueOf(filter.getLong("speakerId"))); - } - if (filter.has("sinceMs")) { - where.add("started_at >= ?"); - args.add(String.valueOf(filter.getLong("sinceMs"))); - } - if (filter.has("untilMs")) { - where.add("started_at <= ?"); - args.add(String.valueOf(filter.getLong("untilMs"))); - } - if (!where.isEmpty()) { - sql.append(" WHERE ").append(String.join(" AND ", where)); - } - sql.append(" ORDER BY started_at DESC LIMIT ") - .append(Math.max(1, Math.min(filter.optInt("limit", 300), 1000))); - JSONArray out = new JSONArray(); - try (Cursor c = getReadableDatabase().rawQuery(sql.toString(), args.toArray(new String[0]))) { - while (c.moveToNext()) { - JSONObject row = segmentRowJson(c); - row.put("sessionId", c.getLong(12)); - out.put(row); - } - } - return out.toString(); - } catch (JSONException e) { - Log.w(TAG, "searchSegments failed", e); - return "[]"; - } - } - - /** Per-segment voice-print embeddings of a session (for re-diarization). */ - public String querySegmentEmbeddings(long sessionId) { - JSONArray out = new JSONArray(); - try (Cursor c = getReadableDatabase().rawQuery( - "SELECT id, embedding FROM segments WHERE session_id=? AND embedding IS NOT NULL", - new String[]{String.valueOf(sessionId)})) { - while (c.moveToNext()) { - JSONObject row = new JSONObject(); - row.put("id", c.getLong(0)); - row.put("embeddingBase64", Base64.encodeToString(c.getBlob(1), Base64.NO_WRAP)); - out.put(row); - } - } catch (JSONException e) { - Log.w(TAG, "querySegmentEmbeddings failed", e); - } - return out.toString(); - } - - // ---- speakers ---- - - public long createSpeaker(String name, String color, boolean isWearer, String embeddingBase64) { - ContentValues values = new ContentValues(); - values.put("name", name); - values.put("color", color == null || color.isEmpty() ? "#4FC3F7" : color); - values.put("is_wearer", isWearer ? 1 : 0); - values.put("created_at", System.currentTimeMillis()); - values.put("last_heard_at", System.currentTimeMillis()); - if (embeddingBase64 != null && !embeddingBase64.isEmpty()) { - values.put("embedding", Base64.decode(embeddingBase64, Base64.NO_WRAP)); - values.put("embedding_count", 1); - } - return getWritableDatabase().insert("speakers", null, values); - } - - public String querySpeakers() { - JSONArray out = new JSONArray(); - try (Cursor c = getReadableDatabase().rawQuery( - "SELECT p.id, p.name, p.color, p.is_wearer, p.embedding, p.embedding_count," - + " p.last_heard_at, p.tag," - + " p.last_recap, p.action_items, p.facts, p.insights_updated_at, p.insights_session_id," - + " (SELECT COUNT(*) FROM segments g WHERE g.speaker_id = p.id) AS segments" - + " FROM speakers p ORDER BY p.last_heard_at DESC", null)) { - while (c.moveToNext()) { - JSONObject row = new JSONObject(); - row.put("id", c.getLong(0)); - row.put("name", c.getString(1)); - row.put("color", c.getString(2)); - row.put("isWearer", c.getInt(3) != 0); - byte[] blob = c.isNull(4) ? null : c.getBlob(4); - row.put("embeddingBase64", blob == null ? "" : Base64.encodeToString(blob, Base64.NO_WRAP)); - row.put("embeddingCount", c.getInt(5)); - row.put("lastHeardAt", c.isNull(6) ? 0 : c.getLong(6)); - row.put("tag", c.isNull(7) ? "" : c.getString(7)); - row.put("lastRecap", c.isNull(8) ? "" : c.getString(8)); - row.put("actionItemsJson", c.isNull(9) ? "" : c.getString(9)); - row.put("factsJson", c.isNull(10) ? "" : c.getString(10)); - row.put("insightsUpdatedAt", c.isNull(11) ? 0 : c.getLong(11)); - row.put("insightsSessionId", c.isNull(12) ? 0 : c.getLong(12)); - row.put("segmentCount", c.getLong(13)); - out.put(row); - } - } catch (JSONException e) { - Log.w(TAG, "querySpeakers failed", e); - } - return out.toString(); - } - - public void renameSpeaker(long speakerId, String name) { - ContentValues values = new ContentValues(); - values.put("name", name); - getWritableDatabase().update("speakers", values, "id=?", new String[]{String.valueOf(speakerId)}); - } - - public void setSpeakerColor(long speakerId, String color) { - ContentValues values = new ContentValues(); - values.put("color", color); - getWritableDatabase().update("speakers", values, "id=?", new String[]{String.valueOf(speakerId)}); - } - - public void setSpeakerTag(long speakerId, String tag) { - ContentValues values = new ContentValues(); - values.put("tag", tag); - getWritableDatabase().update("speakers", values, "id=?", new String[]{String.valueOf(speakerId)}); - } - - /** - * Store LLM-derived conversation insights for a speaker: a recap of their - * most recent conversation, its open action items (JSON string array), and - * the accumulated inferred facts about them (JSON string array). - */ - public void setSpeakerInsights(long speakerId, String recap, String actionItemsJson, - String factsJson, long sessionId) { - ContentValues values = new ContentValues(); - values.put("last_recap", recap == null ? "" : recap); - values.put("action_items", actionItemsJson == null ? "" : actionItemsJson); - values.put("facts", factsJson == null ? "" : factsJson); - values.put("insights_updated_at", System.currentTimeMillis()); - values.put("insights_session_id", sessionId); - getWritableDatabase().update("speakers", values, "id=?", new String[]{String.valueOf(speakerId)}); - } - - public void setSpeakerWearer(long speakerId, boolean isWearer) { - SQLiteDatabase db = getWritableDatabase(); - if (isWearer) { - // Exactly one wearer profile at a time. - db.execSQL("UPDATE speakers SET is_wearer = 0"); - } - ContentValues values = new ContentValues(); - values.put("is_wearer", isWearer ? 1 : 0); - db.update("speakers", values, "id=?", new String[]{String.valueOf(speakerId)}); - } - - /** - * Running-mean centroid update for a speaker's voice-print, capped so a - * long session cannot drown the enrolled voice. - */ - public void updateSpeakerEmbedding(long speakerId, String embeddingBase64, int maxCount) { - try { - byte[] incoming = Base64.decode(embeddingBase64, Base64.NO_WRAP); - float[] update = blobToFloats(incoming); - if (update == null) { - return; - } - float[] current = null; - int count = 0; - try (Cursor c = getReadableDatabase().rawQuery( - "SELECT embedding, embedding_count FROM speakers WHERE id=?", - new String[]{String.valueOf(speakerId)})) { - if (c.moveToFirst()) { - current = c.isNull(0) ? null : blobToFloats(c.getBlob(0)); - count = c.getInt(1); - } - } - float[] merged; - if (current == null || current.length != update.length) { - merged = update; - count = 1; - } else { - int effective = Math.min(count, Math.max(1, maxCount)); - merged = new float[current.length]; - for (int i = 0; i < merged.length; i++) { - merged[i] = (current[i] * effective + update[i]) / (effective + 1); - } - l2NormalizeInPlace(merged); - count = count + 1; - } - ContentValues values = new ContentValues(); - values.put("embedding", floatsToBlob(merged)); - values.put("embedding_count", count); - values.put("last_heard_at", System.currentTimeMillis()); - getWritableDatabase().update("speakers", values, "id=?", - new String[]{String.valueOf(speakerId)}); - } catch (Throwable t) { - Log.w(TAG, "updateSpeakerEmbedding failed", t); - } - } - - /** Move every segment from one speaker onto another and drop the source. */ - public void mergeSpeakers(long fromId, long intoId) { - if (fromId == intoId) { - return; - } - SQLiteDatabase db = getWritableDatabase(); - db.beginTransaction(); - try { - db.execSQL("UPDATE segments SET speaker_id=? WHERE speaker_id=?", - new Object[]{intoId, fromId}); - // Blend the two centroids weighted by their sample counts. - float[] from = null; - float[] into = null; - int fromCount = 0; - int intoCount = 0; - boolean fromWearer = false; - try (Cursor c = db.rawQuery( - "SELECT id, embedding, embedding_count, is_wearer FROM speakers WHERE id IN (?,?)", - new String[]{String.valueOf(fromId), String.valueOf(intoId)})) { - while (c.moveToNext()) { - long id = c.getLong(0); - float[] embedding = c.isNull(1) ? null : blobToFloats(c.getBlob(1)); - int count = c.getInt(2); - if (id == fromId) { - from = embedding; - fromCount = count; - fromWearer = c.getInt(3) != 0; - } else { - into = embedding; - intoCount = count; - } - } - } - float[] merged = into; - if (from != null && into != null && from.length == into.length) { - merged = new float[into.length]; - int total = Math.max(1, fromCount + intoCount); - for (int i = 0; i < merged.length; i++) { - merged[i] = (into[i] * intoCount + from[i] * fromCount) / total; - } - l2NormalizeInPlace(merged); - } else if (into == null) { - merged = from; - } - ContentValues values = new ContentValues(); - if (merged != null) { - values.put("embedding", floatsToBlob(merged)); - values.put("embedding_count", fromCount + intoCount); - } - if (fromWearer) { - values.put("is_wearer", 1); - } - values.put("last_heard_at", System.currentTimeMillis()); - // Keep the target's conversation insights; adopt the source's only - // where the target has none (e.g. merging a rich profile into a - // freshly auto-created one). - try (Cursor c = db.rawQuery( - "SELECT last_recap, action_items, facts, insights_updated_at, insights_session_id" - + " FROM speakers WHERE id IN (?,?) ORDER BY CASE id WHEN ? THEN 0 ELSE 1 END", - new String[]{String.valueOf(fromId), String.valueOf(intoId), String.valueOf(intoId)})) { - boolean targetHasInsights = false; - while (c.moveToNext()) { - boolean hasInsights = !c.isNull(0) && !c.getString(0).isEmpty(); - if (c.getPosition() == 0) { - targetHasInsights = hasInsights; - } else if (!targetHasInsights && hasInsights) { - values.put("last_recap", c.getString(0)); - values.put("action_items", c.isNull(1) ? "" : c.getString(1)); - values.put("facts", c.isNull(2) ? "" : c.getString(2)); - values.put("insights_updated_at", c.isNull(3) ? 0 : c.getLong(3)); - values.put("insights_session_id", c.isNull(4) ? 0 : c.getLong(4)); - } - } - } - db.update("speakers", values, "id=?", new String[]{String.valueOf(intoId)}); - db.delete("speakers", "id=?", new String[]{String.valueOf(fromId)}); - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } - - public void reassignSegmentSpeaker(long segmentId, long speakerId) { - ContentValues values = new ContentValues(); - values.put("speaker_id", speakerId); - getWritableDatabase().update("segments", values, "id=?", new String[]{String.valueOf(segmentId)}); - } - - /** Reassign every segment of a speaker within one session (split support). */ - public void reassignSessionSpeaker(long sessionId, long fromSpeakerId, long toSpeakerId) { - getWritableDatabase().execSQL( - "UPDATE segments SET speaker_id=? WHERE session_id=? AND speaker_id=?", - new Object[]{toSpeakerId, sessionId, fromSpeakerId}); - } - - public void deleteSpeaker(long speakerId) { - SQLiteDatabase db = getWritableDatabase(); - db.execSQL("UPDATE segments SET speaker_id=NULL WHERE speaker_id=?", new Object[]{speakerId}); - db.delete("speakers", "id=?", new String[]{String.valueOf(speakerId)}); - } - - // ---- retention ---- - - /** - * Delete caption sessions older than the cutoff (0 disables), and strip - * recordings older than their own cutoff while keeping the transcript. - * Returns a JSON summary of what was removed. - */ - public String applyRetention(long captionCutoffMs, long recordingCutoffMs) { - SQLiteDatabase db = getWritableDatabase(); - int sessionsDeleted = 0; - int recordingsDeleted = 0; - if (recordingCutoffMs > 0) { - List paths = new ArrayList<>(); - try (Cursor c = db.rawQuery( - "SELECT id, audio_path FROM sessions WHERE audio_path IS NOT NULL AND started_at < ?", - new String[]{String.valueOf(recordingCutoffMs)})) { - while (c.moveToNext()) { - if (!c.isNull(1)) { - paths.add(c.getString(1)); - } - } - } - for (String path : paths) { - if (new File(path).delete()) { - recordingsDeleted++; - } - } - db.execSQL("UPDATE sessions SET audio_path=NULL, audio_codec=NULL WHERE started_at < ?", - new Object[]{recordingCutoffMs}); - } - if (captionCutoffMs > 0) { - List paths = new ArrayList<>(); - try (Cursor c = db.rawQuery( - "SELECT audio_path FROM sessions WHERE audio_path IS NOT NULL AND started_at < ?", - new String[]{String.valueOf(captionCutoffMs)})) { - while (c.moveToNext()) { - paths.add(c.getString(0)); - } - } - for (String path : paths) { - if (path != null && new File(path).delete()) { - recordingsDeleted++; - } - } - db.execSQL("DELETE FROM segments WHERE session_id IN (SELECT id FROM sessions WHERE started_at < ?)", - new Object[]{captionCutoffMs}); - Cursor count = db.rawQuery("SELECT changes()", null); - count.close(); - db.execSQL("DELETE FROM sessions WHERE started_at < ?", new Object[]{captionCutoffMs}); - try (Cursor c = db.rawQuery("SELECT changes()", null)) { - if (c.moveToFirst()) { - sessionsDeleted = c.getInt(0); - } - } - } - try { - JSONObject summary = new JSONObject(); - summary.put("sessionsDeleted", sessionsDeleted); - summary.put("recordingsDeleted", recordingsDeleted); - return summary.toString(); - } catch (JSONException e) { - return "{}"; - } - } - - public void deleteSession(long sessionId) { - SQLiteDatabase db = getWritableDatabase(); - String path = getSessionAudioPath(sessionId); - if (!path.isEmpty()) { - new File(path).delete(); - } - db.delete("segments", "session_id=?", new String[]{String.valueOf(sessionId)}); - db.delete("sessions", "id=?", new String[]{String.valueOf(sessionId)}); - } - - // ---- blob helpers ---- - - private static float[] blobToFloats(byte[] blob) { - if (blob == null || blob.length < 4 || blob.length % 4 != 0) { - return null; - } - ByteBuffer buffer = ByteBuffer.wrap(blob).order(ByteOrder.LITTLE_ENDIAN); - float[] out = new float[blob.length / 4]; - for (int i = 0; i < out.length; i++) { - out[i] = buffer.getFloat(); - } - return out; - } - - private static byte[] floatsToBlob(float[] values) { - ByteBuffer buffer = ByteBuffer.allocate(values.length * 4).order(ByteOrder.LITTLE_ENDIAN); - for (float v : values) { - buffer.putFloat(v); - } - return buffer.array(); - } - - private static void l2NormalizeInPlace(float[] v) { - double sum = 0; - for (float x : v) { - sum += (double) x * x; - } - double norm = Math.sqrt(sum); - if (norm <= 0) { - return; - } - for (int i = 0; i < v.length; i++) { - v[i] = (float) (v[i] / norm); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt new file mode 100644 index 00000000..d9002ede --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt @@ -0,0 +1,790 @@ +package com.faceclaw.app + +import android.content.ContentValues +import android.content.Context +import android.database.Cursor +import android.database.sqlite.SQLiteDatabase +import android.database.sqlite.SQLiteOpenHelper +import android.util.Base64 +import android.util.Log + +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject + +import java.io.File +import java.nio.ByteBuffer +import java.nio.ByteOrder +import java.util.ArrayList + +/** + * Persistent store for caption sessions, transcript segments, and speaker + * voice profiles, backing the Microphones app and its phone-side review UI. + * All complex values cross the JS bridge as JSON strings; voice-print + * embeddings are float32 LE blobs, exposed as base64. + */ +class FaceclawConversationStore private constructor(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) { + companion object { + private const val TAG = "FaceclawConvStore" + private const val DB_NAME = "faceclaw-conversations.db" + private const val DB_VERSION = 2 + + private var instance: FaceclawConversationStore? = null + + @JvmStatic + @Synchronized + fun getInstance(context: Context): FaceclawConversationStore { + if (instance == null) { + instance = FaceclawConversationStore(context.applicationContext) + } + return instance!! + } + + @Throws(JSONException::class) + private fun putOptString(values: ContentValues, s: JSONObject, jsonKey: String, column: String) { + if (s.has(jsonKey) && !s.isNull(jsonKey)) { + values.put(column, s.getString(jsonKey)) + } + } + + // ---- blob helpers ---- + + private fun blobToFloats(blob: ByteArray?): FloatArray? { + if (blob == null || blob.size < 4 || blob.size % 4 != 0) { + return null + } + val buffer = ByteBuffer.wrap(blob).order(ByteOrder.LITTLE_ENDIAN) + val out = FloatArray(blob.size / 4) + for (i in out.indices) { + out[i] = buffer.getFloat() + } + return out + } + + private fun floatsToBlob(values: FloatArray): ByteArray { + val buffer = ByteBuffer.allocate(values.size * 4).order(ByteOrder.LITTLE_ENDIAN) + for (v in values) { + buffer.putFloat(v) + } + return buffer.array() + } + + private fun l2NormalizeInPlace(v: FloatArray) { + var sum = 0.0 + for (x in v) { + sum += x.toDouble() * x + } + val norm = Math.sqrt(sum) + if (norm <= 0) { + return + } + for (i in v.indices) { + v[i] = (v[i] / norm).toFloat() + } + } + } + + override fun onCreate(db: SQLiteDatabase) { + db.execSQL("CREATE TABLE speakers (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "name TEXT NOT NULL," + + "color TEXT NOT NULL DEFAULT '#4FC3F7'," + + "is_wearer INTEGER NOT NULL DEFAULT 0," + + "embedding BLOB," + + "embedding_count INTEGER NOT NULL DEFAULT 0," + + "created_at INTEGER NOT NULL," + + "last_heard_at INTEGER," + + "tag TEXT," + + "last_recap TEXT," + + "action_items TEXT," + + "facts TEXT," + + "insights_updated_at INTEGER," + + "insights_session_id INTEGER)") + db.execSQL("CREATE TABLE sessions (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "started_at INTEGER NOT NULL," + + "ended_at INTEGER," + + "title TEXT," + + "audio_path TEXT," + + "audio_codec TEXT," + + "avg_sentiment REAL," + + "segment_count INTEGER NOT NULL DEFAULT 0)") + db.execSQL("CREATE TABLE segments (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "session_id INTEGER NOT NULL," + + "speaker_id INTEGER," + + "started_at INTEGER NOT NULL," + + "ended_at INTEGER NOT NULL," + + "audio_offset_ms INTEGER," + + "text TEXT NOT NULL," + + "lang TEXT," + + "translation TEXT," + + "translation_lang TEXT," + + "sentiment REAL," + + "emotion TEXT," + + "search_meta TEXT," + + "angle INTEGER," + + "embedding BLOB)") + db.execSQL("CREATE INDEX idx_segments_session ON segments(session_id)") + db.execSQL("CREATE INDEX idx_segments_speaker ON segments(speaker_id)") + db.execSQL("CREATE INDEX idx_segments_time ON segments(started_at)") + db.execSQL("CREATE INDEX idx_sessions_time ON sessions(started_at)") + } + + override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { + if (oldVersion < 2) { + // v2: per-speaker conversation insights (recap of the most recent + // conversation, its action items, and accumulated inferred facts). + db.execSQL("ALTER TABLE speakers ADD COLUMN last_recap TEXT") + db.execSQL("ALTER TABLE speakers ADD COLUMN action_items TEXT") + db.execSQL("ALTER TABLE speakers ADD COLUMN facts TEXT") + db.execSQL("ALTER TABLE speakers ADD COLUMN insights_updated_at INTEGER") + db.execSQL("ALTER TABLE speakers ADD COLUMN insights_session_id INTEGER") + } + } + + // ---- sessions ---- + + fun startSession(startedAtMs: Long, title: String?): Long { + val values = ContentValues() + values.put("started_at", startedAtMs) + values.put("title", if (title == null || title.isEmpty()) null else title) + return writableDatabase.insert("sessions", null, values) + } + + fun endSession(sessionId: Long, endedAtMs: Long, audioPath: String?, audioCodec: String?, avgSentiment: Double) { + val values = ContentValues() + values.put("ended_at", endedAtMs) + if (audioPath != null && !audioPath.isEmpty()) { + values.put("audio_path", audioPath) + values.put("audio_codec", audioCodec) + } + values.put("avg_sentiment", avgSentiment) + writableDatabase.update("sessions", values, "id=?", arrayOf(sessionId.toString())) + } + + fun setSessionAudio(sessionId: Long, audioPath: String?, audioCodec: String?) { + val values = ContentValues() + values.put("audio_path", audioPath) + values.put("audio_codec", audioCodec) + writableDatabase.update("sessions", values, "id=?", arrayOf(sessionId.toString())) + } + + fun getSessionAudioPath(sessionId: Long): String { + readableDatabase.rawQuery( + "SELECT audio_path FROM sessions WHERE id=?", arrayOf(sessionId.toString())).use { c -> + if (c.moveToFirst()) { + return if (c.isNull(0)) "" else c.getString(0) + } + } + return "" + } + + /** + * Sessions, newest first, as JSON. filterJson supports: sinceMs, untilMs, + * speakerId, emotion (matches any segment emotion in the session), query + * (LIKE over title and segment text/search metadata), limit. + */ + fun querySessions(filterJson: String?): String { + try { + val filter = if (filterJson == null || filterJson.isEmpty()) + JSONObject() else JSONObject(filterJson) + val sql = StringBuilder( + "SELECT DISTINCT s.id, s.started_at, s.ended_at, s.title, s.audio_path, s.audio_codec," + + " s.avg_sentiment, s.segment_count FROM sessions s") + val args: MutableList = ArrayList() + val where: MutableList = ArrayList() + val joinSegments = filter.has("speakerId") || filter.has("emotion") || filter.has("query") + if (joinSegments) { + sql.append(" LEFT JOIN segments g ON g.session_id = s.id") + } + if (filter.has("sinceMs")) { + where.add("s.started_at >= ?") + args.add(filter.getLong("sinceMs").toString()) + } + if (filter.has("untilMs")) { + where.add("s.started_at <= ?") + args.add(filter.getLong("untilMs").toString()) + } + if (filter.has("speakerId")) { + where.add("g.speaker_id = ?") + args.add(filter.getLong("speakerId").toString()) + } + if (filter.has("emotion")) { + where.add("g.emotion = ?") + args.add(filter.getString("emotion")) + } + if (filter.has("query")) { + val like = "%" + filter.getString("query") + "%" + where.add("(s.title LIKE ? OR g.text LIKE ? OR g.search_meta LIKE ?)") + args.add(like) + args.add(like) + args.add(like) + } + if (!where.isEmpty()) { + sql.append(" WHERE ").append(where.joinToString(" AND ")) + } + sql.append(" ORDER BY s.started_at DESC") + val limit = filter.optInt("limit", 200) + sql.append(" LIMIT ").append(Math.max(1, Math.min(limit, 1000))) + + val out = JSONArray() + readableDatabase.rawQuery(sql.toString(), args.toTypedArray()).use { c -> + while (c.moveToNext()) { + val row = JSONObject() + val id = c.getLong(0) + row.put("id", id) + row.put("startedAt", c.getLong(1)) + row.put("endedAt", if (c.isNull(2)) JSONObject.NULL else c.getLong(2)) + row.put("title", if (c.isNull(3)) "" else c.getString(3)) + row.put("audioPath", if (c.isNull(4)) "" else c.getString(4)) + row.put("audioCodec", if (c.isNull(5)) "" else c.getString(5)) + row.put("avgSentiment", if (c.isNull(6)) 0.0 else c.getDouble(6)) + row.put("segmentCount", c.getLong(7)) + row.put("speakers", sessionSpeakersJson(id)) + out.put(row) + } + } + return out.toString() + } catch (e: JSONException) { + Log.w(TAG, "querySessions failed", e) + return "[]" + } + } + + @Throws(JSONException::class) + private fun sessionSpeakersJson(sessionId: Long): JSONArray { + val out = JSONArray() + readableDatabase.rawQuery( + "SELECT DISTINCT p.id, p.name, p.color FROM segments g" + + " JOIN speakers p ON p.id = g.speaker_id WHERE g.session_id=?", + arrayOf(sessionId.toString())).use { c -> + while (c.moveToNext()) { + val row = JSONObject() + row.put("id", c.getLong(0)) + row.put("name", c.getString(1)) + row.put("color", c.getString(2)) + out.put(row) + } + } + return out + } + + // ---- segments ---- + + /** + * Insert one transcript segment. json fields: sessionId, speakerId?, + * startedAt, endedAt, audioOffsetMs?, text, lang?, translation?, + * translationLang?, sentiment?, emotion?, searchMeta?, angle?, + * embeddingBase64?. Returns the new row id, or -1. + */ + fun insertSegment(json: String?): Long { + try { + val s = JSONObject(json) + val values = ContentValues() + val sessionId = s.getLong("sessionId") + values.put("session_id", sessionId) + if (s.has("speakerId")) { + values.put("speaker_id", s.getLong("speakerId")) + } + values.put("started_at", s.getLong("startedAt")) + values.put("ended_at", s.getLong("endedAt")) + if (s.has("audioOffsetMs")) { + values.put("audio_offset_ms", s.getLong("audioOffsetMs")) + } + values.put("text", s.getString("text")) + putOptString(values, s, "lang", "lang") + putOptString(values, s, "translation", "translation") + putOptString(values, s, "translationLang", "translation_lang") + if (s.has("sentiment")) { + values.put("sentiment", s.getDouble("sentiment")) + } + putOptString(values, s, "emotion", "emotion") + putOptString(values, s, "searchMeta", "search_meta") + if (s.has("angle")) { + values.put("angle", s.getInt("angle")) + } + if (s.has("embeddingBase64")) { + values.put("embedding", Base64.decode(s.getString("embeddingBase64"), Base64.NO_WRAP)) + } + val db = writableDatabase + val id = db.insert("segments", null, values) + db.execSQL("UPDATE sessions SET segment_count = segment_count + 1 WHERE id=?", + arrayOf(sessionId)) + return id + } catch (t: Throwable) { + Log.w(TAG, "insertSegment failed", t) + return -1 + } + } + + /** Update mutable fields of a segment (same keys as insertSegment). */ + fun updateSegment(segmentId: Long, json: String?) { + try { + val s = JSONObject(json) + val values = ContentValues() + if (s.has("speakerId")) { + if (s.isNull("speakerId")) { + values.putNull("speaker_id") + } else { + values.put("speaker_id", s.getLong("speakerId")) + } + } + if (s.has("text")) { + values.put("text", s.getString("text")) + } + putOptString(values, s, "lang", "lang") + putOptString(values, s, "translation", "translation") + putOptString(values, s, "translationLang", "translation_lang") + if (s.has("sentiment")) { + values.put("sentiment", s.getDouble("sentiment")) + } + putOptString(values, s, "emotion", "emotion") + putOptString(values, s, "searchMeta", "search_meta") + if (values.size() > 0) { + writableDatabase.update("segments", values, "id=?", + arrayOf(segmentId.toString())) + } + } catch (t: Throwable) { + Log.w(TAG, "updateSegment failed", t) + } + } + + fun querySegments(sessionId: Long): String { + val out = JSONArray() + try { + readableDatabase.rawQuery( + "SELECT id, speaker_id, started_at, ended_at, audio_offset_ms, text, lang," + + " translation, translation_lang, sentiment, emotion, angle" + + " FROM segments WHERE session_id=? ORDER BY started_at ASC", + arrayOf(sessionId.toString())).use { c -> + while (c.moveToNext()) { + out.put(segmentRowJson(c)) + } + } + } catch (e: JSONException) { + Log.w(TAG, "querySegments failed", e) + } + return out.toString() + } + + @Throws(JSONException::class) + private fun segmentRowJson(c: Cursor): JSONObject { + val row = JSONObject() + row.put("id", c.getLong(0)) + row.put("speakerId", if (c.isNull(1)) JSONObject.NULL else c.getLong(1)) + row.put("startedAt", c.getLong(2)) + row.put("endedAt", c.getLong(3)) + row.put("audioOffsetMs", if (c.isNull(4)) JSONObject.NULL else c.getLong(4)) + row.put("text", c.getString(5)) + row.put("lang", if (c.isNull(6)) "" else c.getString(6)) + row.put("translation", if (c.isNull(7)) "" else c.getString(7)) + row.put("translationLang", if (c.isNull(8)) "" else c.getString(8)) + row.put("sentiment", if (c.isNull(9)) 0.0 else c.getDouble(9)) + row.put("emotion", if (c.isNull(10)) "" else c.getString(10)) + row.put("angle", if (c.isNull(11)) JSONObject.NULL else c.getInt(11)) + return row + } + + /** + * Search segments across sessions. filterJson: query?, emotion?, + * speakerId?, sinceMs?, untilMs?, limit?. Matches text, translation, and + * the sentiment search metadata. + */ + fun searchSegments(filterJson: String?): String { + try { + val filter = if (filterJson == null || filterJson.isEmpty()) + JSONObject() else JSONObject(filterJson) + val sql = StringBuilder( + "SELECT id, speaker_id, started_at, ended_at, audio_offset_ms, text, lang," + + " translation, translation_lang, sentiment, emotion, angle, session_id" + + " FROM segments") + val args: MutableList = ArrayList() + val where: MutableList = ArrayList() + if (filter.has("query") && !filter.getString("query").isEmpty()) { + val like = "%" + filter.getString("query") + "%" + where.add("(text LIKE ? OR translation LIKE ? OR search_meta LIKE ?)") + args.add(like) + args.add(like) + args.add(like) + } + if (filter.has("emotion")) { + where.add("emotion = ?") + args.add(filter.getString("emotion")) + } + if (filter.has("speakerId")) { + where.add("speaker_id = ?") + args.add(filter.getLong("speakerId").toString()) + } + if (filter.has("sinceMs")) { + where.add("started_at >= ?") + args.add(filter.getLong("sinceMs").toString()) + } + if (filter.has("untilMs")) { + where.add("started_at <= ?") + args.add(filter.getLong("untilMs").toString()) + } + if (!where.isEmpty()) { + sql.append(" WHERE ").append(where.joinToString(" AND ")) + } + sql.append(" ORDER BY started_at DESC LIMIT ") + .append(Math.max(1, Math.min(filter.optInt("limit", 300), 1000))) + val out = JSONArray() + readableDatabase.rawQuery(sql.toString(), args.toTypedArray()).use { c -> + while (c.moveToNext()) { + val row = segmentRowJson(c) + row.put("sessionId", c.getLong(12)) + out.put(row) + } + } + return out.toString() + } catch (e: JSONException) { + Log.w(TAG, "searchSegments failed", e) + return "[]" + } + } + + /** Per-segment voice-print embeddings of a session (for re-diarization). */ + fun querySegmentEmbeddings(sessionId: Long): String { + val out = JSONArray() + try { + readableDatabase.rawQuery( + "SELECT id, embedding FROM segments WHERE session_id=? AND embedding IS NOT NULL", + arrayOf(sessionId.toString())).use { c -> + while (c.moveToNext()) { + val row = JSONObject() + row.put("id", c.getLong(0)) + row.put("embeddingBase64", Base64.encodeToString(c.getBlob(1), Base64.NO_WRAP)) + out.put(row) + } + } + } catch (e: JSONException) { + Log.w(TAG, "querySegmentEmbeddings failed", e) + } + return out.toString() + } + + // ---- speakers ---- + + fun createSpeaker(name: String?, color: String?, isWearer: Boolean, embeddingBase64: String?): Long { + val values = ContentValues() + values.put("name", name) + values.put("color", if (color == null || color.isEmpty()) "#4FC3F7" else color) + values.put("is_wearer", if (isWearer) 1 else 0) + values.put("created_at", System.currentTimeMillis()) + values.put("last_heard_at", System.currentTimeMillis()) + if (embeddingBase64 != null && !embeddingBase64.isEmpty()) { + values.put("embedding", Base64.decode(embeddingBase64, Base64.NO_WRAP)) + values.put("embedding_count", 1) + } + return writableDatabase.insert("speakers", null, values) + } + + fun querySpeakers(): String { + val out = JSONArray() + try { + readableDatabase.rawQuery( + "SELECT p.id, p.name, p.color, p.is_wearer, p.embedding, p.embedding_count," + + " p.last_heard_at, p.tag," + + " p.last_recap, p.action_items, p.facts, p.insights_updated_at, p.insights_session_id," + + " (SELECT COUNT(*) FROM segments g WHERE g.speaker_id = p.id) AS segments" + + " FROM speakers p ORDER BY p.last_heard_at DESC", null).use { c -> + while (c.moveToNext()) { + val row = JSONObject() + row.put("id", c.getLong(0)) + row.put("name", c.getString(1)) + row.put("color", c.getString(2)) + row.put("isWearer", c.getInt(3) != 0) + val blob = if (c.isNull(4)) null else c.getBlob(4) + row.put("embeddingBase64", if (blob == null) "" else Base64.encodeToString(blob, Base64.NO_WRAP)) + row.put("embeddingCount", c.getInt(5)) + row.put("lastHeardAt", if (c.isNull(6)) 0L else c.getLong(6)) + row.put("tag", if (c.isNull(7)) "" else c.getString(7)) + row.put("lastRecap", if (c.isNull(8)) "" else c.getString(8)) + row.put("actionItemsJson", if (c.isNull(9)) "" else c.getString(9)) + row.put("factsJson", if (c.isNull(10)) "" else c.getString(10)) + row.put("insightsUpdatedAt", if (c.isNull(11)) 0L else c.getLong(11)) + row.put("insightsSessionId", if (c.isNull(12)) 0L else c.getLong(12)) + row.put("segmentCount", c.getLong(13)) + out.put(row) + } + } + } catch (e: JSONException) { + Log.w(TAG, "querySpeakers failed", e) + } + return out.toString() + } + + fun renameSpeaker(speakerId: Long, name: String?) { + val values = ContentValues() + values.put("name", name) + writableDatabase.update("speakers", values, "id=?", arrayOf(speakerId.toString())) + } + + fun setSpeakerColor(speakerId: Long, color: String?) { + val values = ContentValues() + values.put("color", color) + writableDatabase.update("speakers", values, "id=?", arrayOf(speakerId.toString())) + } + + fun setSpeakerTag(speakerId: Long, tag: String?) { + val values = ContentValues() + values.put("tag", tag) + writableDatabase.update("speakers", values, "id=?", arrayOf(speakerId.toString())) + } + + /** + * Store LLM-derived conversation insights for a speaker: a recap of their + * most recent conversation, its open action items (JSON string array), and + * the accumulated inferred facts about them (JSON string array). + */ + fun setSpeakerInsights(speakerId: Long, recap: String?, actionItemsJson: String?, + factsJson: String?, sessionId: Long) { + val values = ContentValues() + values.put("last_recap", recap ?: "") + values.put("action_items", actionItemsJson ?: "") + values.put("facts", factsJson ?: "") + values.put("insights_updated_at", System.currentTimeMillis()) + values.put("insights_session_id", sessionId) + writableDatabase.update("speakers", values, "id=?", arrayOf(speakerId.toString())) + } + + fun setSpeakerWearer(speakerId: Long, isWearer: Boolean) { + val db = writableDatabase + if (isWearer) { + // Exactly one wearer profile at a time. + db.execSQL("UPDATE speakers SET is_wearer = 0") + } + val values = ContentValues() + values.put("is_wearer", if (isWearer) 1 else 0) + db.update("speakers", values, "id=?", arrayOf(speakerId.toString())) + } + + /** + * Running-mean centroid update for a speaker's voice-print, capped so a + * long session cannot drown the enrolled voice. + */ + fun updateSpeakerEmbedding(speakerId: Long, embeddingBase64: String?, maxCount: Int) { + try { + val incoming = Base64.decode(embeddingBase64, Base64.NO_WRAP) + val update = blobToFloats(incoming) + if (update == null) { + return + } + var current: FloatArray? = null + var count = 0 + val c = readableDatabase.rawQuery( + "SELECT embedding, embedding_count FROM speakers WHERE id=?", + arrayOf(speakerId.toString())) + try { + if (c.moveToFirst()) { + current = if (c.isNull(0)) null else blobToFloats(c.getBlob(0)) + count = c.getInt(1) + } + } finally { + c.close() + } + val merged: FloatArray + if (current == null || current.size != update.size) { + merged = update + count = 1 + } else { + val effective = Math.min(count, Math.max(1, maxCount)) + merged = FloatArray(current.size) + for (i in merged.indices) { + merged[i] = (current[i] * effective + update[i]) / (effective + 1) + } + l2NormalizeInPlace(merged) + count = count + 1 + } + val values = ContentValues() + values.put("embedding", floatsToBlob(merged)) + values.put("embedding_count", count) + values.put("last_heard_at", System.currentTimeMillis()) + writableDatabase.update("speakers", values, "id=?", + arrayOf(speakerId.toString())) + } catch (t: Throwable) { + Log.w(TAG, "updateSpeakerEmbedding failed", t) + } + } + + /** Move every segment from one speaker onto another and drop the source. */ + fun mergeSpeakers(fromId: Long, intoId: Long) { + if (fromId == intoId) { + return + } + val db = writableDatabase + db.beginTransaction() + try { + db.execSQL("UPDATE segments SET speaker_id=? WHERE speaker_id=?", + arrayOf(intoId, fromId)) + // Blend the two centroids weighted by their sample counts. + var from: FloatArray? = null + var into: FloatArray? = null + var fromCount = 0 + var intoCount = 0 + var fromWearer = false + val c = db.rawQuery( + "SELECT id, embedding, embedding_count, is_wearer FROM speakers WHERE id IN (?,?)", + arrayOf(fromId.toString(), intoId.toString())) + try { + while (c.moveToNext()) { + val id = c.getLong(0) + val embedding = if (c.isNull(1)) null else blobToFloats(c.getBlob(1)) + val count = c.getInt(2) + if (id == fromId) { + from = embedding + fromCount = count + fromWearer = c.getInt(3) != 0 + } else { + into = embedding + intoCount = count + } + } + } finally { + c.close() + } + var merged: FloatArray? = into + if (from != null && into != null && from.size == into.size) { + val blended = FloatArray(into.size) + val total = Math.max(1, fromCount + intoCount) + for (i in blended.indices) { + blended[i] = (into[i] * intoCount + from[i] * fromCount) / total + } + l2NormalizeInPlace(blended) + merged = blended + } else if (into == null) { + merged = from + } + val values = ContentValues() + if (merged != null) { + values.put("embedding", floatsToBlob(merged)) + values.put("embedding_count", fromCount + intoCount) + } + if (fromWearer) { + values.put("is_wearer", 1) + } + values.put("last_heard_at", System.currentTimeMillis()) + // Keep the target's conversation insights; adopt the source's only + // where the target has none (e.g. merging a rich profile into a + // freshly auto-created one). + db.rawQuery( + "SELECT last_recap, action_items, facts, insights_updated_at, insights_session_id" + + " FROM speakers WHERE id IN (?,?) ORDER BY CASE id WHEN ? THEN 0 ELSE 1 END", + arrayOf(fromId.toString(), intoId.toString(), intoId.toString())).use { c2 -> + var targetHasInsights = false + while (c2.moveToNext()) { + val hasInsights = !c2.isNull(0) && !c2.getString(0).isEmpty() + if (c2.position == 0) { + targetHasInsights = hasInsights + } else if (!targetHasInsights && hasInsights) { + values.put("last_recap", c2.getString(0)) + values.put("action_items", if (c2.isNull(1)) "" else c2.getString(1)) + values.put("facts", if (c2.isNull(2)) "" else c2.getString(2)) + values.put("insights_updated_at", if (c2.isNull(3)) 0L else c2.getLong(3)) + values.put("insights_session_id", if (c2.isNull(4)) 0L else c2.getLong(4)) + } + } + } + db.update("speakers", values, "id=?", arrayOf(intoId.toString())) + db.delete("speakers", "id=?", arrayOf(fromId.toString())) + db.setTransactionSuccessful() + } finally { + db.endTransaction() + } + } + + fun reassignSegmentSpeaker(segmentId: Long, speakerId: Long) { + val values = ContentValues() + values.put("speaker_id", speakerId) + writableDatabase.update("segments", values, "id=?", arrayOf(segmentId.toString())) + } + + /** Reassign every segment of a speaker within one session (split support). */ + fun reassignSessionSpeaker(sessionId: Long, fromSpeakerId: Long, toSpeakerId: Long) { + writableDatabase.execSQL( + "UPDATE segments SET speaker_id=? WHERE session_id=? AND speaker_id=?", + arrayOf(toSpeakerId, sessionId, fromSpeakerId)) + } + + fun deleteSpeaker(speakerId: Long) { + val db = writableDatabase + db.execSQL("UPDATE segments SET speaker_id=NULL WHERE speaker_id=?", arrayOf(speakerId)) + db.delete("speakers", "id=?", arrayOf(speakerId.toString())) + } + + // ---- retention ---- + + /** + * Delete caption sessions older than the cutoff (0 disables), and strip + * recordings older than their own cutoff while keeping the transcript. + * Returns a JSON summary of what was removed. + */ + fun applyRetention(captionCutoffMs: Long, recordingCutoffMs: Long): String { + val db = writableDatabase + var sessionsDeleted = 0 + var recordingsDeleted = 0 + if (recordingCutoffMs > 0) { + val paths: MutableList = ArrayList() + db.rawQuery( + "SELECT id, audio_path FROM sessions WHERE audio_path IS NOT NULL AND started_at < ?", + arrayOf(recordingCutoffMs.toString())).use { c -> + while (c.moveToNext()) { + if (!c.isNull(1)) { + paths.add(c.getString(1)) + } + } + } + for (path in paths) { + if (File(path).delete()) { + recordingsDeleted++ + } + } + db.execSQL("UPDATE sessions SET audio_path=NULL, audio_codec=NULL WHERE started_at < ?", + arrayOf(recordingCutoffMs)) + } + if (captionCutoffMs > 0) { + val paths: MutableList = ArrayList() + db.rawQuery( + "SELECT audio_path FROM sessions WHERE audio_path IS NOT NULL AND started_at < ?", + arrayOf(captionCutoffMs.toString())).use { c -> + while (c.moveToNext()) { + paths.add(c.getString(0)) + } + } + for (path in paths) { + if (path != null && File(path).delete()) { + recordingsDeleted++ + } + } + db.execSQL("DELETE FROM segments WHERE session_id IN (SELECT id FROM sessions WHERE started_at < ?)", + arrayOf(captionCutoffMs)) + val count = db.rawQuery("SELECT changes()", null) + count.close() + db.execSQL("DELETE FROM sessions WHERE started_at < ?", arrayOf(captionCutoffMs)) + db.rawQuery("SELECT changes()", null).use { c -> + if (c.moveToFirst()) { + sessionsDeleted = c.getInt(0) + } + } + } + try { + val summary = JSONObject() + summary.put("sessionsDeleted", sessionsDeleted) + summary.put("recordingsDeleted", recordingsDeleted) + return summary.toString() + } catch (e: JSONException) { + return "{}" + } + } + + fun deleteSession(sessionId: Long) { + val db = writableDatabase + val path = getSessionAudioPath(sessionId) + if (!path.isEmpty()) { + File(path).delete() + } + db.delete("segments", "session_id=?", arrayOf(sessionId.toString())) + db.delete("sessions", "id=?", arrayOf(sessionId.toString())) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.java deleted file mode 100644 index 53645f27..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.java +++ /dev/null @@ -1,386 +0,0 @@ -package com.faceclaw.app; - -import android.annotation.SuppressLint; -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothManager; -import android.bluetooth.le.BluetoothLeScanner; -import android.bluetooth.le.ScanCallback; -import android.bluetooth.le.ScanRecord; -import android.bluetooth.le.ScanResult; -import android.bluetooth.le.ScanSettings; -import android.content.Context; -import android.os.Build; -import android.os.Handler; -import android.os.Looper; -import android.util.SparseArray; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * Finds Even Realities hardware over BLE and hands every advertisement up to - * TypeScript with the raw fields the pairing screen needs: the LIVE local name - * from the scan record (BluetoothDevice.getName() is a cache that can hold a - * pre-reset value indefinitely), the full manufacturer-specific payload with - * its company identifier restored so the "ER"+serial+MAC layout survives - * intact, RSSI, advertised TX power, and connectability. - * - * Admission is deliberately loose — a name containing G2, the stock - * "EVEN R1…" ring prefix, or the Even "ER" manufacturer signature — because - * renamed custom firmware may drop the stock name. Side, serial, and pair - * matching are decided in TypeScript (app/g2/even-advertisement.ts, - * app/g2/pairing-candidates.ts) where they can be unit-tested; this filter - * must stay a superset of the TS classifier's admission. - */ -@SuppressLint("MissingPermission") -public class FaceclawDeviceDiscovery { - /** Even Realities' company identifier: the ASCII bytes "ER" read little-endian. */ - public static final int EVEN_COMPANY_ID = 0x5245; - - private final BluetoothAdapter bluetoothAdapter; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - - private final Object lock = new Object(); - private ScanCallback activeCallback; - private volatile FaceclawDeviceDiscoveryListener listener; - - public FaceclawDeviceDiscovery(Context context) { - Context appContext = context.getApplicationContext(); - BluetoothManager bluetoothManager = - (BluetoothManager) appContext.getSystemService(Context.BLUETOOTH_SERVICE); - if (bluetoothManager == null || bluetoothManager.getAdapter() == null) { - throw new IllegalStateException("Bluetooth adapter unavailable"); - } - this.bluetoothAdapter = bluetoothManager.getAdapter(); - } - - public boolean isBluetoothEnabled() { - return bluetoothAdapter.isEnabled(); - } - - public void setListener(FaceclawDeviceDiscoveryListener newListener) { - this.listener = newListener; - } - - // ------------------------------------------------------------------ - // Live scan - // ------------------------------------------------------------------ - - /** - * Start streaming advertisements to the listener. Returns false when the - * radio is off or the scanner is unavailable; a later platform refusal - * arrives through onScanFailed. Calling while a scan is running is a no-op. - */ - public boolean startScan() { - synchronized (lock) { - if (activeCallback != null) { - return true; - } - if (!bluetoothAdapter.isEnabled()) { - emitLog("scan not started: Bluetooth is off"); - return false; - } - BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner(); - if (scanner == null) { - emitLog("scan not started: no BLE scanner"); - return false; - } - final ScanCallback callback = new ScanCallback() { - @Override - public void onScanResult(int callbackType, ScanResult result) { - if (result != null) { - emitAdvertisement(result); - } - } - - @Override - public void onBatchScanResults(List results) { - if (results == null) { - return; - } - for (ScanResult result : results) { - if (result != null) { - emitAdvertisement(result); - } - } - } - - @Override - public void onScanFailed(int errorCode) { - synchronized (lock) { - if (activeCallback == this) { - activeCallback = null; - } - } - final FaceclawDeviceDiscoveryListener l = listener; - if (l != null) { - final String message = describeScanError(errorCode); - mainHandler.post(() -> l.onScanFailed(errorCode, message)); - } - } - }; - activeCallback = callback; - try { - scanner.startScan(null, buildScanSettings(), callback); - } catch (Throwable t) { - activeCallback = null; - emitLog("scan not started: " + t); - return false; - } - emitLog("scan started (unfiltered, low latency)"); - return true; - } - } - - public void stopScan() { - ScanCallback callback; - synchronized (lock) { - callback = activeCallback; - activeCallback = null; - } - if (callback == null) { - return; - } - BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner(); - if (scanner != null) { - try { - scanner.stopScan(callback); - } catch (Throwable ignored) { - } - } - emitLog("scan stopped"); - } - - public boolean isScanning() { - synchronized (lock) { - return activeCallback != null; - } - } - - /** - * Replay bonded Even devices to the listener. A bonded listing has no - * signal sample and no manufacturer data, so its serial stays unknown until - * the device is also heard advertising. - */ - public void emitBondedDevices() { - final FaceclawDeviceDiscoveryListener l = listener; - if (l == null) { - return; - } - for (String json : bondedCandidateJsonList()) { - l.onAdvertisement(json); - } - } - - /** Bonded Even devices as one JSON array, for callers without a listener. */ - public String getBondedCandidatesJson() { - JSONArray array = new JSONArray(); - for (String json : bondedCandidateJsonList()) { - try { - array.put(new JSONObject(json)); - } catch (JSONException ignored) { - } - } - return array.toString(); - } - - // ------------------------------------------------------------------ - // Internals - // ------------------------------------------------------------------ - - private static ScanSettings buildScanSettings() { - ScanSettings.Builder builder = new ScanSettings.Builder() - .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) - .setReportDelay(0); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - builder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES); - builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE); - builder.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - // Accept extended advertising too; setLegacy(true) would hide it. - builder.setLegacy(false); - } - return builder.build(); - } - - private void emitAdvertisement(ScanResult result) { - final JSONObject object = toJson(result); - if (object == null) { - return; - } - final FaceclawDeviceDiscoveryListener l = listener; - if (l == null) { - return; - } - final String json = object.toString(); - if (Looper.myLooper() == Looper.getMainLooper()) { - l.onAdvertisement(json); - } else { - mainHandler.post(() -> { - FaceclawDeviceDiscoveryListener current = listener; - if (current != null) { - current.onAdvertisement(json); - } - }); - } - } - - private List bondedCandidateJsonList() { - List out = new ArrayList<>(); - Set bonded = bluetoothAdapter.getBondedDevices(); - if (bonded == null) { - return out; - } - long now = System.currentTimeMillis(); - for (BluetoothDevice device : bonded) { - if (device == null) { - continue; - } - String name = device.getName(); - if (!isAdmissible(name, null)) { - continue; - } - JSONObject object = buildJson( - device.getAddress(), name, "", null, null, null, true, "paired", now); - if (object != null) { - out.add(object.toString()); - } - } - return out; - } - - /** Null when the result is not something we pair with. */ - private static JSONObject toJson(ScanResult result) { - BluetoothDevice device = result.getDevice(); - if (device == null) { - return null; - } - ScanRecord record = result.getScanRecord(); - String liveName = record == null ? null : record.getDeviceName(); - String name = liveName != null && !liveName.isEmpty() ? liveName : device.getName(); - byte[] manufacturerData = extractEvenManufacturerData(record); - if (!isAdmissible(name, manufacturerData)) { - return null; - } - Integer txPower = null; - if (record != null && record.getTxPowerLevel() != Integer.MIN_VALUE) { - txPower = record.getTxPowerLevel(); - } - if (txPower == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - && result.getTxPower() != ScanResult.TX_POWER_NOT_PRESENT) { - txPower = result.getTxPower(); - } - Boolean connectable = null; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - connectable = result.isConnectable(); - } - int rssi = result.getRssi(); - // 127 is the "unavailable" sentinel; 0 dBm never happens for a real sample. - Integer rssiValue = (rssi == 127 || rssi == 0) ? null : rssi; - boolean bonded = device.getBondState() == BluetoothDevice.BOND_BONDED; - return buildJson( - device.getAddress(), name, FaceclawFirmwareUtil.bytesToHex(manufacturerData), rssiValue, txPower, - connectable, bonded, "scan", System.currentTimeMillis()); - } - - /** - * Android strips the 2-byte company identifier from each manufacturer - * record and keys the SparseArray by it. Put the bytes back (little-endian) - * so TypeScript sees the same "ER"+… layout the HCI captures - * document. Prefers Even's own id; otherwise returns the first record so an - * unexpected company id still reaches the diagnostics log. - */ - private static byte[] extractEvenManufacturerData(ScanRecord record) { - if (record == null) { - return new byte[0]; - } - SparseArray all = record.getManufacturerSpecificData(); - if (all == null || all.size() == 0) { - return new byte[0]; - } - byte[] payload = all.get(EVEN_COMPANY_ID); - int companyId = EVEN_COMPANY_ID; - if (payload == null) { - companyId = all.keyAt(0); - payload = all.valueAt(0); - } - if (payload == null) { - return new byte[0]; - } - byte[] out = new byte[payload.length + 2]; - out[0] = (byte) (companyId & 0xff); - out[1] = (byte) ((companyId >> 8) & 0xff); - System.arraycopy(payload, 0, out, 2, payload.length); - return out; - } - - private static boolean isAdmissible(String name, byte[] manufacturerData) { - if (manufacturerData != null && manufacturerData.length >= 2 - && manufacturerData[0] == 0x45 && manufacturerData[1] == 0x52) { - return true; - } - if (name == null) { - return false; - } - String upper = name.toUpperCase(); - // A bare "R1" substring also matches unrelated hardware ("Oppo Enco - // R1"), and TS only classifies rings from the stock name prefix. - return upper.contains("G2") || upper.startsWith("EVEN R1"); - } - - private static JSONObject buildJson( - String address, String name, String manufacturerHex, Integer rssi, Integer txPower, - Boolean connectable, boolean bonded, String source, long seenAtMs) { - if (address == null || address.isEmpty()) { - return null; - } - try { - JSONObject object = new JSONObject(); - object.put("address", address); - object.put("name", name == null ? "" : name); - object.put("manufacturerData", manufacturerHex == null ? "" : manufacturerHex); - object.put("rssi", rssi == null ? JSONObject.NULL : rssi); - object.put("txPower", txPower == null ? JSONObject.NULL : txPower); - object.put("connectable", connectable == null ? JSONObject.NULL : connectable); - object.put("bonded", bonded); - object.put("source", source); - object.put("seenAtMs", seenAtMs); - return object; - } catch (JSONException e) { - return null; - } - } - - private static String describeScanError(int errorCode) { - switch (errorCode) { - case ScanCallback.SCAN_FAILED_ALREADY_STARTED: - return "a scan is already running"; - case ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED: - return "the Bluetooth stack refused to register the scan (try toggling Bluetooth)"; - case ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED: - return "BLE scanning is not supported on this device"; - case ScanCallback.SCAN_FAILED_INTERNAL_ERROR: - return "internal Bluetooth error"; - case 5: // SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES (API 31) - return "out of Bluetooth hardware resources"; - case 6: // SCAN_FAILED_SCANNING_TOO_FREQUENTLY (API 31) - return "scanning too frequently; wait a moment and try again"; - default: - return "scan failed (code " + errorCode + ")"; - } - } - - private void emitLog(String line) { - FaceclawDeviceDiscoveryListener l = listener; - if (l != null) { - l.onLog(line); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.kt new file mode 100644 index 00000000..b43bcaae --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.kt @@ -0,0 +1,372 @@ +package com.faceclaw.app + +import android.annotation.SuppressLint +import android.bluetooth.BluetoothAdapter +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothManager +import android.bluetooth.le.BluetoothLeScanner +import android.bluetooth.le.ScanCallback +import android.bluetooth.le.ScanRecord +import android.bluetooth.le.ScanResult +import android.bluetooth.le.ScanSettings +import android.content.Context +import android.os.Build +import android.os.Handler +import android.os.Looper +import android.util.SparseArray + +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject + +import java.util.ArrayList + +/** + * Finds Even Realities hardware over BLE and hands every advertisement up to + * TypeScript with the raw fields the pairing screen needs: the LIVE local name + * from the scan record (BluetoothDevice.getName() is a cache that can hold a + * pre-reset value indefinitely), the full manufacturer-specific payload with + * its company identifier restored so the "ER"+serial+MAC layout survives + * intact, RSSI, advertised TX power, and connectability. + * + * Admission is deliberately loose — a name containing G2, the stock + * "EVEN R1…" ring prefix, or the Even "ER" manufacturer signature — because + * renamed custom firmware may drop the stock name. Side, serial, and pair + * matching are decided in TypeScript (app/g2/even-advertisement.ts, + * app/g2/pairing-candidates.ts) where they can be unit-tested; this filter + * must stay a superset of the TS classifier's admission. + */ +@SuppressLint("MissingPermission") +class FaceclawDeviceDiscovery(context: Context) { + companion object { + /** Even Realities' company identifier: the ASCII bytes "ER" read little-endian. */ + const val EVEN_COMPANY_ID = 0x5245 + + // ------------------------------------------------------------------ + // Internals + // ------------------------------------------------------------------ + + private fun buildScanSettings(): ScanSettings { + val builder = ScanSettings.Builder() + .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) + .setReportDelay(0) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + builder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) + builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE) + builder.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT) + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + // Accept extended advertising too; setLegacy(true) would hide it. + builder.setLegacy(false) + } + return builder.build() + } + + /** Null when the result is not something we pair with. */ + private fun toJson(result: ScanResult): JSONObject? { + val device = result.device ?: return null + val record = result.scanRecord + val liveName = record?.deviceName + val name = if (liveName != null && !liveName.isEmpty()) liveName else device.name + val manufacturerData = extractEvenManufacturerData(record) + if (!isAdmissible(name, manufacturerData)) { + return null + } + var txPower: Int? = null + if (record != null && record.txPowerLevel != Int.MIN_VALUE) { + txPower = record.txPowerLevel + } + if (txPower == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && result.txPower != ScanResult.TX_POWER_NOT_PRESENT) { + txPower = result.txPower + } + var connectable: Boolean? = null + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + connectable = result.isConnectable + } + val rssi = result.rssi + // 127 is the "unavailable" sentinel; 0 dBm never happens for a real sample. + val rssiValue: Int? = if (rssi == 127 || rssi == 0) null else rssi + val bonded = device.bondState == BluetoothDevice.BOND_BONDED + return buildJson( + device.address, name, FaceclawFirmwareUtil.bytesToHex(manufacturerData), rssiValue, txPower, + connectable, bonded, "scan", System.currentTimeMillis()) + } + + /** + * Android strips the 2-byte company identifier from each manufacturer + * record and keys the SparseArray by it. Put the bytes back (little-endian) + * so TypeScript sees the same "ER"+… layout the HCI captures + * document. Prefers Even's own id; otherwise returns the first record so an + * unexpected company id still reaches the diagnostics log. + */ + private fun extractEvenManufacturerData(record: ScanRecord?): ByteArray { + if (record == null) { + return ByteArray(0) + } + val all: SparseArray? = record.manufacturerSpecificData + if (all == null || all.size() == 0) { + return ByteArray(0) + } + var payload: ByteArray? = all.get(EVEN_COMPANY_ID) + var companyId = EVEN_COMPANY_ID + if (payload == null) { + companyId = all.keyAt(0) + payload = all.valueAt(0) + } + if (payload == null) { + return ByteArray(0) + } + val out = ByteArray(payload.size + 2) + out[0] = (companyId and 0xff).toByte() + out[1] = ((companyId shr 8) and 0xff).toByte() + System.arraycopy(payload, 0, out, 2, payload.size) + return out + } + + private fun isAdmissible(name: String?, manufacturerData: ByteArray?): Boolean { + if (manufacturerData != null && manufacturerData.size >= 2 + && manufacturerData[0] == 0x45.toByte() && manufacturerData[1] == 0x52.toByte()) { + return true + } + if (name == null) { + return false + } + val upper = name.uppercase() + // A bare "R1" substring also matches unrelated hardware ("Oppo Enco + // R1"), and TS only classifies rings from the stock name prefix. + return upper.contains("G2") || upper.startsWith("EVEN R1") + } + + private fun buildJson( + address: String?, name: String?, manufacturerHex: String?, rssi: Int?, txPower: Int?, + connectable: Boolean?, bonded: Boolean, source: String, seenAtMs: Long): JSONObject? { + if (address == null || address.isEmpty()) { + return null + } + try { + val obj = JSONObject() + obj.put("address", address) + obj.put("name", name ?: "") + obj.put("manufacturerData", manufacturerHex ?: "") + obj.put("rssi", rssi ?: JSONObject.NULL) + obj.put("txPower", txPower ?: JSONObject.NULL) + obj.put("connectable", connectable ?: JSONObject.NULL) + obj.put("bonded", bonded) + obj.put("source", source) + obj.put("seenAtMs", seenAtMs) + return obj + } catch (e: JSONException) { + return null + } + } + + private fun describeScanError(errorCode: Int): String { + return when (errorCode) { + ScanCallback.SCAN_FAILED_ALREADY_STARTED -> + "a scan is already running" + ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED -> + "the Bluetooth stack refused to register the scan (try toggling Bluetooth)" + ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED -> + "BLE scanning is not supported on this device" + ScanCallback.SCAN_FAILED_INTERNAL_ERROR -> + "internal Bluetooth error" + 5 -> // SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES (API 31) + "out of Bluetooth hardware resources" + 6 -> // SCAN_FAILED_SCANNING_TOO_FREQUENTLY (API 31) + "scanning too frequently; wait a moment and try again" + else -> + "scan failed (code $errorCode)" + } + } + } + + private val bluetoothAdapter: BluetoothAdapter + private val mainHandler = Handler(Looper.getMainLooper()) + + private val lock = Any() + private var activeCallback: ScanCallback? = null + @Volatile + private var listener: FaceclawDeviceDiscoveryListener? = null + + init { + val appContext = context.applicationContext + val bluetoothManager = + appContext.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager? + if (bluetoothManager == null || bluetoothManager.adapter == null) { + throw IllegalStateException("Bluetooth adapter unavailable") + } + this.bluetoothAdapter = bluetoothManager.adapter + } + + fun isBluetoothEnabled(): Boolean { + return bluetoothAdapter.isEnabled + } + + fun setListener(newListener: FaceclawDeviceDiscoveryListener?) { + this.listener = newListener + } + + // ------------------------------------------------------------------ + // Live scan + // ------------------------------------------------------------------ + + /** + * Start streaming advertisements to the listener. Returns false when the + * radio is off or the scanner is unavailable; a later platform refusal + * arrives through onScanFailed. Calling while a scan is running is a no-op. + */ + fun startScan(): Boolean { + synchronized(lock) { + if (activeCallback != null) { + return true + } + if (!bluetoothAdapter.isEnabled) { + emitLog("scan not started: Bluetooth is off") + return false + } + val scanner: BluetoothLeScanner? = bluetoothAdapter.bluetoothLeScanner + if (scanner == null) { + emitLog("scan not started: no BLE scanner") + return false + } + val callback = object : ScanCallback() { + override fun onScanResult(callbackType: Int, result: ScanResult?) { + if (result != null) { + emitAdvertisement(result) + } + } + + override fun onBatchScanResults(results: List?) { + if (results == null) { + return + } + for (result in results) { + if (result != null) { + emitAdvertisement(result) + } + } + } + + override fun onScanFailed(errorCode: Int) { + synchronized(lock) { + if (activeCallback === this) { + activeCallback = null + } + } + val l = listener + if (l != null) { + val message = describeScanError(errorCode) + mainHandler.post { l.onScanFailed(errorCode, message) } + } + } + } + activeCallback = callback + try { + scanner.startScan(null, buildScanSettings(), callback) + } catch (t: Throwable) { + activeCallback = null + emitLog("scan not started: $t") + return false + } + emitLog("scan started (unfiltered, low latency)") + return true + } + } + + fun stopScan() { + val callback: ScanCallback? + synchronized(lock) { + callback = activeCallback + activeCallback = null + } + if (callback == null) { + return + } + val scanner = bluetoothAdapter.bluetoothLeScanner + if (scanner != null) { + try { + scanner.stopScan(callback) + } catch (ignored: Throwable) { + } + } + emitLog("scan stopped") + } + + fun isScanning(): Boolean { + synchronized(lock) { + return activeCallback != null + } + } + + /** + * Replay bonded Even devices to the listener. A bonded listing has no + * signal sample and no manufacturer data, so its serial stays unknown until + * the device is also heard advertising. + */ + fun emitBondedDevices() { + val l = listener ?: return + for (json in bondedCandidateJsonList()) { + l.onAdvertisement(json) + } + } + + /** Bonded Even devices as one JSON array, for callers without a listener. */ + fun getBondedCandidatesJson(): String { + val array = JSONArray() + for (json in bondedCandidateJsonList()) { + try { + array.put(JSONObject(json)) + } catch (ignored: JSONException) { + } + } + return array.toString() + } + + private fun emitAdvertisement(result: ScanResult) { + val obj = toJson(result) ?: return + val l = listener ?: return + val json = obj.toString() + if (Looper.myLooper() == Looper.getMainLooper()) { + l.onAdvertisement(json) + } else { + mainHandler.post { + val current = listener + if (current != null) { + current.onAdvertisement(json) + } + } + } + } + + private fun bondedCandidateJsonList(): List { + val out = ArrayList() + val bonded: Set? = bluetoothAdapter.bondedDevices + if (bonded == null) { + return out + } + val now = System.currentTimeMillis() + for (device in bonded) { + if (device == null) { + continue + } + val name = device.name + if (!isAdmissible(name, null)) { + continue + } + val obj = buildJson( + device.address, name, "", null, null, null, true, "paired", now) + if (obj != null) { + out.add(obj.toString()) + } + } + return out + } + + private fun emitLog(line: String) { + val l = listener + if (l != null) { + l.onLog(line) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java deleted file mode 100644 index 7e7e5991..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.java +++ /dev/null @@ -1,619 +0,0 @@ -package com.faceclaw.app; - -import android.bluetooth.BluetoothDevice; -import android.bluetooth.BluetoothGatt; -import android.content.Context; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; -import android.util.Log; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * Connects to the glasses (stock-firmware compatible), reads the device-info / - * settings response, and reports the firmware versions plus the firmware- - * extension string (empty on stock firmware). Used by onboarding to decide whether to - * flash. Reuses FaceclawBleManager + BleProtocol; owns its own connection and - * runs on a single worker thread. Shows nothing on the lens. - */ -public class FaceclawDeviceInfoProbe implements FaceclawBleListener { - private static final String TAG = "FaceclawDeviceInfo"; - private static final int QUERY_TIMEOUT_MS = 4_000; - /** Connect + auth attempts per arm; a link that drops mid-pairing is retried once the bond settles. */ - private static final int ARM_ATTEMPTS = 3; - private static final int ARM_RETRY_DELAY_MS = 1_000; - /** - * Upper bound on waiting for the auth success while Android reports the arm - * as BOND_BONDING — i.e. an OS pairing dialog may be sitting there waiting - * for the user, which can take a lot longer than the normal 30 s window. - */ - private static final int PAIRING_WAIT_CAP_MS = 90_000; - /** After a fresh bond, how long the firmware gets to notify success on its own before the request is re-sent. */ - private static final int POST_BOND_GRACE_MS = 2_000; - private static final int POLL_MS = 250; - - private final Context context; - private final String rightAddress; - private final String leftAddress; - private final FaceclawBleManager bleManager; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - - private final Object lock = new Object(); - private int nextSeq = 0x40; - private int nextMagic = 100; - - private int awaitSid = -1; - private int awaitMagic = -1; - private byte[] awaitPb = null; - private CountDownLatch awaitLatch = null; - - /** - * Security-auth wait, kept separate from the generic ack wait: only the - * firmware's SUCCESS result (empty result message) may satisfy it. The - * firmware answers the request as soon as it arrives, but with a - * non-success result until the link is encrypted; accepting that first - * reply as "the ack" is what let the probe move on to the other arm while - * Android's pairing dialog for this one was still up. - */ - private final Set authMagics = new HashSet<>(); - private CountDownLatch authLatch = null; - - /** - * A sid-0x09 frame that carried firmware versions without matching the - * awaited magic — some firmware pushes the settings snapshot on a magic it - * picked itself instead of (or in addition to) acking the read. - */ - private volatile byte[] unsolicitedSettingsPb; - - private volatile FaceclawDeviceInfoProbeListener listener; - private volatile Thread worker; - private volatile boolean cancelled = false; - - public FaceclawDeviceInfoProbe(Context context, String rightAddress, String leftAddress) { - this.context = context.getApplicationContext(); - this.rightAddress = rightAddress == null ? "" : rightAddress; - this.leftAddress = leftAddress == null ? "" : leftAddress; - this.bleManager = new FaceclawBleManager(this.context); - this.bleManager.setListener(this); - } - - public void setListener(FaceclawDeviceInfoProbeListener listener) { - this.listener = listener; - } - - public void start() { - synchronized (lock) { - if (worker != null) { - return; - } - worker = new Thread(this::run, "faceclaw-device-info"); - worker.start(); - } - } - - public void cancel() { - cancelled = true; - Thread w = worker; - if (w != null) { - w.interrupt(); - } - } - - public void close() { - cancel(); - try { - bleManager.close(); - } catch (Exception ignored) { - } - } - - private void run() { - try { - if (rightAddress.trim().isEmpty()) { - emitError("No right-arm address configured."); - return; - } - - boolean haveLeft = !leftAddress.trim().isEmpty() && !leftAddress.equalsIgnoreCase(rightAddress); - - // Bring up and authenticate BOTH arms before asking for versions. - // Each arm is its own peripheral with its own bond, so on a fresh - // phone each raises its own pairing prompt; completing both here - // means the flash step (and the app proper) find both bonds in - // place. Strictly one arm at a time: Android pairs with one device - // at a time, and a second arm connected while the first was still - // pairing has been seen to drop within a second and never pair - // (2026-09-11 logcat). - boolean rightAuthenticated = bringUpArm(rightAddress, "right"); - boolean leftAuthenticated = false; - if (haveLeft && !cancelled) { - leftAuthenticated = bringUpArm(leftAddress, "left"); - } - if (cancelled) { - emitError("Cancelled."); - return; - } - if (!bleManager.isConnected(rightAddress)) { - // The right lens may have dropped while the left one paired; - // it is bonded by now, so this comes back quickly. - emitLog("right lens disconnected while the left lens was set up; reconnecting"); - rightAuthenticated = bringUpArm(rightAddress, "right"); - if (cancelled) { - emitError("Cancelled."); - return; - } - } - - byte[] ack = null; - String rightFailure = null; - try { - ack = queryArm(rightAddress, "right", rightAuthenticated); - } catch (IllegalStateException e) { - rightFailure = e.getMessage() == null ? e.toString() : e.getMessage(); - emitLog("right-lens query failed: " + rightFailure); - } - // The right lens is the documented control endpoint, but a silent - // right lens has been observed on stock 2.2.9 even after a - // successful security auth — run the same probe against the left - // lens rather than giving up, and log which lens answered. - if (ack == null && !cancelled && haveLeft) { - emitLog("right lens did not answer the settings query; probing the left lens"); - try { - ack = queryArm(leftAddress, "left", leftAuthenticated); - } catch (Exception e) { - emitLog("left-lens probe failed: " + (e.getMessage() == null ? e.toString() : e.getMessage())); - } - } - if (cancelled) { - emitError("Cancelled."); - return; - } - if (ack == null) { - throw new IllegalStateException(rightFailure != null - ? rightFailure - : "no response to the device-info query on either lens — check `adb logcat -s " - + TAG + "` for the frame trace"); - } - - BleProtocol.FirmwareInfo info = BleProtocol.parseSettingsFirmwareInfo(ack); - String left = info == null ? "" : info.leftVersion; - String right = info == null ? "" : info.rightVersion; - String extension = info == null ? "" : info.extension; - emitLog("device-info: L=" + left + " R=" + right + " ext=[" + extension + "]"); - emitResult(left, right, extension); - } catch (Exception e) { - String message = cancelled ? "Cancelled." : (e.getMessage() == null ? e.toString() : e.getMessage()); - emitError(message); - } finally { - try { - bleManager.close(); - } catch (Exception ignored) { - } - } - } - - /** - * Connect to one arm and complete its security-auth exchange, retrying - * when the link drops mid-pairing. Returns whether the auth success was - * seen (false = connected but unconfirmed, tolerated because the custom - * firmware's response to the exchange is not yet hardware-verified); - * throws when the arm cannot be brought up at all. - */ - private boolean bringUpArm(String address, String label) throws InterruptedException { - String lastFailure = null; - for (int attempt = 1; attempt <= ARM_ATTEMPTS && !cancelled; attempt++) { - if (attempt > 1) { - // A link Android dropped while it was still pairing comes back - // once the bond settles; reconnecting sooner just fails again. - waitForBondToSettle(address, label); - if (cancelled) { - break; - } - emitLog("retrying the " + label + " lens (attempt " + attempt + "/" + ARM_ATTEMPTS + "): " + lastFailure); - Thread.sleep(ARM_RETRY_DELAY_MS); - } - emitState("connecting", label); - try { - connectArm(address); - } catch (IllegalStateException e) { - lastFailure = e.getMessage() == null ? e.toString() : e.getMessage(); - emitLog(label + " lens: " + lastFailure); - continue; - } - if (cancelled) { - break; - } - - // Firmware 2.2.9 answers no queries until the security-auth - // exchange completes over an encrypted link; on a phone with no - // existing bond this is also what triggers SMP pairing (and its OS - // prompt), so it must come before the prelude and query. - emitState("authenticating", label); - AuthResult result = authenticate(address, label); - if (result == AuthResult.SUCCESS) { - return true; - } - if (result == AuthResult.UNCONFIRMED) { - return false; - } - lastFailure = "link dropped during authentication"; - } - if (cancelled) { - return false; - } - throw new IllegalStateException("could not connect to the " + label + " lens (" + address + "): " - + lastFailure + " — if Android showed a Bluetooth pairing request, accept it and try again"); - } - - private enum AuthResult { SUCCESS, UNCONFIRMED, LINK_DROPPED } - - /** - * Send the sid-0x80 authentication request and wait for the firmware's - * SUCCESS notification, which only arrives once the link is encrypted. - * On an unbonded phone that means waiting through Android's pairing flow - * (BOND_BONDING, possibly with a dialog up), so the wait is extended while - * the OS reports pairing in progress and the request is re-sent once - * after a fresh bond in case the pre-pairing write was dropped. Bond - * state is polled rather than awaited via broadcast; 250 ms granularity - * is plenty here. - */ - private AuthResult authenticate(String address, String label) throws InterruptedException { - long start = SystemClock.elapsedRealtime(); - long deadline = start + ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS; - long hardDeadline = start + PAIRING_WAIT_CAP_MS; - CountDownLatch latch = new CountDownLatch(1); - synchronized (lock) { - authMagics.clear(); - authLatch = latch; - } - int initialBond = bleManager.getBondState(address); - emitLog("security auth: " + label + " lens, Android bond state " + bondStateName(initialBond)); - try { - int sends = 0; - boolean lastSendFailed = false; - long nextSendAt = start; - long bondedAt = -1; - boolean resentAfterBond = false; - boolean loggedBonding = false; - while (!cancelled) { - long now = SystemClock.elapsedRealtime(); - int bond = bleManager.getBondState(address); - - if (bond == BluetoothDevice.BOND_BONDING) { - // OS pairing in progress — the firmware will answer once the - // link is encrypted. Don't write, don't give up, don't move - // on to the other arm. - if (!loggedBonding) { - emitLog("Android is pairing with the " + label + " lens; waiting for the user to accept"); - loggedBonding = true; - } - if (now >= hardDeadline) { - break; - } - } else { - if (bond == BluetoothDevice.BOND_BONDED && initialBond != BluetoothDevice.BOND_BONDED - && bondedAt < 0) { - bondedAt = now; - emitLog("Android bond established with the " + label + " lens; waiting for the auth success"); - deadline = Math.max(deadline, now + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS); - } - boolean wantSend = sends == 0 - || (lastSendFailed && sends < 3 && now >= nextSendAt) - || (bondedAt >= 0 && !resentAfterBond && now - bondedAt >= POST_BOND_GRACE_MS); - if (wantSend) { - if (bondedAt >= 0) { - resentAfterBond = true; - if (sends > 0) { - emitLog("re-sending the auth request after pairing (" + label + " lens)"); - } - } - lastSendFailed = !sendAuthRequest(address); - sends++; - nextSendAt = SystemClock.elapsedRealtime() + ARM_RETRY_DELAY_MS; - if (lastSendFailed && !bleManager.isConnected(address)) { - return AuthResult.LINK_DROPPED; - } - } - if (now >= deadline) { - break; - } - } - - if (latch.await(POLL_MS, TimeUnit.MILLISECONDS)) { - emitLog("security auth complete: " + label + " lens (" + address + ")"); - return AuthResult.SUCCESS; - } - if (!bleManager.isConnected(address)) { - emitLog("security auth: " + label + " lens disconnected while waiting" - + (bond == BluetoothDevice.BOND_BONDING ? " (Android was still pairing)" : "")); - return AuthResult.LINK_DROPPED; - } - } - if (cancelled) { - return AuthResult.UNCONFIRMED; - } - emitLog("security auth unconfirmed: " + label + " lens (" + address + "), Android bond state " - + bondStateName(bleManager.getBondState(address))); - return AuthResult.UNCONFIRMED; - } finally { - synchronized (lock) { - authLatch = null; - authMagics.clear(); - } - } - } - - private boolean sendAuthRequest(String address) { - int magic = allocMagic(); - int seq; - synchronized (lock) { - authMagics.add(magic); - seq = nextSeq++ & 0xff; - } - byte[] payload = BleProtocol.buildAuthenticationRequest(magic); - emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d", - address, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, magic, seq, payload.length)); - List frames = BleProtocol.framePb(payload, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, seq); - boolean written; - try { - written = bleManager.writeFrames( - address, BleProtocol.WRITE_CHAR_UUID, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS); - } catch (IllegalStateException e) { - // "Not connected" — the link went away underneath us. - written = false; - } - if (!written) { - emitLog("tx write FAILED sid=0x80 (" + address + ")"); - } - return written; - } - - /** Block while Android reports this arm as BOND_BONDING (pairing dialog up / SMP in flight). */ - private void waitForBondToSettle(String address, String label) throws InterruptedException { - long cap = SystemClock.elapsedRealtime() + PAIRING_WAIT_CAP_MS; - boolean logged = false; - while (!cancelled && bleManager.getBondState(address) == BluetoothDevice.BOND_BONDING - && SystemClock.elapsedRealtime() < cap) { - if (!logged) { - emitLog("waiting for Android to finish pairing with the " + label + " lens before reconnecting"); - logged = true; - } - Thread.sleep(POLL_MS); - } - } - - private static String bondStateName(int state) { - switch (state) { - case BluetoothDevice.BOND_NONE: - return "none"; - case BluetoothDevice.BOND_BONDING: - return "bonding"; - case BluetoothDevice.BOND_BONDED: - return "bonded"; - default: - return "unknown"; - } - } - - /** - * Prelude + settings read on an already connected/authenticated lens. - * Returns the settings ack protobuf, an unsolicited settings push that - * carried firmware versions, or null when the lens never answered the read. - * Throws on prelude failure; the caller wraps the fallback lens's attempt - * so its failure cannot mask the primary lens's outcome. - */ - private byte[] queryArm(String address, String label, boolean authenticated) throws InterruptedException { - if (cancelled) { - return null; - } - - emitState("querying", label); - // Session prelude, then a settings/device-info read (both arms' - // versions and the firmware-extension string ride back in one response). - if (writeAndAwaitAck(address, BleProtocol.PRELUDE_ACK_SID, BleProtocol.FLAG_REQUEST, - BleProtocol.PRELUDE_ACK_MAGIC, BleProtocol.PRELUDE_F5872_PAYLOAD, - ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) { - throw new IllegalStateException("session prelude not acked (" + label + " lens)" - + (authenticated ? "" : "; authentication did not complete —" - + " if Android shows a Bluetooth pairing request, accept it and try again")); - } - - // Two attempts: the first read straight after a fresh pairing has been - // seen to go unanswered while a later one succeeds. - for (int attempt = 0; attempt < 2 && !cancelled; attempt++) { - int magic = allocMagic(); - byte[] ack = writeAndAwaitAck(address, BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST, - magic, BleProtocol.buildSettingsQuery(magic), QUERY_TIMEOUT_MS); - if (ack != null) { - return ack; - } - // A push with the firmware versions on the device's own magic is - // as good as the ack we asked for. - byte[] pushed = unsolicitedSettingsPb; - if (pushed != null) { - emitLog("using unsolicited settings push instead of the read ack (" + label + " lens)"); - return pushed; - } - emitLog("settings query attempt " + (attempt + 1) + " unanswered (" + label + " lens)"); - } - return null; - } - - private void connectArm(String address) { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw new IllegalStateException("connect failed"); - } - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH); - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS); - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw new IllegalStateException("service discovery failed"); - } - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - throw new IllegalStateException("could not subscribe to notifications"); - } - } - - private byte[] writeAndAwaitAck(String address, int sid, int flag, int magic, byte[] payload, int timeoutMs) - throws InterruptedException { - CountDownLatch latch = new CountDownLatch(1); - synchronized (lock) { - awaitSid = sid; - awaitMagic = magic; - awaitPb = null; - awaitLatch = latch; - } - int seq; - synchronized (lock) { - seq = nextSeq++ & 0xff; - } - emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d", - address, sid, flag, magic, seq, payload.length)); - List frames = BleProtocol.framePb(payload, sid, flag, seq); - boolean written = bleManager.writeFrames( - address, BleProtocol.WRITE_CHAR_UUID, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS); - if (!written) { - emitLog("tx write FAILED sid=0x" + Integer.toHexString(sid)); - synchronized (lock) { - awaitLatch = null; - } - return null; - } - boolean acked = latch.await(timeoutMs, TimeUnit.MILLISECONDS); - synchronized (lock) { - awaitLatch = null; - return acked ? awaitPb : null; - } - } - - @Override - public void onNotification(String address, String characteristicUuid, byte[] data) { - if (!BleProtocol.NOTIFY_CHAR_UUID.equalsIgnoreCase(characteristicUuid)) { - return; - } - // One notification value can carry several envelope frames back to - // back; reading only the first would silently drop the rest. - List frames = BleProtocol.splitFrames(data); - if (frames.size() > 1) { - emitLog("rx " + address + " value carries " + frames.size() + " frames (raw " + data.length + " bytes)"); - } - for (byte[] buf : frames) { - handleFrame(address, buf, data.length); - } - } - - private void handleFrame(String address, byte[] buf, int rawValueLength) { - BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(buf); - if (!frame.ok) { - emitLog("rx " + address + " unparseable frame len=" + buf.length + " (raw value " + rawValueLength + ")" - + " head=" + FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(buf, Math.min(16, buf.length)))); - return; - } - // Log every control frame while diagnosing 2.2.9: sid/flag/type/magic - // plus a payload prefix is enough to reconstruct what the lens said. - int declared = buf.length > 3 ? buf[3] & 0xff : 0; - String truncated = buf.length < 8 + declared ? " TRUNCATED(declared=" + declared + ")" : ""; - emitLog(String.format("rx %s sid=0x%02x flag=0x%02x type=%d magic=%d frag=%d/%d len=%d%s pb=%s", - address, frame.sid, frame.flag, frame.msgType, frame.msgSeq, - buf.length > 5 ? buf[5] & 0xff : 0, buf.length > 4 ? buf[4] & 0xff : 0, frame.pb.length, truncated, - FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(frame.pb, Math.min(48, frame.pb.length))))); - if (frame.sid == BleProtocol.SID_UI_SETTING - && BleProtocol.parseSettingsFirmwareInfo(frame.pb) != null) { - // Any settings frame carrying firmware versions answers the probe's - // question, whether or not it matches the magic we asked with. - unsolicitedSettingsPb = frame.pb; - } - if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { - // Async event, not an ack. This includes the lens's own periodic - // sid-0x80 notifies (device-chosen magic, non-empty result). - return; - } - if (frame.sid == BleProtocol.SID_SECURITY_AUTH) { - boolean success = false; - boolean ours = false; - synchronized (lock) { - if (authLatch != null) { - ours = authMagics.contains(frame.msgSeq); - for (int magic : authMagics) { - if (BleProtocol.isAuthenticationSuccess(frame.pb, magic)) { - success = true; - authLatch.countDown(); - break; - } - } - } - } - if (ours && !success) { - // Expected before the link is encrypted: the firmware answers - // the request straight away with a non-success result and - // sends the real success once pairing/encryption completes. - emitLog("auth reply for magic " + frame.msgSeq + " is not the success result; still waiting"); - } - return; - } - synchronized (lock) { - if (awaitLatch != null && frame.sid == awaitSid && frame.msgSeq == awaitMagic) { - awaitPb = frame.pb; - awaitLatch.countDown(); - } - } - } - - @Override - public void onConnectionStateChange(String address, boolean connected) { - if (!connected) { - Log.i(TAG, "disconnected: " + address); - } - } - - private int allocMagic() { - synchronized (lock) { - int magic = nextMagic; - nextMagic = nextMagic >= 255 ? 100 : nextMagic + 1; - return magic; - } - } - - private void emitLog(String line) { - Log.i(TAG, line); - mainHandler.post(() -> { - FaceclawDeviceInfoProbeListener current = listener; - if (current != null) { - current.onLog(line); - } - }); - } - - private void emitState(String state, String detail) { - final String safeDetail = detail == null ? "" : detail; - mainHandler.post(() -> { - FaceclawDeviceInfoProbeListener current = listener; - if (current != null) { - current.onState(state, safeDetail); - } - }); - } - - private void emitResult(String left, String right, String extension) { - mainHandler.post(() -> { - FaceclawDeviceInfoProbeListener current = listener; - if (current != null) { - current.onResult(left, right, extension); - } - }); - } - - private void emitError(String message) { - final String safeMessage = message == null ? "" : message; - mainHandler.post(() -> { - FaceclawDeviceInfoProbeListener current = listener; - if (current != null) { - current.onError(safeMessage); - } - }); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt new file mode 100644 index 00000000..9d734da2 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt @@ -0,0 +1,629 @@ +package com.faceclaw.app + +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothGatt +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.util.Log + +import java.util.HashSet +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit + +/** + * Connects to the glasses (stock-firmware compatible), reads the device-info / + * settings response, and reports the firmware versions plus the firmware- + * extension string (empty on stock firmware). Used by onboarding to decide whether to + * flash. Reuses FaceclawBleManager + BleProtocol; owns its own connection and + * runs on a single worker thread. Shows nothing on the lens. + */ +class FaceclawDeviceInfoProbe(context: Context, rightAddress: String?, leftAddress: String?) : FaceclawBleListener { + companion object { + private const val TAG = "FaceclawDeviceInfo" + private const val QUERY_TIMEOUT_MS = 4_000 + /** Connect + auth attempts per arm; a link that drops mid-pairing is retried once the bond settles. */ + private const val ARM_ATTEMPTS = 3 + private const val ARM_RETRY_DELAY_MS = 1_000 + /** + * Upper bound on waiting for the auth success while Android reports the arm + * as BOND_BONDING — i.e. an OS pairing dialog may be sitting there waiting + * for the user, which can take a lot longer than the normal 30 s window. + */ + private const val PAIRING_WAIT_CAP_MS = 90_000 + /** After a fresh bond, how long the firmware gets to notify success on its own before the request is re-sent. */ + private const val POST_BOND_GRACE_MS = 2_000 + private const val POLL_MS = 250 + + private fun bondStateName(state: Int): String { + return when (state) { + BluetoothDevice.BOND_NONE -> "none" + BluetoothDevice.BOND_BONDING -> "bonding" + BluetoothDevice.BOND_BONDED -> "bonded" + else -> "unknown" + } + } + } + + private val context: Context + private val rightAddress: String + private val leftAddress: String + private val bleManager: FaceclawBleManager + private val mainHandler = Handler(Looper.getMainLooper()) + + private val lock = Any() + private var nextSeq = 0x40 + private var nextMagic = 100 + + private var awaitSid = -1 + private var awaitMagic = -1 + private var awaitPb: ByteArray? = null + private var awaitLatch: CountDownLatch? = null + + /** + * Security-auth wait, kept separate from the generic ack wait: only the + * firmware's SUCCESS result (empty result message) may satisfy it. The + * firmware answers the request as soon as it arrives, but with a + * non-success result until the link is encrypted; accepting that first + * reply as "the ack" is what let the probe move on to the other arm while + * Android's pairing dialog for this one was still up. + */ + private val authMagics: MutableSet = HashSet() + private var authLatch: CountDownLatch? = null + + /** + * A sid-0x09 frame that carried firmware versions without matching the + * awaited magic — some firmware pushes the settings snapshot on a magic it + * picked itself instead of (or in addition to) acking the read. + */ + @Volatile + private var unsolicitedSettingsPb: ByteArray? = null + + @Volatile + private var listener: FaceclawDeviceInfoProbeListener? = null + @Volatile + private var worker: Thread? = null + @Volatile + private var cancelled = false + + init { + this.context = context.applicationContext + this.rightAddress = rightAddress ?: "" + this.leftAddress = leftAddress ?: "" + this.bleManager = FaceclawBleManager(this.context) + this.bleManager.setListener(this) + } + + fun setListener(listener: FaceclawDeviceInfoProbeListener?) { + this.listener = listener + } + + fun start() { + synchronized(lock) { + if (worker != null) { + return + } + val w = Thread({ run() }, "faceclaw-device-info") + worker = w + w.start() + } + } + + fun cancel() { + cancelled = true + val w = worker + if (w != null) { + w.interrupt() + } + } + + fun close() { + cancel() + try { + bleManager.close() + } catch (ignored: Exception) { + } + } + + private fun run() { + try { + if (rightAddress.trim().isEmpty()) { + emitError("No right-arm address configured.") + return + } + + val haveLeft = !leftAddress.trim().isEmpty() && !leftAddress.equals(rightAddress, ignoreCase = true) + + // Bring up and authenticate BOTH arms before asking for versions. + // Each arm is its own peripheral with its own bond, so on a fresh + // phone each raises its own pairing prompt; completing both here + // means the flash step (and the app proper) find both bonds in + // place. Strictly one arm at a time: Android pairs with one device + // at a time, and a second arm connected while the first was still + // pairing has been seen to drop within a second and never pair + // (2026-09-11 logcat). + var rightAuthenticated = bringUpArm(rightAddress, "right") + var leftAuthenticated = false + if (haveLeft && !cancelled) { + leftAuthenticated = bringUpArm(leftAddress, "left") + } + if (cancelled) { + emitError("Cancelled.") + return + } + if (!bleManager.isConnected(rightAddress)) { + // The right lens may have dropped while the left one paired; + // it is bonded by now, so this comes back quickly. + emitLog("right lens disconnected while the left lens was set up; reconnecting") + rightAuthenticated = bringUpArm(rightAddress, "right") + if (cancelled) { + emitError("Cancelled.") + return + } + } + + var ack: ByteArray? = null + var rightFailure: String? = null + try { + ack = queryArm(rightAddress, "right", rightAuthenticated) + } catch (e: IllegalStateException) { + rightFailure = if (e.message == null) e.toString() else e.message + emitLog("right-lens query failed: $rightFailure") + } + // The right lens is the documented control endpoint, but a silent + // right lens has been observed on stock 2.2.9 even after a + // successful security auth — run the same probe against the left + // lens rather than giving up, and log which lens answered. + if (ack == null && !cancelled && haveLeft) { + emitLog("right lens did not answer the settings query; probing the left lens") + try { + ack = queryArm(leftAddress, "left", leftAuthenticated) + } catch (e: Exception) { + emitLog("left-lens probe failed: " + (if (e.message == null) e.toString() else e.message)) + } + } + if (cancelled) { + emitError("Cancelled.") + return + } + if (ack == null) { + throw IllegalStateException(if (rightFailure != null) + rightFailure + else "no response to the device-info query on either lens — check `adb logcat -s " + + TAG + "` for the frame trace") + } + + val info: BleProtocol.FirmwareInfo? = BleProtocol.parseSettingsFirmwareInfo(ack) + val left = if (info == null) "" else info.leftVersion + val right = if (info == null) "" else info.rightVersion + val extension = if (info == null) "" else info.extension + emitLog("device-info: L=$left R=$right ext=[$extension]") + emitResult(left, right, extension) + } catch (e: Exception) { + val message = if (cancelled) "Cancelled." else (if (e.message == null) e.toString() else e.message) + emitError(message) + } finally { + try { + bleManager.close() + } catch (ignored: Exception) { + } + } + } + + /** + * Connect to one arm and complete its security-auth exchange, retrying + * when the link drops mid-pairing. Returns whether the auth success was + * seen (false = connected but unconfirmed, tolerated because the custom + * firmware's response to the exchange is not yet hardware-verified); + * throws when the arm cannot be brought up at all. + */ + @Throws(InterruptedException::class) + private fun bringUpArm(address: String, label: String): Boolean { + var lastFailure: String? = null + var attempt = 1 + while (attempt <= ARM_ATTEMPTS && !cancelled) { + if (attempt > 1) { + // A link Android dropped while it was still pairing comes back + // once the bond settles; reconnecting sooner just fails again. + waitForBondToSettle(address, label) + if (cancelled) { + break + } + emitLog("retrying the $label lens (attempt $attempt/$ARM_ATTEMPTS): $lastFailure") + Thread.sleep(ARM_RETRY_DELAY_MS.toLong()) + } + emitState("connecting", label) + try { + connectArm(address) + } catch (e: IllegalStateException) { + lastFailure = if (e.message == null) e.toString() else e.message + emitLog("$label lens: $lastFailure") + attempt++ + continue + } + if (cancelled) { + break + } + + // Firmware 2.2.9 answers no queries until the security-auth + // exchange completes over an encrypted link; on a phone with no + // existing bond this is also what triggers SMP pairing (and its OS + // prompt), so it must come before the prelude and query. + emitState("authenticating", label) + val result = authenticate(address, label) + if (result == AuthResult.SUCCESS) { + return true + } + if (result == AuthResult.UNCONFIRMED) { + return false + } + lastFailure = "link dropped during authentication" + attempt++ + } + if (cancelled) { + return false + } + throw IllegalStateException("could not connect to the $label lens ($address): " + + lastFailure + " — if Android showed a Bluetooth pairing request, accept it and try again") + } + + private enum class AuthResult { SUCCESS, UNCONFIRMED, LINK_DROPPED } + + /** + * Send the sid-0x80 authentication request and wait for the firmware's + * SUCCESS notification, which only arrives once the link is encrypted. + * On an unbonded phone that means waiting through Android's pairing flow + * (BOND_BONDING, possibly with a dialog up), so the wait is extended while + * the OS reports pairing in progress and the request is re-sent once + * after a fresh bond in case the pre-pairing write was dropped. Bond + * state is polled rather than awaited via broadcast; 250 ms granularity + * is plenty here. + */ + @Throws(InterruptedException::class) + private fun authenticate(address: String, label: String): AuthResult { + val start = SystemClock.elapsedRealtime() + var deadline = start + ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS + val hardDeadline = start + PAIRING_WAIT_CAP_MS + val latch = CountDownLatch(1) + synchronized(lock) { + authMagics.clear() + authLatch = latch + } + val initialBond = bleManager.getBondState(address) + emitLog("security auth: $label lens, Android bond state " + bondStateName(initialBond)) + try { + var sends = 0 + var lastSendFailed = false + var nextSendAt = start + var bondedAt = -1L + var resentAfterBond = false + var loggedBonding = false + while (!cancelled) { + val now = SystemClock.elapsedRealtime() + val bond = bleManager.getBondState(address) + + if (bond == BluetoothDevice.BOND_BONDING) { + // OS pairing in progress — the firmware will answer once the + // link is encrypted. Don't write, don't give up, don't move + // on to the other arm. + if (!loggedBonding) { + emitLog("Android is pairing with the $label lens; waiting for the user to accept") + loggedBonding = true + } + if (now >= hardDeadline) { + break + } + } else { + if (bond == BluetoothDevice.BOND_BONDED && initialBond != BluetoothDevice.BOND_BONDED + && bondedAt < 0) { + bondedAt = now + emitLog("Android bond established with the $label lens; waiting for the auth success") + deadline = Math.max(deadline, now + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS) + } + val wantSend = sends == 0 + || (lastSendFailed && sends < 3 && now >= nextSendAt) + || (bondedAt >= 0 && !resentAfterBond && now - bondedAt >= POST_BOND_GRACE_MS) + if (wantSend) { + if (bondedAt >= 0) { + resentAfterBond = true + if (sends > 0) { + emitLog("re-sending the auth request after pairing ($label lens)") + } + } + lastSendFailed = !sendAuthRequest(address) + sends++ + nextSendAt = SystemClock.elapsedRealtime() + ARM_RETRY_DELAY_MS + if (lastSendFailed && !bleManager.isConnected(address)) { + return AuthResult.LINK_DROPPED + } + } + if (now >= deadline) { + break + } + } + + if (latch.await(POLL_MS.toLong(), TimeUnit.MILLISECONDS)) { + emitLog("security auth complete: $label lens ($address)") + return AuthResult.SUCCESS + } + if (!bleManager.isConnected(address)) { + emitLog("security auth: $label lens disconnected while waiting" + + (if (bond == BluetoothDevice.BOND_BONDING) " (Android was still pairing)" else "")) + return AuthResult.LINK_DROPPED + } + } + if (cancelled) { + return AuthResult.UNCONFIRMED + } + emitLog("security auth unconfirmed: $label lens ($address), Android bond state " + + bondStateName(bleManager.getBondState(address))) + return AuthResult.UNCONFIRMED + } finally { + synchronized(lock) { + authLatch = null + authMagics.clear() + } + } + } + + private fun sendAuthRequest(address: String): Boolean { + val magic = allocMagic() + val seq: Int + synchronized(lock) { + authMagics.add(magic) + seq = nextSeq++ and 0xff + } + val payload = BleProtocol.buildAuthenticationRequest(magic) + emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d", + address, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, magic, seq, payload.size)) + val frames = BleProtocol.framePb(payload, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, seq) + var written: Boolean + try { + written = bleManager.writeFrames( + address, BleProtocol.WRITE_CHAR_UUID, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS) + } catch (e: IllegalStateException) { + // "Not connected" — the link went away underneath us. + written = false + } + if (!written) { + emitLog("tx write FAILED sid=0x80 ($address)") + } + return written + } + + /** Block while Android reports this arm as BOND_BONDING (pairing dialog up / SMP in flight). */ + @Throws(InterruptedException::class) + private fun waitForBondToSettle(address: String, label: String) { + val cap = SystemClock.elapsedRealtime() + PAIRING_WAIT_CAP_MS + var logged = false + while (!cancelled && bleManager.getBondState(address) == BluetoothDevice.BOND_BONDING + && SystemClock.elapsedRealtime() < cap) { + if (!logged) { + emitLog("waiting for Android to finish pairing with the $label lens before reconnecting") + logged = true + } + Thread.sleep(POLL_MS.toLong()) + } + } + + /** + * Prelude + settings read on an already connected/authenticated lens. + * Returns the settings ack protobuf, an unsolicited settings push that + * carried firmware versions, or null when the lens never answered the read. + * Throws on prelude failure; the caller wraps the fallback lens's attempt + * so its failure cannot mask the primary lens's outcome. + */ + @Throws(InterruptedException::class) + private fun queryArm(address: String, label: String, authenticated: Boolean): ByteArray? { + if (cancelled) { + return null + } + + emitState("querying", label) + // Session prelude, then a settings/device-info read (both arms' + // versions and the firmware-extension string ride back in one response). + if (writeAndAwaitAck(address, BleProtocol.PRELUDE_ACK_SID, BleProtocol.FLAG_REQUEST, + BleProtocol.PRELUDE_ACK_MAGIC, BleProtocol.PRELUDE_F5872_PAYLOAD, + ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) { + throw IllegalStateException("session prelude not acked ($label lens)" + + (if (authenticated) "" else "; authentication did not complete —" + + " if Android shows a Bluetooth pairing request, accept it and try again")) + } + + // Two attempts: the first read straight after a fresh pairing has been + // seen to go unanswered while a later one succeeds. + var attempt = 0 + while (attempt < 2 && !cancelled) { + val magic = allocMagic() + val ack = writeAndAwaitAck(address, BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST, + magic, BleProtocol.buildSettingsQuery(magic), QUERY_TIMEOUT_MS) + if (ack != null) { + return ack + } + // A push with the firmware versions on the device's own magic is + // as good as the ack we asked for. + val pushed = unsolicitedSettingsPb + if (pushed != null) { + emitLog("using unsolicited settings push instead of the read ack ($label lens)") + return pushed + } + emitLog("settings query attempt " + (attempt + 1) + " unanswered (" + label + " lens)") + attempt++ + } + return null + } + + private fun connectArm(address: String) { + if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { + throw IllegalStateException("connect failed") + } + bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) + bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) + if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { + throw IllegalStateException("service discovery failed") + } + if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { + throw IllegalStateException("could not subscribe to notifications") + } + } + + @Throws(InterruptedException::class) + private fun writeAndAwaitAck(address: String, sid: Int, flag: Int, magic: Int, payload: ByteArray, timeoutMs: Int): ByteArray? { + val latch = CountDownLatch(1) + synchronized(lock) { + awaitSid = sid + awaitMagic = magic + awaitPb = null + awaitLatch = latch + } + val seq: Int + synchronized(lock) { + seq = nextSeq++ and 0xff + } + emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d", + address, sid, flag, magic, seq, payload.size)) + val frames = BleProtocol.framePb(payload, sid, flag, seq) + val written = bleManager.writeFrames( + address, BleProtocol.WRITE_CHAR_UUID, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS) + if (!written) { + emitLog("tx write FAILED sid=0x" + Integer.toHexString(sid)) + synchronized(lock) { + awaitLatch = null + } + return null + } + val acked = latch.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS) + synchronized(lock) { + awaitLatch = null + return if (acked) awaitPb else null + } + } + + override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { + if (!BleProtocol.NOTIFY_CHAR_UUID.equals(characteristicUuid, ignoreCase = true)) { + return + } + // One notification value can carry several envelope frames back to + // back; reading only the first would silently drop the rest. + val frames = BleProtocol.splitFrames(data) + if (frames.size > 1) { + emitLog("rx " + address + " value carries " + frames.size + " frames (raw " + data!!.size + " bytes)") + } + for (buf in frames) { + handleFrame(address, buf, data!!.size) + } + } + + private fun handleFrame(address: String?, buf: ByteArray, rawValueLength: Int) { + val frame = BleProtocol.parseFrame(buf) + if (!frame.ok) { + emitLog("rx " + address + " unparseable frame len=" + buf.size + " (raw value " + rawValueLength + ")" + + " head=" + FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(buf, Math.min(16, buf.size)))) + return + } + // Log every control frame while diagnosing 2.2.9: sid/flag/type/magic + // plus a payload prefix is enough to reconstruct what the lens said. + val declared = if (buf.size > 3) buf[3].toInt() and 0xff else 0 + val truncated = if (buf.size < 8 + declared) " TRUNCATED(declared=$declared)" else "" + emitLog(String.format("rx %s sid=0x%02x flag=0x%02x type=%d magic=%d frag=%d/%d len=%d%s pb=%s", + address, frame.sid, frame.flag, frame.msgType, frame.msgSeq, + if (buf.size > 5) buf[5].toInt() and 0xff else 0, if (buf.size > 4) buf[4].toInt() and 0xff else 0, frame.pb.size, truncated, + FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(frame.pb, Math.min(48, frame.pb.size))))) + if (frame.sid == BleProtocol.SID_UI_SETTING + && BleProtocol.parseSettingsFirmwareInfo(frame.pb) != null) { + // Any settings frame carrying firmware versions answers the probe's + // question, whether or not it matches the magic we asked with. + unsolicitedSettingsPb = frame.pb + } + if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { + // Async event, not an ack. This includes the lens's own periodic + // sid-0x80 notifies (device-chosen magic, non-empty result). + return + } + if (frame.sid == BleProtocol.SID_SECURITY_AUTH) { + var success = false + var ours = false + synchronized(lock) { + val currentLatch = authLatch + if (currentLatch != null) { + ours = authMagics.contains(frame.msgSeq) + for (magic in authMagics) { + if (BleProtocol.isAuthenticationSuccess(frame.pb, magic)) { + success = true + currentLatch.countDown() + break + } + } + } + } + if (ours && !success) { + // Expected before the link is encrypted: the firmware answers + // the request straight away with a non-success result and + // sends the real success once pairing/encryption completes. + emitLog("auth reply for magic " + frame.msgSeq + " is not the success result; still waiting") + } + return + } + synchronized(lock) { + val currentLatch = awaitLatch + if (currentLatch != null && frame.sid == awaitSid && frame.msgSeq == awaitMagic) { + awaitPb = frame.pb + currentLatch.countDown() + } + } + } + + override fun onConnectionStateChange(address: String?, connected: Boolean) { + if (!connected) { + Log.i(TAG, "disconnected: $address") + } + } + + private fun allocMagic(): Int { + synchronized(lock) { + val magic = nextMagic + nextMagic = if (nextMagic >= 255) 100 else nextMagic + 1 + return magic + } + } + + private fun emitLog(line: String) { + Log.i(TAG, line) + mainHandler.post { + val current = listener + if (current != null) { + current.onLog(line) + } + } + } + + private fun emitState(state: String, detail: String?) { + val safeDetail = detail ?: "" + mainHandler.post { + val current = listener + if (current != null) { + current.onState(state, safeDetail) + } + } + } + + private fun emitResult(left: String, right: String, extension: String) { + mainHandler.post { + val current = listener + if (current != null) { + current.onResult(left, right, extension) + } + } + } + + private fun emitError(message: String?) { + val safeMessage = message ?: "" + mainHandler.post { + val current = listener + if (current != null) { + current.onError(safeMessage) + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.java deleted file mode 100644 index ea9352aa..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.java +++ /dev/null @@ -1,262 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import com.k2fsa.sherpa.onnx.FastClusteringConfig; -import com.k2fsa.sherpa.onnx.OfflineSpeakerDiarization; -import com.k2fsa.sherpa.onnx.OfflineSpeakerDiarizationConfig; -import com.k2fsa.sherpa.onnx.OfflineSpeakerDiarizationSegment; -import com.k2fsa.sherpa.onnx.OfflineSpeakerSegmentationModelConfig; -import com.k2fsa.sherpa.onnx.OfflineSpeakerSegmentationPyannoteModelConfig; -import com.k2fsa.sherpa.onnx.SpeakerEmbeddingExtractorConfig; - -import org.json.JSONArray; -import org.json.JSONObject; - -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.ByteBuffer; - -/** - * Offline re-diarization of a stored conversation recording (16-bit mono - * WAV): pyannote segmentation plus the shared speaker-embedding model with - * clustering, via sherpa-onnx. Runs on its own thread; results are handed to - * TS as JSON turns for reconciliation against the transcript segments. - */ -public class FaceclawDiarizer { - private static final String TAG = "FaceclawDiarizer"; - - public interface Listener { - /** progress in [0, 1]. */ - void onProgress(double progress); - - /** turns: [{startMs, endMs, cluster}], sorted by start time. */ - void onDone(String turnsJson); - - void onError(String message); - } - - private final String segmentationModelPath; - private final String embeddingModelPath; - private final String wavPath; - private final int numClusters; - private final float threshold; - private final Listener listener; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private volatile boolean cancelled; - - public FaceclawDiarizer( - String segmentationModelPath, - String embeddingModelPath, - String wavPath, - int numClusters, - float threshold, - Listener listener) { - this.segmentationModelPath = segmentationModelPath; - this.embeddingModelPath = embeddingModelPath; - this.wavPath = wavPath; - this.numClusters = numClusters; - this.threshold = threshold <= 0 ? 0.5f : threshold; - this.listener = listener; - } - - public void start() { - Thread thread = new Thread(this::run, "FaceclawDiarizer"); - thread.setPriority(Thread.MIN_PRIORITY); - thread.start(); - } - - public void cancel() { - cancelled = true; - } - - private void run() { - OfflineSpeakerDiarization diarization = null; - try { - float[] samples = wavPath.endsWith(".wav") - ? readWavMono16(wavPath) - : decodeCompressedMono(wavPath); - OfflineSpeakerDiarizationConfig config = OfflineSpeakerDiarizationConfig.builder() - .setSegmentation(OfflineSpeakerSegmentationModelConfig.builder() - .setPyannote(OfflineSpeakerSegmentationPyannoteModelConfig.builder() - .setModel(segmentationModelPath) - .build()) - .setNumThreads(1) - .build()) - .setEmbedding(SpeakerEmbeddingExtractorConfig.builder() - .setModel(embeddingModelPath) - .setNumThreads(1) - .build()) - .setClustering(FastClusteringConfig.builder() - .setNumClusters(numClusters > 0 ? numClusters : -1) - .setThreshold(threshold) - .build()) - .setMinDurationOn(0.3f) - .setMinDurationOff(0.5f) - .build(); - diarization = new OfflineSpeakerDiarization(config); - OfflineSpeakerDiarizationSegment[] segments = diarization.processWithCallback( - samples, - (numProcessedChunks, numTotalChunks, arg) -> { - emitProgress(numTotalChunks <= 0 ? 0 - : (double) numProcessedChunks / numTotalChunks); - return cancelled ? 1 : 0; - }); - JSONArray turns = new JSONArray(); - if (segments != null) { - for (OfflineSpeakerDiarizationSegment segment : segments) { - JSONObject turn = new JSONObject(); - turn.put("startMs", Math.round(segment.getStart() * 1000)); - turn.put("endMs", Math.round(segment.getEnd() * 1000)); - turn.put("cluster", segment.getSpeaker()); - turns.put(turn); - } - } - String result = turns.toString(); - mainHandler.post(() -> listener.onDone(result)); - } catch (Throwable t) { - Log.w(TAG, "diarization failed for " + wavPath, t); - String message = t.getMessage() == null ? t.toString() : t.getMessage(); - mainHandler.post(() -> listener.onError(message)); - } finally { - if (diarization != null) { - diarization.release(); - } - } - } - - private void emitProgress(double progress) { - mainHandler.post(() -> listener.onProgress(Math.max(0, Math.min(1, progress)))); - } - - /** - * Decode a compressed recording (M4A/AAC from the transcode sweep) into - * [-1, 1] floats via MediaExtractor + MediaCodec. Recordings are written - * as 16 kHz mono, so no resampling is needed. - */ - private static float[] decodeCompressedMono(String path) throws IOException { - android.media.MediaExtractor extractor = new android.media.MediaExtractor(); - android.media.MediaCodec codec = null; - java.io.ByteArrayOutputStream pcm = new java.io.ByteArrayOutputStream(); - try { - extractor.setDataSource(path); - int trackIndex = -1; - android.media.MediaFormat format = null; - for (int i = 0; i < extractor.getTrackCount(); i++) { - android.media.MediaFormat candidate = extractor.getTrackFormat(i); - String mime = candidate.getString(android.media.MediaFormat.KEY_MIME); - if (mime != null && mime.startsWith("audio/")) { - trackIndex = i; - format = candidate; - break; - } - } - if (trackIndex < 0 || format == null) { - throw new IOException("no audio track in " + path); - } - extractor.selectTrack(trackIndex); - codec = android.media.MediaCodec.createDecoderByType( - format.getString(android.media.MediaFormat.KEY_MIME)); - codec.configure(format, null, null, 0); - codec.start(); - android.media.MediaCodec.BufferInfo info = new android.media.MediaCodec.BufferInfo(); - boolean inputDone = false; - boolean outputDone = false; - while (!outputDone) { - if (!inputDone) { - int inIndex = codec.dequeueInputBuffer(10_000); - if (inIndex >= 0) { - ByteBuffer inBuf = codec.getInputBuffer(inIndex); - int size = extractor.readSampleData(inBuf, 0); - if (size < 0) { - codec.queueInputBuffer(inIndex, 0, 0, 0, - android.media.MediaCodec.BUFFER_FLAG_END_OF_STREAM); - inputDone = true; - } else { - codec.queueInputBuffer(inIndex, 0, size, extractor.getSampleTime(), 0); - extractor.advance(); - } - } - } - int outIndex = codec.dequeueOutputBuffer(info, 10_000); - if (outIndex >= 0) { - ByteBuffer outBuf = codec.getOutputBuffer(outIndex); - byte[] chunk = new byte[info.size]; - outBuf.position(info.offset); - outBuf.get(chunk); - pcm.write(chunk); - codec.releaseOutputBuffer(outIndex, false); - if ((info.flags & android.media.MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) { - outputDone = true; - } - } - } - } finally { - extractor.release(); - if (codec != null) { - try { - codec.stop(); - } catch (Throwable ignored) { - } - codec.release(); - } - } - byte[] bytes = pcm.toByteArray(); - int count = bytes.length / 2; - float[] samples = new float[count]; - for (int i = 0; i < count; i++) { - samples[i] = ((short) ((bytes[i * 2] & 0xff) | (bytes[i * 2 + 1] << 8))) / 32768.0f; - } - return samples; - } - - /** Load a 16-bit mono PCM WAV into [-1, 1] floats. */ - private static float[] readWavMono16(String path) throws IOException { - File file = new File(path); - long fileLength = file.length(); - try (DataInputStream in = new DataInputStream(new FileInputStream(file))) { - byte[] header = new byte[44]; - in.readFully(header); - if (header[0] != 'R' || header[1] != 'I' || header[8] != 'W') { - throw new IOException("not a WAV file"); - } - int channels = (header[22] & 0xff) | (header[23] << 8); - int bits = (header[34] & 0xff) | (header[35] << 8); - if (channels != 1 || bits != 16) { - throw new IOException("only 16-bit mono WAV is supported"); - } - long dataBytes = fileLength - 44; - int count = (int) Math.min(dataBytes / 2, Integer.MAX_VALUE); - float[] samples = new float[count]; - byte[] chunk = new byte[65536]; - int sampleIndex = 0; - int carried = 0; - byte carriedByte = 0; - int read; - while (sampleIndex < count && (read = in.read(chunk)) > 0) { - int offset = 0; - if (carried == 1) { - samples[sampleIndex++] = - ((short) ((carriedByte & 0xff) | (chunk[0] << 8))) / 32768.0f; - offset = 1; - carried = 0; - } - int pairs = (read - offset) / 2; - for (int i = 0; i < pairs && sampleIndex < count; i++) { - int base = offset + i * 2; - samples[sampleIndex++] = - ((short) ((chunk[base] & 0xff) | (chunk[base + 1] << 8))) / 32768.0f; - } - if (((read - offset) & 1) == 1) { - carried = 1; - carriedByte = chunk[read - 1]; - } - } - return samples; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt new file mode 100644 index 00000000..95cd7e98 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt @@ -0,0 +1,260 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.util.Log + +import com.k2fsa.sherpa.onnx.FastClusteringConfig +import com.k2fsa.sherpa.onnx.OfflineSpeakerDiarization +import com.k2fsa.sherpa.onnx.OfflineSpeakerDiarizationCallback +import com.k2fsa.sherpa.onnx.OfflineSpeakerDiarizationConfig +import com.k2fsa.sherpa.onnx.OfflineSpeakerDiarizationSegment +import com.k2fsa.sherpa.onnx.OfflineSpeakerSegmentationModelConfig +import com.k2fsa.sherpa.onnx.OfflineSpeakerSegmentationPyannoteModelConfig +import com.k2fsa.sherpa.onnx.SpeakerEmbeddingExtractorConfig + +import org.json.JSONArray +import org.json.JSONObject + +import java.io.DataInputStream +import java.io.File +import java.io.FileInputStream +import java.io.IOException +import java.nio.ByteBuffer + +/** + * Offline re-diarization of a stored conversation recording (16-bit mono + * WAV): pyannote segmentation plus the shared speaker-embedding model with + * clustering, via sherpa-onnx. Runs on its own thread; results are handed to + * TS as JSON turns for reconciliation against the transcript segments. + */ +class FaceclawDiarizer( + private val segmentationModelPath: String?, + private val embeddingModelPath: String?, + private val wavPath: String?, + private val numClusters: Int, + threshold: Float, + private val listener: Listener +) { + companion object { + private const val TAG = "FaceclawDiarizer" + + /** + * Decode a compressed recording (M4A/AAC from the transcode sweep) into + * [-1, 1] floats via MediaExtractor + MediaCodec. Recordings are written + * as 16 kHz mono, so no resampling is needed. + */ + @JvmStatic + @Throws(IOException::class) + private fun decodeCompressedMono(path: String?): FloatArray { + val extractor = android.media.MediaExtractor() + var codec: android.media.MediaCodec? = null + val pcm = java.io.ByteArrayOutputStream() + try { + extractor.setDataSource(path!!) + var trackIndex = -1 + var format: android.media.MediaFormat? = null + for (i in 0 until extractor.trackCount) { + val candidate = extractor.getTrackFormat(i) + val mime = candidate.getString(android.media.MediaFormat.KEY_MIME) + if (mime != null && mime.startsWith("audio/")) { + trackIndex = i + format = candidate + break + } + } + if (trackIndex < 0 || format == null) { + throw IOException("no audio track in $path") + } + extractor.selectTrack(trackIndex) + codec = android.media.MediaCodec.createDecoderByType( + format.getString(android.media.MediaFormat.KEY_MIME)!!) + codec.configure(format, null, null, 0) + codec.start() + val info = android.media.MediaCodec.BufferInfo() + var inputDone = false + var outputDone = false + while (!outputDone) { + if (!inputDone) { + val inIndex = codec.dequeueInputBuffer(10_000) + if (inIndex >= 0) { + val inBuf = codec.getInputBuffer(inIndex)!! + val size = extractor.readSampleData(inBuf, 0) + if (size < 0) { + codec.queueInputBuffer(inIndex, 0, 0, 0, + android.media.MediaCodec.BUFFER_FLAG_END_OF_STREAM) + inputDone = true + } else { + codec.queueInputBuffer(inIndex, 0, size, extractor.sampleTime, 0) + extractor.advance() + } + } + } + val outIndex = codec.dequeueOutputBuffer(info, 10_000) + if (outIndex >= 0) { + val outBuf = codec.getOutputBuffer(outIndex)!! + val chunk = ByteArray(info.size) + outBuf.position(info.offset) + outBuf.get(chunk) + pcm.write(chunk) + codec.releaseOutputBuffer(outIndex, false) + if ((info.flags and android.media.MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) { + outputDone = true + } + } + } + } finally { + extractor.release() + if (codec != null) { + try { + codec.stop() + } catch (ignored: Throwable) { + } + codec.release() + } + } + val bytes = pcm.toByteArray() + val count = bytes.size / 2 + val samples = FloatArray(count) + for (i in 0 until count) { + samples[i] = ((bytes[i * 2].toInt() and 0xff) or (bytes[i * 2 + 1].toInt() shl 8)).toShort() / 32768.0f + } + return samples + } + + /** Load a 16-bit mono PCM WAV into [-1, 1] floats. */ + @JvmStatic + @Throws(IOException::class) + private fun readWavMono16(path: String?): FloatArray { + val file = File(path) + val fileLength = file.length() + DataInputStream(FileInputStream(file)).use { `in` -> + val header = ByteArray(44) + `in`.readFully(header) + if (header[0] != 'R'.code.toByte() || header[1] != 'I'.code.toByte() || header[8] != 'W'.code.toByte()) { + throw IOException("not a WAV file") + } + val channels = (header[22].toInt() and 0xff) or (header[23].toInt() shl 8) + val bits = (header[34].toInt() and 0xff) or (header[35].toInt() shl 8) + if (channels != 1 || bits != 16) { + throw IOException("only 16-bit mono WAV is supported") + } + val dataBytes = fileLength - 44 + val count = Math.min(dataBytes / 2, Int.MAX_VALUE.toLong()).toInt() + val samples = FloatArray(count) + val chunk = ByteArray(65536) + var sampleIndex = 0 + var carried = 0 + var carriedByte: Byte = 0 + var read = 0 + while (sampleIndex < count && `in`.read(chunk).also { read = it } > 0) { + var offset = 0 + if (carried == 1) { + samples[sampleIndex++] = + ((carriedByte.toInt() and 0xff) or (chunk[0].toInt() shl 8)).toShort() / 32768.0f + offset = 1 + carried = 0 + } + val pairs = (read - offset) / 2 + var i = 0 + while (i < pairs && sampleIndex < count) { + val base = offset + i * 2 + samples[sampleIndex++] = + ((chunk[base].toInt() and 0xff) or (chunk[base + 1].toInt() shl 8)).toShort() / 32768.0f + i++ + } + if (((read - offset) and 1) == 1) { + carried = 1 + carriedByte = chunk[read - 1] + } + } + return samples + } + } + } + + interface Listener { + /** progress in [0, 1]. */ + fun onProgress(progress: Double) + + /** turns: [{startMs, endMs, cluster}], sorted by start time. */ + fun onDone(turnsJson: String?) + + fun onError(message: String?) + } + + private val threshold: Float = if (threshold <= 0) 0.5f else threshold + private val mainHandler = Handler(Looper.getMainLooper()) + @Volatile + private var cancelled = false + + fun start() { + val thread = Thread(Runnable { run() }, "FaceclawDiarizer") + thread.priority = Thread.MIN_PRIORITY + thread.start() + } + + fun cancel() { + cancelled = true + } + + private fun run() { + var diarization: OfflineSpeakerDiarization? = null + try { + val samples = if (wavPath!!.endsWith(".wav")) + readWavMono16(wavPath) + else + decodeCompressedMono(wavPath) + val config = OfflineSpeakerDiarizationConfig.builder() + .setSegmentation(OfflineSpeakerSegmentationModelConfig.builder() + .setPyannote(OfflineSpeakerSegmentationPyannoteModelConfig.builder() + .setModel(segmentationModelPath) + .build()) + .setNumThreads(1) + .build()) + .setEmbedding(SpeakerEmbeddingExtractorConfig.builder() + .setModel(embeddingModelPath) + .setNumThreads(1) + .build()) + .setClustering(FastClusteringConfig.builder() + .setNumClusters(if (numClusters > 0) numClusters else -1) + .setThreshold(threshold) + .build()) + .setMinDurationOn(0.3f) + .setMinDurationOff(0.5f) + .build() + diarization = OfflineSpeakerDiarization(config) + val segments: Array? = diarization.processWithCallback( + samples, + OfflineSpeakerDiarizationCallback { numProcessedChunks, numTotalChunks, _ -> + emitProgress(if (numTotalChunks <= 0) 0.0 + else numProcessedChunks.toDouble() / numTotalChunks) + if (cancelled) 1 else 0 + }) + val turns = JSONArray() + if (segments != null) { + for (segment in segments) { + val turn = JSONObject() + turn.put("startMs", Math.round(segment.start * 1000)) + turn.put("endMs", Math.round(segment.end * 1000)) + turn.put("cluster", segment.speaker) + turns.put(turn) + } + } + val result = turns.toString() + mainHandler.post { listener.onDone(result) } + } catch (t: Throwable) { + Log.w(TAG, "diarization failed for $wavPath", t) + val message = if (t.message == null) t.toString() else t.message + mainHandler.post { listener.onError(message) } + } finally { + if (diarization != null) { + diarization.release() + } + } + } + + private fun emitProgress(progress: Double) { + mainHandler.post { listener.onProgress(Math.max(0.0, Math.min(1.0, progress))) } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java deleted file mode 100644 index bb3e952d..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.faceclaw.app; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.net.Uri; -import android.provider.Settings; -import android.util.Log; - -public final class FaceclawEvenAppDetector { - private static final String TAG = "FaceclawEvenApp"; - - public static final String EVEN_PACKAGE_NAME = "com.even.sg"; - public static final String EVEN_NOTIFICATION_TITLE = "Even Notification Service"; - - private FaceclawEvenAppDetector() { - } - - public static boolean isNotificationAccessEnabled(Context context) { - if (context == null) { - return false; - } - Context appContext = context.getApplicationContext(); - ComponentName listenerComponent = new ComponentName(appContext, FaceclawMediaNotificationListenerService.class); - String enabledListeners = Settings.Secure.getString( - appContext.getContentResolver(), - "enabled_notification_listeners" - ); - if (enabledListeners == null || enabledListeners.isEmpty()) { - return false; - } - String fullName = listenerComponent.flattenToString(); - String shortName = listenerComponent.flattenToShortString(); - return enabledListeners.contains(fullName) - || enabledListeners.contains(shortName) - || enabledListeners.contains(appContext.getPackageName()); - } - - public static boolean isEvenNotificationActive(Context context) { - boolean hasAccess = isNotificationAccessEnabled(context); - if (!hasAccess) { - Log.i(TAG, "Can't check for Even Realities app notification, permission is not enabled"); - return false; - } - boolean hasNotfication = FaceclawMediaNotificationListenerService.hasActiveNotificationTitle(EVEN_NOTIFICATION_TITLE); - Log.i(TAG, "isEvenNotificationActive: " + hasNotfication); - return hasNotfication; - } - - /** Returns "opened", "not-installed", or "failed" for the phone UI. */ - public static String openEvenAppSettings(Context context) { - if (context == null) { - return "failed"; - } - Context appContext = context.getApplicationContext(); - try { - // Settings may launch successfully and then immediately close for a - // missing package, so check before starting the activity. - appContext.getPackageManager().getApplicationInfo(EVEN_PACKAGE_NAME, 0); - Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.setData(Uri.parse("package:" + EVEN_PACKAGE_NAME)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - appContext.startActivity(intent); - return "opened"; - } catch (PackageManager.NameNotFoundException e) { - return "not-installed"; - } catch (Exception t) { - Log.w(TAG, "failed to open Even app settings", t); - return "failed"; - } - } - - public static void openNotificationAccessSettings(Context context) { - if (context == null) { - return; - } - Context appContext = context.getApplicationContext(); - Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - try { - appContext.startActivity(intent); - } catch (Throwable t) { - Log.w(TAG, "failed to open notification access settings", t); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.kt new file mode 100644 index 00000000..4a0b64be --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.kt @@ -0,0 +1,90 @@ +package com.faceclaw.app + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.net.Uri +import android.provider.Settings +import android.util.Log + +class FaceclawEvenAppDetector private constructor() { + companion object { + private const val TAG = "FaceclawEvenApp" + + const val EVEN_PACKAGE_NAME = "com.even.sg" + const val EVEN_NOTIFICATION_TITLE = "Even Notification Service" + + @JvmStatic + fun isNotificationAccessEnabled(context: Context?): Boolean { + if (context == null) { + return false + } + val appContext = context.applicationContext + val listenerComponent = ComponentName(appContext, FaceclawMediaNotificationListenerService::class.java) + val enabledListeners = Settings.Secure.getString( + appContext.contentResolver, + "enabled_notification_listeners" + ) + if (enabledListeners == null || enabledListeners.isEmpty()) { + return false + } + val fullName = listenerComponent.flattenToString() + val shortName = listenerComponent.flattenToShortString() + return enabledListeners.contains(fullName) + || enabledListeners.contains(shortName) + || enabledListeners.contains(appContext.packageName) + } + + @JvmStatic + fun isEvenNotificationActive(context: Context?): Boolean { + val hasAccess = isNotificationAccessEnabled(context) + if (!hasAccess) { + Log.i(TAG, "Can't check for Even Realities app notification, permission is not enabled") + return false + } + val hasNotfication = FaceclawMediaNotificationListenerService.hasActiveNotificationTitle(EVEN_NOTIFICATION_TITLE) + Log.i(TAG, "isEvenNotificationActive: $hasNotfication") + return hasNotfication + } + + /** Returns "opened", "not-installed", or "failed" for the phone UI. */ + @JvmStatic + fun openEvenAppSettings(context: Context?): String { + if (context == null) { + return "failed" + } + val appContext = context.applicationContext + try { + // Settings may launch successfully and then immediately close for a + // missing package, so check before starting the activity. + appContext.packageManager.getApplicationInfo(EVEN_PACKAGE_NAME, 0) + val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) + intent.data = Uri.parse("package:$EVEN_PACKAGE_NAME") + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + appContext.startActivity(intent) + return "opened" + } catch (e: PackageManager.NameNotFoundException) { + return "not-installed" + } catch (t: Exception) { + Log.w(TAG, "failed to open Even app settings", t) + return "failed" + } + } + + @JvmStatic + fun openNotificationAccessSettings(context: Context?) { + if (context == null) { + return + } + val appContext = context.applicationContext + val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + try { + appContext.startActivity(intent) + } catch (t: Throwable) { + Log.w(TAG, "failed to open notification access settings", t) + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.java deleted file mode 100644 index 2f9c0e90..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.faceclaw.app; - -import android.util.Log; -import android.webkit.WebView; - -import androidx.webkit.WebViewCompat; -import androidx.webkit.WebViewFeature; - -import java.util.Collections; -import java.util.Set; - -/** - * Injects the EvenHub bridge shim at document start into a WebView that loads - * a page over the real network (the developer "Load app from URL" flow). - * - * Packaged apps get the shim spliced into the HTML they are served - * (FaceclawEvenHubWebViewClient), which is not an option for a page fetched - * from a live server. WebViewCompat.addDocumentStartJavaScript is the - * supported way to run script before any page script, and unlike an - * onPageStarted evaluateJavascript it is guaranteed to win the race — apps - * poll for window.flutter_inappwebview with a few seconds' patience, but the - * timer shim must be in place before the app captures setTimeout. - * - * Requires WebView 83+; the caller falls back to onPageStarted injection when - * this returns false. - */ -public final class FaceclawEvenHubDocumentStart { - private static final String TAG = "FaceclawEvenHub"; - - private FaceclawEvenHubDocumentStart() {} - - /** - * @param originRule an allowed-origin rule, e.g. "https://example.com" or "*". - * @return whether the script was registered. - */ - public static boolean install(WebView webView, String script, String originRule) { - if (!WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) { - Log.w(TAG, "document-start scripts unsupported; falling back to onPageStarted"); - return false; - } - try { - Set rules = Collections.singleton(originRule); - WebViewCompat.addDocumentStartJavaScript(webView, script, rules); - return true; - } catch (Throwable error) { - Log.w(TAG, "addDocumentStartJavaScript failed for " + originRule, error); - return false; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.kt new file mode 100644 index 00000000..3f50eaec --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.kt @@ -0,0 +1,50 @@ +package com.faceclaw.app + +import android.util.Log +import android.webkit.WebView + +import androidx.webkit.WebViewCompat +import androidx.webkit.WebViewFeature + +import java.util.Collections + +/** + * Injects the EvenHub bridge shim at document start into a WebView that loads + * a page over the real network (the developer "Load app from URL" flow). + * + * Packaged apps get the shim spliced into the HTML they are served + * (FaceclawEvenHubWebViewClient), which is not an option for a page fetched + * from a live server. WebViewCompat.addDocumentStartJavaScript is the + * supported way to run script before any page script, and unlike an + * onPageStarted evaluateJavascript it is guaranteed to win the race — apps + * poll for window.flutter_inappwebview with a few seconds' patience, but the + * timer shim must be in place before the app captures setTimeout. + * + * Requires WebView 83+; the caller falls back to onPageStarted injection when + * this returns false. + */ +class FaceclawEvenHubDocumentStart private constructor() { + companion object { + private const val TAG = "FaceclawEvenHub" + + /** + * @param originRule an allowed-origin rule, e.g. "https://example.com" or "*". + * @return whether the script was registered. + */ + @JvmStatic + fun install(webView: WebView, script: String, originRule: String): Boolean { + if (!WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) { + Log.w(TAG, "document-start scripts unsupported; falling back to onPageStarted") + return false + } + try { + val rules: Set = Collections.singleton(originRule) + WebViewCompat.addDocumentStartJavaScript(webView, script, rules) + return true + } catch (error: Throwable) { + Log.w(TAG, "addDocumentStartJavaScript failed for $originRule", error) + return false + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.java deleted file mode 100644 index 6e40bbef..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.webkit.JavascriptInterface; - -/** - * The object injected into a hosted EvenHub app's WebView as - * window.__faceclawEvenHub. The document-start shim (served inline by - * FaceclawEvenHubWebViewClient) wraps it in a promise-returning - * window.flutter_inappwebview.callHandler, which is what the EvenHub SDK - * actually talks to. - * - * JavascriptInterface methods run on a WebView-internal thread; everything - * is bounced to the main thread before touching the NativeScript listener. - */ -public class FaceclawEvenHubJsBridge { - private final FaceclawEvenHubListener listener; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - - public FaceclawEvenHubJsBridge(FaceclawEvenHubListener listener) { - this.listener = listener; - } - - @JavascriptInterface - public void postMessage(final String handlerName, final String argsJson, final int callId) { - mainHandler.post(new Runnable() { - @Override - public void run() { - listener.onEvenAppMessage(handlerName, argsJson, callId); - } - }); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt new file mode 100644 index 00000000..90c8c1e7 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt @@ -0,0 +1,26 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.webkit.JavascriptInterface + +/** + * The object injected into a hosted EvenHub app's WebView as + * window.__faceclawEvenHub. The document-start shim (served inline by + * FaceclawEvenHubWebViewClient) wraps it in a promise-returning + * window.flutter_inappwebview.callHandler, which is what the EvenHub SDK + * actually talks to. + * + * JavascriptInterface methods run on a WebView-internal thread; everything + * is bounced to the main thread before touching the NativeScript listener. + */ +class FaceclawEvenHubJsBridge(private val listener: FaceclawEvenHubListener) { + private val mainHandler = Handler(Looper.getMainLooper()) + + @JavascriptInterface + fun postMessage(handlerName: String?, argsJson: String?, callId: Int) { + mainHandler.post { + listener.onEvenAppMessage(handlerName, argsJson, callId) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebView.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebView.kt similarity index 78% rename from App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebView.java rename to App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebView.kt index 5a590902..4f5024a6 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebView.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebView.kt @@ -1,8 +1,8 @@ -package com.faceclaw.app; +package com.faceclaw.app -import android.content.Context; -import android.view.View; -import android.webkit.WebView; +import android.content.Context +import android.view.View +import android.webkit.WebView /** * A WebView for hosting an EvenHub app that keeps rendering and running JS even @@ -25,16 +25,11 @@ import android.webkit.WebView; * service regardless of the phone's screen, so "always rendering" is what we * actually want; there is no on-phone cost while the app is unseen. */ -public class FaceclawEvenHubWebView extends WebView { +class FaceclawEvenHubWebView(context: Context) : WebView(context) { - public FaceclawEvenHubWebView(Context context) { - super(context); - } - - @Override - protected void onWindowVisibilityChanged(int visibility) { + override fun onWindowVisibilityChanged(visibility: Int) { // Never propagate a hidden window: keep Chromium's page-visibility // "visible" so the renderer isn't frozen when Faceclaw backgrounds. - super.onWindowVisibilityChanged(View.VISIBLE); + super.onWindowVisibilityChanged(View.VISIBLE) } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.java deleted file mode 100644 index f8c21348..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import android.net.Uri; -import android.util.Log; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -/** - * Serves an unpacked EvenHub app's files to its WebView from a fake per-app - * https origin, entirely offline. HTML responses get the host bridge shim - * injected at the top of the document, guaranteeing - * window.flutter_inappwebview exists before any app JS runs (apps race - * waitForEvenAppBridge against 4-6s timeouts and silently fall back to demo - * modes if the handler appears late). - * - * shouldInterceptRequest runs on a WebView-internal thread; it only touches - * files, never the NativeScript runtime. Requests to other hosts fall - * through to the network (the manifest whitelist is not yet enforced). - * - * A developer-loaded app ("Load app from URL") has no local root: host is - * empty, nothing is intercepted, and the page loads normally from its server. - * The shim is registered as a document-start script instead - * (FaceclawEvenHubDocumentStart); injectOnPageStarted is the fallback for - * WebView versions that lack that API. - */ -public class FaceclawEvenHubWebViewClient extends WebViewClient { - private static final String TAG = "FaceclawEvenHub"; - - private final String rootDir; - private final String host; - private final String injectScript; - private final boolean injectOnPageStarted; - private final FaceclawEvenHubListener listener; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - - public FaceclawEvenHubWebViewClient( - String rootDir, - String host, - String injectScript, - boolean injectOnPageStarted, - FaceclawEvenHubListener listener) { - this.rootDir = rootDir; - this.host = host; - this.injectScript = injectScript; - this.injectOnPageStarted = injectOnPageStarted; - this.listener = listener; - } - - @Override - public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { - if (host == null || host.isEmpty()) { - return null; // Remote app: everything comes from the network. - } - Uri url = request.getUrl(); - if (url == null || !host.equals(url.getHost())) { - return null; // External hosts: normal network handling. - } - String path = url.getPath(); - if (path == null || path.isEmpty() || path.equals("/")) { - path = "/index.html"; - } - try { - File root = new File(rootDir).getCanonicalFile(); - File target = new File(root, path.substring(1)).getCanonicalFile(); - if (!target.getPath().startsWith(root.getPath()) || !target.isFile()) { - Log.w(TAG, "404 " + path); - return new WebResourceResponse( - "text/plain", "utf-8", - new ByteArrayInputStream("not found".getBytes(StandardCharsets.UTF_8))); - } - String mime = mimeTypeFor(target.getName()); - if (mime.equals("text/html")) { - return new WebResourceResponse(mime, "utf-8", new ByteArrayInputStream(injectIntoHtml(target))); - } - InputStream stream = new FileInputStream(target); - return new WebResourceResponse(mime, null, stream); - } catch (IOException e) { - Log.e(TAG, "serve failed for " + path, e); - return new WebResourceResponse( - "text/plain", "utf-8", - new ByteArrayInputStream("error".getBytes(StandardCharsets.UTF_8))); - } - } - - @Override - public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) { - super.onPageStarted(view, url, favicon); - if (!injectOnPageStarted) return; - // Best-effort: the document has committed but the parser has not run - // the page's own scripts yet, so this usually lands first. Only used - // when document-start scripts are unavailable. - view.evaluateJavascript(injectScript, null); - } - - @Override - public void onPageFinished(WebView view, final String url) { - mainHandler.post(new Runnable() { - @Override - public void run() { - listener.onPageFinished(url); - } - }); - } - - private byte[] injectIntoHtml(File file) throws IOException { - byte[] raw = readAll(file); - String html = new String(raw, StandardCharsets.UTF_8); - String tag = ""; - // After if present, else before everything. - int headIndex = indexOfIgnoreCase(html, "= 0) { - int close = html.indexOf('>', headIndex); - if (close >= 0) { - return (html.substring(0, close + 1) + tag + html.substring(close + 1)) - .getBytes(StandardCharsets.UTF_8); - } - } - return (tag + html).getBytes(StandardCharsets.UTF_8); - } - - private static int indexOfIgnoreCase(String haystack, String needle) { - return haystack.toLowerCase(Locale.ROOT).indexOf(needle); - } - - private static byte[] readAll(File file) throws IOException { - FileInputStream in = new FileInputStream(file); - try { - byte[] data = new byte[(int) file.length()]; - int off = 0; - while (off < data.length) { - int n = in.read(data, off, data.length - off); - if (n < 0) throw new IOException("short read: " + file); - off += n; - } - return data; - } finally { - in.close(); - } - } - - private static String mimeTypeFor(String name) { - String lower = name.toLowerCase(Locale.ROOT); - if (lower.endsWith(".html") || lower.endsWith(".htm")) return "text/html"; - if (lower.endsWith(".js") || lower.endsWith(".mjs")) return "application/javascript"; - if (lower.endsWith(".css")) return "text/css"; - if (lower.endsWith(".json")) return "application/json"; - if (lower.endsWith(".png")) return "image/png"; - if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "image/jpeg"; - if (lower.endsWith(".gif")) return "image/gif"; - if (lower.endsWith(".svg")) return "image/svg+xml"; - if (lower.endsWith(".webp")) return "image/webp"; - if (lower.endsWith(".ico")) return "image/x-icon"; - if (lower.endsWith(".wasm")) return "application/wasm"; - if (lower.endsWith(".woff")) return "font/woff"; - if (lower.endsWith(".woff2")) return "font/woff2"; - if (lower.endsWith(".ttf")) return "font/ttf"; - if (lower.endsWith(".txt") || lower.endsWith(".map")) return "text/plain"; - return "application/octet-stream"; - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt new file mode 100644 index 00000000..bec2b8a3 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt @@ -0,0 +1,158 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse +import android.webkit.WebView +import android.webkit.WebViewClient +import android.net.Uri +import android.util.Log + +import java.io.ByteArrayInputStream +import java.io.File +import java.io.FileInputStream +import java.io.IOException +import java.io.InputStream +import java.nio.charset.StandardCharsets +import java.util.Locale + +/** + * Serves an unpacked EvenHub app's files to its WebView from a fake per-app + * https origin, entirely offline. HTML responses get the host bridge shim + * injected at the top of the document, guaranteeing + * window.flutter_inappwebview exists before any app JS runs (apps race + * waitForEvenAppBridge against 4-6s timeouts and silently fall back to demo + * modes if the handler appears late). + * + * shouldInterceptRequest runs on a WebView-internal thread; it only touches + * files, never the NativeScript runtime. Requests to other hosts fall + * through to the network (the manifest whitelist is not yet enforced). + * + * A developer-loaded app ("Load app from URL") has no local root: host is + * empty, nothing is intercepted, and the page loads normally from its server. + * The shim is registered as a document-start script instead + * (FaceclawEvenHubDocumentStart); injectOnPageStarted is the fallback for + * WebView versions that lack that API. + */ +class FaceclawEvenHubWebViewClient( + private val rootDir: String?, + private val host: String?, + private val injectScript: String, + private val injectOnPageStarted: Boolean, + private val listener: FaceclawEvenHubListener +) : WebViewClient() { + private val mainHandler = Handler(Looper.getMainLooper()) + + override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? { + if (host == null || host.isEmpty()) { + return null // Remote app: everything comes from the network. + } + val url: Uri? = request.url + if (url == null || host != url.host) { + return null // External hosts: normal network handling. + } + var path = url.path + if (path == null || path.isEmpty() || path == "/") { + path = "/index.html" + } + try { + val root = File(rootDir).canonicalFile + val target = File(root, path.substring(1)).canonicalFile + if (!target.path.startsWith(root.path) || !target.isFile) { + Log.w(TAG, "404 $path") + return WebResourceResponse( + "text/plain", "utf-8", + ByteArrayInputStream("not found".toByteArray(StandardCharsets.UTF_8))) + } + val mime = mimeTypeFor(target.name) + if (mime == "text/html") { + return WebResourceResponse(mime, "utf-8", ByteArrayInputStream(injectIntoHtml(target))) + } + val stream: InputStream = FileInputStream(target) + return WebResourceResponse(mime, null, stream) + } catch (e: IOException) { + Log.e(TAG, "serve failed for $path", e) + return WebResourceResponse( + "text/plain", "utf-8", + ByteArrayInputStream("error".toByteArray(StandardCharsets.UTF_8))) + } + } + + override fun onPageStarted(view: WebView, url: String?, favicon: android.graphics.Bitmap?) { + super.onPageStarted(view, url, favicon) + if (!injectOnPageStarted) return + // Best-effort: the document has committed but the parser has not run + // the page's own scripts yet, so this usually lands first. Only used + // when document-start scripts are unavailable. + view.evaluateJavascript(injectScript, null) + } + + override fun onPageFinished(view: WebView, url: String?) { + mainHandler.post { + listener.onPageFinished(url) + } + } + + @Throws(IOException::class) + private fun injectIntoHtml(file: File): ByteArray { + val raw = readAll(file) + val html = String(raw, StandardCharsets.UTF_8) + val tag = "" + // After if present, else before everything. + val headIndex = indexOfIgnoreCase(html, "= 0) { + val close = html.indexOf('>', headIndex) + if (close >= 0) { + return (html.substring(0, close + 1) + tag + html.substring(close + 1)) + .toByteArray(StandardCharsets.UTF_8) + } + } + return (tag + html).toByteArray(StandardCharsets.UTF_8) + } + + companion object { + private const val TAG = "FaceclawEvenHub" + + private fun indexOfIgnoreCase(haystack: String, needle: String): Int { + return haystack.lowercase(Locale.ROOT).indexOf(needle) + } + + @Throws(IOException::class) + private fun readAll(file: File): ByteArray { + val input = FileInputStream(file) + try { + val data = ByteArray(file.length().toInt()) + var off = 0 + while (off < data.size) { + val n = input.read(data, off, data.size - off) + if (n < 0) throw IOException("short read: $file") + off += n + } + return data + } finally { + input.close() + } + } + + private fun mimeTypeFor(name: String): String { + val lower = name.lowercase(Locale.ROOT) + if (lower.endsWith(".html") || lower.endsWith(".htm")) return "text/html" + if (lower.endsWith(".js") || lower.endsWith(".mjs")) return "application/javascript" + if (lower.endsWith(".css")) return "text/css" + if (lower.endsWith(".json")) return "application/json" + if (lower.endsWith(".png")) return "image/png" + if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "image/jpeg" + if (lower.endsWith(".gif")) return "image/gif" + if (lower.endsWith(".svg")) return "image/svg+xml" + if (lower.endsWith(".webp")) return "image/webp" + if (lower.endsWith(".ico")) return "image/x-icon" + if (lower.endsWith(".wasm")) return "application/wasm" + if (lower.endsWith(".woff")) return "font/woff" + if (lower.endsWith(".woff2")) return "font/woff2" + if (lower.endsWith(".ttf")) return "font/ttf" + if (lower.endsWith(".txt") || lower.endsWith(".map")) return "text/plain" + return "application/octet-stream" + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt similarity index 56% rename from App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.java rename to App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt index d50d00ae..7e563d0e 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt @@ -1,16 +1,15 @@ -package com.faceclaw.app; +package com.faceclaw.app -import android.app.Activity; -import android.os.Build; -import android.os.Handler; -import android.os.Looper; -import android.view.View; -import android.view.ViewGroup; -import android.webkit.WebView; -import android.widget.FrameLayout; +import android.app.Activity +import android.os.Build +import android.os.Handler +import android.os.Looper +import android.view.View +import android.view.ViewGroup +import android.webkit.WebView +import android.widget.FrameLayout -import java.util.ArrayList; -import java.util.List; +import java.util.ArrayList /** * Keeps EvenHub app WebViews alive and rendering while the phone shows the @@ -49,109 +48,113 @@ import java.util.List; * activity is foreground. When Faceclaw itself is backgrounded, the window goes * invisible and Chromium freezes the renderer — the timer/rAF ticks and pushed * input events then queue up and only run once foregrounded again. Two things - * prevent that: the WebViews are {@link FaceclawEvenHubWebView}, which lies to + * prevent that: the WebViews are [FaceclawEvenHubWebView], which lies to * Chromium about window visibility so the page never goes hidden; and each is * pinned to IMPORTANT renderer priority (not waived when not visible) with * timers/onResume asserted on attach. The main Looper keeps ticking under the * foreground service, so apps keep driving their glasses windows in the * background. */ -public class FaceclawEvenHubWebViewHost { - private static FaceclawEvenHubWebViewHost instance; +class FaceclawEvenHubWebViewHost { + private var overlay: FrameLayout? = null + private var shown = false - /** How often the host fires the JS timer queue. 60Hz keeps games smooth. */ - private static final long TICK_MS = 16; - - private FrameLayout overlay; - private boolean shown = false; - - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private final List webViews = new ArrayList<>(); - private boolean ticking = false; - private final Runnable ticker = new Runnable() { - @Override - public void run() { - for (int i = 0; i < webViews.size(); i++) { - webViews.get(i).evaluateJavascript( - "window.__fcTimerTick&&__fcTimerTick();window.__fcRafTick&&__fcRafTick()", null); + private val mainHandler = Handler(Looper.getMainLooper()) + private val webViews: MutableList = ArrayList() + private var ticking = false + private val ticker: Runnable = object : Runnable { + override fun run() { + for (i in 0 until webViews.size) { + webViews[i].evaluateJavascript( + "window.__fcTimerTick&&__fcTimerTick();window.__fcRafTick&&__fcRafTick()", null) } - if (ticking) mainHandler.postDelayed(this, TICK_MS); + if (ticking) mainHandler.postDelayed(this, TICK_MS) } - }; - - public static synchronized FaceclawEvenHubWebViewHost getInstance() { - if (instance == null) instance = new FaceclawEvenHubWebViewHost(); - return instance; } - private FrameLayout ensureOverlay(Activity activity) { - if (overlay != null) return overlay; - ViewGroup content = activity.findViewById(android.R.id.content); - overlay = new FrameLayout(activity); + companion object { + private var instance: FaceclawEvenHubWebViewHost? = null + + /** How often the host fires the JS timer queue. 60Hz keeps games smooth. */ + private const val TICK_MS = 16L + + @JvmStatic + @Synchronized + fun getInstance(): FaceclawEvenHubWebViewHost { + if (instance == null) instance = FaceclawEvenHubWebViewHost() + return instance!! + } + } + + private fun ensureOverlay(activity: Activity): FrameLayout { + overlay?.let { return it } + val content = activity.findViewById(android.R.id.content) + val created = FrameLayout(activity) + overlay = created // index 0 = behind the NativeScript content view. - content.addView(overlay, 0, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - return overlay; + content.addView(created, 0, FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)) + return created } /** Add a WebView to the host, full-size and rendering, hidden behind the UI. */ - public void attach(Activity activity, WebView web) { - FrameLayout o = ensureOverlay(activity); - web.setVisibility(View.VISIBLE); - if (web.getParent() == null) { - o.addView(web, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + fun attach(activity: Activity, web: WebView) { + val o = ensureOverlay(activity) + web.visibility = View.VISIBLE + if (web.parent == null) { + o.addView(web, FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)) } // resumeTimers() is process-global; make sure nothing left timers paused. // onResume() undoes any per-WebView pause. Together with // FaceclawEvenHubWebView faking window visibility, this keeps the page // running JS while Faceclaw is backgrounded. - web.resumeTimers(); - web.onResume(); + web.resumeTimers() + web.onResume() // Keep the renderer process at IMPORTANT priority even when the WebView // isn't visible (waivedWhenNotVisible=false), so Android doesn't // deprioritize/kill it in the background. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - web.setRendererPriorityPolicy(WebView.RENDERER_PRIORITY_IMPORTANT, false); + web.setRendererPriorityPolicy(WebView.RENDERER_PRIORITY_IMPORTANT, false) } - if (!webViews.contains(web)) webViews.add(web); + if (!webViews.contains(web)) webViews.add(web) if (!ticking) { - ticking = true; - mainHandler.postDelayed(ticker, TICK_MS); + ticking = true + mainHandler.postDelayed(ticker, TICK_MS) } } /** Bring an app's WebView to the front so it is visible on the phone. */ - public void showOnPhone(WebView web) { - if (overlay == null) return; - web.bringToFront(); - overlay.bringToFront(); - shown = true; + fun showOnPhone(web: WebView) { + val o = overlay ?: return + web.bringToFront() + o.bringToFront() + shown = true } /** Send the overlay back behind the NativeScript UI. */ - public void hideOnPhone() { - shown = false; - if (overlay == null) return; - ViewGroup content = (ViewGroup) overlay.getParent(); + fun hideOnPhone() { + shown = false + val o = overlay ?: return + val content = o.parent as ViewGroup? if (content != null) { - content.removeView(overlay); - content.addView(overlay, 0); + content.removeView(o) + content.addView(o, 0) } } - public boolean isShown() { - return shown; + fun isShown(): Boolean { + return shown } /** Remove and destroy a WebView (its app is closing). */ - public void detach(WebView web) { - webViews.remove(web); + fun detach(web: WebView) { + webViews.remove(web) if (webViews.isEmpty() && ticking) { - ticking = false; - mainHandler.removeCallbacks(ticker); + ticking = false + mainHandler.removeCallbacks(ticker) } - if (overlay != null) overlay.removeView(web); - web.destroy(); + overlay?.removeView(web) + web.destroy() } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.java deleted file mode 100644 index 3a941ac6..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.java +++ /dev/null @@ -1,695 +0,0 @@ -package com.faceclaw.app; - -import android.bluetooth.BluetoothGatt; -import android.content.Context; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; -import android.util.Log; - -import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * Ports g2flash.py's OTA flash procedure to Android. Streams the EVENOTA - * firmware container to each lens over the firmware-data service using the - * aa21 envelope (BleProtocol.framePb) and the c0/c1 control/data protocol. - * - * Each lens connection completes the sid-0x80 security-auth exchange before - * OTA BEGIN — firmware 2.2.9 closes unauthenticated links ~30 s in, killing - * the transfer mid-component. No control-channel traffic is injected during - * the transfer itself: official OTA captures show none between BEGIN and the - * final END, heartbeats demonstrably do not satisfy the 2.2.9 deadline, and a - * concurrent control writer would interleave with the marker/data - * transactions. (See ../notes/ble-connections-2.2.9.md.) - * - * Lenses are flashed one at a time (left, then right). Finishing either lens - * reboots BOTH lenses, so the second lens is briefly unreachable — the reconnect - * for it uses a generous window rather than failing fast. - * - * Separate from FaceclawBleCommunicator on purpose: this speaks the stock OTA - * protocol and must run before the custom firmware exists. It reuses the GATT - * wrapper (FaceclawBleManager) and framing (BleProtocol). - */ -public class FaceclawFirmwareFlasher implements FaceclawBleListener { - private static final String TAG = "FaceclawFlasher"; - - // OTA message types (envelope sid byte) and control opcodes. - private static final int SID_CTRL = 0xc0; - private static final int SID_DATA = 0xc1; - private static final int FLAG_OTA = 0x00; - private static final int OP_BEGIN = 0x00; - private static final int OP_FILE_CHECK = 0x01; - private static final int OP_BLOCK = 0x02; - private static final int OP_END = 0x03; - - private static final int BLOCK_SIZE = 4096; - private static final int BLOCK_ACK_TIMEOUT_MS = 4_000; - private static final int CTRL_ACK_TIMEOUT_MS = 8_000; - private static final int BLOCK_NAK_RETRIES = 3; - private static final int COMPONENT_RETRIES = 3; - - // Reconnect windows. The first lens connects from an idle device; the second - // must ride out the post-first-lens reboot of both lenses. - private static final int FIRST_LENS_CONNECT_WINDOW_MS = 30_000; - private static final int SECOND_LENS_CONNECT_WINDOW_MS = 120_000; - private static final int REBOOT_SETTLE_MS = 5_000; - private static final int NOTIFY_SETTLE_MS = 2_500; - private static final int RETRY_DELAY_MS = 2_500; - - // END ack statuses that mean "component accepted": SUCCESS, UPDATING, SYS_RESTART. - private static final int[] END_OK = new int[] {0, 8, 9}; - - // Firmware layout expectations (mirrors g2flash.py). Firmware 2.2.4 has 5 - // components; 2.2.6 has 6. - private static final int MIN_SEGMENTS = 5; - private static final int MAX_SEGMENTS = 6; - private static final String REQUIRED_SEGMENT = "ota/s200_firmware_ota.bin"; - private static final long APP_LOAD_ADDR = 0x00438000L; - private static final long APP_MAX_END = 0x007F0000L; - private static final int APP_PREAMBLE = 0x20; - - private final Context context; - private final String leftAddress; - private final String rightAddress; - private final String firmwarePath; - private final FaceclawBleManager bleManager; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - - private final Object lock = new Object(); - private final LinkedBlockingQueue dataAcks = new LinkedBlockingQueue<>(); - - private volatile FaceclawFirmwareFlasherListener listener; - private volatile Thread worker; - private volatile boolean cancelled = false; - - private int nextSeq = 0; - private int nextAuthMagic = 0x60; - private int pendingAuthMagic = -1; - private CountDownLatch authLatch; - private byte[] authAckPb; - - public FaceclawFirmwareFlasher(Context context, String rightAddress, String leftAddress, String firmwarePath) { - this.context = context.getApplicationContext(); - this.rightAddress = rightAddress == null ? "" : rightAddress; - this.leftAddress = leftAddress == null ? "" : leftAddress; - this.firmwarePath = firmwarePath == null ? "" : firmwarePath; - this.bleManager = new FaceclawBleManager(this.context); - this.bleManager.setListener(this); - } - - public void setListener(FaceclawFirmwareFlasherListener listener) { - this.listener = listener; - } - - public void start() { - synchronized (lock) { - if (worker != null) { - return; - } - worker = new Thread(this::run, "faceclaw-flasher"); - worker.start(); - } - } - - public void cancel() { - cancelled = true; - Thread w = worker; - if (w != null) { - w.interrupt(); - } - } - - public void close() { - cancel(); - try { - bleManager.close(); - } catch (Exception ignored) { - } - } - - private void run() { - try { - if (leftAddress.trim().isEmpty() || rightAddress.trim().isEmpty()) { - throw new IllegalStateException("Both lens addresses are required to flash."); - } - - emitState("validating", ""); - byte[] img = readFile(firmwarePath); - List segs = validate(img); - emitLog("firmware validated: " + segs.size() + " components, " + img.length + " bytes"); - - flashLens("left", leftAddress, img, segs, FIRST_LENS_CONNECT_WINDOW_MS); - if (cancelled) { - emitState("error", "Cancelled."); - emitComplete(false, "Cancelled after the left lens."); - return; - } - - emitState("rebooting", "Left lens done. Both lenses reboot briefly; reconnecting for the right lens."); - sleepInterruptibly(REBOOT_SETTLE_MS); - flashLens("right", rightAddress, img, segs, SECOND_LENS_CONNECT_WINDOW_MS); - - emitState("done", ""); - emitComplete(true, "Both lenses flashed. The glasses are rebooting into the custom firmware."); - } catch (Exception e) { - String message = e.getMessage() == null ? e.toString() : e.getMessage(); - if (cancelled) { - message = "Cancelled."; - } - emitState("error", message); - emitComplete(false, message); - } finally { - teardown(); - } - } - - private void flashLens(String lens, String address, byte[] img, List segs, int connectWindowMs) - throws TimeoutException { - emitState("connecting", lens); - connectLensResilient(lens, address, connectWindowMs); - sleepInterruptibly(NOTIFY_SETTLE_MS); - drainAcks(); - // Fresh envelope counter for the OTA stream (the auth exchange during - // bring-up used its own); mirrors the stock sequence. - resetSeq(); - - emitState("flashing", lens); - int beginStatus = sendCtrlAndWait(address, OP_BEGIN, EMPTY, CTRL_ACK_TIMEOUT_MS); - if (!isEndOk(beginStatus)) { - emitLog("warning: unexpected begin status " + beginStatus + "; continuing"); - } - // Progress is reported in bytes across the whole image: the segments - // are one large firmware blob plus several small ones, so a bar - // stepped per segment would sit still through the big one and then - // sprint through the rest. - long totalBytes = 0; - for (Segment seg : segs) { - totalBytes += seg.ps; - } - long bytesBefore = 0; - for (int i = 0; i < segs.size(); i++) { - if (cancelled) { - throw new IllegalStateException("Cancelled."); - } - flashComponentWithRetry(lens, address, i, segs.size(), segs.get(i), img, bytesBefore, totalBytes); - bytesBefore += segs.get(i).ps; - } - emitLog(lens + " lens: all components verified"); - try { - bleManager.disconnect(address); - } catch (Exception ignored) { - } - } - - private void flashComponentWithRetry(String lens, String address, int index, int count, Segment seg, byte[] img, - long bytesBefore, long totalBytes) { - for (int attempt = 0; attempt < COMPONENT_RETRIES; attempt++) { - if (attempt > 0) { - emitLog(seg.name + ": re-flash attempt " + (attempt + 1) + "/" + COMPONENT_RETRIES); - } - int endStatus; - try { - endStatus = flashComponent(lens, address, index, count, seg, img, bytesBefore, totalBytes); - } catch (TimeoutException | RuntimeException e) { - emitLog(seg.name + ": block phase failed: " + e.getMessage()); - endStatus = -1; - } - if (isEndOk(endStatus)) { - emitLog(seg.name + ": END verify OK (status " + endStatus + ")"); - return; - } - if (endStatus >= 0) { - emitLog(seg.name + ": END verify FAILED (status " + endStatus + ")"); - } - drainAcks(); - sleepInterruptibly(1_500); - } - throw new IllegalStateException("component " + seg.name + " failed after " + COMPONENT_RETRIES + " attempts"); - } - - private int flashComponent(String lens, String address, int index, int count, Segment seg, byte[] img, - long bytesBefore, long totalBytes) throws TimeoutException { - byte[] sub = Arrays.copyOfRange(img, seg.off, seg.off + 128); - int ps = seg.ps; - int payloadStart = seg.off + 128; - - int checkStatus = sendCtrlAndWait(address, OP_FILE_CHECK, sub, CTRL_ACK_TIMEOUT_MS); - if (checkStatus != 0) { - throw new IllegalStateException("FILE_CHECK rejected status=" + checkStatus); - } - - int blockCount = (ps + BLOCK_SIZE - 1) / BLOCK_SIZE; - for (int b = 0; b < blockCount; b++) { - if (cancelled) { - throw new IllegalStateException("Cancelled."); - } - int start = payloadStart + b * BLOCK_SIZE; - int end = Math.min(start + BLOCK_SIZE, payloadStart + ps); - byte[] block = Arrays.copyOfRange(img, start, end); - - boolean accepted = false; - for (int tries = 0; tries < BLOCK_NAK_RETRIES; tries++) { - int status = sendBlock(address, block); // throws TimeoutException -> component re-flash - if (status == 0) { - accepted = true; - break; - } - emitLog(seg.name + ": block " + b + "/" + blockCount + " NAK=" + status - + " resend " + (tries + 1) + "/" + BLOCK_NAK_RETRIES); - } - if (!accepted) { - throw new IllegalStateException("block " + b + " NAK'd " + BLOCK_NAK_RETRIES + " times"); - } - if (b % 20 == 0 || b == blockCount - 1) { - long bytesSent = bytesBefore + Math.min((long) (b + 1) * BLOCK_SIZE, (long) ps); - emitProgress(lens, index + 1, count, b + 1, blockCount, bytesSent, totalBytes); - } - } - emitLog(seg.name + ": data phase done; sending END"); - return sendCtrlAndWait(address, OP_END, EMPTY, CTRL_ACK_TIMEOUT_MS); - } - - /** Send one 4 KB block as a marker + data pair sharing one envelope seq. */ - private int sendBlock(String address, byte[] block) throws TimeoutException { - int seq = nextSeq(); - drainAcks(); - writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_CTRL, new byte[] {(byte) OP_BLOCK}, seq); - writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_DATA, block, seq); - return waitAck(OP_BLOCK, BLOCK_ACK_TIMEOUT_MS); - } - - private int sendCtrlAndWait(String address, int op, byte[] data, int timeoutMs) throws TimeoutException { - int seq = nextSeq(); - drainAcks(); - byte[] payload = new byte[1 + data.length]; - payload[0] = (byte) op; - System.arraycopy(data, 0, payload, 1, data.length); - writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_CTRL, payload, seq); - return waitAck(op, timeoutMs); - } - - private boolean writeOta(String address, String writeChar, int sid, byte[] payload, int seq) { - List frames = BleProtocol.framePb(payload, sid, FLAG_OTA, seq); - return bleManager.writeFrames( - address, writeChar, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS); - } - - private int waitAck(int wantOp, int timeoutMs) throws TimeoutException { - long deadline = SystemClock.elapsedRealtime() + timeoutMs; - while (true) { - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - break; - } - byte[] pb; - try { - pb = dataAcks.poll(remaining, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new TimeoutException("interrupted waiting for ack op=" + wantOp); - } - if (pb == null) { - break; - } - if (pb.length >= 2 && (pb[0] & 0xff) == wantOp) { - return pb[1] & 0xff; - } - // Different opcode (e.g. a late ack from a prior stage) — ignore, keep waiting. - } - throw new TimeoutException("no ack op=0x" + Integer.toHexString(wantOp) + " within " + timeoutMs + "ms"); - } - - // ---- connection ---------------------------------------------------------- - - private void connectLensResilient(String lens, String address, int windowMs) { - long deadline = SystemClock.elapsedRealtime() + windowMs; - String lastError = "unknown"; - int attempt = 0; - while (SystemClock.elapsedRealtime() < deadline && !cancelled) { - attempt++; - try { - if (bringUpLens(address)) { - emitLog("connected " + lens + " lens (attempt " + attempt + ")"); - return; - } - lastError = "connect/discover incomplete"; - } catch (Exception e) { - lastError = e.getMessage() == null ? e.toString() : e.getMessage(); - } - emitLog(lens + " connect attempt " + attempt + " failed (" + lastError + "); retrying..."); - try { - bleManager.disconnect(address); - } catch (Exception ignored) { - } - sleepInterruptibly(RETRY_DELAY_MS); - } - if (cancelled) { - throw new IllegalStateException("Cancelled."); - } - throw new IllegalStateException("could not reach " + lens + " lens: " + lastError); - } - - private boolean bringUpLens(String address) { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - return false; - } - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH); - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS); - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - return false; - } - // Control-channel notify carries the auth response; mandatory. - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - return false; - } - if (!bleManager.enableNotifications(address, BleProtocol.OTA_DATA_NOTIFY_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - return false; - } - if (!authenticate(address)) { - throw new IllegalStateException( - "security auth not acknowledged — if Android shows a Bluetooth pairing request, accept it"); - } - return true; - } - - /** - * Complete the sid-0x80 security-auth exchange on this connection. On an - * unbonded phone this triggers SMP pairing (possibly with an OS prompt), - * so the wait is generous. Must succeed before any OTA traffic. - */ - private boolean authenticate(String address) { - int magic; - CountDownLatch latch = new CountDownLatch(1); - synchronized (lock) { - magic = nextAuthMagic; - nextAuthMagic = nextAuthMagic >= 0x7f ? 0x60 : nextAuthMagic + 1; - pendingAuthMagic = magic; - authAckPb = null; - authLatch = latch; - } - try { - if (!writeOta(address, BleProtocol.WRITE_CHAR_UUID, BleProtocol.SID_SECURITY_AUTH, - BleProtocol.buildAuthenticationRequest(magic), nextSeq())) { - emitLog("auth write failed: " + address); - return false; - } - boolean signalled; - try { - signalled = latch.await(ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return false; - } - byte[] pb; - synchronized (lock) { - pb = authAckPb; - } - if (!signalled || !BleProtocol.isAuthenticationSuccess(pb, magic)) { - emitLog("security auth not acknowledged (" + address - + ") — if Android shows a Bluetooth pairing request, accept it"); - return false; - } - emitLog("security auth complete: " + address); - return true; - } finally { - synchronized (lock) { - pendingAuthMagic = -1; - authLatch = null; - } - } - } - - // ---- firmware container parsing / validation ----------------------------- - - private static final byte[] EMPTY = new byte[0]; - - private static final class Segment { - final int off; - final int ps; - final long crc; - final String name; - - Segment(int off, int ps, long crc, String name) { - this.off = off; - this.ps = ps; - this.crc = crc; - this.name = name; - } - } - - private List parseSegments(byte[] img) { - if (img.length < 0x40) { - throw new IllegalStateException("file is too small to be a firmware image"); - } - long n = readU32(img, 8); - if (n <= 0 || n > 64) { - throw new IllegalStateException("implausible component count " + n + " (corrupt image?)"); - } - List segs = new ArrayList<>(); - for (int i = 0; i < n; i++) { - int base = 0x40 + i * 16; - long crc = readU32(img, base + 12); - int off = (int) readU32(img, base + 4); - if (off + 128 > img.length) { - throw new IllegalStateException("segment " + i + " subheader runs past end of file"); - } - int ps = (int) readU32(img, off + 8); - String name = readCString(img, off + 48, 80); - segs.add(new Segment(off, ps, crc, name)); - } - return segs; - } - - private List validate(byte[] img) { - List segs = parseSegments(img); - if (segs.size() < MIN_SEGMENTS || segs.size() > MAX_SEGMENTS) { - throw new IllegalStateException( - "expected " + MIN_SEGMENTS + "-" + MAX_SEGMENTS + " components, found " + segs.size()); - } - Segment main = null; - for (Segment s : segs) { - byte[] payload = Arrays.copyOfRange(img, s.off + 128, s.off + 128 + s.ps); - long calc = crc32cMsb(payload) & 0xffffffffL; - long subCrc = readU32(img, s.off + 12); - if (calc != s.crc || calc != subCrc) { - throw new IllegalStateException("component " + s.name + " CRC32C is stale (image not checksum-fixed)"); - } - if (REQUIRED_SEGMENT.equals(s.name)) { - main = s; - } - } - if (main == null) { - throw new IllegalStateException("required component " + REQUIRED_SEGMENT + " not found"); - } - checkMainAppFitsMram(img, main); - return segs; - } - - private void checkMainAppFitsMram(byte[] img, Segment main) { - if (main.ps < APP_PREAMBLE) { - throw new IllegalStateException("main-app payload is smaller than its preamble"); - } - long loadAddr = readU32(img, main.off + 128 + 0x14); - long preLen = readU32(img, main.off + 128) & 0xFFFFFFL; - if (loadAddr != APP_LOAD_ADDR) { - throw new IllegalStateException( - "main-app preamble load address is 0x" + Long.toHexString(loadAddr) - + ", expected 0x" + Long.toHexString(APP_LOAD_ADDR)); - } - if (preLen != main.ps) { - throw new IllegalStateException( - "main-app preamble length (" + preLen + ") != staged payload size (" + main.ps + ")"); - } - long progEnd = APP_LOAD_ADDR + main.ps - APP_PREAMBLE; - if (progEnd > APP_MAX_END) { - long over = progEnd - APP_MAX_END; - throw new IllegalStateException( - "main-app is too large: programmed region ends at 0x" + Long.toHexString(progEnd) - + ", " + over + " bytes past the safe MRAM ceiling — refusing to flash (brick risk)"); - } - } - - // ---- listener callbacks -------------------------------------------------- - - @Override - public void onNotification(String address, String characteristicUuid, byte[] data) { - if (BleProtocol.NOTIFY_CHAR_UUID.equalsIgnoreCase(characteristicUuid)) { - // Control channel: only the security-auth response is awaited here. - // A value can carry several envelope frames back to back (e.g. the - // response packed with one of the lens's own sid-0x80 notifies). - for (byte[] buf : BleProtocol.splitFrames(data)) { - BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(buf); - if (frame.ok && frame.sid == BleProtocol.SID_SECURITY_AUTH) { - synchronized (lock) { - if (authLatch != null && frame.msgSeq == pendingAuthMagic) { - authAckPb = frame.pb; - authLatch.countDown(); - } - } - } - } - return; - } - if (!BleProtocol.OTA_DATA_NOTIFY_UUID.equalsIgnoreCase(characteristicUuid)) { - return; // OTA acks arrive on the data-notify char - } - BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(data); - if (!frame.ok || frame.pb.length < 2) { - return; - } - dataAcks.add(Arrays.copyOf(frame.pb, Math.min(frame.pb.length, 2))); - } - - @Override - public void onConnectionStateChange(String address, boolean connected) { - if (!connected) { - Log.i(TAG, "disconnected: " + address); - } - } - - // ---- helpers ------------------------------------------------------------- - - private void teardown() { - try { - bleManager.close(); - } catch (Exception ignored) { - } - } - - private void resetSeq() { - synchronized (lock) { - nextSeq = 0; - } - } - - private int nextSeq() { - synchronized (lock) { - nextSeq = (nextSeq + 1) & 0xff; - return nextSeq; - } - } - - private void drainAcks() { - dataAcks.clear(); - } - - private static boolean isEndOk(int status) { - for (int ok : END_OK) { - if (ok == status) { - return true; - } - } - return false; - } - - private void sleepInterruptibly(int ms) { - try { - Thread.sleep(ms); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - - private static byte[] readFile(String path) { - try (FileInputStream fis = new FileInputStream(path)) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buf = new byte[65536]; - int read; - while ((read = fis.read(buf)) >= 0) { - out.write(buf, 0, read); - } - return out.toByteArray(); - } catch (IOException e) { - throw new IllegalStateException("could not read firmware: " + e.getMessage(), e); - } - } - - private static long readU32(byte[] buf, int offset) { - return (buf[offset] & 0xffL) - | ((buf[offset + 1] & 0xffL) << 8) - | ((buf[offset + 2] & 0xffL) << 16) - | ((buf[offset + 3] & 0xffL) << 24); - } - - private static String readCString(byte[] buf, int offset, int maxLen) { - int end = offset; - int limit = Math.min(buf.length, offset + maxLen); - while (end < limit && buf[end] != 0) { - end++; - } - return new String(buf, offset, end - offset, StandardCharsets.ISO_8859_1); - } - - private static final int[] CRC32C_TABLE = buildCrc32cTable(); - - private static int[] buildCrc32cTable() { - int[] table = new int[256]; - for (int b = 0; b < 256; b++) { - int c = b << 24; - for (int i = 0; i < 8; i++) { - c = (c & 0x80000000) != 0 ? (c << 1) ^ 0x1edc6f41 : c << 1; - } - table[b] = c; - } - return table; - } - - /** CRC-32C, MSB-first, init 0, no final xor (matches g2flash.py crc32c_msb). */ - private static int crc32cMsb(byte[] data) { - int crc = 0; - for (byte value : data) { - crc = (crc << 8) ^ CRC32C_TABLE[((crc >>> 24) ^ (value & 0xff)) & 0xff]; - } - return crc; - } - - private void emitLog(String line) { - Log.i(TAG, line); - mainHandler.post(() -> { - FaceclawFirmwareFlasherListener current = listener; - if (current != null) { - current.onLog(line); - } - }); - } - - private void emitProgress(String lens, int componentIndex, int componentCount, int blockIndex, int blockCount, - long bytesSent, long bytesTotal) { - mainHandler.post(() -> { - FaceclawFirmwareFlasherListener current = listener; - if (current != null) { - current.onProgress(lens, componentIndex, componentCount, blockIndex, blockCount, bytesSent, bytesTotal); - } - }); - } - - private void emitState(String state, String detail) { - final String safeDetail = detail == null ? "" : detail; - mainHandler.post(() -> { - FaceclawFirmwareFlasherListener current = listener; - if (current != null) { - current.onState(state, safeDetail); - } - }); - } - - private void emitComplete(boolean success, String detail) { - final String safeDetail = detail == null ? "" : detail; - mainHandler.post(() -> { - FaceclawFirmwareFlasherListener current = listener; - if (current != null) { - current.onComplete(success, safeDetail); - } - }); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt new file mode 100644 index 00000000..714b3377 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt @@ -0,0 +1,707 @@ +package com.faceclaw.app + +import android.bluetooth.BluetoothGatt +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.util.Log + +import java.io.ByteArrayOutputStream +import java.io.FileInputStream +import java.io.IOException +import java.nio.charset.StandardCharsets +import java.util.ArrayList +import java.util.Arrays +import java.util.concurrent.CountDownLatch +import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeoutException + +/** + * Ports g2flash.py's OTA flash procedure to Android. Streams the EVENOTA + * firmware container to each lens over the firmware-data service using the + * aa21 envelope (BleProtocol.framePb) and the c0/c1 control/data protocol. + * + * Each lens connection completes the sid-0x80 security-auth exchange before + * OTA BEGIN — firmware 2.2.9 closes unauthenticated links ~30 s in, killing + * the transfer mid-component. No control-channel traffic is injected during + * the transfer itself: official OTA captures show none between BEGIN and the + * final END, heartbeats demonstrably do not satisfy the 2.2.9 deadline, and a + * concurrent control writer would interleave with the marker/data + * transactions. (See ../notes/ble-connections-2.2.9.md.) + * + * Lenses are flashed one at a time (left, then right). Finishing either lens + * reboots BOTH lenses, so the second lens is briefly unreachable — the reconnect + * for it uses a generous window rather than failing fast. + * + * Separate from FaceclawBleCommunicator on purpose: this speaks the stock OTA + * protocol and must run before the custom firmware exists. It reuses the GATT + * wrapper (FaceclawBleManager) and framing (BleProtocol). + */ +class FaceclawFirmwareFlasher(context: Context, rightAddress: String?, leftAddress: String?, firmwarePath: String?) : FaceclawBleListener { + companion object { + private const val TAG = "FaceclawFlasher" + + // OTA message types (envelope sid byte) and control opcodes. + private const val SID_CTRL = 0xc0 + private const val SID_DATA = 0xc1 + private const val FLAG_OTA = 0x00 + private const val OP_BEGIN = 0x00 + private const val OP_FILE_CHECK = 0x01 + private const val OP_BLOCK = 0x02 + private const val OP_END = 0x03 + + private const val BLOCK_SIZE = 4096 + private const val BLOCK_ACK_TIMEOUT_MS = 4_000 + private const val CTRL_ACK_TIMEOUT_MS = 8_000 + private const val BLOCK_NAK_RETRIES = 3 + private const val COMPONENT_RETRIES = 3 + + // Reconnect windows. The first lens connects from an idle device; the second + // must ride out the post-first-lens reboot of both lenses. + private const val FIRST_LENS_CONNECT_WINDOW_MS = 30_000 + private const val SECOND_LENS_CONNECT_WINDOW_MS = 120_000 + private const val REBOOT_SETTLE_MS = 5_000 + private const val NOTIFY_SETTLE_MS = 2_500 + private const val RETRY_DELAY_MS = 2_500 + + // END ack statuses that mean "component accepted": SUCCESS, UPDATING, SYS_RESTART. + private val END_OK = intArrayOf(0, 8, 9) + + // Firmware layout expectations (mirrors g2flash.py). Firmware 2.2.4 has 5 + // components; 2.2.6 has 6. + private const val MIN_SEGMENTS = 5 + private const val MAX_SEGMENTS = 6 + private const val REQUIRED_SEGMENT = "ota/s200_firmware_ota.bin" + private const val APP_LOAD_ADDR = 0x00438000L + private const val APP_MAX_END = 0x007F0000L + private const val APP_PREAMBLE = 0x20 + + // ---- firmware container parsing / validation ----------------------------- + + private val EMPTY = ByteArray(0) + + // ---- helpers ------------------------------------------------------------- + + private fun isEndOk(status: Int): Boolean { + for (ok in END_OK) { + if (ok == status) { + return true + } + } + return false + } + + private fun readFile(path: String): ByteArray { + try { + FileInputStream(path).use { fis -> + val out = ByteArrayOutputStream() + val buf = ByteArray(65536) + var read: Int + while (fis.read(buf).also { read = it } >= 0) { + out.write(buf, 0, read) + } + return out.toByteArray() + } + } catch (e: IOException) { + throw IllegalStateException("could not read firmware: " + e.message, e) + } + } + + private fun readU32(buf: ByteArray, offset: Int): Long { + return (buf[offset].toLong() and 0xffL) or + ((buf[offset + 1].toLong() and 0xffL) shl 8) or + ((buf[offset + 2].toLong() and 0xffL) shl 16) or + ((buf[offset + 3].toLong() and 0xffL) shl 24) + } + + private fun readCString(buf: ByteArray, offset: Int, maxLen: Int): String { + var end = offset + val limit = Math.min(buf.size, offset + maxLen) + while (end < limit && buf[end].toInt() != 0) { + end++ + } + return String(buf, offset, end - offset, StandardCharsets.ISO_8859_1) + } + + private val CRC32C_TABLE: IntArray = buildCrc32cTable() + + private fun buildCrc32cTable(): IntArray { + val table = IntArray(256) + for (b in 0 until 256) { + var c = b shl 24 + for (i in 0 until 8) { + c = if ((c and 0x80000000.toInt()) != 0) (c shl 1) xor 0x1edc6f41 else c shl 1 + } + table[b] = c + } + return table + } + + /** CRC-32C, MSB-first, init 0, no final xor (matches g2flash.py crc32c_msb). */ + private fun crc32cMsb(data: ByteArray): Int { + var crc = 0 + for (value in data) { + crc = (crc shl 8) xor CRC32C_TABLE[((crc ushr 24) xor (value.toInt() and 0xff)) and 0xff] + } + return crc + } + } + + private val context: Context + private val leftAddress: String + private val rightAddress: String + private val firmwarePath: String + private val bleManager: FaceclawBleManager + private val mainHandler = Handler(Looper.getMainLooper()) + + private val lock = Any() + private val dataAcks = LinkedBlockingQueue() + + @Volatile + private var listener: FaceclawFirmwareFlasherListener? = null + @Volatile + private var worker: Thread? = null + @Volatile + private var cancelled = false + + private var nextSeq = 0 + private var nextAuthMagic = 0x60 + private var pendingAuthMagic = -1 + private var authLatch: CountDownLatch? = null + private var authAckPb: ByteArray? = null + + init { + this.context = context.applicationContext + this.rightAddress = rightAddress ?: "" + this.leftAddress = leftAddress ?: "" + this.firmwarePath = firmwarePath ?: "" + this.bleManager = FaceclawBleManager(this.context) + this.bleManager.setListener(this) + } + + fun setListener(listener: FaceclawFirmwareFlasherListener?) { + this.listener = listener + } + + fun start() { + synchronized(lock) { + if (worker != null) { + return + } + val w = Thread({ run() }, "faceclaw-flasher") + worker = w + w.start() + } + } + + fun cancel() { + cancelled = true + val w = worker + if (w != null) { + w.interrupt() + } + } + + fun close() { + cancel() + try { + bleManager.close() + } catch (ignored: Exception) { + } + } + + private fun run() { + try { + if (leftAddress.trim().isEmpty() || rightAddress.trim().isEmpty()) { + throw IllegalStateException("Both lens addresses are required to flash.") + } + + emitState("validating", "") + val img = readFile(firmwarePath) + val segs = validate(img) + emitLog("firmware validated: " + segs.size + " components, " + img.size + " bytes") + + flashLens("left", leftAddress, img, segs, FIRST_LENS_CONNECT_WINDOW_MS) + if (cancelled) { + emitState("error", "Cancelled.") + emitComplete(false, "Cancelled after the left lens.") + return + } + + emitState("rebooting", "Left lens done. Both lenses reboot briefly; reconnecting for the right lens.") + sleepInterruptibly(REBOOT_SETTLE_MS) + flashLens("right", rightAddress, img, segs, SECOND_LENS_CONNECT_WINDOW_MS) + + emitState("done", "") + emitComplete(true, "Both lenses flashed. The glasses are rebooting into the custom firmware.") + } catch (e: Exception) { + var message = if (e.message == null) e.toString() else e.message + if (cancelled) { + message = "Cancelled." + } + emitState("error", message) + emitComplete(false, message) + } finally { + teardown() + } + } + + @Throws(TimeoutException::class) + private fun flashLens(lens: String, address: String, img: ByteArray, segs: List, connectWindowMs: Int) { + emitState("connecting", lens) + connectLensResilient(lens, address, connectWindowMs) + sleepInterruptibly(NOTIFY_SETTLE_MS) + drainAcks() + // Fresh envelope counter for the OTA stream (the auth exchange during + // bring-up used its own); mirrors the stock sequence. + resetSeq() + + emitState("flashing", lens) + val beginStatus = sendCtrlAndWait(address, OP_BEGIN, EMPTY, CTRL_ACK_TIMEOUT_MS) + if (!isEndOk(beginStatus)) { + emitLog("warning: unexpected begin status $beginStatus; continuing") + } + // Progress is reported in bytes across the whole image: the segments + // are one large firmware blob plus several small ones, so a bar + // stepped per segment would sit still through the big one and then + // sprint through the rest. + var totalBytes = 0L + for (seg in segs) { + totalBytes += seg.ps + } + var bytesBefore = 0L + for (i in segs.indices) { + if (cancelled) { + throw IllegalStateException("Cancelled.") + } + flashComponentWithRetry(lens, address, i, segs.size, segs[i], img, bytesBefore, totalBytes) + bytesBefore += segs[i].ps + } + emitLog("$lens lens: all components verified") + try { + bleManager.disconnect(address) + } catch (ignored: Exception) { + } + } + + private fun flashComponentWithRetry(lens: String, address: String, index: Int, count: Int, seg: Segment, img: ByteArray, + bytesBefore: Long, totalBytes: Long) { + for (attempt in 0 until COMPONENT_RETRIES) { + if (attempt > 0) { + emitLog(seg.name + ": re-flash attempt " + (attempt + 1) + "/" + COMPONENT_RETRIES) + } + var endStatus: Int + try { + endStatus = flashComponent(lens, address, index, count, seg, img, bytesBefore, totalBytes) + } catch (e: TimeoutException) { + emitLog(seg.name + ": block phase failed: " + e.message) + endStatus = -1 + } catch (e: RuntimeException) { + emitLog(seg.name + ": block phase failed: " + e.message) + endStatus = -1 + } + if (isEndOk(endStatus)) { + emitLog(seg.name + ": END verify OK (status " + endStatus + ")") + return + } + if (endStatus >= 0) { + emitLog(seg.name + ": END verify FAILED (status " + endStatus + ")") + } + drainAcks() + sleepInterruptibly(1_500) + } + throw IllegalStateException("component " + seg.name + " failed after " + COMPONENT_RETRIES + " attempts") + } + + @Throws(TimeoutException::class) + private fun flashComponent(lens: String, address: String, index: Int, count: Int, seg: Segment, img: ByteArray, + bytesBefore: Long, totalBytes: Long): Int { + val sub = Arrays.copyOfRange(img, seg.off, seg.off + 128) + val ps = seg.ps + val payloadStart = seg.off + 128 + + val checkStatus = sendCtrlAndWait(address, OP_FILE_CHECK, sub, CTRL_ACK_TIMEOUT_MS) + if (checkStatus != 0) { + throw IllegalStateException("FILE_CHECK rejected status=$checkStatus") + } + + val blockCount = (ps + BLOCK_SIZE - 1) / BLOCK_SIZE + for (b in 0 until blockCount) { + if (cancelled) { + throw IllegalStateException("Cancelled.") + } + val start = payloadStart + b * BLOCK_SIZE + val end = Math.min(start + BLOCK_SIZE, payloadStart + ps) + val block = Arrays.copyOfRange(img, start, end) + + var accepted = false + for (tries in 0 until BLOCK_NAK_RETRIES) { + val status = sendBlock(address, block) // throws TimeoutException -> component re-flash + if (status == 0) { + accepted = true + break + } + emitLog(seg.name + ": block " + b + "/" + blockCount + " NAK=" + status + + " resend " + (tries + 1) + "/" + BLOCK_NAK_RETRIES) + } + if (!accepted) { + throw IllegalStateException("block " + b + " NAK'd " + BLOCK_NAK_RETRIES + " times") + } + if (b % 20 == 0 || b == blockCount - 1) { + val bytesSent = bytesBefore + Math.min((b + 1).toLong() * BLOCK_SIZE, ps.toLong()) + emitProgress(lens, index + 1, count, b + 1, blockCount, bytesSent, totalBytes) + } + } + emitLog(seg.name + ": data phase done; sending END") + return sendCtrlAndWait(address, OP_END, EMPTY, CTRL_ACK_TIMEOUT_MS) + } + + /** Send one 4 KB block as a marker + data pair sharing one envelope seq. */ + @Throws(TimeoutException::class) + private fun sendBlock(address: String, block: ByteArray): Int { + val seq = nextSeq() + drainAcks() + writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_CTRL, byteArrayOf(OP_BLOCK.toByte()), seq) + writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_DATA, block, seq) + return waitAck(OP_BLOCK, BLOCK_ACK_TIMEOUT_MS) + } + + @Throws(TimeoutException::class) + private fun sendCtrlAndWait(address: String, op: Int, data: ByteArray, timeoutMs: Int): Int { + val seq = nextSeq() + drainAcks() + val payload = ByteArray(1 + data.size) + payload[0] = op.toByte() + System.arraycopy(data, 0, payload, 1, data.size) + writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_CTRL, payload, seq) + return waitAck(op, timeoutMs) + } + + private fun writeOta(address: String, writeChar: String, sid: Int, payload: ByteArray, seq: Int): Boolean { + val frames = BleProtocol.framePb(payload, sid, FLAG_OTA, seq) + return bleManager.writeFrames( + address, writeChar, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS) + } + + @Throws(TimeoutException::class) + private fun waitAck(wantOp: Int, timeoutMs: Int): Int { + val deadline = SystemClock.elapsedRealtime() + timeoutMs + while (true) { + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + break + } + val pb: ByteArray? + try { + pb = dataAcks.poll(remaining, TimeUnit.MILLISECONDS) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + throw TimeoutException("interrupted waiting for ack op=$wantOp") + } + if (pb == null) { + break + } + if (pb.size >= 2 && (pb[0].toInt() and 0xff) == wantOp) { + return pb[1].toInt() and 0xff + } + // Different opcode (e.g. a late ack from a prior stage) — ignore, keep waiting. + } + throw TimeoutException("no ack op=0x" + Integer.toHexString(wantOp) + " within " + timeoutMs + "ms") + } + + // ---- connection ---------------------------------------------------------- + + private fun connectLensResilient(lens: String, address: String, windowMs: Int) { + val deadline = SystemClock.elapsedRealtime() + windowMs + var lastError: String? = "unknown" + var attempt = 0 + while (SystemClock.elapsedRealtime() < deadline && !cancelled) { + attempt++ + try { + if (bringUpLens(address)) { + emitLog("connected $lens lens (attempt $attempt)") + return + } + lastError = "connect/discover incomplete" + } catch (e: Exception) { + lastError = if (e.message == null) e.toString() else e.message + } + emitLog("$lens connect attempt $attempt failed ($lastError); retrying...") + try { + bleManager.disconnect(address) + } catch (ignored: Exception) { + } + sleepInterruptibly(RETRY_DELAY_MS) + } + if (cancelled) { + throw IllegalStateException("Cancelled.") + } + throw IllegalStateException("could not reach $lens lens: $lastError") + } + + private fun bringUpLens(address: String): Boolean { + if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { + return false + } + bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) + bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) + if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { + return false + } + // Control-channel notify carries the auth response; mandatory. + if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { + return false + } + if (!bleManager.enableNotifications(address, BleProtocol.OTA_DATA_NOTIFY_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { + return false + } + if (!authenticate(address)) { + throw IllegalStateException( + "security auth not acknowledged — if Android shows a Bluetooth pairing request, accept it") + } + return true + } + + /** + * Complete the sid-0x80 security-auth exchange on this connection. On an + * unbonded phone this triggers SMP pairing (possibly with an OS prompt), + * so the wait is generous. Must succeed before any OTA traffic. + */ + private fun authenticate(address: String): Boolean { + val magic: Int + val latch = CountDownLatch(1) + synchronized(lock) { + magic = nextAuthMagic + nextAuthMagic = if (nextAuthMagic >= 0x7f) 0x60 else nextAuthMagic + 1 + pendingAuthMagic = magic + authAckPb = null + authLatch = latch + } + try { + if (!writeOta(address, BleProtocol.WRITE_CHAR_UUID, BleProtocol.SID_SECURITY_AUTH, + BleProtocol.buildAuthenticationRequest(magic), nextSeq())) { + emitLog("auth write failed: $address") + return false + } + val signalled: Boolean + try { + signalled = latch.await(ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + return false + } + val pb: ByteArray? + synchronized(lock) { + pb = authAckPb + } + if (!signalled || !BleProtocol.isAuthenticationSuccess(pb, magic)) { + emitLog("security auth not acknowledged (" + address + + ") — if Android shows a Bluetooth pairing request, accept it") + return false + } + emitLog("security auth complete: $address") + return true + } finally { + synchronized(lock) { + pendingAuthMagic = -1 + authLatch = null + } + } + } + + // ---- firmware container parsing / validation ----------------------------- + + private class Segment( + @JvmField val off: Int, + @JvmField val ps: Int, + @JvmField val crc: Long, + @JvmField val name: String + ) + + private fun parseSegments(img: ByteArray): List { + if (img.size < 0x40) { + throw IllegalStateException("file is too small to be a firmware image") + } + val n = readU32(img, 8) + if (n <= 0 || n > 64) { + throw IllegalStateException("implausible component count $n (corrupt image?)") + } + val segs = ArrayList() + var i = 0 + while (i < n) { + val base = 0x40 + i * 16 + val crc = readU32(img, base + 12) + val off = readU32(img, base + 4).toInt() + if (off + 128 > img.size) { + throw IllegalStateException("segment $i subheader runs past end of file") + } + val ps = readU32(img, off + 8).toInt() + val name = readCString(img, off + 48, 80) + segs.add(Segment(off, ps, crc, name)) + i++ + } + return segs + } + + private fun validate(img: ByteArray): List { + val segs = parseSegments(img) + if (segs.size < MIN_SEGMENTS || segs.size > MAX_SEGMENTS) { + throw IllegalStateException( + "expected " + MIN_SEGMENTS + "-" + MAX_SEGMENTS + " components, found " + segs.size) + } + var main: Segment? = null + for (s in segs) { + val payload = Arrays.copyOfRange(img, s.off + 128, s.off + 128 + s.ps) + val calc = crc32cMsb(payload).toLong() and 0xffffffffL + val subCrc = readU32(img, s.off + 12) + if (calc != s.crc || calc != subCrc) { + throw IllegalStateException("component " + s.name + " CRC32C is stale (image not checksum-fixed)") + } + if (REQUIRED_SEGMENT == s.name) { + main = s + } + } + if (main == null) { + throw IllegalStateException("required component $REQUIRED_SEGMENT not found") + } + checkMainAppFitsMram(img, main) + return segs + } + + private fun checkMainAppFitsMram(img: ByteArray, main: Segment) { + if (main.ps < APP_PREAMBLE) { + throw IllegalStateException("main-app payload is smaller than its preamble") + } + val loadAddr = readU32(img, main.off + 128 + 0x14) + val preLen = readU32(img, main.off + 128) and 0xFFFFFFL + if (loadAddr != APP_LOAD_ADDR) { + throw IllegalStateException( + "main-app preamble load address is 0x" + java.lang.Long.toHexString(loadAddr) + + ", expected 0x" + java.lang.Long.toHexString(APP_LOAD_ADDR)) + } + if (preLen != main.ps.toLong()) { + throw IllegalStateException( + "main-app preamble length (" + preLen + ") != staged payload size (" + main.ps + ")") + } + val progEnd = APP_LOAD_ADDR + main.ps - APP_PREAMBLE + if (progEnd > APP_MAX_END) { + val over = progEnd - APP_MAX_END + throw IllegalStateException( + "main-app is too large: programmed region ends at 0x" + java.lang.Long.toHexString(progEnd) + + ", " + over + " bytes past the safe MRAM ceiling — refusing to flash (brick risk)") + } + } + + // ---- listener callbacks -------------------------------------------------- + + override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { + if (BleProtocol.NOTIFY_CHAR_UUID.equals(characteristicUuid, ignoreCase = true)) { + // Control channel: only the security-auth response is awaited here. + // A value can carry several envelope frames back to back (e.g. the + // response packed with one of the lens's own sid-0x80 notifies). + for (buf in BleProtocol.splitFrames(data)) { + val frame = BleProtocol.parseFrame(buf) + if (frame.ok && frame.sid == BleProtocol.SID_SECURITY_AUTH) { + synchronized(lock) { + val currentLatch = authLatch + if (currentLatch != null && frame.msgSeq == pendingAuthMagic) { + authAckPb = frame.pb + currentLatch.countDown() + } + } + } + } + return + } + if (!BleProtocol.OTA_DATA_NOTIFY_UUID.equals(characteristicUuid, ignoreCase = true)) { + return // OTA acks arrive on the data-notify char + } + val frame = BleProtocol.parseFrame(data) + if (!frame.ok || frame.pb.size < 2) { + return + } + dataAcks.add(Arrays.copyOf(frame.pb, Math.min(frame.pb.size, 2))) + } + + override fun onConnectionStateChange(address: String?, connected: Boolean) { + if (!connected) { + Log.i(TAG, "disconnected: $address") + } + } + + // ---- helpers ------------------------------------------------------------- + + private fun teardown() { + try { + bleManager.close() + } catch (ignored: Exception) { + } + } + + private fun resetSeq() { + synchronized(lock) { + nextSeq = 0 + } + } + + private fun nextSeq(): Int { + synchronized(lock) { + nextSeq = (nextSeq + 1) and 0xff + return nextSeq + } + } + + private fun drainAcks() { + dataAcks.clear() + } + + private fun sleepInterruptibly(ms: Int) { + try { + Thread.sleep(ms.toLong()) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + } + } + + private fun emitLog(line: String) { + Log.i(TAG, line) + mainHandler.post { + val current = listener + if (current != null) { + current.onLog(line) + } + } + } + + private fun emitProgress(lens: String, componentIndex: Int, componentCount: Int, blockIndex: Int, blockCount: Int, + bytesSent: Long, bytesTotal: Long) { + mainHandler.post { + val current = listener + if (current != null) { + current.onProgress(lens, componentIndex, componentCount, blockIndex, blockCount, bytesSent, bytesTotal) + } + } + } + + private fun emitState(state: String, detail: String?) { + val safeDetail = detail ?: "" + mainHandler.post { + val current = listener + if (current != null) { + current.onState(state, safeDetail) + } + } + } + + private fun emitComplete(success: Boolean, detail: String?) { + val safeDetail = detail ?: "" + mainHandler.post { + val current = listener + if (current != null) { + current.onComplete(success, safeDetail) + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java deleted file mode 100644 index ef342706..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java +++ /dev/null @@ -1,546 +0,0 @@ -package com.faceclaw.app; - -import android.bluetooth.BluetoothGatt; -import android.content.Context; -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -/** - * A minimal, stock-firmware-compatible BLE communicator used only to show the - * pre-flash confirmation prompt on the glasses and read back the user's Yes/No - * choice. It is deliberately separate from FaceclawBleCommunicator: the main - * app assumes the custom firmware (image containers, compositor, etc.), whereas - * this must work on unmodified glasses, so it speaks only the stock subset — - * session prelude, a text container, a list container, and heartbeats. No - * images. - * - * It reuses the low-level GATT wrapper (FaceclawBleManager) and the framing / - * protobuf helpers (BleProtocol), but owns its own GATT connection and runs its - * whole lifecycle on a single worker thread. It expects the main app to be - * disconnected while it runs (onboarding, before flashing). - * - * Both arms are connected and security-authenticated up front, even though the - * prompt itself only needs the right arm (the lenses relay messages to each - * other, and acks/events only ever come from the right arm): on an unbonded - * phone the auth exchange is what raises the OS pairing prompt, and doing both - * here means both prompts appear at the start rather than one popping up half - * way through flashing the second lens. While connected, each arm's battery - * level is read (they are independent batteries) so the caller can refuse to - * flash on a low charge. - * - * With `skipPrompt` the on-glasses confirmation is not shown: the flow is just - * connect + auth + battery read + result(approved). Used to re-check the - * battery after the user has already confirmed once. - */ -public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { - private static final String TAG = "FaceclawFlashPrompt"; - - private static final String TEXT_NAME = "flashwarn"; - private static final String LIST_NAME = "flashmenu"; - private static final int TEXT_CONTAINER_ID = 1; - private static final int LIST_CONTAINER_ID = 2; - // Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid. - private static final String[] ITEMS = new String[] {"No, cancel", "Yes, flash"}; - - private static final int HEARTBEAT_INTERVAL_MS = 4_000; - private static final int SELECTION_TIMEOUT_MS = 120_000; - private static final int CREATE_ACK_TIMEOUT_MS = 3_000; - private static final int BATTERY_ACK_TIMEOUT_MS = 3_000; - - private final Context context; - private final String rightAddress; - private final String leftAddress; - private final String warningText; - private final boolean skipPrompt; - private final FaceclawBleManager bleManager; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - - private final Object lock = new Object(); - private final ConcurrentHashMap pendingAcks = new ConcurrentHashMap<>(); - private final ConcurrentHashMap ackPayloads = new ConcurrentHashMap<>(); - private final CountDownLatch selectionLatch = new CountDownLatch(1); - - private volatile FaceclawFlashPromptListener listener; - private volatile Thread worker; - private volatile boolean cancelled = false; - private volatile boolean finished = false; - private volatile boolean rightConnected = false; - private volatile boolean leftConnected = false; - private volatile boolean rightLost = false; - private volatile Boolean approved = null; - private volatile ScheduledExecutorService heartbeatExecutor; - - private int nextMagic = 100; - private int nextSeq = 0x40; - - public FaceclawFlashPromptCommunicator( - Context context, String rightAddress, String leftAddress, String warningText, boolean skipPrompt) { - this.context = context.getApplicationContext(); - this.rightAddress = rightAddress == null ? "" : rightAddress; - this.leftAddress = leftAddress == null ? "" : leftAddress; - this.warningText = warningText == null ? "" : warningText; - this.skipPrompt = skipPrompt; - this.bleManager = new FaceclawBleManager(this.context); - this.bleManager.setListener(this); - } - - public void setListener(FaceclawFlashPromptListener listener) { - this.listener = listener; - } - - public void start() { - synchronized (lock) { - if (worker != null) { - return; - } - worker = new Thread(this::run, "faceclaw-flash-prompt"); - worker.start(); - } - } - - /** Abort the prompt (e.g. the user backed out on the phone). */ - public void cancel() { - cancelled = true; - selectionLatch.countDown(); - Thread w = worker; - if (w != null) { - w.interrupt(); - } - } - - public void close() { - cancel(); - stopHeartbeat(); - try { - bleManager.close(); - } catch (Exception ignored) { - } - } - - private void run() { - try { - if (rightAddress.trim().isEmpty()) { - emitState("error", "No right-arm address configured."); - return; - } - - emitState("connecting", ""); - connectArm(rightAddress, "right"); - rightConnected = true; - if (cancelled) { - teardown(); - return; - } - if (!leftAddress.trim().isEmpty()) { - connectArm(leftAddress, "left"); - leftConnected = true; - if (cancelled) { - teardown(); - return; - } - } - - emitState("connected", ""); - // Auth both arms now (pairing prompts, if any, happen here) before - // anything else, so both bonds exist by the time flashing starts. - authenticateArm(rightAddress, "right"); - if (leftConnected) { - authenticateArm(leftAddress, "left"); - } - if (cancelled) { - teardown(); - return; - } - sendPrelude(rightAddress); - - if (!skipPrompt) { - showPrompt(rightAddress); - startHeartbeat(); - emitState("prompting", ""); - - selectionLatch.await(SELECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); - stopHeartbeat(); - - if (cancelled) { - emitState("cancelled", ""); - teardown(); - return; - } - if (approved == null) { - if (rightLost) { - emitState("disconnected", "Lost connection to the glasses."); - } else { - emitState("timeout", "No response from the glasses."); - } - teardown(); - return; - } - try { - sendShutdown(); - } catch (Exception ignored) { - } - if (!Boolean.TRUE.equals(approved)) { - emitResult(false); - emitState("result", "declined"); - teardown(); - return; - } - } - - // Approved (or prompt skipped): read each arm's battery while the - // links are still up, then report the result. - emitState("battery", ""); - readBatteries(); - if (cancelled) { - emitState("cancelled", ""); - teardown(); - return; - } - if (rightLost) { - emitState("disconnected", "Lost connection to the glasses."); - teardown(); - return; - } - finished = true; - emitResult(true); - emitState("result", "approved"); - teardown(); - } catch (Exception e) { - stopHeartbeat(); - if (!cancelled) { - String message = e.getMessage() == null ? e.toString() : e.getMessage(); - emitState("error", message); - } - teardown(); - } - } - - private void connectArm(String address, String arm) { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw new IllegalStateException("could not connect to the " + arm + " arm (" + address + ")"); - } - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH); - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS); - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw new IllegalStateException("discoverServices failed: " + arm + " arm (" + address + ")"); - } - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - throw new IllegalStateException("enableNotifications failed: " + arm + " arm (" + address + ")"); - } - emitLog("connected " + arm + " arm"); - } - - /** - * Security-auth exchange on sid=0x80: firmware 2.2.9 will not run a - * session (and closes the link after ~30 s) without it, and on an - * unbonded phone this is what triggers SMP pairing, so it may sit - * waiting on an OS pairing prompt. - */ - private void authenticateArm(String address, String arm) throws InterruptedException { - int authMagic = allocMagic(); - byte[] authAck = writeAndAwaitAck( - address, - BleProtocol.SID_SECURITY_AUTH, - BleProtocol.FLAG_SECURITY_AUTH, - authMagic, - BleProtocol.buildAuthenticationRequest(authMagic), - ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS); - if (authAck == null || !BleProtocol.isAuthenticationSuccess(authAck, authMagic)) { - throw new IllegalStateException( - "could not authenticate with the " + arm + " arm (" + address - + ") — if Android shows a Bluetooth pairing request, accept it and try again"); - } - emitLog("security auth complete: " + arm + " arm"); - } - - /** Mandatory session prelude on sid=0x01 (app-launch). Right arm only; it relays. */ - private void sendPrelude(String address) throws InterruptedException { - if (writeAndAwaitAck( - address, - BleProtocol.PRELUDE_ACK_SID, - BleProtocol.FLAG_REQUEST, - BleProtocol.PRELUDE_ACK_MAGIC, - BleProtocol.PRELUDE_F5872_PAYLOAD, - ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) { - throw new IllegalStateException("session prelude not acked: " + address); - } - } - - private void showPrompt(String address) throws InterruptedException { - // Create the prompt page (warning text + No/Yes list) on sid=0xe0 Cmd=0. - // Two attempts: on 2.2.9 the first request sent right after the - // prelude can be dropped while the lens emits its own sid-0x80 - // notifications (observed with the device-info settings read). - byte[] pageAck = null; - for (int attempt = 0; attempt < 2 && pageAck == null && !cancelled; attempt++) { - int magic = allocMagic(); - byte[] page = BleProtocol.buildCreatePromptPage( - magic, TEXT_NAME, TEXT_CONTAINER_ID, warningText, LIST_NAME, LIST_CONTAINER_ID, ITEMS); - pageAck = writeAndAwaitAck(address, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, magic, page, CREATE_ACK_TIMEOUT_MS); - if (pageAck == null) { - emitLog("prompt page attempt " + (attempt + 1) + " unacked: " + address); - } - } - if (pageAck == null) { - throw new IllegalStateException("prompt page not acked: " + address); - } - emitLog("prompt page shown on " + address); - } - - /** - * Read each arm's battery via a sid-0x09 settings read on that arm's own - * link (the arms have independent batteries and each answers with its - * own). An arm that does not answer reports -1; the caller decides what - * to do with a partial reading. - */ - private void readBatteries() throws InterruptedException { - int right = rightConnected ? readBattery(rightAddress, "right") : -1; - int left = leftConnected ? readBattery(leftAddress, "left") : -1; - emitLog("battery R=" + (right < 0 ? "?" : right + "%") + " L=" + (left < 0 ? "?" : left + "%")); - emitBattery(right, left); - } - - private int readBattery(String address, String arm) throws InterruptedException { - for (int attempt = 0; attempt < 2 && !cancelled; attempt++) { - int magic = allocMagic(); - byte[] ack = writeAndAwaitAck( - address, - BleProtocol.SID_UI_SETTING, - BleProtocol.FLAG_REQUEST, - magic, - BleProtocol.buildSettingsQuery(magic), - BATTERY_ACK_TIMEOUT_MS); - if (ack == null) { - emitLog("battery read attempt " + (attempt + 1) + " unacked: " + arm + " arm"); - continue; - } - BleProtocol.BatterySnapshot snapshot = BleProtocol.parseSettingsBattery(ack); - if (snapshot != null) { - return snapshot.battery; - } - emitLog("battery read ack had no battery field: " + arm + " arm"); - } - return -1; - } - - /** Write and wait for the matching ack; returns the ack's protobuf (may be empty), or null on timeout/write failure. */ - private byte[] writeAndAwaitAck(String address, int sid, int flag, int magic, byte[] payload, int timeoutMs) - throws InterruptedException { - CountDownLatch latch = new CountDownLatch(1); - String key = ackKey(sid, magic); - pendingAcks.put(key, latch); - try { - if (!writeFrame(address, sid, flag, payload)) { - return null; - } - if (!latch.await(timeoutMs, TimeUnit.MILLISECONDS)) { - return null; - } - byte[] pb = ackPayloads.get(key); - return pb == null ? new byte[0] : pb; - } finally { - pendingAcks.remove(key, latch); - ackPayloads.remove(key); - } - } - - private boolean writeFrame(String address, int sid, int flag, byte[] payload) { - int seq; - synchronized (lock) { - seq = nextSeq++ & 0xff; - } - List frames = BleProtocol.framePb(payload, sid, flag, seq); - return bleManager.writeFrames( - address, - BleProtocol.WRITE_CHAR_UUID, - frames, - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS); - } - - private void startHeartbeat() { - stopHeartbeat(); - ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(runnable -> { - Thread t = new Thread(runnable, "faceclaw-flash-hb"); - t.setDaemon(true); - return t; - }); - heartbeatExecutor = executor; - executor.scheduleWithFixedDelay( - this::sendHeartbeat, HEARTBEAT_INTERVAL_MS, HEARTBEAT_INTERVAL_MS, TimeUnit.MILLISECONDS); - } - - private void sendHeartbeat() { - if (finished || cancelled) { - return; - } - try { - byte[] heartbeat = BleProtocol.buildHeartbeat(allocMagic()); - if (rightConnected) { - writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat); - } - } catch (Exception e) { - Log.w(TAG, "heartbeat failed: " + e.getMessage()); - } - } - - private void stopHeartbeat() { - ScheduledExecutorService executor = heartbeatExecutor; - heartbeatExecutor = null; - if (executor != null) { - executor.shutdownNow(); - } - } - - private void sendShutdown() { - byte[] shutdown = BleProtocol.buildShutdown(allocMagic(), 0); - if (rightConnected) { - writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown); - } - } - - private void teardown() { - finished = true; - stopHeartbeat(); - try { - bleManager.close(); - } catch (Exception ignored) { - } - rightConnected = false; - leftConnected = false; - } - - @Override - public void onNotification(String address, String characteristicUuid, byte[] data) { - if (!BleProtocol.NOTIFY_CHAR_UUID.equalsIgnoreCase(characteristicUuid)) { - return; - } - // A value can carry several envelope frames back to back. - for (byte[] buf : BleProtocol.splitFrames(data)) { - handleFrame(address, buf); - } - } - - private void handleFrame(String address, byte[] buf) { - BleProtocol.ParsedFrame frame = BleProtocol.parseFrame(buf); - if (!frame.ok) { - return; - } - if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { - handleEvent(frame); - return; - } - if (frame.msgSeq >= 0) { - String key = ackKey(frame.sid, frame.msgSeq); - CountDownLatch latch = pendingAcks.get(key); - if (latch != null) { - ackPayloads.put(key, frame.pb); - latch.countDown(); - } - } - } - - private void handleEvent(BleProtocol.ParsedFrame frame) { - BleProtocol.ListSelection selection = BleProtocol.parseListSelection(frame); - if (selection == null || !LIST_NAME.equals(selection.containerName)) { - return; - } - // Only a confirmed click is a decision; scroll/highlight changes are ignored. - if (selection.eventType != BleProtocol.EVENT_CLICK) { - return; - } - boolean yes = selection.itemIndex == 1 - || (selection.itemName != null && selection.itemName.toLowerCase().startsWith("yes")); - synchronized (lock) { - if (finished) { - return; - } - finished = true; - approved = yes; - } - emitLog("selection: " + (yes ? "flash" : "cancel") + " (index " + selection.itemIndex + ")"); - selectionLatch.countDown(); - } - - @Override - public void onConnectionStateChange(String address, boolean connected) { - if (connected) { - return; - } - if (address.equalsIgnoreCase(leftAddress)) { - // The prompt itself only needs the right arm; a dropped left link - // just means no left battery reading. - leftConnected = false; - emitLog("left arm disconnected"); - return; - } - if (address.equalsIgnoreCase(rightAddress)) { - rightConnected = false; - synchronized (lock) { - if (!finished && !cancelled) { - rightLost = true; - finished = true; - selectionLatch.countDown(); - } - } - } - } - - private int allocMagic() { - synchronized (lock) { - int magic = nextMagic; - nextMagic = nextMagic >= 255 ? 100 : nextMagic + 1; - return magic; - } - } - - private static String ackKey(int sid, int magic) { - return sid + ":" + magic; - } - - private void emitLog(String line) { - Log.i(TAG, line); - mainHandler.post(() -> { - FaceclawFlashPromptListener current = listener; - if (current != null) { - current.onLog(line); - } - }); - } - - private void emitState(String state, String detail) { - final String safeDetail = detail == null ? "" : detail; - mainHandler.post(() -> { - FaceclawFlashPromptListener current = listener; - if (current != null) { - current.onState(state, safeDetail); - } - }); - } - - private void emitBattery(int rightPercent, int leftPercent) { - mainHandler.post(() -> { - FaceclawFlashPromptListener current = listener; - if (current != null) { - current.onBattery(rightPercent, leftPercent); - } - }); - } - - private void emitResult(boolean approvedResult) { - mainHandler.post(() -> { - FaceclawFlashPromptListener current = listener; - if (current != null) { - current.onResult(approvedResult); - } - }); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt new file mode 100644 index 00000000..b3cf1d83 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt @@ -0,0 +1,566 @@ +package com.faceclaw.app + +import android.bluetooth.BluetoothGatt +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.util.Log + +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CountDownLatch +import java.util.concurrent.Executors +import java.util.concurrent.ScheduledExecutorService +import java.util.concurrent.TimeUnit + +/** + * A minimal, stock-firmware-compatible BLE communicator used only to show the + * pre-flash confirmation prompt on the glasses and read back the user's Yes/No + * choice. It is deliberately separate from FaceclawBleCommunicator: the main + * app assumes the custom firmware (image containers, compositor, etc.), whereas + * this must work on unmodified glasses, so it speaks only the stock subset — + * session prelude, a text container, a list container, and heartbeats. No + * images. + * + * It reuses the low-level GATT wrapper (FaceclawBleManager) and the framing / + * protobuf helpers (BleProtocol), but owns its own GATT connection and runs its + * whole lifecycle on a single worker thread. It expects the main app to be + * disconnected while it runs (onboarding, before flashing). + * + * Both arms are connected and security-authenticated up front, even though the + * prompt itself only needs the right arm (the lenses relay messages to each + * other, and acks/events only ever come from the right arm): on an unbonded + * phone the auth exchange is what raises the OS pairing prompt, and doing both + * here means both prompts appear at the start rather than one popping up half + * way through flashing the second lens. While connected, each arm's battery + * level is read (they are independent batteries) so the caller can refuse to + * flash on a low charge. + * + * With `skipPrompt` the on-glasses confirmation is not shown: the flow is just + * connect + auth + battery read + result(approved). Used to re-check the + * battery after the user has already confirmed once. + */ +class FaceclawFlashPromptCommunicator( + context: Context, rightAddress: String?, leftAddress: String?, warningText: String?, skipPrompt: Boolean) : FaceclawBleListener { + companion object { + private const val TAG = "FaceclawFlashPrompt" + + private const val TEXT_NAME = "flashwarn" + private const val LIST_NAME = "flashmenu" + private const val TEXT_CONTAINER_ID = 1 + private const val LIST_CONTAINER_ID = 2 + // Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid. + private val ITEMS = arrayOf("No, cancel", "Yes, flash") + + private const val HEARTBEAT_INTERVAL_MS = 4_000 + private const val SELECTION_TIMEOUT_MS = 120_000 + private const val CREATE_ACK_TIMEOUT_MS = 3_000 + private const val BATTERY_ACK_TIMEOUT_MS = 3_000 + + private fun ackKey(sid: Int, magic: Int): String { + return "$sid:$magic" + } + } + + private val context: Context + private val rightAddress: String + private val leftAddress: String + private val warningText: String + private val skipPrompt: Boolean + private val bleManager: FaceclawBleManager + private val mainHandler = Handler(Looper.getMainLooper()) + + private val lock = Any() + private val pendingAcks = ConcurrentHashMap() + private val ackPayloads = ConcurrentHashMap() + private val selectionLatch = CountDownLatch(1) + + @Volatile + private var listener: FaceclawFlashPromptListener? = null + @Volatile + private var worker: Thread? = null + @Volatile + private var cancelled = false + @Volatile + private var finished = false + @Volatile + private var rightConnected = false + @Volatile + private var leftConnected = false + @Volatile + private var rightLost = false + @Volatile + private var approved: Boolean? = null + @Volatile + private var heartbeatExecutor: ScheduledExecutorService? = null + + private var nextMagic = 100 + private var nextSeq = 0x40 + + init { + this.context = context.applicationContext + this.rightAddress = rightAddress ?: "" + this.leftAddress = leftAddress ?: "" + this.warningText = warningText ?: "" + this.skipPrompt = skipPrompt + this.bleManager = FaceclawBleManager(this.context) + this.bleManager.setListener(this) + } + + fun setListener(listener: FaceclawFlashPromptListener?) { + this.listener = listener + } + + fun start() { + synchronized(lock) { + if (worker != null) { + return + } + val w = Thread({ run() }, "faceclaw-flash-prompt") + worker = w + w.start() + } + } + + /** Abort the prompt (e.g. the user backed out on the phone). */ + fun cancel() { + cancelled = true + selectionLatch.countDown() + val w = worker + if (w != null) { + w.interrupt() + } + } + + fun close() { + cancel() + stopHeartbeat() + try { + bleManager.close() + } catch (ignored: Exception) { + } + } + + private fun run() { + try { + if (rightAddress.trim().isEmpty()) { + emitState("error", "No right-arm address configured.") + return + } + + emitState("connecting", "") + connectArm(rightAddress, "right") + rightConnected = true + if (cancelled) { + teardown() + return + } + if (!leftAddress.trim().isEmpty()) { + connectArm(leftAddress, "left") + leftConnected = true + if (cancelled) { + teardown() + return + } + } + + emitState("connected", "") + // Auth both arms now (pairing prompts, if any, happen here) before + // anything else, so both bonds exist by the time flashing starts. + authenticateArm(rightAddress, "right") + if (leftConnected) { + authenticateArm(leftAddress, "left") + } + if (cancelled) { + teardown() + return + } + sendPrelude(rightAddress) + + if (!skipPrompt) { + showPrompt(rightAddress) + startHeartbeat() + emitState("prompting", "") + + selectionLatch.await(SELECTION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS) + stopHeartbeat() + + if (cancelled) { + emitState("cancelled", "") + teardown() + return + } + if (approved == null) { + if (rightLost) { + emitState("disconnected", "Lost connection to the glasses.") + } else { + emitState("timeout", "No response from the glasses.") + } + teardown() + return + } + try { + sendShutdown() + } catch (ignored: Exception) { + } + if (approved != true) { + emitResult(false) + emitState("result", "declined") + teardown() + return + } + } + + // Approved (or prompt skipped): read each arm's battery while the + // links are still up, then report the result. + emitState("battery", "") + readBatteries() + if (cancelled) { + emitState("cancelled", "") + teardown() + return + } + if (rightLost) { + emitState("disconnected", "Lost connection to the glasses.") + teardown() + return + } + finished = true + emitResult(true) + emitState("result", "approved") + teardown() + } catch (e: Exception) { + stopHeartbeat() + if (!cancelled) { + val message = if (e.message == null) e.toString() else e.message + emitState("error", message) + } + teardown() + } + } + + private fun connectArm(address: String, arm: String) { + if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { + throw IllegalStateException("could not connect to the $arm arm ($address)") + } + bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) + bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) + if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { + throw IllegalStateException("discoverServices failed: $arm arm ($address)") + } + if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { + throw IllegalStateException("enableNotifications failed: $arm arm ($address)") + } + emitLog("connected $arm arm") + } + + /** + * Security-auth exchange on sid=0x80: firmware 2.2.9 will not run a + * session (and closes the link after ~30 s) without it, and on an + * unbonded phone this is what triggers SMP pairing, so it may sit + * waiting on an OS pairing prompt. + */ + @Throws(InterruptedException::class) + private fun authenticateArm(address: String, arm: String) { + val authMagic = allocMagic() + val authAck = writeAndAwaitAck( + address, + BleProtocol.SID_SECURITY_AUTH, + BleProtocol.FLAG_SECURITY_AUTH, + authMagic, + BleProtocol.buildAuthenticationRequest(authMagic), + ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS) + if (authAck == null || !BleProtocol.isAuthenticationSuccess(authAck, authMagic)) { + throw IllegalStateException( + "could not authenticate with the $arm arm ($address" + + ") — if Android shows a Bluetooth pairing request, accept it and try again") + } + emitLog("security auth complete: $arm arm") + } + + /** Mandatory session prelude on sid=0x01 (app-launch). Right arm only; it relays. */ + @Throws(InterruptedException::class) + private fun sendPrelude(address: String) { + if (writeAndAwaitAck( + address, + BleProtocol.PRELUDE_ACK_SID, + BleProtocol.FLAG_REQUEST, + BleProtocol.PRELUDE_ACK_MAGIC, + BleProtocol.PRELUDE_F5872_PAYLOAD, + ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) { + throw IllegalStateException("session prelude not acked: $address") + } + } + + @Throws(InterruptedException::class) + private fun showPrompt(address: String) { + // Create the prompt page (warning text + No/Yes list) on sid=0xe0 Cmd=0. + // Two attempts: on 2.2.9 the first request sent right after the + // prelude can be dropped while the lens emits its own sid-0x80 + // notifications (observed with the device-info settings read). + var pageAck: ByteArray? = null + var attempt = 0 + while (attempt < 2 && pageAck == null && !cancelled) { + val magic = allocMagic() + val page = BleProtocol.buildCreatePromptPage( + magic, TEXT_NAME, TEXT_CONTAINER_ID, warningText, LIST_NAME, LIST_CONTAINER_ID, ITEMS) + pageAck = writeAndAwaitAck(address, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, magic, page, CREATE_ACK_TIMEOUT_MS) + if (pageAck == null) { + emitLog("prompt page attempt " + (attempt + 1) + " unacked: " + address) + } + attempt++ + } + if (pageAck == null) { + throw IllegalStateException("prompt page not acked: $address") + } + emitLog("prompt page shown on $address") + } + + /** + * Read each arm's battery via a sid-0x09 settings read on that arm's own + * link (the arms have independent batteries and each answers with its + * own). An arm that does not answer reports -1; the caller decides what + * to do with a partial reading. + */ + @Throws(InterruptedException::class) + private fun readBatteries() { + val right = if (rightConnected) readBattery(rightAddress, "right") else -1 + val left = if (leftConnected) readBattery(leftAddress, "left") else -1 + emitLog("battery R=" + (if (right < 0) "?" else "$right%") + " L=" + (if (left < 0) "?" else "$left%")) + emitBattery(right, left) + } + + @Throws(InterruptedException::class) + private fun readBattery(address: String, arm: String): Int { + var attempt = 0 + while (attempt < 2 && !cancelled) { + val magic = allocMagic() + val ack = writeAndAwaitAck( + address, + BleProtocol.SID_UI_SETTING, + BleProtocol.FLAG_REQUEST, + magic, + BleProtocol.buildSettingsQuery(magic), + BATTERY_ACK_TIMEOUT_MS) + if (ack == null) { + emitLog("battery read attempt " + (attempt + 1) + " unacked: " + arm + " arm") + attempt++ + continue + } + val snapshot: BleProtocol.BatterySnapshot? = BleProtocol.parseSettingsBattery(ack) + if (snapshot != null) { + return snapshot.battery + } + emitLog("battery read ack had no battery field: $arm arm") + attempt++ + } + return -1 + } + + /** Write and wait for the matching ack; returns the ack's protobuf (may be empty), or null on timeout/write failure. */ + @Throws(InterruptedException::class) + private fun writeAndAwaitAck(address: String, sid: Int, flag: Int, magic: Int, payload: ByteArray, timeoutMs: Int): ByteArray? { + val latch = CountDownLatch(1) + val key = ackKey(sid, magic) + pendingAcks[key] = latch + try { + if (!writeFrame(address, sid, flag, payload)) { + return null + } + if (!latch.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS)) { + return null + } + val pb = ackPayloads[key] + return pb ?: ByteArray(0) + } finally { + pendingAcks.remove(key, latch) + ackPayloads.remove(key) + } + } + + private fun writeFrame(address: String, sid: Int, flag: Int, payload: ByteArray): Boolean { + val seq: Int + synchronized(lock) { + seq = nextSeq++ and 0xff + } + val frames = BleProtocol.framePb(payload, sid, flag, seq) + return bleManager.writeFrames( + address, + BleProtocol.WRITE_CHAR_UUID, + frames, + AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), + ConnectionOptions.WRITE_TIMEOUT_MS) + } + + private fun startHeartbeat() { + stopHeartbeat() + val executor = Executors.newSingleThreadScheduledExecutor { runnable -> + val t = Thread(runnable, "faceclaw-flash-hb") + t.isDaemon = true + t + } + heartbeatExecutor = executor + executor.scheduleWithFixedDelay( + { sendHeartbeat() }, HEARTBEAT_INTERVAL_MS.toLong(), HEARTBEAT_INTERVAL_MS.toLong(), TimeUnit.MILLISECONDS) + } + + private fun sendHeartbeat() { + if (finished || cancelled) { + return + } + try { + val heartbeat = BleProtocol.buildHeartbeat(allocMagic()) + if (rightConnected) { + writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat) + } + } catch (e: Exception) { + Log.w(TAG, "heartbeat failed: " + e.message) + } + } + + private fun stopHeartbeat() { + val executor = heartbeatExecutor + heartbeatExecutor = null + if (executor != null) { + executor.shutdownNow() + } + } + + private fun sendShutdown() { + val shutdown = BleProtocol.buildShutdown(allocMagic(), 0) + if (rightConnected) { + writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown) + } + } + + private fun teardown() { + finished = true + stopHeartbeat() + try { + bleManager.close() + } catch (ignored: Exception) { + } + rightConnected = false + leftConnected = false + } + + override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { + if (!BleProtocol.NOTIFY_CHAR_UUID.equals(characteristicUuid, ignoreCase = true)) { + return + } + // A value can carry several envelope frames back to back. + for (buf in BleProtocol.splitFrames(data)) { + handleFrame(address, buf) + } + } + + private fun handleFrame(address: String?, buf: ByteArray) { + val frame = BleProtocol.parseFrame(buf) + if (!frame.ok) { + return + } + if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { + handleEvent(frame) + return + } + if (frame.msgSeq >= 0) { + val key = ackKey(frame.sid, frame.msgSeq) + val latch = pendingAcks[key] + if (latch != null) { + ackPayloads[key] = frame.pb + latch.countDown() + } + } + } + + private fun handleEvent(frame: BleProtocol.ParsedFrame) { + val selection: BleProtocol.ListSelection? = BleProtocol.parseListSelection(frame) + if (selection == null || LIST_NAME != selection.containerName) { + return + } + // Only a confirmed click is a decision; scroll/highlight changes are ignored. + if (selection.eventType != BleProtocol.EVENT_CLICK) { + return + } + val itemName = selection.itemName + val yes = selection.itemIndex == 1 + || (itemName != null && itemName.lowercase().startsWith("yes")) + synchronized(lock) { + if (finished) { + return + } + finished = true + approved = yes + } + emitLog("selection: " + (if (yes) "flash" else "cancel") + " (index " + selection.itemIndex + ")") + selectionLatch.countDown() + } + + override fun onConnectionStateChange(address: String?, connected: Boolean) { + if (connected) { + return + } + if (address!!.equals(leftAddress, ignoreCase = true)) { + // The prompt itself only needs the right arm; a dropped left link + // just means no left battery reading. + leftConnected = false + emitLog("left arm disconnected") + return + } + if (address.equals(rightAddress, ignoreCase = true)) { + rightConnected = false + synchronized(lock) { + if (!finished && !cancelled) { + rightLost = true + finished = true + selectionLatch.countDown() + } + } + } + } + + private fun allocMagic(): Int { + synchronized(lock) { + val magic = nextMagic + nextMagic = if (nextMagic >= 255) 100 else nextMagic + 1 + return magic + } + } + + private fun emitLog(line: String) { + Log.i(TAG, line) + mainHandler.post { + val current = listener + if (current != null) { + current.onLog(line) + } + } + } + + private fun emitState(state: String, detail: String?) { + val safeDetail = detail ?: "" + mainHandler.post { + val current = listener + if (current != null) { + current.onState(state, safeDetail) + } + } + } + + private fun emitBattery(rightPercent: Int, leftPercent: Int) { + mainHandler.post { + val current = listener + if (current != null) { + current.onBattery(rightPercent, leftPercent) + } + } + } + + private fun emitResult(approvedResult: Boolean) { + mainHandler.post { + val current = listener + if (current != null) { + current.onResult(approvedResult) + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java deleted file mode 100644 index 44e38a0b..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.faceclaw.app; - -import android.Manifest; -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.app.Service; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ServiceInfo; -import android.os.Build; -import android.os.IBinder; - -import androidx.core.content.ContextCompat; - -import com.tns.NativeScriptActivity; - -public class FaceclawForegroundService extends Service { - public static final String ACTION_START = "com.faceclaw.app.action.START"; - public static final String ACTION_UPDATE = "com.faceclaw.app.action.UPDATE"; - public static final String ACTION_STOP = "com.faceclaw.app.action.STOP"; - public static final String EXTRA_TEXT = "text"; - - // Channel id was bumped from "faceclaw-dashboard" when the badge setting - // changed: Android freezes a channel's showBadge flag at creation, so the - // old channel (which let Samsung's launcher count the pinned notification - // as a red "1" badge) is deleted on upgrade rather than reused. - private static final String LEGACY_CHANNEL_ID = "faceclaw-dashboard"; - private static final String CHANNEL_ID = "faceclaw-connection"; - private static final int NOTIFICATION_ID = 4201; - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - String action = intent != null ? intent.getAction() : ACTION_START; - String text = intent != null ? intent.getStringExtra(EXTRA_TEXT) : null; - - if (ACTION_STOP.equals(action)) { - stopForeground(STOP_FOREGROUND_REMOVE); - stopSelf(); - return START_NOT_STICKY; - } - - ensureNotificationChannel(); - Notification notification = buildNotification( - text != null && !text.trim().isEmpty() ? text : "Connected to glasses" - ); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - startForeground(NOTIFICATION_ID, notification, foregroundServiceType()); - } else { - startForeground(NOTIFICATION_ID, notification); - } - - if (ACTION_UPDATE.equals(action)) { - NotificationManager manager = getSystemService(NotificationManager.class); - if (manager != null) { - manager.notify(NOTIFICATION_ID, notification); - } - } - - return START_STICKY; - } - - private void ensureNotificationChannel() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - return; - } - - NotificationChannel channel = new NotificationChannel( - CHANNEL_ID, - "Glasses connection", - NotificationManager.IMPORTANCE_LOW - ); - channel.setDescription("Keeps Faceclaw connected to the glasses."); - // The pinned status notification must not count toward the launcher - // icon's notification badge. - channel.setShowBadge(false); - - NotificationManager manager = getSystemService(NotificationManager.class); - if (manager != null) { - manager.createNotificationChannel(channel); - manager.deleteNotificationChannel(LEGACY_CHANNEL_ID); - } - } - - private Notification buildNotification(String text) { - Intent launchIntent = new Intent(this, NativeScriptActivity.class); - launchIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - - int flags = PendingIntent.FLAG_UPDATE_CURRENT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - flags |= PendingIntent.FLAG_IMMUTABLE; - } - - PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launchIntent, flags); - - Notification.Builder builder = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - ? new Notification.Builder(this, CHANNEL_ID) - : new Notification.Builder(this); - - return builder - .setContentTitle("Faceclaw") - .setContentText(text) - .setSmallIcon(getApplicationInfo().icon) - .setContentIntent(contentIntent) - .setOngoing(true) - .setOnlyAlertOnce(true) - .build(); - } - - private int foregroundServiceType() { - int type = ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE; - // TODO: Make this depend on which audio path (G2 vs phone) is selected - if (hasRecordAudioPermission()) { - type |= ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE; - } - // The location type keeps while-in-use location flowing to the - // Navigate app when the phone screen locks. Only claimed once the - // permission exists: on API 34+ claiming it without the permission - // makes startForeground throw. - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && hasFineLocationPermission()) { - type |= ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION; - } - return type; - } - - private boolean hasRecordAudioPermission() { - return ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) - == PackageManager.PERMISSION_GRANTED; - } - - private boolean hasFineLocationPermission() { - return ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) - == PackageManager.PERMISSION_GRANTED; - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.kt new file mode 100644 index 00000000..9b50bd3e --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.kt @@ -0,0 +1,141 @@ +package com.faceclaw.app + +import android.Manifest +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.app.Service +import android.content.Intent +import android.content.pm.PackageManager +import android.content.pm.ServiceInfo +import android.os.Build +import android.os.IBinder + +import androidx.core.content.ContextCompat + +import com.tns.NativeScriptActivity + +class FaceclawForegroundService : Service() { + companion object { + const val ACTION_START = "com.faceclaw.app.action.START" + const val ACTION_UPDATE = "com.faceclaw.app.action.UPDATE" + const val ACTION_STOP = "com.faceclaw.app.action.STOP" + const val EXTRA_TEXT = "text" + + // Channel id was bumped from "faceclaw-dashboard" when the badge setting + // changed: Android freezes a channel's showBadge flag at creation, so the + // old channel (which let Samsung's launcher count the pinned notification + // as a red "1" badge) is deleted on upgrade rather than reused. + private const val LEGACY_CHANNEL_ID = "faceclaw-dashboard" + private const val CHANNEL_ID = "faceclaw-connection" + private const val NOTIFICATION_ID = 4201 + } + + override fun onBind(intent: Intent?): IBinder? { + return null + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + val action = if (intent != null) intent.action else ACTION_START + val text = intent?.getStringExtra(EXTRA_TEXT) + + if (ACTION_STOP == action) { + stopForeground(STOP_FOREGROUND_REMOVE) + stopSelf() + return START_NOT_STICKY + } + + ensureNotificationChannel() + val notification = buildNotification( + if (text != null && !text.trim().isEmpty()) text else "Connected to glasses" + ) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + startForeground(NOTIFICATION_ID, notification, foregroundServiceType()) + } else { + startForeground(NOTIFICATION_ID, notification) + } + + if (ACTION_UPDATE == action) { + val manager = getSystemService(NotificationManager::class.java) + manager?.notify(NOTIFICATION_ID, notification) + } + + return START_STICKY + } + + private fun ensureNotificationChannel() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + return + } + + val channel = NotificationChannel( + CHANNEL_ID, + "Glasses connection", + NotificationManager.IMPORTANCE_LOW + ) + channel.description = "Keeps Faceclaw connected to the glasses." + // The pinned status notification must not count toward the launcher + // icon's notification badge. + channel.setShowBadge(false) + + val manager = getSystemService(NotificationManager::class.java) + if (manager != null) { + manager.createNotificationChannel(channel) + manager.deleteNotificationChannel(LEGACY_CHANNEL_ID) + } + } + + private fun buildNotification(text: String): Notification { + val launchIntent = Intent(this, NativeScriptActivity::class.java) + launchIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + + var flags = PendingIntent.FLAG_UPDATE_CURRENT + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + flags = flags or PendingIntent.FLAG_IMMUTABLE + } + + val contentIntent = PendingIntent.getActivity(this, 0, launchIntent, flags) + + val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + Notification.Builder(this, CHANNEL_ID) + else + Notification.Builder(this) + + return builder + .setContentTitle("Faceclaw") + .setContentText(text) + .setSmallIcon(applicationInfo.icon) + .setContentIntent(contentIntent) + .setOngoing(true) + .setOnlyAlertOnce(true) + .build() + } + + private fun foregroundServiceType(): Int { + var type = ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE + // TODO: Make this depend on which audio path (G2 vs phone) is selected + if (hasRecordAudioPermission()) { + type = type or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE + } + // The location type keeps while-in-use location flowing to the + // Navigate app when the phone screen locks. Only claimed once the + // permission exists: on API 34+ claiming it without the permission + // makes startForeground throw. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && hasFineLocationPermission()) { + type = type or ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION + } + return type + } + + private fun hasRecordAudioPermission(): Boolean { + return ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == + PackageManager.PERMISSION_GRANTED + } + + private fun hasFineLocationPermission(): Boolean { + return ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == + PackageManager.PERMISSION_GRANTED + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.java deleted file mode 100644 index 9f9287a9..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.faceclaw.app; - -import java.io.IOException; - -import okhttp3.Interceptor; -import okhttp3.Request; -import okhttp3.Response; - -/** - * Shared HTTP identity for the Java networking helpers. The version lives in - * app/version.ts, so the TypeScript side pushes the real string in at startup - * (see installNativeUserAgent in app/util/http.ts); the default below is only - * a fallback for requests that somehow beat that call. - */ -public final class FaceclawHttp { - private static volatile String userAgent = "Faceclaw"; - - private FaceclawHttp() {} - - public static void setUserAgent(String value) { - if (value != null && !value.trim().isEmpty()) { - userAgent = value.trim(); - } - } - - public static String getUserAgent() { - return userAgent; - } - - /** Stamps our User-Agent on any request that doesn't already carry one. */ - public static Interceptor userAgentInterceptor() { - return new Interceptor() { - @Override public Response intercept(Chain chain) throws IOException { - Request request = chain.request(); - if (request.header("User-Agent") != null) { - return chain.proceed(request); - } - return chain.proceed(request.newBuilder().header("User-Agent", userAgent).build()); - } - }; - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt new file mode 100644 index 00000000..6e5a2855 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt @@ -0,0 +1,47 @@ +package com.faceclaw.app + +import java.io.IOException + +import okhttp3.Interceptor +import okhttp3.Request +import okhttp3.Response + +/** + * Shared HTTP identity for the Java networking helpers. The version lives in + * app/version.ts, so the TypeScript side pushes the real string in at startup + * (see installNativeUserAgent in app/util/http.ts); the default below is only + * a fallback for requests that somehow beat that call. + */ +class FaceclawHttp private constructor() { + companion object { + @Volatile + private var userAgent = "Faceclaw" + + @JvmStatic + fun setUserAgent(value: String?) { + if (value != null && !value.trim().isEmpty()) { + userAgent = value.trim() + } + } + + @JvmStatic + fun getUserAgent(): String { + return userAgent + } + + /** Stamps our User-Agent on any request that doesn't already carry one. */ + @JvmStatic + fun userAgentInterceptor(): Interceptor { + return object : Interceptor { + @Throws(IOException::class) + override fun intercept(chain: Interceptor.Chain): Response { + val request: Request = chain.request() + if (request.header("User-Agent") != null) { + return chain.proceed(request) + } + return chain.proceed(request.newBuilder().header("User-Agent", userAgent).build()) + } + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.java deleted file mode 100644 index 1ed6b950..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.faceclaw.app; - -import android.util.Log; - -public class FaceclawLc3Decoder { - private static final String TAG = "FaceclawLc3"; - public static final int SAMPLE_RATE = 16000; - public static final int FRAME_US = 10000; - public static final int FRAME_BYTES = 40; - public static final int FRAMES_PER_PACKET = 5; - public static final int PACKET_BYTES = 205; - public static final int COUNTER_OFFSET = 204; - public static final int SAMPLES_PER_FRAME = 160; - public static final int SAMPLES_PER_PACKET = FRAMES_PER_PACKET * SAMPLES_PER_FRAME; - // Trailer layout (firmware service_audio.c): after the 200 LC3 bytes the - // glasses DSP appends two signed 16-bit LE values computed on the raw - // stereo capture before the mono downmix — a signal-strength ratio and the - // asin-derived direction-of-arrival in degrees — then the packet counter. - public static final int SSR_OFFSET = 200; - public static final int ANGLE_OFFSET = 202; - - static { - System.loadLibrary("faceclaw_lc3"); - } - - private long nativeHandle; - private int lastCounter = -1; - private long realPackets; - private long duplicatePackets; - private long missingPackets; - private long decodeErrors; - private int lastSsr; - private int lastAngleDegrees; - - public FaceclawLc3Decoder() { - nativeHandle = nativeCreate(FRAME_US, SAMPLE_RATE); - if (nativeHandle == 0) { - throw new IllegalStateException("Could not create LC3 decoder"); - } - } - - public synchronized int decodePacket(byte[] packet, short[] pcmOut) { - if (nativeHandle == 0) { - throw new IllegalStateException("LC3 decoder is closed"); - } - if (packet == null || packet.length != PACKET_BYTES) { - decodeErrors++; - Log.w(TAG, "unexpected G2 audio packet length=" + (packet == null ? -1 : packet.length)); - return 0; - } - if (pcmOut == null || pcmOut.length < SAMPLES_PER_PACKET) { - throw new IllegalArgumentException("pcmOut must hold " + SAMPLES_PER_PACKET + " samples"); - } - - int counter = packet[COUNTER_OFFSET] & 0xff; - if (lastCounter >= 0) { - int gap = (counter - lastCounter) & 0xff; - if (gap == 0) { - duplicatePackets++; - return 0; - } - int missing = gap - 1; - if (missing > 0) { - missingPackets += missing; - } - } - - int decoded = nativeDecodePacket(nativeHandle, packet, pcmOut); - if (decoded <= 0) { - decodeErrors++; - return 0; - } - realPackets++; - lastCounter = counter; - lastSsr = (short) ((packet[SSR_OFFSET] & 0xff) | (packet[SSR_OFFSET + 1] << 8)); - lastAngleDegrees = (short) ((packet[ANGLE_OFFSET] & 0xff) | (packet[ANGLE_OFFSET + 1] << 8)); - return decoded; - } - - /** Firmware signal-strength ratio from the most recent decoded packet. */ - public synchronized int getLastSsr() { - return lastSsr; - } - - /** Firmware direction-of-arrival (signed degrees) from the most recent decoded packet. */ - public synchronized int getLastAngleDegrees() { - return lastAngleDegrees; - } - - public synchronized long getRealPackets() { - return realPackets; - } - - public synchronized long getDuplicatePackets() { - return duplicatePackets; - } - - public synchronized long getMissingPackets() { - return missingPackets; - } - - public synchronized long getDecodeErrors() { - return decodeErrors; - } - - public synchronized void close() { - long handle = nativeHandle; - nativeHandle = 0; - if (handle != 0) { - nativeDestroy(handle); - } - } - - private static native long nativeCreate(int frameUs, int sampleRate); - private static native int nativeDecodePacket(long handle, byte[] packet, short[] pcmOut); - private static native void nativeDestroy(long handle); -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt new file mode 100644 index 00000000..ce53c010 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt @@ -0,0 +1,130 @@ +package com.faceclaw.app + +import android.util.Log + +class FaceclawLc3Decoder { + companion object { + private const val TAG = "FaceclawLc3" + const val SAMPLE_RATE = 16000 + const val FRAME_US = 10000 + const val FRAME_BYTES = 40 + const val FRAMES_PER_PACKET = 5 + const val PACKET_BYTES = 205 + const val COUNTER_OFFSET = 204 + const val SAMPLES_PER_FRAME = 160 + const val SAMPLES_PER_PACKET = FRAMES_PER_PACKET * SAMPLES_PER_FRAME + // Trailer layout (firmware service_audio.c): after the 200 LC3 bytes the + // glasses DSP appends two signed 16-bit LE values computed on the raw + // stereo capture before the mono downmix — a signal-strength ratio and the + // asin-derived direction-of-arrival in degrees — then the packet counter. + const val SSR_OFFSET = 200 + const val ANGLE_OFFSET = 202 + + init { + System.loadLibrary("faceclaw_lc3") + } + + @JvmStatic + private external fun nativeCreate(frameUs: Int, sampleRate: Int): Long + @JvmStatic + private external fun nativeDecodePacket(handle: Long, packet: ByteArray, pcmOut: ShortArray): Int + @JvmStatic + private external fun nativeDestroy(handle: Long) + } + + private var nativeHandle: Long + private var lastCounter = -1 + private var realPackets: Long = 0 + private var duplicatePackets: Long = 0 + private var missingPackets: Long = 0 + private var decodeErrors: Long = 0 + private var lastSsr = 0 + private var lastAngleDegrees = 0 + + init { + nativeHandle = nativeCreate(FRAME_US, SAMPLE_RATE) + if (nativeHandle == 0L) { + throw IllegalStateException("Could not create LC3 decoder") + } + } + + @Synchronized + fun decodePacket(packet: ByteArray?, pcmOut: ShortArray?): Int { + if (nativeHandle == 0L) { + throw IllegalStateException("LC3 decoder is closed") + } + if (packet == null || packet.size != PACKET_BYTES) { + decodeErrors++ + Log.w(TAG, "unexpected G2 audio packet length=" + (packet?.size ?: -1)) + return 0 + } + if (pcmOut == null || pcmOut.size < SAMPLES_PER_PACKET) { + throw IllegalArgumentException("pcmOut must hold $SAMPLES_PER_PACKET samples") + } + + val counter = packet[COUNTER_OFFSET].toInt() and 0xff + if (lastCounter >= 0) { + val gap = (counter - lastCounter) and 0xff + if (gap == 0) { + duplicatePackets++ + return 0 + } + val missing = gap - 1 + if (missing > 0) { + missingPackets += missing.toLong() + } + } + + val decoded = nativeDecodePacket(nativeHandle, packet, pcmOut) + if (decoded <= 0) { + decodeErrors++ + return 0 + } + realPackets++ + lastCounter = counter + lastSsr = ((packet[SSR_OFFSET].toInt() and 0xff) or (packet[SSR_OFFSET + 1].toInt() shl 8)).toShort().toInt() + lastAngleDegrees = ((packet[ANGLE_OFFSET].toInt() and 0xff) or (packet[ANGLE_OFFSET + 1].toInt() shl 8)).toShort().toInt() + return decoded + } + + /** Firmware signal-strength ratio from the most recent decoded packet. */ + @Synchronized + fun getLastSsr(): Int { + return lastSsr + } + + /** Firmware direction-of-arrival (signed degrees) from the most recent decoded packet. */ + @Synchronized + fun getLastAngleDegrees(): Int { + return lastAngleDegrees + } + + @Synchronized + fun getRealPackets(): Long { + return realPackets + } + + @Synchronized + fun getDuplicatePackets(): Long { + return duplicatePackets + } + + @Synchronized + fun getMissingPackets(): Long { + return missingPackets + } + + @Synchronized + fun getDecodeErrors(): Long { + return decodeErrors + } + + @Synchronized + fun close() { + val handle = nativeHandle + nativeHandle = 0 + if (handle != 0L) { + nativeDestroy(handle) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.java deleted file mode 100644 index 17e98834..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * On-phone LLM inference for the voice assistant (llama.cpp over JNI). - * - * All model work (load, generate, free) runs on a single background executor - * thread so calls are naturally serialized; listener callbacks are posted to - * the Looper of the thread that constructed this object (the JS thread), the - * same contract as FaceclawSseRequest. cancel() may be called from any thread - * and interrupts the in-flight generation at the next token boundary. - * - * The model stays loaded between generations (turn iterations reuse the KV - * cache prefix); the TypeScript side calls unload() on an idle timer to give - * the ~3GB back. - */ -public class FaceclawLlamaRunner { - private static final String TAG = "FaceclawLlamaRunner"; - - static { - System.loadLibrary("faceclaw_llama"); - } - - private final Handler callbackHandler; - private final ExecutorService executor = Executors.newSingleThreadExecutor(runnable -> { - Thread thread = new Thread(runnable, "FaceclawLlama"); - thread.setPriority(Thread.NORM_PRIORITY); - return thread; - }); - - // Mutated only on the executor thread; volatile so cancel() can read it. - private volatile long handle; - private String loadedPath; - - public FaceclawLlamaRunner() { - Looper looper = Looper.myLooper(); - callbackHandler = new Handler(looper != null ? looper : Looper.getMainLooper()); - } - - public boolean isModelLoaded() { - return handle != 0; - } - - /** - * Generate a completion, loading (or swapping) the model first if needed. - * grammar may be null/empty for unconstrained generation. - */ - public void generate(final String modelPath, final int nCtx, final int nThreads, - final String prompt, final String grammar, final int maxTokens, - final float temperature, final float topP, final int topK, - final FaceclawLlamaListener listener) { - executor.execute(() -> { - try { - if (handle != 0 && !modelPath.equals(loadedPath)) { - nativeFree(handle); - handle = 0; - loadedPath = null; - } - if (handle == 0) { - long loaded = nativeLoadModel(modelPath, nCtx, nThreads); - if (loaded == 0) { - post(() -> listener.onError("Could not load the on-phone model")); - return; - } - handle = loaded; - loadedPath = modelPath; - } - nativeGenerate(handle, prompt, grammar == null ? "" : grammar, - maxTokens, temperature, topP, topK, new FaceclawLlamaListener() { - @Override public void onToken(final String piece) { - post(() -> listener.onToken(piece)); - } - @Override public void onDone(final String stopReason) { - post(() -> listener.onDone(stopReason)); - } - @Override public void onError(final String message) { - post(() -> listener.onError(message)); - } - }); - } catch (Throwable t) { - Log.e(TAG, "generation failed", t); - final String message = String.valueOf(t); - post(() -> listener.onError("On-phone model failed: " + message)); - } - }); - } - - /** Interrupt the current generation (its listener gets onDone("cancelled")). */ - public void cancel() { - long current = handle; - if (current != 0) { - nativeCancel(current); - } - } - - /** Free the model and its KV cache. Safe to call when nothing is loaded. */ - public void unload() { - executor.execute(() -> { - if (handle != 0) { - nativeFree(handle); - handle = 0; - loadedPath = null; - } - }); - } - - private void post(Runnable runnable) { - callbackHandler.post(runnable); - } - - private static native long nativeLoadModel(String path, int nCtx, int nThreads); - private static native void nativeGenerate(long handle, String prompt, String grammar, - int maxTokens, float temperature, float topP, int topK, FaceclawLlamaListener listener); - private static native void nativeCancel(long handle); - private static native void nativeFree(long handle); -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.kt new file mode 100644 index 00000000..9cc3fa66 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.kt @@ -0,0 +1,133 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.util.Log + +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + +/** + * On-phone LLM inference for the voice assistant (llama.cpp over JNI). + * + * All model work (load, generate, free) runs on a single background executor + * thread so calls are naturally serialized; listener callbacks are posted to + * the Looper of the thread that constructed this object (the JS thread), the + * same contract as FaceclawSseRequest. cancel() may be called from any thread + * and interrupts the in-flight generation at the next token boundary. + * + * The model stays loaded between generations (turn iterations reuse the KV + * cache prefix); the TypeScript side calls unload() on an idle timer to give + * the ~3GB back. + */ +class FaceclawLlamaRunner { + companion object { + private const val TAG = "FaceclawLlamaRunner" + + init { + System.loadLibrary("faceclaw_llama") + } + + @JvmStatic + private external fun nativeLoadModel(path: String?, nCtx: Int, nThreads: Int): Long + @JvmStatic + private external fun nativeGenerate( + handle: Long, prompt: String?, grammar: String, + maxTokens: Int, temperature: Float, topP: Float, topK: Int, listener: FaceclawLlamaListener + ) + @JvmStatic + private external fun nativeCancel(handle: Long) + @JvmStatic + private external fun nativeFree(handle: Long) + } + + private val callbackHandler: Handler + private val executor: ExecutorService = Executors.newSingleThreadExecutor { runnable -> + val thread = Thread(runnable, "FaceclawLlama") + thread.priority = Thread.NORM_PRIORITY + thread + } + + // Mutated only on the executor thread; volatile so cancel() can read it. + @Volatile + private var handle: Long = 0 + private var loadedPath: String? = null + + init { + val looper = Looper.myLooper() + callbackHandler = Handler(looper ?: Looper.getMainLooper()) + } + + fun isModelLoaded(): Boolean { + return handle != 0L + } + + /** + * Generate a completion, loading (or swapping) the model first if needed. + * grammar may be null/empty for unconstrained generation. + */ + fun generate( + modelPath: String?, nCtx: Int, nThreads: Int, + prompt: String?, grammar: String?, maxTokens: Int, + temperature: Float, topP: Float, topK: Int, + listener: FaceclawLlamaListener + ) { + executor.execute { + try { + if (handle != 0L && modelPath != loadedPath) { + nativeFree(handle) + handle = 0 + loadedPath = null + } + if (handle == 0L) { + val loaded = nativeLoadModel(modelPath, nCtx, nThreads) + if (loaded == 0L) { + post { listener.onError("Could not load the on-phone model") } + return@execute + } + handle = loaded + loadedPath = modelPath + } + nativeGenerate(handle, prompt, grammar ?: "", + maxTokens, temperature, topP, topK, object : FaceclawLlamaListener { + override fun onToken(piece: String?) { + post { listener.onToken(piece) } + } + override fun onDone(stopReason: String?) { + post { listener.onDone(stopReason) } + } + override fun onError(message: String?) { + post { listener.onError(message) } + } + }) + } catch (t: Throwable) { + Log.e(TAG, "generation failed", t) + val message = t.toString() + post { listener.onError("On-phone model failed: $message") } + } + } + } + + /** Interrupt the current generation (its listener gets onDone("cancelled")). */ + fun cancel() { + val current = handle + if (current != 0L) { + nativeCancel(current) + } + } + + /** Free the model and its KV cache. Safe to call when nothing is loaded. */ + fun unload() { + executor.execute { + if (handle != 0L) { + nativeFree(handle) + handle = 0 + loadedPath = null + } + } + } + + private fun post(runnable: Runnable) { + callbackHandler.post(runnable) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.java deleted file mode 100644 index 90e610c9..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.java +++ /dev/null @@ -1,196 +0,0 @@ -package com.faceclaw.app; - -import android.Manifest; -import android.content.Context; -import android.content.pm.PackageManager; -import android.location.Criteria; -import android.location.Location; -import android.location.LocationListener; -import android.location.LocationManager; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; - -import androidx.core.content.ContextCompat; - -import java.util.List; - -/** - * One-shot, foreground-only location lookup for Weather. It prefers a fresh - * coarse network fix, but can fall back to the newest cached provider fix if - * Android cannot produce a new location before the timeout. - */ -public final class FaceclawLocationProvider implements LocationListener { - private static final long FRESH_CACHE_MS = 10L * 60L * 1000L; - private static final long MAX_CACHE_MS = 24L * 60L * 60L * 1000L; - private static final long TIMEOUT_MS = 15L * 1000L; - - private final Context context; - private final LocationManager locationManager; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private final Runnable timeout = this::onTimeout; - - private FaceclawLocationListener listener; - private Location cachedLocation; - private boolean running; - - public FaceclawLocationProvider(Context context) { - this.context = context.getApplicationContext(); - this.locationManager = (LocationManager) this.context.getSystemService(Context.LOCATION_SERVICE); - } - - public void setListener(FaceclawLocationListener listener) { - this.listener = listener; - } - - public void start() { - mainHandler.post(this::startOnMainThread); - } - - public void cancel() { - mainHandler.post(() -> finish(null, null)); - } - - private void startOnMainThread() { - if (running) { - return; - } - if (locationManager == null) { - deliverError("Android location service is unavailable."); - return; - } - if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) - != PackageManager.PERMISSION_GRANTED - && ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) - != PackageManager.PERMISSION_GRANTED) { - deliverError("Location permission is required."); - return; - } - - cachedLocation = newestCachedLocation(); - if (isRecent(cachedLocation, FRESH_CACHE_MS)) { - deliverLocation(cachedLocation); - return; - } - - String provider = chooseProvider(); - if (provider == null) { - if (isRecent(cachedLocation, MAX_CACHE_MS)) { - deliverLocation(cachedLocation); - } else { - deliverError("Turn on Location on your phone, then retry."); - } - return; - } - - try { - running = true; - locationManager.requestSingleUpdate(provider, this, Looper.getMainLooper()); - mainHandler.postDelayed(timeout, TIMEOUT_MS); - } catch (SecurityException error) { - finish(null, "Location permission is required."); - } catch (Throwable error) { - finish(null, "Unable to request the current location."); - } - } - - private String chooseProvider() { - try { - if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { - return LocationManager.NETWORK_PROVIDER; - } - Criteria criteria = new Criteria(); - criteria.setAccuracy(Criteria.ACCURACY_COARSE); - criteria.setPowerRequirement(Criteria.POWER_LOW); - return locationManager.getBestProvider(criteria, true); - } catch (Throwable ignored) { - return null; - } - } - - private Location newestCachedLocation() { - Location newest = null; - try { - List providers = locationManager.getProviders(true); - for (String provider : providers) { - Location candidate = locationManager.getLastKnownLocation(provider); - if (candidate != null && (newest == null || candidate.getTime() > newest.getTime())) { - newest = candidate; - } - } - } catch (SecurityException ignored) { - // The explicit permission check above owns the user-facing error. - } catch (Throwable ignored) { - // A fresh request may still succeed even if cached providers fail. - } - return newest; - } - - private static boolean isRecent(Location location, long maximumAgeMs) { - return location != null - && location.getTime() > 0L - && System.currentTimeMillis() - location.getTime() <= maximumAgeMs; - } - - private void onTimeout() { - if (isRecent(cachedLocation, MAX_CACHE_MS)) { - finish(cachedLocation, null); - } else { - finish(null, "Couldn't get your current location. Tap to retry."); - } - } - - @Override - public void onLocationChanged(Location location) { - finish(location, null); - } - - @Override - public void onProviderDisabled(String provider) { - // Keep waiting: Android may still deliver a queued fix or the timeout - // can fall back to another provider's cached location. - } - - @Override - public void onProviderEnabled(String provider) { - } - - @Override - @SuppressWarnings("deprecation") - public void onStatusChanged(String provider, int status, Bundle extras) { - } - - private void finish(Location location, String error) { - if (running) { - try { - locationManager.removeUpdates(this); - } catch (Throwable ignored) { - } - } - running = false; - mainHandler.removeCallbacks(timeout); - if (location != null) { - deliverLocation(location); - } else if (error != null) { - deliverError(error); - } - } - - private void deliverLocation(Location location) { - FaceclawLocationListener current = listener; - if (current != null && location != null) { - current.onLocation( - location.getLatitude(), - location.getLongitude(), - location.hasAccuracy() ? location.getAccuracy() : -1f, - location.getTime()); - } - } - - private void deliverError(String message) { - FaceclawLocationListener current = listener; - if (current != null) { - current.onError(message); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.kt new file mode 100644 index 00000000..ce3a7568 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.kt @@ -0,0 +1,188 @@ +package com.faceclaw.app + +import android.Manifest +import android.content.Context +import android.content.pm.PackageManager +import android.location.Criteria +import android.location.Location +import android.location.LocationListener +import android.location.LocationManager +import android.os.Bundle +import android.os.Handler +import android.os.Looper + +import androidx.core.content.ContextCompat + +/** + * One-shot, foreground-only location lookup for Weather. It prefers a fresh + * coarse network fix, but can fall back to the newest cached provider fix if + * Android cannot produce a new location before the timeout. + */ +class FaceclawLocationProvider(context: Context) : LocationListener { + companion object { + private const val FRESH_CACHE_MS = 10L * 60L * 1000L + private const val MAX_CACHE_MS = 24L * 60L * 60L * 1000L + private const val TIMEOUT_MS = 15L * 1000L + + private fun isRecent(location: Location?, maximumAgeMs: Long): Boolean { + return location != null && + location.time > 0L && + System.currentTimeMillis() - location.time <= maximumAgeMs + } + } + + private val context: Context = context.applicationContext + private val locationManager: LocationManager? = + this.context.getSystemService(Context.LOCATION_SERVICE) as LocationManager? + private val mainHandler = Handler(Looper.getMainLooper()) + private val timeout = Runnable { onTimeout() } + + private var listener: FaceclawLocationListener? = null + private var cachedLocation: Location? = null + private var running = false + + fun setListener(listener: FaceclawLocationListener?) { + this.listener = listener + } + + fun start() { + mainHandler.post { startOnMainThread() } + } + + fun cancel() { + mainHandler.post { finish(null, null) } + } + + private fun startOnMainThread() { + if (running) { + return + } + val manager = locationManager + if (manager == null) { + deliverError("Android location service is unavailable.") + return + } + if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != + PackageManager.PERMISSION_GRANTED && + ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != + PackageManager.PERMISSION_GRANTED) { + deliverError("Location permission is required.") + return + } + + cachedLocation = newestCachedLocation() + if (isRecent(cachedLocation, FRESH_CACHE_MS)) { + deliverLocation(cachedLocation) + return + } + + val provider = chooseProvider() + if (provider == null) { + if (isRecent(cachedLocation, MAX_CACHE_MS)) { + deliverLocation(cachedLocation) + } else { + deliverError("Turn on Location on your phone, then retry.") + } + return + } + + try { + running = true + @Suppress("DEPRECATION") + manager.requestSingleUpdate(provider, this, Looper.getMainLooper()) + mainHandler.postDelayed(timeout, TIMEOUT_MS) + } catch (error: SecurityException) { + finish(null, "Location permission is required.") + } catch (error: Throwable) { + finish(null, "Unable to request the current location.") + } + } + + private fun chooseProvider(): String? { + try { + if (locationManager!!.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { + return LocationManager.NETWORK_PROVIDER + } + val criteria = Criteria() + criteria.accuracy = Criteria.ACCURACY_COARSE + criteria.powerRequirement = Criteria.POWER_LOW + return locationManager.getBestProvider(criteria, true) + } catch (ignored: Throwable) { + return null + } + } + + private fun newestCachedLocation(): Location? { + var newest: Location? = null + try { + val providers = locationManager!!.getProviders(true) + for (provider in providers) { + val candidate = locationManager.getLastKnownLocation(provider) + if (candidate != null && (newest == null || candidate.time > newest.time)) { + newest = candidate + } + } + } catch (ignored: SecurityException) { + // The explicit permission check above owns the user-facing error. + } catch (ignored: Throwable) { + // A fresh request may still succeed even if cached providers fail. + } + return newest + } + + private fun onTimeout() { + if (isRecent(cachedLocation, MAX_CACHE_MS)) { + finish(cachedLocation, null) + } else { + finish(null, "Couldn't get your current location. Tap to retry.") + } + } + + override fun onLocationChanged(location: Location) { + finish(location, null) + } + + override fun onProviderDisabled(provider: String) { + // Keep waiting: Android may still deliver a queued fix or the timeout + // can fall back to another provider's cached location. + } + + override fun onProviderEnabled(provider: String) { + } + + @Deprecated("Deprecated in Java") + override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) { + } + + private fun finish(location: Location?, error: String?) { + if (running) { + try { + locationManager!!.removeUpdates(this) + } catch (ignored: Throwable) { + } + } + running = false + mainHandler.removeCallbacks(timeout) + if (location != null) { + deliverLocation(location) + } else if (error != null) { + deliverError(error) + } + } + + private fun deliverLocation(location: Location?) { + val current = listener + if (current != null && location != null) { + current.onLocation( + location.latitude, + location.longitude, + if (location.hasAccuracy()) location.accuracy else -1f, + location.time) + } + } + + private fun deliverError(message: String) { + val current = listener + current?.onError(message) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.java deleted file mode 100644 index c39f3fa6..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.faceclaw.app; - -import android.Manifest; -import android.content.Context; -import android.content.pm.PackageManager; -import android.location.Location; -import android.location.LocationListener; -import android.location.LocationManager; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; - -import androidx.core.content.ContextCompat; - -/** - * Continuous location updates for turn-by-turn navigation. Unlike - * FaceclawLocationProvider (one-shot, coarse, for Weather), this streams GPS - * fixes with bearing and speed until stopped. - * - * Callbacks are delivered on the Looper of the thread that constructed the - * tracker, so a worker isolate receives them on its own thread (the same - * convention as FaceclawSseRequest). - */ -public final class FaceclawLocationTracker implements LocationListener { - private final Context context; - private final LocationManager locationManager; - private final Handler callbackHandler; - - /** - * Only seed from the platform's cached fix when it is this fresh. An older - * one is likely wherever the phone was last used (for example the previous - * navigation's destination), and guidance built on it is wrong from the - * first frame: the route starts there and arrival fires immediately. - */ - private static final long MAX_SEED_AGE_MS = 60L * 1000L; - - private FaceclawLocationTrackerListener listener; - private boolean running; - - public FaceclawLocationTracker(Context context) { - this.context = context.getApplicationContext(); - this.locationManager = (LocationManager) this.context.getSystemService(Context.LOCATION_SERVICE); - Looper looper = Looper.myLooper(); - this.callbackHandler = new Handler(looper != null ? looper : Looper.getMainLooper()); - } - - public void setListener(FaceclawLocationTrackerListener listener) { - this.listener = listener; - } - - /** Begin streaming fixes at roughly the requested interval. */ - public void start(long intervalMs) { - callbackHandler.post(() -> startOnCallbackThread(intervalMs)); - } - - public void stop() { - callbackHandler.post(() -> { - if (!running) { - return; - } - running = false; - try { - locationManager.removeUpdates(this); - } catch (Throwable ignored) { - } - }); - } - - private void startOnCallbackThread(long intervalMs) { - if (running) { - return; - } - if (locationManager == null) { - deliverError("Android location service is unavailable."); - return; - } - if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) - != PackageManager.PERMISSION_GRANTED) { - deliverError("Precise location permission is required for navigation."); - return; - } - - String provider = chooseProvider(); - if (provider == null) { - deliverError("Turn on Location on your phone, then retry."); - return; - } - - try { - running = true; - locationManager.requestLocationUpdates(provider, Math.max(500L, intervalMs), 0f, this, - callbackHandler.getLooper()); - // Seed with the freshest cached fix so the UI has a position - // before the first live fix (GPS cold starts can take a while), - // but only if it's recent enough to still be where the user is. - Location cached = freshestCachedLocation(provider); - if (cached != null) { - deliverLocation(cached); - } - } catch (SecurityException error) { - running = false; - deliverError("Precise location permission is required for navigation."); - } catch (Throwable error) { - running = false; - deliverError("Unable to start location updates."); - } - } - - private Location freshestCachedLocation(String primaryProvider) { - Location best = null; - for (String provider : new String[] {primaryProvider, LocationManager.NETWORK_PROVIDER, - LocationManager.GPS_PROVIDER}) { - Location candidate; - try { - candidate = locationManager.getLastKnownLocation(provider); - } catch (Throwable ignored) { - continue; - } - if (candidate == null || ageMs(candidate) > MAX_SEED_AGE_MS) { - continue; - } - if (best == null || candidate.getElapsedRealtimeNanos() > best.getElapsedRealtimeNanos()) { - best = candidate; - } - } - return best; - } - - /** Age via the monotonic clock, so a wall-clock change can't make an old fix look fresh. */ - private static long ageMs(Location location) { - long ageNanos = SystemClock.elapsedRealtimeNanos() - location.getElapsedRealtimeNanos(); - return ageNanos / 1_000_000L; - } - - private String chooseProvider() { - try { - if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { - return LocationManager.GPS_PROVIDER; - } - if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { - return LocationManager.NETWORK_PROVIDER; - } - } catch (Throwable ignored) { - } - return null; - } - - @Override - public void onLocationChanged(Location location) { - deliverLocation(location); - } - - @Override - public void onProviderDisabled(String provider) { - deliverError("Location was turned off on the phone."); - } - - @Override - public void onProviderEnabled(String provider) { - } - - @Override - @SuppressWarnings("deprecation") - public void onStatusChanged(String provider, int status, Bundle extras) { - } - - private void deliverLocation(Location location) { - FaceclawLocationTrackerListener current = listener; - if (current == null || location == null) { - return; - } - current.onLocation( - location.getLatitude(), - location.getLongitude(), - location.hasAccuracy() ? location.getAccuracy() : -1f, - location.hasBearing() ? location.getBearing() : -1f, - location.hasSpeed() ? location.getSpeed() : -1f, - location.getTime()); - } - - private void deliverError(String message) { - FaceclawLocationTrackerListener current = listener; - if (current != null) { - current.onError(message); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.kt new file mode 100644 index 00000000..9eb4e255 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.kt @@ -0,0 +1,184 @@ +package com.faceclaw.app + +import android.Manifest +import android.content.Context +import android.content.pm.PackageManager +import android.location.Location +import android.location.LocationListener +import android.location.LocationManager +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.os.SystemClock + +import androidx.core.content.ContextCompat + +/** + * Continuous location updates for turn-by-turn navigation. Unlike + * FaceclawLocationProvider (one-shot, coarse, for Weather), this streams GPS + * fixes with bearing and speed until stopped. + * + * Callbacks are delivered on the Looper of the thread that constructed the + * tracker, so a worker isolate receives them on its own thread (the same + * convention as FaceclawSseRequest). + */ +class FaceclawLocationTracker(context: Context) : LocationListener { + companion object { + /** + * Only seed from the platform's cached fix when it is this fresh. An older + * one is likely wherever the phone was last used (for example the previous + * navigation's destination), and guidance built on it is wrong from the + * first frame: the route starts there and arrival fires immediately. + */ + private const val MAX_SEED_AGE_MS = 60L * 1000L + + /** Age via the monotonic clock, so a wall-clock change can't make an old fix look fresh. */ + private fun ageMs(location: Location): Long { + val ageNanos = SystemClock.elapsedRealtimeNanos() - location.elapsedRealtimeNanos + return ageNanos / 1_000_000L + } + } + + private val context: Context = context.applicationContext + private val locationManager: LocationManager? = + this.context.getSystemService(Context.LOCATION_SERVICE) as LocationManager? + private val callbackHandler: Handler + + private var listener: FaceclawLocationTrackerListener? = null + private var running = false + + init { + val looper = Looper.myLooper() + this.callbackHandler = Handler(looper ?: Looper.getMainLooper()) + } + + fun setListener(listener: FaceclawLocationTrackerListener?) { + this.listener = listener + } + + /** Begin streaming fixes at roughly the requested interval. */ + fun start(intervalMs: Long) { + callbackHandler.post { startOnCallbackThread(intervalMs) } + } + + fun stop() { + callbackHandler.post { + if (!running) { + return@post + } + running = false + try { + locationManager!!.removeUpdates(this) + } catch (ignored: Throwable) { + } + } + } + + private fun startOnCallbackThread(intervalMs: Long) { + if (running) { + return + } + val manager = locationManager + if (manager == null) { + deliverError("Android location service is unavailable.") + return + } + if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != + PackageManager.PERMISSION_GRANTED) { + deliverError("Precise location permission is required for navigation.") + return + } + + val provider = chooseProvider() + if (provider == null) { + deliverError("Turn on Location on your phone, then retry.") + return + } + + try { + running = true + manager.requestLocationUpdates(provider, Math.max(500L, intervalMs), 0f, this, + callbackHandler.looper) + // Seed with the freshest cached fix so the UI has a position + // before the first live fix (GPS cold starts can take a while), + // but only if it's recent enough to still be where the user is. + val cached = freshestCachedLocation(provider) + if (cached != null) { + deliverLocation(cached) + } + } catch (error: SecurityException) { + running = false + deliverError("Precise location permission is required for navigation.") + } catch (error: Throwable) { + running = false + deliverError("Unable to start location updates.") + } + } + + private fun freshestCachedLocation(primaryProvider: String): Location? { + var best: Location? = null + for (provider in arrayOf(primaryProvider, LocationManager.NETWORK_PROVIDER, + LocationManager.GPS_PROVIDER)) { + val candidate: Location? + try { + candidate = locationManager!!.getLastKnownLocation(provider) + } catch (ignored: Throwable) { + continue + } + if (candidate == null || ageMs(candidate) > MAX_SEED_AGE_MS) { + continue + } + if (best == null || candidate.elapsedRealtimeNanos > best.elapsedRealtimeNanos) { + best = candidate + } + } + return best + } + + private fun chooseProvider(): String? { + try { + if (locationManager!!.isProviderEnabled(LocationManager.GPS_PROVIDER)) { + return LocationManager.GPS_PROVIDER + } + if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { + return LocationManager.NETWORK_PROVIDER + } + } catch (ignored: Throwable) { + } + return null + } + + override fun onLocationChanged(location: Location) { + deliverLocation(location) + } + + override fun onProviderDisabled(provider: String) { + deliverError("Location was turned off on the phone.") + } + + override fun onProviderEnabled(provider: String) { + } + + @Deprecated("Deprecated in Java") + override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) { + } + + private fun deliverLocation(location: Location?) { + val current = listener + if (current == null || location == null) { + return + } + current.onLocation( + location.latitude, + location.longitude, + if (location.hasAccuracy()) location.accuracy else -1f, + if (location.hasBearing()) location.bearing else -1f, + if (location.hasSpeed()) location.speed else -1f, + location.time) + } + + private fun deliverError(message: String) { + val current = listener + current?.onError(message) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.java deleted file mode 100644 index 07bef961..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.java +++ /dev/null @@ -1,321 +0,0 @@ -package com.faceclaw.app; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.media.browse.MediaBrowser; -import android.media.session.MediaController; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; -import android.util.Log; - -import org.json.JSONArray; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Client for other apps' MediaBrowserService implementations (the mechanism - * Android Auto uses). Binding starts the target player's process even when it - * is not running, so this can list a player's library (playlists, albums, ...) - * and start playback without the phone being unlocked. - * - * Holds at most one connection at a time. All MediaBrowser interaction happens - * on the main thread; results are reported through - * FaceclawMediaBrowserListener, also on the main thread. - */ -public class FaceclawMediaBrowser { - private static final String TAG = "FaceclawMediaBrowser"; - private static final String BROWSER_SERVICE_ACTION = "android.media.browse.MediaBrowserService"; - // Generous: connecting may cold-start the player's process. - private static final long CONNECT_TIMEOUT_MS = 15_000; - private static final long BROWSE_TIMEOUT_MS = 15_000; - // Unbinding immediately after a play command can race the player promoting - // itself to a foreground service, letting the system kill its process - // before playback starts; keep the binding alive briefly instead. - private static final long PLAY_DISCONNECT_GRACE_MS = 5_000; - - private final Context appContext; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private volatile FaceclawMediaBrowserListener listener; - - // Main-thread only. - private MediaBrowser browser; - private int generation; - private long lastPlayCommandAtMs; - - public FaceclawMediaBrowser(Context context) { - this.appContext = context.getApplicationContext(); - } - - public void setListener(FaceclawMediaBrowserListener listener) { - this.listener = listener; - } - - /** - * Installed apps exposing a media browser service, as JSON sorted by app - * name: [{"packageName": ..., "serviceClass": ..., "appName": ...}, ...]. - * Synchronous (PackageManager lookup only). - */ - public String listBrowsableAppsJson() { - PackageManager packageManager = appContext.getPackageManager(); - List services; - try { - services = packageManager.queryIntentServices(new Intent(BROWSER_SERVICE_ACTION), 0); - } catch (Exception e) { - Log.w(TAG, "media browser service query failed", e); - return "[]"; - } - List apps = new ArrayList<>(); - for (ResolveInfo service : services) { - if (service.serviceInfo == null) { - continue; - } - try { - CharSequence label = service.serviceInfo.applicationInfo.loadLabel(packageManager); - JSONObject app = new JSONObject(); - app.put("packageName", service.serviceInfo.packageName); - app.put("serviceClass", service.serviceInfo.name); - app.put("appName", label == null ? service.serviceInfo.packageName : label.toString()); - apps.add(app); - } catch (Exception e) { - Log.w(TAG, "media browser service entry failed", e); - } - } - Collections.sort(apps, (a, b) -> a.optString("appName").compareToIgnoreCase(b.optString("appName"))); - return new JSONArray(apps).toString(); - } - - /** - * Connect to an app's media browser service, starting its process if - * needed; replaces any existing connection. Async; reports through - * onConnectResult with the browse-tree root id on success. - */ - public void connect(int requestId, String packageName, String serviceClass) { - mainHandler.post(() -> { - closeBrowser(); - final int myGeneration = generation; - final boolean[] settled = {false}; - final MediaBrowser[] browserRef = new MediaBrowser[1]; - MediaBrowser newBrowser = new MediaBrowser( - appContext, - new ComponentName(packageName, serviceClass), - new MediaBrowser.ConnectionCallback() { - @Override - public void onConnected() { - if (generation != myGeneration || settled[0]) { - return; - } - settled[0] = true; - String rootId = ""; - try { - rootId = browserRef[0].getRoot(); - } catch (Exception e) { - Log.w(TAG, "getRoot failed", e); - } - emitConnectResult(requestId, true, rootId, ""); - } - - @Override - public void onConnectionFailed() { - if (generation != myGeneration || settled[0]) { - return; - } - settled[0] = true; - closeBrowser(); - emitConnectResult(requestId, false, "", "Connection refused by " + packageName); - } - - @Override - public void onConnectionSuspended() { - if (generation != myGeneration) { - return; - } - FaceclawMediaBrowserListener currentListener = listener; - if (currentListener != null) { - currentListener.onDisconnected(); - } - } - }, - null - ); - browserRef[0] = newBrowser; - browser = newBrowser; - mainHandler.postDelayed(() -> { - if (generation != myGeneration || settled[0]) { - return; - } - settled[0] = true; - closeBrowser(); - emitConnectResult(requestId, false, "", "Connection to " + packageName + " timed out"); - }, CONNECT_TIMEOUT_MS); - try { - newBrowser.connect(); - } catch (Exception e) { - if (!settled[0]) { - settled[0] = true; - closeBrowser(); - emitConnectResult(requestId, false, "", "Connection failed: " + e.getMessage()); - } - } - }); - } - - /** - * Fetch one level of the connected service's content tree. Async; reports - * through onBrowseResult with children as JSON: - * [{"mediaId": ..., "title": ..., "subtitle": ..., "browsable": bool, "playable": bool}, ...]. - */ - public void browse(int requestId, String parentId) { - mainHandler.post(() -> { - final MediaBrowser currentBrowser = browser; - if (currentBrowser == null || !currentBrowser.isConnected()) { - emitBrowseResult(requestId, "", "Not connected"); - return; - } - final int myGeneration = generation; - final boolean[] settled = {false}; - mainHandler.postDelayed(() -> { - if (generation != myGeneration || settled[0]) { - return; - } - settled[0] = true; - try { - currentBrowser.unsubscribe(parentId); - } catch (Exception ignored) { - } - emitBrowseResult(requestId, "", "Browse timed out"); - }, BROWSE_TIMEOUT_MS); - try { - currentBrowser.subscribe(parentId, new MediaBrowser.SubscriptionCallback() { - @Override - public void onChildrenLoaded(String loadedParentId, List children) { - if (generation != myGeneration || settled[0]) { - return; - } - settled[0] = true; - // One snapshot is all we want; unsubscribe outside the callback. - mainHandler.post(() -> { - try { - currentBrowser.unsubscribe(loadedParentId); - } catch (Exception ignored) { - } - }); - emitBrowseResult(requestId, serializeChildren(children), ""); - } - - @Override - public void onError(String erroredParentId) { - if (generation != myGeneration || settled[0]) { - return; - } - settled[0] = true; - mainHandler.post(() -> { - try { - currentBrowser.unsubscribe(erroredParentId); - } catch (Exception ignored) { - } - }); - emitBrowseResult(requestId, "", "Browse failed"); - } - }); - } catch (Exception e) { - if (!settled[0]) { - settled[0] = true; - emitBrowseResult(requestId, "", "Browse failed: " + e.getMessage()); - } - } - }); - } - - /** Start playback of a browsed item through the connected service's session. */ - public void playFromMediaId(String mediaId) { - mainHandler.post(() -> { - if (browser == null || !browser.isConnected()) { - return; - } - try { - MediaController controller = new MediaController(appContext, browser.getSessionToken()); - controller.getTransportControls().playFromMediaId(mediaId, null); - lastPlayCommandAtMs = SystemClock.elapsedRealtime(); - } catch (Exception e) { - Log.w(TAG, "playFromMediaId failed", e); - } - }); - } - - public void disconnect() { - mainHandler.post(() -> { - long sincePlayMs = SystemClock.elapsedRealtime() - lastPlayCommandAtMs; - long graceMs = lastPlayCommandAtMs == 0 ? 0 : PLAY_DISCONNECT_GRACE_MS - sincePlayMs; - if (graceMs <= 0) { - closeBrowser(); - return; - } - final MediaBrowser lingering = browser; - browser = null; - generation++; - if (lingering != null) { - mainHandler.postDelayed(() -> { - try { - lingering.disconnect(); - } catch (Exception ignored) { - } - }, graceMs); - } - }); - } - - private void closeBrowser() { - generation++; - if (browser != null) { - try { - browser.disconnect(); - } catch (Exception ignored) { - } - browser = null; - } - } - - private String serializeChildren(List children) { - JSONArray out = new JSONArray(); - if (children == null) { - return out.toString(); - } - for (MediaBrowser.MediaItem item : children) { - try { - CharSequence title = item.getDescription() == null ? null : item.getDescription().getTitle(); - CharSequence subtitle = item.getDescription() == null ? null : item.getDescription().getSubtitle(); - JSONObject entry = new JSONObject(); - entry.put("mediaId", item.getMediaId() == null ? "" : item.getMediaId()); - entry.put("title", title == null ? "" : title.toString()); - entry.put("subtitle", subtitle == null ? "" : subtitle.toString()); - entry.put("browsable", item.isBrowsable()); - entry.put("playable", item.isPlayable()); - out.put(entry); - } catch (Exception e) { - Log.w(TAG, "media item serialization failed", e); - } - } - return out.toString(); - } - - private void emitConnectResult(int requestId, boolean connected, String rootId, String error) { - FaceclawMediaBrowserListener currentListener = listener; - if (currentListener != null) { - currentListener.onConnectResult(requestId, connected, rootId, error); - } - } - - private void emitBrowseResult(int requestId, String childrenJson, String error) { - FaceclawMediaBrowserListener currentListener = listener; - if (currentListener != null) { - currentListener.onBrowseResult(requestId, childrenJson, error); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.kt new file mode 100644 index 00000000..fb716c84 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.kt @@ -0,0 +1,316 @@ +package com.faceclaw.app + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.content.pm.ResolveInfo +import android.media.browse.MediaBrowser +import android.media.session.MediaController +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.util.Log + +import org.json.JSONArray +import org.json.JSONObject + +import java.util.ArrayList +import java.util.Collections + +/** + * Client for other apps' MediaBrowserService implementations (the mechanism + * Android Auto uses). Binding starts the target player's process even when it + * is not running, so this can list a player's library (playlists, albums, ...) + * and start playback without the phone being unlocked. + * + * Holds at most one connection at a time. All MediaBrowser interaction happens + * on the main thread; results are reported through + * FaceclawMediaBrowserListener, also on the main thread. + */ +class FaceclawMediaBrowser(context: Context) { + companion object { + private const val TAG = "FaceclawMediaBrowser" + private const val BROWSER_SERVICE_ACTION = "android.media.browse.MediaBrowserService" + // Generous: connecting may cold-start the player's process. + private const val CONNECT_TIMEOUT_MS = 15_000L + private const val BROWSE_TIMEOUT_MS = 15_000L + // Unbinding immediately after a play command can race the player promoting + // itself to a foreground service, letting the system kill its process + // before playback starts; keep the binding alive briefly instead. + private const val PLAY_DISCONNECT_GRACE_MS = 5_000L + } + + private val appContext: Context = context.applicationContext + private val mainHandler = Handler(Looper.getMainLooper()) + @Volatile + private var listener: FaceclawMediaBrowserListener? = null + + // Main-thread only. + private var browser: MediaBrowser? = null + private var generation = 0 + private var lastPlayCommandAtMs = 0L + + fun setListener(listener: FaceclawMediaBrowserListener?) { + this.listener = listener + } + + /** + * Installed apps exposing a media browser service, as JSON sorted by app + * name: [{"packageName": ..., "serviceClass": ..., "appName": ...}, ...]. + * Synchronous (PackageManager lookup only). + */ + fun listBrowsableAppsJson(): String { + val packageManager = appContext.packageManager + val services: List + try { + services = packageManager.queryIntentServices(Intent(BROWSER_SERVICE_ACTION), 0) + } catch (e: Exception) { + Log.w(TAG, "media browser service query failed", e) + return "[]" + } + val apps: MutableList = ArrayList() + for (service in services) { + if (service.serviceInfo == null) { + continue + } + try { + val label: CharSequence? = service.serviceInfo.applicationInfo.loadLabel(packageManager) + val app = JSONObject() + app.put("packageName", service.serviceInfo.packageName) + app.put("serviceClass", service.serviceInfo.name) + app.put("appName", if (label == null) service.serviceInfo.packageName else label.toString()) + apps.add(app) + } catch (e: Exception) { + Log.w(TAG, "media browser service entry failed", e) + } + } + Collections.sort(apps) { a, b -> a.optString("appName").compareTo(b.optString("appName"), ignoreCase = true) } + return JSONArray(apps).toString() + } + + /** + * Connect to an app's media browser service, starting its process if + * needed; replaces any existing connection. Async; reports through + * onConnectResult with the browse-tree root id on success. + */ + fun connect(requestId: Int, packageName: String?, serviceClass: String?) { + mainHandler.post { + closeBrowser() + val myGeneration = generation + val settled = booleanArrayOf(false) + val browserRef = arrayOfNulls(1) + val newBrowser = MediaBrowser( + appContext, + ComponentName(packageName!!, serviceClass!!), + object : MediaBrowser.ConnectionCallback() { + override fun onConnected() { + if (generation != myGeneration || settled[0]) { + return + } + settled[0] = true + var rootId = "" + try { + rootId = browserRef[0]!!.root + } catch (e: Exception) { + Log.w(TAG, "getRoot failed", e) + } + emitConnectResult(requestId, true, rootId, "") + } + + override fun onConnectionFailed() { + if (generation != myGeneration || settled[0]) { + return + } + settled[0] = true + closeBrowser() + emitConnectResult(requestId, false, "", "Connection refused by $packageName") + } + + override fun onConnectionSuspended() { + if (generation != myGeneration) { + return + } + val currentListener = listener + if (currentListener != null) { + currentListener.onDisconnected() + } + } + }, + null + ) + browserRef[0] = newBrowser + browser = newBrowser + mainHandler.postDelayed({ + if (generation != myGeneration || settled[0]) { + return@postDelayed + } + settled[0] = true + closeBrowser() + emitConnectResult(requestId, false, "", "Connection to $packageName timed out") + }, CONNECT_TIMEOUT_MS) + try { + newBrowser.connect() + } catch (e: Exception) { + if (!settled[0]) { + settled[0] = true + closeBrowser() + emitConnectResult(requestId, false, "", "Connection failed: " + e.message) + } + } + } + } + + /** + * Fetch one level of the connected service's content tree. Async; reports + * through onBrowseResult with children as JSON: + * [{"mediaId": ..., "title": ..., "subtitle": ..., "browsable": bool, "playable": bool}, ...]. + */ + fun browse(requestId: Int, parentId: String?) { + mainHandler.post { + val currentBrowser = browser + if (currentBrowser == null || !currentBrowser.isConnected) { + emitBrowseResult(requestId, "", "Not connected") + return@post + } + val myGeneration = generation + val settled = booleanArrayOf(false) + mainHandler.postDelayed({ + if (generation != myGeneration || settled[0]) { + return@postDelayed + } + settled[0] = true + try { + currentBrowser.unsubscribe(parentId!!) + } catch (ignored: Exception) { + } + emitBrowseResult(requestId, "", "Browse timed out") + }, BROWSE_TIMEOUT_MS) + try { + currentBrowser.subscribe(parentId!!, object : MediaBrowser.SubscriptionCallback() { + override fun onChildrenLoaded(loadedParentId: String, children: List) { + if (generation != myGeneration || settled[0]) { + return + } + settled[0] = true + // One snapshot is all we want; unsubscribe outside the callback. + mainHandler.post { + try { + currentBrowser.unsubscribe(loadedParentId) + } catch (ignored: Exception) { + } + } + emitBrowseResult(requestId, serializeChildren(children), "") + } + + override fun onError(erroredParentId: String) { + if (generation != myGeneration || settled[0]) { + return + } + settled[0] = true + mainHandler.post { + try { + currentBrowser.unsubscribe(erroredParentId) + } catch (ignored: Exception) { + } + } + emitBrowseResult(requestId, "", "Browse failed") + } + }) + } catch (e: Exception) { + if (!settled[0]) { + settled[0] = true + emitBrowseResult(requestId, "", "Browse failed: " + e.message) + } + } + } + } + + /** Start playback of a browsed item through the connected service's session. */ + fun playFromMediaId(mediaId: String?) { + mainHandler.post { + val currentBrowser = browser + if (currentBrowser == null || !currentBrowser.isConnected) { + return@post + } + try { + val controller = MediaController(appContext, currentBrowser.sessionToken) + controller.transportControls.playFromMediaId(mediaId, null) + lastPlayCommandAtMs = SystemClock.elapsedRealtime() + } catch (e: Exception) { + Log.w(TAG, "playFromMediaId failed", e) + } + } + } + + fun disconnect() { + mainHandler.post { + val sincePlayMs = SystemClock.elapsedRealtime() - lastPlayCommandAtMs + val graceMs = if (lastPlayCommandAtMs == 0L) 0 else PLAY_DISCONNECT_GRACE_MS - sincePlayMs + if (graceMs <= 0) { + closeBrowser() + return@post + } + val lingering = browser + browser = null + generation++ + if (lingering != null) { + mainHandler.postDelayed({ + try { + lingering.disconnect() + } catch (ignored: Exception) { + } + }, graceMs) + } + } + } + + private fun closeBrowser() { + generation++ + val currentBrowser = browser + if (currentBrowser != null) { + try { + currentBrowser.disconnect() + } catch (ignored: Exception) { + } + browser = null + } + } + + private fun serializeChildren(children: List?): String { + val out = JSONArray() + if (children == null) { + return out.toString() + } + for (item in children) { + try { + val title: CharSequence? = if (item.description == null) null else item.description.title + val subtitle: CharSequence? = if (item.description == null) null else item.description.subtitle + val entry = JSONObject() + entry.put("mediaId", if (item.mediaId == null) "" else item.mediaId) + entry.put("title", if (title == null) "" else title.toString()) + entry.put("subtitle", if (subtitle == null) "" else subtitle.toString()) + entry.put("browsable", item.isBrowsable) + entry.put("playable", item.isPlayable) + out.put(entry) + } catch (e: Exception) { + Log.w(TAG, "media item serialization failed", e) + } + } + return out.toString() + } + + private fun emitConnectResult(requestId: Int, connected: Boolean, rootId: String?, error: String?) { + val currentListener = listener + if (currentListener != null) { + currentListener.onConnectResult(requestId, connected, rootId, error) + } + } + + private fun emitBrowseResult(requestId: Int, childrenJson: String?, error: String?) { + val currentListener = listener + if (currentListener != null) { + currentListener.onBrowseResult(requestId, childrenJson, error) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java deleted file mode 100644 index c8775f40..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java +++ /dev/null @@ -1,576 +0,0 @@ -package com.faceclaw.app; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.database.ContentObserver; -import android.graphics.Bitmap; -import android.media.AudioManager; -import android.media.MediaDescription; -import android.media.MediaMetadata; -import android.media.session.MediaController; -import android.media.session.MediaSession; -import android.media.session.MediaSessionManager; -import android.media.session.PlaybackState; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; -import android.provider.Settings; -import android.util.Log; - -import org.json.JSONArray; -import org.json.JSONObject; - -import java.util.List; -import java.util.HashSet; -import java.util.Set; - -public class FaceclawMediaController { - private static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners"; - - private final Context appContext; - private final Object lock = new Object(); - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private final ComponentName listenerComponent; - private final MediaSessionManager sessionManager; - private final AudioManager audioManager; - - private final MediaController.Callback controllerCallback = new MediaController.Callback() { - @Override - public void onPlaybackStateChanged(PlaybackState state) { - synchronized (lock) { - emitStateLocked(); - } - } - - @Override - public void onMetadataChanged(MediaMetadata metadata) { - synchronized (lock) { - emitStateLocked(); - } - } - - @Override - public void onQueueChanged(List queue) { - synchronized (lock) { - emitStateLocked(); - } - } - - @Override - public void onSessionDestroyed() { - synchronized (lock) { - refreshActiveControllerLocked(null); - } - } - }; - - private final MediaSessionManager.OnActiveSessionsChangedListener sessionsChangedListener = controllers -> { - synchronized (lock) { - refreshActiveControllerLocked(controllers); - } - }; - - /** - * Fires when the user grants or revokes notification-listener access in - * system settings. Session access depends on that grant, so the sessions - * listener is (re)registered and the state re-emitted whenever it changes; - * otherwise a grant made after start() would never be noticed. - */ - private final ContentObserver notificationAccessObserver = new ContentObserver(mainHandler) { - @Override - public void onChange(boolean selfChange) { - synchronized (lock) { - if (!started) return; - syncSessionsListenerLocked(); - refreshActiveControllerLocked(null); - } - } - }; - - private volatile FaceclawMediaControllerListener listener; - private MediaController activeController; - private boolean started; - private boolean sessionsListenerRegistered; - private Set ignoredPackages = new HashSet<>(); - - public FaceclawMediaController(Context context) { - this.appContext = context.getApplicationContext(); - this.listenerComponent = new ComponentName(appContext, FaceclawMediaNotificationListenerService.class); - this.sessionManager = (MediaSessionManager) appContext.getSystemService(Context.MEDIA_SESSION_SERVICE); - this.audioManager = (AudioManager) appContext.getSystemService(Context.AUDIO_SERVICE); - } - - public void setListener(FaceclawMediaControllerListener listener) { - synchronized (lock) { - this.listener = listener; - emitStateLocked(); - } - } - - public void start() { - synchronized (lock) { - if (started) { - emitStateLocked(); - return; - } - started = true; - try { - appContext.getContentResolver().registerContentObserver( - Settings.Secure.getUriFor(ENABLED_NOTIFICATION_LISTENERS), - false, - notificationAccessObserver - ); - } catch (Exception e) { - Log.w("FaceclawMedia", "notification access observer registration failed", e); - } - syncSessionsListenerLocked(); - refreshActiveControllerLocked(null); - } - } - - /** - * Keep the active-sessions listener registered exactly while notification - * access is granted. Registration throws SecurityException without the - * grant, so this is retried from the settings observer rather than only - * attempted once at start(). - */ - private void syncSessionsListenerLocked() { - if (sessionManager == null) return; - boolean accessEnabled = started && isNotificationAccessEnabled(); - if (accessEnabled && !sessionsListenerRegistered) { - try { - sessionManager.addOnActiveSessionsChangedListener( - sessionsChangedListener, - listenerComponent, - mainHandler - ); - sessionsListenerRegistered = true; - } catch (SecurityException ignored) { - } - } else if (!accessEnabled && sessionsListenerRegistered) { - try { - sessionManager.removeOnActiveSessionsChangedListener(sessionsChangedListener); - } catch (SecurityException ignored) { - } - sessionsListenerRegistered = false; - } - } - - /** Apply the complete preference set and immediately choose an allowed session. */ - public void setIgnoredPackagesJson(String packagesJson) { - Set packages = new HashSet<>(); - try { - JSONArray array = new JSONArray(packagesJson); - for (int i = 0; i < array.length(); i++) packages.add(array.getString(i)); - } catch (Exception e) { - Log.w("FaceclawMedia", "invalid ignored packages", e); - return; - } - synchronized (lock) { - if (ignoredPackages.equals(packages)) return; - ignoredPackages = packages; - refreshActiveControllerLocked(null); - } - } - - public void stop() { - synchronized (lock) { - if (!started) { - return; - } - started = false; - try { - appContext.getContentResolver().unregisterContentObserver(notificationAccessObserver); - } catch (Exception ignored) { - } - syncSessionsListenerLocked(); - setActiveControllerLocked(null); - emitStateLocked(); - } - } - - public void playPause() { - synchronized (lock) { - if (activeController == null) { - return; - } - PlaybackState playbackState = activeController.getPlaybackState(); - MediaController.TransportControls controls = activeController.getTransportControls(); - if (playbackState == null) { - controls.play(); - return; - } - switch (playbackState.getState()) { - case PlaybackState.STATE_PLAYING: - case PlaybackState.STATE_BUFFERING: - case PlaybackState.STATE_CONNECTING: - controls.pause(); - return; - default: - controls.play(); - } - } - } - - public void skipNext() { - synchronized (lock) { - if (activeController != null) { - activeController.getTransportControls().skipToNext(); - } - } - } - - public void skipPrevious() { - synchronized (lock) { - if (activeController != null) { - activeController.getTransportControls().skipToPrevious(); - } - } - } - - public void skipToQueueItem(long queueId) { - synchronized (lock) { - if (activeController != null) { - activeController.getTransportControls().skipToQueueItem(queueId); - } - } - } - - /** Current phone media-stream volume normalized to the range 0..100. */ - public int getMediaVolumePercent() { - if (audioManager == null) { - return -1; - } - int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - if (maxVolume <= 0) { - return 0; - } - int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); - return Math.max(0, Math.min(100, Math.round(currentVolume * 100f / maxVolume))); - } - - /** Set the phone media-stream volume from a normalized 0..100 value. */ - public void setMediaVolumePercent(int volumePercent) { - if (audioManager == null) { - return; - } - int clampedPercent = Math.max(0, Math.min(100, volumePercent)); - int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); - int streamVolume = Math.round(clampedPercent * maxVolume / 100f); - audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume, 0); - } - - /** - * Album art for the active session's current item, grayscale, scaled to - * fit within maxSize x maxSize preserving aspect. Returns a gray packet - * (see ImageFileLoader.bitmapToGrayPacket) or an empty array when no art - * is available. gamma and dither are the photographic tone handling - * described on ImageFileLoader.bitmapToGrayPacket; the TS side passes - * its shared photo preset. - */ - public byte[] getAlbumArtGray(int maxSize, float gamma, boolean dither) { - Bitmap art; - synchronized (lock) { - if (activeController == null) { - return new byte[0]; - } - MediaMetadata metadata = activeController.getMetadata(); - if (metadata == null) { - return new byte[0]; - } - art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART); - if (art == null) { - art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ART); - } - if (art == null) { - art = metadata.getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON); - } - } - return ImageFileLoader.bitmapToGrayPacket(art, maxSize, maxSize, gamma, dither); - } - - /** - * The active session's queue (playlist) as JSON: - * [{"id": long, "title": string, "active": bool}, ...]. Empty string when - * the player exposes no queue. - */ - public String getQueueJson() { - synchronized (lock) { - if (activeController == null) { - return ""; - } - List queue = activeController.getQueue(); - if (queue == null || queue.isEmpty()) { - return ""; - } - PlaybackState state = activeController.getPlaybackState(); - long activeId = state == null ? -1 : state.getActiveQueueItemId(); - try { - JSONArray out = new JSONArray(); - for (MediaSession.QueueItem item : queue) { - MediaDescription description = item.getDescription(); - CharSequence title = description == null ? null : description.getTitle(); - JSONObject entry = new JSONObject(); - entry.put("id", item.getQueueId()); - entry.put("title", title == null ? "" : title.toString()); - entry.put("active", item.getQueueId() == activeId); - out.put(entry); - } - return out.toString(); - } catch (Exception e) { - Log.w("FaceclawMedia", "queue serialization failed", e); - return ""; - } - } - } - - public void openNotificationAccessSettings() { - Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - appContext.startActivity(intent); - } - - private void refreshActiveControllerLocked(List controllers) { - if (!started) { - setActiveControllerLocked(null); - emitStateLocked(); - return; - } - if (!isNotificationAccessEnabled()) { - setActiveControllerLocked(null); - emitStateLocked(); - return; - } - if (controllers == null && sessionManager != null) { - try { - controllers = sessionManager.getActiveSessions(listenerComponent); - } catch (SecurityException ignored) { - controllers = null; - } - } - emitSessionAppsLocked(controllers); - setActiveControllerLocked(chooseController(controllers)); - emitStateLocked(); - } - - private MediaController chooseController(List controllers) { - if (controllers == null || controllers.isEmpty()) { - return null; - } - MediaController first = null; - for (MediaController controller : controllers) { - if (ignoredPackages.contains(controller.getPackageName())) continue; - if (first == null) first = controller; - PlaybackState playbackState = controller.getPlaybackState(); - if (playbackState != null && playbackState.getState() == PlaybackState.STATE_PLAYING) { - return controller; - } - } - return first; - } - - private void emitSessionAppsLocked(List controllers) { - FaceclawMediaControllerListener currentListener = listener; - if (currentListener == null || controllers == null) return; - JSONArray apps = new JSONArray(); - Set seen = new HashSet<>(); - for (MediaController controller : controllers) { - String packageName = safe(controller.getPackageName()); - if (packageName.isEmpty() || !seen.add(packageName)) continue; - try { - JSONObject app = new JSONObject(); - app.put("packageName", packageName); - app.put("appName", getApplicationLabel(packageName)); - apps.put(app); - } catch (Exception e) { - Log.w("FaceclawMedia", "session app serialization failed", e); - } - } - String json = apps.toString(); - mainHandler.post(() -> currentListener.onSessionAppsChanged(json)); - } - - private void setActiveControllerLocked(MediaController controller) { - if (sameController(activeController, controller)) { - return; - } - if (activeController != null) { - activeController.unregisterCallback(controllerCallback); - } - activeController = controller; - if (activeController != null) { - activeController.registerCallback(controllerCallback, mainHandler); - } - } - - private boolean sameController(MediaController a, MediaController b) { - if (a == b) { - return true; - } - if (a == null || b == null) { - return false; - } - return a.getSessionToken().equals(b.getSessionToken()); - } - - private boolean isNotificationAccessEnabled() { - String enabledListeners = Settings.Secure.getString( - appContext.getContentResolver(), - ENABLED_NOTIFICATION_LISTENERS - ); - if (enabledListeners == null || enabledListeners.isEmpty()) { - return false; - } - String fullName = listenerComponent.flattenToString(); - String shortName = listenerComponent.flattenToShortString(); - return enabledListeners.contains(fullName) - || enabledListeners.contains(shortName) - || enabledListeners.contains(appContext.getPackageName()); - } - - private void emitStateLocked() { - FaceclawMediaControllerListener currentListener = listener; - if (currentListener == null) { - return; - } - - String playbackState = started ? "idle" : "stopped"; - String packageName = ""; - String appName = ""; - String title = ""; - String artist = ""; - String album = ""; - long positionMs = -1L; - long durationMs = -1L; - float playbackSpeed = 0f; - boolean canPlayPause = false; - boolean canSkipNext = false; - boolean canSkipPrevious = false; - boolean accessEnabled = isNotificationAccessEnabled(); - String status; - - if (!accessEnabled) { - playbackState = "notification-access-required"; - status = "Notification access required."; - } else if (activeController == null) { - status = "No active media session."; - } else { - packageName = safe(activeController.getPackageName()); - appName = getApplicationLabel(packageName); - PlaybackState state = activeController.getPlaybackState(); - MediaMetadata metadata = activeController.getMetadata(); - playbackState = playbackStateName(state); - if (metadata != null) { - title = safe(metadata.getString(MediaMetadata.METADATA_KEY_TITLE)); - artist = safe(metadata.getString(MediaMetadata.METADATA_KEY_ARTIST)); - album = safe(metadata.getString(MediaMetadata.METADATA_KEY_ALBUM)); - durationMs = metadata.getLong(MediaMetadata.METADATA_KEY_DURATION); - if (durationMs <= 0L) { - durationMs = -1L; - } - } - if (state != null) { - positionMs = estimatedPositionMs(state, durationMs); - playbackSpeed = state.getPlaybackSpeed(); - } - long actions = state == null ? 0L : state.getActions(); - canPlayPause = (actions & PlaybackState.ACTION_PLAY_PAUSE) != 0 - || (actions & PlaybackState.ACTION_PLAY) != 0 - || (actions & PlaybackState.ACTION_PAUSE) != 0; - canSkipNext = (actions & PlaybackState.ACTION_SKIP_TO_NEXT) != 0; - canSkipPrevious = (actions & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0; - status = packageName.isEmpty() ? "Active media session." : "Active session: " + packageName; - } - - final String finalPlaybackState = playbackState; - final String finalPackageName = packageName; - final String finalAppName = appName; - final String finalTitle = title; - final String finalArtist = artist; - final String finalAlbum = album; - final long finalPositionMs = positionMs; - final long finalDurationMs = durationMs; - final float finalPlaybackSpeed = playbackSpeed; - final boolean finalCanPlayPause = canPlayPause; - final boolean finalCanSkipNext = canSkipNext; - final boolean finalCanSkipPrevious = canSkipPrevious; - final boolean finalAccessEnabled = accessEnabled; - final String finalStatus = status; - - mainHandler.post(() -> currentListener.onStateChange( - finalPlaybackState, - finalPackageName, - finalAppName, - finalTitle, - finalArtist, - finalAlbum, - finalPositionMs, - finalDurationMs, - finalPlaybackSpeed, - finalCanPlayPause, - finalCanSkipNext, - finalCanSkipPrevious, - finalAccessEnabled, - finalStatus - )); - } - - private String playbackStateName(PlaybackState state) { - if (state == null) { - return "idle"; - } - switch (state.getState()) { - case PlaybackState.STATE_PLAYING: - return "playing"; - case PlaybackState.STATE_PAUSED: - return "paused"; - case PlaybackState.STATE_BUFFERING: - case PlaybackState.STATE_CONNECTING: - return "buffering"; - case PlaybackState.STATE_STOPPED: - return "stopped"; - default: - return "idle"; - } - } - - /** PlaybackState positions are snapshots; advance a playing snapshot to now. */ - private long estimatedPositionMs(PlaybackState state, long durationMs) { - long positionMs = state.getPosition(); - if (positionMs == PlaybackState.PLAYBACK_POSITION_UNKNOWN) { - return -1L; - } - if (state.getState() == PlaybackState.STATE_PLAYING) { - long updatedAtMs = state.getLastPositionUpdateTime(); - if (updatedAtMs > 0L) { - positionMs += (long) ((SystemClock.elapsedRealtime() - updatedAtMs) * state.getPlaybackSpeed()); - } - } - positionMs = Math.max(0L, positionMs); - return durationMs > 0L ? Math.min(positionMs, durationMs) : positionMs; - } - - /** Resolve a media session's package id to the user-facing installed app name. */ - private String getApplicationLabel(String packageName) { - if (packageName == null || packageName.isEmpty()) { - return ""; - } - PackageManager packageManager = appContext.getPackageManager(); - try { - ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0); - CharSequence label = packageManager.getApplicationLabel(applicationInfo); - if (label != null && label.length() > 0) { - return label.toString(); - } - } catch (PackageManager.NameNotFoundException ignored) { - } - return packageName; - } - - private String safe(String value) { - return value == null ? "" : value; - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.kt new file mode 100644 index 00000000..b7f8ca5a --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.kt @@ -0,0 +1,577 @@ +package com.faceclaw.app + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.pm.ApplicationInfo +import android.content.pm.PackageManager +import android.database.ContentObserver +import android.graphics.Bitmap +import android.media.AudioManager +import android.media.MediaDescription +import android.media.MediaMetadata +import android.media.session.MediaController +import android.media.session.MediaSession +import android.media.session.MediaSessionManager +import android.media.session.PlaybackState +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.provider.Settings +import android.util.Log + +import org.json.JSONArray +import org.json.JSONObject + +import java.util.HashSet + +class FaceclawMediaController(context: Context) { + companion object { + private const val ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners" + } + + private val appContext: Context = context.applicationContext + private val lock = Any() + private val mainHandler = Handler(Looper.getMainLooper()) + private val listenerComponent: ComponentName + private val sessionManager: MediaSessionManager? + private val audioManager: AudioManager? + + private val controllerCallback: MediaController.Callback = object : MediaController.Callback() { + override fun onPlaybackStateChanged(state: PlaybackState?) { + synchronized(lock) { + emitStateLocked() + } + } + + override fun onMetadataChanged(metadata: MediaMetadata?) { + synchronized(lock) { + emitStateLocked() + } + } + + override fun onQueueChanged(queue: MutableList?) { + synchronized(lock) { + emitStateLocked() + } + } + + override fun onSessionDestroyed() { + synchronized(lock) { + refreshActiveControllerLocked(null) + } + } + } + + private val sessionsChangedListener = MediaSessionManager.OnActiveSessionsChangedListener { controllers -> + synchronized(lock) { + refreshActiveControllerLocked(controllers) + } + } + + /** + * Fires when the user grants or revokes notification-listener access in + * system settings. Session access depends on that grant, so the sessions + * listener is (re)registered and the state re-emitted whenever it changes; + * otherwise a grant made after start() would never be noticed. + */ + private val notificationAccessObserver: ContentObserver = object : ContentObserver(mainHandler) { + override fun onChange(selfChange: Boolean) { + synchronized(lock) { + if (!started) return + syncSessionsListenerLocked() + refreshActiveControllerLocked(null) + } + } + } + + @Volatile + private var listener: FaceclawMediaControllerListener? = null + private var activeController: MediaController? = null + private var started = false + private var sessionsListenerRegistered = false + private var ignoredPackages: Set = HashSet() + + init { + this.listenerComponent = ComponentName(appContext, FaceclawMediaNotificationListenerService::class.java) + this.sessionManager = appContext.getSystemService(Context.MEDIA_SESSION_SERVICE) as MediaSessionManager? + this.audioManager = appContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager? + } + + fun setListener(listener: FaceclawMediaControllerListener?) { + synchronized(lock) { + this.listener = listener + emitStateLocked() + } + } + + fun start() { + synchronized(lock) { + if (started) { + emitStateLocked() + return + } + started = true + try { + appContext.contentResolver.registerContentObserver( + Settings.Secure.getUriFor(ENABLED_NOTIFICATION_LISTENERS), + false, + notificationAccessObserver + ) + } catch (e: Exception) { + Log.w("FaceclawMedia", "notification access observer registration failed", e) + } + syncSessionsListenerLocked() + refreshActiveControllerLocked(null) + } + } + + /** + * Keep the active-sessions listener registered exactly while notification + * access is granted. Registration throws SecurityException without the + * grant, so this is retried from the settings observer rather than only + * attempted once at start(). + */ + private fun syncSessionsListenerLocked() { + if (sessionManager == null) return + val accessEnabled = started && isNotificationAccessEnabled() + if (accessEnabled && !sessionsListenerRegistered) { + try { + sessionManager.addOnActiveSessionsChangedListener( + sessionsChangedListener, + listenerComponent, + mainHandler + ) + sessionsListenerRegistered = true + } catch (ignored: SecurityException) { + } + } else if (!accessEnabled && sessionsListenerRegistered) { + try { + sessionManager.removeOnActiveSessionsChangedListener(sessionsChangedListener) + } catch (ignored: SecurityException) { + } + sessionsListenerRegistered = false + } + } + + /** Apply the complete preference set and immediately choose an allowed session. */ + fun setIgnoredPackagesJson(packagesJson: String?) { + val packages: MutableSet = HashSet() + try { + val array = JSONArray(packagesJson) + for (i in 0 until array.length()) packages.add(array.getString(i)) + } catch (e: Exception) { + Log.w("FaceclawMedia", "invalid ignored packages", e) + return + } + synchronized(lock) { + if (ignoredPackages == packages) return + ignoredPackages = packages + refreshActiveControllerLocked(null) + } + } + + fun stop() { + synchronized(lock) { + if (!started) { + return + } + started = false + try { + appContext.contentResolver.unregisterContentObserver(notificationAccessObserver) + } catch (ignored: Exception) { + } + syncSessionsListenerLocked() + setActiveControllerLocked(null) + emitStateLocked() + } + } + + fun playPause() { + synchronized(lock) { + val controller = activeController + if (controller == null) { + return + } + val playbackState: PlaybackState? = controller.playbackState + val controls: MediaController.TransportControls = controller.transportControls + if (playbackState == null) { + controls.play() + return + } + when (playbackState.state) { + PlaybackState.STATE_PLAYING, + PlaybackState.STATE_BUFFERING, + PlaybackState.STATE_CONNECTING -> { + controls.pause() + return + } + else -> controls.play() + } + } + } + + fun skipNext() { + synchronized(lock) { + val controller = activeController + if (controller != null) { + controller.transportControls.skipToNext() + } + } + } + + fun skipPrevious() { + synchronized(lock) { + val controller = activeController + if (controller != null) { + controller.transportControls.skipToPrevious() + } + } + } + + fun skipToQueueItem(queueId: Long) { + synchronized(lock) { + val controller = activeController + if (controller != null) { + controller.transportControls.skipToQueueItem(queueId) + } + } + } + + /** Current phone media-stream volume normalized to the range 0..100. */ + fun getMediaVolumePercent(): Int { + if (audioManager == null) { + return -1 + } + val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) + if (maxVolume <= 0) { + return 0 + } + val currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + return Math.max(0, Math.min(100, Math.round(currentVolume * 100f / maxVolume))) + } + + /** Set the phone media-stream volume from a normalized 0..100 value. */ + fun setMediaVolumePercent(volumePercent: Int) { + if (audioManager == null) { + return + } + val clampedPercent = Math.max(0, Math.min(100, volumePercent)) + val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) + val streamVolume = Math.round(clampedPercent * maxVolume / 100f) + audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamVolume, 0) + } + + /** + * Album art for the active session's current item, grayscale, scaled to + * fit within maxSize x maxSize preserving aspect. Returns a gray packet + * (see ImageFileLoader.bitmapToGrayPacket) or an empty array when no art + * is available. gamma and dither are the photographic tone handling + * described on ImageFileLoader.bitmapToGrayPacket; the TS side passes + * its shared photo preset. + */ + fun getAlbumArtGray(maxSize: Int, gamma: Float, dither: Boolean): ByteArray { + var art: Bitmap? + synchronized(lock) { + val controller = activeController + if (controller == null) { + return ByteArray(0) + } + val metadata: MediaMetadata? = controller.metadata + if (metadata == null) { + return ByteArray(0) + } + art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART) + if (art == null) { + art = metadata.getBitmap(MediaMetadata.METADATA_KEY_ART) + } + if (art == null) { + art = metadata.getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON) + } + } + return ImageFileLoader.bitmapToGrayPacket(art, maxSize, maxSize, gamma, dither) + } + + /** + * The active session's queue (playlist) as JSON: + * [{"id": long, "title": string, "active": bool}, ...]. Empty string when + * the player exposes no queue. + */ + fun getQueueJson(): String { + synchronized(lock) { + val controller = activeController + if (controller == null) { + return "" + } + val queue: List? = controller.queue + if (queue == null || queue.isEmpty()) { + return "" + } + val state: PlaybackState? = controller.playbackState + val activeId = if (state == null) -1L else state.activeQueueItemId + try { + val out = JSONArray() + for (item in queue) { + val description: MediaDescription? = item.description + val title: CharSequence? = if (description == null) null else description.title + val entry = JSONObject() + entry.put("id", item.queueId) + entry.put("title", if (title == null) "" else title.toString()) + entry.put("active", item.queueId == activeId) + out.put(entry) + } + return out.toString() + } catch (e: Exception) { + Log.w("FaceclawMedia", "queue serialization failed", e) + return "" + } + } + } + + fun openNotificationAccessSettings() { + val intent = Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + appContext.startActivity(intent) + } + + private fun refreshActiveControllerLocked(controllersIn: List?) { + var controllers = controllersIn + if (!started) { + setActiveControllerLocked(null) + emitStateLocked() + return + } + if (!isNotificationAccessEnabled()) { + setActiveControllerLocked(null) + emitStateLocked() + return + } + if (controllers == null && sessionManager != null) { + try { + controllers = sessionManager.getActiveSessions(listenerComponent) + } catch (ignored: SecurityException) { + controllers = null + } + } + emitSessionAppsLocked(controllers) + setActiveControllerLocked(chooseController(controllers)) + emitStateLocked() + } + + private fun chooseController(controllers: List?): MediaController? { + if (controllers == null || controllers.isEmpty()) { + return null + } + var first: MediaController? = null + for (controller in controllers) { + if (ignoredPackages.contains(controller.packageName)) continue + if (first == null) first = controller + val playbackState: PlaybackState? = controller.playbackState + if (playbackState != null && playbackState.state == PlaybackState.STATE_PLAYING) { + return controller + } + } + return first + } + + private fun emitSessionAppsLocked(controllers: List?) { + val currentListener = listener + if (currentListener == null || controllers == null) return + val apps = JSONArray() + val seen: MutableSet = HashSet() + for (controller in controllers) { + val packageName = safe(controller.packageName) + if (packageName.isEmpty() || !seen.add(packageName)) continue + try { + val app = JSONObject() + app.put("packageName", packageName) + app.put("appName", getApplicationLabel(packageName)) + apps.put(app) + } catch (e: Exception) { + Log.w("FaceclawMedia", "session app serialization failed", e) + } + } + val json = apps.toString() + mainHandler.post { currentListener.onSessionAppsChanged(json) } + } + + private fun setActiveControllerLocked(controller: MediaController?) { + if (sameController(activeController, controller)) { + return + } + val previous = activeController + if (previous != null) { + previous.unregisterCallback(controllerCallback) + } + activeController = controller + if (controller != null) { + controller.registerCallback(controllerCallback, mainHandler) + } + } + + private fun sameController(a: MediaController?, b: MediaController?): Boolean { + if (a === b) { + return true + } + if (a == null || b == null) { + return false + } + return a.sessionToken == b.sessionToken + } + + private fun isNotificationAccessEnabled(): Boolean { + val enabledListeners: String? = Settings.Secure.getString( + appContext.contentResolver, + ENABLED_NOTIFICATION_LISTENERS + ) + if (enabledListeners == null || enabledListeners.isEmpty()) { + return false + } + val fullName = listenerComponent.flattenToString() + val shortName = listenerComponent.flattenToShortString() + return enabledListeners.contains(fullName) + || enabledListeners.contains(shortName) + || enabledListeners.contains(appContext.packageName) + } + + private fun emitStateLocked() { + val currentListener = listener + if (currentListener == null) { + return + } + + var playbackState = if (started) "idle" else "stopped" + var packageName = "" + var appName = "" + var title = "" + var artist = "" + var album = "" + var positionMs = -1L + var durationMs = -1L + var playbackSpeed = 0f + var canPlayPause = false + var canSkipNext = false + var canSkipPrevious = false + val accessEnabled = isNotificationAccessEnabled() + val status: String + + val controller = activeController + if (!accessEnabled) { + playbackState = "notification-access-required" + status = "Notification access required." + } else if (controller == null) { + status = "No active media session." + } else { + packageName = safe(controller.packageName) + appName = getApplicationLabel(packageName) + val state: PlaybackState? = controller.playbackState + val metadata: MediaMetadata? = controller.metadata + playbackState = playbackStateName(state) + if (metadata != null) { + title = safe(metadata.getString(MediaMetadata.METADATA_KEY_TITLE)) + artist = safe(metadata.getString(MediaMetadata.METADATA_KEY_ARTIST)) + album = safe(metadata.getString(MediaMetadata.METADATA_KEY_ALBUM)) + durationMs = metadata.getLong(MediaMetadata.METADATA_KEY_DURATION) + if (durationMs <= 0L) { + durationMs = -1L + } + } + if (state != null) { + positionMs = estimatedPositionMs(state, durationMs) + playbackSpeed = state.playbackSpeed + } + val actions = if (state == null) 0L else state.actions + canPlayPause = (actions and PlaybackState.ACTION_PLAY_PAUSE) != 0L + || (actions and PlaybackState.ACTION_PLAY) != 0L + || (actions and PlaybackState.ACTION_PAUSE) != 0L + canSkipNext = (actions and PlaybackState.ACTION_SKIP_TO_NEXT) != 0L + canSkipPrevious = (actions and PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0L + status = if (packageName.isEmpty()) "Active media session." else "Active session: $packageName" + } + + val finalPlaybackState = playbackState + val finalPackageName = packageName + val finalAppName = appName + val finalTitle = title + val finalArtist = artist + val finalAlbum = album + val finalPositionMs = positionMs + val finalDurationMs = durationMs + val finalPlaybackSpeed = playbackSpeed + val finalCanPlayPause = canPlayPause + val finalCanSkipNext = canSkipNext + val finalCanSkipPrevious = canSkipPrevious + val finalAccessEnabled = accessEnabled + val finalStatus = status + + mainHandler.post { + currentListener.onStateChange( + finalPlaybackState, + finalPackageName, + finalAppName, + finalTitle, + finalArtist, + finalAlbum, + finalPositionMs, + finalDurationMs, + finalPlaybackSpeed, + finalCanPlayPause, + finalCanSkipNext, + finalCanSkipPrevious, + finalAccessEnabled, + finalStatus + ) + } + } + + private fun playbackStateName(state: PlaybackState?): String { + if (state == null) { + return "idle" + } + return when (state.state) { + PlaybackState.STATE_PLAYING -> "playing" + PlaybackState.STATE_PAUSED -> "paused" + PlaybackState.STATE_BUFFERING, + PlaybackState.STATE_CONNECTING -> "buffering" + PlaybackState.STATE_STOPPED -> "stopped" + else -> "idle" + } + } + + /** PlaybackState positions are snapshots; advance a playing snapshot to now. */ + private fun estimatedPositionMs(state: PlaybackState, durationMs: Long): Long { + var positionMs = state.position + if (positionMs == PlaybackState.PLAYBACK_POSITION_UNKNOWN) { + return -1L + } + if (state.state == PlaybackState.STATE_PLAYING) { + val updatedAtMs = state.lastPositionUpdateTime + if (updatedAtMs > 0L) { + positionMs += ((SystemClock.elapsedRealtime() - updatedAtMs) * state.playbackSpeed).toLong() + } + } + positionMs = Math.max(0L, positionMs) + return if (durationMs > 0L) Math.min(positionMs, durationMs) else positionMs + } + + /** Resolve a media session's package id to the user-facing installed app name. */ + private fun getApplicationLabel(packageName: String?): String { + if (packageName == null || packageName.isEmpty()) { + return "" + } + val packageManager = appContext.packageManager + try { + val applicationInfo: ApplicationInfo = packageManager.getApplicationInfo(packageName, 0) + val label: CharSequence? = packageManager.getApplicationLabel(applicationInfo) + if (label != null && label.length > 0) { + return label.toString() + } + } catch (ignored: PackageManager.NameNotFoundException) { + } + return packageName + } + + private fun safe(value: String?): String { + return value ?: "" + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.java deleted file mode 100644 index 8ca97f00..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.java +++ /dev/null @@ -1,657 +0,0 @@ -package com.faceclaw.app; - -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.Icon; -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.service.notification.NotificationListenerService; -import android.service.notification.StatusBarNotification; -import android.util.Log; - -import java.io.ByteArrayOutputStream; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -public class FaceclawMediaNotificationListenerService extends NotificationListenerService { - private static final String TAG = "FaceclawNotify"; - private static final double NOTIFICATION_ICON_GAMMA = 1.6; - private static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName"; - - private static volatile FaceclawMediaNotificationListenerService activeService; - private static final Handler mainHandler = new Handler(Looper.getMainLooper()); - private static final Set notificationListeners = new CopyOnWriteArraySet<>(); - private static final Set activeNotificationWakeKeys = new HashSet<>(); - - @Override - public void onCreate() { - super.onCreate(); - activeService = this; - } - - @Override - public void onDestroy() { - if (activeService == this) { - activeService = null; - } - super.onDestroy(); - } - - @Override - public void onListenerConnected() { - activeService = this; - super.onListenerConnected(); - refreshActiveNotificationWakeKeys(this); - } - - @Override - public void onListenerDisconnected() { - if (activeService == this) { - activeService = null; - } - super.onListenerDisconnected(); - } - - @Override - public void onNotificationPosted(StatusBarNotification statusBarNotification) { - super.onNotificationPosted(statusBarNotification); - if (!shouldShowNotificationInList(this, statusBarNotification)) { - forgetActiveNotificationWakeKey(statusBarNotification); - return; - } - if (shouldEmitNotificationPosted(statusBarNotification)) { - emitNotificationPosted(statusBarNotification.getKey()); - } - } - - @Override - public void onNotificationRemoved(StatusBarNotification statusBarNotification) { - forgetActiveNotificationWakeKey(statusBarNotification); - super.onNotificationRemoved(statusBarNotification); - } - - public static void addNotificationListener(FaceclawNotificationListener listener) { - if (listener != null) { - notificationListeners.add(listener); - } - } - - public static void removeNotificationListener(FaceclawNotificationListener listener) { - if (listener != null) { - notificationListeners.remove(listener); - } - } - - public static boolean hasActiveNotificationTitle(String expectedTitle) { - FaceclawMediaNotificationListenerService service = activeService; - if (service == null || expectedTitle == null || expectedTitle.isEmpty()) { - return false; - } - StatusBarNotification[] notifications; - try { - notifications = service.getActiveNotifications(); - } catch (SecurityException e) { - Log.w(TAG, "notification access denied while checking active notifications", e); - return false; - } catch (Throwable t) { - Log.w(TAG, "failed to check active notifications", t); - return false; - } - if (notifications == null || notifications.length == 0) { - return false; - } - for (StatusBarNotification notification : notifications) { - if (notification == null || notification.getNotification() == null) { - continue; - } - Bundle extras = notification.getNotification().extras; - if (extras == null) { - continue; - } - CharSequence title = extras.getCharSequence(Notification.EXTRA_TITLE); - if (title != null && expectedTitle.contentEquals(title)) { - return true; - } - } - return false; - } - - public static byte[] getActiveNotificationIconGrays(int iconSize, int maxIcons) { - FaceclawMediaNotificationListenerService service = activeService; - int size = Math.max(1, Math.min(96, iconSize)); - int limit = Math.max(0, maxIcons); - if (service == null || limit == 0) { - return new byte[0]; - } - - StatusBarNotification[] notifications; - try { - notifications = service.getActiveNotifications(); - } catch (SecurityException e) { - Log.w(TAG, "notification access denied while reading icons", e); - return new byte[0]; - } catch (Throwable t) { - Log.w(TAG, "failed to read notification icons", t); - return new byte[0]; - } - if (notifications == null || notifications.length == 0) { - return new byte[0]; - } - - ByteArrayOutputStream out = new ByteArrayOutputStream(size * size * Math.min(limit, notifications.length)); - Set emittedGroupKeys = new HashSet<>(); - int emitted = 0; - for (StatusBarNotification statusBarNotification : notifications) { - if (!shouldShowNotificationIcon(service, statusBarNotification)) { - continue; - } - String dedupeGroupKey = getNotificationDedupeGroupKey(statusBarNotification); - if (dedupeGroupKey != null && emittedGroupKeys.contains(dedupeGroupKey)) { - continue; - } - Drawable drawable = loadNotificationIcon(service, statusBarNotification.getNotification()); - if (drawable == null) { - Log.i(TAG, "icon skipped (no drawable): " + statusBarNotification.getPackageName()); - continue; - } - Log.i(TAG, "icon[" + emitted + "] pkg=" + statusBarNotification.getPackageName() - + " drawable=" + drawable.getClass().getSimpleName() - + " intrinsic=" + drawable.getIntrinsicWidth() + "x" + drawable.getIntrinsicHeight()); - appendIconGrayBytes(drawable, size, out, service, emitted, statusBarNotification.getPackageName()); - if (dedupeGroupKey != null) { - emittedGroupKeys.add(dedupeGroupKey); - } - emitted += 1; - if (emitted >= limit) { - break; - } - } - return out.toByteArray(); - } - - /** - * Grayscale icon (iconSize*iconSize bytes) for one active notification, - * identified by its key; empty array when the notification or its icon is - * unavailable. Shares the extraction/scaling pipeline with the tray icon - * strip above. - */ - public static byte[] getNotificationIconGrayForKey(String key, int iconSize) { - FaceclawMediaNotificationListenerService service = activeService; - int size = Math.max(1, Math.min(96, iconSize)); - if (service == null) { - return new byte[0]; - } - StatusBarNotification statusBarNotification = findActiveNotificationByKey(service, key); - if (statusBarNotification == null || statusBarNotification.getNotification() == null) { - return new byte[0]; - } - Drawable drawable = loadNotificationIcon(service, statusBarNotification.getNotification()); - if (drawable == null) { - return new byte[0]; - } - ByteArrayOutputStream out = new ByteArrayOutputStream(size * size); - appendIconGrayBytes(drawable, size, out, service, -1, statusBarNotification.getPackageName()); - return out.toByteArray(); - } - - public static String getActiveNotificationsJson(int maxNotifications) { - FaceclawMediaNotificationListenerService service = activeService; - int limit = Math.max(0, maxNotifications); - if (service == null || limit == 0) { - return "[]"; - } - - StatusBarNotification[] notifications; - try { - notifications = service.getActiveNotifications(); - } catch (SecurityException e) { - Log.w(TAG, "notification access denied while reading notifications", e); - return "[]"; - } catch (Throwable t) { - Log.w(TAG, "failed to read notifications", t); - return "[]"; - } - if (notifications == null || notifications.length == 0) { - return "[]"; - } - - Arrays.sort(notifications, new Comparator() { - @Override - public int compare(StatusBarNotification a, StatusBarNotification b) { - long left = a == null ? 0 : a.getPostTime(); - long right = b == null ? 0 : b.getPostTime(); - return Long.compare(right, left); - } - }); - - JSONArray out = new JSONArray(); - for (StatusBarNotification statusBarNotification : notifications) { - if (out.length() >= limit) { - break; - } - if (!shouldShowNotificationInList(service, statusBarNotification)) { - continue; - } - try { - out.put(buildNotificationJson(service, statusBarNotification)); - } catch (Throwable t) { - Log.w(TAG, "failed to serialize notification", t); - } - } - return out.toString(); - } - - public static boolean invokeNotificationAction(String key, int actionIndex) { - FaceclawMediaNotificationListenerService service = activeService; - StatusBarNotification statusBarNotification = findActiveNotificationByKey(service, key); - if (statusBarNotification == null || statusBarNotification.getNotification() == null) { - return false; - } - Notification.Action[] actions = statusBarNotification.getNotification().actions; - if (actions == null || actionIndex < 0 || actionIndex >= actions.length) { - return false; - } - PendingIntent intent = actions[actionIndex].actionIntent; - if (intent == null) { - return false; - } - try { - intent.send(); - return true; - } catch (PendingIntent.CanceledException e) { - Log.w(TAG, "notification action pending intent was canceled", e); - return false; - } catch (Throwable t) { - Log.w(TAG, "failed to invoke notification action", t); - return false; - } - } - - public static boolean dismissNotification(String key) { - FaceclawMediaNotificationListenerService service = activeService; - if (service == null || key == null || key.isEmpty()) { - return false; - } - try { - service.cancelNotification(key); - return true; - } catch (SecurityException e) { - Log.w(TAG, "notification access denied while dismissing notification", e); - return false; - } catch (Throwable t) { - Log.w(TAG, "failed to dismiss notification", t); - return false; - } - } - - private static void emitNotificationPosted(String key) { - if (key == null || key.isEmpty() || notificationListeners.isEmpty()) { - return; - } - for (FaceclawNotificationListener listener : notificationListeners) { - mainHandler.post(() -> { - try { - listener.onNotificationPosted(key); - } catch (Throwable t) { - Log.w(TAG, "notification listener failed", t); - } - }); - } - } - - private static void refreshActiveNotificationWakeKeys(FaceclawMediaNotificationListenerService service) { - StatusBarNotification[] notifications; - try { - notifications = service.getActiveNotifications(); - } catch (Throwable t) { - Log.w(TAG, "failed to refresh active notification wake keys", t); - return; - } - synchronized (activeNotificationWakeKeys) { - activeNotificationWakeKeys.clear(); - if (notifications == null) { - return; - } - for (StatusBarNotification statusBarNotification : notifications) { - if (shouldShowNotificationInList(service, statusBarNotification)) { - String key = statusBarNotification.getKey(); - if (key != null && !key.isEmpty()) { - activeNotificationWakeKeys.add(key); - } - } - } - } - } - - private static boolean shouldEmitNotificationPosted(StatusBarNotification statusBarNotification) { - String key = statusBarNotification.getKey(); - if (key == null || key.isEmpty()) { - return true; - } - - boolean alreadyActive; - synchronized (activeNotificationWakeKeys) { - alreadyActive = activeNotificationWakeKeys.contains(key); - activeNotificationWakeKeys.add(key); - } - return !alreadyActive || !isPersistentNotification(statusBarNotification); - } - - private static void forgetActiveNotificationWakeKey(StatusBarNotification statusBarNotification) { - if (statusBarNotification == null) { - return; - } - String key = statusBarNotification.getKey(); - if (key == null || key.isEmpty()) { - return; - } - synchronized (activeNotificationWakeKeys) { - activeNotificationWakeKeys.remove(key); - } - } - - private static boolean isPersistentNotification(StatusBarNotification statusBarNotification) { - Notification notification = statusBarNotification.getNotification(); - if (notification == null) { - return false; - } - int persistentFlags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; - return (notification.flags & persistentFlags) != 0; - } - - private static boolean shouldShowNotificationIcon(FaceclawMediaNotificationListenerService service, StatusBarNotification statusBarNotification) { - if (!shouldShowNotificationInList(service, statusBarNotification)) { - return false; - } - Notification notification = statusBarNotification.getNotification(); - if ((notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0) { - return false; - } - return true; - } - - private static boolean shouldShowNotificationInList(FaceclawMediaNotificationListenerService service, StatusBarNotification statusBarNotification) { - if (statusBarNotification == null || statusBarNotification.getNotification() == null) { - return false; - } - // Our own notifications stay out of the mirror: the foreground-service - // one is noise, and the Timers app rings on the glasses itself (its - // phone notification is for the phone), so mirroring it would stack a - // notification modal over the ringing screen. - if (service.getPackageName().equals(statusBarNotification.getPackageName())) { - return false; - } - Notification notification = statusBarNotification.getNotification(); - if (Notification.CATEGORY_TRANSPORT.equals(notification.category)) { - return false; - } - Bundle extras = notification.extras; - if (extras != null && extras.containsKey("android.mediaSession")) { - return false; - } - - NotificationListenerService.RankingMap rankingMap = service.getCurrentRanking(); - if (rankingMap == null) { - return true; - } - NotificationListenerService.Ranking ranking = new NotificationListenerService.Ranking(); - if (!rankingMap.getRanking(statusBarNotification.getKey(), ranking)) { - return true; - } - int importance = ranking.getImportance(); - return importance > NotificationManager.IMPORTANCE_MIN; - } - - private static String getNotificationDedupeGroupKey(StatusBarNotification statusBarNotification) { - Notification notification = statusBarNotification.getNotification(); - if (notification.getGroup() == null && statusBarNotification.getOverrideGroupKey() == null) { - return null; - } - String groupKey = statusBarNotification.getGroupKey(); - if (groupKey == null || groupKey.isEmpty()) { - return null; - } - // Group children often share the same small icon. Emit only one icon for the group. - return groupKey; - } - - private static Drawable loadNotificationIcon(FaceclawMediaNotificationListenerService service, Notification notification) { - try { - Icon smallIcon = notification.getSmallIcon(); - if (smallIcon != null) { - Drawable drawable = smallIcon.loadDrawable(service); - if (drawable != null) { - // Status-bar small icons are alpha templates: the platform - // draws them tinted and ignores their color channels, which - // apps may fill with garbage (Discord ships noise there). - // Tint white so the shape comes from alpha alone, matching - // how the status bar renders them. - drawable.mutate(); - drawable.setTint(Color.WHITE); - if (drawable instanceof BitmapDrawable) { - ((BitmapDrawable) drawable).setFilterBitmap(true); - } - return drawable; - } - } - } catch (Throwable t) { - Log.w(TAG, "failed to load small notification icon", t); - } - try { - // Large icons are real color images (avatars, album art); keep color. - Icon largeIcon = notification.getLargeIcon(); - if (largeIcon != null) { - return largeIcon.loadDrawable(service); - } - } catch (Throwable t) { - Log.w(TAG, "failed to load large notification icon", t); - } - return null; - } - - private static void appendIconGrayBytes(Drawable drawable, int size, ByteArrayOutputStream out, - FaceclawMediaNotificationListenerService service, int index, String packageName) { - Bitmap bitmap = renderIconScaled(drawable, size); - dumpIconDebugPng(service, index, packageName, bitmap); - for (int y = 0; y < size; y++) { - for (int x = 0; x < size; x++) { - int color = bitmap.getPixel(x, y); - int alpha = Color.alpha(color); - double grayLinear = (0.2126 * Color.red(color) + 0.7152 * Color.green(color) + 0.0722 * Color.blue(color)) * alpha / (255.0 * 255.0); - int gray = (int) Math.round(255.0 * Math.pow(Math.max(0.0, Math.min(1.0, grayLinear)), NOTIFICATION_ICON_GAMMA)); - out.write(gray & 0xff); - } - } - bitmap.recycle(); - } - - /** - * Render a drawable at the target size with proper downscaling. Detailed - * sources (e.g. avatar bitmaps used as notification icons) are rendered at - * native resolution and reduced by repeated halving: a single filtered pass - * from, say, 126px to 24px samples too sparsely and turns fine detail into - * speckle that reads as a garbled icon. - */ - private static Bitmap renderIconScaled(Drawable drawable, int size) { - int renderW = Math.max(size, drawable.getIntrinsicWidth()); - int renderH = Math.max(size, drawable.getIntrinsicHeight()); - Bitmap bitmap = Bitmap.createBitmap(renderW, renderH, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - drawable.setBounds(0, 0, renderW, renderH); - drawable.draw(canvas); - while (bitmap.getWidth() >= size * 2 && bitmap.getHeight() >= size * 2) { - Bitmap halved = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / 2, bitmap.getHeight() / 2, true); - bitmap.recycle(); - bitmap = halved; - } - if (bitmap.getWidth() != size || bitmap.getHeight() != size) { - Bitmap scaled = Bitmap.createScaledBitmap(bitmap, size, size, true); - bitmap.recycle(); - bitmap = scaled; - } - return bitmap; - } - - /** - * Debug aid for garbled-icon reports: saves each rendered icon to - * /debug-icons/ (adb-pullable) so extraction problems can - * be told apart from downstream compositing/transmission problems. Cheap: - * runs at most once per icon-cache refresh on tiny bitmaps. - */ - private static void dumpIconDebugPng(FaceclawMediaNotificationListenerService service, int index, String packageName, Bitmap bitmap) { - if (index < 0) { - return; - } - try { - java.io.File dir = new java.io.File(service.getExternalFilesDir(null), "debug-icons"); - if (!dir.exists() && !dir.mkdirs()) { - return; - } - String safeName = packageName == null ? "unknown" : packageName.replaceAll("[^A-Za-z0-9._-]", "_"); - java.io.File file = new java.io.File(dir, "icon-" + index + "-" + safeName + ".png"); - try (java.io.FileOutputStream stream = new java.io.FileOutputStream(file)) { - bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); - } - } catch (Throwable t) { - Log.w(TAG, "failed to dump debug icon", t); - } - } - - private static StatusBarNotification findActiveNotificationByKey(FaceclawMediaNotificationListenerService service, String key) { - if (service == null || key == null || key.isEmpty()) { - return null; - } - StatusBarNotification[] notifications; - try { - notifications = service.getActiveNotifications(); - } catch (Throwable t) { - Log.w(TAG, "failed to find active notification", t); - return null; - } - if (notifications == null) { - return null; - } - for (StatusBarNotification statusBarNotification : notifications) { - if (statusBarNotification != null && key.equals(statusBarNotification.getKey())) { - return statusBarNotification; - } - } - return null; - } - - private static JSONObject buildNotificationJson(FaceclawMediaNotificationListenerService service, StatusBarNotification statusBarNotification) - throws JSONException { - Notification notification = statusBarNotification.getNotification(); - Bundle extras = notification.extras; - JSONObject out = new JSONObject(); - out.put("key", statusBarNotification.getKey()); - out.put("packageName", statusBarNotification.getPackageName()); - out.put("appName", getNotificationAppName(service, statusBarNotification)); - out.put("postTime", statusBarNotification.getPostTime()); - out.put("when", notification.when); - putString(out, "category", notification.category); - if (extras != null) { - putCharSequence(out, "title", firstNonEmpty( - extras.getCharSequence(Notification.EXTRA_TITLE_BIG), - extras.getCharSequence(Notification.EXTRA_TITLE) - )); - putCharSequence(out, "text", extras.getCharSequence(Notification.EXTRA_TEXT)); - putCharSequence(out, "bigText", extras.getCharSequence(Notification.EXTRA_BIG_TEXT)); - putCharSequence(out, "subText", extras.getCharSequence(Notification.EXTRA_SUB_TEXT)); - putCharSequence(out, "infoText", extras.getCharSequence(Notification.EXTRA_INFO_TEXT)); - putCharSequence(out, "summaryText", extras.getCharSequence(Notification.EXTRA_SUMMARY_TEXT)); - CharSequence[] textLines = extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES); - JSONArray lines = new JSONArray(); - if (textLines != null) { - for (CharSequence line : textLines) { - String text = charSequenceToString(line); - if (!text.isEmpty()) { - lines.put(text); - } - } - } - out.put("lines", lines); - } else { - out.put("lines", new JSONArray()); - } - - JSONArray actionsJson = new JSONArray(); - Notification.Action[] actions = notification.actions; - if (actions != null) { - for (int index = 0; index < actions.length; index++) { - Notification.Action action = actions[index]; - if (action == null) { - continue; - } - String title = charSequenceToString(action.title); - if (title.isEmpty()) { - continue; - } - JSONObject actionJson = new JSONObject(); - actionJson.put("index", index); - actionJson.put("title", title); - actionJson.put("enabled", action.actionIntent != null); - actionsJson.put(actionJson); - } - } - out.put("actions", actionsJson); - return out; - } - - private static String getNotificationAppName(FaceclawMediaNotificationListenerService service, StatusBarNotification statusBarNotification) { - Notification notification = statusBarNotification.getNotification(); - Bundle extras = notification.extras; - if (extras != null) { - String substituteName = charSequenceToString(extras.getCharSequence(EXTRA_SUBSTITUTE_APP_NAME)); - if (!substituteName.isEmpty()) { - return substituteName; - } - } - return getAppLabel(service, statusBarNotification.getPackageName()); - } - - private static String getAppLabel(FaceclawMediaNotificationListenerService service, String packageName) { - if (packageName == null || packageName.isEmpty()) { - return ""; - } - try { - CharSequence label = service - .getPackageManager() - .getApplicationLabel(service.getPackageManager().getApplicationInfo(packageName, 0)); - String text = charSequenceToString(label); - return text.isEmpty() ? packageName : text; - } catch (Throwable t) { - return packageName; - } - } - - private static void putString(JSONObject out, String key, String value) throws JSONException { - out.put(key, value == null ? "" : value); - } - - private static void putCharSequence(JSONObject out, String key, CharSequence value) throws JSONException { - out.put(key, charSequenceToString(value)); - } - - private static CharSequence firstNonEmpty(CharSequence first, CharSequence second) { - return charSequenceToString(first).isEmpty() ? second : first; - } - - private static String charSequenceToString(CharSequence value) { - return value == null ? "" : value.toString(); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.kt new file mode 100644 index 00000000..7c40de56 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.kt @@ -0,0 +1,662 @@ +package com.faceclaw.app + +import android.app.Notification +import android.app.NotificationManager +import android.app.PendingIntent +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable +import android.graphics.drawable.Icon +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.service.notification.NotificationListenerService +import android.service.notification.StatusBarNotification +import android.util.Log + +import java.io.ByteArrayOutputStream +import java.util.Arrays +import java.util.Comparator +import java.util.HashSet +import java.util.concurrent.CopyOnWriteArraySet + +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject + +class FaceclawMediaNotificationListenerService : NotificationListenerService() { + companion object { + private const val TAG = "FaceclawNotify" + private const val NOTIFICATION_ICON_GAMMA = 1.6 + private const val EXTRA_SUBSTITUTE_APP_NAME = "android.substName" + + @Volatile + private var activeService: FaceclawMediaNotificationListenerService? = null + private val mainHandler = Handler(Looper.getMainLooper()) + private val notificationListeners: MutableSet = CopyOnWriteArraySet() + private val activeNotificationWakeKeys: MutableSet = HashSet() + + @JvmStatic + fun addNotificationListener(listener: FaceclawNotificationListener?) { + if (listener != null) { + notificationListeners.add(listener) + } + } + + @JvmStatic + fun removeNotificationListener(listener: FaceclawNotificationListener?) { + if (listener != null) { + notificationListeners.remove(listener) + } + } + + @JvmStatic + fun hasActiveNotificationTitle(expectedTitle: String?): Boolean { + val service = activeService + if (service == null || expectedTitle == null || expectedTitle.isEmpty()) { + return false + } + val notifications: Array? + try { + notifications = service.activeNotifications + } catch (e: SecurityException) { + Log.w(TAG, "notification access denied while checking active notifications", e) + return false + } catch (t: Throwable) { + Log.w(TAG, "failed to check active notifications", t) + return false + } + if (notifications == null || notifications.size == 0) { + return false + } + for (notification in notifications) { + if (notification == null || notification.notification == null) { + continue + } + val extras: Bundle? = notification.notification.extras + if (extras == null) { + continue + } + val title: CharSequence? = extras.getCharSequence(Notification.EXTRA_TITLE) + if (title != null && expectedTitle.contentEquals(title)) { + return true + } + } + return false + } + + @JvmStatic + fun getActiveNotificationIconGrays(iconSize: Int, maxIcons: Int): ByteArray { + val service = activeService + val size = Math.max(1, Math.min(96, iconSize)) + val limit = Math.max(0, maxIcons) + if (service == null || limit == 0) { + return ByteArray(0) + } + + val notifications: Array? + try { + notifications = service.activeNotifications + } catch (e: SecurityException) { + Log.w(TAG, "notification access denied while reading icons", e) + return ByteArray(0) + } catch (t: Throwable) { + Log.w(TAG, "failed to read notification icons", t) + return ByteArray(0) + } + if (notifications == null || notifications.size == 0) { + return ByteArray(0) + } + + val out = ByteArrayOutputStream(size * size * Math.min(limit, notifications.size)) + val emittedGroupKeys: MutableSet = HashSet() + var emitted = 0 + for (statusBarNotification in notifications) { + if (!shouldShowNotificationIcon(service, statusBarNotification)) { + continue + } + val dedupeGroupKey = getNotificationDedupeGroupKey(statusBarNotification!!) + if (dedupeGroupKey != null && emittedGroupKeys.contains(dedupeGroupKey)) { + continue + } + val drawable = loadNotificationIcon(service, statusBarNotification.notification) + if (drawable == null) { + Log.i(TAG, "icon skipped (no drawable): " + statusBarNotification.packageName) + continue + } + Log.i(TAG, "icon[" + emitted + "] pkg=" + statusBarNotification.packageName + + " drawable=" + drawable.javaClass.simpleName + + " intrinsic=" + drawable.intrinsicWidth + "x" + drawable.intrinsicHeight) + appendIconGrayBytes(drawable, size, out, service, emitted, statusBarNotification.packageName) + if (dedupeGroupKey != null) { + emittedGroupKeys.add(dedupeGroupKey) + } + emitted += 1 + if (emitted >= limit) { + break + } + } + return out.toByteArray() + } + + /** + * Grayscale icon (iconSize*iconSize bytes) for one active notification, + * identified by its key; empty array when the notification or its icon is + * unavailable. Shares the extraction/scaling pipeline with the tray icon + * strip above. + */ + @JvmStatic + fun getNotificationIconGrayForKey(key: String?, iconSize: Int): ByteArray { + val service = activeService + val size = Math.max(1, Math.min(96, iconSize)) + if (service == null) { + return ByteArray(0) + } + val statusBarNotification = findActiveNotificationByKey(service, key) + if (statusBarNotification == null || statusBarNotification.notification == null) { + return ByteArray(0) + } + val drawable = loadNotificationIcon(service, statusBarNotification.notification) + if (drawable == null) { + return ByteArray(0) + } + val out = ByteArrayOutputStream(size * size) + appendIconGrayBytes(drawable, size, out, service, -1, statusBarNotification.packageName) + return out.toByteArray() + } + + @JvmStatic + fun getActiveNotificationsJson(maxNotifications: Int): String { + val service = activeService + val limit = Math.max(0, maxNotifications) + if (service == null || limit == 0) { + return "[]" + } + + val notifications: Array? + try { + notifications = service.activeNotifications + } catch (e: SecurityException) { + Log.w(TAG, "notification access denied while reading notifications", e) + return "[]" + } catch (t: Throwable) { + Log.w(TAG, "failed to read notifications", t) + return "[]" + } + if (notifications == null || notifications.size == 0) { + return "[]" + } + + Arrays.sort(notifications, object : Comparator { + override fun compare(a: StatusBarNotification?, b: StatusBarNotification?): Int { + val left = if (a == null) 0L else a.postTime + val right = if (b == null) 0L else b.postTime + return java.lang.Long.compare(right, left) + } + }) + + val out = JSONArray() + for (statusBarNotification in notifications) { + if (out.length() >= limit) { + break + } + if (!shouldShowNotificationInList(service, statusBarNotification)) { + continue + } + try { + out.put(buildNotificationJson(service, statusBarNotification!!)) + } catch (t: Throwable) { + Log.w(TAG, "failed to serialize notification", t) + } + } + return out.toString() + } + + @JvmStatic + fun invokeNotificationAction(key: String?, actionIndex: Int): Boolean { + val service = activeService + val statusBarNotification = findActiveNotificationByKey(service, key) + if (statusBarNotification == null || statusBarNotification.notification == null) { + return false + } + val actions: Array? = statusBarNotification.notification.actions + if (actions == null || actionIndex < 0 || actionIndex >= actions.size) { + return false + } + val intent: PendingIntent? = actions[actionIndex].actionIntent + if (intent == null) { + return false + } + try { + intent.send() + return true + } catch (e: PendingIntent.CanceledException) { + Log.w(TAG, "notification action pending intent was canceled", e) + return false + } catch (t: Throwable) { + Log.w(TAG, "failed to invoke notification action", t) + return false + } + } + + @JvmStatic + fun dismissNotification(key: String?): Boolean { + val service = activeService + if (service == null || key == null || key.isEmpty()) { + return false + } + try { + service.cancelNotification(key) + return true + } catch (e: SecurityException) { + Log.w(TAG, "notification access denied while dismissing notification", e) + return false + } catch (t: Throwable) { + Log.w(TAG, "failed to dismiss notification", t) + return false + } + } + + private fun emitNotificationPosted(key: String?) { + if (key == null || key.isEmpty() || notificationListeners.isEmpty()) { + return + } + for (listener in notificationListeners) { + mainHandler.post { + try { + listener.onNotificationPosted(key) + } catch (t: Throwable) { + Log.w(TAG, "notification listener failed", t) + } + } + } + } + + private fun refreshActiveNotificationWakeKeys(service: FaceclawMediaNotificationListenerService) { + val notifications: Array? + try { + notifications = service.activeNotifications + } catch (t: Throwable) { + Log.w(TAG, "failed to refresh active notification wake keys", t) + return + } + synchronized(activeNotificationWakeKeys) { + activeNotificationWakeKeys.clear() + if (notifications == null) { + return + } + for (statusBarNotification in notifications) { + if (shouldShowNotificationInList(service, statusBarNotification)) { + val key: String? = statusBarNotification!!.key + if (key != null && !key.isEmpty()) { + activeNotificationWakeKeys.add(key) + } + } + } + } + } + + private fun shouldEmitNotificationPosted(statusBarNotification: StatusBarNotification): Boolean { + val key: String? = statusBarNotification.key + if (key == null || key.isEmpty()) { + return true + } + + val alreadyActive: Boolean + synchronized(activeNotificationWakeKeys) { + alreadyActive = activeNotificationWakeKeys.contains(key) + activeNotificationWakeKeys.add(key) + } + return !alreadyActive || !isPersistentNotification(statusBarNotification) + } + + private fun forgetActiveNotificationWakeKey(statusBarNotification: StatusBarNotification?) { + if (statusBarNotification == null) { + return + } + val key: String? = statusBarNotification.key + if (key == null || key.isEmpty()) { + return + } + synchronized(activeNotificationWakeKeys) { + activeNotificationWakeKeys.remove(key) + } + } + + private fun isPersistentNotification(statusBarNotification: StatusBarNotification): Boolean { + val notification: Notification? = statusBarNotification.notification + if (notification == null) { + return false + } + val persistentFlags = Notification.FLAG_ONGOING_EVENT or Notification.FLAG_NO_CLEAR + return (notification.flags and persistentFlags) != 0 + } + + private fun shouldShowNotificationIcon(service: FaceclawMediaNotificationListenerService, statusBarNotification: StatusBarNotification?): Boolean { + if (!shouldShowNotificationInList(service, statusBarNotification)) { + return false + } + val notification = statusBarNotification!!.notification + if ((notification.flags and Notification.FLAG_GROUP_SUMMARY) != 0) { + return false + } + return true + } + + private fun shouldShowNotificationInList(service: FaceclawMediaNotificationListenerService, statusBarNotification: StatusBarNotification?): Boolean { + if (statusBarNotification == null || statusBarNotification.notification == null) { + return false + } + // Our own notifications stay out of the mirror: the foreground-service + // one is noise, and the Timers app rings on the glasses itself (its + // phone notification is for the phone), so mirroring it would stack a + // notification modal over the ringing screen. + if (service.packageName == statusBarNotification.packageName) { + return false + } + val notification = statusBarNotification.notification + if (Notification.CATEGORY_TRANSPORT == notification.category) { + return false + } + val extras: Bundle? = notification.extras + if (extras != null && extras.containsKey("android.mediaSession")) { + return false + } + + val rankingMap: NotificationListenerService.RankingMap? = service.currentRanking + if (rankingMap == null) { + return true + } + val ranking = NotificationListenerService.Ranking() + if (!rankingMap.getRanking(statusBarNotification.key, ranking)) { + return true + } + val importance = ranking.importance + return importance > NotificationManager.IMPORTANCE_MIN + } + + private fun getNotificationDedupeGroupKey(statusBarNotification: StatusBarNotification): String? { + val notification = statusBarNotification.notification + if (notification.group == null && statusBarNotification.overrideGroupKey == null) { + return null + } + val groupKey: String? = statusBarNotification.groupKey + if (groupKey == null || groupKey.isEmpty()) { + return null + } + // Group children often share the same small icon. Emit only one icon for the group. + return groupKey + } + + private fun loadNotificationIcon(service: FaceclawMediaNotificationListenerService, notification: Notification): Drawable? { + try { + val smallIcon: Icon? = notification.smallIcon + if (smallIcon != null) { + val drawable: Drawable? = smallIcon.loadDrawable(service) + if (drawable != null) { + // Status-bar small icons are alpha templates: the platform + // draws them tinted and ignores their color channels, which + // apps may fill with garbage (Discord ships noise there). + // Tint white so the shape comes from alpha alone, matching + // how the status bar renders them. + drawable.mutate() + drawable.setTint(Color.WHITE) + if (drawable is BitmapDrawable) { + drawable.setFilterBitmap(true) + } + return drawable + } + } + } catch (t: Throwable) { + Log.w(TAG, "failed to load small notification icon", t) + } + try { + // Large icons are real color images (avatars, album art); keep color. + val largeIcon: Icon? = notification.getLargeIcon() + if (largeIcon != null) { + return largeIcon.loadDrawable(service) + } + } catch (t: Throwable) { + Log.w(TAG, "failed to load large notification icon", t) + } + return null + } + + private fun appendIconGrayBytes(drawable: Drawable, size: Int, out: ByteArrayOutputStream, + service: FaceclawMediaNotificationListenerService, index: Int, packageName: String?) { + val bitmap = renderIconScaled(drawable, size) + dumpIconDebugPng(service, index, packageName, bitmap) + for (y in 0 until size) { + for (x in 0 until size) { + val color = bitmap.getPixel(x, y) + val alpha = Color.alpha(color) + val grayLinear = (0.2126 * Color.red(color) + 0.7152 * Color.green(color) + 0.0722 * Color.blue(color)) * alpha / (255.0 * 255.0) + val gray = Math.round(255.0 * Math.pow(Math.max(0.0, Math.min(1.0, grayLinear)), NOTIFICATION_ICON_GAMMA)).toInt() + out.write(gray and 0xff) + } + } + bitmap.recycle() + } + + /** + * Render a drawable at the target size with proper downscaling. Detailed + * sources (e.g. avatar bitmaps used as notification icons) are rendered at + * native resolution and reduced by repeated halving: a single filtered pass + * from, say, 126px to 24px samples too sparsely and turns fine detail into + * speckle that reads as a garbled icon. + */ + private fun renderIconScaled(drawable: Drawable, size: Int): Bitmap { + val renderW = Math.max(size, drawable.intrinsicWidth) + val renderH = Math.max(size, drawable.intrinsicHeight) + var bitmap = Bitmap.createBitmap(renderW, renderH, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + drawable.setBounds(0, 0, renderW, renderH) + drawable.draw(canvas) + while (bitmap.width >= size * 2 && bitmap.height >= size * 2) { + val halved = Bitmap.createScaledBitmap(bitmap, bitmap.width / 2, bitmap.height / 2, true) + bitmap.recycle() + bitmap = halved + } + if (bitmap.width != size || bitmap.height != size) { + val scaled = Bitmap.createScaledBitmap(bitmap, size, size, true) + bitmap.recycle() + bitmap = scaled + } + return bitmap + } + + /** + * Debug aid for garbled-icon reports: saves each rendered icon to + * /debug-icons/ (adb-pullable) so extraction problems can + * be told apart from downstream compositing/transmission problems. Cheap: + * runs at most once per icon-cache refresh on tiny bitmaps. + */ + private fun dumpIconDebugPng(service: FaceclawMediaNotificationListenerService, index: Int, packageName: String?, bitmap: Bitmap) { + if (index < 0) { + return + } + try { + val dir = java.io.File(service.getExternalFilesDir(null), "debug-icons") + if (!dir.exists() && !dir.mkdirs()) { + return + } + val safeName = if (packageName == null) "unknown" else packageName.replace(Regex("[^A-Za-z0-9._-]"), "_") + val file = java.io.File(dir, "icon-$index-$safeName.png") + java.io.FileOutputStream(file).use { stream -> + bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream) + } + } catch (t: Throwable) { + Log.w(TAG, "failed to dump debug icon", t) + } + } + + private fun findActiveNotificationByKey(service: FaceclawMediaNotificationListenerService?, key: String?): StatusBarNotification? { + if (service == null || key == null || key.isEmpty()) { + return null + } + val notifications: Array? + try { + notifications = service.activeNotifications + } catch (t: Throwable) { + Log.w(TAG, "failed to find active notification", t) + return null + } + if (notifications == null) { + return null + } + for (statusBarNotification in notifications) { + if (statusBarNotification != null && key == statusBarNotification.key) { + return statusBarNotification + } + } + return null + } + + @Throws(JSONException::class) + private fun buildNotificationJson(service: FaceclawMediaNotificationListenerService, statusBarNotification: StatusBarNotification): JSONObject { + val notification = statusBarNotification.notification + val extras: Bundle? = notification.extras + val out = JSONObject() + out.put("key", statusBarNotification.key) + out.put("packageName", statusBarNotification.packageName) + out.put("appName", getNotificationAppName(service, statusBarNotification)) + out.put("postTime", statusBarNotification.postTime) + out.put("when", notification.`when`) + putString(out, "category", notification.category) + if (extras != null) { + putCharSequence(out, "title", firstNonEmpty( + extras.getCharSequence(Notification.EXTRA_TITLE_BIG), + extras.getCharSequence(Notification.EXTRA_TITLE) + )) + putCharSequence(out, "text", extras.getCharSequence(Notification.EXTRA_TEXT)) + putCharSequence(out, "bigText", extras.getCharSequence(Notification.EXTRA_BIG_TEXT)) + putCharSequence(out, "subText", extras.getCharSequence(Notification.EXTRA_SUB_TEXT)) + putCharSequence(out, "infoText", extras.getCharSequence(Notification.EXTRA_INFO_TEXT)) + putCharSequence(out, "summaryText", extras.getCharSequence(Notification.EXTRA_SUMMARY_TEXT)) + val textLines: Array? = extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES) + val lines = JSONArray() + if (textLines != null) { + for (line in textLines) { + val text = charSequenceToString(line) + if (!text.isEmpty()) { + lines.put(text) + } + } + } + out.put("lines", lines) + } else { + out.put("lines", JSONArray()) + } + + val actionsJson = JSONArray() + val actions: Array? = notification.actions + if (actions != null) { + for (index in actions.indices) { + val action = actions[index] + if (action == null) { + continue + } + val title = charSequenceToString(action.title) + if (title.isEmpty()) { + continue + } + val actionJson = JSONObject() + actionJson.put("index", index) + actionJson.put("title", title) + actionJson.put("enabled", action.actionIntent != null) + actionsJson.put(actionJson) + } + } + out.put("actions", actionsJson) + return out + } + + private fun getNotificationAppName(service: FaceclawMediaNotificationListenerService, statusBarNotification: StatusBarNotification): String { + val notification = statusBarNotification.notification + val extras: Bundle? = notification.extras + if (extras != null) { + val substituteName = charSequenceToString(extras.getCharSequence(EXTRA_SUBSTITUTE_APP_NAME)) + if (!substituteName.isEmpty()) { + return substituteName + } + } + return getAppLabel(service, statusBarNotification.packageName) + } + + private fun getAppLabel(service: FaceclawMediaNotificationListenerService, packageName: String?): String { + if (packageName == null || packageName.isEmpty()) { + return "" + } + try { + val label: CharSequence? = service + .packageManager + .getApplicationLabel(service.packageManager.getApplicationInfo(packageName, 0)) + val text = charSequenceToString(label) + return if (text.isEmpty()) packageName else text + } catch (t: Throwable) { + return packageName + } + } + + @Throws(JSONException::class) + private fun putString(out: JSONObject, key: String, value: String?) { + out.put(key, value ?: "") + } + + @Throws(JSONException::class) + private fun putCharSequence(out: JSONObject, key: String, value: CharSequence?) { + out.put(key, charSequenceToString(value)) + } + + private fun firstNonEmpty(first: CharSequence?, second: CharSequence?): CharSequence? { + return if (charSequenceToString(first).isEmpty()) second else first + } + + private fun charSequenceToString(value: CharSequence?): String { + return value?.toString() ?: "" + } + } + + override fun onCreate() { + super.onCreate() + activeService = this + } + + override fun onDestroy() { + if (activeService === this) { + activeService = null + } + super.onDestroy() + } + + override fun onListenerConnected() { + activeService = this + super.onListenerConnected() + refreshActiveNotificationWakeKeys(this) + } + + override fun onListenerDisconnected() { + if (activeService === this) { + activeService = null + } + super.onListenerDisconnected() + } + + override fun onNotificationPosted(statusBarNotification: StatusBarNotification?) { + super.onNotificationPosted(statusBarNotification) + if (!shouldShowNotificationInList(this, statusBarNotification)) { + forgetActiveNotificationWakeKey(statusBarNotification) + return + } + if (shouldEmitNotificationPosted(statusBarNotification!!)) { + emitNotificationPosted(statusBarNotification.key) + } + } + + override fun onNotificationRemoved(statusBarNotification: StatusBarNotification?) { + forgetActiveNotificationWakeKey(statusBarNotification) + super.onNotificationRemoved(statusBarNotification) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.java deleted file mode 100644 index c1764d6e..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.util.concurrent.TimeUnit; - -import okhttp3.Call; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; - -/** - * Large-file downloader for on-phone model weights (multi-GB, from Hugging - * Face). Downloads to ".part" with HTTP Range resume across app - * restarts, verifies a pinned sha256 (hashed incrementally, including the - * resumed prefix), then renames into place. Listener callbacks are posted to - * the constructing thread's Looper, like the other Faceclaw bridges. - */ -public class FaceclawModelDownloader { - private static final String TAG = "FaceclawModelDl"; - private static final long PROGRESS_INTERVAL_MS = 500; - - private static volatile OkHttpClient sharedClient; - - private final Handler callbackHandler; - private final String url; - private final File destFile; - private final File partFile; - private final String expectedSha256; - private final long expectedTotalBytes; - private final FaceclawModelDownloaderListener listener; - - private volatile boolean cancelled; - private volatile Call call; - private Thread worker; - - public FaceclawModelDownloader(String url, String destPath, String expectedSha256, - long expectedTotalBytes, FaceclawModelDownloaderListener listener) { - if (listener == null) throw new IllegalArgumentException("listener is required"); - Looper looper = Looper.myLooper(); - this.callbackHandler = new Handler(looper != null ? looper : Looper.getMainLooper()); - this.url = url; - this.destFile = new File(destPath); - this.partFile = new File(destPath + ".part"); - this.expectedSha256 = expectedSha256 == null ? "" : expectedSha256.toLowerCase(); - this.expectedTotalBytes = expectedTotalBytes; - this.listener = listener; - } - - private static OkHttpClient getClient() { - if (sharedClient == null) { - synchronized (FaceclawModelDownloader.class) { - if (sharedClient == null) { - sharedClient = new OkHttpClient.Builder() - .connectTimeout(30, TimeUnit.SECONDS) - .readTimeout(60, TimeUnit.SECONDS) - .addInterceptor(FaceclawHttp.userAgentInterceptor()) - .build(); - } - } - } - return sharedClient; - } - - public void start() { - worker = new Thread(this::run, "FaceclawModelDl"); - worker.start(); - } - - /** Stops the download but keeps the .part file so a later start() resumes. */ - public void cancel() { - cancelled = true; - Call current = call; - if (current != null) current.cancel(); - } - - private void run() { - try { - if (destFile.exists() && destFile.length() > 0) { - post(() -> listener.onDone(destFile.getAbsolutePath())); - return; - } - destFile.getParentFile().mkdirs(); - - MessageDigest digest = MessageDigest.getInstance("SHA-256"); - long offset = 0; - if (partFile.exists()) { - offset = hashExistingPrefix(digest); - if (cancelled) return; - } - - Request.Builder builder = new Request.Builder().url(url); - if (offset > 0) builder.header("Range", "bytes=" + offset + "-"); - call = getClient().newCall(builder.build()); - - try (Response response = call.execute()) { - ResponseBody body = response.body(); - if (!response.isSuccessful() || body == null) { - postError("Model download failed: HTTP " + response.code()); - return; - } - boolean resumed = response.code() == 206; - if (offset > 0 && !resumed) { - // Server ignored the Range header; start over. - offset = 0; - digest = MessageDigest.getInstance("SHA-256"); - } - long total = expectedTotalBytes > 0 ? expectedTotalBytes - : (body.contentLength() > 0 ? offset + body.contentLength() : -1); - - try (FileOutputStream out = new FileOutputStream(partFile, resumed); - InputStream in = body.byteStream()) { - byte[] buffer = new byte[1 << 16]; - long done = offset; - long lastProgressAt = 0; - int read; - while ((read = in.read(buffer)) != -1) { - if (cancelled) return; - out.write(buffer, 0, read); - digest.update(buffer, 0, read); - done += read; - long now = System.currentTimeMillis(); - if (now - lastProgressAt >= PROGRESS_INTERVAL_MS) { - lastProgressAt = now; - final long doneFinal = done; - final long totalFinal = total; - post(() -> listener.onProgress(doneFinal, totalFinal)); - } - } - } - } - - if (expectedTotalBytes > 0 && partFile.length() != expectedTotalBytes) { - postError("Model download ended early (" + partFile.length() + " of " - + expectedTotalBytes + " bytes); try again to resume"); - return; - } - String actualSha = FaceclawFirmwareUtil.bytesToHex(digest.digest()); - if (!expectedSha256.isEmpty() && !actualSha.equals(expectedSha256)) { - partFile.delete(); - postError("Model download was corrupted (checksum mismatch); download it again"); - return; - } - if (!partFile.renameTo(destFile)) { - postError("Could not move the downloaded model into place"); - return; - } - post(() -> listener.onDone(destFile.getAbsolutePath())); - } catch (Exception e) { - if (cancelled) return; - Log.w(TAG, "download failed", e); - postError("Model download failed: " + e); - } - } - - /** Hash the already-downloaded prefix so the final digest covers the whole file. */ - private long hashExistingPrefix(MessageDigest digest) throws IOException { - long hashed = 0; - try (FileInputStream in = new FileInputStream(partFile)) { - byte[] buffer = new byte[1 << 16]; - int read; - while ((read = in.read(buffer)) != -1) { - if (cancelled) return hashed; - digest.update(buffer, 0, read); - hashed += read; - } - } - return hashed; - } - - private void post(Runnable runnable) { - callbackHandler.post(runnable); - } - - private void postError(final String message) { - post(() -> listener.onError(message)); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt new file mode 100644 index 00000000..376175d8 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt @@ -0,0 +1,198 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.util.Log + +import java.io.File +import java.io.FileInputStream +import java.io.FileOutputStream +import java.io.IOException +import java.security.MessageDigest +import java.util.concurrent.TimeUnit + +import okhttp3.Call +import okhttp3.OkHttpClient +import okhttp3.Request + +/** + * Large-file downloader for on-phone model weights (multi-GB, from Hugging + * Face). Downloads to ".part" with HTTP Range resume across app + * restarts, verifies a pinned sha256 (hashed incrementally, including the + * resumed prefix), then renames into place. Listener callbacks are posted to + * the constructing thread's Looper, like the other Faceclaw bridges. + */ +class FaceclawModelDownloader( + url: String, + destPath: String, + expectedSha256: String?, + expectedTotalBytes: Long, + listener: FaceclawModelDownloaderListener? +) { + private val callbackHandler: Handler + private val url: String + private val destFile: File + private val partFile: File + private val expectedSha256: String + private val expectedTotalBytes: Long + private val listener: FaceclawModelDownloaderListener + + @Volatile + private var cancelled = false + @Volatile + private var call: Call? = null + private var worker: Thread? = null + + init { + if (listener == null) throw IllegalArgumentException("listener is required") + val looper = Looper.myLooper() + this.callbackHandler = Handler(looper ?: Looper.getMainLooper()) + this.url = url + this.destFile = File(destPath) + this.partFile = File("$destPath.part") + this.expectedSha256 = expectedSha256?.lowercase() ?: "" + this.expectedTotalBytes = expectedTotalBytes + this.listener = listener + } + + companion object { + private const val TAG = "FaceclawModelDl" + private const val PROGRESS_INTERVAL_MS = 500L + + @Volatile + private var sharedClient: OkHttpClient? = null + + private fun getClient(): OkHttpClient { + if (sharedClient == null) { + synchronized(FaceclawModelDownloader::class.java) { + if (sharedClient == null) { + sharedClient = OkHttpClient.Builder() + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(60, TimeUnit.SECONDS) + .addInterceptor(FaceclawHttp.userAgentInterceptor()) + .build() + } + } + } + return sharedClient!! + } + } + + fun start() { + val thread = Thread({ run() }, "FaceclawModelDl") + worker = thread + thread.start() + } + + /** Stops the download but keeps the .part file so a later start() resumes. */ + fun cancel() { + cancelled = true + val current = call + current?.cancel() + } + + private fun run() { + try { + if (destFile.exists() && destFile.length() > 0) { + post { listener.onDone(destFile.absolutePath) } + return + } + destFile.parentFile.mkdirs() + + var digest = MessageDigest.getInstance("SHA-256") + var offset = 0L + if (partFile.exists()) { + offset = hashExistingPrefix(digest) + if (cancelled) return + } + + val builder = Request.Builder().url(url) + if (offset > 0) builder.header("Range", "bytes=$offset-") + val newCall = getClient().newCall(builder.build()) + call = newCall + + newCall.execute().use { response -> + val body = response.body + if (!response.isSuccessful || body == null) { + postError("Model download failed: HTTP " + response.code) + return + } + val resumed = response.code == 206 + if (offset > 0 && !resumed) { + // Server ignored the Range header; start over. + offset = 0L + digest = MessageDigest.getInstance("SHA-256") + } + val total = if (expectedTotalBytes > 0) expectedTotalBytes + else (if (body.contentLength() > 0) offset + body.contentLength() else -1L) + + FileOutputStream(partFile, resumed).use { out -> + body.byteStream().use { input -> + val buffer = ByteArray(1 shl 16) + var done = offset + var lastProgressAt = 0L + var read: Int + while (input.read(buffer).also { read = it } != -1) { + if (cancelled) return + out.write(buffer, 0, read) + digest.update(buffer, 0, read) + done += read + val now = System.currentTimeMillis() + if (now - lastProgressAt >= PROGRESS_INTERVAL_MS) { + lastProgressAt = now + val doneFinal = done + val totalFinal = total + post { listener.onProgress(doneFinal, totalFinal) } + } + } + } + } + } + + if (expectedTotalBytes > 0 && partFile.length() != expectedTotalBytes) { + postError("Model download ended early (" + partFile.length() + " of " + + expectedTotalBytes + " bytes); try again to resume") + return + } + val actualSha = FaceclawFirmwareUtil.bytesToHex(digest.digest()) + if (!expectedSha256.isEmpty() && actualSha != expectedSha256) { + partFile.delete() + postError("Model download was corrupted (checksum mismatch); download it again") + return + } + if (!partFile.renameTo(destFile)) { + postError("Could not move the downloaded model into place") + return + } + post { listener.onDone(destFile.absolutePath) } + } catch (e: Exception) { + if (cancelled) return + Log.w(TAG, "download failed", e) + postError("Model download failed: $e") + } + } + + /** Hash the already-downloaded prefix so the final digest covers the whole file. */ + @Throws(IOException::class) + private fun hashExistingPrefix(digest: MessageDigest): Long { + var hashed = 0L + FileInputStream(partFile).use { input -> + val buffer = ByteArray(1 shl 16) + var read: Int + while (input.read(buffer).also { read = it } != -1) { + if (cancelled) return hashed + digest.update(buffer, 0, read) + hashed += read + } + } + return hashed + } + + private fun post(runnable: Runnable) { + callbackHandler.post(runnable) + } + + private fun postError(message: String) { + post { listener.onError(message) } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java deleted file mode 100644 index e0351588..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; - -/** - * Headless display target for preview-only mode (no glasses paired). Hosts - * the same SurfaceCompositor the BLE communicator uses, so the TS side can - * run its full surface/render pipeline unchanged; composited frames simply - * have nowhere to go, and the phone-mirror preview, screenshots, and GIF - * recordings read the retained composite back exactly as they do on a live - * connection. - * - * The method signatures mirror the display subset of FaceclawBleCommunicator - * (the TS DisplayTarget interface is typed against that subset). - */ -public final class FaceclawPreviewCompositor { - private final Context appContext; - private final SurfaceCompositor compositor = new SurfaceCompositor(); - private final android.os.Handler mainHandler = new android.os.Handler(android.os.Looper.getMainLooper()); - - // Notified (on the main looper, where the phone UI's JS runs) after each - // applied surface frame, standing in for the BLE path's per-frame metrics - // callback so the phone mirror refreshes promptly instead of waiting for - // its safety-net poll. - private volatile Runnable frameListener; - - // Active animated-GIF screen recording, or null when idle. Frames are - // pushed by recordScreenFrame(), which the TS side calls at each - // phone-preview flush. - private volatile GifScreenRecorder screenRecorder; - - // Worker-app isolates locate their frame target through a static, like - // FaceclawBleCommunicator.getActive(); Java statics are shared across - // isolates, unlike anything on the JS side. - private static volatile FaceclawPreviewCompositor activeInstance; - - public static FaceclawPreviewCompositor getActive() { - return activeInstance; - } - - public FaceclawPreviewCompositor(Context context) { - this.appContext = context.getApplicationContext(); - } - - /** Publish this compositor as the workers' frame target. */ - public void makeActive() { - activeInstance = this; - } - - /** Withdraw from workers (a real connection is taking over). */ - public void release() { - if (activeInstance == this) { - activeInstance = null; - } - frameListener = null; - } - - public void setFrameListener(Runnable listener) { - this.frameListener = listener; - } - - /** Set the compositor's output frame size. Call before configuring surfaces. */ - public void configureCompositorScreen(int width, int height) { - compositor.configureScreen(width, height); - } - - public void configureSurface(String id, int x, int y, int width, int height, int zOrder, int transparency) { - compositor.configureSurface(id, x, y, width, height, zOrder, transparency); - } - - public void removeSurface(String id) { - compositor.removeSurface(id); - } - - /** Dim every surface below zOrder belowZOrder to factor256/256 (see SurfaceCompositor). */ - public void submitShellScene(java.nio.ByteBuffer bytes, int paintMs, int frameId) { - compositor.setShellScene(new AndroidByteReader(bytes)); - FrameTimings.getInstance().finishFrame(frameId, "composited (preview-only, no glasses)"); - Runnable listener = frameListener; - if (listener != null) mainHandler.post(listener); - } - - public void setUnderlayDim(int belowZOrder, int factor256) { - compositor.setUnderlayDim(belowZOrder, factor256); - } - - public void setSurfaceVisible(String id, boolean visible) { - compositor.setSurfaceVisible(id, visible); - } - - /** Blank (screen off) or unblank the output; retained surface state survives. */ - public void setScreenBlanked(boolean blanked) { - compositor.setBlanked(blanked); - } - - /** - * Apply an update to one compositor surface. Unlike the connected path - * there is no desired-frame store or transmit pipeline downstream; the - * preview/screenshot calls recomposite the retained state on demand, so - * applying the update is the whole job and the frame finishes here. - */ - public void submitSurfaceFrame( - java.nio.ByteBuffer pixels8bpp, - String surfaceId, - int rectX, - int rectY, - int rectWidth, - int rectHeight, - String contentFingerprint, - int paintMs, - int frameId, - java.nio.ByteBuffer glyphs - ) { - compositor.submitSurface( - surfaceId, new AndroidByteReader(pixels8bpp), rectX, rectY, rectWidth, rectHeight, contentFingerprint, - glyphs == null ? null : new AndroidByteReader(glyphs)); - FrameTimings.getInstance().finishFrame(frameId, "composited (preview-only, no glasses)"); - Runnable listener = frameListener; - if (listener != null) { - mainHandler.post(listener); - } - } - - /** - * The current composited screen as a phone-UI preview bitmap, or null - * before any surface has been configured. - */ - public android.graphics.Bitmap getCompositePreviewBitmap(double brightenGamma, boolean green) { - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return null; - } - return PreviewBitmapUtil.fromGray( - java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green); - } - - /** Save the current composite as a 4-bit grayscale PNG; returns the path or "". */ - public String saveCompositePngScreenshot() throws java.io.IOException { - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return ""; - } - return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height); - } - - /** - * Save the current composite cropped to the given screen rect (the region - * the shell says is actually occupied). The rect is clamped to the screen; - * a degenerate rect falls back to the full screen. - */ - public String saveCompositePngScreenshot(int cropX, int cropY, int cropWidth, int cropHeight) - throws java.io.IOException { - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return ""; - } - int x = Math.max(0, cropX); - int y = Math.max(0, cropY); - int width = Math.min(composite.width - x, cropWidth - (x - cropX)); - int height = Math.min(composite.height - y, cropHeight - (y - cropY)); - if (width <= 0 || height <= 0 || (x == 0 && y == 0 && width == composite.width && height == composite.height)) { - return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height); - } - byte[] cropped = new byte[width * height]; - for (int row = 0; row < height; row++) { - System.arraycopy(composite.gray, (y + row) * composite.width + x, cropped, row * width, width); - } - return ScreenshotUtil.savePngScreenshot(appContext, cropped, width, height); - } - - /** Begin collecting composite frames for an animated-GIF screen recording. */ - public void startScreenRecording() { - screenRecorder = new GifScreenRecorder(); - } - - /** Capture the current composite into the active recording; no-op when idle. */ - public void recordScreenFrame() { - GifScreenRecorder recorder = screenRecorder; - if (recorder == null) { - return; - } - SurfaceCompositor.Composite composite = compositor.previewComposite(); - if (composite == null) { - return; - } - recorder.addFrame(composite.gray, composite.width, composite.height, System.currentTimeMillis()); - } - - /** Finish the recording and save it as an animated GIF; returns the path or "". */ - public String stopScreenRecording() throws java.io.IOException { - GifScreenRecorder recorder = screenRecorder; - screenRecorder = null; - if (recorder == null) { - return ""; - } - return recorder.save(appContext); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt new file mode 100644 index 00000000..570ad3f2 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt @@ -0,0 +1,199 @@ +package com.faceclaw.app + +import android.content.Context + +/** + * Headless display target for preview-only mode (no glasses paired). Hosts + * the same SurfaceCompositor the BLE communicator uses, so the TS side can + * run its full surface/render pipeline unchanged; composited frames simply + * have nowhere to go, and the phone-mirror preview, screenshots, and GIF + * recordings read the retained composite back exactly as they do on a live + * connection. + * + * The method signatures mirror the display subset of FaceclawBleCommunicator + * (the TS DisplayTarget interface is typed against that subset). + */ +class FaceclawPreviewCompositor(context: Context) { + private val appContext: Context = context.applicationContext + private val compositor = SurfaceCompositor() + private val mainHandler = android.os.Handler(android.os.Looper.getMainLooper()) + + // Notified (on the main looper, where the phone UI's JS runs) after each + // applied surface frame, standing in for the BLE path's per-frame metrics + // callback so the phone mirror refreshes promptly instead of waiting for + // its safety-net poll. + @Volatile private var frameListener: Runnable? = null + + // Active animated-GIF screen recording, or null when idle. Frames are + // pushed by recordScreenFrame(), which the TS side calls at each + // phone-preview flush. + @Volatile private var screenRecorder: GifScreenRecorder? = null + + companion object { + // Worker-app isolates locate their frame target through a static, like + // FaceclawBleCommunicator.getActive(); Java statics are shared across + // isolates, unlike anything on the JS side. + @Volatile private var activeInstance: FaceclawPreviewCompositor? = null + + @JvmStatic + fun getActive(): FaceclawPreviewCompositor? { + return activeInstance + } + } + + /** Publish this compositor as the workers' frame target. */ + fun makeActive() { + activeInstance = this + } + + /** Withdraw from workers (a real connection is taking over). */ + fun release() { + if (activeInstance === this) { + activeInstance = null + } + frameListener = null + } + + fun setFrameListener(listener: Runnable?) { + this.frameListener = listener + } + + /** Set the compositor's output frame size. Call before configuring surfaces. */ + fun configureCompositorScreen(width: Int, height: Int) { + compositor.configureScreen(width, height) + } + + fun configureSurface(id: String?, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) { + compositor.configureSurface(id, x, y, width, height, zOrder, transparency) + } + + fun removeSurface(id: String) { + compositor.removeSurface(id) + } + + /** Dim every surface below zOrder belowZOrder to factor256/256 (see SurfaceCompositor). */ + fun submitShellScene(bytes: java.nio.ByteBuffer, paintMs: Int, frameId: Int) { + compositor.setShellScene(AndroidByteReader(bytes)) + FrameTimings.getInstance().finishFrame(frameId, "composited (preview-only, no glasses)") + val listener = frameListener + if (listener != null) mainHandler.post(listener) + } + + fun setUnderlayDim(belowZOrder: Int, factor256: Int) { + compositor.setUnderlayDim(belowZOrder, factor256) + } + + fun setSurfaceVisible(id: String, visible: Boolean) { + compositor.setSurfaceVisible(id, visible) + } + + /** Blank (screen off) or unblank the output; retained surface state survives. */ + fun setScreenBlanked(blanked: Boolean) { + compositor.setBlanked(blanked) + } + + /** + * Apply an update to one compositor surface. Unlike the connected path + * there is no desired-frame store or transmit pipeline downstream; the + * preview/screenshot calls recomposite the retained state on demand, so + * applying the update is the whole job and the frame finishes here. + */ + fun submitSurfaceFrame( + pixels8bpp: java.nio.ByteBuffer, + surfaceId: String, + rectX: Int, + rectY: Int, + rectWidth: Int, + rectHeight: Int, + contentFingerprint: String, + paintMs: Int, + frameId: Int, + glyphs: java.nio.ByteBuffer? + ) { + compositor.submitSurface( + surfaceId, AndroidByteReader(pixels8bpp), rectX, rectY, rectWidth, rectHeight, contentFingerprint, + if (glyphs == null) null else AndroidByteReader(glyphs)) + FrameTimings.getInstance().finishFrame(frameId, "composited (preview-only, no glasses)") + val listener = frameListener + if (listener != null) { + mainHandler.post(listener) + } + } + + /** + * The current composited screen as a phone-UI preview bitmap, or null + * before any surface has been configured. + */ + fun getCompositePreviewBitmap(brightenGamma: Double, green: Boolean): android.graphics.Bitmap? { + val composite = compositor.previewComposite() + if (composite == null) { + return null + } + return PreviewBitmapUtil.fromGray( + java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green) + } + + /** Save the current composite as a 4-bit grayscale PNG; returns the path or "". */ + @Throws(java.io.IOException::class) + fun saveCompositePngScreenshot(): String { + val composite = compositor.previewComposite() + if (composite == null) { + return "" + } + return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height) + } + + /** + * Save the current composite cropped to the given screen rect (the region + * the shell says is actually occupied). The rect is clamped to the screen; + * a degenerate rect falls back to the full screen. + */ + @Throws(java.io.IOException::class) + fun saveCompositePngScreenshot(cropX: Int, cropY: Int, cropWidth: Int, cropHeight: Int): String { + val composite = compositor.previewComposite() + if (composite == null) { + return "" + } + val x = Math.max(0, cropX) + val y = Math.max(0, cropY) + val width = Math.min(composite.width - x, cropWidth - (x - cropX)) + val height = Math.min(composite.height - y, cropHeight - (y - cropY)) + if (width <= 0 || height <= 0 || (x == 0 && y == 0 && width == composite.width && height == composite.height)) { + return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height) + } + val cropped = ByteArray(width * height) + for (row in 0 until height) { + System.arraycopy(composite.gray, (y + row) * composite.width + x, cropped, row * width, width) + } + return ScreenshotUtil.savePngScreenshot(appContext, cropped, width, height) + } + + /** Begin collecting composite frames for an animated-GIF screen recording. */ + fun startScreenRecording() { + screenRecorder = GifScreenRecorder() + } + + /** Capture the current composite into the active recording; no-op when idle. */ + fun recordScreenFrame() { + val recorder = screenRecorder + if (recorder == null) { + return + } + val composite = compositor.previewComposite() + if (composite == null) { + return + } + recorder.addFrame(composite.gray, composite.width, composite.height, System.currentTimeMillis()) + } + + /** Finish the recording and save it as an animated GIF; returns the path or "". */ + @Throws(java.io.IOException::class) + fun stopScreenRecording(): String { + val recorder = screenRecorder + screenRecorder = null + if (recorder == null) { + return "" + } + return recorder.save(appContext) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.java deleted file mode 100644 index 4b7cd5c4..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.faceclaw.app; - -import android.app.Activity; -import android.content.Context; -import android.util.Log; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; -import com.google.android.gms.tasks.OnCanceledListener; -import com.google.android.gms.tasks.OnFailureListener; -import com.google.android.gms.tasks.OnSuccessListener; -import com.google.mlkit.vision.barcode.common.Barcode; -import com.google.mlkit.vision.codescanner.GmsBarcodeScanner; -import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions; -import com.google.mlkit.vision.codescanner.GmsBarcodeScanning; - -/** - * QR scanning through Play Services' ML Kit code scanner. The scanner UI and - * the camera both live inside Play Services, so Faceclaw needs no camera - * permission of its own and no third-party scanner app — which is what the - * earlier ZXing SCAN intent needed, and no app on a stock Pixel registers for - * it. - * - * The scanner module is downloaded on demand the first time it is used (the - * manifest's com.google.mlkit.vision.DEPENDENCIES meta-data asks Play Services - * to fetch it at install time instead); a scan attempted before that finishes - * fails with a module-unavailable error rather than blocking. - * - * Callbacks fire on the main thread. - */ -public final class FaceclawQrScanner { - private static final String TAG = "FaceclawQrScanner"; - - private FaceclawQrScanner() {} - - /** Whether Play Services is present and current enough to scan. */ - public static boolean isAvailable(Context context) { - try { - int status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context); - return status == ConnectionResult.SUCCESS; - } catch (Throwable error) { - Log.w(TAG, "Play Services availability check failed", error); - return false; - } - } - - /** Open the scanner UI; the listener gets the decoded text, or a cancel/error. */ - public static void scan(Activity activity, final FaceclawQrScannerListener listener) { - GmsBarcodeScannerOptions options = new GmsBarcodeScannerOptions.Builder() - .setBarcodeFormats(Barcode.FORMAT_QR_CODE) - .enableAutoZoom() - .build(); - GmsBarcodeScanner scanner = GmsBarcodeScanning.getClient(activity, options); - scanner.startScan() - .addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(Barcode barcode) { - String value = barcode == null ? null : barcode.getRawValue(); - if (value == null) { - listener.onError("The code held no text."); - } else { - listener.onResult(value); - } - } - }) - .addOnCanceledListener(new OnCanceledListener() { - @Override - public void onCanceled() { - listener.onCancelled(); - } - }) - .addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(Exception error) { - Log.w(TAG, "scan failed", error); - String message = error.getMessage(); - listener.onError(message == null ? error.toString() : message); - } - }); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.kt new file mode 100644 index 00000000..a3857f44 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.kt @@ -0,0 +1,74 @@ +package com.faceclaw.app + +import android.app.Activity +import android.content.Context +import android.util.Log + +import com.google.android.gms.common.ConnectionResult +import com.google.android.gms.common.GoogleApiAvailability +import com.google.android.gms.tasks.OnCanceledListener +import com.google.android.gms.tasks.OnFailureListener +import com.google.android.gms.tasks.OnSuccessListener +import com.google.mlkit.vision.barcode.common.Barcode +import com.google.mlkit.vision.codescanner.GmsBarcodeScanner +import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions +import com.google.mlkit.vision.codescanner.GmsBarcodeScanning + +/** + * QR scanning through Play Services' ML Kit code scanner. The scanner UI and + * the camera both live inside Play Services, so Faceclaw needs no camera + * permission of its own and no third-party scanner app — which is what the + * earlier ZXing SCAN intent needed, and no app on a stock Pixel registers for + * it. + * + * The scanner module is downloaded on demand the first time it is used (the + * manifest's com.google.mlkit.vision.DEPENDENCIES meta-data asks Play Services + * to fetch it at install time instead); a scan attempted before that finishes + * fails with a module-unavailable error rather than blocking. + * + * Callbacks fire on the main thread. + */ +class FaceclawQrScanner private constructor() { + companion object { + private const val TAG = "FaceclawQrScanner" + + /** Whether Play Services is present and current enough to scan. */ + @JvmStatic + fun isAvailable(context: Context): Boolean { + try { + val status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) + return status == ConnectionResult.SUCCESS + } catch (error: Throwable) { + Log.w(TAG, "Play Services availability check failed", error) + return false + } + } + + /** Open the scanner UI; the listener gets the decoded text, or a cancel/error. */ + @JvmStatic + fun scan(activity: Activity, listener: FaceclawQrScannerListener) { + val options = GmsBarcodeScannerOptions.Builder() + .setBarcodeFormats(Barcode.FORMAT_QR_CODE) + .enableAutoZoom() + .build() + val scanner: GmsBarcodeScanner = GmsBarcodeScanning.getClient(activity, options) + scanner.startScan() + .addOnSuccessListener(OnSuccessListener { barcode -> + val value = barcode?.rawValue + if (value == null) { + listener.onError("The code held no text.") + } else { + listener.onResult(value) + } + }) + .addOnCanceledListener(OnCanceledListener { + listener.onCancelled() + }) + .addOnFailureListener(OnFailureListener { error -> + Log.w(TAG, "scan failed", error) + val message = error.message + listener.onError(message ?: error.toString()) + }) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java deleted file mode 100644 index a44f47c9..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import java.io.ByteArrayOutputStream; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.util.Collections; -import org.json.JSONArray; -import java.net.ServerSocket; -import java.net.Socket; -import java.nio.charset.StandardCharsets; -import java.nio.ByteBuffer; -import java.security.MessageDigest; -import java.security.SecureRandom; -import org.json.JSONObject; - -/** Explicit-address, bounded input port. Complete requests notify JS on the main thread. */ -public final class FaceclawRemoteInput { - private static final FaceclawRemoteInput INSTANCE = new FaceclawRemoteInput(); - public static FaceclawRemoteInput getInstance() { return INSTANCE; } - private ServerSocket server; - private Socket client; - private String pending, reply; - private long nextId, requestId; - private long deadline; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private Runnable requestListener; - - public synchronized void setRequestListener(Runnable listener) { requestListener = listener; } - - private void notifyRequestReady(long id) { - // Called with this monitor held; posting avoids entering JS on the socket thread. - mainHandler.post(() -> { - Runnable callback; - synchronized (this) { - if (requestId != id || pending == null || System.currentTimeMillis() >= deadline) return; - callback = requestListener; - } - if (callback != null) callback.run(); - }); - } - - public synchronized String start(int port) { return startAddress(port, "127.0.0.1"); } - public synchronized String startAddress(int port, String address) { - if (server != null) return ""; - try { - // Numeric local addresses only; never resolve hostnames or bind a wildcard. - if (!address.matches("[0-9.]+|[0-9a-fA-F]*:[0-9a-fA-F:.]*(%[a-zA-Z0-9_.-]+)?")) return "Invalid local address."; - InetAddress local = InetAddress.getByName(address); - if (local.isAnyLocalAddress() || local.isMulticastAddress() || NetworkInterface.getByInetAddress(local) == null) - return "Address is not assigned to a local interface."; - ServerSocket listener = new ServerSocket(port, 8, local); - server = listener; - Thread thread = new Thread(() -> serve(listener), "FaceclawInput"); - thread.setDaemon(true); - thread.start(); - return ""; - } catch (Exception e) { return "Could not open local input port " + port + "."; } - } - public synchronized void stop() { - try { if (server != null) server.close(); } catch (Exception ignored) {} - try { if (client != null) client.close(); } catch (Exception ignored) {} - server = null; client = null; pending = null; requestId = 0; reply = null; - notifyAll(); - } - public synchronized String nextRequest() { - if (System.currentTimeMillis() >= deadline) { pending = null; return null; } - String result = pending; pending = null; return result; - } - public synchronized void complete(long id, String value) { - if (id == requestId && System.currentTimeMillis() < deadline) { reply = value; notifyAll(); } - } - private void serve(ServerSocket listener) { - while (!listener.isClosed()) { - try (Socket socket = listener.accept()) { - synchronized (this) { if (server != listener) return; client = socket; } - socket.setSoTimeout(5000); - socket.setTcpNoDelay(true); - long readDeadline = System.currentTimeMillis() + 5000; - ByteArrayOutputStream body = new ByteArrayOutputStream(); - int b; - for (;;) { - long remaining = readDeadline - System.currentTimeMillis(); - if (remaining <= 0) throw new Exception("Read timeout"); - socket.setSoTimeout((int) remaining); - b = socket.getInputStream().read(); - if (b == -1 || b == '\n') break; - if (body.size() >= 65536) throw new Exception("Invalid frame"); - body.write(b); - } - if (b != '\n') continue; - String text = StandardCharsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(body.toByteArray())).toString(); - String response; - synchronized (this) { - if (server != listener) return; - requestId = ++nextId; - deadline = System.currentTimeMillis() + 5000; - reply = null; - pending = new JSONObject().put("id", requestId).put("expiresAt", deadline) - .put("body", text).toString(); - notifyRequestReady(requestId); - while (reply == null && server == listener && System.currentTimeMillis() < deadline) { - wait(Math.max(1, deadline - System.currentTimeMillis())); - } - response = reply != null ? reply : "{\"ok\":false,\"error\":\"timeout\",\"message\":\"Faceclaw did not respond in time.\"}"; - if (server == listener) { pending = null; reply = null; requestId = 0; } - } - socket.getOutputStream().write((response + "\n").getBytes(StandardCharsets.UTF_8)); - } catch (Exception ignored) { - // Never log request bodies: they contain credentials and possibly private text. - } finally { - synchronized (this) { if (server == listener) client = null; } - } - } - } - public static String interfaces() { - JSONArray result = new JSONArray(); - try { - for (NetworkInterface device : Collections.list(NetworkInterface.getNetworkInterfaces())) { - if (!device.isUp()) continue; - for (InetAddress address : Collections.list(device.getInetAddresses())) { - if (address.isLoopbackAddress() || address.isLinkLocalAddress() || address.isAnyLocalAddress()) continue; - result.put(new JSONObject().put("name", device.getName()).put("address", address.getHostAddress()) - .put("pointToPoint", device.isPointToPoint())); - } - } - } catch (Exception ignored) {} - return result.toString(); - } - public String randomSecret() { - byte[] bytes = new byte[32]; new SecureRandom().nextBytes(bytes); return hex(bytes); - } - public String hash(String value) { - try { return hex(MessageDigest.getInstance("SHA-256").digest(value.getBytes(StandardCharsets.UTF_8))); } - catch (Exception e) { throw new IllegalStateException("SHA-256 unavailable", e); } - } - private static String hex(byte[] bytes) { - StringBuilder result = new StringBuilder(bytes.length * 2); - for (byte b : bytes) result.append(String.format(java.util.Locale.ROOT, "%02x", b & 255)); - return result.toString(); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt new file mode 100644 index 00000000..358098ab --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt @@ -0,0 +1,152 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import java.io.ByteArrayOutputStream +import java.net.InetAddress +import java.net.NetworkInterface +import java.util.Collections +import org.json.JSONArray +import java.net.ServerSocket +import java.net.Socket +import java.nio.charset.StandardCharsets +import java.nio.ByteBuffer +import java.security.MessageDigest +import java.security.SecureRandom +import org.json.JSONObject + +/** Explicit-address, bounded input port. Complete requests notify JS on the main thread. */ +class FaceclawRemoteInput { + companion object { + private val INSTANCE = FaceclawRemoteInput() + @JvmStatic fun getInstance(): FaceclawRemoteInput { return INSTANCE } + + @JvmStatic + fun interfaces(): String { + val result = JSONArray() + try { + for (device in Collections.list(NetworkInterface.getNetworkInterfaces())) { + if (!device.isUp) continue + for (address in Collections.list(device.inetAddresses)) { + if (address.isLoopbackAddress || address.isLinkLocalAddress || address.isAnyLocalAddress) continue + result.put(JSONObject().put("name", device.name).put("address", address.hostAddress) + .put("pointToPoint", device.isPointToPoint)) + } + } + } catch (ignored: Exception) {} + return result.toString() + } + + private fun hex(bytes: ByteArray): String { + val result = StringBuilder(bytes.size * 2) + for (b in bytes) result.append(String.format(java.util.Locale.ROOT, "%02x", b.toInt() and 255)) + return result.toString() + } + } + private var server: ServerSocket? = null + private var client: Socket? = null + private var pending: String? = null + private var reply: String? = null + private var nextId = 0L + private var requestId = 0L + private var deadline = 0L + private val mainHandler = Handler(Looper.getMainLooper()) + private var requestListener: Runnable? = null + + @Synchronized fun setRequestListener(listener: Runnable?) { requestListener = listener } + + private fun notifyRequestReady(id: Long) { + // Called with this monitor held; posting avoids entering JS on the socket thread. + mainHandler.post { + val callback: Runnable? + synchronized(this) { + if (requestId != id || pending == null || System.currentTimeMillis() >= deadline) return@post + callback = requestListener + } + callback?.run() + } + } + + @Synchronized fun start(port: Int): String { return startAddress(port, "127.0.0.1") } + @Synchronized fun startAddress(port: Int, address: String): String { + if (server != null) return "" + try { + // Numeric local addresses only; never resolve hostnames or bind a wildcard. + if (!address.matches(Regex("[0-9.]+|[0-9a-fA-F]*:[0-9a-fA-F:.]*(%[a-zA-Z0-9_.-]+)?"))) return "Invalid local address." + val local = InetAddress.getByName(address) + if (local.isAnyLocalAddress || local.isMulticastAddress || NetworkInterface.getByInetAddress(local) == null) + return "Address is not assigned to a local interface." + val listener = ServerSocket(port, 8, local) + server = listener + val thread = Thread({ serve(listener) }, "FaceclawInput") + thread.isDaemon = true + thread.start() + return "" + } catch (e: Exception) { return "Could not open local input port $port." } + } + @Synchronized fun stop() { + try { server?.close() } catch (ignored: Exception) {} + try { client?.close() } catch (ignored: Exception) {} + server = null; client = null; pending = null; requestId = 0; reply = null + (this as java.lang.Object).notifyAll() + } + @Synchronized fun nextRequest(): String? { + if (System.currentTimeMillis() >= deadline) { pending = null; return null } + val result = pending; pending = null; return result + } + @Synchronized fun complete(id: Long, value: String?) { + if (id == requestId && System.currentTimeMillis() < deadline) { reply = value; (this as java.lang.Object).notifyAll() } + } + private fun serve(listener: ServerSocket) { + while (!listener.isClosed) { + try { + listener.accept().use { socket -> + synchronized(this) { if (server !== listener) return; client = socket } + socket.soTimeout = 5000 + socket.tcpNoDelay = true + val readDeadline = System.currentTimeMillis() + 5000 + val body = ByteArrayOutputStream() + var b = -1 + while (true) { + val remaining = readDeadline - System.currentTimeMillis() + if (remaining <= 0) throw Exception("Read timeout") + socket.soTimeout = remaining.toInt() + b = socket.getInputStream().read() + if (b == -1 || b == '\n'.code) break + if (body.size() >= 65536) throw Exception("Invalid frame") + body.write(b) + } + if (b != '\n'.code) return@use + val text = StandardCharsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(body.toByteArray())).toString() + val response: String + synchronized(this) { + if (server !== listener) return + requestId = ++nextId + deadline = System.currentTimeMillis() + 5000 + reply = null + pending = JSONObject().put("id", requestId).put("expiresAt", deadline) + .put("body", text).toString() + notifyRequestReady(requestId) + while (reply == null && server === listener && System.currentTimeMillis() < deadline) { + (this as java.lang.Object).wait(Math.max(1L, deadline - System.currentTimeMillis())) + } + response = reply ?: "{\"ok\":false,\"error\":\"timeout\",\"message\":\"Faceclaw did not respond in time.\"}" + if (server === listener) { pending = null; reply = null; requestId = 0 } + } + socket.getOutputStream().write((response + "\n").toByteArray(StandardCharsets.UTF_8)) + } + } catch (ignored: Exception) { + // Never log request bodies: they contain credentials and possibly private text. + } finally { + synchronized(this) { if (server === listener) client = null } + } + } + } + fun randomSecret(): String { + val bytes = ByteArray(32); SecureRandom().nextBytes(bytes); return hex(bytes) + } + fun hash(value: String): String { + try { return hex(MessageDigest.getInstance("SHA-256").digest(value.toByteArray(StandardCharsets.UTF_8))) } + catch (e: Exception) { throw IllegalStateException("SHA-256 unavailable", e) } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.java deleted file mode 100644 index d2358878..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.faceclaw.app; - -import android.os.Debug; -import android.os.Process; -import android.os.SystemClock; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; - -/** Lightweight process counters for the on-glasses resource-usage monitor. */ -public final class FaceclawResourceUsage { - private FaceclawResourceUsage() {} - - /** - * Returns elapsedMs, processCpuMs, rssKb, nativeHeapKb, javaHeapKb, - * javaHeapCommittedKb, and threadCount. Reading /proc/self/status avoids - * the considerably heavier full Debug.MemoryInfo/PSS collection once per - * second while still reporting the RSS that Android records at exit. - */ - public static long[] sample() { - long[] status = readProcessStatus(); - Runtime runtime = Runtime.getRuntime(); - long javaUsedBytes = runtime.totalMemory() - runtime.freeMemory(); - return new long[] { - SystemClock.elapsedRealtime(), - Process.getElapsedCpuTime(), - status[0], - Debug.getNativeHeapAllocatedSize() / 1024L, - javaUsedBytes / 1024L, - runtime.totalMemory() / 1024L, - status[1], - }; - } - - /** Returns {VmRSS in KiB, thread count}; unavailable values are zero. */ - private static long[] readProcessStatus() { - long rssKb = 0; - long threadCount = 0; - try (BufferedReader reader = new BufferedReader(new FileReader("/proc/self/status"))) { - String line; - while ((line = reader.readLine()) != null) { - if (line.startsWith("VmRSS:")) { - rssKb = firstNumber(line); - } else if (line.startsWith("Threads:")) { - threadCount = firstNumber(line); - } - if (rssKb > 0 && threadCount > 0) break; - } - } catch (IOException ignored) { - // The graph remains useful with the runtime heap counters alone. - } - return new long[] { rssKb, threadCount }; - } - - private static long firstNumber(String line) { - int start = 0; - while (start < line.length() && !Character.isDigit(line.charAt(start))) start++; - int end = start; - while (end < line.length() && Character.isDigit(line.charAt(end))) end++; - if (start == end) return 0; - try { - return Long.parseLong(line.substring(start, end)); - } catch (NumberFormatException ignored) { - return 0; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.kt new file mode 100644 index 00000000..c5a94b4c --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.kt @@ -0,0 +1,72 @@ +package com.faceclaw.app + +import android.os.Debug +import android.os.Process +import android.os.SystemClock + +import java.io.BufferedReader +import java.io.FileReader +import java.io.IOException + +/** Lightweight process counters for the on-glasses resource-usage monitor. */ +class FaceclawResourceUsage private constructor() { + companion object { + /** + * Returns elapsedMs, processCpuMs, rssKb, nativeHeapKb, javaHeapKb, + * javaHeapCommittedKb, and threadCount. Reading /proc/self/status avoids + * the considerably heavier full Debug.MemoryInfo/PSS collection once per + * second while still reporting the RSS that Android records at exit. + */ + @JvmStatic + fun sample(): LongArray { + val status = readProcessStatus() + val runtime = Runtime.getRuntime() + val javaUsedBytes = runtime.totalMemory() - runtime.freeMemory() + return longArrayOf( + SystemClock.elapsedRealtime(), + Process.getElapsedCpuTime(), + status[0], + Debug.getNativeHeapAllocatedSize() / 1024L, + javaUsedBytes / 1024L, + runtime.totalMemory() / 1024L, + status[1], + ) + } + + /** Returns {VmRSS in KiB, thread count}; unavailable values are zero. */ + private fun readProcessStatus(): LongArray { + var rssKb = 0L + var threadCount = 0L + try { + BufferedReader(FileReader("/proc/self/status")).use { reader -> + var line: String? + while (reader.readLine().also { line = it } != null) { + val current = line!! + if (current.startsWith("VmRSS:")) { + rssKb = firstNumber(current) + } else if (current.startsWith("Threads:")) { + threadCount = firstNumber(current) + } + if (rssKb > 0 && threadCount > 0) break + } + } + } catch (ignored: IOException) { + // The graph remains useful with the runtime heap counters alone. + } + return longArrayOf(rssKb, threadCount) + } + + private fun firstNumber(line: String): Long { + var start = 0 + while (start < line.length && !Character.isDigit(line[start])) start++ + var end = start + while (end < line.length && Character.isDigit(line[end])) end++ + if (start == end) return 0 + return try { + line.substring(start, end).toLong() + } catch (ignored: NumberFormatException) { + 0 + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.java deleted file mode 100644 index bec8c494..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * App settings store shared by every JS isolate (main thread and app - * workers). Values live in a dedicated SharedPreferences file, distinct from - * NativeScript's ApplicationSettings file, so this store owns its keys - * outright (the old TS-side settings were deliberately abandoned, not - * migrated). - * - * Change notifications: each isolate registers one listener from its own - * thread. The registering thread's Looper is captured, and notifications are - * posted through it so the JS callback always runs on the isolate's own - * thread (calling into an isolate from a foreign thread is not allowed). - * NativeScript worker threads run a message loop, so both the main thread - * and workers have a Looper; a listener registered from a Looper-less thread - * is accepted but never notified (it can still read fresh values on demand). - */ -public final class FaceclawSettings { - private static final String TAG = "FaceclawSettings"; - private static final String PREFS_NAME = "faceclaw_settings"; - private static volatile FaceclawSettings instance; - - private final SharedPreferences prefs; - private final CopyOnWriteArrayList listeners = new CopyOnWriteArrayList<>(); - - private static final class ListenerEntry { - final FaceclawSettingsListener listener; - final Handler handler; - - ListenerEntry(FaceclawSettingsListener listener, Handler handler) { - this.listener = listener; - this.handler = handler; - } - } - - private FaceclawSettings(Context context) { - this.prefs = context.getApplicationContext() - .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - } - - /** Initialize (idempotent) and return the singleton. */ - public static FaceclawSettings getInstance(Context context) { - if (instance == null) { - synchronized (FaceclawSettings.class) { - if (instance == null) { - instance = new FaceclawSettings(context); - } - } - } - return instance; - } - - /** Return the singleton; the main isolate must have initialized it first. */ - public static FaceclawSettings getInstance() { - FaceclawSettings result = instance; - if (result == null) { - throw new IllegalStateException("FaceclawSettings not initialized; call getInstance(context) first"); - } - return result; - } - - public String getString(String key, String defaultValue) { - return prefs.getString(key, defaultValue); - } - - public void setString(String key, String value) { - prefs.edit().putString(key, value).apply(); - notifyChanged(key); - } - - public boolean getBoolean(String key, boolean defaultValue) { - return prefs.getBoolean(key, defaultValue); - } - - public void setBoolean(String key, boolean value) { - prefs.edit().putBoolean(key, value).apply(); - notifyChanged(key); - } - - /** - * Register a change listener. Must be called from the thread whose - * isolate owns the listener; that thread's Looper is captured for - * dispatch. - */ - public void registerListener(FaceclawSettingsListener listener) { - Looper looper = Looper.myLooper(); - if (looper == null) { - Log.w(TAG, "settings listener registered from a Looper-less thread; it will never be notified"); - } - listeners.add(new ListenerEntry(listener, looper != null ? new Handler(looper) : null)); - } - - public void unregisterListener(FaceclawSettingsListener listener) { - for (ListenerEntry entry : listeners) { - if (entry.listener == listener) { - listeners.remove(entry); - } - } - } - - private void notifyChanged(String key) { - for (ListenerEntry entry : listeners) { - if (entry.handler == null) continue; - entry.handler.post(() -> { - try { - entry.listener.onSettingChanged(key); - } catch (Exception e) { - Log.w(TAG, "settings listener failed for key " + key, e); - } - }); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt new file mode 100644 index 00000000..abd6d7c1 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt @@ -0,0 +1,112 @@ +package com.faceclaw.app + +import android.content.Context +import android.content.SharedPreferences +import android.os.Handler +import android.os.Looper +import android.util.Log + +import java.util.concurrent.CopyOnWriteArrayList + +/** + * App settings store shared by every JS isolate (main thread and app + * workers). Values live in a dedicated SharedPreferences file, distinct from + * NativeScript's ApplicationSettings file, so this store owns its keys + * outright (the old TS-side settings were deliberately abandoned, not + * migrated). + * + * Change notifications: each isolate registers one listener from its own + * thread. The registering thread's Looper is captured, and notifications are + * posted through it so the JS callback always runs on the isolate's own + * thread (calling into an isolate from a foreign thread is not allowed). + * NativeScript worker threads run a message loop, so both the main thread + * and workers have a Looper; a listener registered from a Looper-less thread + * is accepted but never notified (it can still read fresh values on demand). + */ +class FaceclawSettings private constructor(context: Context) { + private val prefs: SharedPreferences = context.applicationContext + .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + private val listeners = CopyOnWriteArrayList() + + private class ListenerEntry(val listener: FaceclawSettingsListener, val handler: Handler?) + + companion object { + private const val TAG = "FaceclawSettings" + private const val PREFS_NAME = "faceclaw_settings" + @Volatile + private var instance: FaceclawSettings? = null + + /** Initialize (idempotent) and return the singleton. */ + @JvmStatic + fun getInstance(context: Context): FaceclawSettings { + if (instance == null) { + synchronized(FaceclawSettings::class.java) { + if (instance == null) { + instance = FaceclawSettings(context) + } + } + } + return instance!! + } + + /** Return the singleton; the main isolate must have initialized it first. */ + @JvmStatic + fun getInstance(): FaceclawSettings { + val result = instance + ?: throw IllegalStateException("FaceclawSettings not initialized; call getInstance(context) first") + return result + } + } + + fun getString(key: String?, defaultValue: String?): String? { + return prefs.getString(key, defaultValue) + } + + fun setString(key: String?, value: String?) { + prefs.edit().putString(key, value).apply() + notifyChanged(key) + } + + fun getBoolean(key: String?, defaultValue: Boolean): Boolean { + return prefs.getBoolean(key, defaultValue) + } + + fun setBoolean(key: String?, value: Boolean) { + prefs.edit().putBoolean(key, value).apply() + notifyChanged(key) + } + + /** + * Register a change listener. Must be called from the thread whose + * isolate owns the listener; that thread's Looper is captured for + * dispatch. + */ + fun registerListener(listener: FaceclawSettingsListener) { + val looper = Looper.myLooper() + if (looper == null) { + Log.w(TAG, "settings listener registered from a Looper-less thread; it will never be notified") + } + listeners.add(ListenerEntry(listener, if (looper != null) Handler(looper) else null)) + } + + fun unregisterListener(listener: FaceclawSettingsListener?) { + for (entry in listeners) { + if (entry.listener === listener) { + listeners.remove(entry) + } + } + } + + private fun notifyChanged(key: String?) { + for (entry in listeners) { + val handler = entry.handler ?: continue + handler.post { + try { + entry.listener.onSettingChanged(key) + } catch (e: Exception) { + Log.w(TAG, "settings listener failed for key $key", e) + } + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.java deleted file mode 100644 index 90becbef..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.faceclaw.app; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Looper; -import android.util.Log; -import android.util.Xml; - -import org.xmlpull.v1.XmlPullParser; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * adb-triggered export/import of the faceclaw_settings SharedPreferences - * file, so configuration (API keys, device addresses, ...) can be moved off a - * release build, where run-as is unavailable. See scripts/pull_config.sh and - * scripts/push_config.sh, which use run-as on debuggable builds and fall back - * to this receiver otherwise. - * - * adb shell am broadcast -n com.faceclaw.app/.FaceclawSettingsPortReceiver \ - * -a com.faceclaw.app.SETTINGS_EXPORT - * adb pull /sdcard/Android/data/com.faceclaw.app/files/faceclaw-settings-export.xml - * - * adb push settings.xml /sdcard/Android/data/com.faceclaw.app/files/faceclaw-settings-import.xml - * adb shell am broadcast -n com.faceclaw.app/.FaceclawSettingsPortReceiver \ - * -a com.faceclaw.app.SETTINGS_IMPORT - * - * Security: the settings file contains API tokens, so the manifest guards - * this receiver with android.permission.DUMP — a development permission the - * adb shell holds but ordinary apps cannot obtain without adb's help, keeping - * the trigger reachable from adb only. The transfer file lives in - * getExternalFilesDir(), which other apps cannot read on Android 11+ (and - * which the scripts delete as soon as the transfer completes); on the - * Android 7-10 devices minSdk still admits, apps holding READ_EXTERNAL_STORAGE - * could read it during that window. - */ -public class FaceclawSettingsPortReceiver extends BroadcastReceiver { - private static final String TAG = "FaceclawSettingsPort"; - public static final String ACTION_EXPORT = "com.faceclaw.app.SETTINGS_EXPORT"; - public static final String ACTION_IMPORT = "com.faceclaw.app.SETTINGS_IMPORT"; - private static final String PREFS_FILE = "faceclaw_settings.xml"; - private static final String EXPORT_NAME = "faceclaw-settings-export.xml"; - private static final String IMPORT_NAME = "faceclaw-settings-import.xml"; - - @Override - public void onReceive(Context context, Intent intent) { - String action = intent == null ? null : intent.getAction(); - try { - if (ACTION_EXPORT.equals(action)) { - setResultData(exportSettings(context)); - } else if (ACTION_IMPORT.equals(action)) { - setResultData(importSettings(context)); - // Exit once the broadcast result has been delivered: this - // process may hold stale in-memory SharedPreferences that a - // later apply() would flush over the imported file, and the - // next launch must re-read from disk. - new Handler(Looper.getMainLooper()).postDelayed(() -> { - Log.i(TAG, "Exiting after settings import"); - System.exit(0); - }, 500); - } - } catch (Exception e) { - Log.e(TAG, "Settings " + action + " failed", e); - setResultData("error: " + e); - } - } - - private File prefsFile(Context context) { - return new File(context.getApplicationInfo().dataDir, "shared_prefs/" + PREFS_FILE); - } - - private File externalFile(Context context, String name) throws IOException { - File dir = context.getExternalFilesDir(null); - if (dir == null) { - throw new IOException("external files dir unavailable"); - } - return new File(dir, name); - } - - private String exportSettings(Context context) throws IOException { - File prefs = prefsFile(context); - if (!prefs.exists()) { - return "error: no settings file yet (" + prefs + ")"; - } - File out = externalFile(context, EXPORT_NAME); - copy(prefs, out); - return "exported: " + out; - } - - private String importSettings(Context context) throws Exception { - File staged = externalFile(context, IMPORT_NAME); - if (!staged.exists()) { - return "error: nothing staged at " + staged; - } - validatePrefsXml(staged); - File prefs = prefsFile(context); - prefs.getParentFile().mkdirs(); - if (prefs.exists()) { - copy(prefs, new File(prefs.getPath() + ".bak")); - } - copy(staged, prefs); - staged.delete(); - return "imported: " + prefs + " (previous settings in " + PREFS_FILE + ".bak)"; - } - - /** Reject files that are not a SharedPreferences document. */ - private void validatePrefsXml(File file) throws Exception { - try (InputStream in = new FileInputStream(file)) { - XmlPullParser parser = Xml.newPullParser(); - parser.setInput(in, null); - int event = parser.next(); - while (event != XmlPullParser.START_TAG && event != XmlPullParser.END_DOCUMENT) { - event = parser.next(); - } - if (event != XmlPullParser.START_TAG || !"map".equals(parser.getName())) { - throw new IOException("not a SharedPreferences document"); - } - // Walk the rest so malformed XML is caught before it replaces - // the live settings file. - while (parser.next() != XmlPullParser.END_DOCUMENT) { } - } - } - - private void copy(File from, File to) throws IOException { - try (InputStream in = new FileInputStream(from); - OutputStream out = new FileOutputStream(to)) { - byte[] buffer = new byte[8192]; - int n; - while ((n = in.read(buffer)) > 0) { - out.write(buffer, 0, n); - } - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.kt new file mode 100644 index 00000000..788c93a1 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.kt @@ -0,0 +1,146 @@ +package com.faceclaw.app + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.os.Handler +import android.os.Looper +import android.util.Log +import android.util.Xml + +import org.xmlpull.v1.XmlPullParser + +import java.io.File +import java.io.FileInputStream +import java.io.FileOutputStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream + +/** + * adb-triggered export/import of the faceclaw_settings SharedPreferences + * file, so configuration (API keys, device addresses, ...) can be moved off a + * release build, where run-as is unavailable. See scripts/pull_config.sh and + * scripts/push_config.sh, which use run-as on debuggable builds and fall back + * to this receiver otherwise. + * + * adb shell am broadcast -n com.faceclaw.app/.FaceclawSettingsPortReceiver \ + * -a com.faceclaw.app.SETTINGS_EXPORT + * adb pull /sdcard/Android/data/com.faceclaw.app/files/faceclaw-settings-export.xml + * + * adb push settings.xml /sdcard/Android/data/com.faceclaw.app/files/faceclaw-settings-import.xml + * adb shell am broadcast -n com.faceclaw.app/.FaceclawSettingsPortReceiver \ + * -a com.faceclaw.app.SETTINGS_IMPORT + * + * Security: the settings file contains API tokens, so the manifest guards + * this receiver with android.permission.DUMP — a development permission the + * adb shell holds but ordinary apps cannot obtain without adb's help, keeping + * the trigger reachable from adb only. The transfer file lives in + * getExternalFilesDir(), which other apps cannot read on Android 11+ (and + * which the scripts delete as soon as the transfer completes); on the + * Android 7-10 devices minSdk still admits, apps holding READ_EXTERNAL_STORAGE + * could read it during that window. + */ +class FaceclawSettingsPortReceiver : BroadcastReceiver() { + companion object { + private const val TAG = "FaceclawSettingsPort" + const val ACTION_EXPORT = "com.faceclaw.app.SETTINGS_EXPORT" + const val ACTION_IMPORT = "com.faceclaw.app.SETTINGS_IMPORT" + private const val PREFS_FILE = "faceclaw_settings.xml" + private const val EXPORT_NAME = "faceclaw-settings-export.xml" + private const val IMPORT_NAME = "faceclaw-settings-import.xml" + } + + override fun onReceive(context: Context, intent: Intent?) { + val action = intent?.action + try { + if (ACTION_EXPORT == action) { + resultData = exportSettings(context) + } else if (ACTION_IMPORT == action) { + resultData = importSettings(context) + // Exit once the broadcast result has been delivered: this + // process may hold stale in-memory SharedPreferences that a + // later apply() would flush over the imported file, and the + // next launch must re-read from disk. + Handler(Looper.getMainLooper()).postDelayed({ + Log.i(TAG, "Exiting after settings import") + System.exit(0) + }, 500) + } + } catch (e: Exception) { + Log.e(TAG, "Settings $action failed", e) + resultData = "error: $e" + } + } + + private fun prefsFile(context: Context): File { + return File(context.applicationInfo.dataDir, "shared_prefs/$PREFS_FILE") + } + + @Throws(IOException::class) + private fun externalFile(context: Context, name: String): File { + val dir = context.getExternalFilesDir(null) + ?: throw IOException("external files dir unavailable") + return File(dir, name) + } + + @Throws(IOException::class) + private fun exportSettings(context: Context): String { + val prefs = prefsFile(context) + if (!prefs.exists()) { + return "error: no settings file yet ($prefs)" + } + val out = externalFile(context, EXPORT_NAME) + copy(prefs, out) + return "exported: $out" + } + + @Throws(Exception::class) + private fun importSettings(context: Context): String { + val staged = externalFile(context, IMPORT_NAME) + if (!staged.exists()) { + return "error: nothing staged at $staged" + } + validatePrefsXml(staged) + val prefs = prefsFile(context) + prefs.parentFile?.mkdirs() + if (prefs.exists()) { + copy(prefs, File(prefs.path + ".bak")) + } + copy(staged, prefs) + staged.delete() + return "imported: $prefs (previous settings in $PREFS_FILE.bak)" + } + + /** Reject files that are not a SharedPreferences document. */ + @Throws(Exception::class) + private fun validatePrefsXml(file: File) { + FileInputStream(file).use { input -> + val parser = Xml.newPullParser() + parser.setInput(input, null) + var event = parser.next() + while (event != XmlPullParser.START_TAG && event != XmlPullParser.END_DOCUMENT) { + event = parser.next() + } + if (event != XmlPullParser.START_TAG || "map" != parser.name) { + throw IOException("not a SharedPreferences document") + } + // Walk the rest so malformed XML is caught before it replaces + // the live settings file. + while (parser.next() != XmlPullParser.END_DOCUMENT) { } + } + } + + @Throws(IOException::class) + private fun copy(from: File, to: File) { + FileInputStream(from).use { input: InputStream -> + FileOutputStream(to).use { out: OutputStream -> + val buffer = ByteArray(8192) + var n: Int + while (input.read(buffer).also { n = it } > 0) { + out.write(buffer, 0, n) + } + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.java deleted file mode 100644 index c258ad91..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.faceclaw.app; - -import android.util.Log; - -import com.k2fsa.sherpa.onnx.OnlineStream; -import com.k2fsa.sherpa.onnx.SpeakerEmbeddingExtractor; -import com.k2fsa.sherpa.onnx.SpeakerEmbeddingExtractorConfig; - -/** - * Speaker voice-print extraction over sherpa-onnx. One embedding per - * utterance; matching/enrollment happens on the TS side (cosine similarity - * against the stored speaker profiles). - */ -public class FaceclawSpeakerId { - private static final String TAG = "FaceclawSpeakerId"; - - private SpeakerEmbeddingExtractor extractor; - private final String modelPath; - - public FaceclawSpeakerId(String modelPath) { - this.modelPath = modelPath; - } - - /** Lazily loads the model; returns false when it cannot be loaded. */ - public synchronized boolean ensureLoaded() { - if (extractor != null) { - return true; - } - try { - SpeakerEmbeddingExtractorConfig config = SpeakerEmbeddingExtractorConfig.builder() - .setModel(modelPath) - .setNumThreads(1) - .setDebug(false) - .setProvider("cpu") - .build(); - extractor = new SpeakerEmbeddingExtractor(config); - return true; - } catch (Throwable t) { - Log.w(TAG, "could not load speaker model at " + modelPath, t); - extractor = null; - return false; - } - } - - public synchronized int embeddingDim() { - return extractor == null ? 0 : extractor.getDim(); - } - - /** - * Compute an L2-normalized voice-print for one utterance of 16 kHz mono - * S16LE PCM. Returns null when the model is unavailable or the utterance - * is too short to embed (under ~0.5 s). - */ - public synchronized float[] embed(byte[] pcm16le, int sampleRate) { - if (pcm16le == null || pcm16le.length < sampleRate) { - return null; - } - if (!ensureLoaded()) { - return null; - } - int count = pcm16le.length / 2; - float[] samples = new float[count]; - for (int i = 0; i < count; i++) { - short s = (short) ((pcm16le[i * 2] & 0xff) | (pcm16le[i * 2 + 1] << 8)); - samples[i] = s / 32768.0f; - } - OnlineStream stream = null; - try { - stream = extractor.createStream(); - stream.acceptWaveform(samples, sampleRate); - stream.inputFinished(); - if (!extractor.isReady(stream)) { - return null; - } - float[] embedding = extractor.compute(stream); - return l2Normalize(embedding); - } catch (Throwable t) { - Log.w(TAG, "embedding failed", t); - return null; - } finally { - if (stream != null) { - stream.release(); - } - } - } - - private static float[] l2Normalize(float[] v) { - if (v == null) { - return null; - } - double sum = 0; - for (float x : v) { - sum += (double) x * x; - } - double norm = Math.sqrt(sum); - if (norm <= 0) { - return v; - } - for (int i = 0; i < v.length; i++) { - v[i] = (float) (v[i] / norm); - } - return v; - } - - public synchronized void close() { - if (extractor != null) { - extractor.release(); - extractor = null; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt new file mode 100644 index 00000000..5cbf7bd2 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt @@ -0,0 +1,116 @@ +package com.faceclaw.app + +import android.util.Log + +import com.k2fsa.sherpa.onnx.OnlineStream +import com.k2fsa.sherpa.onnx.SpeakerEmbeddingExtractor +import com.k2fsa.sherpa.onnx.SpeakerEmbeddingExtractorConfig + +/** + * Speaker voice-print extraction over sherpa-onnx. One embedding per + * utterance; matching/enrollment happens on the TS side (cosine similarity + * against the stored speaker profiles). + */ +class FaceclawSpeakerId(private val modelPath: String?) { + companion object { + private const val TAG = "FaceclawSpeakerId" + + @JvmStatic + private fun l2Normalize(v: FloatArray?): FloatArray? { + if (v == null) { + return null + } + var sum = 0.0 + for (x in v) { + sum += x.toDouble() * x + } + val norm = Math.sqrt(sum) + if (norm <= 0) { + return v + } + for (i in v.indices) { + v[i] = (v[i] / norm).toFloat() + } + return v + } + } + + private var extractor: SpeakerEmbeddingExtractor? = null + + /** Lazily loads the model; returns false when it cannot be loaded. */ + @Synchronized + fun ensureLoaded(): Boolean { + if (extractor != null) { + return true + } + try { + val config = SpeakerEmbeddingExtractorConfig.builder() + .setModel(modelPath) + .setNumThreads(1) + .setDebug(false) + .setProvider("cpu") + .build() + extractor = SpeakerEmbeddingExtractor(config) + return true + } catch (t: Throwable) { + Log.w(TAG, "could not load speaker model at $modelPath", t) + extractor = null + return false + } + } + + @Synchronized + fun embeddingDim(): Int { + val extractor = this.extractor + return if (extractor == null) 0 else extractor.dim + } + + /** + * Compute an L2-normalized voice-print for one utterance of 16 kHz mono + * S16LE PCM. Returns null when the model is unavailable or the utterance + * is too short to embed (under ~0.5 s). + */ + @Synchronized + fun embed(pcm16le: ByteArray?, sampleRate: Int): FloatArray? { + if (pcm16le == null || pcm16le.size < sampleRate) { + return null + } + if (!ensureLoaded()) { + return null + } + val extractor = this.extractor!! + val count = pcm16le.size / 2 + val samples = FloatArray(count) + for (i in 0 until count) { + val s = ((pcm16le[i * 2].toInt() and 0xff) or (pcm16le[i * 2 + 1].toInt() shl 8)).toShort() + samples[i] = s / 32768.0f + } + var stream: OnlineStream? = null + try { + stream = extractor.createStream() + stream.acceptWaveform(samples, sampleRate) + stream.inputFinished() + if (!extractor.isReady(stream)) { + return null + } + val embedding = extractor.compute(stream) + return l2Normalize(embedding) + } catch (t: Throwable) { + Log.w(TAG, "embedding failed", t) + return null + } finally { + if (stream != null) { + stream.release() + } + } + } + + @Synchronized + fun close() { + val extractor = this.extractor + if (extractor != null) { + extractor.release() + this.extractor = null + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.java deleted file mode 100644 index 5ec20fe9..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import java.io.BufferedReader; -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; - -/** - * Streaming HTTP POST for the TypeScript side, used for server-sent-events - * APIs (e.g. the Anthropic Messages API with stream=true). The response body - * is delivered line by line as it arrives, so the JS side can parse SSE - * events incrementally. Like FaceclawWebSocket, listener callbacks are posted - * to the Looper of the thread that constructed this object. - */ -public class FaceclawSseRequest { - private static final String TAG = "FaceclawSseRequest"; - private static final MediaType JSON = MediaType.get("application/json; charset=utf-8"); - private static volatile OkHttpClient sharedClient; - - private final Handler callbackHandler; - private final Call call; - private volatile boolean cancelled; - - /** - * Starts the request immediately. headers is a flat alternating - * [name, value, name, value, ...] array (okhttp Headers can't cross the - * JS bridge, and parallel arrays are easy to build with Array.create). - */ - public FaceclawSseRequest(String url, String jsonBody, String[] headers, final FaceclawSseListener listener) { - if (url == null || url.trim().isEmpty()) { - throw new IllegalArgumentException("url is required"); - } - if (listener == null) { - throw new IllegalArgumentException("listener is required"); - } - Looper looper = Looper.myLooper(); - callbackHandler = new Handler(looper != null ? looper : Looper.getMainLooper()); - Request.Builder builder = new Request.Builder() - .url(url.trim()) - .post(RequestBody.create(JSON, jsonBody == null ? "" : jsonBody)); - if (headers != null) { - for (int i = 0; i + 1 < headers.length; i += 2) { - if (headers[i] != null && !headers[i].isEmpty() && headers[i + 1] != null) { - builder.addHeader(headers[i], headers[i + 1]); - } - } - } - call = getClient().newCall(builder.build()); - call.enqueue(new Callback() { - @Override public void onFailure(Call call, IOException e) { - postFailure(listener, String.valueOf(e)); - } - - @Override public void onResponse(Call call, Response response) { - try (ResponseBody body = response.body()) { - if (!response.isSuccessful()) { - final int code = response.code(); - String errorBody = ""; - try { - errorBody = body == null ? "" : body.string(); - } catch (IOException e) { - Log.w(TAG, "error body read failed", e); - } - final String finalBody = errorBody; - post(() -> listener.onHttpError(code, finalBody)); - return; - } - if (body == null) { - post(listener::onComplete); - return; - } - BufferedReader reader = new BufferedReader(body.charStream()); - String line; - while ((line = reader.readLine()) != null) { - final String finalLine = line; - post(() -> listener.onLine(finalLine)); - } - post(listener::onComplete); - } catch (IOException e) { - postFailure(listener, String.valueOf(e)); - } - } - }); - } - - public void cancel() { - cancelled = true; - call.cancel(); - } - - private void post(Runnable runnable) { - if (cancelled) { - return; - } - callbackHandler.post(() -> { - if (cancelled) { - return; - } - try { - runnable.run(); - } catch (Throwable t) { - Log.w(TAG, "listener callback failed", t); - } - }); - } - - private void postFailure(FaceclawSseListener listener, String message) { - if (cancelled) { - return; - } - post(() -> listener.onFailure(message)); - } - - private static OkHttpClient getClient() { - OkHttpClient client = sharedClient; - if (client == null) { - synchronized (FaceclawSseRequest.class) { - if (sharedClient == null) { - // Streaming responses can pause between events (e.g. while - // the model thinks), so the read timeout is generous. The - // Anthropic API sends periodic ping events well within it. - sharedClient = new OkHttpClient.Builder() - .connectTimeout(15, TimeUnit.SECONDS) - .readTimeout(180, TimeUnit.SECONDS) - .addInterceptor(FaceclawHttp.userAgentInterceptor()) - .build(); - } - client = sharedClient; - } - } - return client; - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt new file mode 100644 index 00000000..cf7a9514 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt @@ -0,0 +1,156 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.util.Log + +import java.io.BufferedReader +import java.io.IOException +import java.util.concurrent.TimeUnit + +import okhttp3.Call +import okhttp3.Callback +import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.Response + +/** + * Streaming HTTP POST for the TypeScript side, used for server-sent-events + * APIs (e.g. the Anthropic Messages API with stream=true). The response body + * is delivered line by line as it arrives, so the JS side can parse SSE + * events incrementally. Like FaceclawWebSocket, listener callbacks are posted + * to the Looper of the thread that constructed this object. + */ +class FaceclawSseRequest +/** + * Starts the request immediately. headers is a flat alternating + * [name, value, name, value, ...] array (okhttp Headers can't cross the + * JS bridge, and parallel arrays are easy to build with Array.create). + */ +constructor(url: String?, jsonBody: String?, headers: Array?, listener: FaceclawSseListener?) { + private val callbackHandler: Handler + private val call: Call + @Volatile + private var cancelled = false + + init { + if (url == null || url.trim().isEmpty()) { + throw IllegalArgumentException("url is required") + } + if (listener == null) { + throw IllegalArgumentException("listener is required") + } + val looper = Looper.myLooper() + callbackHandler = Handler(looper ?: Looper.getMainLooper()) + val builder = Request.Builder() + .url(url.trim()) + .post((jsonBody ?: "").toRequestBody(JSON)) + if (headers != null) { + var i = 0 + while (i + 1 < headers.size) { + val name = headers[i] + val value = headers[i + 1] + if (name != null && !name.isEmpty() && value != null) { + builder.addHeader(name, value) + } + i += 2 + } + } + call = getClient().newCall(builder.build()) + call.enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) { + postFailure(listener, e.toString()) + } + + override fun onResponse(call: Call, response: Response) { + try { + response.body.use { body -> + if (!response.isSuccessful) { + val code = response.code + var errorBody = "" + try { + errorBody = body?.string() ?: "" + } catch (e: IOException) { + Log.w(TAG, "error body read failed", e) + } + val finalBody = errorBody + post { listener.onHttpError(code, finalBody) } + return + } + if (body == null) { + post { listener.onComplete() } + return + } + val reader = BufferedReader(body.charStream()) + var line: String? + while (reader.readLine().also { line = it } != null) { + val finalLine = line + post { listener.onLine(finalLine) } + } + post { listener.onComplete() } + } + } catch (e: IOException) { + postFailure(listener, e.toString()) + } + } + }) + } + + fun cancel() { + cancelled = true + call.cancel() + } + + private fun post(runnable: Runnable) { + if (cancelled) { + return + } + callbackHandler.post { + if (cancelled) { + return@post + } + try { + runnable.run() + } catch (t: Throwable) { + Log.w(TAG, "listener callback failed", t) + } + } + } + + private fun postFailure(listener: FaceclawSseListener, message: String) { + if (cancelled) { + return + } + post { listener.onFailure(message) } + } + + companion object { + private const val TAG = "FaceclawSseRequest" + private val JSON: MediaType = "application/json; charset=utf-8".toMediaType() + @Volatile + private var sharedClient: OkHttpClient? = null + + private fun getClient(): OkHttpClient { + var client = sharedClient + if (client == null) { + synchronized(FaceclawSseRequest::class.java) { + if (sharedClient == null) { + // Streaming responses can pause between events (e.g. while + // the model thinks), so the read timeout is generous. The + // Anthropic API sends periodic ping events well within it. + sharedClient = OkHttpClient.Builder() + .connectTimeout(15, TimeUnit.SECONDS) + .readTimeout(180, TimeUnit.SECONDS) + .addInterceptor(FaceclawHttp.userAgentInterceptor()) + .build() + } + client = sharedClient + } + } + return client!! + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.java deleted file mode 100644 index 34209e16..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.Network; -import android.net.NetworkCapabilities; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.os.Build; -import android.telephony.SignalStrength; -import android.telephony.TelephonyManager; -import android.util.Log; - -import java.io.ByteArrayOutputStream; -import java.lang.reflect.Method; - -public final class FaceclawSystemStatusIconProvider { - private static final String TAG = "FaceclawStatusIcons"; - private static final int ICON_SIZE = 24; - - private FaceclawSystemStatusIconProvider() { - } - - public static byte[] getSystemStatusIconGrays(Context context, int iconSize) { - if (context == null) { - return new byte[0]; - } - Context appContext = context.getApplicationContext(); - int size = Math.max(1, Math.min(96, iconSize)); - ByteArrayOutputStream out = new ByteArrayOutputStream(size * size * 3); - - int wifiLevel = getWifiLevel(appContext); - if (wifiLevel >= 0) { - append(out, scaleIcon(drawWifiIcon(wifiLevel), size)); - } - - int cellLevel = getCellLevel(appContext); - if (cellLevel >= 0) { - append(out, scaleIcon(drawCellIcon(cellLevel), size)); - } - - if (isHotspotEnabled(appContext)) { - append(out, scaleIcon(drawHotspotIcon(), size)); - } - - return out.toByteArray(); - } - - private static int getWifiLevel(Context context) { - try { - ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - Network activeNetwork = connectivityManager == null ? null : connectivityManager.getActiveNetwork(); - NetworkCapabilities capabilities = activeNetwork == null ? null : connectivityManager.getNetworkCapabilities(activeNetwork); - if (capabilities == null || !capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { - return -1; - } - WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); - WifiInfo info = wifiManager == null ? null : wifiManager.getConnectionInfo(); - if (info == null || !isValidRssi(info.getRssi())) { - return -1; - } - return Math.max(0, Math.min(4, WifiManager.calculateSignalLevel(info.getRssi(), 5))); - } catch (Throwable t) { - Log.w(TAG, "failed to read Wi-Fi status", t); - return -1; - } - } - - private static int getCellLevel(Context context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { - return -1; - } - try { - TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - SignalStrength signalStrength = telephonyManager == null ? null : telephonyManager.getSignalStrength(); - if (signalStrength == null) { - return -1; - } - return Math.max(0, Math.min(4, signalStrength.getLevel())); - } catch (SecurityException e) { - // Most Android versions require READ_PHONE_STATE for this. We skip it - // rather than prompting for a broad phone permission just for an icon. - return -1; - } catch (Throwable t) { - Log.w(TAG, "failed to read cellular status", t); - return -1; - } - } - - private static boolean isHotspotEnabled(Context context) { - try { - WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); - if (wifiManager == null) { - return false; - } - Method method = wifiManager.getClass().getDeclaredMethod("getWifiApState"); - method.setAccessible(true); - Object result = method.invoke(wifiManager); - int state = result instanceof Integer ? (Integer) result : -1; - return state == 13 || state == 12; // WIFI_AP_STATE_ENABLED / ENABLING - } catch (Throwable ignored) { - return false; - } - } - - private static boolean isValidRssi(int rssi) { - return rssi > -127 && rssi < 0; - } - - private static byte[] drawWifiIcon(int level) { - byte[] icon = new byte[ICON_SIZE * ICON_SIZE]; - int cx = 12; - int cy = 18; - fillRect(icon, cx - 1, cy - 1, 3, 3, 230); - int[] radii = new int[] {5, 9, 13, 17}; - for (int index = 0; index < radii.length; index++) { - if (level <= index) { - continue; - } - drawWifiArc(icon, cx, cy, radii[index], 210); - } - return icon; - } - - private static void drawWifiArc(byte[] icon, int cx, int cy, int radius, int value) { - int inner = (radius - 1) * (radius - 1); - int outer = (radius + 1) * (radius + 1); - for (int y = 0; y < ICON_SIZE; y++) { - for (int x = 0; x < ICON_SIZE; x++) { - int dx = x - cx; - int dy = y - cy; - int dist = dx * dx + dy * dy; - if (dy <= 0 && dist >= inner && dist <= outer && Math.abs(dx) <= radius) { - setPixel(icon, x, y, value); - } - } - } - } - - private static byte[] drawCellIcon(int level) { - byte[] icon = new byte[ICON_SIZE * ICON_SIZE]; - for (int bar = 0; bar < 4; bar++) { - int x = 5 + bar * 4; - int height = 5 + bar * 4; - int value = level > bar ? 220 : 55; - fillRect(icon, x, 20 - height, 3, height, value); - } - return icon; - } - - private static byte[] drawHotspotIcon() { - byte[] icon = new byte[ICON_SIZE * ICON_SIZE]; - fillRect(icon, 11, 17, 3, 3, 230); - drawWifiArc(icon, 12, 19, 7, 210); - drawWifiArc(icon, 12, 19, 12, 210); - fillRect(icon, 6, 5, 12, 2, 170); - return icon; - } - - private static byte[] scaleIcon(byte[] source, int size) { - if (size == ICON_SIZE) { - return source; - } - byte[] scaled = new byte[size * size]; - for (int y = 0; y < size; y++) { - int sy = Math.min(ICON_SIZE - 1, (y * ICON_SIZE) / size); - for (int x = 0; x < size; x++) { - int sx = Math.min(ICON_SIZE - 1, (x * ICON_SIZE) / size); - scaled[y * size + x] = source[sy * ICON_SIZE + sx]; - } - } - return scaled; - } - - private static void fillRect(byte[] icon, int x, int y, int width, int height, int value) { - for (int row = y; row < y + height; row++) { - for (int col = x; col < x + width; col++) { - setPixel(icon, col, row, value); - } - } - } - - private static void setPixel(byte[] icon, int x, int y, int value) { - if (x < 0 || y < 0 || x >= ICON_SIZE || y >= ICON_SIZE) { - return; - } - icon[y * ICON_SIZE + x] = (byte) Math.max(0, Math.min(255, value)); - } - - private static void append(ByteArrayOutputStream out, byte[] bytes) { - out.write(bytes, 0, bytes.length); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt new file mode 100644 index 00000000..7c8be12c --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt @@ -0,0 +1,193 @@ +package com.faceclaw.app + +import android.content.Context +import android.net.ConnectivityManager +import android.net.Network +import android.net.NetworkCapabilities +import android.net.wifi.WifiInfo +import android.net.wifi.WifiManager +import android.os.Build +import android.telephony.SignalStrength +import android.telephony.TelephonyManager +import android.util.Log + +import java.io.ByteArrayOutputStream +import java.lang.reflect.Method + +class FaceclawSystemStatusIconProvider private constructor() { + companion object { + private const val TAG = "FaceclawStatusIcons" + private const val ICON_SIZE = 24 + + @JvmStatic + fun getSystemStatusIconGrays(context: Context?, iconSize: Int): ByteArray { + if (context == null) { + return ByteArray(0) + } + val appContext = context.applicationContext + val size = Math.max(1, Math.min(96, iconSize)) + val out = ByteArrayOutputStream(size * size * 3) + + val wifiLevel = getWifiLevel(appContext) + if (wifiLevel >= 0) { + append(out, scaleIcon(drawWifiIcon(wifiLevel), size)) + } + + val cellLevel = getCellLevel(appContext) + if (cellLevel >= 0) { + append(out, scaleIcon(drawCellIcon(cellLevel), size)) + } + + if (isHotspotEnabled(appContext)) { + append(out, scaleIcon(drawHotspotIcon(), size)) + } + + return out.toByteArray() + } + + private fun getWifiLevel(context: Context): Int { + try { + val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager? + val activeNetwork: Network? = if (connectivityManager == null) null else connectivityManager.activeNetwork + val capabilities: NetworkCapabilities? = if (activeNetwork == null) null else connectivityManager!!.getNetworkCapabilities(activeNetwork) + if (capabilities == null || !capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + return -1 + } + val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager? + val info: WifiInfo? = if (wifiManager == null) null else wifiManager.connectionInfo + if (info == null || !isValidRssi(info.rssi)) { + return -1 + } + return Math.max(0, Math.min(4, WifiManager.calculateSignalLevel(info.rssi, 5))) + } catch (t: Throwable) { + Log.w(TAG, "failed to read Wi-Fi status", t) + return -1 + } + } + + private fun getCellLevel(context: Context): Int { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { + return -1 + } + try { + val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager? + val signalStrength: SignalStrength? = if (telephonyManager == null) null else telephonyManager.signalStrength + if (signalStrength == null) { + return -1 + } + return Math.max(0, Math.min(4, signalStrength.level)) + } catch (e: SecurityException) { + // Most Android versions require READ_PHONE_STATE for this. We skip it + // rather than prompting for a broad phone permission just for an icon. + return -1 + } catch (t: Throwable) { + Log.w(TAG, "failed to read cellular status", t) + return -1 + } + } + + private fun isHotspotEnabled(context: Context): Boolean { + try { + val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager? + if (wifiManager == null) { + return false + } + val method: Method = wifiManager.javaClass.getDeclaredMethod("getWifiApState") + method.isAccessible = true + val result: Any? = method.invoke(wifiManager) + val state = if (result is Int) result else -1 + return state == 13 || state == 12 // WIFI_AP_STATE_ENABLED / ENABLING + } catch (ignored: Throwable) { + return false + } + } + + private fun isValidRssi(rssi: Int): Boolean { + return rssi > -127 && rssi < 0 + } + + private fun drawWifiIcon(level: Int): ByteArray { + val icon = ByteArray(ICON_SIZE * ICON_SIZE) + val cx = 12 + val cy = 18 + fillRect(icon, cx - 1, cy - 1, 3, 3, 230) + val radii = intArrayOf(5, 9, 13, 17) + for (index in radii.indices) { + if (level <= index) { + continue + } + drawWifiArc(icon, cx, cy, radii[index], 210) + } + return icon + } + + private fun drawWifiArc(icon: ByteArray, cx: Int, cy: Int, radius: Int, value: Int) { + val inner = (radius - 1) * (radius - 1) + val outer = (radius + 1) * (radius + 1) + for (y in 0 until ICON_SIZE) { + for (x in 0 until ICON_SIZE) { + val dx = x - cx + val dy = y - cy + val dist = dx * dx + dy * dy + if (dy <= 0 && dist >= inner && dist <= outer && Math.abs(dx) <= radius) { + setPixel(icon, x, y, value) + } + } + } + } + + private fun drawCellIcon(level: Int): ByteArray { + val icon = ByteArray(ICON_SIZE * ICON_SIZE) + for (bar in 0 until 4) { + val x = 5 + bar * 4 + val height = 5 + bar * 4 + val value = if (level > bar) 220 else 55 + fillRect(icon, x, 20 - height, 3, height, value) + } + return icon + } + + private fun drawHotspotIcon(): ByteArray { + val icon = ByteArray(ICON_SIZE * ICON_SIZE) + fillRect(icon, 11, 17, 3, 3, 230) + drawWifiArc(icon, 12, 19, 7, 210) + drawWifiArc(icon, 12, 19, 12, 210) + fillRect(icon, 6, 5, 12, 2, 170) + return icon + } + + private fun scaleIcon(source: ByteArray, size: Int): ByteArray { + if (size == ICON_SIZE) { + return source + } + val scaled = ByteArray(size * size) + for (y in 0 until size) { + val sy = Math.min(ICON_SIZE - 1, (y * ICON_SIZE) / size) + for (x in 0 until size) { + val sx = Math.min(ICON_SIZE - 1, (x * ICON_SIZE) / size) + scaled[y * size + x] = source[sy * ICON_SIZE + sx] + } + } + return scaled + } + + private fun fillRect(icon: ByteArray, x: Int, y: Int, width: Int, height: Int, value: Int) { + for (row in y until y + height) { + for (col in x until x + width) { + setPixel(icon, col, row, value) + } + } + } + + private fun setPixel(icon: ByteArray, x: Int, y: Int, value: Int) { + if (x < 0 || y < 0 || x >= ICON_SIZE || y >= ICON_SIZE) { + return + } + icon[y * ICON_SIZE + x] = Math.max(0, Math.min(255, value)).toByte() + } + + private fun append(out: ByteArrayOutputStream, bytes: ByteArray) { + out.write(bytes, 0, bytes.size) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java deleted file mode 100644 index de09ae61..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java +++ /dev/null @@ -1,1162 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; -import android.os.Handler; -import android.os.Looper; -import android.os.SystemClock; -import android.util.Log; - -import com.k2fsa.sherpa.onnx.FeatureConfig; -import com.k2fsa.sherpa.onnx.OfflineModelConfig; -import com.k2fsa.sherpa.onnx.OfflineMoonshineModelConfig; -import com.k2fsa.sherpa.onnx.OfflineRecognizer; -import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig; -import com.k2fsa.sherpa.onnx.OfflineRecognizerResult; -import com.k2fsa.sherpa.onnx.OfflineStream; -import com.k2fsa.sherpa.onnx.OfflineWhisperModelConfig; - -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.util.ArrayDeque; -import java.util.Arrays; - -public class FaceclawVoiceController { - private static final String TAG = "FaceclawVoice"; - private static final int SAMPLE_RATE = 16000; - private static final int FEATURE_DIM = 80; - private static final int MAX_AUDIO_QUEUE_PACKETS = 80; - private static final int EXPECTED_PACKET_INTERVAL_MS = 50; - private static final int LATE_PACKET_INTERVAL_MS = 90; - private static final int STATS_INTERVAL_MS = 5_000; - // Push-to-talk utterance boundaries come from the button. We re-decode the - // current audio segment in full for each live partial and emit the complete - // utterance text (REPLACE, never a delta). The sherpa Moonshine v2 decoder - // used here fails once a single input grows past roughly 9.1 seconds, so - // longer utterances are committed in model-safe segments. - private static final int TRANSCRIPT_DECODE_INTERVAL_MS = 700; - private static final int TRANSCRIPT_MIN_SAMPLES = SAMPLE_RATE / 3; - private static final int TRANSCRIPT_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8; - // When a segment fills, cut at the quietest window within the last - // TRANSCRIPT_CUT_SEARCH_SAMPLES rather than mid-word at the 8s mark; the - // audio after the cut carries over into the next segment. - private static final int TRANSCRIPT_CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2; - private static final int TRANSCRIPT_CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000; - // Glasses-mic PCM peaks around 0.1 full scale, and at that level the - // quantized Moonshine model often returns empty or garbled text. Boost - // each decode window toward this peak, with a gain cap so near-silent - // buffers aren't amplified into pure noise. - private static final float TRANSCRIPT_NORMALIZE_TARGET_PEAK = 0.9f; - private static final float TRANSCRIPT_NORMALIZE_MAX_GAIN = 30f; - private static final int TRANSCRIPT_LOG_PREVIEW_CHARS = 80; - // Model directory shared with the TS-side download flow (asr-model.ts), - // which fetches the Moonshine files here on demand; they are no longer - // bundled in the APK. - private static final String ASR_ROOT = "faceclaw-voice-asr"; - private static final String ASR_MODEL_DIR = "sherpa-onnx-moonshine-base-en-quantized-2026-02-27"; - // Model files for the retired on-phone wake-word spotter, copied to - // filesDir by earlier releases; deleted on sight to reclaim the space. - // (The wakeword is now detected by the glasses firmware itself.) - private static final String LEGACY_KWS_ROOT = "faceclaw-voice"; - private static final String[] ASR_MODEL_FILES = { - "encoder_model.ort", - "decoder_model_merged.ort", - "tokens.txt" - }; - // Second on-device model: sherpa-onnx's offline Whisper backend (base.en, - // int8-quantized -- see the model-choice note in asr-model.ts). Directory - // shared with the TS-side download flow, same convention as ASR_MODEL_DIR. - // - // On every call, sherpa-onnx (offline-recognizer-whisper-impl.h, v1.13.0) - // runs Whisper's encoder over the whole buffer plus 1000 frames (~10s) of - // zero tail padding, capped at 30s. Re-decoding on Moonshine's - // TRANSCRIPT_DECODE_INTERVAL_MS live-partial cadence would repeat that - // encode, growing with the utterance, roughly 1.4x/second while the user is - // still speaking, so onboardModelKind gates that loop off for Whisper -- - // see processRecognizer(). Whisper is also known to hallucinate text on - // near-silent input; recognizeTranscriptSegment() gates that too. - private static final String ASR_WHISPER_MODEL_DIR = "sherpa-onnx-whisper-base-en-int8"; - private static final String[] ASR_WHISPER_MODEL_FILES = { - "base.en-encoder.int8.onnx", - "base.en-decoder.int8.onnx", - "base.en-tokens.txt" - }; - // Below this peak amplitude (pre-normalization, of a full-scale +/-1.0f - // buffer) a segment is treated as silence and never reaches the Whisper - // recognizer at all, rather than risking a hallucinated non-answer. Picked - // conservatively low (well under typical mic noise floor already seen in - // this pipeline's normalization target) -- UNTESTED on real hardware, tune - // against real glasses captures rather than trusting this number. - private static final float WHISPER_SILENCE_PEAK_THRESHOLD = 0.01f; - - private enum VoiceInputMode { - ONBOARD, // on-phone transcription (Moonshine or Whisper; see onboardModelKind) - CLOUD // decode locally, emit PCM for a cloud recognizer on the TS side - } - - /** Which on-device model ONBOARD mode uses. Set via setOnboardModelKind() before start(). */ - private enum OnboardModelKind { - MOONSHINE, - WHISPER - } - - private final Context appContext; - private final Handler mainHandler = new Handler(Looper.getMainLooper()); - private final Object lock = new Object(); - private final Object audioQueueLock = new Object(); - private final ArrayDeque audioQueue = new ArrayDeque<>(); - private volatile FaceclawVoiceControllerListener listener; - private volatile FaceclawBleCommunicator communicator; - private Thread workerThread; - private volatile boolean started; - // Set once the worker has the glasses mic enabled for this session. - // Read and written under `lock`, so it flips with `started` atomically. - private boolean audioStarted; - // Capture from the phone's own microphone instead of the G2 over BLE - // (preview-only mode, where no glasses are connected). Latched into - // activePhoneMic at start() (under `lock`) so a mid-session setter call - // can't switch pipelines underneath the worker. - private volatile boolean usePhoneMic; - private boolean activePhoneMic; - private VoiceInputMode mode = VoiceInputMode.CLOUD; - private volatile OnboardModelKind onboardModelKind = OnboardModelKind.MOONSHINE; - private OfflineRecognizer recognizer; - private FaceclawLc3Decoder lc3Decoder; - private final float[] transcriptSamples = new float[TRANSCRIPT_SEGMENT_MAX_SAMPLES]; - private int transcriptSampleCount; - private long committedTranscriptSampleCount; - private String committedTranscript = ""; - private String currentSegmentTranscript = ""; - private long lastTranscriptDecodeAtMs; - private String lastTranscript = ""; - private volatile boolean saveRecordings; - private volatile boolean endpointing; - private final VoiceEndpointDetector endpointDetector = new VoiceEndpointDetector(); - private java.io.ByteArrayOutputStream recordingPcm; - // Speaker verification against the enrolled wearer voice-print ("my voice - // only" command gating). Configured before start(); the utterance PCM is - // buffered (capped) and verified once at session end. - private static final int VERIFY_MAX_SAMPLES = SAMPLE_RATE * 10; - private static final int VERIFY_MIN_SAMPLES = SAMPLE_RATE; - private volatile String verifySpeakerModelPath; - private volatile float[] verifyWearerEmbedding; - private volatile float verifyThreshold = 0.8f; - private short[] verifyBuffer; - private int verifyCount; - // Global mic processing (Microphones app config): spectral noise - // suppression and firmware-DoA beam gating, applied to every capture - // session that opts in (assistant push-to-talk, Transcribe, hands-free). - // The raw tap opts out — raw means raw, and the Microphones session does - // its own beam-compensated processing on that path. - private volatile boolean suppressionEnabled; - private volatile boolean beamFilterEnabled; - private volatile int beamCenterDeg; - private volatile int beamHalfWidthDeg = 180; - private FaceclawNoiseSuppressor suppressor; - private long queuedPackets; - private long queueDroppedPackets; - private long decodedSamples; - private long latePackets; - private long wrongArmPackets; - private long lastPacketArrivalMs; - private long maxInterPacketMs; - private long lastStatsAtMs; - - public FaceclawVoiceController(Context context) { - this.appContext = context.getApplicationContext(); - } - - public void setListener(FaceclawVoiceControllerListener listener) { - this.listener = listener; - } - - public void setCommunicator(FaceclawBleCommunicator communicator) { - this.communicator = communicator; - } - - /** Source the next capture from the phone microphone (no glasses paired). */ - public void setUsePhoneMic(boolean usePhoneMic) { - this.usePhoneMic = usePhoneMic; - } - - /** When true, the decoded mic PCM for each session is saved as a WAV. */ - public void setSaveRecordings(boolean saveRecordings) { - this.saveRecordings = saveRecordings; - } - - /** - * Which on-device model {@link #start}("onboard") should load: "whisper" - * selects the second on-device model (sherpa-onnx offline Whisper); any - * other value (including null/absent) keeps the existing Moonshine model, - * so callers that never call this see unchanged behavior. Must be set - * before {@link #start}; has no effect in CLOUD mode. - */ - public void setOnboardModelKind(String kind) { - this.onboardModelKind = "whisper".equals(kind) ? OnboardModelKind.WHISPER : OnboardModelKind.MOONSHINE; - } - - /** - * When true, watch the decoded PCM and fire {@code onSpeechEnd} once the - * speaker stops. Used by hands-free ("Hey Even") capture, which has no - * button release to end the utterance. Must be set before {@link #start}. - */ - public void setEndpointing(boolean endpointing) { - this.endpointing = endpointing; - } - - /** - * Verify this session's speaker against the enrolled wearer voice-print - * and report the result via onSpeakerVerified just before the final - * transcript. Must be set before {@link #start}; pass a null model path - * to disable. - */ - public void setSpeakerVerification(String speakerModelPath, float[] wearerEmbedding, float threshold) { - this.verifySpeakerModelPath = speakerModelPath; - this.verifyWearerEmbedding = wearerEmbedding; - this.verifyThreshold = threshold > 0 ? threshold : 0.8f; - } - - public void clearSpeakerVerification() { - this.verifySpeakerModelPath = null; - this.verifyWearerEmbedding = null; - } - - /** Spectral noise suppression on the decoded stream. Safe to flip mid-run. */ - public void setNoiseSuppression(boolean enabled) { - this.suppressionEnabled = enabled; - } - - /** - * Direction gating from the Sonic Radar beam: packets whose firmware - * direction-of-arrival falls outside centerDeg ± halfWidthDeg (device - * frame, 0 = straight ahead, positive right) are dropped before any - * consumer sees them. Safe to update mid-run. - */ - public void setBeamFilter(boolean enabled, int centerDeg, int halfWidthDeg) { - this.beamFilterEnabled = enabled; - this.beamCenterDeg = centerDeg; - this.beamHalfWidthDeg = Math.max(5, Math.min(180, halfWidthDeg)); - } - - private boolean withinBeam(int angleDegrees) { - int delta = angleDegrees - beamCenterDeg; - while (delta > 180) delta -= 360; - while (delta < -180) delta += 360; - return Math.abs(delta) <= beamHalfWidthDeg; - } - - private void applySuppression(short[] pcm, int count) { - try { - if (suppressor == null) { - suppressor = new FaceclawNoiseSuppressor(SAMPLE_RATE); - } - byte[] le = new byte[count * 2]; - for (int i = 0; i < count; i++) { - le[i * 2] = (byte) (pcm[i] & 0xff); - le[i * 2 + 1] = (byte) ((pcm[i] >> 8) & 0xff); - } - byte[] cleaned = suppressor.process(le); - int cleanedCount = Math.min(count, cleaned.length / 2); - for (int i = 0; i < cleanedCount; i++) { - pcm[i] = (short) ((cleaned[i * 2] & 0xff) | (cleaned[i * 2 + 1] << 8)); - } - } catch (Throwable t) { - Log.w(TAG, "noise suppression failed; passing audio through", t); - suppressionEnabled = false; - } - } - - public void start(String requestedMode) { - start(requestedMode, 0); - } - - public void start(String requestedMode, int captureId) { - synchronized (lock) { - if (started) { - emitStatus("Voice control is already listening."); - emitStopped(captureId); - return; - } - if (!usePhoneMic && (communicator == null || !communicator.isSessionReady())) { - emitStatus("Voice control needs an active G2 connection."); - emitStopped(captureId); - return; - } - mode = parseMode(requestedMode); - activePhoneMic = usePhoneMic; - started = true; - audioStarted = false; - workerThread = new Thread(() -> runLoop(captureId), "FaceclawVoiceController"); - workerThread.start(); - } - } - - /** - * Whether mic audio is actually flowing. {@link #start} only records - * intent: the enable lives in the glasses' EvenHub session, so a transport - * drop or a session suspend can leave this controller started with a - * worker that will never see another packet. Anything deciding whether to - * (re)start capture must ask this rather than assume its own bookkeeping. - */ - public boolean isCapturing() { - boolean audioUp; - boolean phoneMic; - synchronized (lock) { - if (!started) { - return false; - } - audioUp = audioStarted; - phoneMic = activePhoneMic; - } - if (!audioUp) { - // The worker is still bringing the mic up; report it as running so - // a concurrent request shares it instead of restarting it. - return true; - } - if (phoneMic) { - // AudioRecord has no session to lose the enable to; it runs until stop(). - return true; - } - FaceclawBleCommunicator currentCommunicator = communicator; - return currentCommunicator != null && currentCommunicator.isAudioCaptureActive(); - } - - public void stop() { - Thread threadToJoin; - synchronized (lock) { - if (!started) { - return; - } - started = false; - threadToJoin = workerThread; - } - stopG2Audio(); - synchronized (audioQueueLock) { - audioQueueLock.notifyAll(); - } - if (threadToJoin != null) { - threadToJoin.interrupt(); - if (Thread.currentThread() != threadToJoin) { - try { - threadToJoin.join(1500); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - } - - public void close() { - stop(); - } - - private VoiceInputMode parseMode(String requestedMode) { - if ("cloud".equals(requestedMode)) { - return VoiceInputMode.CLOUD; - } - return VoiceInputMode.ONBOARD; - } - - private void runLoop(int captureId) { - try { - deleteLegacyKwsFiles(); - VoiceInputMode currentMode = mode; - OnboardModelKind currentOnboardKind = onboardModelKind; - if (currentMode == VoiceInputMode.ONBOARD) { - File modelDir = findAsrModelDir(currentOnboardKind); - if (modelDir == null) { - emitStatus("Voice model not downloaded (see Settings > Voice)."); - return; - } - emitStatus("Loading transcription model..."); - recognizer = new OfflineRecognizer(buildRecognizerConfig(modelDir, currentOnboardKind)); - resetTranscriptState(); - lastTranscript = ""; - } - endpointDetector.reset(); - if (suppressor != null) { - suppressor.reset(); - } - recordingPcm = saveRecordings ? new java.io.ByteArrayOutputStream(SAMPLE_RATE * 2 * 4) : null; - boolean verifying = verifySpeakerModelPath != null && verifyWearerEmbedding != null; - verifyBuffer = verifying ? new short[VERIFY_MAX_SAMPLES] : null; - verifyCount = 0; - if (activePhoneMic) { - android.media.AudioRecord record = openPhoneMic(); - if (record == null) { - emitStatus("Could not start the phone microphone."); - return; - } - synchronized (lock) { - audioStarted = true; - } - emitStatus(currentMode == VoiceInputMode.CLOUD - ? "Listening (cloud)..." - : "Listening..."); - try { - processPhoneAudio(record); - } finally { - try { - record.stop(); - } catch (Throwable ignored) { - // Already stopped or never recording; release below either way. - } - record.release(); - } - } else { - lc3Decoder = new FaceclawLc3Decoder(); - if (!startG2Audio()) { - emitStatus("Could not start G2 microphone input."); - return; - } - synchronized (lock) { - audioStarted = true; - } - emitStatus(currentMode == VoiceInputMode.CLOUD - ? "Listening (cloud)..." - : "Listening..."); - processG2Audio(); - } - // Verification result must precede the final transcript so the - // TS bridge can suppress a non-wearer command before it is acted - // on (the callbacks are posted in order to the main handler). - runSpeakerVerification(); - // Button released / stop requested: emit one final full-utterance - // transcript so the UI can freeze it. - if (currentMode == VoiceInputMode.ONBOARD) { - decodeTranscript(true); - } - } catch (Throwable error) { - Log.e(TAG, "Voice control failed", error); - emitStatus("Voice control failed: " + error.getMessage()); - } finally { - stopG2Audio(); - writeRecordingIfAny(); - releaseSherpa(); - releaseLc3(); - synchronized (lock) { - started = false; - audioStarted = false; - workerThread = null; - } - emitStopped(captureId); - } - } - - private void appendRecording(short[] pcm, int count) { - java.io.ByteArrayOutputStream out = recordingPcm; - if (out == null) { - return; - } - for (int i = 0; i < count; i++) { - short s = pcm[i]; - out.write(s & 0xff); - out.write((s >> 8) & 0xff); - } - } - - /** Save the session's decoded mic PCM as a 16 kHz mono 16-bit WAV. */ - private void writeRecordingIfAny() { - java.io.ByteArrayOutputStream out = recordingPcm; - recordingPcm = null; - if (out == null || out.size() == 0) { - return; - } - try { - byte[] pcmBytes = out.toByteArray(); - java.io.File dir = new java.io.File(appContext.getExternalFilesDir(null), "voice-recordings"); - if (!dir.exists() && !dir.mkdirs()) { - Log.w(TAG, "could not create voice-recordings dir"); - return; - } - String stamp = new java.text.SimpleDateFormat("yyyyMMdd-HHmmss-SSS", java.util.Locale.US) - .format(new java.util.Date()); - java.io.File file = new java.io.File(dir, "voice-" + stamp + ".wav"); - try (java.io.FileOutputStream fos = new java.io.FileOutputStream(file)) { - fos.write(buildWavHeader(pcmBytes.length, SAMPLE_RATE, 1, 16)); - fos.write(pcmBytes); - } - Log.i(TAG, "saved voice recording " + file.getAbsolutePath() - + " samples=" + (pcmBytes.length / 2) - + " sec=" + String.format(java.util.Locale.US, "%.2f", pcmBytes.length / 2.0 / SAMPLE_RATE)); - } catch (Throwable t) { - Log.w(TAG, "failed to save voice recording", t); - } - } - - private static byte[] buildWavHeader(int pcmBytes, int sampleRate, int channels, int bitsPerSample) { - int byteRate = sampleRate * channels * bitsPerSample / 8; - int blockAlign = channels * bitsPerSample / 8; - int dataSize = pcmBytes; - int riffSize = 36 + dataSize; - java.nio.ByteBuffer b = java.nio.ByteBuffer.allocate(44).order(java.nio.ByteOrder.LITTLE_ENDIAN); - b.put("RIFF".getBytes(StandardCharsets.US_ASCII)); - b.putInt(riffSize); - b.put("WAVE".getBytes(StandardCharsets.US_ASCII)); - b.put("fmt ".getBytes(StandardCharsets.US_ASCII)); - b.putInt(16); // PCM fmt chunk size - b.putShort((short) 1); // PCM - b.putShort((short) channels); - b.putInt(sampleRate); - b.putInt(byteRate); - b.putShort((short) blockAlign); - b.putShort((short) bitsPerSample); - b.put("data".getBytes(StandardCharsets.US_ASCII)); - b.putInt(dataSize); - return b.array(); - } - - private OfflineRecognizerConfig buildRecognizerConfig(File modelDir, OnboardModelKind kind) { - OfflineModelConfig.Builder modelConfig = OfflineModelConfig.builder() - .setNumThreads(1); - if (kind == OnboardModelKind.WHISPER) { - modelConfig - .setWhisper(OfflineWhisperModelConfig.builder() - .setEncoder(new File(modelDir, "base.en-encoder.int8.onnx").getAbsolutePath()) - .setDecoder(new File(modelDir, "base.en-decoder.int8.onnx").getAbsolutePath()) - .setLanguage("en") - .setTask("transcribe") - .build()) - .setTokens(new File(modelDir, "base.en-tokens.txt").getAbsolutePath()); - } else { - modelConfig - .setMoonshine(OfflineMoonshineModelConfig.builder() - .setEncoder(new File(modelDir, "encoder_model.ort").getAbsolutePath()) - .setMergedDecoder(new File(modelDir, "decoder_model_merged.ort").getAbsolutePath()) - .build()) - .setTokens(new File(modelDir, "tokens.txt").getAbsolutePath()); - } - return OfflineRecognizerConfig.builder() - .setFeatureConfig(FeatureConfig.builder() - .setSampleRate(SAMPLE_RATE) - .setFeatureDim(FEATURE_DIM) - .build()) - .setModelConfig(modelConfig.build()) - .build(); - } - - /** - * The on-device model directory for the given kind, populated by the - * download flow in asr-model.ts (releases before 0.5.0 copied the - * Moonshine files out of the APK directly, so upgraded installs are - * already complete for that model). Null when any expected file is - * missing, i.e. the model still needs to be downloaded. - */ - private File findAsrModelDir(OnboardModelKind kind) { - boolean whisper = kind == OnboardModelKind.WHISPER; - String dirName = whisper ? ASR_WHISPER_MODEL_DIR : ASR_MODEL_DIR; - String[] fileNames = whisper ? ASR_WHISPER_MODEL_FILES : ASR_MODEL_FILES; - File modelDir = new File(appContext.getFilesDir(), ASR_ROOT + File.separator + dirName); - for (String fileName : fileNames) { - File file = new File(modelDir, fileName); - if (!file.exists() || file.length() == 0) { - return null; - } - } - return modelDir; - } - - private void deleteLegacyKwsFiles() { - try { - deleteRecursively(new File(appContext.getFilesDir(), LEGACY_KWS_ROOT)); - } catch (Throwable t) { - Log.w(TAG, "failed to delete legacy wake-word files", t); - } - } - - private static void deleteRecursively(File file) { - if (!file.exists()) { - return; - } - File[] children = file.listFiles(); - if (children != null) { - for (File child : children) { - deleteRecursively(child); - } - } - file.delete(); - } - - private boolean startG2Audio() { - FaceclawBleCommunicator currentCommunicator = communicator; - if (currentCommunicator == null) { - return false; - } - resetAudioStats(); - synchronized (audioQueueLock) { - audioQueue.clear(); - } - return currentCommunicator.startG2AudioCapture(this::queueAudioPacket); - } - - private void processG2Audio() { - short[] pcm = new short[FaceclawLc3Decoder.SAMPLES_PER_PACKET]; - while (started && !Thread.currentThread().isInterrupted()) { - FaceclawLc3Decoder currentDecoder = lc3Decoder; - if (currentDecoder == null) { - return; - } - - AudioPacket packet = takeAudioPacket(); - if (packet == null) { - continue; - } - - int count = currentDecoder.decodePacket(packet.data, pcm); - if (count <= 0) { - maybeEmitAudioStats(false); - continue; - } - decodedSamples += count; - // Global mic processing from the Microphones app config: the - // beam filter drops packets whose firmware direction-of-arrival - // falls outside the listening wedge (isolating the aimed talker - // for every consumer, recognition included), and the spectral - // noise suppressor cleans what remains before it reaches the - // recognizer, cloud PCM, endpointing, or speaker verification. - int angleDegrees = currentDecoder.getLastAngleDegrees(); - int ssr = currentDecoder.getLastSsr(); - if (beamFilterEnabled && ssr > 0 && !withinBeam(angleDegrees)) { - emitFrameMeta(angleDegrees, ssr); - maybeEmitAudioStats(false); - continue; - } - processPcmChunk(pcm, count, angleDegrees, ssr, true); - maybeEmitAudioStats(false); - } - } - - /** - * Per-chunk processing shared by the G2 and phone-mic paths, downstream of - * decode and the beam filter. hasFrameMeta is false for the phone mic, - * which has no firmware DSP metadata to report. - */ - private void processPcmChunk(short[] pcm, int count, int angleDegrees, int ssr, boolean hasFrameMeta) { - if (suppressionEnabled) { - applySuppression(pcm, count); - } - if (recordingPcm != null) { - appendRecording(pcm, count); - } - if (verifyBuffer != null && verifyCount < VERIFY_MAX_SAMPLES) { - int copied = Math.min(count, VERIFY_MAX_SAMPLES - verifyCount); - System.arraycopy(pcm, 0, verifyBuffer, verifyCount, copied); - verifyCount += copied; - } - if (endpointing && endpointDetector.accept(pcm, count)) { - emitSpeechEnd(); - } - // PCM and frame metadata flow in every mode so levels, recording, - // and the Microphones radar keep working alongside onboard ASR. - emitPcm(pcm, count); - if (hasFrameMeta) { - emitFrameMeta(angleDegrees, ssr); - } - if (mode != VoiceInputMode.CLOUD) { - float[] samples = new float[count]; - for (int i = 0; i < count; i++) { - samples[i] = pcm[i] / 32768.0f; - } - processRecognizer(samples); - } - } - - // 50 ms chunks match the G2 packet cadence the rest of the pipeline - // (endpointing, transcript pacing) is tuned for. - private static final int PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20; - - /** - * Open the phone's own microphone at the pipeline's native format - * (16 kHz mono PCM16), or null when it cannot start — the permission is - * missing (SecurityException) or the device refuses the configuration. - */ - private android.media.AudioRecord openPhoneMic() { - android.media.AudioRecord record = null; - try { - int minBytes = android.media.AudioRecord.getMinBufferSize( - SAMPLE_RATE, - android.media.AudioFormat.CHANNEL_IN_MONO, - android.media.AudioFormat.ENCODING_PCM_16BIT); - int bufferBytes = Math.max(minBytes, PHONE_MIC_CHUNK_SAMPLES * 2 * 4); - record = new android.media.AudioRecord( - android.media.MediaRecorder.AudioSource.VOICE_RECOGNITION, - SAMPLE_RATE, - android.media.AudioFormat.CHANNEL_IN_MONO, - android.media.AudioFormat.ENCODING_PCM_16BIT, - bufferBytes); - if (record.getState() != android.media.AudioRecord.STATE_INITIALIZED) { - record.release(); - return null; - } - record.startRecording(); - if (record.getRecordingState() != android.media.AudioRecord.RECORDSTATE_RECORDING) { - record.release(); - return null; - } - return record; - } catch (Throwable t) { - Log.w(TAG, "phone mic open failed", t); - if (record != null) { - record.release(); - } - return null; - } - } - - /** - * Phone-mic capture loop: no LC3 decode, no arm bookkeeping, no frame - * metadata — AudioRecord already delivers the pipeline's PCM format. The - * blocking read returns every chunk (50 ms), which bounds how long a - * stop() waits for the loop to notice `started` dropped. - */ - private void processPhoneAudio(android.media.AudioRecord record) { - short[] pcm = new short[PHONE_MIC_CHUNK_SAMPLES]; - while (started && !Thread.currentThread().isInterrupted()) { - int read = record.read(pcm, 0, pcm.length); - if (read < 0) { - Log.w(TAG, "phone mic read failed: " + read); - return; - } - if (read == 0) { - continue; - } - decodedSamples += read; - processPcmChunk(pcm, read, 0, 0, false); - } - } - - private void processRecognizer(float[] samples) { - appendTranscriptSamples(samples); - // Each Whisper call re-encodes the whole buffer plus ~10s of tail - // padding (see the ASR_WHISPER_* comment above), - // so it skips the live-partial redecode Moonshine does on this - // interval and only decodes when a segment commits (8s buffer fill) - // or the utterance ends (decodeTranscript(true) in runLoop()). This - // means no live preview text while speaking in Whisper mode -- status - // stays "Listening..." until release. This is a deliberate tradeoff. - if (onboardModelKind == OnboardModelKind.WHISPER) { - return; - } - long now = SystemClock.elapsedRealtime(); - if (transcriptSampleCount >= TRANSCRIPT_MIN_SAMPLES - && now - lastTranscriptDecodeAtMs >= TRANSCRIPT_DECODE_INTERVAL_MS) { - decodeTranscript(false); - lastTranscriptDecodeAtMs = now; - } - } - - private void appendTranscriptSamples(float[] samples) { - int sourceOffset = 0; - while (sourceOffset < samples.length) { - int available = TRANSCRIPT_SEGMENT_MAX_SAMPLES - transcriptSampleCount; - int count = Math.min(available, samples.length - sourceOffset); - System.arraycopy(samples, sourceOffset, transcriptSamples, transcriptSampleCount, count); - transcriptSampleCount += count; - sourceOffset += count; - - if (transcriptSampleCount == TRANSCRIPT_SEGMENT_MAX_SAMPLES) { - commitTranscriptSegment(); - } - } - } - - /** - * Decode the current model-safe segment and emit the best transcript of the - * complete utterance (REPLACE semantics — the caller displays it as-is). - */ - private void decodeTranscript(boolean isFinal) { - if (recognizer == null || transcriptSampleCount <= 0) { - if (isFinal) { - emitTranscript(lastTranscript, true); - } - return; - } - int segmentSampleCount = transcriptSampleCount; - String segmentText = recognizeTranscriptSegment(segmentSampleCount); - if (segmentText.length() > 0) { - currentSegmentTranscript = segmentText; - } else { - segmentText = currentSegmentTranscript; - } - String text = joinTranscript(committedTranscript, segmentText); - lastTranscript = text; - logTranscriptDecode(isFinal, segmentSampleCount, text); - emitTranscript(text, isFinal); - } - - /** - * Finalize a full segment before accepting more audio. This keeps every - * Moonshine invocation below its failing sequence length while retaining - * all earlier text in the replace-semantics preview. - */ - private void commitTranscriptSegment() { - int cut = findSegmentCutPoint(); - String segmentText = recognizeTranscriptSegment(cut); - if (segmentText.length() == 0) { - // Fallback text came from partial decodes of the full buffer, so it - // may include words from the carried-over tail; rare now that decode - // windows are peak-normalized. - segmentText = currentSegmentTranscript; - } - committedTranscript = joinTranscript(committedTranscript, segmentText); - currentSegmentTranscript = ""; - committedTranscriptSampleCount += cut; - int tail = transcriptSampleCount - cut; - System.arraycopy(transcriptSamples, cut, transcriptSamples, 0, tail); - transcriptSampleCount = tail; - lastTranscript = committedTranscript; - lastTranscriptDecodeAtMs = SystemClock.elapsedRealtime(); - logTranscriptDecode(false, cut, committedTranscript); - emitTranscript(committedTranscript, false); - } - - /** - * Pick where to end the committed segment: the center of the quietest - * window within the search region at the end of the buffer, so the cut - * lands between words instead of splitting one. - */ - private int findSegmentCutPoint() { - int count = transcriptSampleCount; - int searchStart = Math.max(0, count - TRANSCRIPT_CUT_SEARCH_SAMPLES); - int win = TRANSCRIPT_CUT_WINDOW_SAMPLES; - if (count - searchStart <= win) { - return count; - } - double sum = 0; - for (int i = searchStart; i < searchStart + win; i++) { - sum += (double) transcriptSamples[i] * transcriptSamples[i]; - } - double best = sum; - int bestStart = searchStart; - for (int start = searchStart + 1; start + win <= count; start++) { - float dropped = transcriptSamples[start - 1]; - float added = transcriptSamples[start + win - 1]; - sum += (double) added * added - (double) dropped * dropped; - if (sum < best) { - best = sum; - bestStart = start; - } - } - return bestStart + win / 2; - } - - private String recognizeTranscriptSegment(int sampleCount) { - OfflineRecognizer currentRecognizer = recognizer; - if (currentRecognizer == null || sampleCount <= 0) { - return ""; - } - float[] segment = Arrays.copyOf(transcriptSamples, sampleCount); - // Whisper hallucinates text on near-silent input (a known quirk of the - // model, not this pipeline); gate it on the PRE-normalization peak, since - // normalizePeak() below would otherwise amplify true silence right up to - // the target level and hide the very thing being checked for. Moonshine - // does not share this failure mode in practice, so it is left unchanged. - if (onboardModelKind == OnboardModelKind.WHISPER && peakAmplitude(segment) < WHISPER_SILENCE_PEAK_THRESHOLD) { - return ""; - } - normalizePeak(segment); - OfflineStream offlineStream = currentRecognizer.createStream(); - try { - offlineStream.acceptWaveform(segment, SAMPLE_RATE); - currentRecognizer.decode(offlineStream); - OfflineRecognizerResult result = currentRecognizer.getResult(offlineStream); - String raw = result == null ? "" : result.getText(); - return raw == null ? "" : raw.trim(); - } finally { - offlineStream.release(); - } - } - - private static float peakAmplitude(float[] samples) { - float peak = 0f; - for (float s : samples) { - float a = Math.abs(s); - if (a > peak) { - peak = a; - } - } - return peak; - } - - private static void normalizePeak(float[] samples) { - float peak = peakAmplitude(samples); - if (peak <= 0f) { - return; - } - float gain = Math.min(TRANSCRIPT_NORMALIZE_TARGET_PEAK / peak, TRANSCRIPT_NORMALIZE_MAX_GAIN); - if (gain <= 1f) { - return; - } - for (int i = 0; i < samples.length; i++) { - samples[i] *= gain; - } - } - - private void logTranscriptDecode(boolean isFinal, int segmentSampleCount, String text) { - double totalAudioSec = - (committedTranscriptSampleCount + transcriptSampleCount) / (double) SAMPLE_RATE; - String preview = text.length() <= TRANSCRIPT_LOG_PREVIEW_CHARS - ? text : text.substring(0, TRANSCRIPT_LOG_PREVIEW_CHARS) + "..."; - Log.i(TAG, (onboardModelKind == OnboardModelKind.WHISPER ? "Whisper" : "Moonshine") + " decode final=" + isFinal - + " audioSec=" + String.format(java.util.Locale.US, "%.2f", totalAudioSec) - + " segmentAudioSec=" + String.format(java.util.Locale.US, "%.2f", segmentSampleCount / (double) SAMPLE_RATE) - + " textLen=" + text.length() + " text=\"" + preview + "\""); - } - - private static String joinTranscript(String prefix, String suffix) { - if (prefix == null || prefix.length() == 0) { - return suffix == null ? "" : suffix; - } - if (suffix == null || suffix.length() == 0) { - return prefix; - } - char first = suffix.charAt(0); - boolean attachesToPrevious = ".,!?;:%)]}".indexOf(first) >= 0; - return prefix + (attachesToPrevious ? "" : " ") + suffix; - } - - private void resetTranscriptState() { - transcriptSampleCount = 0; - committedTranscriptSampleCount = 0; - committedTranscript = ""; - currentSegmentTranscript = ""; - lastTranscriptDecodeAtMs = 0; - } - - private void emitPcm(short[] pcm, int count) { - FaceclawVoiceControllerListener currentListener = listener; - if (currentListener == null || count <= 0) { - return; - } - byte[] le = new byte[count * 2]; - for (int i = 0; i < count; i++) { - short s = pcm[i]; - le[i * 2] = (byte) (s & 0xff); - le[i * 2 + 1] = (byte) ((s >> 8) & 0xff); - } - mainHandler.post(() -> currentListener.onPcm(le)); - } - - /** - * Embed the session's buffered utterance and compare it to the enrolled - * wearer voice-print. Fails open: a session too short to verify, or a - * model that will not load, counts as the wearer rather than silencing - * every command. - */ - private void runSpeakerVerification() { - short[] buffer = verifyBuffer; - float[] wearer = verifyWearerEmbedding; - String modelPath = verifySpeakerModelPath; - verifyBuffer = null; - if (buffer == null || wearer == null || modelPath == null) { - return; - } - if (verifyCount < VERIFY_MIN_SAMPLES) { - emitSpeakerVerified(true, 0f); - return; - } - FaceclawSpeakerId speakerId = cachedSpeakerId(modelPath); - try { - byte[] le = new byte[verifyCount * 2]; - for (int i = 0; i < verifyCount; i++) { - short s = buffer[i]; - le[i * 2] = (byte) (s & 0xff); - le[i * 2 + 1] = (byte) ((s >> 8) & 0xff); - } - float[] embedding = speakerId.embed(le, SAMPLE_RATE); - if (embedding == null || embedding.length != wearer.length) { - emitSpeakerVerified(true, 0f); - return; - } - double dot = 0; - for (int i = 0; i < embedding.length; i++) { - dot += (double) embedding[i] * wearer[i]; - } - boolean isWearer = dot >= verifyThreshold; - Log.i(TAG, "speaker verification similarity=" + String.format(java.util.Locale.US, "%.3f", dot) - + " threshold=" + verifyThreshold + " isWearer=" + isWearer); - emitSpeakerVerified(isWearer, (float) dot); - } catch (Throwable t) { - Log.w(TAG, "speaker verification failed", t); - emitSpeakerVerified(true, 0f); - } - } - - // The 28 MB embedding model takes seconds to load; keep one instance - // across capture sessions so verification adds only the embed time. - private static FaceclawSpeakerId sharedSpeakerId; - private static String sharedSpeakerIdPath; - - private static synchronized FaceclawSpeakerId cachedSpeakerId(String modelPath) { - if (sharedSpeakerId == null || !modelPath.equals(sharedSpeakerIdPath)) { - if (sharedSpeakerId != null) { - sharedSpeakerId.close(); - } - sharedSpeakerId = new FaceclawSpeakerId(modelPath); - sharedSpeakerIdPath = modelPath; - } - return sharedSpeakerId; - } - - private void emitSpeakerVerified(boolean isWearer, float similarity) { - FaceclawVoiceControllerListener currentListener = listener; - if (currentListener == null) { - return; - } - mainHandler.post(() -> currentListener.onSpeakerVerified(isWearer, similarity)); - } - - private void emitFrameMeta(int angleDegrees, int ssr) { - FaceclawVoiceControllerListener currentListener = listener; - if (currentListener == null) { - return; - } - mainHandler.post(() -> currentListener.onFrameMeta(angleDegrees, ssr)); - } - - private void emitSpeechEnd() { - FaceclawVoiceControllerListener currentListener = listener; - if (currentListener == null) { - return; - } - mainHandler.post(currentListener::onSpeechEnd); - } - - private void emitStopped(int captureId) { - FaceclawVoiceControllerListener currentListener = listener; - if (currentListener != null) { - mainHandler.post(() -> currentListener.onStopped(captureId)); - } - } - - private void stopG2Audio() { - FaceclawBleCommunicator currentCommunicator = communicator; - if (currentCommunicator != null) { - currentCommunicator.stopG2AudioCapture(); - } - maybeEmitAudioStats(true); - } - - private void releaseSherpa() { - if (recognizer != null) { - recognizer.release(); - recognizer = null; - } - } - - private void releaseLc3() { - if (lc3Decoder != null) { - lc3Decoder.close(); - lc3Decoder = null; - } - } - - private void queueAudioPacket(byte[] data, String arm, long arrivalMs) { - if (!started || data == null) { - return; - } - if (!"L".equals(arm)) { - wrongArmPackets++; - } - synchronized (audioQueueLock) { - if (audioQueue.size() >= MAX_AUDIO_QUEUE_PACKETS) { - audioQueue.removeFirst(); - queueDroppedPackets++; - } - audioQueue.addLast(new AudioPacket(data, arm, arrivalMs)); - queuedPackets++; - if (lastPacketArrivalMs > 0) { - long delta = arrivalMs - lastPacketArrivalMs; - if (delta > maxInterPacketMs) { - maxInterPacketMs = delta; - } - if (delta > LATE_PACKET_INTERVAL_MS) { - latePackets++; - } - } - lastPacketArrivalMs = arrivalMs; - audioQueueLock.notifyAll(); - } - } - - private AudioPacket takeAudioPacket() { - synchronized (audioQueueLock) { - while (started && audioQueue.isEmpty()) { - try { - audioQueueLock.wait(250); - maybeEmitAudioStats(false); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return null; - } - } - return audioQueue.pollFirst(); - } - } - - private void resetAudioStats() { - queuedPackets = 0; - queueDroppedPackets = 0; - decodedSamples = 0; - latePackets = 0; - wrongArmPackets = 0; - lastPacketArrivalMs = 0; - maxInterPacketMs = 0; - lastStatsAtMs = SystemClock.elapsedRealtime(); - } - - private void maybeEmitAudioStats(boolean force) { - long now = SystemClock.elapsedRealtime(); - if (!force && now - lastStatsAtMs < STATS_INTERVAL_MS) { - return; - } - lastStatsAtMs = now; - FaceclawLc3Decoder currentDecoder = lc3Decoder; - long real = currentDecoder == null ? 0 : currentDecoder.getRealPackets(); - long duplicate = currentDecoder == null ? 0 : currentDecoder.getDuplicatePackets(); - long missing = currentDecoder == null ? 0 : currentDecoder.getMissingPackets(); - long decodeErrors = currentDecoder == null ? 0 : currentDecoder.getDecodeErrors(); - String status = "G2 mic packets=" + queuedPackets - + " decoded=" + real - + " missing=" + missing - + " duplicate=" + duplicate - + " late=" + latePackets - + " maxGapMs=" + maxInterPacketMs - + "\n" - + " queueDrop=" + queueDroppedPackets - + " decodeErrors=" + decodeErrors - + " wrongArm=" + wrongArmPackets - + " audioSec=" + String.format(java.util.Locale.US, "%.1f", decodedSamples / (double) SAMPLE_RATE); - // Audio-pipeline stats are diagnostic; keep them in logcat only, out of - // the on-glasses voice UI. - Log.i(TAG, status.replace('\n', ' ') + " expectedIntervalMs=" + EXPECTED_PACKET_INTERVAL_MS); - } - - private void emitStatus(String status) { - FaceclawVoiceControllerListener currentListener = listener; - if (currentListener == null) { - return; - } - mainHandler.post(() -> currentListener.onStatus(status)); - } - - private void emitTranscript(String text, boolean isFinal) { - FaceclawVoiceControllerListener currentListener = listener; - if (currentListener == null) { - return; - } - Log.i(TAG, "Emit transcript final=" + isFinal + " textLen=" + (text == null ? 0 : text.trim().length())); - mainHandler.post(() -> currentListener.onTranscript(text, isFinal)); - } - - private static final class AudioPacket { - final byte[] data; - final String arm; - final long arrivalMs; - - AudioPacket(byte[] data, String arm, long arrivalMs) { - this.data = data; - this.arm = arm == null ? "?" : arm; - this.arrivalMs = arrivalMs; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt new file mode 100644 index 00000000..0e59e435 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt @@ -0,0 +1,1186 @@ +package com.faceclaw.app + +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.util.Log + +import com.k2fsa.sherpa.onnx.FeatureConfig +import com.k2fsa.sherpa.onnx.OfflineModelConfig +import com.k2fsa.sherpa.onnx.OfflineMoonshineModelConfig +import com.k2fsa.sherpa.onnx.OfflineRecognizer +import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig +import com.k2fsa.sherpa.onnx.OfflineRecognizerResult +import com.k2fsa.sherpa.onnx.OfflineStream +import com.k2fsa.sherpa.onnx.OfflineWhisperModelConfig + +import java.io.File +import java.nio.charset.StandardCharsets +import java.util.ArrayDeque +import java.util.Arrays + +class FaceclawVoiceController(context: Context) { + companion object { + private const val TAG = "FaceclawVoice" + private const val SAMPLE_RATE = 16000 + private const val FEATURE_DIM = 80 + private const val MAX_AUDIO_QUEUE_PACKETS = 80 + private const val EXPECTED_PACKET_INTERVAL_MS = 50 + private const val LATE_PACKET_INTERVAL_MS = 90 + private const val STATS_INTERVAL_MS = 5_000 + // Push-to-talk utterance boundaries come from the button. We re-decode the + // current audio segment in full for each live partial and emit the complete + // utterance text (REPLACE, never a delta). The sherpa Moonshine v2 decoder + // used here fails once a single input grows past roughly 9.1 seconds, so + // longer utterances are committed in model-safe segments. + private const val TRANSCRIPT_DECODE_INTERVAL_MS = 700 + private const val TRANSCRIPT_MIN_SAMPLES = SAMPLE_RATE / 3 + private const val TRANSCRIPT_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8 + // When a segment fills, cut at the quietest window within the last + // TRANSCRIPT_CUT_SEARCH_SAMPLES rather than mid-word at the 8s mark; the + // audio after the cut carries over into the next segment. + private const val TRANSCRIPT_CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2 + private const val TRANSCRIPT_CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000 + // Glasses-mic PCM peaks around 0.1 full scale, and at that level the + // quantized Moonshine model often returns empty or garbled text. Boost + // each decode window toward this peak, with a gain cap so near-silent + // buffers aren't amplified into pure noise. + private const val TRANSCRIPT_NORMALIZE_TARGET_PEAK = 0.9f + private const val TRANSCRIPT_NORMALIZE_MAX_GAIN = 30f + private const val TRANSCRIPT_LOG_PREVIEW_CHARS = 80 + // Model directory shared with the TS-side download flow (asr-model.ts), + // which fetches the Moonshine files here on demand; they are no longer + // bundled in the APK. + private const val ASR_ROOT = "faceclaw-voice-asr" + private const val ASR_MODEL_DIR = "sherpa-onnx-moonshine-base-en-quantized-2026-02-27" + // Model files for the retired on-phone wake-word spotter, copied to + // filesDir by earlier releases; deleted on sight to reclaim the space. + // (The wakeword is now detected by the glasses firmware itself.) + private const val LEGACY_KWS_ROOT = "faceclaw-voice" + private val ASR_MODEL_FILES = arrayOf( + "encoder_model.ort", + "decoder_model_merged.ort", + "tokens.txt" + ) + // Second on-device model: sherpa-onnx's offline Whisper backend (base.en, + // int8-quantized -- see the model-choice note in asr-model.ts). Directory + // shared with the TS-side download flow, same convention as ASR_MODEL_DIR. + // + // On every call, sherpa-onnx (offline-recognizer-whisper-impl.h, v1.13.0) + // runs Whisper's encoder over the whole buffer plus 1000 frames (~10s) of + // zero tail padding, capped at 30s. Re-decoding on Moonshine's + // TRANSCRIPT_DECODE_INTERVAL_MS live-partial cadence would repeat that + // encode, growing with the utterance, roughly 1.4x/second while the user is + // still speaking, so onboardModelKind gates that loop off for Whisper -- + // see processRecognizer(). Whisper is also known to hallucinate text on + // near-silent input; recognizeTranscriptSegment() gates that too. + private const val ASR_WHISPER_MODEL_DIR = "sherpa-onnx-whisper-base-en-int8" + private val ASR_WHISPER_MODEL_FILES = arrayOf( + "base.en-encoder.int8.onnx", + "base.en-decoder.int8.onnx", + "base.en-tokens.txt" + ) + // Below this peak amplitude (pre-normalization, of a full-scale +/-1.0f + // buffer) a segment is treated as silence and never reaches the Whisper + // recognizer at all, rather than risking a hallucinated non-answer. Picked + // conservatively low (well under typical mic noise floor already seen in + // this pipeline's normalization target) -- UNTESTED on real hardware, tune + // against real glasses captures rather than trusting this number. + private const val WHISPER_SILENCE_PEAK_THRESHOLD = 0.01f + + // Speaker verification against the enrolled wearer voice-print ("my voice + // only" command gating). Configured before start(); the utterance PCM is + // buffered (capped) and verified once at session end. + private const val VERIFY_MAX_SAMPLES = SAMPLE_RATE * 10 + private const val VERIFY_MIN_SAMPLES = SAMPLE_RATE + + // 50 ms chunks match the G2 packet cadence the rest of the pipeline + // (endpointing, transcript pacing) is tuned for. + private const val PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20 + + @JvmStatic + private fun buildWavHeader(pcmBytes: Int, sampleRate: Int, channels: Int, bitsPerSample: Int): ByteArray { + val byteRate = sampleRate * channels * bitsPerSample / 8 + val blockAlign = channels * bitsPerSample / 8 + val dataSize = pcmBytes + val riffSize = 36 + dataSize + val b = java.nio.ByteBuffer.allocate(44).order(java.nio.ByteOrder.LITTLE_ENDIAN) + b.put("RIFF".toByteArray(StandardCharsets.US_ASCII)) + b.putInt(riffSize) + b.put("WAVE".toByteArray(StandardCharsets.US_ASCII)) + b.put("fmt ".toByteArray(StandardCharsets.US_ASCII)) + b.putInt(16) // PCM fmt chunk size + b.putShort(1.toShort()) // PCM + b.putShort(channels.toShort()) + b.putInt(sampleRate) + b.putInt(byteRate) + b.putShort(blockAlign.toShort()) + b.putShort(bitsPerSample.toShort()) + b.put("data".toByteArray(StandardCharsets.US_ASCII)) + b.putInt(dataSize) + return b.array() + } + + @JvmStatic + private fun deleteRecursively(file: File) { + if (!file.exists()) { + return + } + val children = file.listFiles() + if (children != null) { + for (child in children) { + deleteRecursively(child) + } + } + file.delete() + } + + @JvmStatic + private fun peakAmplitude(samples: FloatArray): Float { + var peak = 0f + for (s in samples) { + val a = Math.abs(s) + if (a > peak) { + peak = a + } + } + return peak + } + + @JvmStatic + private fun normalizePeak(samples: FloatArray) { + val peak = peakAmplitude(samples) + if (peak <= 0f) { + return + } + val gain = Math.min(TRANSCRIPT_NORMALIZE_TARGET_PEAK / peak, TRANSCRIPT_NORMALIZE_MAX_GAIN) + if (gain <= 1f) { + return + } + for (i in samples.indices) { + samples[i] *= gain + } + } + + @JvmStatic + private fun joinTranscript(prefix: String?, suffix: String?): String { + if (prefix == null || prefix.length == 0) { + return suffix ?: "" + } + if (suffix == null || suffix.length == 0) { + return prefix + } + val first = suffix[0] + val attachesToPrevious = ".,!?;:%)]}".indexOf(first) >= 0 + return prefix + (if (attachesToPrevious) "" else " ") + suffix + } + + // The 28 MB embedding model takes seconds to load; keep one instance + // across capture sessions so verification adds only the embed time. + private var sharedSpeakerId: FaceclawSpeakerId? = null + private var sharedSpeakerIdPath: String? = null + + @JvmStatic + @Synchronized + private fun cachedSpeakerId(modelPath: String): FaceclawSpeakerId { + if (sharedSpeakerId == null || modelPath != sharedSpeakerIdPath) { + if (sharedSpeakerId != null) { + sharedSpeakerId!!.close() + } + sharedSpeakerId = FaceclawSpeakerId(modelPath) + sharedSpeakerIdPath = modelPath + } + return sharedSpeakerId!! + } + } + + private enum class VoiceInputMode { + ONBOARD, // on-phone transcription (Moonshine or Whisper; see onboardModelKind) + CLOUD // decode locally, emit PCM for a cloud recognizer on the TS side + } + + /** Which on-device model ONBOARD mode uses. Set via setOnboardModelKind() before start(). */ + private enum class OnboardModelKind { + MOONSHINE, + WHISPER + } + + private val appContext: Context = context.applicationContext + private val mainHandler = Handler(Looper.getMainLooper()) + private val lock = Any() + private val audioQueueLock = Any() + private val audioQueue = ArrayDeque() + @Volatile + private var listener: FaceclawVoiceControllerListener? = null + @Volatile + private var communicator: FaceclawBleCommunicator? = null + private var workerThread: Thread? = null + @Volatile + private var started = false + // Set once the worker has the glasses mic enabled for this session. + // Read and written under `lock`, so it flips with `started` atomically. + private var audioStarted = false + // Capture from the phone's own microphone instead of the G2 over BLE + // (preview-only mode, where no glasses are connected). Latched into + // activePhoneMic at start() (under `lock`) so a mid-session setter call + // can't switch pipelines underneath the worker. + @Volatile + private var usePhoneMic = false + private var activePhoneMic = false + private var mode = VoiceInputMode.CLOUD + @Volatile + private var onboardModelKind = OnboardModelKind.MOONSHINE + private var recognizer: OfflineRecognizer? = null + private var lc3Decoder: FaceclawLc3Decoder? = null + private val transcriptSamples = FloatArray(TRANSCRIPT_SEGMENT_MAX_SAMPLES) + private var transcriptSampleCount = 0 + private var committedTranscriptSampleCount: Long = 0 + private var committedTranscript = "" + private var currentSegmentTranscript = "" + private var lastTranscriptDecodeAtMs: Long = 0 + private var lastTranscript = "" + @Volatile + private var saveRecordings = false + @Volatile + private var endpointing = false + private val endpointDetector = VoiceEndpointDetector() + private var recordingPcm: java.io.ByteArrayOutputStream? = null + // Speaker verification against the enrolled wearer voice-print ("my voice + // only" command gating). Configured before start(); the utterance PCM is + // buffered (capped) and verified once at session end. + @Volatile + private var verifySpeakerModelPath: String? = null + @Volatile + private var verifyWearerEmbedding: FloatArray? = null + @Volatile + private var verifyThreshold = 0.8f + private var verifyBuffer: ShortArray? = null + private var verifyCount = 0 + // Global mic processing (Microphones app config): spectral noise + // suppression and firmware-DoA beam gating, applied to every capture + // session that opts in (assistant push-to-talk, Transcribe, hands-free). + // The raw tap opts out — raw means raw, and the Microphones session does + // its own beam-compensated processing on that path. + @Volatile + private var suppressionEnabled = false + @Volatile + private var beamFilterEnabled = false + @Volatile + private var beamCenterDeg = 0 + @Volatile + private var beamHalfWidthDeg = 180 + private var suppressor: FaceclawNoiseSuppressor? = null + private var queuedPackets: Long = 0 + private var queueDroppedPackets: Long = 0 + private var decodedSamples: Long = 0 + private var latePackets: Long = 0 + private var wrongArmPackets: Long = 0 + private var lastPacketArrivalMs: Long = 0 + private var maxInterPacketMs: Long = 0 + private var lastStatsAtMs: Long = 0 + + fun setListener(listener: FaceclawVoiceControllerListener?) { + this.listener = listener + } + + fun setCommunicator(communicator: FaceclawBleCommunicator?) { + this.communicator = communicator + } + + /** Source the next capture from the phone microphone (no glasses paired). */ + fun setUsePhoneMic(usePhoneMic: Boolean) { + this.usePhoneMic = usePhoneMic + } + + /** When true, the decoded mic PCM for each session is saved as a WAV. */ + fun setSaveRecordings(saveRecordings: Boolean) { + this.saveRecordings = saveRecordings + } + + /** + * Which on-device model {@link #start}("onboard") should load: "whisper" + * selects the second on-device model (sherpa-onnx offline Whisper); any + * other value (including null/absent) keeps the existing Moonshine model, + * so callers that never call this see unchanged behavior. Must be set + * before {@link #start}; has no effect in CLOUD mode. + */ + fun setOnboardModelKind(kind: String?) { + this.onboardModelKind = if ("whisper" == kind) OnboardModelKind.WHISPER else OnboardModelKind.MOONSHINE + } + + /** + * When true, watch the decoded PCM and fire {@code onSpeechEnd} once the + * speaker stops. Used by hands-free ("Hey Even") capture, which has no + * button release to end the utterance. Must be set before {@link #start}. + */ + fun setEndpointing(endpointing: Boolean) { + this.endpointing = endpointing + } + + /** + * Verify this session's speaker against the enrolled wearer voice-print + * and report the result via onSpeakerVerified just before the final + * transcript. Must be set before {@link #start}; pass a null model path + * to disable. + */ + fun setSpeakerVerification(speakerModelPath: String?, wearerEmbedding: FloatArray?, threshold: Float) { + this.verifySpeakerModelPath = speakerModelPath + this.verifyWearerEmbedding = wearerEmbedding + this.verifyThreshold = if (threshold > 0) threshold else 0.8f + } + + fun clearSpeakerVerification() { + this.verifySpeakerModelPath = null + this.verifyWearerEmbedding = null + } + + /** Spectral noise suppression on the decoded stream. Safe to flip mid-run. */ + fun setNoiseSuppression(enabled: Boolean) { + this.suppressionEnabled = enabled + } + + /** + * Direction gating from the Sonic Radar beam: packets whose firmware + * direction-of-arrival falls outside centerDeg ± halfWidthDeg (device + * frame, 0 = straight ahead, positive right) are dropped before any + * consumer sees them. Safe to update mid-run. + */ + fun setBeamFilter(enabled: Boolean, centerDeg: Int, halfWidthDeg: Int) { + this.beamFilterEnabled = enabled + this.beamCenterDeg = centerDeg + this.beamHalfWidthDeg = Math.max(5, Math.min(180, halfWidthDeg)) + } + + private fun withinBeam(angleDegrees: Int): Boolean { + var delta = angleDegrees - beamCenterDeg + while (delta > 180) delta -= 360 + while (delta < -180) delta += 360 + return Math.abs(delta) <= beamHalfWidthDeg + } + + private fun applySuppression(pcm: ShortArray, count: Int) { + try { + if (suppressor == null) { + suppressor = FaceclawNoiseSuppressor(SAMPLE_RATE) + } + val le = ByteArray(count * 2) + for (i in 0 until count) { + le[i * 2] = (pcm[i].toInt() and 0xff).toByte() + le[i * 2 + 1] = ((pcm[i].toInt() shr 8) and 0xff).toByte() + } + val cleaned = suppressor!!.process(le)!! + val cleanedCount = Math.min(count, cleaned.size / 2) + for (i in 0 until cleanedCount) { + pcm[i] = ((cleaned[i * 2].toInt() and 0xff) or (cleaned[i * 2 + 1].toInt() shl 8)).toShort() + } + } catch (t: Throwable) { + Log.w(TAG, "noise suppression failed; passing audio through", t) + suppressionEnabled = false + } + } + + fun start(requestedMode: String?) { + start(requestedMode, 0) + } + + fun start(requestedMode: String?, captureId: Int) { + synchronized(lock) { + if (started) { + emitStatus("Voice control is already listening.") + emitStopped(captureId) + return + } + if (!usePhoneMic && (communicator == null || !communicator!!.isSessionReady())) { + emitStatus("Voice control needs an active G2 connection.") + emitStopped(captureId) + return + } + mode = parseMode(requestedMode) + activePhoneMic = usePhoneMic + started = true + audioStarted = false + workerThread = Thread(Runnable { runLoop(captureId) }, "FaceclawVoiceController") + workerThread!!.start() + } + } + + /** + * Whether mic audio is actually flowing. {@link #start} only records + * intent: the enable lives in the glasses' EvenHub session, so a transport + * drop or a session suspend can leave this controller started with a + * worker that will never see another packet. Anything deciding whether to + * (re)start capture must ask this rather than assume its own bookkeeping. + */ + fun isCapturing(): Boolean { + val audioUp: Boolean + val phoneMic: Boolean + synchronized(lock) { + if (!started) { + return false + } + audioUp = audioStarted + phoneMic = activePhoneMic + } + if (!audioUp) { + // The worker is still bringing the mic up; report it as running so + // a concurrent request shares it instead of restarting it. + return true + } + if (phoneMic) { + // AudioRecord has no session to lose the enable to; it runs until stop(). + return true + } + val currentCommunicator = communicator + return currentCommunicator != null && currentCommunicator.isAudioCaptureActive() + } + + fun stop() { + val threadToJoin: Thread? + synchronized(lock) { + if (!started) { + return + } + started = false + threadToJoin = workerThread + } + stopG2Audio() + synchronized(audioQueueLock) { + (audioQueueLock as java.lang.Object).notifyAll() + } + if (threadToJoin != null) { + threadToJoin.interrupt() + if (Thread.currentThread() !== threadToJoin) { + try { + threadToJoin.join(1500) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + } + } + } + } + + fun close() { + stop() + } + + private fun parseMode(requestedMode: String?): VoiceInputMode { + if ("cloud" == requestedMode) { + return VoiceInputMode.CLOUD + } + return VoiceInputMode.ONBOARD + } + + private fun runLoop(captureId: Int) { + try { + deleteLegacyKwsFiles() + val currentMode = mode + val currentOnboardKind = onboardModelKind + if (currentMode == VoiceInputMode.ONBOARD) { + val modelDir = findAsrModelDir(currentOnboardKind) + if (modelDir == null) { + emitStatus("Voice model not downloaded (see Settings > Voice).") + return + } + emitStatus("Loading transcription model...") + recognizer = OfflineRecognizer(buildRecognizerConfig(modelDir, currentOnboardKind)) + resetTranscriptState() + lastTranscript = "" + } + endpointDetector.reset() + if (suppressor != null) { + suppressor!!.reset() + } + recordingPcm = if (saveRecordings) java.io.ByteArrayOutputStream(SAMPLE_RATE * 2 * 4) else null + val verifying = verifySpeakerModelPath != null && verifyWearerEmbedding != null + verifyBuffer = if (verifying) ShortArray(VERIFY_MAX_SAMPLES) else null + verifyCount = 0 + if (activePhoneMic) { + val record = openPhoneMic() + if (record == null) { + emitStatus("Could not start the phone microphone.") + return + } + synchronized(lock) { + audioStarted = true + } + emitStatus(if (currentMode == VoiceInputMode.CLOUD) + "Listening (cloud)..." + else + "Listening...") + try { + processPhoneAudio(record) + } finally { + try { + record.stop() + } catch (ignored: Throwable) { + // Already stopped or never recording; release below either way. + } + record.release() + } + } else { + lc3Decoder = FaceclawLc3Decoder() + if (!startG2Audio()) { + emitStatus("Could not start G2 microphone input.") + return + } + synchronized(lock) { + audioStarted = true + } + emitStatus(if (currentMode == VoiceInputMode.CLOUD) + "Listening (cloud)..." + else + "Listening...") + processG2Audio() + } + // Verification result must precede the final transcript so the + // TS bridge can suppress a non-wearer command before it is acted + // on (the callbacks are posted in order to the main handler). + runSpeakerVerification() + // Button released / stop requested: emit one final full-utterance + // transcript so the UI can freeze it. + if (currentMode == VoiceInputMode.ONBOARD) { + decodeTranscript(true) + } + } catch (error: Throwable) { + Log.e(TAG, "Voice control failed", error) + emitStatus("Voice control failed: " + error.message) + } finally { + stopG2Audio() + writeRecordingIfAny() + releaseSherpa() + releaseLc3() + synchronized(lock) { + started = false + audioStarted = false + workerThread = null + } + emitStopped(captureId) + } + } + + private fun appendRecording(pcm: ShortArray, count: Int) { + val out = recordingPcm + if (out == null) { + return + } + for (i in 0 until count) { + val s = pcm[i].toInt() + out.write(s and 0xff) + out.write((s shr 8) and 0xff) + } + } + + /** Save the session's decoded mic PCM as a 16 kHz mono 16-bit WAV. */ + private fun writeRecordingIfAny() { + val out = recordingPcm + recordingPcm = null + if (out == null || out.size() == 0) { + return + } + try { + val pcmBytes = out.toByteArray() + val dir = java.io.File(appContext.getExternalFilesDir(null), "voice-recordings") + if (!dir.exists() && !dir.mkdirs()) { + Log.w(TAG, "could not create voice-recordings dir") + return + } + val stamp = java.text.SimpleDateFormat("yyyyMMdd-HHmmss-SSS", java.util.Locale.US) + .format(java.util.Date()) + val file = java.io.File(dir, "voice-$stamp.wav") + java.io.FileOutputStream(file).use { fos -> + fos.write(buildWavHeader(pcmBytes.size, SAMPLE_RATE, 1, 16)) + fos.write(pcmBytes) + } + Log.i(TAG, "saved voice recording " + file.absolutePath + + " samples=" + (pcmBytes.size / 2) + + " sec=" + String.format(java.util.Locale.US, "%.2f", pcmBytes.size / 2.0 / SAMPLE_RATE)) + } catch (t: Throwable) { + Log.w(TAG, "failed to save voice recording", t) + } + } + + private fun buildRecognizerConfig(modelDir: File, kind: OnboardModelKind): OfflineRecognizerConfig { + val modelConfig = OfflineModelConfig.builder() + .setNumThreads(1) + if (kind == OnboardModelKind.WHISPER) { + modelConfig + .setWhisper(OfflineWhisperModelConfig.builder() + .setEncoder(File(modelDir, "base.en-encoder.int8.onnx").absolutePath) + .setDecoder(File(modelDir, "base.en-decoder.int8.onnx").absolutePath) + .setLanguage("en") + .setTask("transcribe") + .build()) + .setTokens(File(modelDir, "base.en-tokens.txt").absolutePath) + } else { + modelConfig + .setMoonshine(OfflineMoonshineModelConfig.builder() + .setEncoder(File(modelDir, "encoder_model.ort").absolutePath) + .setMergedDecoder(File(modelDir, "decoder_model_merged.ort").absolutePath) + .build()) + .setTokens(File(modelDir, "tokens.txt").absolutePath) + } + return OfflineRecognizerConfig.builder() + .setFeatureConfig(FeatureConfig.builder() + .setSampleRate(SAMPLE_RATE) + .setFeatureDim(FEATURE_DIM) + .build()) + .setModelConfig(modelConfig.build()) + .build() + } + + /** + * The on-device model directory for the given kind, populated by the + * download flow in asr-model.ts (releases before 0.5.0 copied the + * Moonshine files out of the APK directly, so upgraded installs are + * already complete for that model). Null when any expected file is + * missing, i.e. the model still needs to be downloaded. + */ + private fun findAsrModelDir(kind: OnboardModelKind): File? { + val whisper = kind == OnboardModelKind.WHISPER + val dirName = if (whisper) ASR_WHISPER_MODEL_DIR else ASR_MODEL_DIR + val fileNames = if (whisper) ASR_WHISPER_MODEL_FILES else ASR_MODEL_FILES + val modelDir = File(appContext.filesDir, ASR_ROOT + File.separator + dirName) + for (fileName in fileNames) { + val file = File(modelDir, fileName) + if (!file.exists() || file.length() == 0L) { + return null + } + } + return modelDir + } + + private fun deleteLegacyKwsFiles() { + try { + deleteRecursively(File(appContext.filesDir, LEGACY_KWS_ROOT)) + } catch (t: Throwable) { + Log.w(TAG, "failed to delete legacy wake-word files", t) + } + } + + private fun startG2Audio(): Boolean { + val currentCommunicator = communicator + if (currentCommunicator == null) { + return false + } + resetAudioStats() + synchronized(audioQueueLock) { + audioQueue.clear() + } + return currentCommunicator.startG2AudioCapture(object : FaceclawAudioPacketListener { + override fun onAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { + queueAudioPacket(data, arm, arrivalMs) + } + }) + } + + private fun processG2Audio() { + val pcm = ShortArray(FaceclawLc3Decoder.SAMPLES_PER_PACKET) + while (started && !Thread.currentThread().isInterrupted) { + val currentDecoder = lc3Decoder + if (currentDecoder == null) { + return + } + + val packet = takeAudioPacket() + if (packet == null) { + continue + } + + val count = currentDecoder.decodePacket(packet.data, pcm) + if (count <= 0) { + maybeEmitAudioStats(false) + continue + } + decodedSamples += count.toLong() + // Global mic processing from the Microphones app config: the + // beam filter drops packets whose firmware direction-of-arrival + // falls outside the listening wedge (isolating the aimed talker + // for every consumer, recognition included), and the spectral + // noise suppressor cleans what remains before it reaches the + // recognizer, cloud PCM, endpointing, or speaker verification. + val angleDegrees = currentDecoder.getLastAngleDegrees() + val ssr = currentDecoder.getLastSsr() + if (beamFilterEnabled && ssr > 0 && !withinBeam(angleDegrees)) { + emitFrameMeta(angleDegrees, ssr) + maybeEmitAudioStats(false) + continue + } + processPcmChunk(pcm, count, angleDegrees, ssr, true) + maybeEmitAudioStats(false) + } + } + + /** + * Per-chunk processing shared by the G2 and phone-mic paths, downstream of + * decode and the beam filter. hasFrameMeta is false for the phone mic, + * which has no firmware DSP metadata to report. + */ + private fun processPcmChunk(pcm: ShortArray, count: Int, angleDegrees: Int, ssr: Int, hasFrameMeta: Boolean) { + if (suppressionEnabled) { + applySuppression(pcm, count) + } + if (recordingPcm != null) { + appendRecording(pcm, count) + } + val verifyBuffer = this.verifyBuffer + if (verifyBuffer != null && verifyCount < VERIFY_MAX_SAMPLES) { + val copied = Math.min(count, VERIFY_MAX_SAMPLES - verifyCount) + System.arraycopy(pcm, 0, verifyBuffer, verifyCount, copied) + verifyCount += copied + } + if (endpointing && endpointDetector.accept(pcm, count)) { + emitSpeechEnd() + } + // PCM and frame metadata flow in every mode so levels, recording, + // and the Microphones radar keep working alongside onboard ASR. + emitPcm(pcm, count) + if (hasFrameMeta) { + emitFrameMeta(angleDegrees, ssr) + } + if (mode != VoiceInputMode.CLOUD) { + val samples = FloatArray(count) + for (i in 0 until count) { + samples[i] = pcm[i] / 32768.0f + } + processRecognizer(samples) + } + } + + /** + * Open the phone's own microphone at the pipeline's native format + * (16 kHz mono PCM16), or null when it cannot start — the permission is + * missing (SecurityException) or the device refuses the configuration. + */ + private fun openPhoneMic(): android.media.AudioRecord? { + var record: android.media.AudioRecord? = null + try { + val minBytes = android.media.AudioRecord.getMinBufferSize( + SAMPLE_RATE, + android.media.AudioFormat.CHANNEL_IN_MONO, + android.media.AudioFormat.ENCODING_PCM_16BIT) + val bufferBytes = Math.max(minBytes, PHONE_MIC_CHUNK_SAMPLES * 2 * 4) + record = android.media.AudioRecord( + android.media.MediaRecorder.AudioSource.VOICE_RECOGNITION, + SAMPLE_RATE, + android.media.AudioFormat.CHANNEL_IN_MONO, + android.media.AudioFormat.ENCODING_PCM_16BIT, + bufferBytes) + if (record.state != android.media.AudioRecord.STATE_INITIALIZED) { + record.release() + return null + } + record.startRecording() + if (record.recordingState != android.media.AudioRecord.RECORDSTATE_RECORDING) { + record.release() + return null + } + return record + } catch (t: Throwable) { + Log.w(TAG, "phone mic open failed", t) + if (record != null) { + record.release() + } + return null + } + } + + /** + * Phone-mic capture loop: no LC3 decode, no arm bookkeeping, no frame + * metadata — AudioRecord already delivers the pipeline's PCM format. The + * blocking read returns every chunk (50 ms), which bounds how long a + * stop() waits for the loop to notice `started` dropped. + */ + private fun processPhoneAudio(record: android.media.AudioRecord) { + val pcm = ShortArray(PHONE_MIC_CHUNK_SAMPLES) + while (started && !Thread.currentThread().isInterrupted) { + val read = record.read(pcm, 0, pcm.size) + if (read < 0) { + Log.w(TAG, "phone mic read failed: $read") + return + } + if (read == 0) { + continue + } + decodedSamples += read.toLong() + processPcmChunk(pcm, read, 0, 0, false) + } + } + + private fun processRecognizer(samples: FloatArray) { + appendTranscriptSamples(samples) + // Each Whisper call re-encodes the whole buffer plus ~10s of tail + // padding (see the ASR_WHISPER_* comment above), + // so it skips the live-partial redecode Moonshine does on this + // interval and only decodes when a segment commits (8s buffer fill) + // or the utterance ends (decodeTranscript(true) in runLoop()). This + // means no live preview text while speaking in Whisper mode -- status + // stays "Listening..." until release. This is a deliberate tradeoff. + if (onboardModelKind == OnboardModelKind.WHISPER) { + return + } + val now = SystemClock.elapsedRealtime() + if (transcriptSampleCount >= TRANSCRIPT_MIN_SAMPLES + && now - lastTranscriptDecodeAtMs >= TRANSCRIPT_DECODE_INTERVAL_MS) { + decodeTranscript(false) + lastTranscriptDecodeAtMs = now + } + } + + private fun appendTranscriptSamples(samples: FloatArray) { + var sourceOffset = 0 + while (sourceOffset < samples.size) { + val available = TRANSCRIPT_SEGMENT_MAX_SAMPLES - transcriptSampleCount + val count = Math.min(available, samples.size - sourceOffset) + System.arraycopy(samples, sourceOffset, transcriptSamples, transcriptSampleCount, count) + transcriptSampleCount += count + sourceOffset += count + + if (transcriptSampleCount == TRANSCRIPT_SEGMENT_MAX_SAMPLES) { + commitTranscriptSegment() + } + } + } + + /** + * Decode the current model-safe segment and emit the best transcript of the + * complete utterance (REPLACE semantics — the caller displays it as-is). + */ + private fun decodeTranscript(isFinal: Boolean) { + if (recognizer == null || transcriptSampleCount <= 0) { + if (isFinal) { + emitTranscript(lastTranscript, true) + } + return + } + val segmentSampleCount = transcriptSampleCount + var segmentText = recognizeTranscriptSegment(segmentSampleCount) + if (segmentText.length > 0) { + currentSegmentTranscript = segmentText + } else { + segmentText = currentSegmentTranscript + } + val text = joinTranscript(committedTranscript, segmentText) + lastTranscript = text + logTranscriptDecode(isFinal, segmentSampleCount, text) + emitTranscript(text, isFinal) + } + + /** + * Finalize a full segment before accepting more audio. This keeps every + * Moonshine invocation below its failing sequence length while retaining + * all earlier text in the replace-semantics preview. + */ + private fun commitTranscriptSegment() { + val cut = findSegmentCutPoint() + var segmentText = recognizeTranscriptSegment(cut) + if (segmentText.length == 0) { + // Fallback text came from partial decodes of the full buffer, so it + // may include words from the carried-over tail; rare now that decode + // windows are peak-normalized. + segmentText = currentSegmentTranscript + } + committedTranscript = joinTranscript(committedTranscript, segmentText) + currentSegmentTranscript = "" + committedTranscriptSampleCount += cut.toLong() + val tail = transcriptSampleCount - cut + System.arraycopy(transcriptSamples, cut, transcriptSamples, 0, tail) + transcriptSampleCount = tail + lastTranscript = committedTranscript + lastTranscriptDecodeAtMs = SystemClock.elapsedRealtime() + logTranscriptDecode(false, cut, committedTranscript) + emitTranscript(committedTranscript, false) + } + + /** + * Pick where to end the committed segment: the center of the quietest + * window within the search region at the end of the buffer, so the cut + * lands between words instead of splitting one. + */ + private fun findSegmentCutPoint(): Int { + val count = transcriptSampleCount + val searchStart = Math.max(0, count - TRANSCRIPT_CUT_SEARCH_SAMPLES) + val win = TRANSCRIPT_CUT_WINDOW_SAMPLES + if (count - searchStart <= win) { + return count + } + var sum = 0.0 + for (i in searchStart until searchStart + win) { + sum += transcriptSamples[i].toDouble() * transcriptSamples[i] + } + var best = sum + var bestStart = searchStart + var start = searchStart + 1 + while (start + win <= count) { + val dropped = transcriptSamples[start - 1] + val added = transcriptSamples[start + win - 1] + sum += added.toDouble() * added - dropped.toDouble() * dropped + if (sum < best) { + best = sum + bestStart = start + } + start++ + } + return bestStart + win / 2 + } + + private fun recognizeTranscriptSegment(sampleCount: Int): String { + val currentRecognizer = recognizer + if (currentRecognizer == null || sampleCount <= 0) { + return "" + } + val segment = Arrays.copyOf(transcriptSamples, sampleCount) + // Whisper hallucinates text on near-silent input (a known quirk of the + // model, not this pipeline); gate it on the PRE-normalization peak, since + // normalizePeak() below would otherwise amplify true silence right up to + // the target level and hide the very thing being checked for. Moonshine + // does not share this failure mode in practice, so it is left unchanged. + if (onboardModelKind == OnboardModelKind.WHISPER && peakAmplitude(segment) < WHISPER_SILENCE_PEAK_THRESHOLD) { + return "" + } + normalizePeak(segment) + val offlineStream: OfflineStream = currentRecognizer.createStream() + try { + offlineStream.acceptWaveform(segment, SAMPLE_RATE) + currentRecognizer.decode(offlineStream) + val result: OfflineRecognizerResult? = currentRecognizer.getResult(offlineStream) + val raw: String? = if (result == null) "" else result.text + return raw?.trim() ?: "" + } finally { + offlineStream.release() + } + } + + private fun logTranscriptDecode(isFinal: Boolean, segmentSampleCount: Int, text: String) { + val totalAudioSec = + (committedTranscriptSampleCount + transcriptSampleCount) / SAMPLE_RATE.toDouble() + val preview = if (text.length <= TRANSCRIPT_LOG_PREVIEW_CHARS) + text else text.substring(0, TRANSCRIPT_LOG_PREVIEW_CHARS) + "..." + Log.i(TAG, (if (onboardModelKind == OnboardModelKind.WHISPER) "Whisper" else "Moonshine") + " decode final=" + isFinal + + " audioSec=" + String.format(java.util.Locale.US, "%.2f", totalAudioSec) + + " segmentAudioSec=" + String.format(java.util.Locale.US, "%.2f", segmentSampleCount / SAMPLE_RATE.toDouble()) + + " textLen=" + text.length + " text=\"" + preview + "\"") + } + + private fun resetTranscriptState() { + transcriptSampleCount = 0 + committedTranscriptSampleCount = 0 + committedTranscript = "" + currentSegmentTranscript = "" + lastTranscriptDecodeAtMs = 0 + } + + private fun emitPcm(pcm: ShortArray, count: Int) { + val currentListener = listener + if (currentListener == null || count <= 0) { + return + } + val le = ByteArray(count * 2) + for (i in 0 until count) { + val s = pcm[i].toInt() + le[i * 2] = (s and 0xff).toByte() + le[i * 2 + 1] = ((s shr 8) and 0xff).toByte() + } + mainHandler.post { currentListener.onPcm(le) } + } + + /** + * Embed the session's buffered utterance and compare it to the enrolled + * wearer voice-print. Fails open: a session too short to verify, or a + * model that will not load, counts as the wearer rather than silencing + * every command. + */ + private fun runSpeakerVerification() { + val buffer = verifyBuffer + val wearer = verifyWearerEmbedding + val modelPath = verifySpeakerModelPath + verifyBuffer = null + if (buffer == null || wearer == null || modelPath == null) { + return + } + if (verifyCount < VERIFY_MIN_SAMPLES) { + emitSpeakerVerified(true, 0f) + return + } + val speakerId = cachedSpeakerId(modelPath) + try { + val le = ByteArray(verifyCount * 2) + for (i in 0 until verifyCount) { + val s = buffer[i].toInt() + le[i * 2] = (s and 0xff).toByte() + le[i * 2 + 1] = ((s shr 8) and 0xff).toByte() + } + val embedding = speakerId.embed(le, SAMPLE_RATE) + if (embedding == null || embedding.size != wearer.size) { + emitSpeakerVerified(true, 0f) + return + } + var dot = 0.0 + for (i in embedding.indices) { + dot += embedding[i].toDouble() * wearer[i] + } + val isWearer = dot >= verifyThreshold + Log.i(TAG, "speaker verification similarity=" + String.format(java.util.Locale.US, "%.3f", dot) + + " threshold=" + verifyThreshold + " isWearer=" + isWearer) + emitSpeakerVerified(isWearer, dot.toFloat()) + } catch (t: Throwable) { + Log.w(TAG, "speaker verification failed", t) + emitSpeakerVerified(true, 0f) + } + } + + private fun emitSpeakerVerified(isWearer: Boolean, similarity: Float) { + val currentListener = listener + if (currentListener == null) { + return + } + mainHandler.post { currentListener.onSpeakerVerified(isWearer, similarity) } + } + + private fun emitFrameMeta(angleDegrees: Int, ssr: Int) { + val currentListener = listener + if (currentListener == null) { + return + } + mainHandler.post { currentListener.onFrameMeta(angleDegrees, ssr) } + } + + private fun emitSpeechEnd() { + val currentListener = listener + if (currentListener == null) { + return + } + mainHandler.post { currentListener.onSpeechEnd() } + } + + private fun emitStopped(captureId: Int) { + val currentListener = listener + if (currentListener != null) { + mainHandler.post { currentListener.onStopped(captureId) } + } + } + + private fun stopG2Audio() { + val currentCommunicator = communicator + if (currentCommunicator != null) { + currentCommunicator.stopG2AudioCapture() + } + maybeEmitAudioStats(true) + } + + private fun releaseSherpa() { + if (recognizer != null) { + recognizer!!.release() + recognizer = null + } + } + + private fun releaseLc3() { + if (lc3Decoder != null) { + lc3Decoder!!.close() + lc3Decoder = null + } + } + + private fun queueAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { + if (!started || data == null) { + return + } + if ("L" != arm) { + wrongArmPackets++ + } + synchronized(audioQueueLock) { + if (audioQueue.size >= MAX_AUDIO_QUEUE_PACKETS) { + audioQueue.removeFirst() + queueDroppedPackets++ + } + audioQueue.addLast(AudioPacket(data, arm, arrivalMs)) + queuedPackets++ + if (lastPacketArrivalMs > 0) { + val delta = arrivalMs - lastPacketArrivalMs + if (delta > maxInterPacketMs) { + maxInterPacketMs = delta + } + if (delta > LATE_PACKET_INTERVAL_MS) { + latePackets++ + } + } + lastPacketArrivalMs = arrivalMs + (audioQueueLock as java.lang.Object).notifyAll() + } + } + + private fun takeAudioPacket(): AudioPacket? { + synchronized(audioQueueLock) { + while (started && audioQueue.isEmpty()) { + try { + (audioQueueLock as java.lang.Object).wait(250) + maybeEmitAudioStats(false) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + return null + } + } + return audioQueue.pollFirst() + } + } + + private fun resetAudioStats() { + queuedPackets = 0 + queueDroppedPackets = 0 + decodedSamples = 0 + latePackets = 0 + wrongArmPackets = 0 + lastPacketArrivalMs = 0 + maxInterPacketMs = 0 + lastStatsAtMs = SystemClock.elapsedRealtime() + } + + private fun maybeEmitAudioStats(force: Boolean) { + val now = SystemClock.elapsedRealtime() + if (!force && now - lastStatsAtMs < STATS_INTERVAL_MS) { + return + } + lastStatsAtMs = now + val currentDecoder = lc3Decoder + val real = if (currentDecoder == null) 0L else currentDecoder.getRealPackets() + val duplicate = if (currentDecoder == null) 0L else currentDecoder.getDuplicatePackets() + val missing = if (currentDecoder == null) 0L else currentDecoder.getMissingPackets() + val decodeErrors = if (currentDecoder == null) 0L else currentDecoder.getDecodeErrors() + val status = "G2 mic packets=" + queuedPackets + + " decoded=" + real + + " missing=" + missing + + " duplicate=" + duplicate + + " late=" + latePackets + + " maxGapMs=" + maxInterPacketMs + + "\n" + + " queueDrop=" + queueDroppedPackets + + " decodeErrors=" + decodeErrors + + " wrongArm=" + wrongArmPackets + + " audioSec=" + String.format(java.util.Locale.US, "%.1f", decodedSamples / SAMPLE_RATE.toDouble()) + // Audio-pipeline stats are diagnostic; keep them in logcat only, out of + // the on-glasses voice UI. + Log.i(TAG, status.replace('\n', ' ') + " expectedIntervalMs=" + EXPECTED_PACKET_INTERVAL_MS) + } + + private fun emitStatus(status: String?) { + val currentListener = listener + if (currentListener == null) { + return + } + mainHandler.post { currentListener.onStatus(status) } + } + + private fun emitTranscript(text: String?, isFinal: Boolean) { + val currentListener = listener + if (currentListener == null) { + return + } + Log.i(TAG, "Emit transcript final=" + isFinal + " textLen=" + (text?.trim()?.length ?: 0)) + mainHandler.post { currentListener.onTranscript(text, isFinal) } + } + + private class AudioPacket(val data: ByteArray?, arm: String?, val arrivalMs: Long) { + val arm: String = arm ?: "?" + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java deleted file mode 100644 index cb0da66f..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.java +++ /dev/null @@ -1,391 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GoogleApiAvailability; -import com.google.android.gms.wearable.CapabilityClient; -import com.google.android.gms.wearable.CapabilityInfo; -import com.google.android.gms.wearable.DataMap; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.PutDataMapRequest; -import com.google.android.gms.wearable.PutDataRequest; -import com.google.android.gms.wearable.Wearable; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * Phone side of the Wear OS integration: the single place that talks to the - * Wearable Data Layer (Google Play services), so the JS side only ever sees - * JSON strings and never touches Play services types. - * - * Inbound: FaceclawWearListenerService hands every watch message to - * {@link #handleMessage}; it is forwarded to the JS listener on the thread - * that registered it (the main isolate), mirroring FaceclawSettings. Messages - * that arrive before a listener exists (the watch poked a phone whose JS - * dashboard is not up yet) are acked with jsReady=false so the watch can say - * "open Faceclaw on your phone"; only idempotent state requests are kept for - * replay on registration — the watch already reported gestures and commands - * as failed, and executing them tens of seconds later would act on whatever - * the glasses happen to show by then. - * - * Outbound: {@link #publishState} mirrors the dashboard state into a Data - * Layer item (delivered even if the watch is out of range right now, and - * available to the watch app the moment it opens), while {@link #sendToWatch} - * sends fire-and-forget messages (acks, assistant text) to every reachable - * watch that advertises the Faceclaw watch-app capability. - * - * Everything is a no-op on phones without Google Play services. - */ -public final class FaceclawWearBridge { - private static final String TAG = "FaceclawWear"; - - /** Advertised by the watch app (wear/app/src/main/res/values/wear.xml). */ - public static final String CAPABILITY_WATCH = "faceclaw_watch"; - /** Advertised by this app (res/values/wear.xml) so the watch can find the phone. */ - public static final String CAPABILITY_PHONE = "faceclaw_phone"; - - public static final String PATH_PREFIX = "/faceclaw"; - public static final String PATH_STATE = "/faceclaw/state"; - public static final String PATH_STATE_REQUEST = "/faceclaw/state/request"; - /** Watch -> phone: the watch's own battery; carries no seq and is never acked. */ - public static final String PATH_WATCH_BATTERY = "/faceclaw/battery"; - /** Phone -> watch: answered with PATH_WATCH_BATTERY even while the watch app is closed. */ - public static final String PATH_WATCH_BATTERY_REQUEST = "/faceclaw/battery/request"; - public static final String PATH_ACK = "/faceclaw/ack"; - public static final String PATH_EVENT = "/faceclaw/event"; - - private static final String STATE_KEY_JSON = "json"; - private static final String STATE_KEY_UPDATED_AT = "updatedAt"; - - /** Messages kept for a listener that is not registered yet. */ - private static final int PENDING_LIMIT = 16; - private static final long PENDING_MAX_AGE_MS = 30_000; - - private static volatile FaceclawWearBridge instance; - - private final Context context; - private final boolean available; - private final Object lock = new Object(); - private FaceclawWearListener listener; - private Handler listenerHandler; - private final ArrayDeque pending = new ArrayDeque<>(); - private final List watchNodes = new ArrayList<>(); - private String lastPublishedState = null; - - private static final class PendingMessage { - final String path; - final String json; - final String nodeId; - final long receivedAt; - - PendingMessage(String path, String json, String nodeId, long receivedAt) { - this.path = path; - this.json = json; - this.nodeId = nodeId; - this.receivedAt = receivedAt; - } - } - - private FaceclawWearBridge(Context context) { - this.context = context.getApplicationContext(); - boolean playServices; - try { - playServices = GoogleApiAvailability.getInstance() - .isGooglePlayServicesAvailable(this.context) == ConnectionResult.SUCCESS; - } catch (Throwable error) { - Log.w(TAG, "Play services availability check failed", error); - playServices = false; - } - this.available = playServices; - if (!available) { - Log.i(TAG, "Google Play services unavailable; watch integration disabled"); - } - } - - /** Initialize (idempotent) and return the singleton. */ - public static FaceclawWearBridge getInstance(Context context) { - if (instance == null) { - synchronized (FaceclawWearBridge.class) { - if (instance == null) { - instance = new FaceclawWearBridge(context); - } - } - } - return instance; - } - - /** Whether the Wearable Data Layer can be used on this phone at all. */ - public boolean isAvailable() { - return available; - } - - /** - * Register the JS listener. Must be called from the thread whose isolate - * owns it; that thread's Looper is captured for dispatch. Replays any - * recently queued watch messages and refreshes the reachable-watch set. - */ - public void setListener(FaceclawWearListener newListener) { - Looper looper = Looper.myLooper(); - if (looper == null) { - Log.w(TAG, "wear listener registered from a Looper-less thread; it will never be notified"); - } - List replay; - synchronized (lock) { - listener = newListener; - listenerHandler = looper != null ? new Handler(looper) : null; - replay = new ArrayList<>(pending); - pending.clear(); - } - long now = System.currentTimeMillis(); - for (PendingMessage message : replay) { - if (now - message.receivedAt <= PENDING_MAX_AGE_MS) { - dispatchMessage(message.path, message.json, message.nodeId); - } - } - refreshWatchNodes(); - } - - public void clearListener() { - synchronized (lock) { - listener = null; - listenerHandler = null; - } - } - - public boolean isWatchReachable() { - synchronized (lock) { - return !watchNodes.isEmpty(); - } - } - - /** Display name of a reachable watch ("" if none). */ - public String getWatchName() { - synchronized (lock) { - return watchNodes.isEmpty() ? "" : watchNodes.get(0).getDisplayName(); - } - } - - /** Re-query which watches advertise the Faceclaw watch-app capability. */ - public void refreshWatchNodes() { - if (!available) return; - try { - Wearable.getCapabilityClient(context) - .getCapability(CAPABILITY_WATCH, CapabilityClient.FILTER_REACHABLE) - .addOnSuccessListener(this::updateWatchNodes) - .addOnFailureListener(error -> Log.w(TAG, "capability query failed", error)); - } catch (Throwable error) { - Log.w(TAG, "capability query failed", error); - } - } - - /** - * Mirror the dashboard state to the watch. Identical consecutive states - * are not re-sent (the Data Layer would drop them anyway). - */ - public void publishState(String json) { - publishState(json, false); - } - - /** As {@link #publishState(String)}; `force` re-sends an unchanged state. */ - public void publishState(String json, boolean force) { - if (!available || json == null) return; - synchronized (lock) { - if (!force && json.equals(lastPublishedState)) return; - lastPublishedState = json; - } - try { - PutDataMapRequest request = PutDataMapRequest.create(PATH_STATE); - DataMap map = request.getDataMap(); - map.putString(STATE_KEY_JSON, json); - map.putLong(STATE_KEY_UPDATED_AT, System.currentTimeMillis()); - PutDataRequest put = request.asPutDataRequest().setUrgent(); - Wearable.getDataClient(context) - .putDataItem(put) - .addOnFailureListener(error -> Log.w(TAG, "state publish failed", error)); - } catch (Throwable error) { - Log.w(TAG, "state publish failed", error); - } - } - - /** Send a message to every reachable watch running the Faceclaw watch app. */ - public void sendToWatch(String path, String json) { - if (!available) return; - List targets; - synchronized (lock) { - targets = new ArrayList<>(watchNodes); - } - if (targets.isEmpty()) { - // Nothing known yet (first message after boot): look the watch up, then send. - try { - Wearable.getCapabilityClient(context) - .getCapability(CAPABILITY_WATCH, CapabilityClient.FILTER_REACHABLE) - .addOnSuccessListener(info -> { - updateWatchNodes(info); - for (Node node : info.getNodes()) { - sendToNode(node.getId(), path, json); - } - }) - .addOnFailureListener(error -> Log.w(TAG, "capability query failed", error)); - } catch (Throwable error) { - Log.w(TAG, "capability query failed", error); - } - return; - } - for (Node node : targets) { - sendToNode(node.getId(), path, json); - } - } - - /** Send a message to one specific node (e.g. an ack back to the sender). */ - public void sendToNode(String nodeId, String path, String json) { - if (!available || nodeId == null || nodeId.isEmpty()) return; - try { - byte[] payload = (json != null ? json : "{}").getBytes(StandardCharsets.UTF_8); - Wearable.getMessageClient(context) - .sendMessage(nodeId, path, payload) - .addOnFailureListener(error -> Log.w(TAG, "send " + path + " to " + nodeId + " failed", error)); - } catch (Throwable error) { - Log.w(TAG, "send " + path + " failed", error); - } - } - - /** Reply to a watch message; `seq` echoes the watch's sequence number. */ - public void sendAck(String nodeId, long seq, boolean ok, boolean jsReady, String message) { - JSONObject ack = new JSONObject(); - try { - ack.put("seq", seq); - ack.put("ok", ok); - ack.put("jsReady", jsReady); - ack.put("message", message != null ? message : ""); - } catch (JSONException ignored) { - // The keys are constants; this cannot happen. - } - sendToNode(nodeId, PATH_ACK, ack.toString()); - } - - /** Entry point for FaceclawWearListenerService; may run on any thread. */ - void handleMessage(MessageEvent event) { - if (event == null) return; - String path = event.getPath(); - if (path == null || !path.startsWith(PATH_PREFIX)) return; - byte[] data = event.getData(); - String json = data != null && data.length > 0 ? new String(data, StandardCharsets.UTF_8) : "{}"; - String nodeId = event.getSourceNodeId(); - Log.d(TAG, "recv " + path + " seq=" + readSeq(json)); - - boolean delivered = dispatchMessage(path, json, nodeId); - if (delivered) return; - // A battery report answers a poll the dashboard sent; with no - // dashboard to receive it, it is simply dropped (the dashboard polls - // again when it starts), and the watch does not expect an ack. - if (PATH_WATCH_BATTERY.equals(path)) return; - - // No JS listener yet: tell the watch so it can explain why nothing is - // happening. Only state requests are kept for replay (see class doc); - // everything else is dropped after the failure ack. - if (PATH_STATE_REQUEST.equals(path)) { - synchronized (lock) { - long now = System.currentTimeMillis(); - while (!pending.isEmpty() && now - pending.peekFirst().receivedAt > PENDING_MAX_AGE_MS) { - pending.pollFirst(); - } - if (pending.size() >= PENDING_LIMIT) { - pending.pollFirst(); - } - pending.addLast(new PendingMessage(path, json, nodeId, now)); - } - } - sendAck(nodeId, readSeq(json), false, false, "Faceclaw is not running on the phone. Open it to connect the glasses."); - } - - /** Entry point for FaceclawWearListenerService's capability callback. */ - void handleCapabilityChanged(CapabilityInfo info) { - if (info == null || !CAPABILITY_WATCH.equals(info.getName())) return; - updateWatchNodes(info); - } - - private void updateWatchNodes(CapabilityInfo info) { - Set nodes = info != null ? info.getNodes() : Collections.emptySet(); - // Every reachable watch gets messages; a nearby (Bluetooth-linked) - // one is listed first so it is the name the phone UI shows. - List reachable = new ArrayList<>(); - for (Node node : nodes) { - if (node.isNearby()) reachable.add(0, node); else reachable.add(node); - } - boolean changed; - String name; - synchronized (lock) { - changed = !sameNodeIds(watchNodes, reachable); - watchNodes.clear(); - watchNodes.addAll(reachable); - name = watchNodes.isEmpty() ? "" : watchNodes.get(0).getDisplayName(); - } - if (changed) { - Log.i(TAG, reachable.isEmpty() ? "no Faceclaw watch reachable" : "watch reachable: " + name); - boolean reachableNow = !reachable.isEmpty(); - FaceclawWearListener target; - Handler handler; - synchronized (lock) { - target = listener; - handler = listenerHandler; - } - if (target != null && handler != null) { - handler.post(() -> { - try { - target.onWatchConnection(reachableNow, name); - } catch (Exception error) { - Log.w(TAG, "watch connection listener failed", error); - } - }); - } - } - } - - private static boolean sameNodeIds(List a, List b) { - if (a.size() != b.size()) return false; - for (int i = 0; i < a.size(); i++) { - if (!a.get(i).getId().equals(b.get(i).getId())) return false; - } - return true; - } - - /** Post to the JS listener; false when there is none to post to. */ - private boolean dispatchMessage(String path, String json, String nodeId) { - FaceclawWearListener target; - Handler handler; - synchronized (lock) { - target = listener; - handler = listenerHandler; - } - if (target == null || handler == null) return false; - handler.post(() -> { - try { - target.onMessage(path, json, nodeId); - } catch (Exception error) { - Log.w(TAG, "wear message listener failed for " + path, error); - } - }); - return true; - } - - private static long readSeq(String json) { - try { - return new JSONObject(json).optLong("seq", 0); - } catch (JSONException error) { - return 0; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.kt new file mode 100644 index 00000000..5be4a511 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.kt @@ -0,0 +1,386 @@ +package com.faceclaw.app + +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.util.Log + +import com.google.android.gms.common.ConnectionResult +import com.google.android.gms.common.GoogleApiAvailability +import com.google.android.gms.wearable.CapabilityClient +import com.google.android.gms.wearable.CapabilityInfo +import com.google.android.gms.wearable.DataMap +import com.google.android.gms.wearable.MessageEvent +import com.google.android.gms.wearable.Node +import com.google.android.gms.wearable.PutDataMapRequest +import com.google.android.gms.wearable.PutDataRequest +import com.google.android.gms.wearable.Wearable + +import org.json.JSONException +import org.json.JSONObject + +import java.nio.charset.StandardCharsets +import java.util.ArrayDeque +import java.util.ArrayList +import java.util.Collections + +/** + * Phone side of the Wear OS integration: the single place that talks to the + * Wearable Data Layer (Google Play services), so the JS side only ever sees + * JSON strings and never touches Play services types. + * + * Inbound: FaceclawWearListenerService hands every watch message to + * [handleMessage]; it is forwarded to the JS listener on the thread + * that registered it (the main isolate), mirroring FaceclawSettings. Messages + * that arrive before a listener exists (the watch poked a phone whose JS + * dashboard is not up yet) are acked with jsReady=false so the watch can say + * "open Faceclaw on your phone"; only idempotent state requests are kept for + * replay on registration — the watch already reported gestures and commands + * as failed, and executing them tens of seconds later would act on whatever + * the glasses happen to show by then. + * + * Outbound: [publishState] mirrors the dashboard state into a Data + * Layer item (delivered even if the watch is out of range right now, and + * available to the watch app the moment it opens), while [sendToWatch] + * sends fire-and-forget messages (acks, assistant text) to every reachable + * watch that advertises the Faceclaw watch-app capability. + * + * Everything is a no-op on phones without Google Play services. + */ +class FaceclawWearBridge private constructor(context: Context) { + companion object { + private const val TAG = "FaceclawWear" + + /** Advertised by the watch app (wear/app/src/main/res/values/wear.xml). */ + const val CAPABILITY_WATCH = "faceclaw_watch" + /** Advertised by this app (res/values/wear.xml) so the watch can find the phone. */ + const val CAPABILITY_PHONE = "faceclaw_phone" + + const val PATH_PREFIX = "/faceclaw" + const val PATH_STATE = "/faceclaw/state" + const val PATH_STATE_REQUEST = "/faceclaw/state/request" + /** Watch -> phone: the watch's own battery; carries no seq and is never acked. */ + const val PATH_WATCH_BATTERY = "/faceclaw/battery" + /** Phone -> watch: answered with PATH_WATCH_BATTERY even while the watch app is closed. */ + const val PATH_WATCH_BATTERY_REQUEST = "/faceclaw/battery/request" + const val PATH_ACK = "/faceclaw/ack" + const val PATH_EVENT = "/faceclaw/event" + + private const val STATE_KEY_JSON = "json" + private const val STATE_KEY_UPDATED_AT = "updatedAt" + + /** Messages kept for a listener that is not registered yet. */ + private const val PENDING_LIMIT = 16 + private const val PENDING_MAX_AGE_MS = 30_000L + + @Volatile + private var instance: FaceclawWearBridge? = null + + /** Initialize (idempotent) and return the singleton. */ + @JvmStatic + fun getInstance(context: Context): FaceclawWearBridge { + if (instance == null) { + synchronized(FaceclawWearBridge::class.java) { + if (instance == null) { + instance = FaceclawWearBridge(context) + } + } + } + return instance!! + } + + private fun sameNodeIds(a: List, b: List): Boolean { + if (a.size != b.size) return false + for (i in a.indices) { + if (a[i].id != b[i].id) return false + } + return true + } + + private fun readSeq(json: String): Long { + try { + return JSONObject(json).optLong("seq", 0) + } catch (error: JSONException) { + return 0 + } + } + } + + private val context: Context + private val available: Boolean + private val lock = Any() + private var listener: FaceclawWearListener? = null + private var listenerHandler: Handler? = null + private val pending = ArrayDeque() + private val watchNodes: MutableList = ArrayList() + private var lastPublishedState: String? = null + + private class PendingMessage( + val path: String, + val json: String, + val nodeId: String?, + val receivedAt: Long, + ) + + init { + this.context = context.applicationContext + var playServices: Boolean + try { + playServices = GoogleApiAvailability.getInstance() + .isGooglePlayServicesAvailable(this.context) == ConnectionResult.SUCCESS + } catch (error: Throwable) { + Log.w(TAG, "Play services availability check failed", error) + playServices = false + } + this.available = playServices + if (!available) { + Log.i(TAG, "Google Play services unavailable; watch integration disabled") + } + } + + /** Whether the Wearable Data Layer can be used on this phone at all. */ + fun isAvailable(): Boolean { + return available + } + + /** + * Register the JS listener. Must be called from the thread whose isolate + * owns it; that thread's Looper is captured for dispatch. Replays any + * recently queued watch messages and refreshes the reachable-watch set. + */ + fun setListener(newListener: FaceclawWearListener?) { + val looper = Looper.myLooper() + if (looper == null) { + Log.w(TAG, "wear listener registered from a Looper-less thread; it will never be notified") + } + val replay: List + synchronized(lock) { + listener = newListener + listenerHandler = if (looper != null) Handler(looper) else null + replay = ArrayList(pending) + pending.clear() + } + val now = System.currentTimeMillis() + for (message in replay) { + if (now - message.receivedAt <= PENDING_MAX_AGE_MS) { + dispatchMessage(message.path, message.json, message.nodeId) + } + } + refreshWatchNodes() + } + + fun clearListener() { + synchronized(lock) { + listener = null + listenerHandler = null + } + } + + fun isWatchReachable(): Boolean { + synchronized(lock) { + return !watchNodes.isEmpty() + } + } + + /** Display name of a reachable watch ("" if none). */ + fun getWatchName(): String { + synchronized(lock) { + return if (watchNodes.isEmpty()) "" else watchNodes[0].displayName + } + } + + /** Re-query which watches advertise the Faceclaw watch-app capability. */ + fun refreshWatchNodes() { + if (!available) return + try { + Wearable.getCapabilityClient(context) + .getCapability(CAPABILITY_WATCH, CapabilityClient.FILTER_REACHABLE) + .addOnSuccessListener { info -> updateWatchNodes(info) } + .addOnFailureListener { error -> Log.w(TAG, "capability query failed", error) } + } catch (error: Throwable) { + Log.w(TAG, "capability query failed", error) + } + } + + /** + * Mirror the dashboard state to the watch. Identical consecutive states + * are not re-sent (the Data Layer would drop them anyway). + */ + fun publishState(json: String?) { + publishState(json, false) + } + + /** As [publishState]; `force` re-sends an unchanged state. */ + fun publishState(json: String?, force: Boolean) { + if (!available || json == null) return + synchronized(lock) { + if (!force && json == lastPublishedState) return + lastPublishedState = json + } + try { + val request = PutDataMapRequest.create(PATH_STATE) + val map: DataMap = request.dataMap + map.putString(STATE_KEY_JSON, json) + map.putLong(STATE_KEY_UPDATED_AT, System.currentTimeMillis()) + val put: PutDataRequest = request.asPutDataRequest().setUrgent() + Wearable.getDataClient(context) + .putDataItem(put) + .addOnFailureListener { error -> Log.w(TAG, "state publish failed", error) } + } catch (error: Throwable) { + Log.w(TAG, "state publish failed", error) + } + } + + /** Send a message to every reachable watch running the Faceclaw watch app. */ + fun sendToWatch(path: String, json: String?) { + if (!available) return + val targets: List + synchronized(lock) { + targets = ArrayList(watchNodes) + } + if (targets.isEmpty()) { + // Nothing known yet (first message after boot): look the watch up, then send. + try { + Wearable.getCapabilityClient(context) + .getCapability(CAPABILITY_WATCH, CapabilityClient.FILTER_REACHABLE) + .addOnSuccessListener { info -> + updateWatchNodes(info) + for (node in info.nodes) { + sendToNode(node.id, path, json) + } + } + .addOnFailureListener { error -> Log.w(TAG, "capability query failed", error) } + } catch (error: Throwable) { + Log.w(TAG, "capability query failed", error) + } + return + } + for (node in targets) { + sendToNode(node.id, path, json) + } + } + + /** Send a message to one specific node (e.g. an ack back to the sender). */ + fun sendToNode(nodeId: String?, path: String, json: String?) { + if (!available || nodeId == null || nodeId.isEmpty()) return + try { + val payload = (json ?: "{}").toByteArray(StandardCharsets.UTF_8) + Wearable.getMessageClient(context) + .sendMessage(nodeId, path, payload) + .addOnFailureListener { error -> Log.w(TAG, "send $path to $nodeId failed", error) } + } catch (error: Throwable) { + Log.w(TAG, "send $path failed", error) + } + } + + /** Reply to a watch message; `seq` echoes the watch's sequence number. */ + fun sendAck(nodeId: String?, seq: Long, ok: Boolean, jsReady: Boolean, message: String?) { + val ack = JSONObject() + try { + ack.put("seq", seq) + ack.put("ok", ok) + ack.put("jsReady", jsReady) + ack.put("message", message ?: "") + } catch (ignored: JSONException) { + // The keys are constants; this cannot happen. + } + sendToNode(nodeId, PATH_ACK, ack.toString()) + } + + /** Entry point for FaceclawWearListenerService; may run on any thread. */ + internal fun handleMessage(event: MessageEvent?) { + if (event == null) return + val path: String? = event.path + if (path == null || !path.startsWith(PATH_PREFIX)) return + val data: ByteArray? = event.data + val json = if (data != null && data.size > 0) String(data, StandardCharsets.UTF_8) else "{}" + val nodeId: String? = event.sourceNodeId + Log.d(TAG, "recv " + path + " seq=" + readSeq(json)) + + val delivered = dispatchMessage(path, json, nodeId) + if (delivered) return + // A battery report answers a poll the dashboard sent; with no + // dashboard to receive it, it is simply dropped (the dashboard polls + // again when it starts), and the watch does not expect an ack. + if (PATH_WATCH_BATTERY == path) return + + // No JS listener yet: tell the watch so it can explain why nothing is + // happening. Only state requests are kept for replay (see class doc); + // everything else is dropped after the failure ack. + if (PATH_STATE_REQUEST == path) { + synchronized(lock) { + val now = System.currentTimeMillis() + while (!pending.isEmpty() && now - pending.peekFirst().receivedAt > PENDING_MAX_AGE_MS) { + pending.pollFirst() + } + if (pending.size >= PENDING_LIMIT) { + pending.pollFirst() + } + pending.addLast(PendingMessage(path, json, nodeId, now)) + } + } + sendAck(nodeId, readSeq(json), false, false, "Faceclaw is not running on the phone. Open it to connect the glasses.") + } + + /** Entry point for FaceclawWearListenerService's capability callback. */ + internal fun handleCapabilityChanged(info: CapabilityInfo?) { + if (info == null || CAPABILITY_WATCH != info.name) return + updateWatchNodes(info) + } + + private fun updateWatchNodes(info: CapabilityInfo?) { + val nodes: Set = if (info != null) info.nodes else Collections.emptySet() + // Every reachable watch gets messages; a nearby (Bluetooth-linked) + // one is listed first so it is the name the phone UI shows. + val reachable: MutableList = ArrayList() + for (node in nodes) { + if (node.isNearby) reachable.add(0, node) else reachable.add(node) + } + val changed: Boolean + val name: String + synchronized(lock) { + changed = !sameNodeIds(watchNodes, reachable) + watchNodes.clear() + watchNodes.addAll(reachable) + name = if (watchNodes.isEmpty()) "" else watchNodes[0].displayName + } + if (changed) { + Log.i(TAG, if (reachable.isEmpty()) "no Faceclaw watch reachable" else "watch reachable: $name") + val reachableNow = !reachable.isEmpty() + val target: FaceclawWearListener? + val handler: Handler? + synchronized(lock) { + target = listener + handler = listenerHandler + } + if (target != null && handler != null) { + handler.post { + try { + target.onWatchConnection(reachableNow, name) + } catch (error: Exception) { + Log.w(TAG, "watch connection listener failed", error) + } + } + } + } + } + + /** Post to the JS listener; false when there is none to post to. */ + private fun dispatchMessage(path: String, json: String, nodeId: String?): Boolean { + val target: FaceclawWearListener? + val handler: Handler? + synchronized(lock) { + target = listener + handler = listenerHandler + } + if (target == null || handler == null) return false + handler.post { + try { + target.onMessage(path, json, nodeId) + } catch (error: Exception) { + Log.w(TAG, "wear message listener failed for $path", error) + } + } + return true + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.java deleted file mode 100644 index 7520d780..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.faceclaw.app; - -import android.util.Log; - -import com.google.android.gms.wearable.CapabilityInfo; -import com.google.android.gms.wearable.MessageEvent; -import com.google.android.gms.wearable.WearableListenerService; - -/** - * Play services starts this service (in the app process) for every Data - * Layer message under /faceclaw and for capability changes, whether or not - * the app is running. It only forwards to FaceclawWearBridge, which owns the - * hand-off to the JS side. - */ -public class FaceclawWearListenerService extends WearableListenerService { - @Override - public void onMessageReceived(MessageEvent event) { - Log.d("FaceclawWear", "service onMessageReceived " + event.getPath() + " from " + event.getSourceNodeId()); - FaceclawWearBridge.getInstance(this).handleMessage(event); - } - - @Override - public void onCapabilityChanged(CapabilityInfo info) { - FaceclawWearBridge.getInstance(this).handleCapabilityChanged(info); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.kt new file mode 100644 index 00000000..ed0ce360 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.kt @@ -0,0 +1,24 @@ +package com.faceclaw.app + +import android.util.Log + +import com.google.android.gms.wearable.CapabilityInfo +import com.google.android.gms.wearable.MessageEvent +import com.google.android.gms.wearable.WearableListenerService + +/** + * Play services starts this service (in the app process) for every Data + * Layer message under /faceclaw and for capability changes, whether or not + * the app is running. It only forwards to FaceclawWearBridge, which owns the + * hand-off to the JS side. + */ +class FaceclawWearListenerService : WearableListenerService() { + override fun onMessageReceived(event: MessageEvent) { + Log.d("FaceclawWear", "service onMessageReceived " + event.path + " from " + event.sourceNodeId) + FaceclawWearBridge.getInstance(this).handleMessage(event) + } + + override fun onCapabilityChanged(info: CapabilityInfo) { + FaceclawWearBridge.getInstance(this).handleCapabilityChanged(info) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.java deleted file mode 100644 index f228ed7a..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.faceclaw.app; - -import android.os.Handler; -import android.os.Looper; -import android.util.Log; - -import java.util.concurrent.TimeUnit; - -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.WebSocket; -import okhttp3.WebSocketListener; -import okio.ByteString; - -/** - * Thin okhttp WebSocket wrapper for the TypeScript side. Sends text frames - * (JSON protocols) and binary frames (raw audio for Soniox). Listener callbacks are - * posted to the Looper of the thread that constructed this object, so a JS - * isolate (main thread or app worker) always receives them on its own - * thread; a Looper-less constructing thread falls back to the main thread. - */ -public class FaceclawWebSocket { - private static final String TAG = "FaceclawWebSocket"; - private static volatile OkHttpClient sharedClient; - - private final Handler callbackHandler; - private final WebSocket socket; - private volatile boolean closeRequested; - - // Single constructor (no overloads) so NativeScript constructor resolution - // can never pick a variant that drops the auth header; callers with no - // header pass null/null. - public FaceclawWebSocket(String url, final FaceclawWebSocketListener listener, String headerName, String headerValue) { - if (url == null || url.trim().isEmpty()) { - throw new IllegalArgumentException("url is required"); - } - if (listener == null) { - throw new IllegalArgumentException("listener is required"); - } - Looper looper = Looper.myLooper(); - callbackHandler = new Handler(looper != null ? looper : Looper.getMainLooper()); - Request.Builder builder = new Request.Builder().url(url.trim()); - if (headerName != null && !headerName.isEmpty() && headerValue != null) { - builder.addHeader(headerName, headerValue); - } - Request request = builder.build(); - // Redacted diagnostics: confirm the auth header is actually present on - // the handshake and carries a plausible value (not empty/truncated). - StringBuilder headerLog = new StringBuilder(); - for (String name : request.headers().names()) { - String value = request.header(name); - headerLog.append(name).append('=').append(redact(value)).append(' '); - } - Log.i(TAG, "ws connect host=" + request.url().host() + request.url().encodedPath() - + " headers=[" + headerLog.toString().trim() + "]"); - socket = getClient().newWebSocket(request, new WebSocketListener() { - @Override public void onOpen(WebSocket webSocket, Response response) { - callbackHandler.post(() -> { - try { - listener.onOpen(); - } catch (Throwable t) { - Log.w(TAG, "listener onOpen failed", t); - } - }); - } - - @Override public void onMessage(WebSocket webSocket, String text) { - callbackHandler.post(() -> { - try { - listener.onTextMessage(text); - } catch (Throwable t) { - Log.w(TAG, "listener onTextMessage failed", t); - } - }); - } - - @Override public void onClosing(WebSocket webSocket, int code, String reason) { - webSocket.close(code, reason); - } - - @Override public void onClosed(WebSocket webSocket, int code, String reason) { - callbackHandler.post(() -> { - try { - listener.onClosed(code, reason == null ? "" : reason); - } catch (Throwable t) { - Log.w(TAG, "listener onClosed failed", t); - } - }); - } - - @Override public void onFailure(WebSocket webSocket, Throwable t, Response response) { - if (closeRequested) { - return; - } - final String message = t == null ? "unknown websocket failure" : String.valueOf(t); - callbackHandler.post(() -> { - try { - listener.onFailure(message); - } catch (Throwable inner) { - Log.w(TAG, "listener onFailure failed", inner); - } - }); - } - }); - } - - private static OkHttpClient getClient() { - OkHttpClient client = sharedClient; - if (client == null) { - synchronized (FaceclawWebSocket.class) { - if (sharedClient == null) { - sharedClient = new OkHttpClient.Builder() - .pingInterval(20, TimeUnit.SECONDS) - .addInterceptor(FaceclawHttp.userAgentInterceptor()) - .build(); - } - client = sharedClient; - } - } - return client; - } - - private static String redact(String value) { - if (value == null) { - return "null"; - } - int len = value.length(); - String prefix = value.substring(0, Math.min(4, len)); - return "len" + len + ":" + prefix + "..."; - } - - public boolean sendText(String message) { - return socket.send(message == null ? "" : message); - } - - public boolean sendBinary(byte[] bytes) { - return socket.send(ByteString.of(bytes == null ? new byte[0] : bytes)); - } - - public void close(int code, String reason) { - closeRequested = true; - try { - if (!socket.close(code, reason)) { - socket.cancel(); - } - } catch (Throwable t) { - socket.cancel(); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.kt new file mode 100644 index 00000000..f4a793bd --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.kt @@ -0,0 +1,156 @@ +package com.faceclaw.app + +import android.os.Handler +import android.os.Looper +import android.util.Log + +import java.util.concurrent.TimeUnit + +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response +import okhttp3.WebSocket +import okhttp3.WebSocketListener +import okio.ByteString.Companion.toByteString + +/** + * Thin okhttp WebSocket wrapper for the TypeScript side. Sends text frames + * (JSON protocols) and binary frames (raw audio for Soniox). Listener callbacks are + * posted to the Looper of the thread that constructed this object, so a JS + * isolate (main thread or app worker) always receives them on its own + * thread; a Looper-less constructing thread falls back to the main thread. + */ +class FaceclawWebSocket +// Single constructor (no overloads) so NativeScript constructor resolution +// can never pick a variant that drops the auth header; callers with no +// header pass null/null. +constructor(url: String?, listener: FaceclawWebSocketListener?, headerName: String?, headerValue: String?) { + private val callbackHandler: Handler + private val socket: WebSocket + @Volatile + private var closeRequested = false + + init { + if (url == null || url.trim().isEmpty()) { + throw IllegalArgumentException("url is required") + } + if (listener == null) { + throw IllegalArgumentException("listener is required") + } + val looper = Looper.myLooper() + callbackHandler = Handler(looper ?: Looper.getMainLooper()) + val builder = Request.Builder().url(url.trim()) + if (headerName != null && !headerName.isEmpty() && headerValue != null) { + builder.addHeader(headerName, headerValue) + } + val request = builder.build() + // Redacted diagnostics: confirm the auth header is actually present on + // the handshake and carries a plausible value (not empty/truncated). + val headerLog = StringBuilder() + for (name in request.headers.names()) { + val value = request.header(name) + headerLog.append(name).append('=').append(redact(value)).append(' ') + } + Log.i(TAG, "ws connect host=" + request.url.host + request.url.encodedPath + + " headers=[" + headerLog.toString().trim() + "]") + socket = getClient().newWebSocket(request, object : WebSocketListener() { + override fun onOpen(webSocket: WebSocket, response: Response) { + callbackHandler.post { + try { + listener.onOpen() + } catch (t: Throwable) { + Log.w(TAG, "listener onOpen failed", t) + } + } + } + + override fun onMessage(webSocket: WebSocket, text: String) { + callbackHandler.post { + try { + listener.onTextMessage(text) + } catch (t: Throwable) { + Log.w(TAG, "listener onTextMessage failed", t) + } + } + } + + override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { + webSocket.close(code, reason) + } + + override fun onClosed(webSocket: WebSocket, code: Int, reason: String) { + callbackHandler.post { + try { + listener.onClosed(code, reason) + } catch (t: Throwable) { + Log.w(TAG, "listener onClosed failed", t) + } + } + } + + override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { + if (closeRequested) { + return + } + val message = t.toString() + callbackHandler.post { + try { + listener.onFailure(message) + } catch (inner: Throwable) { + Log.w(TAG, "listener onFailure failed", inner) + } + } + } + }) + } + + companion object { + private const val TAG = "FaceclawWebSocket" + @Volatile + private var sharedClient: OkHttpClient? = null + + private fun getClient(): OkHttpClient { + var client = sharedClient + if (client == null) { + synchronized(FaceclawWebSocket::class.java) { + if (sharedClient == null) { + sharedClient = OkHttpClient.Builder() + .pingInterval(20, TimeUnit.SECONDS) + .addInterceptor(FaceclawHttp.userAgentInterceptor()) + .build() + } + client = sharedClient + } + } + return client!! + } + + private fun redact(value: String?): String { + if (value == null) { + return "null" + } + val len = value.length + val prefix = value.substring(0, Math.min(4, len)) + return "len$len:$prefix..." + } + } + + fun sendText(message: String?): Boolean { + return socket.send(message ?: "") + } + + fun sendBinary(bytes: ByteArray?): Boolean { + return socket.send((bytes ?: ByteArray(0)).toByteString()) + } + + fun close(code: Int, reason: String?) { + closeRequested = true + try { + if (!socket.close(code, reason)) { + socket.cancel() + } + } catch (t: Throwable) { + socket.cancel() + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.java deleted file mode 100644 index 0eca05e5..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.java +++ /dev/null @@ -1,537 +0,0 @@ -package com.faceclaw.app; - -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Typeface; -import android.os.Build; -import android.util.Log; - -import java.io.File; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Rasterizes text using font files (TTF/OTF/TTC) via the Android text stack, - * so shaping, kerning, and antialiasing are all delegated to - * minikin/HarfBuzz. Output uses the same grayscale packet format as - * ImageFileLoader ([widthLo, widthHi, heightLo, heightHi, pixels...], one - * byte per pixel, row-major), which the TS side turns into a GrayImage and - * the compositor later quantizes to the 4bpp the firmware wants. - * - * The gamma parameter maps antialiased coverage to output shade: - * out = 255 * (coverage/255)^gamma. The G2 display response looks roughly - * linear, so 1.0 is the expected default; the font previewer exposes it for - * on-hardware comparison. - */ -public final class FontFileRenderer { - private static final String TAG = "FontFileRenderer"; - private static final int TYPEFACE_CACHE_SIZE = 4; - - /** Small LRU of loaded typefaces keyed by file path. */ - private static final Map typefaceCache = - new LinkedHashMap(TYPEFACE_CACHE_SIZE, 0.75f, true) { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > TYPEFACE_CACHE_SIZE; - } - }; - - private FontFileRenderer() {} - - /** - * Render one line of text with the given font file at the given pixel - * size. The returned image is the font's full vertical extent (top to - * bottom, taller than ascent+descent), plus any horizontal glyph - * overhang beyond the advance width. - * - * Returns an empty array if the font cannot be loaded or the text - * renders to nothing. - */ - public static byte[] renderText(String path, String text, float sizePx, double gamma) { - if (path == null || text == null || sizePx <= 0) { - return new byte[0]; - } - Typeface typeface = loadTypeface(path); - if (typeface == null) { - return new byte[0]; - } - try { - Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); - paint.setTypeface(typeface); - paint.setTextSize(sizePx); - paint.setColor(Color.WHITE); - - // top/bottom (the font's maximal extent) rather than - // ascent/descent, so diacritics and swashes don't clip. - Paint.FontMetricsInt fm = paint.getFontMetricsInt(); - int ascent = -fm.top; - int height = -fm.top + fm.bottom; - // measureText gives advance width; italic/swash glyphs can paint - // outside it, so pad by half an em on each side and trim after. - int pad = (int) Math.ceil(sizePx / 2); - int advance = (int) Math.ceil(paint.measureText(text)); - int width = advance + 2 * pad; - if (width <= 0 || height <= 0 || width * height > 4_000_000) { - return new byte[0]; - } - - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8); - Canvas canvas = new Canvas(bitmap); - canvas.drawText(text, pad, ascent, paint); - byte[] pixels = alpha8Pixels(bitmap, width, height); - bitmap.recycle(); - - // Trim the horizontal padding down to the painted extent, but - // keep at least the advance width so spacing stays truthful. - int left = pad; - int right = pad + advance; - int[] painted = paintedColumnRange(pixels, width, height); - if (painted != null) { - left = Math.min(left, painted[0]); - right = Math.max(right, painted[1] + 1); - } - int outWidth = Math.max(1, right - left); - - byte[] lut = gammaLut(gamma); - byte[] out = new byte[4 + outWidth * height]; - out[0] = (byte) (outWidth & 0xff); - out[1] = (byte) ((outWidth >> 8) & 0xff); - out[2] = (byte) (height & 0xff); - out[3] = (byte) ((height >> 8) & 0xff); - for (int y = 0; y < height; y++) { - int srcRow = y * width; - int dstRow = 4 + y * outWidth; - for (int x = 0; x < outWidth; x++) { - out[dstRow + x] = lut[pixels[srcRow + left + x] & 0xff]; - } - } - return out; - } catch (Exception | OutOfMemoryError e) { - Log.w(TAG, "text render failed: " + path, e); - return new byte[0]; - } - } - - /** - * Render a multi-line block of text wrapped to maxWidth, with line - * breaking delegated to StaticLayout (so it matches Android text - * behavior, including breaking inside long words). Truncated with an - * ellipsis past maxLines. Same packet format as renderText. - */ - public static byte[] renderWrapped( - String path, String text, float sizePx, int maxWidth, double gamma, int maxLines) { - if (path == null || text == null || sizePx <= 0 || maxWidth <= 0 || maxLines <= 0) { - return new byte[0]; - } - Typeface typeface = loadTypeface(path); - if (typeface == null) { - return new byte[0]; - } - try { - android.text.TextPaint paint = - new android.text.TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); - paint.setTypeface(typeface); - paint.setTextSize(sizePx); - paint.setColor(Color.WHITE); - paint.setHinting(Paint.HINTING_ON); - - android.text.StaticLayout layout = android.text.StaticLayout.Builder - .obtain(text, 0, text.length(), paint, maxWidth) - .setAlignment(android.text.Layout.Alignment.ALIGN_NORMAL) - .setIncludePad(false) - .setMaxLines(maxLines) - .setEllipsize(android.text.TextUtils.TruncateAt.END) - .build(); - int height = Math.max(1, layout.getHeight()); - if ((long) maxWidth * height > 4_000_000L) { - return new byte[0]; - } - - Bitmap bitmap = Bitmap.createBitmap(maxWidth, height, Bitmap.Config.ALPHA_8); - Canvas canvas = new Canvas(bitmap); - layout.draw(canvas); - byte[] pixels = alpha8Pixels(bitmap, maxWidth, height); - bitmap.recycle(); - - byte[] lut = gammaLut(gamma); - byte[] out = new byte[4 + pixels.length]; - out[0] = (byte) (maxWidth & 0xff); - out[1] = (byte) ((maxWidth >> 8) & 0xff); - out[2] = (byte) (height & 0xff); - out[3] = (byte) ((height >> 8) & 0xff); - for (int i = 0; i < pixels.length; i++) { - out[4 + i] = lut[pixels[i] & 0xff]; - } - return out; - } catch (Exception | OutOfMemoryError e) { - Log.w(TAG, "wrapped render failed: " + path, e); - return new byte[0]; - } - } - - /** - * Render one codepoint as a tight-ink-box antialiased glyph cell for the - * texture-cache text pipeline (see app/graphics/ttf-font.ts). Ligatures - * are disabled so a per-codepoint raster plus pairwise kerning (measured - * via measureTextExact) fully describes a line. Little-endian packet: - * [advance u16, 26.6 fixed point] - * [bearingX s16] ink left relative to the pen position - * [inkTop s16] ink top relative to the line top (ascent above baseline) - * [width u16][height u16] - * [width*height coverage bytes, gamma-mapped] - * An ink-free glyph (space) has width = height = 0 but a valid advance. - * Empty array when the font cannot be loaded or the render fails. - */ - public static byte[] renderGlyphCell(String path, float sizePx, int codePoint, double gamma) { - Typeface typeface = loadTypeface(path); - if (typeface == null || sizePx <= 0 || codePoint < 0 || codePoint > 0x10ffff) { - return new byte[0]; - } - try { - Paint paint = glyphPaint(typeface, sizePx); - String text = new String(Character.toChars(codePoint)); - float advance = paint.measureText(text); - int advanceFixed = Math.max(0, Math.min(0xffff, Math.round(advance * 64f))); - - android.graphics.Rect bounds = new android.graphics.Rect(); - paint.getTextBounds(text, 0, text.length(), bounds); - if (bounds.isEmpty()) { - return glyphCellPacket(advanceFixed, 0, 0, 0, 0, null); - } - // getTextBounds can be off by a hair on AA edges; render with - // padding, then trim to the actually painted box. - int pad = 2; - int bw = bounds.width() + 2 * pad; - int bh = bounds.height() + 2 * pad; - if (bw <= 0 || bh <= 0 || bw * bh > 1_000_000) { - return new byte[0]; - } - int penX = pad - bounds.left; - int baselineY = pad - bounds.top; - Bitmap bitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ALPHA_8); - Canvas canvas = new Canvas(bitmap); - canvas.drawText(text, penX, baselineY, paint); - byte[] pixels = alpha8Pixels(bitmap, bw, bh); - bitmap.recycle(); - - int x0 = bw, x1 = -1, y0 = bh, y1 = -1; - for (int y = 0; y < bh; y++) { - int row = y * bw; - for (int x = 0; x < bw; x++) { - if (pixels[row + x] != 0) { - if (x < x0) x0 = x; - if (x > x1) x1 = x; - if (y < y0) y0 = y; - if (y > y1) y1 = y; - } - } - } - if (x1 < x0) { - return glyphCellPacket(advanceFixed, 0, 0, 0, 0, null); - } - int width = x1 - x0 + 1; - int height = y1 - y0 + 1; - Paint.FontMetricsInt fm = paint.getFontMetricsInt(); - int bearingX = x0 - penX; - int inkTop = (-fm.ascent) + (y0 - baselineY); - - byte[] lut = gammaLut(gamma); - byte[] coverage = new byte[width * height]; - for (int y = 0; y < height; y++) { - int src = (y0 + y) * bw + x0; - int dst = y * width; - for (int x = 0; x < width; x++) { - coverage[dst + x] = lut[pixels[src + x] & 0xff]; - } - } - return glyphCellPacket(advanceFixed, bearingX, inkTop, width, height, coverage); - } catch (Exception | OutOfMemoryError e) { - Log.w(TAG, "glyph render failed: " + path + " U+" + Integer.toHexString(codePoint), e); - return new byte[0]; - } - } - - /** - * Exact (float) advance width of a text run, with the same paint setup as - * renderGlyphCell (subpixel advances, ligatures off), so pair kerning can - * be derived as measure(ab) - measure(a) - measure(b). - */ - public static double measureTextExact(String path, String text, float sizePx) { - Typeface typeface = loadTypeface(path); - if (typeface == null || text == null || sizePx <= 0) { - return 0; - } - return glyphPaint(typeface, sizePx).measureText(text); - } - - /** Paint used by both the glyph-cell renderer and its measurements. */ - private static Paint glyphPaint(Typeface typeface, float sizePx) { - Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG); - paint.setTypeface(typeface); - paint.setTextSize(sizePx); - paint.setColor(Color.WHITE); - // Ligatures merge codepoints into one glyph, which the per-codepoint - // cache model cannot represent; kerning still applies. - paint.setFontFeatureSettings("'liga' off, 'clig' off"); - return paint; - } - - private static byte[] glyphCellPacket( - int advanceFixed, int bearingX, int inkTop, int width, int height, byte[] coverage) { - byte[] out = new byte[10 + (coverage == null ? 0 : coverage.length)]; - out[0] = (byte) (advanceFixed & 0xff); - out[1] = (byte) ((advanceFixed >> 8) & 0xff); - out[2] = (byte) (bearingX & 0xff); - out[3] = (byte) ((bearingX >> 8) & 0xff); - out[4] = (byte) (inkTop & 0xff); - out[5] = (byte) ((inkTop >> 8) & 0xff); - out[6] = (byte) (width & 0xff); - out[7] = (byte) ((width >> 8) & 0xff); - out[8] = (byte) (height & 0xff); - out[9] = (byte) ((height >> 8) & 0xff); - if (coverage != null) { - System.arraycopy(coverage, 0, out, 10, coverage.length); - } - return out; - } - - /** - * Line metrics for a font at a pixel size, as "ascent descent lineGap" - * (integers, pixels). Empty string if the font cannot be loaded. - */ - public static String getFontMetrics(String path, float sizePx) { - Typeface typeface = loadTypeface(path); - if (typeface == null || sizePx <= 0) { - return ""; - } - Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); - paint.setTypeface(typeface); - paint.setTextSize(sizePx); - Paint.FontMetricsInt fm = paint.getFontMetricsInt(); - int lineGap = fm.leading; - return (-fm.ascent) + " " + fm.descent + " " + lineGap; - } - - /** Advance width in pixels of a line of text (rounded up). */ - public static int measureText(String path, String text, float sizePx) { - Typeface typeface = loadTypeface(path); - if (typeface == null || text == null || sizePx <= 0) { - return 0; - } - Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); - paint.setTypeface(typeface); - paint.setTextSize(sizePx); - return (int) Math.ceil(paint.measureText(text)); - } - - /** - * Whether the font file loads at all (strictly validated on API 29+; - * best-effort below that). - */ - public static boolean canLoadFont(String path) { - return loadTypeface(path) != null; - } - - /** - * The font's family and style names from its 'name' table, as - * "Family\nStyle" ("Style" may be empty). Falls back to "" when the - * table cannot be parsed; callers should then use the filename. - */ - public static String getFontName(String path) { - try { - return parseNameTable(path); - } catch (Exception e) { - Log.w(TAG, "name table parse failed: " + path, e); - return ""; - } - } - - private static synchronized Typeface loadTypeface(String path) { - if (path == null) { - return null; - } - Typeface cached = typefaceCache.get(path); - if (cached != null) { - return cached; - } - File file = new File(path); - if (!file.isFile() || !file.canRead()) { - return null; - } - Typeface typeface = null; - try { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - // Strict path: Font.Builder throws on files that are not - // valid fonts, unlike createFromFile which silently falls - // back to the default typeface. - android.graphics.fonts.Font font = - new android.graphics.fonts.Font.Builder(file).build(); - typeface = new Typeface.CustomFallbackBuilder( - new android.graphics.fonts.FontFamily.Builder(font).build()) - .build(); - } else { - typeface = Typeface.createFromFile(file); - if (typeface == null || typeface.equals(Typeface.DEFAULT)) { - typeface = null; - } - } - } catch (Exception | LinkageError e) { - Log.w(TAG, "font load failed: " + path + ": " + e); - typeface = null; - } - if (typeface != null) { - typefaceCache.put(path, typeface); - } - return typeface; - } - - /** - * The coverage bytes of an ALPHA_8 bitmap as a tightly-packed - * width*height array (copyPixelsToBuffer copies rowBytes*height, and the - * row stride is not guaranteed to equal the width). - */ - private static byte[] alpha8Pixels(Bitmap bitmap, int width, int height) { - int rowBytes = bitmap.getRowBytes(); - byte[] raw = new byte[rowBytes * height]; - bitmap.copyPixelsToBuffer(ByteBuffer.wrap(raw)); - if (rowBytes == width) { - return raw; - } - byte[] pixels = new byte[width * height]; - for (int y = 0; y < height; y++) { - System.arraycopy(raw, y * rowBytes, pixels, y * width, width); - } - return pixels; - } - - /** [first, last] painted (nonzero) column indexes, or null if blank. */ - private static int[] paintedColumnRange(byte[] pixels, int width, int height) { - int first = width; - int last = -1; - for (int y = 0; y < height; y++) { - int row = y * width; - for (int x = 0; x < first; x++) { - if (pixels[row + x] != 0) { - first = x; - break; - } - } - for (int x = width - 1; x > last; x--) { - if (pixels[row + x] != 0) { - last = x; - break; - } - } - } - return last >= first ? new int[] { first, last } : null; - } - - private static byte[] gammaLut(double gamma) { - byte[] lut = new byte[256]; - if (gamma <= 0) { - gamma = 1.0; - } - for (int i = 0; i < 256; i++) { - lut[i] = (byte) Math.max(0, Math.min(255, - (int) Math.round(255.0 * Math.pow(i / 255.0, gamma)))); - } - return lut; - } - - // --- Minimal 'name' table reader (TTF/OTF/TTC) for preview titles --- - - private static String parseNameTable(String path) throws Exception { - try (RandomAccessFile raf = new RandomAccessFile(path, "r")) { - long fileSize = raf.length(); - if (fileSize < 12) { - return ""; - } - long offset = 0; - int tag = readU32(raf, 0); - if (tag == 0x74746366) { // 'ttcf': use the first face - if (readU32(raf, 8) < 1) { - return ""; - } - offset = readU32(raf, 12) & 0xffffffffL; - } - int numTables = readU16(raf, offset + 4); - long nameOffset = -1; - for (int i = 0; i < numTables; i++) { - long rec = offset + 12 + i * 16L; - if (rec + 16 > fileSize) { - return ""; - } - if (readU32(raf, rec) == 0x6e616d65) { // 'name' - nameOffset = readU32(raf, rec + 8) & 0xffffffffL; - break; - } - } - if (nameOffset < 0 || nameOffset + 6 > fileSize) { - return ""; - } - int count = readU16(raf, nameOffset + 2); - long stringStorage = nameOffset + readU16(raf, nameOffset + 4); - String family = null; - String style = null; - String preferredFamily = null; - String preferredStyle = null; - for (int i = 0; i < count; i++) { - long rec = nameOffset + 6 + i * 12L; - if (rec + 12 > fileSize) { - break; - } - int platform = readU16(raf, rec); - int nameId = readU16(raf, rec + 6); - if (nameId != 1 && nameId != 2 && nameId != 16 && nameId != 17) { - continue; - } - int length = readU16(raf, rec + 8); - long strOffset = stringStorage + readU16(raf, rec + 10); - if (strOffset + length > fileSize || length <= 0 || length > 512) { - continue; - } - byte[] data = new byte[length]; - raf.seek(strOffset); - raf.readFully(data); - // Platform 0 (Unicode) and 3 (Windows) store UTF-16BE; - // platform 1 (Mac) is close enough to Latin-1 for names. - String value = platform == 1 - ? new String(data, java.nio.charset.StandardCharsets.ISO_8859_1) - : new String(data, java.nio.charset.StandardCharsets.UTF_16BE); - value = value.trim(); - if (value.isEmpty()) { - continue; - } - if (nameId == 1 && family == null) family = value; - if (nameId == 2 && style == null) style = value; - if (nameId == 16 && preferredFamily == null) preferredFamily = value; - if (nameId == 17 && preferredStyle == null) preferredStyle = value; - } - String outFamily = preferredFamily != null ? preferredFamily : family; - String outStyle = preferredStyle != null ? preferredStyle : style; - if (outFamily == null) { - return ""; - } - return outFamily + "\n" + (outStyle == null ? "" : outStyle); - } - } - - private static int readU16(RandomAccessFile raf, long offset) throws Exception { - raf.seek(offset); - byte[] b = new byte[2]; - raf.readFully(b); - return ByteBuffer.wrap(b).order(ByteOrder.BIG_ENDIAN).getShort() & 0xffff; - } - - private static int readU32(RandomAccessFile raf, long offset) throws Exception { - raf.seek(offset); - byte[] b = new byte[4]; - raf.readFully(b); - return ByteBuffer.wrap(b).order(ByteOrder.BIG_ENDIAN).getInt(); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt new file mode 100644 index 00000000..e6b717ec --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt @@ -0,0 +1,574 @@ +package com.faceclaw.app + +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Typeface +import android.os.Build +import android.util.Log + +import java.io.File +import java.io.RandomAccessFile +import java.nio.ByteBuffer +import java.nio.ByteOrder +import java.util.LinkedHashMap + +/** + * Rasterizes text using font files (TTF/OTF/TTC) via the Android text stack, + * so shaping, kerning, and antialiasing are all delegated to + * minikin/HarfBuzz. Output uses the same grayscale packet format as + * ImageFileLoader ([widthLo, widthHi, heightLo, heightHi, pixels...], one + * byte per pixel, row-major), which the TS side turns into a GrayImage and + * the compositor later quantizes to the 4bpp the firmware wants. + * + * The gamma parameter maps antialiased coverage to output shade: + * out = 255 * (coverage/255)^gamma. The G2 display response looks roughly + * linear, so 1.0 is the expected default; the font previewer exposes it for + * on-hardware comparison. + */ +class FontFileRenderer private constructor() { + companion object { + private const val TAG = "FontFileRenderer" + private const val TYPEFACE_CACHE_SIZE = 4 + + /** Small LRU of loaded typefaces keyed by file path. */ + private val typefaceCache: MutableMap = + object : LinkedHashMap(TYPEFACE_CACHE_SIZE, 0.75f, true) { + override fun removeEldestEntry(eldest: MutableMap.MutableEntry): Boolean { + return size > TYPEFACE_CACHE_SIZE + } + } + + /** + * Render one line of text with the given font file at the given pixel + * size. The returned image is the font's full vertical extent (top to + * bottom, taller than ascent+descent), plus any horizontal glyph + * overhang beyond the advance width. + * + * Returns an empty array if the font cannot be loaded or the text + * renders to nothing. + */ + @JvmStatic + fun renderText(path: String?, text: String?, sizePx: Float, gamma: Double): ByteArray { + if (path == null || text == null || sizePx <= 0) { + return ByteArray(0) + } + val typeface = loadTypeface(path) + if (typeface == null) { + return ByteArray(0) + } + try { + val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG) + paint.typeface = typeface + paint.textSize = sizePx + paint.color = Color.WHITE + + // top/bottom (the font's maximal extent) rather than + // ascent/descent, so diacritics and swashes don't clip. + val fm = paint.fontMetricsInt + val ascent = -fm.top + val height = -fm.top + fm.bottom + // measureText gives advance width; italic/swash glyphs can paint + // outside it, so pad by half an em on each side and trim after. + val pad = Math.ceil((sizePx / 2).toDouble()).toInt() + val advance = Math.ceil(paint.measureText(text).toDouble()).toInt() + val width = advance + 2 * pad + if (width <= 0 || height <= 0 || width * height > 4_000_000) { + return ByteArray(0) + } + + val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8) + val canvas = Canvas(bitmap) + canvas.drawText(text, pad.toFloat(), ascent.toFloat(), paint) + val pixels = alpha8Pixels(bitmap, width, height) + bitmap.recycle() + + // Trim the horizontal padding down to the painted extent, but + // keep at least the advance width so spacing stays truthful. + var left = pad + var right = pad + advance + val painted = paintedColumnRange(pixels, width, height) + if (painted != null) { + left = Math.min(left, painted[0]) + right = Math.max(right, painted[1] + 1) + } + val outWidth = Math.max(1, right - left) + + val lut = gammaLut(gamma) + val out = ByteArray(4 + outWidth * height) + out[0] = (outWidth and 0xff).toByte() + out[1] = ((outWidth shr 8) and 0xff).toByte() + out[2] = (height and 0xff).toByte() + out[3] = ((height shr 8) and 0xff).toByte() + for (y in 0 until height) { + val srcRow = y * width + val dstRow = 4 + y * outWidth + for (x in 0 until outWidth) { + out[dstRow + x] = lut[pixels[srcRow + left + x].toInt() and 0xff] + } + } + return out + } catch (e: Exception) { + Log.w(TAG, "text render failed: $path", e) + return ByteArray(0) + } catch (e: OutOfMemoryError) { + Log.w(TAG, "text render failed: $path", e) + return ByteArray(0) + } + } + + /** + * Render a multi-line block of text wrapped to maxWidth, with line + * breaking delegated to StaticLayout (so it matches Android text + * behavior, including breaking inside long words). Truncated with an + * ellipsis past maxLines. Same packet format as renderText. + */ + @JvmStatic + fun renderWrapped( + path: String?, text: String?, sizePx: Float, maxWidth: Int, gamma: Double, maxLines: Int): ByteArray { + if (path == null || text == null || sizePx <= 0 || maxWidth <= 0 || maxLines <= 0) { + return ByteArray(0) + } + val typeface = loadTypeface(path) + if (typeface == null) { + return ByteArray(0) + } + try { + val paint = android.text.TextPaint(Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG) + paint.typeface = typeface + paint.textSize = sizePx + paint.color = Color.WHITE + paint.hinting = Paint.HINTING_ON + + val layout = android.text.StaticLayout.Builder + .obtain(text, 0, text.length, paint, maxWidth) + .setAlignment(android.text.Layout.Alignment.ALIGN_NORMAL) + .setIncludePad(false) + .setMaxLines(maxLines) + .setEllipsize(android.text.TextUtils.TruncateAt.END) + .build() + val height = Math.max(1, layout.height) + if (maxWidth.toLong() * height > 4_000_000L) { + return ByteArray(0) + } + + val bitmap = Bitmap.createBitmap(maxWidth, height, Bitmap.Config.ALPHA_8) + val canvas = Canvas(bitmap) + layout.draw(canvas) + val pixels = alpha8Pixels(bitmap, maxWidth, height) + bitmap.recycle() + + val lut = gammaLut(gamma) + val out = ByteArray(4 + pixels.size) + out[0] = (maxWidth and 0xff).toByte() + out[1] = ((maxWidth shr 8) and 0xff).toByte() + out[2] = (height and 0xff).toByte() + out[3] = ((height shr 8) and 0xff).toByte() + for (i in pixels.indices) { + out[4 + i] = lut[pixels[i].toInt() and 0xff] + } + return out + } catch (e: Exception) { + Log.w(TAG, "wrapped render failed: $path", e) + return ByteArray(0) + } catch (e: OutOfMemoryError) { + Log.w(TAG, "wrapped render failed: $path", e) + return ByteArray(0) + } + } + + /** + * Render one codepoint as a tight-ink-box antialiased glyph cell for the + * texture-cache text pipeline (see app/graphics/ttf-font.ts). Ligatures + * are disabled so a per-codepoint raster plus pairwise kerning (measured + * via measureTextExact) fully describes a line. Little-endian packet: + * [advance u16, 26.6 fixed point] + * [bearingX s16] ink left relative to the pen position + * [inkTop s16] ink top relative to the line top (ascent above baseline) + * [width u16][height u16] + * [width*height coverage bytes, gamma-mapped] + * An ink-free glyph (space) has width = height = 0 but a valid advance. + * Empty array when the font cannot be loaded or the render fails. + */ + @JvmStatic + fun renderGlyphCell(path: String?, sizePx: Float, codePoint: Int, gamma: Double): ByteArray { + val typeface = loadTypeface(path) + if (typeface == null || sizePx <= 0 || codePoint < 0 || codePoint > 0x10ffff) { + return ByteArray(0) + } + try { + val paint = glyphPaint(typeface, sizePx) + val text = String(Character.toChars(codePoint)) + val advance = paint.measureText(text) + val advanceFixed = Math.max(0, Math.min(0xffff, Math.round(advance * 64f))) + + val bounds = android.graphics.Rect() + paint.getTextBounds(text, 0, text.length, bounds) + if (bounds.isEmpty) { + return glyphCellPacket(advanceFixed, 0, 0, 0, 0, null) + } + // getTextBounds can be off by a hair on AA edges; render with + // padding, then trim to the actually painted box. + val pad = 2 + val bw = bounds.width() + 2 * pad + val bh = bounds.height() + 2 * pad + if (bw <= 0 || bh <= 0 || bw * bh > 1_000_000) { + return ByteArray(0) + } + val penX = pad - bounds.left + val baselineY = pad - bounds.top + val bitmap = Bitmap.createBitmap(bw, bh, Bitmap.Config.ALPHA_8) + val canvas = Canvas(bitmap) + canvas.drawText(text, penX.toFloat(), baselineY.toFloat(), paint) + val pixels = alpha8Pixels(bitmap, bw, bh) + bitmap.recycle() + + var x0 = bw + var x1 = -1 + var y0 = bh + var y1 = -1 + for (y in 0 until bh) { + val row = y * bw + for (x in 0 until bw) { + if (pixels[row + x].toInt() != 0) { + if (x < x0) x0 = x + if (x > x1) x1 = x + if (y < y0) y0 = y + if (y > y1) y1 = y + } + } + } + if (x1 < x0) { + return glyphCellPacket(advanceFixed, 0, 0, 0, 0, null) + } + val width = x1 - x0 + 1 + val height = y1 - y0 + 1 + val fm = paint.fontMetricsInt + val bearingX = x0 - penX + val inkTop = (-fm.ascent) + (y0 - baselineY) + + val lut = gammaLut(gamma) + val coverage = ByteArray(width * height) + for (y in 0 until height) { + val src = (y0 + y) * bw + x0 + val dst = y * width + for (x in 0 until width) { + coverage[dst + x] = lut[pixels[src + x].toInt() and 0xff] + } + } + return glyphCellPacket(advanceFixed, bearingX, inkTop, width, height, coverage) + } catch (e: Exception) { + Log.w(TAG, "glyph render failed: " + path + " U+" + Integer.toHexString(codePoint), e) + return ByteArray(0) + } catch (e: OutOfMemoryError) { + Log.w(TAG, "glyph render failed: " + path + " U+" + Integer.toHexString(codePoint), e) + return ByteArray(0) + } + } + + /** + * Exact (float) advance width of a text run, with the same paint setup as + * renderGlyphCell (subpixel advances, ligatures off), so pair kerning can + * be derived as measure(ab) - measure(a) - measure(b). + */ + @JvmStatic + fun measureTextExact(path: String?, text: String?, sizePx: Float): Double { + val typeface = loadTypeface(path) + if (typeface == null || text == null || sizePx <= 0) { + return 0.0 + } + return glyphPaint(typeface, sizePx).measureText(text).toDouble() + } + + /** Paint used by both the glyph-cell renderer and its measurements. */ + @JvmStatic + private fun glyphPaint(typeface: Typeface, sizePx: Float): Paint { + val paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG) + paint.typeface = typeface + paint.textSize = sizePx + paint.color = Color.WHITE + // Ligatures merge codepoints into one glyph, which the per-codepoint + // cache model cannot represent; kerning still applies. + paint.fontFeatureSettings = "'liga' off, 'clig' off" + return paint + } + + @JvmStatic + private fun glyphCellPacket( + advanceFixed: Int, bearingX: Int, inkTop: Int, width: Int, height: Int, coverage: ByteArray?): ByteArray { + val out = ByteArray(10 + (coverage?.size ?: 0)) + out[0] = (advanceFixed and 0xff).toByte() + out[1] = ((advanceFixed shr 8) and 0xff).toByte() + out[2] = (bearingX and 0xff).toByte() + out[3] = ((bearingX shr 8) and 0xff).toByte() + out[4] = (inkTop and 0xff).toByte() + out[5] = ((inkTop shr 8) and 0xff).toByte() + out[6] = (width and 0xff).toByte() + out[7] = ((width shr 8) and 0xff).toByte() + out[8] = (height and 0xff).toByte() + out[9] = ((height shr 8) and 0xff).toByte() + if (coverage != null) { + System.arraycopy(coverage, 0, out, 10, coverage.size) + } + return out + } + + /** + * Line metrics for a font at a pixel size, as "ascent descent lineGap" + * (integers, pixels). Empty string if the font cannot be loaded. + */ + @JvmStatic + fun getFontMetrics(path: String?, sizePx: Float): String { + val typeface = loadTypeface(path) + if (typeface == null || sizePx <= 0) { + return "" + } + val paint = Paint(Paint.ANTI_ALIAS_FLAG) + paint.typeface = typeface + paint.textSize = sizePx + val fm = paint.fontMetricsInt + val lineGap = fm.leading + return (-fm.ascent).toString() + " " + fm.descent + " " + lineGap + } + + /** Advance width in pixels of a line of text (rounded up). */ + @JvmStatic + fun measureText(path: String?, text: String?, sizePx: Float): Int { + val typeface = loadTypeface(path) + if (typeface == null || text == null || sizePx <= 0) { + return 0 + } + val paint = Paint(Paint.ANTI_ALIAS_FLAG) + paint.typeface = typeface + paint.textSize = sizePx + return Math.ceil(paint.measureText(text).toDouble()).toInt() + } + + /** + * Whether the font file loads at all (strictly validated on API 29+; + * best-effort below that). + */ + @JvmStatic + fun canLoadFont(path: String?): Boolean { + return loadTypeface(path) != null + } + + /** + * The font's family and style names from its 'name' table, as + * "Family\nStyle" ("Style" may be empty). Falls back to "" when the + * table cannot be parsed; callers should then use the filename. + */ + @JvmStatic + fun getFontName(path: String?): String { + try { + return parseNameTable(path) + } catch (e: Exception) { + Log.w(TAG, "name table parse failed: $path", e) + return "" + } + } + + @JvmStatic + @Synchronized + private fun loadTypeface(path: String?): Typeface? { + if (path == null) { + return null + } + val cached = typefaceCache[path] + if (cached != null) { + return cached + } + val file = File(path) + if (!file.isFile || !file.canRead()) { + return null + } + var typeface: Typeface? = null + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + // Strict path: Font.Builder throws on files that are not + // valid fonts, unlike createFromFile which silently falls + // back to the default typeface. + val font = android.graphics.fonts.Font.Builder(file).build() + typeface = Typeface.CustomFallbackBuilder( + android.graphics.fonts.FontFamily.Builder(font).build()) + .build() + } else { + typeface = Typeface.createFromFile(file) + if (typeface == null || typeface == Typeface.DEFAULT) { + typeface = null + } + } + } catch (e: Exception) { + Log.w(TAG, "font load failed: $path: $e") + typeface = null + } catch (e: LinkageError) { + Log.w(TAG, "font load failed: $path: $e") + typeface = null + } + if (typeface != null) { + typefaceCache[path] = typeface + } + return typeface + } + + /** + * The coverage bytes of an ALPHA_8 bitmap as a tightly-packed + * width*height array (copyPixelsToBuffer copies rowBytes*height, and the + * row stride is not guaranteed to equal the width). + */ + @JvmStatic + private fun alpha8Pixels(bitmap: Bitmap, width: Int, height: Int): ByteArray { + val rowBytes = bitmap.rowBytes + val raw = ByteArray(rowBytes * height) + bitmap.copyPixelsToBuffer(ByteBuffer.wrap(raw)) + if (rowBytes == width) { + return raw + } + val pixels = ByteArray(width * height) + for (y in 0 until height) { + System.arraycopy(raw, y * rowBytes, pixels, y * width, width) + } + return pixels + } + + /** [first, last] painted (nonzero) column indexes, or null if blank. */ + @JvmStatic + private fun paintedColumnRange(pixels: ByteArray, width: Int, height: Int): IntArray? { + var first = width + var last = -1 + for (y in 0 until height) { + val row = y * width + var x = 0 + while (x < first) { + if (pixels[row + x].toInt() != 0) { + first = x + break + } + x++ + } + x = width - 1 + while (x > last) { + if (pixels[row + x].toInt() != 0) { + last = x + break + } + x-- + } + } + return if (last >= first) intArrayOf(first, last) else null + } + + @JvmStatic + private fun gammaLut(gammaIn: Double): ByteArray { + val lut = ByteArray(256) + var gamma = gammaIn + if (gamma <= 0) { + gamma = 1.0 + } + for (i in 0 until 256) { + lut[i] = Math.max(0, Math.min(255, + Math.round(255.0 * Math.pow(i / 255.0, gamma)).toInt())).toByte() + } + return lut + } + + // --- Minimal 'name' table reader (TTF/OTF/TTC) for preview titles --- + + @JvmStatic + @Throws(Exception::class) + private fun parseNameTable(path: String?): String { + RandomAccessFile(path, "r").use { raf -> + val fileSize = raf.length() + if (fileSize < 12) { + return "" + } + var offset = 0L + val tag = readU32(raf, 0) + if (tag == 0x74746366) { // 'ttcf': use the first face + if (readU32(raf, 8) < 1) { + return "" + } + offset = readU32(raf, 12).toLong() and 0xffffffffL + } + val numTables = readU16(raf, offset + 4) + var nameOffset = -1L + for (i in 0 until numTables) { + val rec = offset + 12 + i * 16L + if (rec + 16 > fileSize) { + return "" + } + if (readU32(raf, rec) == 0x6e616d65) { // 'name' + nameOffset = readU32(raf, rec + 8).toLong() and 0xffffffffL + break + } + } + if (nameOffset < 0 || nameOffset + 6 > fileSize) { + return "" + } + val count = readU16(raf, nameOffset + 2) + val stringStorage = nameOffset + readU16(raf, nameOffset + 4) + var family: String? = null + var style: String? = null + var preferredFamily: String? = null + var preferredStyle: String? = null + for (i in 0 until count) { + val rec = nameOffset + 6 + i * 12L + if (rec + 12 > fileSize) { + break + } + val platform = readU16(raf, rec) + val nameId = readU16(raf, rec + 6) + if (nameId != 1 && nameId != 2 && nameId != 16 && nameId != 17) { + continue + } + val length = readU16(raf, rec + 8) + val strOffset = stringStorage + readU16(raf, rec + 10) + if (strOffset + length > fileSize || length <= 0 || length > 512) { + continue + } + val data = ByteArray(length) + raf.seek(strOffset) + raf.readFully(data) + // Platform 0 (Unicode) and 3 (Windows) store UTF-16BE; + // platform 1 (Mac) is close enough to Latin-1 for names. + var value = if (platform == 1) + String(data, java.nio.charset.StandardCharsets.ISO_8859_1) + else String(data, java.nio.charset.StandardCharsets.UTF_16BE) + value = value.trim() + if (value.isEmpty()) { + continue + } + if (nameId == 1 && family == null) family = value + if (nameId == 2 && style == null) style = value + if (nameId == 16 && preferredFamily == null) preferredFamily = value + if (nameId == 17 && preferredStyle == null) preferredStyle = value + } + val outFamily = preferredFamily ?: family + val outStyle = preferredStyle ?: style + if (outFamily == null) { + return "" + } + return outFamily + "\n" + (outStyle ?: "") + } + } + + @JvmStatic + @Throws(Exception::class) + private fun readU16(raf: RandomAccessFile, offset: Long): Int { + raf.seek(offset) + val b = ByteArray(2) + raf.readFully(b) + return ByteBuffer.wrap(b).order(ByteOrder.BIG_ENDIAN).getShort().toInt() and 0xffff + } + + @JvmStatic + @Throws(Exception::class) + private fun readU32(raf: RandomAccessFile, offset: Long): Int { + raf.seek(offset) + val b = ByteArray(4) + raf.readFully(b) + return ByteBuffer.wrap(b).order(ByteOrder.BIG_ENDIAN).getInt() + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.java deleted file mode 100644 index 4dba5ac0..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.java +++ /dev/null @@ -1,567 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; -import android.os.SystemClock; -import android.util.Log; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * Per-frame timing instrumentation, shared between the Java BLE layer and the - * Typescript UI layer. A "frame" starts when we receive an input event (or a - * timer fires and we decide to redraw), and finishes when the resulting screen - * update has been fully transmitted to the glasses, is discarded unsent, or - * times out because nobody reported finishing it. - * - * Frames form a tree. One input event can fan out into several renders (the - * focused app's window plus the shell chrome, say), and each of those is its - * own frame linked back to the input frame that caused it via - * {@link #startFrame(String, int)}. The export nests descendants under their - * root and renders every line against the root's clock, so a single block - * shows the whole input-to-pixels story. Latency percentiles are measured over - * roots: root start to the first descendant that actually reached the glasses. - * - * All public methods are thread-safe and cheap enough to call from the BLE - * worker thread, the Android main thread, the JS thread, and app worker - * threads. Frame IDs are positive ints; 0 means "no frame" and is silently - * ignored everywhere, so callers do not need to null-check. - * - * Statistics and full log lines for recent and slowest frames are periodically - * exported to getExternalFilesDir()/frame-timings.txt, retrievable via - * adb pull /sdcard/Android/data//files/frame-timings.txt - */ -public final class FrameTimings { - private static final String TAG = "FrameTimings"; - private static final FrameTimings INSTANCE = new FrameTimings(); - - /** Frames still open after this long are finished as "timeout". */ - private static final long FRAME_TIMEOUT_MS = 30_000; - private static final long EXPORT_INTERVAL_MS = 15_000; - private static final long SWEEP_INTERVAL_MS = 5_000; - private static final int RECENT_ROOTS_KEPT = 40; - private static final int SLOWEST_ROOTS_KEPT = 20; - private static final int SENT_DURATIONS_WINDOW = 512; - private static final int MAX_LINES_PER_FRAME = 200; - /** - * Frames retained for ID lookup. Well above the number any export can - * reference, so a late log/span/finish call always finds its frame; frames - * older than this are unreachable and get collected. - */ - private static final int FRAMES_RETAINED = 1024; - private static final String EXPORT_FILE_NAME = "frame-timings.txt"; - - public static FrameTimings getInstance() { - return INSTANCE; - } - - private static final class Line { - final long atMs; // SystemClock.elapsedRealtime() - final String thread; - final String message; - - Line(long atMs, String thread, String message) { - this.atMs = atMs; - this.thread = thread; - this.message = message; - } - } - - private static final class Frame { - final int id; - final long startedAtMs; // SystemClock.elapsedRealtime() - final long startedWallClockMs; - final Frame parent; - final List children = new ArrayList<>(0); - final List lines = new ArrayList<>(); - final Map openSpans = new LinkedHashMap<>(); - String reason; - long finishedAtMs; - String outcome; // null while open; "sent", "discarded: ...", "timeout: ..." - /** Set on the root once some frame in its subtree reached the glasses. */ - boolean subtreeSentRecorded; - - Frame(int id, String reason, long startedAtMs, long startedWallClockMs, Frame parent) { - this.id = id; - this.reason = reason; - this.startedAtMs = startedAtMs; - this.startedWallClockMs = startedWallClockMs; - this.parent = parent; - } - - Frame root() { - Frame frame = this; - while (frame.parent != null) { - frame = frame.parent; - } - return frame; - } - - boolean isOpen() { - return outcome == null; - } - - long durationMs() { - return finishedAtMs - startedAtMs; - } - - boolean wasSent() { - return outcome != null && outcome.startsWith("sent"); - } - - /** Last moment anything in this subtree happened, for whole-tree duration. */ - long subtreeEndAtMs(long nowMs) { - long end = isOpen() ? nowMs : finishedAtMs; - for (Frame child : children) { - end = Math.max(end, child.subtreeEndAtMs(nowMs)); - } - return end; - } - - boolean subtreeHasOpenFrame() { - if (isOpen()) { - return true; - } - for (Frame child : children) { - if (child.subtreeHasOpenFrame()) { - return true; - } - } - return false; - } - } - - private final Object lock = new Object(); - /** - * Every frame we still retain, keyed by ID: open frames plus enough - * history that late calls and the export can still resolve one. - */ - private final LinkedHashMap framesById = - new LinkedHashMap(64, 0.75f, false) { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > FRAMES_RETAINED && !eldest.getValue().isOpen(); - } - }; - private final ArrayDeque recentRoots = new ArrayDeque<>(); - private final List slowestRoots = new ArrayList<>(); - private final ArrayDeque inputLatencies = new ArrayDeque<>(); - private final ArrayDeque renderLatencies = new ArrayDeque<>(); - private int nextFrameId = 1; - private long framesStarted; - private long framesSent; - private long framesDiscarded; - private long framesTimedOut; - private boolean exportDirty; - private File exportDir; - private Thread exportThread; - - private FrameTimings() { - } - - /** Idempotent; enables filesystem export. Safe to call from any constructor path. */ - public void init(Context context) { - File dir = context.getApplicationContext().getExternalFilesDir(null); - if (dir == null) { - dir = context.getApplicationContext().getFilesDir(); - } - synchronized (lock) { - exportDir = dir; - if (exportThread == null) { - exportThread = new Thread(this::exportLoop, "FrameTimingsExport"); - exportThread.setDaemon(true); - exportThread.start(); - } - } - } - - /** Begin a root frame; reason is a short label like "input:sys-event type=0". */ - public int startFrame(String reason) { - return startFrame(reason, 0); - } - - /** - * Begin a frame caused by an existing one (parentFrameId; 0 for a root). - * The child is nested under its root in the export and its latency counts - * against the root, so an input event that fans out into an app render and - * a shell-chrome render reads as one timeline instead of three. - */ - public int startFrame(String reason, int parentFrameId) { - long now = SystemClock.elapsedRealtime(); - Frame frame; - synchronized (lock) { - Frame parent = framesById.get(parentFrameId); - frame = new Frame(nextFrameId++, reason == null ? "" : reason, now, - System.currentTimeMillis(), parent); - framesById.put(frame.id, frame); - framesStarted++; - if (parent != null) { - parent.children.add(frame); - addLineLocked(parent, now, "spawned frame#" + frame.id + " (" + frame.reason + ")"); - } - } - return frame.id; - } - - /** - * Append to a frame's label, for facts only known after it started (which - * app is in the foreground, which window a render is for). Shows up in the - * frame's header line, so the export is scannable without reading bodies. - */ - public void annotate(int frameId, String text) { - if (text == null || text.isEmpty()) { - return; - } - synchronized (lock) { - Frame frame = framesById.get(frameId); - if (frame == null) { - return; - } - frame.reason = frame.reason.isEmpty() ? text : frame.reason + " " + text; - } - } - - public void log(int frameId, String message) { - long now = SystemClock.elapsedRealtime(); - synchronized (lock) { - Frame frame = openFrameLocked(frameId); - if (frame == null) { - return; - } - addLineLocked(frame, now, message); - } - } - - public void spanStart(int frameId, String name) { - long now = SystemClock.elapsedRealtime(); - synchronized (lock) { - Frame frame = openFrameLocked(frameId); - if (frame == null) { - return; - } - frame.openSpans.put(name, now); - addLineLocked(frame, now, "span " + name + " start"); - } - } - - public void spanEnd(int frameId, String name) { - long now = SystemClock.elapsedRealtime(); - synchronized (lock) { - Frame frame = openFrameLocked(frameId); - if (frame == null) { - return; - } - Long startedAt = frame.openSpans.remove(name); - if (startedAt == null) { - addLineLocked(frame, now, "span " + name + " end (start not recorded)"); - } else { - addLineLocked(frame, now, "span " + name + " end (" + (now - startedAt) + "ms)"); - } - } - } - - /** - * Finish a frame. Outcomes: "sent" (counted in latency percentiles), anything - * starting with "discarded", or "timeout". First finish wins; later calls for - * the same frame are ignored, so racing completion paths are safe. - */ - public void finishFrame(int frameId, String outcome) { - long now = SystemClock.elapsedRealtime(); - Frame finished; - synchronized (lock) { - Frame frame = openFrameLocked(frameId); - if (frame == null) { - return; - } - finishFrameLocked(frame, now, outcome == null ? "discarded: no outcome given" : outcome); - finished = frame; - } - Log.i(TAG, "frame#" + finished.id + " [" + finished.reason + "] -> " + finished.outcome - + " in " + finished.durationMs() + "ms"); - } - - /** One-line stats summary, e.g. for showing in the phone UI. */ - public String statsSummary() { - synchronized (lock) { - long[] input = percentilesLocked(inputLatencies); - return "frames started=" + framesStarted + " sent=" + framesSent - + " discarded=" + framesDiscarded + " timeout=" + framesTimedOut - + (input == null - ? "" - : " | input-to-display p50=" + input[0] + "ms p90=" + input[1] - + "ms p99=" + input[2] + "ms max=" + input[3] + "ms"); - } - } - - // --------------------------------------------------------------------- - - /** The frame with this ID if it exists and is still open, else null. */ - private Frame openFrameLocked(int frameId) { - if (frameId <= 0) { - return null; - } - Frame frame = framesById.get(frameId); - return frame != null && frame.isOpen() ? frame : null; - } - - private void addLineLocked(Frame frame, long now, String message) { - if (frame.lines.size() >= MAX_LINES_PER_FRAME) { - if (frame.lines.size() == MAX_LINES_PER_FRAME) { - frame.lines.add(new Line(now, Thread.currentThread().getName(), "... line cap reached")); - } - return; - } - frame.lines.add(new Line(now, Thread.currentThread().getName(), message)); - } - - private void finishFrameLocked(Frame frame, long now, String outcome) { - frame.finishedAtMs = now; - frame.outcome = outcome; - for (Map.Entry open : frame.openSpans.entrySet()) { - frame.lines.add(new Line(now, Thread.currentThread().getName(), - "span " + open.getKey() + " never ended (started at +" - + (open.getValue() - frame.startedAtMs) + "ms)")); - } - frame.openSpans.clear(); - addLineLocked(frame, now, "finished: " + outcome); - - Frame root = frame.root(); - if (frame.wasSent()) { - framesSent++; - // The user-visible latency is input (or timer) to the first pixels - // that actually reached the glasses, wherever in the tree that was. - if (!root.subtreeSentRecorded) { - root.subtreeSentRecorded = true; - recordLatencyLocked(root, now - root.startedAtMs); - insertSlowestLocked(root); - } - } else if (outcome.startsWith("timeout")) { - framesTimedOut++; - } else { - framesDiscarded++; - } - - if (root == frame) { - recentRoots.addLast(frame); - while (recentRoots.size() > RECENT_ROOTS_KEPT) { - recentRoots.removeFirst(); - } - } - exportDirty = true; - } - - private void recordLatencyLocked(Frame root, long latencyMs) { - ArrayDeque bucket = root.reason.startsWith("input:") ? inputLatencies : renderLatencies; - bucket.addLast(latencyMs); - while (bucket.size() > SENT_DURATIONS_WINDOW) { - bucket.removeFirst(); - } - } - - private void insertSlowestLocked(Frame root) { - if (!slowestRoots.contains(root)) { - slowestRoots.add(root); - } - // Sorted and trimmed at export time, when every subtree duration is final. - } - - /** {p50, p90, p99, max} over a rolling latency window, or null if empty. */ - private long[] percentilesLocked(ArrayDeque window) { - if (window.isEmpty()) { - return null; - } - List sorted = new ArrayList<>(window); - Collections.sort(sorted); - return new long[] { - percentileOfSorted(sorted, 50), - percentileOfSorted(sorted, 90), - percentileOfSorted(sorted, 99), - sorted.get(sorted.size() - 1), - }; - } - - private static long percentileOfSorted(List sorted, int percentile) { - int index = (int) Math.ceil(percentile / 100.0 * sorted.size()) - 1; - return sorted.get(Math.max(0, Math.min(sorted.size() - 1, index))); - } - - private void sweepTimedOutFrames() { - long now = SystemClock.elapsedRealtime(); - List timedOut = new ArrayList<>(); - synchronized (lock) { - for (Frame frame : new ArrayList<>(framesById.values())) { - if (frame.isOpen() && now - frame.startedAtMs >= FRAME_TIMEOUT_MS) { - finishFrameLocked(frame, now, "timeout: never reported finished"); - timedOut.add(frame); - } - } - } - for (Frame frame : timedOut) { - Log.w(TAG, "frame#" + frame.id + " [" + frame.reason + "] timed out after " - + frame.durationMs() + "ms without being finished"); - } - } - - private void exportLoop() { - long lastExportAtMs = 0; - while (true) { - try { - Thread.sleep(SWEEP_INTERVAL_MS); - } catch (InterruptedException e) { - return; - } - try { - sweepTimedOutFrames(); - long now = SystemClock.elapsedRealtime(); - boolean shouldExport; - synchronized (lock) { - shouldExport = exportDirty && exportDir != null && now - lastExportAtMs >= EXPORT_INTERVAL_MS; - } - if (shouldExport) { - lastExportAtMs = now; - exportToFile(); - } - } catch (Throwable t) { - Log.w(TAG, "export loop error", t); - } - } - } - - private void exportToFile() { - String content; - File dir; - synchronized (lock) { - dir = exportDir; - if (dir == null) { - return; - } - content = buildExportLocked(); - exportDirty = false; - } - File target = new File(dir, EXPORT_FILE_NAME); - File temp = new File(dir, EXPORT_FILE_NAME + ".tmp"); - try { - try (Writer writer = new OutputStreamWriter(new FileOutputStream(temp), StandardCharsets.UTF_8)) { - writer.write(content); - } - if (!temp.renameTo(target)) { - Log.w(TAG, "failed to rename " + temp + " to " + target); - } - } catch (Throwable t) { - Log.w(TAG, "failed to export frame timings", t); - } - } - - private String buildExportLocked() { - long now = SystemClock.elapsedRealtime(); - SimpleDateFormat wallClockFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); - StringBuilder out = new StringBuilder(64 * 1024); - out.append("FrameTimings export at ").append(wallClockFormat.format(new Date())).append('\n'); - out.append(statsSummaryLocked()).append('\n'); - out.append('\n'); - out.append("Frames are trees: an input event's own frame is the root, and the renders it\n"); - out.append("caused are indented under it with offsets measured from the root's start.\n"); - out.append('\n'); - - Collections.sort(slowestRoots, (a, b) -> - Long.compare(b.subtreeEndAtMs(now) - b.startedAtMs, a.subtreeEndAtMs(now) - a.startedAtMs)); - while (slowestRoots.size() > SLOWEST_ROOTS_KEPT) { - slowestRoots.remove(slowestRoots.size() - 1); - } - - out.append("=== slowest frames that reached the glasses ===\n"); - for (Frame frame : slowestRoots) { - appendTreeLocked(out, frame, frame, wallClockFormat, now); - } - - out.append("=== recent frames (oldest first) ===\n"); - for (Frame frame : recentRoots) { - appendTreeLocked(out, frame, frame, wallClockFormat, now); - } - return out.toString(); - } - - private String statsSummaryLocked() { - long[] input = percentilesLocked(inputLatencies); - long[] render = percentilesLocked(renderLatencies); - StringBuilder out = new StringBuilder(); - out.append("frames started=").append(framesStarted).append(" sent=").append(framesSent) - .append(" discarded=").append(framesDiscarded).append(" timeout=").append(framesTimedOut) - .append(" open=").append(openFrameCountLocked()); - appendPercentilesLocked(out, "input-to-display latency", inputLatencies.size(), input); - appendPercentilesLocked(out, "render-to-display latency", renderLatencies.size(), render); - return out.toString(); - } - - private void appendPercentilesLocked(StringBuilder out, String label, int count, long[] percentiles) { - if (percentiles == null) { - return; - } - out.append('\n').append(label).append(" (last ").append(count).append("): p50=") - .append(percentiles[0]).append("ms p90=").append(percentiles[1]) - .append("ms p99=").append(percentiles[2]).append("ms max=").append(percentiles[3]).append("ms"); - } - - private int openFrameCountLocked() { - int open = 0; - for (Frame frame : framesById.values()) { - if (frame.isOpen()) { - open++; - } - } - return open; - } - - /** Print a frame and its descendants, all timed against root's start. */ - private void appendTreeLocked( - StringBuilder out, Frame frame, Frame root, SimpleDateFormat wallClockFormat, long now) { - int depth = 0; - for (Frame walk = frame; walk != root; walk = walk.parent) { - depth++; - } - String indent = repeat(" ", depth); - long startOffsetMs = frame.startedAtMs - root.startedAtMs; - out.append(indent).append("frame#").append(frame.id) - .append(" [").append(frame.reason).append(']'); - if (frame == root) { - out.append(" started ").append(wallClockFormat.format(new Date(frame.startedWallClockMs))); - long totalMs = frame.subtreeEndAtMs(now) - frame.startedAtMs; - out.append(" duration ").append(frame.durationMs()).append("ms"); - if (!frame.children.isEmpty()) { - out.append(" (tree ").append(totalMs).append("ms") - .append(frame.subtreeHasOpenFrame() ? ", still open" : "").append(')'); - } - } else { - out.append(" started +").append(startOffsetMs).append("ms") - .append(" duration ").append(frame.isOpen() ? "open" : (frame.durationMs() + "ms")); - } - out.append(" outcome ").append(frame.outcome == null ? "(open)" : frame.outcome).append('\n'); - for (Line line : frame.lines) { - out.append(indent).append(String.format(Locale.US, " %+7dms [%s] %s", - line.atMs - root.startedAtMs, line.thread, line.message)).append('\n'); - } - for (Frame child : frame.children) { - appendTreeLocked(out, child, root, wallClockFormat, now); - } - } - - private static String repeat(String unit, int times) { - StringBuilder out = new StringBuilder(unit.length() * times); - for (int i = 0; i < times; i++) { - out.append(unit); - } - return out.toString(); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt new file mode 100644 index 00000000..fdf2ce4d --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt @@ -0,0 +1,554 @@ +package com.faceclaw.app + +import android.content.Context +import android.os.SystemClock +import android.util.Log + +import java.io.File +import java.io.FileOutputStream +import java.io.OutputStreamWriter +import java.io.Writer +import java.nio.charset.StandardCharsets +import java.text.SimpleDateFormat +import java.util.ArrayDeque +import java.util.ArrayList +import java.util.Collections +import java.util.Date +import java.util.LinkedHashMap +import java.util.Locale + +/** + * Per-frame timing instrumentation, shared between the Java BLE layer and the + * Typescript UI layer. A "frame" starts when we receive an input event (or a + * timer fires and we decide to redraw), and finishes when the resulting screen + * update has been fully transmitted to the glasses, is discarded unsent, or + * times out because nobody reported finishing it. + * + * Frames form a tree. One input event can fan out into several renders (the + * focused app's window plus the shell chrome, say), and each of those is its + * own frame linked back to the input frame that caused it via + * [startFrame]. The export nests descendants under their + * root and renders every line against the root's clock, so a single block + * shows the whole input-to-pixels story. Latency percentiles are measured over + * roots: root start to the first descendant that actually reached the glasses. + * + * All public methods are thread-safe and cheap enough to call from the BLE + * worker thread, the Android main thread, the JS thread, and app worker + * threads. Frame IDs are positive ints; 0 means "no frame" and is silently + * ignored everywhere, so callers do not need to null-check. + * + * Statistics and full log lines for recent and slowest frames are periodically + * exported to getExternalFilesDir()/frame-timings.txt, retrievable via + * adb pull /sdcard/Android/data//files/frame-timings.txt + */ +class FrameTimings private constructor() { + companion object { + private const val TAG = "FrameTimings" + private val INSTANCE = FrameTimings() + + /** Frames still open after this long are finished as "timeout". */ + private const val FRAME_TIMEOUT_MS = 30_000L + private const val EXPORT_INTERVAL_MS = 15_000L + private const val SWEEP_INTERVAL_MS = 5_000L + private const val RECENT_ROOTS_KEPT = 40 + private const val SLOWEST_ROOTS_KEPT = 20 + private const val SENT_DURATIONS_WINDOW = 512 + private const val MAX_LINES_PER_FRAME = 200 + /** + * Frames retained for ID lookup. Well above the number any export can + * reference, so a late log/span/finish call always finds its frame; frames + * older than this are unreachable and get collected. + */ + private const val FRAMES_RETAINED = 1024 + private const val EXPORT_FILE_NAME = "frame-timings.txt" + + @JvmStatic + fun getInstance(): FrameTimings { + return INSTANCE + } + + @JvmStatic + private fun percentileOfSorted(sorted: List, percentile: Int): Long { + val index = Math.ceil(percentile / 100.0 * sorted.size).toInt() - 1 + return sorted[Math.max(0, Math.min(sorted.size - 1, index))] + } + + @JvmStatic + private fun repeat(unit: String, times: Int): String { + val out = StringBuilder(unit.length * times) + for (i in 0 until times) { + out.append(unit) + } + return out.toString() + } + } + + private class Line( + val atMs: Long, // SystemClock.elapsedRealtime() + val thread: String, + val message: String? + ) + + private class Frame( + val id: Int, + var reason: String, + val startedAtMs: Long, // SystemClock.elapsedRealtime() + val startedWallClockMs: Long, + val parent: Frame? + ) { + val children: MutableList = ArrayList(0) + val lines: MutableList = ArrayList() + val openSpans: MutableMap = LinkedHashMap() + var finishedAtMs: Long = 0 + var outcome: String? = null // null while open; "sent", "discarded: ...", "timeout: ..." + /** Set on the root once some frame in its subtree reached the glasses. */ + var subtreeSentRecorded = false + + fun root(): Frame { + var frame: Frame = this + while (frame.parent != null) { + frame = frame.parent!! + } + return frame + } + + fun isOpen(): Boolean { + return outcome == null + } + + fun durationMs(): Long { + return finishedAtMs - startedAtMs + } + + fun wasSent(): Boolean { + val outcome = this.outcome + return outcome != null && outcome.startsWith("sent") + } + + /** Last moment anything in this subtree happened, for whole-tree duration. */ + fun subtreeEndAtMs(nowMs: Long): Long { + var end = if (isOpen()) nowMs else finishedAtMs + for (child in children) { + end = Math.max(end, child.subtreeEndAtMs(nowMs)) + } + return end + } + + fun subtreeHasOpenFrame(): Boolean { + if (isOpen()) { + return true + } + for (child in children) { + if (child.subtreeHasOpenFrame()) { + return true + } + } + return false + } + } + + private val lock = Any() + /** + * Every frame we still retain, keyed by ID: open frames plus enough + * history that late calls and the export can still resolve one. + */ + private val framesById: LinkedHashMap = + object : LinkedHashMap(64, 0.75f, false) { + override fun removeEldestEntry(eldest: MutableMap.MutableEntry): Boolean { + return size > FRAMES_RETAINED && !eldest.value.isOpen() + } + } + private val recentRoots = ArrayDeque() + private val slowestRoots: MutableList = ArrayList() + private val inputLatencies = ArrayDeque() + private val renderLatencies = ArrayDeque() + private var nextFrameId = 1 + private var framesStarted: Long = 0 + private var framesSent: Long = 0 + private var framesDiscarded: Long = 0 + private var framesTimedOut: Long = 0 + private var exportDirty = false + private var exportDir: File? = null + private var exportThread: Thread? = null + + /** Idempotent; enables filesystem export. Safe to call from any constructor path. */ + fun init(context: Context) { + var dir = context.applicationContext.getExternalFilesDir(null) + if (dir == null) { + dir = context.applicationContext.filesDir + } + synchronized(lock) { + exportDir = dir + if (exportThread == null) { + val thread = Thread(Runnable { exportLoop() }, "FrameTimingsExport") + thread.isDaemon = true + thread.start() + exportThread = thread + } + } + } + + /** Begin a root frame; reason is a short label like "input:sys-event type=0". */ + fun startFrame(reason: String?): Int { + return startFrame(reason, 0) + } + + /** + * Begin a frame caused by an existing one (parentFrameId; 0 for a root). + * The child is nested under its root in the export and its latency counts + * against the root, so an input event that fans out into an app render and + * a shell-chrome render reads as one timeline instead of three. + */ + fun startFrame(reason: String?, parentFrameId: Int): Int { + val now = SystemClock.elapsedRealtime() + val frame: Frame + synchronized(lock) { + val parent = framesById[parentFrameId] + frame = Frame(nextFrameId++, reason ?: "", now, + System.currentTimeMillis(), parent) + framesById[frame.id] = frame + framesStarted++ + if (parent != null) { + parent.children.add(frame) + addLineLocked(parent, now, "spawned frame#" + frame.id + " (" + frame.reason + ")") + } + } + return frame.id + } + + /** + * Append to a frame's label, for facts only known after it started (which + * app is in the foreground, which window a render is for). Shows up in the + * frame's header line, so the export is scannable without reading bodies. + */ + fun annotate(frameId: Int, text: String?) { + if (text == null || text.isEmpty()) { + return + } + synchronized(lock) { + val frame = framesById[frameId] + if (frame == null) { + return + } + frame.reason = if (frame.reason.isEmpty()) text else frame.reason + " " + text + } + } + + fun log(frameId: Int, message: String?) { + val now = SystemClock.elapsedRealtime() + synchronized(lock) { + val frame = openFrameLocked(frameId) + if (frame == null) { + return + } + addLineLocked(frame, now, message) + } + } + + fun spanStart(frameId: Int, name: String) { + val now = SystemClock.elapsedRealtime() + synchronized(lock) { + val frame = openFrameLocked(frameId) + if (frame == null) { + return + } + frame.openSpans[name] = now + addLineLocked(frame, now, "span $name start") + } + } + + fun spanEnd(frameId: Int, name: String) { + val now = SystemClock.elapsedRealtime() + synchronized(lock) { + val frame = openFrameLocked(frameId) + if (frame == null) { + return + } + val startedAt = frame.openSpans.remove(name) + if (startedAt == null) { + addLineLocked(frame, now, "span $name end (start not recorded)") + } else { + addLineLocked(frame, now, "span " + name + " end (" + (now - startedAt) + "ms)") + } + } + } + + /** + * Finish a frame. Outcomes: "sent" (counted in latency percentiles), anything + * starting with "discarded", or "timeout". First finish wins; later calls for + * the same frame are ignored, so racing completion paths are safe. + */ + fun finishFrame(frameId: Int, outcome: String?) { + val now = SystemClock.elapsedRealtime() + val finished: Frame + synchronized(lock) { + val frame = openFrameLocked(frameId) + if (frame == null) { + return + } + finishFrameLocked(frame, now, outcome ?: "discarded: no outcome given") + finished = frame + } + Log.i(TAG, "frame#" + finished.id + " [" + finished.reason + "] -> " + finished.outcome + + " in " + finished.durationMs() + "ms") + } + + /** One-line stats summary, e.g. for showing in the phone UI. */ + fun statsSummary(): String { + synchronized(lock) { + val input = percentilesLocked(inputLatencies) + return "frames started=" + framesStarted + " sent=" + framesSent + + " discarded=" + framesDiscarded + " timeout=" + framesTimedOut + + (if (input == null) + "" + else " | input-to-display p50=" + input[0] + "ms p90=" + input[1] + + "ms p99=" + input[2] + "ms max=" + input[3] + "ms") + } + } + + // --------------------------------------------------------------------- + + /** The frame with this ID if it exists and is still open, else null. */ + private fun openFrameLocked(frameId: Int): Frame? { + if (frameId <= 0) { + return null + } + val frame = framesById[frameId] + return if (frame != null && frame.isOpen()) frame else null + } + + private fun addLineLocked(frame: Frame, now: Long, message: String?) { + if (frame.lines.size >= MAX_LINES_PER_FRAME) { + if (frame.lines.size == MAX_LINES_PER_FRAME) { + frame.lines.add(Line(now, Thread.currentThread().name, "... line cap reached")) + } + return + } + frame.lines.add(Line(now, Thread.currentThread().name, message)) + } + + private fun finishFrameLocked(frame: Frame, now: Long, outcome: String) { + frame.finishedAtMs = now + frame.outcome = outcome + for (open in frame.openSpans.entries) { + frame.lines.add(Line(now, Thread.currentThread().name, + "span " + open.key + " never ended (started at +" + + (open.value - frame.startedAtMs) + "ms)")) + } + frame.openSpans.clear() + addLineLocked(frame, now, "finished: $outcome") + + val root = frame.root() + if (frame.wasSent()) { + framesSent++ + // The user-visible latency is input (or timer) to the first pixels + // that actually reached the glasses, wherever in the tree that was. + if (!root.subtreeSentRecorded) { + root.subtreeSentRecorded = true + recordLatencyLocked(root, now - root.startedAtMs) + insertSlowestLocked(root) + } + } else if (outcome.startsWith("timeout")) { + framesTimedOut++ + } else { + framesDiscarded++ + } + + if (root === frame) { + recentRoots.addLast(frame) + while (recentRoots.size > RECENT_ROOTS_KEPT) { + recentRoots.removeFirst() + } + } + exportDirty = true + } + + private fun recordLatencyLocked(root: Frame, latencyMs: Long) { + val bucket = if (root.reason.startsWith("input:")) inputLatencies else renderLatencies + bucket.addLast(latencyMs) + while (bucket.size > SENT_DURATIONS_WINDOW) { + bucket.removeFirst() + } + } + + private fun insertSlowestLocked(root: Frame) { + if (!slowestRoots.contains(root)) { + slowestRoots.add(root) + } + // Sorted and trimmed at export time, when every subtree duration is final. + } + + /** {p50, p90, p99, max} over a rolling latency window, or null if empty. */ + private fun percentilesLocked(window: ArrayDeque): LongArray? { + if (window.isEmpty()) { + return null + } + val sorted: MutableList = ArrayList(window) + Collections.sort(sorted) + return longArrayOf( + percentileOfSorted(sorted, 50), + percentileOfSorted(sorted, 90), + percentileOfSorted(sorted, 99), + sorted[sorted.size - 1], + ) + } + + private fun sweepTimedOutFrames() { + val now = SystemClock.elapsedRealtime() + val timedOut: MutableList = ArrayList() + synchronized(lock) { + for (frame in ArrayList(framesById.values)) { + if (frame.isOpen() && now - frame.startedAtMs >= FRAME_TIMEOUT_MS) { + finishFrameLocked(frame, now, "timeout: never reported finished") + timedOut.add(frame) + } + } + } + for (frame in timedOut) { + Log.w(TAG, "frame#" + frame.id + " [" + frame.reason + "] timed out after " + + frame.durationMs() + "ms without being finished") + } + } + + private fun exportLoop() { + var lastExportAtMs = 0L + while (true) { + try { + Thread.sleep(SWEEP_INTERVAL_MS) + } catch (e: InterruptedException) { + return + } + try { + sweepTimedOutFrames() + val now = SystemClock.elapsedRealtime() + val shouldExport: Boolean + synchronized(lock) { + shouldExport = exportDirty && exportDir != null && now - lastExportAtMs >= EXPORT_INTERVAL_MS + } + if (shouldExport) { + lastExportAtMs = now + exportToFile() + } + } catch (t: Throwable) { + Log.w(TAG, "export loop error", t) + } + } + } + + private fun exportToFile() { + val content: String + val dir: File + synchronized(lock) { + dir = exportDir ?: return + content = buildExportLocked() + exportDirty = false + } + val target = File(dir, EXPORT_FILE_NAME) + val temp = File(dir, "$EXPORT_FILE_NAME.tmp") + try { + (OutputStreamWriter(FileOutputStream(temp), StandardCharsets.UTF_8) as Writer).use { writer -> + writer.write(content) + } + if (!temp.renameTo(target)) { + Log.w(TAG, "failed to rename $temp to $target") + } + } catch (t: Throwable) { + Log.w(TAG, "failed to export frame timings", t) + } + } + + private fun buildExportLocked(): String { + val now = SystemClock.elapsedRealtime() + val wallClockFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US) + val out = StringBuilder(64 * 1024) + out.append("FrameTimings export at ").append(wallClockFormat.format(Date())).append('\n') + out.append(statsSummaryLocked()).append('\n') + out.append('\n') + out.append("Frames are trees: an input event's own frame is the root, and the renders it\n") + out.append("caused are indented under it with offsets measured from the root's start.\n") + out.append('\n') + + Collections.sort(slowestRoots, Comparator { a, b -> + java.lang.Long.compare(b.subtreeEndAtMs(now) - b.startedAtMs, a.subtreeEndAtMs(now) - a.startedAtMs) }) + while (slowestRoots.size > SLOWEST_ROOTS_KEPT) { + slowestRoots.removeAt(slowestRoots.size - 1) + } + + out.append("=== slowest frames that reached the glasses ===\n") + for (frame in slowestRoots) { + appendTreeLocked(out, frame, frame, wallClockFormat, now) + } + + out.append("=== recent frames (oldest first) ===\n") + for (frame in recentRoots) { + appendTreeLocked(out, frame, frame, wallClockFormat, now) + } + return out.toString() + } + + private fun statsSummaryLocked(): String { + val input = percentilesLocked(inputLatencies) + val render = percentilesLocked(renderLatencies) + val out = StringBuilder() + out.append("frames started=").append(framesStarted).append(" sent=").append(framesSent) + .append(" discarded=").append(framesDiscarded).append(" timeout=").append(framesTimedOut) + .append(" open=").append(openFrameCountLocked()) + appendPercentilesLocked(out, "input-to-display latency", inputLatencies.size, input) + appendPercentilesLocked(out, "render-to-display latency", renderLatencies.size, render) + return out.toString() + } + + private fun appendPercentilesLocked(out: StringBuilder, label: String, count: Int, percentiles: LongArray?) { + if (percentiles == null) { + return + } + out.append('\n').append(label).append(" (last ").append(count).append("): p50=") + .append(percentiles[0]).append("ms p90=").append(percentiles[1]) + .append("ms p99=").append(percentiles[2]).append("ms max=").append(percentiles[3]).append("ms") + } + + private fun openFrameCountLocked(): Int { + var open = 0 + for (frame in framesById.values) { + if (frame.isOpen()) { + open++ + } + } + return open + } + + /** Print a frame and its descendants, all timed against root's start. */ + private fun appendTreeLocked( + out: StringBuilder, frame: Frame, root: Frame, wallClockFormat: SimpleDateFormat, now: Long) { + var depth = 0 + var walk: Frame? = frame + while (walk !== root) { + depth++ + walk = walk!!.parent + } + val indent = repeat(" ", depth) + val startOffsetMs = frame.startedAtMs - root.startedAtMs + out.append(indent).append("frame#").append(frame.id) + .append(" [").append(frame.reason).append(']') + if (frame === root) { + out.append(" started ").append(wallClockFormat.format(Date(frame.startedWallClockMs))) + val totalMs = frame.subtreeEndAtMs(now) - frame.startedAtMs + out.append(" duration ").append(frame.durationMs()).append("ms") + if (!frame.children.isEmpty()) { + out.append(" (tree ").append(totalMs).append("ms") + .append(if (frame.subtreeHasOpenFrame()) ", still open" else "").append(')') + } + } else { + out.append(" started +").append(startOffsetMs).append("ms") + .append(" duration ").append(if (frame.isOpen()) "open" else (frame.durationMs().toString() + "ms")) + } + out.append(" outcome ").append(frame.outcome ?: "(open)").append('\n') + for (line in frame.lines) { + out.append(indent).append(String.format(Locale.US, " %+7dms [%s] %s", + line.atMs - root.startedAtMs, line.thread, line.message)).append('\n') + } + for (child in frame.children) { + appendTreeLocked(out, child, root, wallClockFormat, now) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.java b/App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.java deleted file mode 100644 index 1346b07e..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -/** Android storage adapter for the shared GIF recorder. */ -public final class GifScreenRecorder { - private final SharedGifScreenRecorder recorder = new SharedGifScreenRecorder(); - - public void addFrame(byte[] gray, int width, int height, long timestampMs) { - recorder.addFrame(gray, width, height, timestampMs); - } - - public boolean isOverflowed() { return recorder.isOverflowed(); } - - public String save(Context context) throws IOException { - byte[] gif = recorder.encode(); - if (gif.length == 0) return ""; - File file = new File(ScreenshotUtil.ensureScreenshotsDir(context), - "recording-" + ScreenshotUtil.timestamp() + ".gif"); - try (FileOutputStream out = new FileOutputStream(file)) { out.write(gif); } - return file.getAbsolutePath(); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.kt new file mode 100644 index 00000000..e2fde296 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.kt @@ -0,0 +1,27 @@ +package com.faceclaw.app + +import android.content.Context +import java.io.File +import java.io.FileOutputStream +import java.io.IOException + +/** Android storage adapter for the shared GIF recorder. */ +class GifScreenRecorder { + private val recorder = SharedGifScreenRecorder() + + fun addFrame(gray: ByteArray?, width: Int, height: Int, timestampMs: Long) { + recorder.addFrame(gray, width, height, timestampMs) + } + + fun isOverflowed(): Boolean = recorder.isOverflowed() + + @Throws(IOException::class) + fun save(context: Context): String { + val gif = recorder.encode() + if (gif.isEmpty()) return "" + val file = File(ScreenshotUtil.ensureScreenshotsDir(context), + "recording-" + ScreenshotUtil.timestamp() + ".gif") + FileOutputStream(file).use { out -> out.write(gif) } + return file.absolutePath + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java deleted file mode 100644 index 80589f47..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.faceclaw.app; - -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Path; -import android.util.Log; - -import androidx.core.graphics.PathParser; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Renders a small subset of SVG (the shapes used by Lucide / simple Noun - * Project icons: path, circle, ellipse, rect, line, polyline, polygon) to a - * grayscale coverage buffer for use as an on-glasses icon. Icons are stroked - * (Lucide style: fill="none", 2px stroke, round caps/joins); the returned - * bytes are one coverage value per pixel (0=transparent .. 255=opaque white), - * row-major, size*size. Called once per icon and cached on the TS side. - */ -public final class IconRenderer { - private static final String TAG = "IconRenderer"; - private static final Pattern TAG_RE = Pattern.compile("<(path|circle|ellipse|rect|line|polyline|polygon)\\b([^>]*)>"); - private static final Pattern VIEWBOX_RE = Pattern.compile("viewBox\\s*=\\s*\"([^\"]*)\""); - - private IconRenderer() {} - - public static byte[] renderSvgGray(String svg, int size, float strokeWidth) { - if (svg == null || size <= 0) { - return new byte[0]; - } - try { - float minX = 0f, minY = 0f, viewW = 24f, viewH = 24f; - Matcher vb = VIEWBOX_RE.matcher(svg); - if (vb.find()) { - String[] parts = vb.group(1).trim().split("[\\s,]+"); - if (parts.length == 4) { - minX = Float.parseFloat(parts[0]); - minY = Float.parseFloat(parts[1]); - viewW = Float.parseFloat(parts[2]); - viewH = Float.parseFloat(parts[3]); - } - } - // Lucide-style icons are stroked outlines (fill="none"); everything - // else (Noun Project glyphs, brand logos) is a filled shape. - boolean stroked = svg.contains("fill=\"none\""); - Path path = new Path(); - Matcher m = TAG_RE.matcher(svg); - while (m.find()) { - appendElement(path, m.group(1), m.group(2)); - } - if (path.isEmpty()) { - return new byte[0]; - } - - Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - float scale = Math.min(size / viewW, size / viewH); - // Center the (square) viewBox in the bitmap, then map its origin. - canvas.translate((size - viewW * scale) / 2f, (size - viewH * scale) / 2f); - canvas.scale(scale, scale); - canvas.translate(-minX, -minY); - Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); - paint.setColor(0xffffffff); - if (stroked) { - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(strokeWidth); - paint.setStrokeCap(Paint.Cap.ROUND); - paint.setStrokeJoin(Paint.Join.ROUND); - } else { - paint.setStyle(Paint.Style.FILL); - } - canvas.drawPath(path, paint); - - int[] pixels = new int[size * size]; - bitmap.getPixels(pixels, 0, size, 0, 0, size, size); - byte[] gray = new byte[size * size]; - for (int i = 0; i < pixels.length; i++) { - gray[i] = (byte) quantizeCoverage((pixels[i] >>> 24) & 0xff); // alpha = coverage - } - return gray; - } catch (Exception e) { - Log.w(TAG, "icon render failed", e); - return new byte[0]; - } - } - - /** - * Snap antialiased coverage toward hard edges so the 4bpp frames sent - * over BLE deflate better: mostly-transparent and mostly-opaque pixels - * become exactly 0/255 (long runs, and 0 stays color-key transparent for - * bitBlt), and only genuinely half-covered edge pixels keep one mid gray. - * The packed frame then uses a 3-symbol alphabet instead of all 16 - * levels, at icon sizes this is visually near-identical. - */ - private static int quantizeCoverage(int alpha) { - if (alpha < 64) return 0; - if (alpha >= 192) return 255; - return 128; - } - - private static void appendElement(Path path, String tag, String attrs) { - switch (tag) { - case "path": { - String d = attr(attrs, "d"); - if (d != null) { - Path sub = PathParser.createPathFromPathData(d); - if (sub != null) { - path.addPath(sub); - } - } - break; - } - case "circle": { - float cx = num(attrs, "cx", 0), cy = num(attrs, "cy", 0), r = num(attrs, "r", 0); - if (r > 0) path.addCircle(cx, cy, r, Path.Direction.CW); - break; - } - case "ellipse": { - float cx = num(attrs, "cx", 0), cy = num(attrs, "cy", 0); - float rx = num(attrs, "rx", 0), ry = num(attrs, "ry", 0); - if (rx > 0 && ry > 0) path.addOval(cx - rx, cy - ry, cx + rx, cy + ry, Path.Direction.CW); - break; - } - case "rect": { - float x = num(attrs, "x", 0), y = num(attrs, "y", 0); - float w = num(attrs, "width", 0), h = num(attrs, "height", 0); - float rx = num(attrs, "rx", 0), ry = num(attrs, "ry", rx > 0 ? rx : 0); - if (rx <= 0) rx = ry; - if (ry <= 0) ry = rx; - if (w > 0 && h > 0) { - if (rx > 0 || ry > 0) { - path.addRoundRect(x, y, x + w, y + h, rx, ry, Path.Direction.CW); - } else { - path.addRect(x, y, x + w, y + h, Path.Direction.CW); - } - } - break; - } - case "line": { - path.moveTo(num(attrs, "x1", 0), num(attrs, "y1", 0)); - path.lineTo(num(attrs, "x2", 0), num(attrs, "y2", 0)); - break; - } - case "polyline": - case "polygon": { - String points = attr(attrs, "points"); - if (points != null) { - String[] nums = points.trim().split("[\\s,]+"); - boolean started = false; - for (int i = 0; i + 1 < nums.length; i += 2) { - float px = Float.parseFloat(nums[i]); - float py = Float.parseFloat(nums[i + 1]); - if (!started) { - path.moveTo(px, py); - started = true; - } else { - path.lineTo(px, py); - } - } - if (tag.equals("polygon")) path.close(); - } - break; - } - default: - break; - } - } - - private static String attr(String attrs, String name) { - Matcher m = Pattern.compile("\\b" + name + "\\s*=\\s*\"([^\"]*)\"").matcher(attrs); - return m.find() ? m.group(1) : null; - } - - private static float num(String attrs, String name, float fallback) { - String value = attr(attrs, name); - if (value == null) return fallback; - try { - return Float.parseFloat(value.trim()); - } catch (NumberFormatException e) { - return fallback; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt new file mode 100644 index 00000000..da181f0d --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt @@ -0,0 +1,196 @@ +package com.faceclaw.app + +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Path +import android.util.Log + +import androidx.core.graphics.PathParser + +import java.util.regex.Matcher +import java.util.regex.Pattern + +/** + * Renders a small subset of SVG (the shapes used by Lucide / simple Noun + * Project icons: path, circle, ellipse, rect, line, polyline, polygon) to a + * grayscale coverage buffer for use as an on-glasses icon. Icons are stroked + * (Lucide style: fill="none", 2px stroke, round caps/joins); the returned + * bytes are one coverage value per pixel (0=transparent .. 255=opaque white), + * row-major, size*size. Called once per icon and cached on the TS side. + */ +class IconRenderer private constructor() { + companion object { + private const val TAG = "IconRenderer" + private val TAG_RE: Pattern = Pattern.compile("<(path|circle|ellipse|rect|line|polyline|polygon)\\b([^>]*)>") + private val VIEWBOX_RE: Pattern = Pattern.compile("viewBox\\s*=\\s*\"([^\"]*)\"") + private val SEPARATOR_RE: Pattern = Pattern.compile("[\\s,]+") + + @JvmStatic + fun renderSvgGray(svg: String?, size: Int, strokeWidth: Float): ByteArray { + if (svg == null || size <= 0) { + return ByteArray(0) + } + try { + var minX = 0f + var minY = 0f + var viewW = 24f + var viewH = 24f + val vb = VIEWBOX_RE.matcher(svg) + if (vb.find()) { + val parts = SEPARATOR_RE.split(vb.group(1)!!.trim()) + if (parts.size == 4) { + minX = java.lang.Float.parseFloat(parts[0]) + minY = java.lang.Float.parseFloat(parts[1]) + viewW = java.lang.Float.parseFloat(parts[2]) + viewH = java.lang.Float.parseFloat(parts[3]) + } + } + // Lucide-style icons are stroked outlines (fill="none"); everything + // else (Noun Project glyphs, brand logos) is a filled shape. + val stroked = svg.contains("fill=\"none\"") + val path = Path() + val m = TAG_RE.matcher(svg) + while (m.find()) { + appendElement(path, m.group(1)!!, m.group(2)!!) + } + if (path.isEmpty) { + return ByteArray(0) + } + + val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val scale = Math.min(size / viewW, size / viewH) + // Center the (square) viewBox in the bitmap, then map its origin. + canvas.translate((size - viewW * scale) / 2f, (size - viewH * scale) / 2f) + canvas.scale(scale, scale) + canvas.translate(-minX, -minY) + val paint = Paint(Paint.ANTI_ALIAS_FLAG) + paint.color = 0xffffffff.toInt() + if (stroked) { + paint.style = Paint.Style.STROKE + paint.strokeWidth = strokeWidth + paint.strokeCap = Paint.Cap.ROUND + paint.strokeJoin = Paint.Join.ROUND + } else { + paint.style = Paint.Style.FILL + } + canvas.drawPath(path, paint) + + val pixels = IntArray(size * size) + bitmap.getPixels(pixels, 0, size, 0, 0, size, size) + val gray = ByteArray(size * size) + for (i in pixels.indices) { + gray[i] = quantizeCoverage((pixels[i] ushr 24) and 0xff).toByte() // alpha = coverage + } + return gray + } catch (e: Exception) { + Log.w(TAG, "icon render failed", e) + return ByteArray(0) + } + } + + /** + * Snap antialiased coverage toward hard edges so the 4bpp frames sent + * over BLE deflate better: mostly-transparent and mostly-opaque pixels + * become exactly 0/255 (long runs, and 0 stays color-key transparent for + * bitBlt), and only genuinely half-covered edge pixels keep one mid gray. + * The packed frame then uses a 3-symbol alphabet instead of all 16 + * levels, at icon sizes this is visually near-identical. + */ + @JvmStatic + private fun quantizeCoverage(alpha: Int): Int { + if (alpha < 64) return 0 + if (alpha >= 192) return 255 + return 128 + } + + @JvmStatic + private fun appendElement(path: Path, tag: String, attrs: String) { + when (tag) { + "path" -> { + val d = attr(attrs, "d") + if (d != null) { + val sub = PathParser.createPathFromPathData(d) + if (sub != null) { + path.addPath(sub) + } + } + } + "circle" -> { + val cx = num(attrs, "cx", 0f) + val cy = num(attrs, "cy", 0f) + val r = num(attrs, "r", 0f) + if (r > 0) path.addCircle(cx, cy, r, Path.Direction.CW) + } + "ellipse" -> { + val cx = num(attrs, "cx", 0f) + val cy = num(attrs, "cy", 0f) + val rx = num(attrs, "rx", 0f) + val ry = num(attrs, "ry", 0f) + if (rx > 0 && ry > 0) path.addOval(cx - rx, cy - ry, cx + rx, cy + ry, Path.Direction.CW) + } + "rect" -> { + val x = num(attrs, "x", 0f) + val y = num(attrs, "y", 0f) + val w = num(attrs, "width", 0f) + val h = num(attrs, "height", 0f) + var rx = num(attrs, "rx", 0f) + var ry = num(attrs, "ry", if (rx > 0) rx else 0f) + if (rx <= 0) rx = ry + if (ry <= 0) ry = rx + if (w > 0 && h > 0) { + if (rx > 0 || ry > 0) { + path.addRoundRect(x, y, x + w, y + h, rx, ry, Path.Direction.CW) + } else { + path.addRect(x, y, x + w, y + h, Path.Direction.CW) + } + } + } + "line" -> { + path.moveTo(num(attrs, "x1", 0f), num(attrs, "y1", 0f)) + path.lineTo(num(attrs, "x2", 0f), num(attrs, "y2", 0f)) + } + "polyline", "polygon" -> { + val points = attr(attrs, "points") + if (points != null) { + val nums = SEPARATOR_RE.split(points.trim()) + var started = false + var i = 0 + while (i + 1 < nums.size) { + val px = java.lang.Float.parseFloat(nums[i]) + val py = java.lang.Float.parseFloat(nums[i + 1]) + if (!started) { + path.moveTo(px, py) + started = true + } else { + path.lineTo(px, py) + } + i += 2 + } + if (tag == "polygon") path.close() + } + } + else -> { + } + } + } + + @JvmStatic + private fun attr(attrs: String, name: String): String? { + val m: Matcher = Pattern.compile("\\b" + name + "\\s*=\\s*\"([^\"]*)\"").matcher(attrs) + return if (m.find()) m.group(1) else null + } + + @JvmStatic + private fun num(attrs: String, name: String, fallback: Float): Float { + val value = attr(attrs, name) + if (value == null) return fallback + try { + return java.lang.Float.parseFloat(value.trim()) + } catch (e: NumberFormatException) { + return fallback + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.java b/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.java deleted file mode 100644 index ef6debbb..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.java +++ /dev/null @@ -1,229 +0,0 @@ -package com.faceclaw.app; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.util.Log; - -/** - * Decodes image files (and bitmaps generally) to the grayscale packet format - * used across the TS bridge: [widthLo, widthHi, heightLo, heightHi, - * pixels...] with one byte per pixel, row-major, or an empty array on - * failure. FaceclawMediaController's album art shares bitmapToGrayPacket; - * the TS side (app/native/image-files.ts) owns the shared photo-tone preset - * passed as (gamma, dither). - */ -public final class ImageFileLoader { - private static final String TAG = "ImageFileLoader"; - - private ImageFileLoader() {} - - /** - * Decode an image file and downscale it to fit within maxWidth x - * maxHeight, preserving aspect ratio and never upscaling. Flat - * conversion (no tone curve, per-pixel rounding): right for UI raster - * such as icons. - */ - public static byte[] loadGray(String path, int maxWidth, int maxHeight) { - return loadGray(path, maxWidth, maxHeight, 1f, false); - } - - /** - * As above, with the photographic tone handling described on - * bitmapToGrayPacket(Bitmap, int, int, float, boolean): use for - * continuous-tone images (photos) viewed on the glasses. - */ - public static byte[] loadGray( - String path, int maxWidth, int maxHeight, float gamma, boolean dither) { - if (path == null || maxWidth <= 0 || maxHeight <= 0) { - return new byte[0]; - } - try { - BitmapFactory.Options bounds = new BitmapFactory.Options(); - bounds.inJustDecodeBounds = true; - BitmapFactory.decodeFile(path, bounds); - if (bounds.outWidth <= 0 || bounds.outHeight <= 0) { - return new byte[0]; - } - // Power-of-two subsampling during decode keeps large photos from - // allocating full-size ARGB buffers; exact fitting happens in - // bitmapToGrayPacket. - BitmapFactory.Options opts = new BitmapFactory.Options(); - opts.inSampleSize = 1; - while (bounds.outWidth / (opts.inSampleSize * 2) >= maxWidth - && bounds.outHeight / (opts.inSampleSize * 2) >= maxHeight) { - opts.inSampleSize *= 2; - } - Bitmap bitmap = BitmapFactory.decodeFile(path, opts); - if (bitmap == null) { - return new byte[0]; - } - return bitmapToGrayPacket(bitmap, maxWidth, maxHeight, gamma, dither); - } catch (Exception | OutOfMemoryError e) { - Log.w(TAG, "image decode failed: " + path, e); - return new byte[0]; - } - } - - /** - * Decode an in-memory image file (PNG/JPEG/WebP bytes, e.g. a fetched - * map tile) and downscale to fit within maxWidth x maxHeight. Takes a - * ByteBuffer because NativeScript marshals a JS ArrayBuffer to one. - */ - public static byte[] loadGrayFromBytes(java.nio.ByteBuffer buffer, int maxWidth, int maxHeight) { - return loadGrayFromBytes(buffer, maxWidth, maxHeight, 1f, false); - } - - /** As above, with photographic tone handling (see bitmapToGrayPacket). */ - public static byte[] loadGrayFromBytes( - java.nio.ByteBuffer buffer, int maxWidth, int maxHeight, float gamma, boolean dither) { - if (buffer == null || maxWidth <= 0 || maxHeight <= 0) { - return new byte[0]; - } - try { - java.nio.ByteBuffer source = buffer.duplicate(); - source.rewind(); - byte[] data = new byte[source.remaining()]; - source.get(data); - if (data.length == 0) { - return new byte[0]; - } - Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); - if (bitmap == null) { - return new byte[0]; - } - return bitmapToGrayPacket(bitmap, maxWidth, maxHeight, gamma, dither); - } catch (Exception | OutOfMemoryError e) { - Log.w(TAG, "byte-array image decode failed", e); - return new byte[0]; - } - } - - /** - * Scale a bitmap to fit within maxWidth x maxHeight (preserving aspect, - * never upscaling) and convert it to the grayscale packet format. - * Transparent pixels darken toward black (the on-glasses background). - */ - public static byte[] bitmapToGrayPacket(Bitmap source, int maxWidth, int maxHeight) { - return bitmapToGrayPacket(source, maxWidth, maxHeight, 1f, false); - } - - /** - * As above, with photographic tone handling for continuous-tone images - * (album art, photos) rather than UI raster: - * - * gamma > 1 darkens midtones (out = 255 * (in/255)^gamma). Source pixels - * are sRGB-encoded but the G2 drives its 16 levels roughly linearly, so - * mid-gray otherwise displays far brighter than intended; 2.2 undoes the - * sRGB encoding outright. - * - * dither error-diffuses against the 16 levels the frame is eventually - * packed to (BmpUtil.GRAY_TO_NIBBLE) instead of leaving each pixel to - * round on its own, which turns smooth gradients into visible bands. - * Dithered output is already quantized: every byte is a level times 16, - * which BmpUtil re-quantizes back to exactly that level. - */ - public static byte[] bitmapToGrayPacket( - Bitmap source, int maxWidth, int maxHeight, float gamma, boolean dither) { - if (source == null || source.getWidth() <= 0 || source.getHeight() <= 0 - || maxWidth <= 0 || maxHeight <= 0) { - return new byte[0]; - } - try { - float scale = Math.min(1f, Math.min( - (float) maxWidth / source.getWidth(), - (float) maxHeight / source.getHeight())); - int width = Math.max(1, Math.round(source.getWidth() * scale)); - int height = Math.max(1, Math.round(source.getHeight() * scale)); - Bitmap scaled = Bitmap.createScaledBitmap(source, width, height, true); - if (scaled.getConfig() == Bitmap.Config.HARDWARE) { - scaled = scaled.copy(Bitmap.Config.ARGB_8888, false); - } - int[] pixels = new int[width * height]; - scaled.getPixels(pixels, 0, width, 0, 0, width, height); - byte[] out = new byte[4 + width * height]; - out[0] = (byte) (width & 0xff); - out[1] = (byte) ((width >> 8) & 0xff); - out[2] = (byte) (height & 0xff); - out[3] = (byte) ((height >> 8) & 0xff); - int[] tone = toneCurve(gamma); - for (int i = 0; i < pixels.length; i++) { - int p = pixels[i]; - int a = (p >>> 24) & 0xff; - int r = (p >> 16) & 0xff; - int g = (p >> 8) & 0xff; - int b = p & 0xff; - out[4 + i] = (byte) tone[((r * 299 + g * 587 + b * 114) / 1000) * a / 255]; - } - if (dither) { - ditherToDisplayLevels(out, 4, width, height); - } - return out; - } catch (Exception | OutOfMemoryError e) { - Log.w(TAG, "bitmap conversion failed", e); - return new byte[0]; - } - } - - /** 256-entry map of source gray to displayed gray for out = in^gamma. */ - private static int[] toneCurve(float gamma) { - int[] curve = new int[256]; - for (int v = 0; v < 256; v++) { - curve[v] = gamma == 1f - ? v - : Math.round(255f * (float) Math.pow(v / 255f, gamma)); - } - return curve; - } - - /** - * Floyd-Steinberg error diffusion onto the display's 16 gray levels, in - * place over an 8bpp plane. Serpentine scanning keeps the diffusion from - * building up a directional texture across wide flat areas. - * - * Level n is written back as n * 16 rather than the n * 17 it stands for - * so that BmpUtil's (v + 8) >> 4 reproduces n exactly; level 0 is written - * as 1, not 0, because 0 is the shell's color-key for transparent. - */ - private static void ditherToDisplayLevels(byte[] plane, int offset, int width, int height) { - float[] curr = new float[width]; - float[] next = new float[width]; - for (int x = 0; x < width; x++) { - curr[x] = plane[offset + x] & 0xff; - } - for (int y = 0; y < height; y++) { - int rowStart = offset + y * width; - int nextStart = rowStart + width; - boolean hasNext = y + 1 < height; - for (int x = 0; x < width; x++) { - next[x] = hasNext ? (plane[nextStart + x] & 0xff) : 0f; - } - boolean leftToRight = (y & 1) == 0; - int start = leftToRight ? 0 : width - 1; - int step = leftToRight ? 1 : -1; - for (int i = 0; i < width; i++) { - int x = start + i * step; - float wanted = curr[x]; - int level = Math.round(Math.min(255f, Math.max(0f, wanted)) / 17f); - float error = wanted - level * 17f; - plane[rowStart + x] = (byte) (level == 0 ? 1 : level * 16); - int ahead = x + step; - if (ahead >= 0 && ahead < width) { - curr[ahead] += error * (7f / 16f); - } - if (hasNext) { - if (ahead >= 0 && ahead < width) { - next[ahead] += error * (1f / 16f); - } - next[x] += error * (5f / 16f); - int behind = x - step; - if (behind >= 0 && behind < width) { - next[behind] += error * (3f / 16f); - } - } - } - float[] swap = curr; - curr = next; - next = swap; - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt new file mode 100644 index 00000000..d1b6c300 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt @@ -0,0 +1,246 @@ +package com.faceclaw.app + +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.util.Log + +/** + * Decodes image files (and bitmaps generally) to the grayscale packet format + * used across the TS bridge: [widthLo, widthHi, heightLo, heightHi, + * pixels...] with one byte per pixel, row-major, or an empty array on + * failure. FaceclawMediaController's album art shares bitmapToGrayPacket; + * the TS side (app/native/image-files.ts) owns the shared photo-tone preset + * passed as (gamma, dither). + */ +class ImageFileLoader private constructor() { + companion object { + private const val TAG = "ImageFileLoader" + + /** + * Decode an image file and downscale it to fit within maxWidth x + * maxHeight, preserving aspect ratio and never upscaling. Flat + * conversion (no tone curve, per-pixel rounding): right for UI raster + * such as icons. + */ + @JvmStatic + fun loadGray(path: String?, maxWidth: Int, maxHeight: Int): ByteArray { + return loadGray(path, maxWidth, maxHeight, 1f, false) + } + + /** + * As above, with the photographic tone handling described on + * bitmapToGrayPacket(Bitmap, int, int, float, boolean): use for + * continuous-tone images (photos) viewed on the glasses. + */ + @JvmStatic + fun loadGray( + path: String?, maxWidth: Int, maxHeight: Int, gamma: Float, dither: Boolean): ByteArray { + if (path == null || maxWidth <= 0 || maxHeight <= 0) { + return ByteArray(0) + } + try { + val bounds = BitmapFactory.Options() + bounds.inJustDecodeBounds = true + BitmapFactory.decodeFile(path, bounds) + if (bounds.outWidth <= 0 || bounds.outHeight <= 0) { + return ByteArray(0) + } + // Power-of-two subsampling during decode keeps large photos from + // allocating full-size ARGB buffers; exact fitting happens in + // bitmapToGrayPacket. + val opts = BitmapFactory.Options() + opts.inSampleSize = 1 + while (bounds.outWidth / (opts.inSampleSize * 2) >= maxWidth + && bounds.outHeight / (opts.inSampleSize * 2) >= maxHeight) { + opts.inSampleSize *= 2 + } + val bitmap = BitmapFactory.decodeFile(path, opts) + if (bitmap == null) { + return ByteArray(0) + } + return bitmapToGrayPacket(bitmap, maxWidth, maxHeight, gamma, dither) + } catch (e: Exception) { + Log.w(TAG, "image decode failed: $path", e) + return ByteArray(0) + } catch (e: OutOfMemoryError) { + Log.w(TAG, "image decode failed: $path", e) + return ByteArray(0) + } + } + + /** + * Decode an in-memory image file (PNG/JPEG/WebP bytes, e.g. a fetched + * map tile) and downscale to fit within maxWidth x maxHeight. Takes a + * ByteBuffer because NativeScript marshals a JS ArrayBuffer to one. + */ + @JvmStatic + fun loadGrayFromBytes(buffer: java.nio.ByteBuffer?, maxWidth: Int, maxHeight: Int): ByteArray { + return loadGrayFromBytes(buffer, maxWidth, maxHeight, 1f, false) + } + + /** As above, with photographic tone handling (see bitmapToGrayPacket). */ + @JvmStatic + fun loadGrayFromBytes( + buffer: java.nio.ByteBuffer?, maxWidth: Int, maxHeight: Int, gamma: Float, dither: Boolean): ByteArray { + if (buffer == null || maxWidth <= 0 || maxHeight <= 0) { + return ByteArray(0) + } + try { + val source = buffer.duplicate() + source.rewind() + val data = ByteArray(source.remaining()) + source.get(data) + if (data.isEmpty()) { + return ByteArray(0) + } + val bitmap = BitmapFactory.decodeByteArray(data, 0, data.size) + if (bitmap == null) { + return ByteArray(0) + } + return bitmapToGrayPacket(bitmap, maxWidth, maxHeight, gamma, dither) + } catch (e: Exception) { + Log.w(TAG, "byte-array image decode failed", e) + return ByteArray(0) + } catch (e: OutOfMemoryError) { + Log.w(TAG, "byte-array image decode failed", e) + return ByteArray(0) + } + } + + /** + * Scale a bitmap to fit within maxWidth x maxHeight (preserving aspect, + * never upscaling) and convert it to the grayscale packet format. + * Transparent pixels darken toward black (the on-glasses background). + */ + @JvmStatic + fun bitmapToGrayPacket(source: Bitmap?, maxWidth: Int, maxHeight: Int): ByteArray { + return bitmapToGrayPacket(source, maxWidth, maxHeight, 1f, false) + } + + /** + * As above, with photographic tone handling for continuous-tone images + * (album art, photos) rather than UI raster: + * + * gamma > 1 darkens midtones (out = 255 * (in/255)^gamma). Source pixels + * are sRGB-encoded but the G2 drives its 16 levels roughly linearly, so + * mid-gray otherwise displays far brighter than intended; 2.2 undoes the + * sRGB encoding outright. + * + * dither error-diffuses against the 16 levels the frame is eventually + * packed to (BmpUtil.GRAY_TO_NIBBLE) instead of leaving each pixel to + * round on its own, which turns smooth gradients into visible bands. + * Dithered output is already quantized: every byte is a level times 16, + * which BmpUtil re-quantizes back to exactly that level. + */ + @JvmStatic + fun bitmapToGrayPacket( + source: Bitmap?, maxWidth: Int, maxHeight: Int, gamma: Float, dither: Boolean): ByteArray { + if (source == null || source.width <= 0 || source.height <= 0 + || maxWidth <= 0 || maxHeight <= 0) { + return ByteArray(0) + } + try { + val scale = Math.min(1f, Math.min( + maxWidth.toFloat() / source.width, + maxHeight.toFloat() / source.height)) + val width = Math.max(1, Math.round(source.width * scale)) + val height = Math.max(1, Math.round(source.height * scale)) + var scaled = Bitmap.createScaledBitmap(source, width, height, true) + if (scaled.config == Bitmap.Config.HARDWARE) { + scaled = scaled.copy(Bitmap.Config.ARGB_8888, false) + } + val pixels = IntArray(width * height) + scaled.getPixels(pixels, 0, width, 0, 0, width, height) + val out = ByteArray(4 + width * height) + out[0] = (width and 0xff).toByte() + out[1] = ((width shr 8) and 0xff).toByte() + out[2] = (height and 0xff).toByte() + out[3] = ((height shr 8) and 0xff).toByte() + val tone = toneCurve(gamma) + for (i in pixels.indices) { + val p = pixels[i] + val a = (p ushr 24) and 0xff + val r = (p shr 16) and 0xff + val g = (p shr 8) and 0xff + val b = p and 0xff + out[4 + i] = tone[((r * 299 + g * 587 + b * 114) / 1000) * a / 255].toByte() + } + if (dither) { + ditherToDisplayLevels(out, 4, width, height) + } + return out + } catch (e: Exception) { + Log.w(TAG, "bitmap conversion failed", e) + return ByteArray(0) + } catch (e: OutOfMemoryError) { + Log.w(TAG, "bitmap conversion failed", e) + return ByteArray(0) + } + } + + /** 256-entry map of source gray to displayed gray for out = in^gamma. */ + @JvmStatic + private fun toneCurve(gamma: Float): IntArray { + val curve = IntArray(256) + for (v in 0 until 256) { + curve[v] = if (gamma == 1f) + v + else Math.round(255f * Math.pow((v / 255f).toDouble(), gamma.toDouble()).toFloat()) + } + return curve + } + + /** + * Floyd-Steinberg error diffusion onto the display's 16 gray levels, in + * place over an 8bpp plane. Serpentine scanning keeps the diffusion from + * building up a directional texture across wide flat areas. + * + * Level n is written back as n * 16 rather than the n * 17 it stands for + * so that BmpUtil's (v + 8) >> 4 reproduces n exactly; level 0 is written + * as 1, not 0, because 0 is the shell's color-key for transparent. + */ + @JvmStatic + private fun ditherToDisplayLevels(plane: ByteArray, offset: Int, width: Int, height: Int) { + var curr = FloatArray(width) + var next = FloatArray(width) + for (x in 0 until width) { + curr[x] = (plane[offset + x].toInt() and 0xff).toFloat() + } + for (y in 0 until height) { + val rowStart = offset + y * width + val nextStart = rowStart + width + val hasNext = y + 1 < height + for (x in 0 until width) { + next[x] = if (hasNext) (plane[nextStart + x].toInt() and 0xff).toFloat() else 0f + } + val leftToRight = (y and 1) == 0 + val start = if (leftToRight) 0 else width - 1 + val step = if (leftToRight) 1 else -1 + for (i in 0 until width) { + val x = start + i * step + val wanted = curr[x] + val level = Math.round(Math.min(255f, Math.max(0f, wanted)) / 17f) + val error = wanted - level * 17f + plane[rowStart + x] = (if (level == 0) 1 else level * 16).toByte() + val ahead = x + step + if (ahead >= 0 && ahead < width) { + curr[ahead] += error * (7f / 16f) + } + if (hasNext) { + if (ahead >= 0 && ahead < width) { + next[ahead] += error * (1f / 16f) + } + next[x] += error * (5f / 16f) + val behind = x - step + if (behind >= 0 && behind < width) { + next[behind] += error * (3f / 16f) + } + } + } + val swap = curr + curr = next + next = swap + } + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java b/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java deleted file mode 100644 index 2a37ad7d..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.faceclaw.app; - -import android.graphics.Bitmap; - -import java.nio.ByteBuffer; - -/** - * Builds the phone-UI preview bitmap from an 8bpp grayscale frame. The - * grayscale buffer arrives as a ByteBuffer (NativeScript marshals a JS - * ArrayBuffer to one without copying element-by-element); doing the - * gray-to-ARGB expansion here keeps the 165KB-per-frame loop out of the - * JS/Java bridge, where it used to cost ~150ms per preview. - */ -public final class PreviewBitmapUtil { - private static int[] cachedLut; - private static long cachedGammaBits; - private static boolean cachedGreen; - - private PreviewBitmapUtil() {} - - /** Reuse the current preview palette; rebuild only when gamma or color changes. */ - private static synchronized int[] lookupTable(double brightenGamma, boolean green) { - long gammaBits = Double.doubleToLongBits(brightenGamma); - if (cachedLut != null && cachedGammaBits == gammaBits && cachedGreen == green) { - return cachedLut; - } - int[] lut = new int[256]; - for (int g = 0; g < 256; g++) { - int v = (int) Math.max(0, Math.min(255, Math.round(255 * Math.pow(g / 255.0, brightenGamma)))); - lut[g] = green ? (0xff000000 | (v << 8)) : (0xff000000 | (v << 16) | (v << 8) | v); - } - cachedGammaBits = gammaBits; - cachedGreen = green; - cachedLut = lut; - return lut; - } - - public static Bitmap fromGray(ByteBuffer gray, int width, int height, double brightenGamma) { - return fromGray(gray, width, height, brightenGamma, false); - } - - /** As above; `green` renders green-on-black (matching the physical glasses) instead of grayscale. */ - public static Bitmap fromGray(ByteBuffer gray, int width, int height, double brightenGamma, boolean green) { - if (gray == null || width <= 0 || height <= 0 || gray.remaining() < width * height) { - throw new IllegalArgumentException("invalid gray preview buffer"); - } - int[] lut = lookupTable(brightenGamma, green); - byte[] bytes = new byte[width * height]; - gray.get(bytes); - int[] colors = new int[width * height]; - for (int i = 0; i < colors.length; i++) { - colors[i] = lut[bytes[i] & 0xff]; - } - return Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888); - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt new file mode 100644 index 00000000..96f98bda --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt @@ -0,0 +1,61 @@ +package com.faceclaw.app + +import android.graphics.Bitmap + +import java.nio.ByteBuffer + +/** + * Builds the phone-UI preview bitmap from an 8bpp grayscale frame. The + * grayscale buffer arrives as a ByteBuffer (NativeScript marshals a JS + * ArrayBuffer to one without copying element-by-element); doing the + * gray-to-ARGB expansion here keeps the 165KB-per-frame loop out of the + * JS/Java bridge, where it used to cost ~150ms per preview. + */ +class PreviewBitmapUtil private constructor() { + companion object { + private var cachedLut: IntArray? = null + private var cachedGammaBits: Long = 0 + private var cachedGreen: Boolean = false + + /** Reuse the current preview palette; rebuild only when gamma or color changes. */ + @JvmStatic + @Synchronized + private fun lookupTable(brightenGamma: Double, green: Boolean): IntArray { + val gammaBits = java.lang.Double.doubleToLongBits(brightenGamma) + val cached = cachedLut + if (cached != null && cachedGammaBits == gammaBits && cachedGreen == green) { + return cached + } + val lut = IntArray(256) + for (g in 0 until 256) { + val v = Math.max(0L, Math.min(255L, Math.round(255 * Math.pow(g / 255.0, brightenGamma)))).toInt() + lut[g] = if (green) (0xff000000.toInt() or (v shl 8)) else (0xff000000.toInt() or (v shl 16) or (v shl 8) or v) + } + cachedGammaBits = gammaBits + cachedGreen = green + cachedLut = lut + return lut + } + + @JvmStatic + fun fromGray(gray: ByteBuffer?, width: Int, height: Int, brightenGamma: Double): Bitmap { + return fromGray(gray, width, height, brightenGamma, false) + } + + /** As above; `green` renders green-on-black (matching the physical glasses) instead of grayscale. */ + @JvmStatic + fun fromGray(gray: ByteBuffer?, width: Int, height: Int, brightenGamma: Double, green: Boolean): Bitmap { + if (gray == null || width <= 0 || height <= 0 || gray.remaining() < width * height) { + throw IllegalArgumentException("invalid gray preview buffer") + } + val lut = lookupTable(brightenGamma, green) + val bytes = ByteArray(width * height) + gray.get(bytes) + val colors = IntArray(width * height) + for (i in colors.indices) { + colors[i] = lut[bytes[i].toInt() and 0xff] + } + return Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.java b/App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.java deleted file mode 100644 index 313abece..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.faceclaw.app; - -import android.content.Context; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -/** - * Saves screenshots of the composited screen as 4-bit grayscale PNGs (the - * display's native depth). Retrieve with - * adb pull /sdcard/Android/data/com.faceclaw.app/files/screenshots/ - */ -public final class ScreenshotUtil { - private ScreenshotUtil() {} - - /** Returns the absolute path of the written file. */ - public static String savePngScreenshot(Context context, byte[] gray, int width, int height) throws IOException { - if (gray == null || width <= 0 || height <= 0 || gray.length < width * height) { - throw new IllegalArgumentException("invalid screenshot buffer"); - } - byte[] png = SharedScreenshots.encode4BitGrayPng(gray, width, height); - File file = new File(ensureScreenshotsDir(context), "screen-" + timestamp() + ".png"); - try (FileOutputStream out = new FileOutputStream(file)) { - out.write(png); - } - return file.getAbsolutePath(); - } - - static File ensureScreenshotsDir(Context context) throws IOException { - File dir = new File(context.getExternalFilesDir(null), "screenshots"); - if (!dir.exists() && !dir.mkdirs()) { - throw new IOException("failed to create " + dir); - } - return dir; - } - - static String timestamp() { - return new SimpleDateFormat("yyyyMMdd-HHmmss-SSS", Locale.US).format(new Date()); - } - -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.kt new file mode 100644 index 00000000..c0d33c9b --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.kt @@ -0,0 +1,49 @@ +package com.faceclaw.app + +import android.content.Context + +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +/** + * Saves screenshots of the composited screen as 4-bit grayscale PNGs (the + * display's native depth). Retrieve with + * adb pull /sdcard/Android/data/com.faceclaw.app/files/screenshots/ + */ +class ScreenshotUtil private constructor() { + companion object { + /** Returns the absolute path of the written file. */ + @JvmStatic + @Throws(IOException::class) + fun savePngScreenshot(context: Context, gray: ByteArray?, width: Int, height: Int): String { + if (gray == null || width <= 0 || height <= 0 || gray.size < width * height) { + throw IllegalArgumentException("invalid screenshot buffer") + } + val png = SharedScreenshots.encode4BitGrayPng(gray, width, height) + val file = File(ensureScreenshotsDir(context), "screen-" + timestamp() + ".png") + FileOutputStream(file).use { out -> + out.write(png) + } + return file.absolutePath + } + + @JvmStatic + @Throws(IOException::class) + fun ensureScreenshotsDir(context: Context): File { + val dir = File(context.getExternalFilesDir(null), "screenshots") + if (!dir.exists() && !dir.mkdirs()) { + throw IOException("failed to create $dir") + } + return dir + } + + @JvmStatic + fun timestamp(): String { + return SimpleDateFormat("yyyyMMdd-HHmmss-SSS", Locale.US).format(Date()) + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.java b/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.java deleted file mode 100644 index a77454a6..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.faceclaw.app; - -import android.os.SystemClock; - -final class InterruptibleSleep { - private final Object lock = new Object(); - private boolean interrupted; - - boolean sleep(long ms) { - long delayMs = Math.max(1, ms); - long deadline = SystemClock.elapsedRealtime() + delayMs; - synchronized (lock) { - // Consume (do not clear-and-ignore) an interrupt delivered before this - // sleep began. interrupt() runs on other threads with no lock held by - // the sleeper between driveSession() returning and sleep() starting, so - // clearing the flag at entry lost that wake and forced the worker to - // sleep the full interval — up to 250ms per idle frame. Honoring it - // costs at most one extra (cheap) driveSession pass. - if (interrupted) { - interrupted = false; - return false; - } - while (true) { - long remaining = deadline - SystemClock.elapsedRealtime(); - if (remaining <= 0) { - return true; - } - try { - lock.wait(remaining); - } catch (InterruptedException ignored) { - interrupted = false; - return false; - } - if (interrupted) { - interrupted = false; - return false; - } - } - } - } - - void interrupt() { - synchronized (lock) { - interrupted = true; - lock.notifyAll(); - } - } -} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt new file mode 100644 index 00000000..60153482 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt @@ -0,0 +1,48 @@ +package com.faceclaw.app + +import android.os.SystemClock + +class InterruptibleSleep { + private val lock = java.lang.Object() + private var interrupted = false + + fun sleep(ms: Long): Boolean { + val delayMs = Math.max(1L, ms) + val deadline = SystemClock.elapsedRealtime() + delayMs + synchronized(lock) { + // Consume (do not clear-and-ignore) an interrupt delivered before this + // sleep began. interrupt() runs on other threads with no lock held by + // the sleeper between driveSession() returning and sleep() starting, so + // clearing the flag at entry lost that wake and forced the worker to + // sleep the full interval — up to 250ms per idle frame. Honoring it + // costs at most one extra (cheap) driveSession pass. + if (interrupted) { + interrupted = false + return false + } + while (true) { + val remaining = deadline - SystemClock.elapsedRealtime() + if (remaining <= 0) { + return true + } + try { + lock.wait(remaining) + } catch (ignored: InterruptedException) { + interrupted = false + return false + } + if (interrupted) { + interrupted = false + return false + } + } + } + } + + fun interrupt() { + synchronized(lock) { + interrupted = true + lock.notifyAll() + } + } +} diff --git a/CLAUDE.md b/CLAUDE.md index 3ef2a977..7dd039ef 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,13 +1,16 @@ This is Faceclaw, an Android program that provides user interface on the Even Realities G2 smart glasses. It is written in a mix of Typescript/NativeScript -(for the user interface parts) and Java (for the low-level bluetooth parts and +(for the user interface parts) and Kotlin (for the low-level bluetooth parts and for interfacing with Android SDK). -Typescript parts are in app/. Java parts are in App_Resources/Android/src/main/java/com/faceclaw/app/. +Typescript parts are in app/. Android-specific Kotlin parts are in +App_Resources/Android/src/main/java/com/faceclaw/app/ (compiled by the NativeScript +Android build; only the vendored com.k2fsa.sherpa.onnx JNI classes there remain Java). +Shared Kotlin Multiplatform code is in native/kotlin/shared/ (see native/kotlin/README.md). wear/ is a separate Gradle project (Kotlin + Compose for Wear OS): the watch remote that drives Faceclaw over the Wearable Data Layer. Its phone-side -counterparts are FaceclawWearBridge.java, app/native/wear-bridge.ts and +counterparts are FaceclawWearBridge.kt, app/native/wear-bridge.ts and app/g2/wear-remote.ts; the message format is in wear/PROTOCOL.md. `build.sh` and `build_wear.sh` build the Android and Wear OS apps respectively. diff --git a/app/apps/timer/timer-engine.ts b/app/apps/timer/timer-engine.ts index 57bb5e88..34dbf3d7 100644 --- a/app/apps/timer/timer-engine.ts +++ b/app/apps/timer/timer-engine.ts @@ -8,7 +8,7 @@ * * Two expiry paths run side by side: a JS deadline for prompt on-glasses * ringing while the process is awake, and an AlarmManager alarm-clock alarm - * (FaceclawAlarms.java) that rings on the phone at the right moment even if + * (FaceclawAlarms.kt) that rings on the phone at the right moment even if * the process is asleep or dead. The phone shows the item silently first * and adds its own sound when the glasses cannot carry it (not connected, * not worn, charging, not shown within seconds, or not acknowledged within diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index a1d0bde9..ba201e83 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -1326,6 +1326,12 @@ class DashboardController { ring: ringAddress, }); this.communicator = communicator; + // Size the compositor before anything else is awaited: windows opened + // during the bridge start-ups below (the terminal hub, restored apps) + // configure their surfaces through this.communicator, and the Java call + // queue is FIFO, so enqueuing the screen size first guarantees it lands + // ahead of them. Mirrors ensurePreviewDisplay. + await communicator.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT); this.offState = communicator.onStateChange((state) => { if (state.phase !== "connected") resetRingInputFilter(); if (state.phase === "unpaired") { @@ -1493,7 +1499,6 @@ class DashboardController { await nightscoutBridge.start(); // Register the compositor surfaces: the shell chrome above all windows, // and a surface per live window (only the foreground one is composited). - await communicator.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT); await communicator.configureSurface(SHELL_SURFACE_ID, { x: 0, y: 0, diff --git a/app/native/asr-model.ts b/app/native/asr-model.ts index 591bdc73..97fc7e3b 100644 --- a/app/native/asr-model.ts +++ b/app/native/asr-model.ts @@ -18,7 +18,7 @@ declare const java: any; * - "whisper-base-en": sherpa-onnx's offline Whisper backend, base.en, * int8-quantized. Picked over tiny.en for materially better accuracy * (Whisper's own tiny/base WER gap is real and well documented) on the - * reasoning that FaceclawVoiceController.java no longer re-decodes a + * reasoning that FaceclawVoiceController.kt no longer re-decodes a * Whisper segment on every live-partial tick — see its ASR_WHISPER_* * comment — so base.en's extra compute is a one-time cost per utterance, * not a cost paid ~1.4x/second while the user is speaking. tiny.en is an diff --git a/app/native/frame-timings.ts b/app/native/frame-timings.ts index 56e2a5e1..294349e8 100644 --- a/app/native/frame-timings.ts +++ b/app/native/frame-timings.ts @@ -1,6 +1,6 @@ /** * TS-side wrapper for the Java FrameTimings singleton (per-frame latency - * instrumentation; see FrameTimings.java). Frame ID 0 means "no frame" and is + * instrumentation; see FrameTimings.kt). Frame ID 0 means "no frame" and is * ignored by every method, so callers never need to null-check. * * Frames form a tree: pass the causing frame's ID as `parentFrameId` when one diff --git a/native/kotlin/README.md b/native/kotlin/README.md index cdc76456..e2939a80 100644 --- a/native/kotlin/README.md +++ b/native/kotlin/README.md @@ -34,12 +34,17 @@ explicitly; iOS also cleans up abandoned native allocations. GATT write modes are mapped by platform adapters. `migrated-java-sources.json` lists each removed Java source and its Kotlin -replacement. Android's build removes precisely those stale generated copies -before compilation. `android-java-boundaries.json` inventories every retained -Java file and its Android API boundary: services/receivers, GATT, media, -WebView, SQLite, rendering, networking and JNI. The sherpa-onnx Java classes -remain the vendored Android JNI ABI. PNG/GIF adapters retain only Android -storage responsibilities; their codecs are shared. +replacement (paths relative to the repository root). Android's build removes +precisely those stale generated copies before compilation. The Android-only +classes (services/receivers, GATT, media, WebView, SQLite, rendering, +networking, JNI engines) are Kotlin in +`App_Resources/Android/src/main/java/com/faceclaw/app/`, compiled by +NativeScript's own `kotlin-android` plugin rather than this KMP module; they keep +their Java-era JVM API (`@JvmStatic`/`@JvmField`/`const val`) so TypeScript and +the manifest are unchanged. `android-java-boundaries.json` inventories the Java +that remains: the sherpa-onnx classes, which are the vendored Android JNI ABI. +PNG/GIF adapters retain only Android storage responsibilities; their codecs are +shared. On `ios-port`, platform adapters route the existing TypeScript session and UI logic through shared Kotlin for protocol builders, CRC/framing/reassembly, diff --git a/native/kotlin/android-java-boundaries.json b/native/kotlin/android-java-boundaries.json index cfceae10..5e5f418e 100644 --- a/native/kotlin/android-java-boundaries.json +++ b/native/kotlin/android-java-boundaries.json @@ -1,118 +1,4 @@ [ - { - "reason": "BluetoothGatt, BluetoothLeScanner, Android callback threads", - "files": [ - "com/faceclaw/app/FaceclawBleCommunicator.java", - "com/faceclaw/app/FaceclawBleManager.java", - "com/faceclaw/app/FaceclawDeviceDiscovery.java", - "com/faceclaw/app/FaceclawDeviceInfoProbe.java", - "com/faceclaw/app/FaceclawFirmwareFlasher.java", - "com/faceclaw/app/FaceclawFlashPromptCommunicator.java" - ] - }, - { - "reason": "AlarmManager, PendingIntent, Android activities/services/receivers", - "files": [ - "com/faceclaw/app/FaceclawAlarmActivity.java", - "com/faceclaw/app/FaceclawAlarmReceiver.java", - "com/faceclaw/app/FaceclawAlarmRescheduleReceiver.java", - "com/faceclaw/app/FaceclawAlarmService.java", - "com/faceclaw/app/FaceclawAlarms.java", - "com/faceclaw/app/FaceclawForegroundService.java" - ] - }, - { - "reason": "Android providers, sensors, permissions and preferences", - "files": [ - "com/faceclaw/app/FaceclawCalendarProvider.java", - "com/faceclaw/app/FaceclawLocationProvider.java", - "com/faceclaw/app/FaceclawLocationTracker.java", - "com/faceclaw/app/FaceclawSettings.java", - "com/faceclaw/app/FaceclawSettingsPortReceiver.java", - "com/faceclaw/app/FaceclawResourceUsage.java" - ] - }, - { - "reason": "Android MediaSession, notifications, status icons and wearable services", - "files": [ - "com/faceclaw/app/FaceclawMediaBrowser.java", - "com/faceclaw/app/FaceclawMediaController.java", - "com/faceclaw/app/FaceclawMediaNotificationListenerService.java", - "com/faceclaw/app/FaceclawSystemStatusIconProvider.java", - "com/faceclaw/app/FaceclawWearBridge.java", - "com/faceclaw/app/FaceclawWearListenerService.java" - ] - }, - { - "reason": "Android WebView/JavascriptInterface, package manager and intent integration", - "files": [ - "com/faceclaw/app/FaceclawEvenAppDetector.java", - "com/faceclaw/app/FaceclawEvenHubDocumentStart.java", - "com/faceclaw/app/FaceclawEvenHubJsBridge.java", - "com/faceclaw/app/FaceclawEvenHubWebView.java", - "com/faceclaw/app/FaceclawEvenHubWebViewClient.java", - "com/faceclaw/app/FaceclawEvenHubWebViewHost.java" - ] - }, - { - "reason": "Android AudioRecord/AudioTrack/MediaCodec, Handler delivery and JNI speech/model engines", - "files": [ - "com/faceclaw/app/AndroidNoiseEffects.java", - "com/faceclaw/app/FaceclawAudioTranscoder.java", - "com/faceclaw/app/FaceclawCaptionEngine.java", - "com/faceclaw/app/FaceclawDiarizer.java", - "com/faceclaw/app/FaceclawLc3Decoder.java", - "com/faceclaw/app/FaceclawLlamaRunner.java", - "com/faceclaw/app/FaceclawSpeakerId.java", - "com/faceclaw/app/FaceclawVoiceController.java" - ] - }, - { - "reason": "Android SQLite persistence and cursor/content APIs", - "files": [ - "com/faceclaw/app/FaceclawConversationStore.java" - ] - }, - { - "reason": "Android OkHttp backend, Handler/Log delivery, download lifecycle", - "files": [ - "com/faceclaw/app/FaceclawHttp.java", - "com/faceclaw/app/FaceclawModelDownloader.java", - "com/faceclaw/app/FaceclawSseRequest.java", - "com/faceclaw/app/FaceclawWebSocket.java" - ] - }, - { - "reason": "Android JVM loopback sockets, SecureRandom and SHA-256; iOS uses its native socket and Security implementations. Protocol and permissions stay in shared TypeScript.", - "files": [ - "com/faceclaw/app/FaceclawRemoteInput.java" - ] - }, - { - "reason": "Android Bitmap/Canvas/Paint/typeface, SVG rasterization and camera scanning", - "files": [ - "com/faceclaw/app/FontFileRenderer.java", - "com/faceclaw/app/IconRenderer.java", - "com/faceclaw/app/ImageFileLoader.java", - "com/faceclaw/app/PreviewBitmapUtil.java", - "com/faceclaw/app/FaceclawQrScanner.java" - ] - }, - { - "reason": "Android preview/UI delivery and app-scoped export paths; codecs/composition are shared", - "files": [ - "com/faceclaw/app/FaceclawPreviewCompositor.java", - "com/faceclaw/app/GifScreenRecorder.java", - "com/faceclaw/app/ScreenshotUtil.java" - ] - }, - { - "reason": "Android elapsedRealtime, worker wait/notify and Context-backed trace export", - "files": [ - "com/faceclaw/app/FrameTimings.java", - "com/faceclaw/app/util/InterruptibleSleep.java" - ] - }, { "reason": "Vendored sherpa-onnx JNI ABI: Java classes/fields are consumed by the Android native library; iOS uses its native engine APIs.", "files": [ diff --git a/native/kotlin/migrated-java-sources.json b/native/kotlin/migrated-java-sources.json index 9d676c85..dd32ffa3 100644 --- a/native/kotlin/migrated-java-sources.json +++ b/native/kotlin/migrated-java-sources.json @@ -1,198 +1,414 @@ [ { "java": "com/faceclaw/app/LvglFontFile.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/graphics/LvglFontFile.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/LvglFontFile.kt" }, { "java": "com/faceclaw/app/FaceclawAlarmListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawAlarmListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawAlarmListener.kt" }, { "java": "com/faceclaw/app/FaceclawAmbientLightListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawAmbientLightListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawAmbientLightListener.kt" }, { "java": "com/faceclaw/app/FaceclawAudioPacketListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawAudioPacketListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawAudioPacketListener.kt" }, { "java": "com/faceclaw/app/FaceclawBleCommunicatorListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleCommunicatorListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleCommunicatorListener.kt" }, { "java": "com/faceclaw/app/FaceclawBleListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawBleListener.kt" }, { "java": "com/faceclaw/app/FaceclawCaptionEngineListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawCaptionEngineListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawCaptionEngineListener.kt" }, { "java": "com/faceclaw/app/FaceclawCompassListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawCompassListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawCompassListener.kt" }, { "java": "com/faceclaw/app/FaceclawDeviceDiscoveryListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawDeviceDiscoveryListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawDeviceDiscoveryListener.kt" }, { "java": "com/faceclaw/app/FaceclawDeviceInfoProbeListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawDeviceInfoProbeListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawDeviceInfoProbeListener.kt" }, { "java": "com/faceclaw/app/FaceclawEvenHubListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawEvenHubListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawEvenHubListener.kt" }, { "java": "com/faceclaw/app/FaceclawFirmwareFlasherListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawFirmwareFlasherListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawFirmwareFlasherListener.kt" }, { "java": "com/faceclaw/app/FaceclawFlashPromptListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawFlashPromptListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawFlashPromptListener.kt" }, { "java": "com/faceclaw/app/FaceclawImuListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawImuListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawImuListener.kt" }, { "java": "com/faceclaw/app/FaceclawLlamaListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawLlamaListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawLlamaListener.kt" }, { "java": "com/faceclaw/app/FaceclawLocationListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawLocationListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawLocationListener.kt" }, { "java": "com/faceclaw/app/FaceclawLocationTrackerListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawLocationTrackerListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawLocationTrackerListener.kt" }, { "java": "com/faceclaw/app/FaceclawMediaBrowserListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawMediaBrowserListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawMediaBrowserListener.kt" }, { "java": "com/faceclaw/app/FaceclawMediaControllerListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawMediaControllerListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawMediaControllerListener.kt" }, { "java": "com/faceclaw/app/FaceclawMicStatusListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawMicStatusListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawMicStatusListener.kt" }, { "java": "com/faceclaw/app/FaceclawModelDownloaderListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawModelDownloaderListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawModelDownloaderListener.kt" }, { "java": "com/faceclaw/app/FaceclawNoiseSuppressor.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/audio/FaceclawNoiseSuppressor.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/FaceclawNoiseSuppressor.kt" }, { "java": "com/faceclaw/app/FaceclawNotificationListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawNotificationListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawNotificationListener.kt" }, { "java": "com/faceclaw/app/FaceclawQrScannerListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawQrScannerListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawQrScannerListener.kt" }, { "java": "com/faceclaw/app/FaceclawRingEventDecoder.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FaceclawRingEventDecoder.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FaceclawRingEventDecoder.kt" }, { "java": "com/faceclaw/app/FaceclawSettingsListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawSettingsListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawSettingsListener.kt" }, { "java": "com/faceclaw/app/FaceclawSseListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawSseListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawSseListener.kt" }, { "java": "com/faceclaw/app/FaceclawVoiceControllerListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawVoiceControllerListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawVoiceControllerListener.kt" }, { "java": "com/faceclaw/app/FaceclawWearListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawWearListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawWearListener.kt" }, { "java": "com/faceclaw/app/FaceclawWebSocketListener.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawWebSocketListener.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/callbacks/FaceclawWebSocketListener.kt" }, { "java": "com/faceclaw/app/FwGlyphAtlas.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FwGlyphAtlas.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FwGlyphAtlas.kt" }, { "java": "com/faceclaw/app/g2protocol/BleImageOptimizer.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleImageOptimizer.kt" }, { "java": "com/faceclaw/app/g2protocol/BleMagicPool.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleMagicPool.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleMagicPool.kt" }, { "java": "com/faceclaw/app/g2protocol/BleProtocol.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleProtocol.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BleProtocol.kt" }, { "java": "com/faceclaw/app/g2protocol/CfwMessageWindow.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageWindow.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwMessageWindow.kt" }, { "java": "com/faceclaw/app/g2protocol/CfwTransport.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwTransport.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/CfwTransport.kt" }, { "java": "com/faceclaw/app/g2protocol/ConnectionOptions.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ConnectionOptions.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ConnectionOptions.kt" }, { "java": "com/faceclaw/app/g2protocol/G2Event.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/G2Event.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/G2Event.kt" }, { "java": "com/faceclaw/app/g2protocol/MessageBuilder.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/MessageBuilder.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/MessageBuilder.kt" }, { "java": "com/faceclaw/app/g2protocol/OutboundMessage.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/OutboundMessage.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/OutboundMessage.kt" }, { "java": "com/faceclaw/app/g2protocol/TextureCacheState.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ResourceCacheState.kt" }, { "java": "com/faceclaw/app/g2protocol/TexturePlanner.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/TexturePlanner.kt" }, { "java": "com/faceclaw/app/GlyphAtlas.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphAtlas.kt" }, { "java": "com/faceclaw/app/ImageAtlas.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ImageAtlas.kt" }, { "java": "com/faceclaw/app/SurfaceCompositor.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt" }, { "java": "com/faceclaw/app/util/BmpUtil.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/BmpUtil.kt" }, { "java": "com/faceclaw/app/util/CollectionUtils.java", - "kotlin": "shared/src/commonMain/kotlin/com/faceclaw/app/util/CollectionUtils.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/CollectionUtils.kt" }, { "java": "com/faceclaw/app/FaceclawFirmwareUtil.java", - "kotlin": "shared/src/androidMain/kotlin/com/faceclaw/app/FaceclawFirmwareUtil.kt" + "kotlin": "native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/FaceclawFirmwareUtil.kt" }, { "java": "com/faceclaw/app/FaceclawWavRecorder.java", - "kotlin": "shared/src/androidMain/kotlin/com/faceclaw/app/FaceclawWavRecorder.kt" + "kotlin": "native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/FaceclawWavRecorder.kt" + }, + { + "java": "com/faceclaw/app/AndroidNoiseEffects.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/AndroidNoiseEffects.kt" + }, + { + "java": "com/faceclaw/app/FaceclawAlarmActivity.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmActivity.kt" + }, + { + "java": "com/faceclaw/app/FaceclawAlarmReceiver.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmReceiver.kt" + }, + { + "java": "com/faceclaw/app/FaceclawAlarmRescheduleReceiver.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmRescheduleReceiver.kt" + }, + { + "java": "com/faceclaw/app/FaceclawAlarmService.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt" + }, + { + "java": "com/faceclaw/app/FaceclawAlarms.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt" + }, + { + "java": "com/faceclaw/app/FaceclawAudioTranscoder.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt" + }, + { + "java": "com/faceclaw/app/FaceclawBleCommunicator.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt" + }, + { + "java": "com/faceclaw/app/FaceclawBleManager.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleManager.kt" + }, + { + "java": "com/faceclaw/app/FaceclawCalendarProvider.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCalendarProvider.kt" + }, + { + "java": "com/faceclaw/app/FaceclawCaptionEngine.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt" + }, + { + "java": "com/faceclaw/app/FaceclawConversationStore.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt" + }, + { + "java": "com/faceclaw/app/FaceclawDeviceDiscovery.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceDiscovery.kt" + }, + { + "java": "com/faceclaw/app/FaceclawDeviceInfoProbe.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt" + }, + { + "java": "com/faceclaw/app/FaceclawDiarizer.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt" + }, + { + "java": "com/faceclaw/app/FaceclawEvenAppDetector.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenAppDetector.kt" + }, + { + "java": "com/faceclaw/app/FaceclawEvenHubDocumentStart.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubDocumentStart.kt" + }, + { + "java": "com/faceclaw/app/FaceclawEvenHubJsBridge.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt" + }, + { + "java": "com/faceclaw/app/FaceclawEvenHubWebView.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebView.kt" + }, + { + "java": "com/faceclaw/app/FaceclawEvenHubWebViewClient.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt" + }, + { + "java": "com/faceclaw/app/FaceclawEvenHubWebViewHost.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt" + }, + { + "java": "com/faceclaw/app/FaceclawFirmwareFlasher.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt" + }, + { + "java": "com/faceclaw/app/FaceclawFlashPromptCommunicator.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt" + }, + { + "java": "com/faceclaw/app/FaceclawForegroundService.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawForegroundService.kt" + }, + { + "java": "com/faceclaw/app/FaceclawHttp.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt" + }, + { + "java": "com/faceclaw/app/FaceclawLc3Decoder.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt" + }, + { + "java": "com/faceclaw/app/FaceclawLlamaRunner.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLlamaRunner.kt" + }, + { + "java": "com/faceclaw/app/FaceclawLocationProvider.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationProvider.kt" + }, + { + "java": "com/faceclaw/app/FaceclawLocationTracker.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLocationTracker.kt" + }, + { + "java": "com/faceclaw/app/FaceclawMediaBrowser.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaBrowser.kt" + }, + { + "java": "com/faceclaw/app/FaceclawMediaController.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.kt" + }, + { + "java": "com/faceclaw/app/FaceclawMediaNotificationListenerService.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaNotificationListenerService.kt" + }, + { + "java": "com/faceclaw/app/FaceclawModelDownloader.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt" + }, + { + "java": "com/faceclaw/app/FaceclawPreviewCompositor.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt" + }, + { + "java": "com/faceclaw/app/FaceclawQrScanner.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawQrScanner.kt" + }, + { + "java": "com/faceclaw/app/FaceclawRemoteInput.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt" + }, + { + "java": "com/faceclaw/app/FaceclawResourceUsage.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawResourceUsage.kt" + }, + { + "java": "com/faceclaw/app/FaceclawSettings.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt" + }, + { + "java": "com/faceclaw/app/FaceclawSettingsPortReceiver.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettingsPortReceiver.kt" + }, + { + "java": "com/faceclaw/app/FaceclawSpeakerId.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt" + }, + { + "java": "com/faceclaw/app/FaceclawSseRequest.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt" + }, + { + "java": "com/faceclaw/app/FaceclawSystemStatusIconProvider.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt" + }, + { + "java": "com/faceclaw/app/FaceclawVoiceController.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt" + }, + { + "java": "com/faceclaw/app/FaceclawWearBridge.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearBridge.kt" + }, + { + "java": "com/faceclaw/app/FaceclawWearListenerService.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWearListenerService.kt" + }, + { + "java": "com/faceclaw/app/FaceclawWebSocket.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawWebSocket.kt" + }, + { + "java": "com/faceclaw/app/FontFileRenderer.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt" + }, + { + "java": "com/faceclaw/app/FrameTimings.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt" + }, + { + "java": "com/faceclaw/app/GifScreenRecorder.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/GifScreenRecorder.kt" + }, + { + "java": "com/faceclaw/app/IconRenderer.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt" + }, + { + "java": "com/faceclaw/app/ImageFileLoader.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt" + }, + { + "java": "com/faceclaw/app/PreviewBitmapUtil.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt" + }, + { + "java": "com/faceclaw/app/ScreenshotUtil.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/ScreenshotUtil.kt" + }, + { + "java": "com/faceclaw/app/util/InterruptibleSleep.java", + "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt" } ] diff --git a/tests/kotlin-build.test.cjs b/tests/kotlin-build.test.cjs index 07d4f8cf..ba68d135 100644 --- a/tests/kotlin-build.test.cjs +++ b/tests/kotlin-build.test.cjs @@ -38,6 +38,6 @@ test('every remaining Java source has an explicit Android boundary and every mig assert.equal(new Set(migrated.map(entry => entry.java)).size, migrated.length); for (const entry of migrated) { assert.equal(fs.existsSync(path.join(java, entry.java)), false, entry.java); - assert.ok(fs.existsSync(path.join(root, 'native/kotlin', entry.kotlin)), entry.kotlin); + assert.ok(fs.existsSync(path.join(root, entry.kotlin)), entry.kotlin); } }); diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index 4b1159f2..ab843e61 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -186,49 +186,87 @@ test('Music settings keeps toggles and selection when a new app arrives and supp assert.equal(closes, 1); }); -test('native session selection skips ignored playing and idle apps, including the all-ignored case', () => { +// FaceclawMediaController is Kotlin compiled by the NativeScript Android build, so +// compile the extracted method with the same Kotlin compiler Gradle already cached. +function kotlinCompiler() { + const gradle = source('App_Resources/Android/before-plugins.gradle').match(/kotlinVersion\s*=\s*"([^"]+)"/); + const cache = path.join(os.homedir(), '.gradle/caches/modules-2/files-2.1'); + const jar = (group, artifact, version) => { + const directory = path.join(cache, group, artifact, version); + if (!fs.existsSync(directory)) return null; + for (const hash of fs.readdirSync(directory)) { + const file = path.join(directory, hash, `${artifact}-${version}.jar`); + if (fs.existsSync(file)) return file; + } + return null; + }; + const anyVersion = (group, artifact) => { + const directory = path.join(cache, group, artifact); + if (!fs.existsSync(directory)) return null; + for (const version of fs.readdirSync(directory).sort().reverse()) { + const file = jar(group, artifact, version); + if (file) return file; + } + return null; + }; + if (!gradle) return null; + const version = gradle[1]; + const stdlib = jar('org.jetbrains.kotlin', 'kotlin-stdlib', version); + const compiler = [ + jar('org.jetbrains.kotlin', 'kotlin-compiler-embeddable', version), + stdlib, + jar('org.jetbrains.kotlin', 'kotlin-script-runtime', version), + jar('org.jetbrains.kotlin', 'kotlin-daemon-embeddable', version), + anyVersion('org.jetbrains.kotlin', 'kotlin-reflect'), + anyVersion('org.jetbrains.intellij.deps', 'trove4j'), + anyVersion('org.jetbrains', 'annotations'), + anyVersion('org.jetbrains.kotlinx', 'kotlinx-coroutines-core-jvm'), + ]; + if (compiler.some(file => !file)) return null; + return { classpath: compiler.join(path.delimiter), stdlib }; +} + +test('native session selection skips ignored playing and idle apps, including the all-ignored case', (t) => { // Execute the production selection method with lightweight media-session doubles. - const java = source('App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.java'); - const method = java.slice(java.indexOf(' private MediaController chooseController('), - java.indexOf(' private void emitSessionAppsLocked(')); - const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'faceclaw-media-java-')); - const javaBin = (name) => process.env.JAVA_HOME ? path.join(process.env.JAVA_HOME, 'bin', name) : name; + const compiler = kotlinCompiler(); + if (!compiler) return t.skip('Kotlin compiler not in the Gradle cache; run ./build.sh once'); + const kotlin = source('App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawMediaController.kt'); + const method = kotlin.slice(kotlin.indexOf(' private fun chooseController('), + kotlin.indexOf(' private fun emitSessionAppsLocked(')); + const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'faceclaw-media-kotlin-')); + const javaBin = process.env.JAVA_HOME ? path.join(process.env.JAVA_HOME, 'bin', 'java') : 'java'; try { - const file = path.join(directory, 'MediaSelectionTest.java'); - fs.writeFileSync(file, `import java.util.*; -public class MediaSelectionTest { - Set ignoredPackages = new HashSet<>(); - static class PlaybackState { - static final int STATE_PLAYING = 3; - int state; PlaybackState(int state) { this.state = state; } int getState() { return state; } + const file = path.join(directory, 'MediaSelectionTest.kt'); + fs.writeFileSync(file, ` +class PlaybackState(val state: Int) { companion object { const val STATE_PLAYING = 3 } } +class MediaController(val packageName: String, state: Int) { var playbackState: PlaybackState? = PlaybackState(state) } +class MediaSelectionTest { + val ignoredPackages: MutableSet = HashSet() +${method} + fun run() { + val ignored = MediaController("browser", 3) + val paused = MediaController("player", 2) + val playing = MediaController("music", 3) + ignoredPackages.add("browser") + check(chooseController(listOf(ignored, paused)) === paused) + check(chooseController(listOf(ignored, paused, playing)) === playing) + check(chooseController(listOf(ignored)) == null) + ignored.playbackState = null + check(chooseController(listOf(ignored, paused)) === paused) + ignoredPackages.add("music") + check(chooseController(listOf(ignored, paused, playing)) === paused) + ignoredPackages.remove("browser"); ignored.playbackState = PlaybackState(3) + check(chooseController(listOf(ignored, paused)) === ignored) + check(chooseController(null) == null) + check(chooseController(emptyList()) == null) } - static class MediaController { - String name; PlaybackState state; - MediaController(String name, int state) { this.name = name; this.state = new PlaybackState(state); } - String getPackageName() { return name; } PlaybackState getPlaybackState() { return state; } - } - ${method} - public static void main(String[] args) { - MediaSelectionTest test = new MediaSelectionTest(); - MediaController ignored = new MediaController("browser", 3); - MediaController paused = new MediaController("player", 2); - MediaController playing = new MediaController("music", 3); - test.ignoredPackages.add("browser"); - assert test.chooseController(Arrays.asList(ignored, paused)) == paused; - assert test.chooseController(Arrays.asList(ignored, paused, playing)) == playing; - assert test.chooseController(Arrays.asList(ignored)) == null; - ignored.state = null; - assert test.chooseController(Arrays.asList(ignored, paused)) == paused; - test.ignoredPackages.add("music"); - assert test.chooseController(Arrays.asList(ignored, paused, playing)) == paused; - test.ignoredPackages.remove("browser"); ignored.state = new PlaybackState(3); - assert test.chooseController(Arrays.asList(ignored, paused)) == ignored; - assert test.chooseController(null) == null; - assert test.chooseController(Collections.emptyList()) == null; - } -}`); - execFileSync(javaBin('javac'), ['-d', directory, file], { stdio: 'pipe' }); - execFileSync(javaBin('java'), ['-ea', '-cp', directory, 'MediaSelectionTest'], { stdio: 'pipe' }); +} +fun main() { MediaSelectionTest().run() } +`); + const out = path.join(directory, 'out'); + execFileSync(javaBin, ['-cp', compiler.classpath, 'org.jetbrains.kotlin.cli.jvm.K2JVMCompiler', + '-no-stdlib', '-cp', compiler.stdlib, '-d', out, file], { stdio: 'pipe' }); + execFileSync(javaBin, ['-cp', [out, compiler.stdlib].join(path.delimiter), 'MediaSelectionTestKt'], { stdio: 'pipe' }); } finally { fs.rmSync(directory, { recursive: true, force: true }); } diff --git a/wear/PROTOCOL.md b/wear/PROTOCOL.md index 90aaf2b0..fba306c9 100644 --- a/wear/PROTOCOL.md +++ b/wear/PROTOCOL.md @@ -3,7 +3,7 @@ Transport: the Wearable Data Layer (Google Play services). Both apps share the `com.faceclaw.app` application id and, for release builds, the signing key — the Data Layer routes only between matching apps. Payloads are UTF-8 JSON -objects. Phone side: `App_Resources/.../FaceclawWearBridge.java` (transport), +objects. Phone side: `App_Resources/.../FaceclawWearBridge.kt` (transport), `app/native/wear-bridge.ts` (JS wrapper), `app/g2/wear-remote.ts` (meaning). Watch side: `app/src/main/kotlin/com/faceclaw/wear/Protocol.kt`, `PhoneLink.kt`. From 587364e5e66c0f47388eea27786611cf76096d06 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 18:43:55 -0700 Subject: [PATCH 11/27] Convert most Android-specific kotlin to shared or shareable --- .../com/faceclaw/app/AndroidSessionLink.kt | 41 + .../com/faceclaw/app/AndroidSpeechEngines.kt | 147 + .../java/com/faceclaw/app/AndroidStockLink.kt | 64 + .../com/faceclaw/app/FaceclawAlarmService.kt | 237 +- .../java/com/faceclaw/app/FaceclawAlarms.kt | 289 +- .../faceclaw/app/FaceclawAudioTranscoder.kt | 83 +- .../faceclaw/app/FaceclawBleCommunicator.kt | 3957 +---------------- .../com/faceclaw/app/FaceclawCaptionEngine.kt | 453 +- .../faceclaw/app/FaceclawConversationStore.kt | 78 +- .../faceclaw/app/FaceclawDeviceInfoProbe.kt | 611 +-- .../java/com/faceclaw/app/FaceclawDiarizer.kt | 33 +- .../app/FaceclawEvenHubWebViewClient.kt | 62 +- .../faceclaw/app/FaceclawFirmwareFlasher.kt | 697 +-- .../app/FaceclawFlashPromptCommunicator.kt | 552 +-- .../java/com/faceclaw/app/FaceclawHttp.kt | 23 +- .../com/faceclaw/app/FaceclawLc3Decoder.kt | 98 +- .../faceclaw/app/FaceclawModelDownloader.kt | 192 +- .../com/faceclaw/app/FaceclawRemoteInput.kt | 196 +- .../java/com/faceclaw/app/FaceclawSettings.kt | 64 +- .../com/faceclaw/app/FaceclawSpeakerId.kt | 39 +- .../com/faceclaw/app/FaceclawSseRequest.kt | 145 +- .../app/FaceclawSystemStatusIconProvider.kt | 88 +- .../faceclaw/app/FaceclawVoiceController.kt | 1073 +---- .../java/com/faceclaw/app/FontFileRenderer.kt | 247 +- .../java/com/faceclaw/app/FrameTimings.kt | 485 +- .../java/com/faceclaw/app/IconRenderer.kt | 167 +- .../java/com/faceclaw/app/ImageFileLoader.kt | 87 +- .../com/faceclaw/app/PreviewBitmapUtil.kt | 33 +- .../faceclaw/app/util/InterruptibleSleep.kt | 48 - native/kotlin/README.md | 20 +- native/kotlin/migrated-java-sources.json | 2 +- .../com/faceclaw/app/PlatformUtil.android.kt | 57 + .../app/g2protocol/AndroidProtocolPlatform.kt | 16 + .../com/faceclaw/app/PlatformServices.kt | 12 + .../com/faceclaw/app/SettingsDocument.kt | 106 +- .../faceclaw/app/alarms/AlarmRingingPolicy.kt | 275 ++ .../com/faceclaw/app/alarms/AlarmSchedule.kt | 235 + .../faceclaw/app/audio/AudioSegmentation.kt | 127 + .../faceclaw/app/audio/CaptionEngineCore.kt | 380 ++ .../com/faceclaw/app/audio/Lc3PacketFramer.kt | 93 + .../faceclaw/app/audio/VoiceCaptureSession.kt | 833 ++++ .../com/faceclaw/app/audio/VoicePorts.kt | 137 + .../com/faceclaw/app/audio/VoicePrint.kt | 104 + .../com/faceclaw/app/audio/WavPcmReader.kt | 66 + .../app/evenhub/EvenHubAssetServer.kt | 94 + .../app/g2protocol/DeviceInfoProbeFlow.kt | 219 + .../faceclaw/app/g2protocol/FirmwareImage.kt | 167 + .../app/g2protocol/FlashPromptFlow.kt | 353 ++ .../faceclaw/app/g2protocol/OtaFlashFlow.kt | 312 ++ .../app/g2protocol/ProtocolPlatform.kt | 28 + .../com/faceclaw/app/g2protocol/StockLink.kt | 91 + .../app/g2protocol/StockLinkSession.kt | 443 ++ .../session/GlassesSessionControls.kt | 695 +++ .../g2protocol/session/GlassesSessionCore.kt | 1917 ++++++++ .../g2protocol/session/GlassesSessionSend.kt | 1301 ++++++ .../app/g2protocol/session/SessionPorts.kt | 165 + .../com/faceclaw/app/graphics/GlyphPacket.kt | 168 + .../com/faceclaw/app/graphics/GrayPacket.kt | 117 + .../faceclaw/app/graphics/OpenTypeNames.kt | 110 + .../faceclaw/app/graphics/PreviewPalette.kt | 52 + .../faceclaw/app/graphics/StatusIconArt.kt | 98 + .../faceclaw/app/graphics/SvgIconSource.kt | 150 + .../com/faceclaw/app/net/HttpIdentity.kt | 26 + .../faceclaw/app/net/RemoteInputSession.kt | 229 + .../com/faceclaw/app/net/ResumableDownload.kt | 178 + .../kotlin/com/faceclaw/app/net/SseStream.kt | 209 + .../app/settings/SettingsChangeHub.kt | 71 + .../com/faceclaw/app/util/Concurrency.kt | 105 + .../com/faceclaw/app/util/FrameTimingsCore.kt | 451 ++ .../kotlin/com/faceclaw/app/util/Json.kt | 161 + .../com/faceclaw/app/util/PlatformUtil.kt | 30 + .../com/faceclaw/app/PlatformUtil.ios.kt | 105 + .../app/g2protocol/IosProtocolPlatform.kt | 18 + .../faceclaw/app/FrameTimingsFormatTest.kt | 33 + .../faceclaw/app/AlarmRingingPolicyTest.kt | 123 + .../com/faceclaw/app/AlarmScheduleTest.kt | 109 + .../com/faceclaw/app/AudioHelpersTest.kt | 130 + .../com/faceclaw/app/CaptionEngineCoreTest.kt | 127 + .../faceclaw/app/EvenHubAssetServerTest.kt | 47 + .../com/faceclaw/app/FirmwareImageTest.kt | 118 + .../kotlin/com/faceclaw/app/FoundationTest.kt | 69 + .../com/faceclaw/app/FrameTimingsCoreTest.kt | 139 + .../faceclaw/app/GlassesSessionCoreTest.kt | 421 ++ .../faceclaw/app/GlyphAndIconSourceTest.kt | 128 + .../com/faceclaw/app/GraphicsCoresTest.kt | 99 + .../com/faceclaw/app/Lc3PacketFramerTest.kt | 67 + .../faceclaw/app/RemoteInputSessionTest.kt | 178 + .../com/faceclaw/app/ResumableDownloadTest.kt | 149 + .../com/faceclaw/app/SettingsChangeHubTest.kt | 46 + .../kotlin/com/faceclaw/app/SseStreamTest.kt | 87 + .../kotlin/com/faceclaw/app/StockFlowsTest.kt | 382 ++ .../faceclaw/app/VoiceCaptureSessionTest.kt | 273 ++ 92 files changed, 14347 insertions(+), 9193 deletions(-) create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSessionLink.kt create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSpeechEngines.kt create mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/AndroidStockLink.kt delete mode 100644 App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt create mode 100644 native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/PlatformUtil.android.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmRingingPolicy.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmSchedule.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/AudioSegmentation.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/CaptionEngineCore.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/Lc3PacketFramer.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoiceCaptureSession.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePorts.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePrint.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/WavPcmReader.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/evenhub/EvenHubAssetServer.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DeviceInfoProbeFlow.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FlashPromptFlow.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/OtaFlashFlow.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLink.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLinkSession.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionControls.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/SessionPorts.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphPacket.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GrayPacket.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/OpenTypeNames.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/PreviewPalette.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/StatusIconArt.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SvgIconSource.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/HttpIdentity.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/ResumableDownload.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/SseStream.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/settings/SettingsChangeHub.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Concurrency.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/FrameTimingsCore.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Json.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/PlatformUtil.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt create mode 100644 tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/FrameTimingsFormatTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmRingingPolicyTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmScheduleTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AudioHelpersTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/CaptionEngineCoreTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/EvenHubAssetServerTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FirmwareImageTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FoundationTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameTimingsCoreTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlassesSessionCoreTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlyphAndIconSourceTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GraphicsCoresTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/Lc3PacketFramerTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RemoteInputSessionTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResumableDownloadTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SettingsChangeHubTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SseStreamTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/StockFlowsTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/VoiceCaptureSessionTest.kt diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSessionLink.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSessionLink.kt new file mode 100644 index 00000000..8f7cb4cb --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSessionLink.kt @@ -0,0 +1,41 @@ +package com.faceclaw.app + +import android.bluetooth.BluetoothGatt + +/** [SessionLink] over the Android GATT boundary ([FaceclawBleManager]). */ +class AndroidSessionLink(private val bleManager: FaceclawBleManager) : SessionLink { + override fun connect(address: String, timeoutMs: Int): Boolean = bleManager.connect(address, timeoutMs) + + override fun requestHighPriority(address: String) { + bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) + } + + override fun requestMtu(address: String, mtu: Int, timeoutMs: Int): Boolean = + bleManager.requestMtu(address, mtu, timeoutMs) + + override fun negotiatedMtu(address: String): Int = bleManager.getNegotiatedMtu(address) + + override fun discoverServices(address: String, timeoutMs: Int): Boolean = + bleManager.discoverServices(address, timeoutMs) + + override fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean = + bleManager.enableNotifications(address, characteristicUuid, enable, timeoutMs) + + override fun writeFrames( + address: String, + characteristicUuid: String, + frames: List, + mode: GattWriteMode, + timeoutMs: Int, + ): Boolean = bleManager.writeFrames(address, characteristicUuid, frames, AndroidProtocolPlatform.writeType(mode), timeoutMs) + + override fun disconnect(address: String) = bleManager.disconnect(address) + + override fun close() = bleManager.close() + + override fun isBonded(address: String): Boolean = bleManager.isBonded(address) + + override fun prepareBenchmarkLink(address: String, mode: Int) = bleManager.prepareBenchmarkLink(address, mode) + + override fun recordDisplayFrameSent() = FaceclawBleManager.recordDisplayFrameSent() +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSpeechEngines.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSpeechEngines.kt new file mode 100644 index 00000000..2b149f09 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidSpeechEngines.kt @@ -0,0 +1,147 @@ +package com.faceclaw.app + +import android.util.Log + +import com.k2fsa.sherpa.onnx.FeatureConfig +import com.k2fsa.sherpa.onnx.OfflineModelConfig +import com.k2fsa.sherpa.onnx.OfflineMoonshineModelConfig +import com.k2fsa.sherpa.onnx.OfflineRecognizer +import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig +import com.k2fsa.sherpa.onnx.OfflineRecognizerResult +import com.k2fsa.sherpa.onnx.OfflineStream +import com.k2fsa.sherpa.onnx.OfflineWhisperModelConfig + +import java.io.File + +/** + * Android implementations of the shared voice ports: the sherpa-onnx offline recognizer as an + * [OfflineTranscriber], the phone microphone as a [PcmAudioSource], and the JNI LC3 decoder as + * an [AudioPacketDecoder]. The pipelines themselves live in the shared VoiceCaptureSession and + * CaptionSession. + */ +internal object AndroidSpeechEngines { + private const val TAG = "FaceclawVoice" + private const val SAMPLE_RATE = 16000 + private const val FEATURE_DIM = 80 + + /** Sherpa-onnx configuration for the on-device model files in [modelDir]. */ + fun recognizerConfig(modelDir: File, kind: VoiceModelKind): OfflineRecognizerConfig { + val modelConfig = OfflineModelConfig.builder() + .setNumThreads(1) + if (kind == VoiceModelKind.WHISPER) { + modelConfig + .setWhisper(OfflineWhisperModelConfig.builder() + .setEncoder(File(modelDir, "base.en-encoder.int8.onnx").absolutePath) + .setDecoder(File(modelDir, "base.en-decoder.int8.onnx").absolutePath) + .setLanguage("en") + .setTask("transcribe") + .build()) + .setTokens(File(modelDir, "base.en-tokens.txt").absolutePath) + } else { + modelConfig + .setMoonshine(OfflineMoonshineModelConfig.builder() + .setEncoder(File(modelDir, "encoder_model.ort").absolutePath) + .setMergedDecoder(File(modelDir, "decoder_model_merged.ort").absolutePath) + .build()) + .setTokens(File(modelDir, "tokens.txt").absolutePath) + } + return OfflineRecognizerConfig.builder() + .setFeatureConfig(FeatureConfig.builder() + .setSampleRate(SAMPLE_RATE) + .setFeatureDim(FEATURE_DIM) + .build()) + .setModelConfig(modelConfig.build()) + .build() + } + + class SherpaTranscriber(config: OfflineRecognizerConfig) : OfflineTranscriber { + private var recognizer: OfflineRecognizer? = OfflineRecognizer(config) + + override fun recognize(samples: FloatArray, count: Int): String { + val currentRecognizer = recognizer ?: return "" + val segment = if (count == samples.size) samples else samples.copyOf(count) + val offlineStream: OfflineStream = currentRecognizer.createStream() + try { + offlineStream.acceptWaveform(segment, SAMPLE_RATE) + currentRecognizer.decode(offlineStream) + val result: OfflineRecognizerResult? = currentRecognizer.getResult(offlineStream) + val raw: String? = if (result == null) "" else result.text + return raw?.trim() ?: "" + } finally { + offlineStream.release() + } + } + + override fun release() { + recognizer?.release() + recognizer = null + } + } + + /** The JNI LC3 decoder behind the shared packet-decoder port. */ + class Lc3DecoderAdapter : AudioPacketDecoder { + private val decoder = FaceclawLc3Decoder() + + override fun decodePacket(packet: ByteArray?, pcmOut: ShortArray?): Int = decoder.decodePacket(packet, pcmOut) + + override val lastAngleDegrees: Int get() = decoder.getLastAngleDegrees() + override val lastSsr: Int get() = decoder.getLastSsr() + override val realPackets: Long get() = decoder.getRealPackets() + override val duplicatePackets: Long get() = decoder.getDuplicatePackets() + override val missingPackets: Long get() = decoder.getMissingPackets() + override val decodeErrors: Long get() = decoder.getDecodeErrors() + + override fun close() = decoder.close() + } + + /** + * Open the phone's own microphone at the pipeline's native format (16 kHz + * mono PCM16), or null when it cannot start — the permission is missing + * (SecurityException) or the device refuses the configuration. + */ + fun openPhoneMic(chunkSamples: Int): PcmAudioSource? { + var record: android.media.AudioRecord? = null + try { + val minBytes = android.media.AudioRecord.getMinBufferSize( + SAMPLE_RATE, + android.media.AudioFormat.CHANNEL_IN_MONO, + android.media.AudioFormat.ENCODING_PCM_16BIT) + val bufferBytes = Math.max(minBytes, chunkSamples * 2 * 4) + record = android.media.AudioRecord( + android.media.MediaRecorder.AudioSource.VOICE_RECOGNITION, + SAMPLE_RATE, + android.media.AudioFormat.CHANNEL_IN_MONO, + android.media.AudioFormat.ENCODING_PCM_16BIT, + bufferBytes) + if (record.state != android.media.AudioRecord.STATE_INITIALIZED) { + record.release() + return null + } + record.startRecording() + if (record.recordingState != android.media.AudioRecord.RECORDSTATE_RECORDING) { + record.release() + return null + } + return AudioRecordSource(record) + } catch (t: Throwable) { + Log.w(TAG, "phone mic open failed", t) + if (record != null) { + record.release() + } + return null + } + } + + private class AudioRecordSource(private val record: android.media.AudioRecord) : PcmAudioSource { + override fun read(pcm: ShortArray): Int = record.read(pcm, 0, pcm.size) + + override fun close() { + try { + record.stop() + } catch (ignored: Throwable) { + // Already stopped or never recording; release below either way. + } + record.release() + } + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidStockLink.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidStockLink.kt new file mode 100644 index 00000000..3e7d264e --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/AndroidStockLink.kt @@ -0,0 +1,64 @@ +package com.faceclaw.app + +import android.bluetooth.BluetoothDevice +import android.bluetooth.BluetoothGatt +import android.content.Context + +/** + * Android [StockLink]: a 1:1 wrapper over FaceclawBleManager for the stock-firmware flows + * (device-info probe, flash prompt, OTA flasher). Owns its own GATT manager, exactly as each + * flow did before the shared cores existed. + */ +class AndroidStockLink(context: Context) : StockLink, FaceclawBleListener { + private val bleManager = FaceclawBleManager(context.applicationContext) + + @Volatile + private var listener: StockLinkListener? = null + + init { + bleManager.setListener(this) + } + + override fun setListener(listener: StockLinkListener?) { + this.listener = listener + } + + override fun connect(address: String, timeoutMs: Int): Boolean = bleManager.connect(address, timeoutMs) + + override fun prepareLink(address: String, desiredMtu: Int, timeoutMs: Int) { + bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) + bleManager.requestMtu(address, desiredMtu, timeoutMs) + } + + override fun discoverServices(address: String, timeoutMs: Int): Boolean = bleManager.discoverServices(address, timeoutMs) + + override fun enableNotifications(address: String, characteristicUuid: String, timeoutMs: Int): Boolean = + bleManager.enableNotifications(address, characteristicUuid, true, timeoutMs) + + override fun writeFrames(address: String, characteristicUuid: String, frames: List, mode: GattWriteMode, timeoutMs: Int): Boolean = + bleManager.writeFrames(address, characteristicUuid, frames, AndroidProtocolPlatform.writeType(mode), timeoutMs) + + override fun isConnected(address: String): Boolean = bleManager.isConnected(address) + + override fun bondState(address: String): BondState = + when (bleManager.getBondState(address)) { + BluetoothDevice.BOND_NONE -> BondState.NONE + BluetoothDevice.BOND_BONDING -> BondState.BONDING + BluetoothDevice.BOND_BONDED -> BondState.BONDED + else -> BondState.UNKNOWN + } + + override fun disconnect(address: String) = bleManager.disconnect(address) + + override fun close() = bleManager.close() + + override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { + if (address == null || characteristicUuid == null || data == null) return + listener?.onNotification(address, characteristicUuid, data) + } + + override fun onConnectionStateChange(address: String?, connected: Boolean) { + if (address == null) return + listener?.onConnectionStateChange(address, connected) + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt index 65ea4dd2..3bddef2b 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarmService.kt @@ -22,9 +22,6 @@ import android.os.PowerManager import android.os.VibrationEffect import android.os.Vibrator -import java.util.ArrayList -import java.util.Collections -import java.util.LinkedHashMap /** * The ringing foreground service. One instance carries every item currently @@ -37,22 +34,14 @@ import java.util.LinkedHashMap * to total silence) Do Not Disturb do not silence it. */ class FaceclawAlarmService : Service() { + /** The shared item model; kept as a nested subclass so the lock-screen activity's references hold. */ internal class Ringing( - @JvmField val id: Long, + id: Long, title: String?, text: String?, kind: String?, snoozeMinutes: Int - ) { - @JvmField val title: String = if (title == null || title.trim().isEmpty()) "Alarm" else title - @JvmField val text: String = text ?: "" - @JvmField val kind: String = kind ?: FaceclawAlarms.KIND_ALARM - @JvmField val snoozeMinutes: Int = Math.max(1, snoozeMinutes) - @JvmField val ringAtMs: Long = System.currentTimeMillis() - @JvmField var deliveredAtMs: Long = 0 - @JvmField var escalated: Boolean = false - @JvmField var silenced: Boolean = false - } + ) : RingingItem(id, title, text, kind, snoozeMinutes, System.currentTimeMillis()) companion object { const val CHANNEL_ID = "faceclaw-alarms" @@ -72,17 +61,11 @@ class FaceclawAlarmService : Service() { /** Alarm-stream level (fraction of max) used when the wearer has it muted. */ internal const val MUTED_VOLUME_FRACTION = 0.6f - /** Ringing items, oldest first; static so the activity can read them. */ - private val ringing: MutableMap = Collections.synchronizedMap(LinkedHashMap()) /** - * Signals that arrived before the ring intent was processed (the JS - * engine fires, launches its window and reports delivery on the same - * main thread the service's onStartCommand queues behind), keyed by id - * with their arrival time. Consumed by startRinging. + * The escalation policy is process-wide (the activity reads it, the static entry points + * consult it before the service exists); the live service attaches its timers/effects. */ - private val deliveredEarly: MutableMap = Collections.synchronizedMap(LinkedHashMap()) - private val stoppedEarly: MutableMap = Collections.synchronizedMap(LinkedHashMap()) - private const val EARLY_SIGNAL_MAX_AGE_MS = 15_000L + private val policy = AlarmRingingPolicy(FaceclawAlarms.glassesGate) // ------------------------------------------------------------------ // Static entry points @@ -102,8 +85,7 @@ class FaceclawAlarmService : Service() { @JvmStatic fun delivered(context: Context, id: Long) { - if (!ringing.containsKey(id)) { - deliveredEarly[id] = System.currentTimeMillis() + if (!policy.deliveredOrDefer(id)) { return } val appContext = context.applicationContext @@ -114,8 +96,7 @@ class FaceclawAlarmService : Service() { @JvmStatic fun stopItem(context: Context, id: Long) { - if (!ringing.containsKey(id)) { - stoppedEarly[id] = System.currentTimeMillis() + if (!policy.stopOrDefer(id)) { return } val appContext = context.applicationContext @@ -125,21 +106,13 @@ class FaceclawAlarmService : Service() { } @JvmStatic - fun isRinging(id: Long): Boolean { - return ringing.containsKey(id) - } + fun isRinging(id: Long): Boolean = policy.isRinging(id) @JvmStatic - fun isAnythingRinging(): Boolean { - return !ringing.isEmpty() - } + fun isAnythingRinging(): Boolean = policy.isAnythingRinging() @JvmStatic - internal fun snapshot(): List { - synchronized(ringing) { - return ArrayList(ringing.values) - } - } + internal fun snapshot(): List = policy.snapshot().map { it as Ringing } @JvmStatic internal fun actionIntent(appContext: Context, action: String, id: Long): PendingIntent { @@ -157,16 +130,6 @@ class FaceclawAlarmService : Service() { return PendingIntent.getService(appContext, code, intent, flags) } - /** Consume an early signal for the id; stale entries are dropped. */ - private fun takeEarlySignal(signals: MutableMap, id: Long): Boolean { - val at = signals.remove(id) - val now = System.currentTimeMillis() - synchronized(signals) { - signals.values.removeIf { stamp -> now - stamp > EARLY_SIGNAL_MAX_AGE_MS } - } - return at != null && now - at <= EARLY_SIGNAL_MAX_AGE_MS - } - private fun notificationId(id: Long): Int { return 0x41000000 or (FaceclawAlarms.requestCode(id) and 0x00ffffff) } @@ -188,6 +151,11 @@ class FaceclawAlarmService : Service() { return null } + override fun onCreate() { + super.onCreate() + policy.attach(timers, effects) + } + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { val action = intent?.action val id = if (intent == null) 0L else intent.getLongExtra(FaceclawAlarms.EXTRA_ID, 0) @@ -206,13 +174,13 @@ class FaceclawAlarmService : Service() { intent.getIntExtra(FaceclawAlarms.EXTRA_SNOOZE_MINUTES, 10) )) ACTION_DELIVERED -> - markDelivered(id) + policy.markDelivered(id) ACTION_DISMISS -> - dismiss(id) + policy.dismiss(id) ACTION_SNOOZE -> - snooze(id) + policy.snooze(id) ACTION_STOP_ITEM -> - stopItemQuietly(id, "acknowledged") + policy.stopQuietly(id, "acknowledged") else -> {} } finishIfIdle() @@ -220,6 +188,7 @@ class FaceclawAlarmService : Service() { } override fun onDestroy() { + policy.detach() handler.removeCallbacksAndMessages(null) stopSound() releaseWakeLock() @@ -234,120 +203,69 @@ class FaceclawAlarmService : Service() { return } ensureChannel() - val existing = ringing[item.id] - if (existing != null) { - // The engine's JS timeout and the AlarmManager alarm both fired: one ring. - showNotification(existing) - return - } - if (takeEarlySignal(stoppedEarly, item.id)) { - // Acknowledged or cancelled before this intent was processed. - FaceclawAlarms.log(this, "ring " + item.id + " already acknowledged") - return - } - ringing[item.id] = item - FaceclawAlarms.log(this, "ring " + item.kind + " " + item.id + " (" + FaceclawAlarms.glassesStatusDescription() + ")") - acquireWakeLock() - showNotification(item) - if (!FaceclawAlarms.glassesCanCarryAlarm()) { - escalate(item, FaceclawAlarms.glassesStatusDescription()) - return - } - if (takeEarlySignal(deliveredEarly, item.id)) { - markDelivered(item.id) - return - } - // The glasses could carry it: give the JS side a moment to confirm - // they are actually showing it, then hold for the acknowledgement. - handler.postDelayed({ - val current = ringing[item.id] - if (current != null && !current.escalated && current.deliveredAtMs == 0L) { - escalate(current, "not delivered to the glasses") + policy.ring(item) + } + + /** Escalation timers on the service's main-thread Handler. */ + private val timers = object : AlarmScheduler { + private val pending = HashMap() + + override fun postDelayed(token: Any, delayMs: Long, action: () -> Unit) { + pending.remove(token)?.let { handler.removeCallbacks(it) } + val runnable = Runnable { + pending.remove(token) + action() } - }, DELIVERY_WAIT_MS) + pending[token] = runnable + handler.postDelayed(runnable, delayMs) + } + + override fun cancel(token: Any) { + pending.remove(token)?.let { handler.removeCallbacks(it) } + } + + override fun cancelAll() { + pending.clear() + handler.removeCallbacksAndMessages(null) + } } - private fun markDelivered(id: Long) { - val item = ringing[id] - if (item == null || item.deliveredAtMs != 0L) { - return - } - item.deliveredAtMs = System.currentTimeMillis() - FaceclawAlarms.log(this, "delivered $id to glasses") - handler.postDelayed({ - val current = ringing[id] - if (current != null && !current.escalated) { - escalate(current, "not acknowledged on the glasses") + /** The phone-side effects of the shared policy: notifications, sound, schedule, journal. */ + private val effects = object : RingingSink { + override fun showNotification(item: RingingItem) = this@FaceclawAlarmService.showNotification(item as Ringing) + + override fun itemRemoved(item: RingingItem) { + val manager = getSystemService(NotificationManager::class.java) + manager?.cancel(notificationId(item.id)) + if (item.id == foregroundId) { + promoteAnotherToForeground() } - }, ACK_WAIT_MS) - } - - private fun escalate(item: Ringing, reason: String) { - if (item.escalated) { - return } - item.escalated = true - FaceclawAlarms.log(this, "phone sound for " + item.id + ": " + reason) - showNotification(item) - startSound() - handler.postDelayed({ - val current = ringing[item.id] - if (current != null && current.escalated && !current.silenced) { - current.silenced = true - FaceclawAlarms.log(this, "auto-silenced " + current.id) - showNotification(current) - syncSound() - } - }, AUTO_SILENCE_MS) - } - private fun dismiss(id: Long) { - val item = ringing[id] ?: return - FaceclawAlarms.recordPhoneAction(this, id, "dismiss", 0) - removeItem(item) - // Also drop the schedule entry (a one-off is over; the engine re-arms repeats). - FaceclawAlarms.cancel(this, id) - } + override fun ringingStarted() = acquireWakeLock() - private fun snooze(id: Long) { - val item = ringing[id] ?: return - val minutes = item.snoozeMinutes - FaceclawAlarms.recordPhoneAction(this, id, "snooze", minutes) - removeItem(item) - // Re-arm on the phone directly so the snooze holds even with the JS - // side gone; the engine replays the journal and lands on the same id. - FaceclawAlarms.schedule( - this, - id, - System.currentTimeMillis() + minutes * 60_000L, - item.title, - item.text, - item.kind, - minutes - ) - } + override fun startSound() = this@FaceclawAlarmService.startSound() - private fun stopItemQuietly(id: Long, reason: String) { - val item = ringing[id] ?: return - FaceclawAlarms.log(this, "$reason $id") - removeItem(item) - } + override fun stopSound() = this@FaceclawAlarmService.stopSound() - private fun removeItem(item: Ringing) { - ringing.remove(item.id) - val manager = getSystemService(NotificationManager::class.java) - manager?.cancel(notificationId(item.id)) - syncSound() - if (item.id == foregroundId) { - promoteAnotherToForeground() + override fun reschedule(item: RingingItem, atMs: Long, minutes: Int) { + // The engine replays the journal and lands on the same id. + FaceclawAlarms.schedule(this@FaceclawAlarmService, item.id, atMs, item.title, item.text, item.kind, minutes) } + + override fun cancelSchedule(id: Long) = FaceclawAlarms.cancel(this@FaceclawAlarmService, id) + + override fun recordPhoneAction(id: Long, action: String, minutes: Int) = + FaceclawAlarms.recordPhoneAction(this@FaceclawAlarmService, id, action, minutes) + + override fun log(line: String) = FaceclawAlarms.log(this@FaceclawAlarmService, line) } private fun finishIfIdle() { - if (!ringing.isEmpty()) { + if (policy.isAnythingRinging()) { return } - handler.removeCallbacksAndMessages(null) + policy.cancelTimers() stopSound() releaseWakeLock() stopForeground(STOP_FOREGROUND_REMOVE) @@ -359,7 +277,7 @@ class FaceclawAlarmService : Service() { private fun showNotification(item: Ringing) { val notification = buildNotification(item) - if (foregroundId == 0L || foregroundId == item.id || !ringing.containsKey(foregroundId)) { + if (foregroundId == 0L || foregroundId == item.id || !policy.isRinging(foregroundId)) { foregroundId = item.id startForegroundCompat(notificationId(item.id), notification) } else { @@ -456,21 +374,6 @@ class FaceclawAlarmService : Service() { // ------------------------------------------------------------------ // Sound and vibration (only while some item is escalated and not yet silenced) - private fun syncSound() { - var wanted = false - for (item in snapshot()) { - if (item.escalated && !item.silenced) { - wanted = true - break - } - } - if (wanted) { - startSound() - } else { - stopSound() - } - } - private fun startSound() { if (player != null) { return diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt index 43ffcfc1..fa6ad2ed 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAlarms.kt @@ -47,32 +47,19 @@ class FaceclawAlarms private constructor() { internal const val EXTRA_KIND = "kind" internal const val EXTRA_SNOOZE_MINUTES = "snoozeMinutes" - const val KIND_TIMER = "timer" - const val KIND_ALARM = "alarm" + const val KIND_TIMER = AlarmSchedule.KIND_TIMER + const val KIND_ALARM = AlarmSchedule.KIND_ALARM private const val PREFS_NAME = "faceclaw-alarms" - private const val KEY_SCHEDULED = "scheduled" - private const val KEY_JOURNAL = "journal" - private const val KEY_LOG = "log" - private const val LOG_LINES = 60 - /** - * A schedule entry found already past due (after a reboot, or when the - * process was asleep) rings if it is at most this late; older ones are - * dropped as missed. Matches the JS engine's grace window. - */ - internal const val LATE_GRACE_MS = 5 * 60_000L - /** A glasses status report older than this is not trusted (the JS side is probably gone). */ - internal const val GLASSES_STATUS_MAX_AGE_MS = 3 * 60_000L + /** Grace window for past-due entries found on replay (shared policy). */ + internal const val LATE_GRACE_MS = AlarmSchedule.LATE_GRACE_MS + /** A glasses status report older than this is not trusted (shared policy). */ + internal const val GLASSES_STATUS_MAX_AGE_MS = GlassesStatusGate.MAX_AGE_MS - @Volatile - private var glassesConnected = false - @Volatile - private var glassesWorn = false - @Volatile - private var glassesCharging = false - @Volatile - private var glassesStatusAtMs = 0L + /** The last glasses status pushed by the JS side; read by the ringing service. */ + @JvmField + internal val glassesGate = GlassesStatusGate() @Volatile private var listener: FaceclawAlarmListener? = null @@ -95,66 +82,30 @@ class FaceclawAlarms private constructor() { return base.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) } - // The Java statics were `synchronized`, i.e. locked on the class object; - // the explicit blocks below keep that single monitor. - private fun readArray(context: Context, key: String): JSONArray { - synchronized(FaceclawAlarms::class.java) { - val raw = prefs(context).getString(key, "[]") - return try { - JSONArray(raw) - } catch (error: JSONException) { - JSONArray() - } - } - } + @Volatile + private var scheduleInstance: AlarmSchedule? = null - private fun writeArray(context: Context, key: String, array: JSONArray) { + /** The shared schedule/journal/log core over the device-protected prefs (one per process). */ + @JvmStatic + internal fun scheduleCore(context: Context): AlarmSchedule { + scheduleInstance?.let { return it } synchronized(FaceclawAlarms::class.java) { - prefs(context).edit().putString(key, array.toString()).apply() + scheduleInstance?.let { return it } + val prefs = prefs(context) + val created = AlarmSchedule(object : AlarmStore { + override fun read(key: String): String? = prefs.getString(key, null) + + override fun write(key: String, value: String?) { + prefs.edit().putString(key, value).apply() + } + }) + scheduleInstance = created + return created } } @JvmStatic - internal fun findScheduled(context: Context, id: Long): JSONObject? { - val scheduled = readArray(context, KEY_SCHEDULED) - for (index in 0 until scheduled.length()) { - val entry = scheduled.optJSONObject(index) - if (entry != null && entry.optLong("id") == id) { - return entry - } - } - return null - } - - private fun putScheduled(context: Context, entry: JSONObject) { - synchronized(FaceclawAlarms::class.java) { - val scheduled = readArray(context, KEY_SCHEDULED) - val next = JSONArray() - val id = entry.optLong("id") - for (index in 0 until scheduled.length()) { - val existing = scheduled.optJSONObject(index) - if (existing != null && existing.optLong("id") != id) { - next.put(existing) - } - } - next.put(entry) - writeArray(context, KEY_SCHEDULED, next) - } - } - - private fun removeScheduled(context: Context, id: Long) { - synchronized(FaceclawAlarms::class.java) { - val scheduled = readArray(context, KEY_SCHEDULED) - val next = JSONArray() - for (index in 0 until scheduled.length()) { - val existing = scheduled.optJSONObject(index) - if (existing != null && existing.optLong("id") != id) { - next.put(existing) - } - } - writeArray(context, KEY_SCHEDULED, next) - } - } + internal fun findScheduled(context: Context, id: Long): AlarmEntry? = scheduleCore(context).find(id) // ------------------------------------------------------------------ // Scheduling @@ -177,26 +128,16 @@ class FaceclawAlarms private constructor() { snoozeMinutes: Int ) { val appContext = context.applicationContext - val entry = JSONObject() - try { - entry.put("id", id) - entry.put("at", triggerAtMs) - entry.put("title", title ?: "") - entry.put("text", text ?: "") - entry.put("kind", kind ?: KIND_ALARM) - entry.put("snoozeMinutes", snoozeMinutes) - } catch (ignored: JSONException) { - return - } - putScheduled(appContext, entry) + val entry = AlarmEntry(id, triggerAtMs, title, text, kind ?: KIND_ALARM, snoozeMinutes) + scheduleCore(appContext).put(entry) armAlarm(appContext, entry) } - private fun armAlarm(appContext: Context, entry: JSONObject) { + private fun armAlarm(appContext: Context, entry: AlarmEntry) { val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? ?: return - val id = entry.optLong("id") - val triggerAt = Math.max(System.currentTimeMillis(), entry.optLong("at")) + val id = entry.id + val triggerAt = Math.max(System.currentTimeMillis(), entry.at) val fire = expiryPendingIntent(appContext, entry) try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -219,15 +160,9 @@ class FaceclawAlarms private constructor() { val appContext = context.applicationContext val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? if (manager != null) { - val entry = JSONObject() - try { - entry.put("id", id) - } catch (ignored: JSONException) { - // unreachable for a numeric put - } - manager.cancel(expiryPendingIntent(appContext, entry)) + manager.cancel(expiryPendingIntent(appContext, AlarmEntry(id, 0L, null, null, null, 10))) } - removeScheduled(appContext, id) + scheduleCore(appContext).remove(id) FaceclawAlarmService.stopItem(appContext, id) } @@ -239,25 +174,7 @@ class FaceclawAlarms private constructor() { @JvmStatic fun rescheduleAll(context: Context, reason: String?) { val appContext = context.applicationContext - val scheduled = readArray(appContext, KEY_SCHEDULED) - val now = System.currentTimeMillis() - var armed = 0 - for (index in 0 until scheduled.length()) { - val entry = scheduled.optJSONObject(index) ?: continue - val at = entry.optLong("at") - if (at <= now) { - if (now - at <= LATE_GRACE_MS) { - ringEntry(appContext, entry) - } else { - log(appContext, "missed " + entry.optString("kind") + " " + entry.optLong("id") + " (" + reason + ")") - removeScheduled(appContext, entry.optLong("id")) - } - continue - } - armAlarm(appContext, entry) - armed++ - } - log(appContext, "rescheduled $armed ($reason)") + scheduleCore(appContext).replay(reason, { ringEntry(appContext, it) }, { armAlarm(appContext, it) }) } /** @@ -271,24 +188,13 @@ class FaceclawAlarms private constructor() { return false } val appContext = context.applicationContext - val scheduled = readArray(appContext, KEY_SCHEDULED) - val now = System.currentTimeMillis() - var soonest = Long.MAX_VALUE - for (index in 0 until scheduled.length()) { - val entry = scheduled.optJSONObject(index) - if (entry != null && entry.optLong("at") > now) { - soonest = Math.min(soonest, entry.optLong("at")) - } - } - if (soonest == Long.MAX_VALUE) { + val core = scheduleCore(appContext) + if (core.soonestPendingAt() == null) { return false } val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? ?: return false - val next = manager.nextAlarmClock - // Another app's alarm may legitimately be sooner; only a later (or - // absent) system alarm proves ours is missing. - return next == null || next.triggerTime > soonest + 1000 + return core.looksStale(manager.nextAlarmClock?.triggerTime) } // ------------------------------------------------------------------ @@ -296,15 +202,8 @@ class FaceclawAlarms private constructor() { /** An item came due: hand it to the ringing service (idempotent per id). */ @JvmStatic - internal fun ringEntry(appContext: Context, entry: JSONObject) { - FaceclawAlarmService.ring( - appContext, - entry.optLong("id"), - entry.optString("title"), - entry.optString("text"), - entry.optString("kind", KIND_ALARM), - entry.optInt("snoozeMinutes", 10) - ) + internal fun ringEntry(appContext: Context, entry: AlarmEntry) { + FaceclawAlarmService.ring(appContext, entry.id, entry.title, entry.text, entry.kind, entry.snoozeMinutes) } /** The JS engine's own expiry path; the service deduplicates against the alarm's. */ @@ -313,13 +212,7 @@ class FaceclawAlarms private constructor() { val appContext = context.applicationContext val manager = appContext.getSystemService(Context.ALARM_SERVICE) as AlarmManager? if (manager != null) { - val probe = JSONObject() - try { - probe.put("id", id) - } catch (ignored: JSONException) { - // unreachable for a numeric put - } - manager.cancel(expiryPendingIntent(appContext, probe)) + manager.cancel(expiryPendingIntent(appContext, AlarmEntry(id, 0L, null, null, null, 10))) } FaceclawAlarmService.ring(appContext, id, title, text, kind, snoozeMinutes) } @@ -334,7 +227,7 @@ class FaceclawAlarms private constructor() { @JvmStatic fun acknowledge(context: Context, id: Long) { val appContext = context.applicationContext - removeScheduled(appContext, id) + scheduleCore(appContext).remove(id) FaceclawAlarmService.stopItem(appContext, id) } @@ -343,42 +236,15 @@ class FaceclawAlarms private constructor() { @JvmStatic fun setGlassesStatus(connected: Boolean, worn: Boolean, charging: Boolean) { - glassesConnected = connected - glassesWorn = worn - glassesCharging = charging - glassesStatusAtMs = System.currentTimeMillis() + glassesGate.set(connected, worn, charging) } /** True only when a fresh report says the glasses are connected, on a head, and not charging. */ @JvmStatic - internal fun glassesCanCarryAlarm(): Boolean { - val age = System.currentTimeMillis() - glassesStatusAtMs - if (glassesStatusAtMs == 0L || age > GLASSES_STATUS_MAX_AGE_MS) { - return false - } - return glassesConnected && glassesWorn && !glassesCharging - } + internal fun glassesCanCarryAlarm(): Boolean = glassesGate.canCarryAlarm() @JvmStatic - internal fun glassesStatusDescription(): String { - if (glassesStatusAtMs == 0L) { - return "no glasses status" - } - val age = System.currentTimeMillis() - glassesStatusAtMs - if (age > GLASSES_STATUS_MAX_AGE_MS) { - return "glasses status stale" - } - if (!glassesConnected) { - return "glasses not connected" - } - if (glassesCharging) { - return "glasses charging" - } - if (!glassesWorn) { - return "glasses not worn" - } - return "glasses worn" - } + internal fun glassesStatusDescription(): String = glassesGate.description() // ------------------------------------------------------------------ // Phone actions -> JS @@ -396,21 +262,7 @@ class FaceclawAlarms private constructor() { @JvmStatic internal fun recordPhoneAction(context: Context, id: Long, action: String, minutes: Int) { val appContext = context.applicationContext - val event = JSONObject() - try { - event.put("id", id) - event.put("action", action) - event.put("minutes", minutes) - event.put("at", System.currentTimeMillis()) - } catch (ignored: JSONException) { - return - } - synchronized(FaceclawAlarms::class.java) { - val journal = readArray(appContext, KEY_JOURNAL) - journal.put(event) - writeArray(appContext, KEY_JOURNAL, journal) - } - log(appContext, "phone " + action + " " + id + (if (minutes > 0) " ($minutes min)" else "")) + scheduleCore(appContext).appendJournal(id, action, minutes) val current = listener if (current != null) { mainHandler.post { @@ -425,14 +277,7 @@ class FaceclawAlarms private constructor() { /** Hand the journal to the JS side (as a JSON array) and clear it. */ @JvmStatic - fun drainJournal(context: Context): String { - synchronized(FaceclawAlarms::class.java) { - val appContext = context.applicationContext - val journal = readArray(appContext, KEY_JOURNAL) - writeArray(appContext, KEY_JOURNAL, JSONArray()) - return journal.toString() - } - } + fun drainJournal(context: Context): String = scheduleCore(context.applicationContext).drainJournal() // ------------------------------------------------------------------ // Reliability self-check @@ -577,45 +422,25 @@ class FaceclawAlarms private constructor() { @JvmStatic internal fun log(context: Context, line: String) { - synchronized(FaceclawAlarms::class.java) { - val appContext = context.applicationContext - val log = readArray(appContext, KEY_LOG) - val next = JSONArray() - val start = Math.max(0, log.length() - (LOG_LINES - 1)) - for (index in start until log.length()) { - next.put(log.optString(index)) - } - next.put(System.currentTimeMillis().toString() + " " + line) - writeArray(appContext, KEY_LOG, next) - } + scheduleCore(context.applicationContext).log(line) } /** The ring / miss / action log, newest last, one line per entry. */ @JvmStatic - fun readLog(context: Context): String { - val log = readArray(context.applicationContext, KEY_LOG) - val out = StringBuilder() - for (index in 0 until log.length()) { - if (index > 0) { - out.append('\n') - } - out.append(log.optString(index)) - } - return out.toString() - } + fun readLog(context: Context): String = scheduleCore(context.applicationContext).readLog() // ------------------------------------------------------------------ // Intents - private fun expiryPendingIntent(appContext: Context, entry: JSONObject): PendingIntent { + private fun expiryPendingIntent(appContext: Context, entry: AlarmEntry): PendingIntent { val intent = Intent(appContext, FaceclawAlarmReceiver::class.java) intent.action = ACTION_EXPIRE - val id = entry.optLong("id") + val id = entry.id intent.putExtra(EXTRA_ID, id) - intent.putExtra(EXTRA_TITLE, entry.optString("title")) - intent.putExtra(EXTRA_TEXT, entry.optString("text")) - intent.putExtra(EXTRA_KIND, entry.optString("kind", KIND_ALARM)) - intent.putExtra(EXTRA_SNOOZE_MINUTES, entry.optInt("snoozeMinutes", 10)) + intent.putExtra(EXTRA_TITLE, entry.title) + intent.putExtra(EXTRA_TEXT, entry.text) + intent.putExtra(EXTRA_KIND, entry.kind) + intent.putExtra(EXTRA_SNOOZE_MINUTES, entry.snoozeMinutes) var flags = PendingIntent.FLAG_UPDATE_CURRENT if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { flags = flags or PendingIntent.FLAG_IMMUTABLE @@ -635,9 +460,7 @@ class FaceclawAlarms private constructor() { } @JvmStatic - internal fun requestCode(id: Long): Int { - return (id xor (id ushr 32)).toInt() and 0x7fffffff - } + internal fun requestCode(id: Long): Int = AlarmSchedule.requestCode(id) @JvmStatic internal fun startServiceCompat(appContext: Context, intent: Intent) { diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt index 1ffe9d16..58e016cd 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawAudioTranscoder.kt @@ -9,8 +9,6 @@ import android.util.Log import java.io.File import java.io.FileInputStream import java.io.IOException -import java.nio.ByteBuffer -import java.nio.ByteOrder /** * Transcodes a 16-bit PCM WAV conversation recording into AAC-LC in an M4A @@ -28,69 +26,25 @@ class FaceclawAudioTranscoder( private const val TAG = "FaceclawTranscode" private const val CODEC_TIMEOUT_US: Long = 10_000 - /** Minimal RIFF walk: locates fmt and data chunks, 16-bit PCM only. */ + /** Shared RIFF walk over the file's first bytes: locates fmt and data chunks, 16-bit PCM only. */ @JvmStatic @Throws(IOException::class) - private fun readWavHeader(path: String?): WavInfo { - FileInputStream(path).use { `in` -> - val head = ByteArray(12) - if (`in`.read(head) != 12 || head[0] != 'R'.code.toByte() || head[1] != 'I'.code.toByte() || head[8] != 'W'.code.toByte()) { - throw IOException("not a WAV file") + private fun readWavHeader(path: String?): WavPcmReader.WavInfo { + val file = File(path) + val fileLength = file.length() + FileInputStream(file).use { `in` -> + val prefix = ByteArray(Math.min(fileLength, WavPcmReader.HEADER_PREFIX_BYTES.toLong()).toInt()) + var filled = 0 + while (filled < prefix.size) { + val read = `in`.read(prefix, filled, prefix.size - filled) + if (read <= 0) break + filled += read } - val info = WavInfo() - var offset: Long = 12 - val chunkHead = ByteArray(8) - while (`in`.read(chunkHead) == 8) { - val b = ByteBuffer.wrap(chunkHead).order(ByteOrder.LITTLE_ENDIAN) - val id = b.getInt() - val size = b.getInt().toLong() and 0xffffffffL - offset += 8 - if (id == 0x20746d66) { // "fmt " - val fmt = ByteArray(Math.min(size, 16L).toInt()) - if (`in`.read(fmt) != fmt.size) { - throw IOException("truncated fmt chunk") - } - val f = ByteBuffer.wrap(fmt).order(ByteOrder.LITTLE_ENDIAN) - val audioFormat = f.getShort().toInt() - info.channels = f.getShort().toInt() - info.sampleRate = f.getInt() - f.getInt() - f.getShort() - val bits = f.getShort().toInt() - if (audioFormat != 1 || bits != 16) { - throw IOException("only 16-bit PCM WAV is supported") - } - var skip = size - fmt.size - while (skip > 0) { - val step = `in`.skip(skip) - if (step <= 0) { - break - } - skip -= step - } - offset += size - } else if (id == 0x61746164) { // "data" - info.dataOffset = offset - // A zero size means the header was never patched (crash - // mid-recording); recover the length from the file size. - info.dataBytes = if (size > 0) size else File(path).length() - offset - break - } else { - var skip = size - while (skip > 0) { - val step = `in`.skip(skip) - if (step <= 0) { - break - } - skip -= step - } - offset += size - } + try { + return WavPcmReader.parseHeader(if (filled == prefix.size) prefix else prefix.copyOf(filled), fileLength) + } catch (e: IllegalArgumentException) { + throw IOException(e.message ?: "not a WAV file") } - if (info.sampleRate == 0 || info.dataOffset == 0L) { - throw IOException("missing fmt or data chunk") - } - return info } } } @@ -226,11 +180,4 @@ class FaceclawAudioTranscoder( } } } - - private class WavInfo { - var sampleRate = 0 - var channels = 0 - var dataOffset: Long = 0 - var dataBytes: Long = 0 - } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt index 97e8d343..d07ffde4 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt @@ -1,7 +1,6 @@ package com.faceclaw.app import android.annotation.SuppressLint -import android.bluetooth.BluetoothGatt import android.app.KeyguardManager import android.content.BroadcastReceiver import android.content.Context @@ -10,41 +9,21 @@ import android.content.IntentFilter import android.os.Handler import android.os.Looper import android.os.PowerManager -import android.os.SystemClock import android.util.Log -import java.io.PrintWriter -import java.io.StringWriter -import java.util.ArrayDeque -import java.util.ArrayList -import java.util.Arrays -import java.util.Collections -import java.util.HashMap -import java.util.Locale -import java.util.Random - +/** + * Android facade over the shared [GlassesSessionCore]: the JVM API TypeScript + * and the other Android classes call by name, plus the Android-only pieces: + * the GATT link ([AndroidSessionLink] over [FaceclawBleManager]), main-thread + * marshalling, the worker thread, the screen wake lock, keyguard/screen + * broadcast state, the Even-app conflict check, and the Bitmap/ByteBuffer/ + * Context entry points for previews, screenshots and recordings. + */ @SuppressLint("MissingPermission") -class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddress: String?, ringAddress: String?) : FaceclawBleListener, Runnable { +class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddress: String?, ringAddress: String?) { companion object { - private const val TAG = "FaceclawComm" - - // Local metadata for custom-command bookkeeping, not an EvenHub container. - // Submitted frames supply pixel geometry; the stock layout only captures input. - private val DASHBOARD_TILE: BleProtocol.ImageTileOptions = - BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288) - + private const val TAG = GlassesSessionCore.TAG private const val G2_SCREEN_WAKE_LOCK_TAG = "Faceclaw:G2Screen" - private const val FACECLAW_WAKE_LEASE_RENEW_MS = 45_000L - private const val FACECLAW_WAKE_CONTROL_WAIT_MS = 1_500L - private const val CFW_CLEANUP_WAIT_MS = 4_000L - private const val COMPASS_REPORT_INTERVAL_MS = 100 - private const val COMPASS_MIN_CHANGE_DEGREES = 0 - - // A timed-out benchmark message aborts the run, but its already-in-flight - // peers still time out one by one; keep the window comfortably below - // MAX_CONSECUTIVE_ACK_TIMEOUTS so a dead run can't escalate into a - // transport-failure reconnect all by itself. - private const val BENCHMARK_MAX_WINDOW = 6 // The most recently started communicator; lets app worker threads submit // surface frames without holding a cross-isolate reference to the bridge @@ -55,53 +34,6 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre fun getActive(): FaceclawBleCommunicator? { return activeInstance } - - private fun chargingStatusText(battery: Int): String { - return if (battery >= 0) - "Glasses charging. Battery $battery%." - else - "Glasses charging." - } - - private fun timestamp(elapsedMs: Long): String { - val wallMs = System.currentTimeMillis() - return String.format(Locale.US, "%tF %tT.%tL elapsed=%dms", wallMs, wallMs, wallMs, elapsedMs) - } - - private fun requireAddress(name: String, address: String?): String { - if (address == null || address.trim().isEmpty()) { - throw IllegalArgumentException("$name is required") - } - return address.trim() - } - - private fun hex(data: ByteArray?): String { - if (data == null || data.isEmpty()) { - return "" - } - val out = CharArray(data.size * 2) - val digits = "0123456789abcdef".toCharArray() - for (i in data.indices) { - val value = data[i].toInt() and 0xff - out[i * 2] = digits[value ushr 4] - out[i * 2 + 1] = digits[value and 0x0f] - } - return String(out) - } - - private fun safeMessage(t: Throwable?): String { - if (t == null) { - return "unknown" - } - val writer = StringWriter() - t.printStackTrace(PrintWriter(writer)) - val trace = writer.toString() - if (trace.trim().isNotEmpty()) { - return trace - } - val message = t.message - return if (message == null || message.trim().isEmpty()) t.toString() else message - } } private val appContext: Context = context.applicationContext @@ -111,222 +43,71 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre private val powerManager: PowerManager = appContext.getSystemService(Context.POWER_SERVICE) as PowerManager private val keyguardManager: KeyguardManager? = appContext.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager? private val bleManager: FaceclawBleManager = FaceclawBleManager(appContext) - private val interruptibleSleep = InterruptibleSleep() - private val lock = java.lang.Object() private val mainHandler = Handler(Looper.getMainLooper()) - private val rightAddress: String = requireAddress("rightAddress", rightAddress) - private val leftAddress: String = requireAddress("leftAddress", leftAddress) - private val ringAddress: String = ringAddress?.trim() ?: "" - - @Volatile private var listener: FaceclawBleCommunicatorListener? = null - private val imuListeners: MutableList = - java.util.concurrent.CopyOnWriteArrayList() - /** A compass subscriber plus the Looper it registered from (see addCompassListener). */ - private class CompassSubscription( - @JvmField val listener: FaceclawCompassListener, - @JvmField val handler: Handler, - ) - - private val compassSubscriptions: MutableList = - java.util.concurrent.CopyOnWriteArrayList() - private val ambientLightListeners: MutableList = - java.util.concurrent.CopyOnWriteArrayList() - private val micStatusListeners: MutableList = - java.util.concurrent.CopyOnWriteArrayList() + private val mainDispatcher = SessionDispatcher { action -> mainHandler.post { action() } } @Volatile private var workerThread: Thread? = null - @Volatile private var running = false - @Volatile private var userDisconnectRequested = false - // Set when a connect attempt failed while an arm's Android bond is gone: - // retrying is pointless until the user re-pairs, so the worker loop parks - // instead of redialing. Cleared by start() (a fresh explicit connect). - @Volatile private var reconnectHalted = false - - private var phase = "disconnected" - private var status = "Disconnected." - - private var rightConnected = false - private var leftConnected = false - private var ringConnected = false - private var ringNotificationsReady = false - private var sessionReady = false - private var fixedLayoutCreated = false - private var shutdownRequested = false - // CFW firmware-debug-flags overlay (mode 7). Desired value pushed from TS; the - // sub-op last sent this session (-1 = not yet), reset on (re)connect so the - // overlay state is re-asserted on every reconnect and whenever the value changes. - @Volatile private var firmwareDebugFlagsEnabled = false - private var firmwareDebugFlagsLastSent = -1 - // Desired CFW mode-10 compass state. It survives reconnects; lastSent is - // reset with each session so an open Compass window is re-asserted. - /** - * Who currently wants the stock compass running (the Compass window, the - * Navigate worker, ...). The magnetometer is one shared resource, so it - * stays on while any owner holds it and is released when the last lets go; - * this keeps one app's release from silently switching off another's feed. - */ - private val compassOwners: MutableSet = HashSet() - private var compassControlLastSent = -1 - // Whether the glasses-side compass may still be running: set when an enable - // is enqueued, cleared only when a disable is acked. Drives the forced - // disable sent ahead of an EvenHub shutdown/suspend, since a pending - // disable can be wiped by the shutdown's queue flush and the retry loop - // does not run while shutdownRequested (magnetometer left on = battery drain). - private var compassMaybeOn = false - private var startupProbePending = false - // Desired ownership of CFW's fail-open stock-wake lease (dashboard launch - // and Even AI foreground takeover). This survives a transport reconnect; - // the lease itself is volatile firmware state and is re-acquired once both - // arms are ready. - private var faceclawWakeLeaseEnabled = false - private var lastFaceclawWakeLeaseQueuedAtMs = 0L - private var faceclawWakeControlGeneration = 0 - private var faceclawWakeControlSentCount = 0 - private var lastFaceclawFramebufferLeaseQueuedAtMs = 0L - private var faceclawFramebufferControlGeneration = 0 - private var faceclawFramebufferControlSentCount = 0 - private var faceclawWakePendingNonce = -1 - /** - * The last firmware-info read said the glasses run Faceclaw's custom - * firmware. Gates the private modes (cleanup, resource cache, ...) so stock - * or third-party firmware never sees them; the TS side checks the actual - * revision and disconnects on a mismatch, so no per-feature gating is - * needed here. - */ - private var customFirmwareDetected = false - private var cfwCleanupDelivered = false - private var lastCfwCleanupAckMagic = 0 - - private var reconnectAfterMs = 0L - private var ringReconnectAfterMs = 0L - private var lastAckAtMs = 0L - private var lastIncomingAtMs = 0L - private var lastHeartbeatSentAtMs = 0L - private var lastHeartbeatAckedAtMs = 0L - private var lastConnectionOrInputAtMs = 0L - private var lastBatteryRefreshAtMs = 0L - private var imageRetryAfterMs = 0L - private var lastSessionReadyAtMs = 0L - private var lastEvenAppConflictAtMs = 0L - private var consecutiveAckTimeouts = 0 - private var lastAudioControlAckMagic = 0 - - private val connectionOptions = ConnectionOptions() - private val magicPool = BleMagicPool(AndroidProtocolPlatform) - private val messageBuilder = MessageBuilder(magicPool) - private var nextTransportSeq = 0x40 - private var nextMapSessionId = 0 - private var nextImageUpdateId = 1 - // Wire frame id for mode-3 deltas (CFW reorder/skip/dup diagnostic). uint16, - // advanced by 1 per emitted delta; kept in [1, 0xfffe] to avoid the CFW's - // 0xffff "empty" sentinel. - private var nextImageFrameId = 1 - private var lastShutdownAckMagic = 0 - private var lastShutdownExitAtMs = 0L - private var headsetBattery = -1 - private var headsetCharging = -1 - private var ringBattery = -1 - private var ringCharging = -1 - // Silent mode: 1 = on, 0 = off, -1 = not yet known. See updateSilentModeLocked. - private var silentMode = -1 - private var wearState = -1 - private var phoneLockState = -1 - private var lastPhoneLockCheckAtMs = 0L - private var phoneLockReceiverRegistered = false - private var audioCaptureActive = false - private var firmwareInfoQueried = false - // Glasses are in the charging case: nobody is wearing them, so display - // communication pauses and only battery polls flow (see driveSession). - private var chargingMode = false - @Volatile private var audioPacketListener: FaceclawAudioPacketListener? = null private var g2ScreenWakeLock: PowerManager.WakeLock? = null + private var phoneLockReceiverRegistered = false - // BLE bandwidth benchmark (Developer app). Streams no-op image payloads - // (CFW mode 7 with an unused sub-op: parsed, acked, and discarded — stock - // firmware likewise ignores unknown image modes) for a fixed duration with - // a selectable message size and pipeline window, then reports throughput. - // While active, desired-frame sends are held back and heartbeats are - // satisfied by the benchmark's own acks, so the stream is the only image - // traffic. All state below is guarded by `lock`; results are read with - // getBandwidthBenchmarkStatus() and survive until the next run starts. - private var benchmarkActive = false - private var benchmarkAborted = false - private val benchmarkRandom = Random() - private var benchmarkMessageSize = 0 - private var benchmarkWindowSize = 0 - private var benchmarkDurationMs = 0 - private var benchmarkLinkMode = 0 - private var benchmarkLinkPending = false - private var benchmarkReadyAtMs = 0L - private var benchmarkStartAtMs = 0L // first benchmark write; 0 until then - private var benchmarkDeadlineAtMs = 0L // start + duration; MAX_VALUE until first write - private var benchmarkLastAckAtMs = 0L - private var benchmarkEndAtMs = 0L // 0 while running; set when the run drains - private var benchmarkMessagesSent = 0 - private var benchmarkMessagesAcked = 0 - private var benchmarkTimeouts = 0 - private var benchmarkPayloadBytesAcked = 0L - private var benchmarkWireBytesAcked = 0L + private val host = object : SessionHost { + override fun postToMain(action: () -> Unit) { + mainHandler.post { action() } + } - private val phoneLockReceiver: BroadcastReceiver = object : BroadcastReceiver() { - override fun onReceive(context: Context?, intent: Intent?) { - emitPhoneLockStateIfChanged(true) - interruptibleSleep.interrupt() + override fun currentThreadDispatcher(): SessionDispatcher { + val looper = Looper.myLooper() ?: return mainDispatcher + val handler = Handler(looper) + return SessionDispatcher { action -> handler.post { action() } } + } + + override fun isPhoneLocked(): Boolean = keyguardManager != null && keyguardManager.isDeviceLocked + + override fun setScreenWakeLock(on: Boolean) = updateG2ScreenWakeLock(on) + + override fun isEvenAppActive(): Boolean = FaceclawEvenAppDetector.isEvenNotificationActive(appContext) + + override fun startWorker(body: () -> Unit) { + val thread = Thread(body, "FaceclawBleCommunicator") + workerThread = thread + thread.start() + } + + override fun joinWorker(timeoutMs: Long) { + val threadToJoin = workerThread ?: return + threadToJoin.interrupt() + try { + threadToJoin.join(timeoutMs) + } catch (e: InterruptedException) { + Thread.currentThread().interrupt() + } + workerThread = null + } + + override fun log(level: SessionLogLevel, tag: String, message: String, error: Throwable?) { + when (level) { + SessionLogLevel.DEBUG -> Log.d(tag, message) + SessionLogLevel.INFO -> Log.i(tag, message) + SessionLogLevel.WARN -> if (error != null) Log.w(tag, message, error) else Log.w(tag, message) + SessionLogLevel.ERROR -> if (error != null) Log.e(tag, message, error) else Log.e(tag, message) + } } } - private var displayedFingerprint = "" - // The frame the firmware shadow will hold once the current image pipeline - // drains: the most recently ENQUEUED image (headerless packed 4bpp, see - // BmpUtil.pack4bppFromGray8), which is the correct base for the next delta - // when frames are pipelined. Set at enqueue; cleared whenever the image - // pipeline is cleared (clearAllMessagesLocked / clearMessagesOfKindLocked - // "image"), so it is only ever read while it holds a valid current-session base. - private var lastEnqueuedPacked: ByteArray = ByteArray(0) - private var lastEnqueuedWidth = 0 - private var lastEnqueuedHeight = 0 - private var lastEnqueuedFingerprint = "" - private val imageUpdateStats: MutableMap = HashMap() + private val core = GlassesSessionCore( + AndroidSessionLink(bleManager), + host, + FrameTimings.getInstance().core, + AndroidProtocolPlatform, + rightAddress, + leftAddress, + ringAddress, + ) - private val desiredTilesLock = Any() - private var desiredFingerprint = "" - // Headerless packed 4bpp frame (see BmpUtil.pack4bppFromGray8) plus its - // pixel dimensions. - private var desiredPacked: ByteArray? = ByteArray(0) - private var desiredWidth = 0 - private var desiredHeight = 0 - private var desiredPaintMs = 0 - private var desiredFrameId = 0 - // Screen-space deferred draws (glyphs + images) whose pixels are baked - // into desiredPacked; the resource-cache planner may replay them as - // on-glasses cached draws. - private var desiredDraws: Array? = arrayOf() - // (frame, reason) of the last "waiting to send" line, so a frame that - // stalls for seconds records one line per state change (see - // noteImageStallLocked). Send-loop thread only. - private var stallFrameId = 0 - private var stallReason = "" - // Highest compositor sequence stored as the desired frame; composites that - // lost a store race to a newer one are discarded (their content is already - // included in the newer composite). - private var lastStoredCompositeSeq = 0L - - // Wire submissions need screenGray + the shell scene, never preview pixels. - // Preview/screenshot/recording callers render those explicitly on demand. - private val compositor = SurfaceCompositor(false) - - // Phone-side model of the CFW's 192 KiB resource cache. - // Reset whenever the image pipeline / EvenHub session is torn down: the - // firmware frees the cache with the fb lease, and after any resync the - // cheap safe assumption is an empty cache (glyphs re-upload lazily). - private val resourceCache = ResourceCacheState() - private val scenePlanner = ScenePlanner(resourceCache) - private var desiredShellScene: ShellScene = ShellScene.EMPTY - - private val pendingMessages = ArrayDeque() - private val cfwTransports = arrayOf(CfwTransport(AndroidProtocolPlatform), CfwTransport(AndroidProtocolPlatform)) - private val inFlightMessages = ArrayDeque() - private var prewrittenMessage: OutboundMessage? = null - private var prewrittenFrames: List = Collections.emptyList() + private val phoneLockReceiver: BroadcastReceiver = object : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + core.onPhoneLockSignal() + } + } // Active animated-GIF screen recording, or null when idle. Frames are // pushed by recordScreenFrame(), which the TS side calls at each @@ -334,7 +115,7 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre @Volatile private var screenRecorder: GifScreenRecorder? = null init { - bleManager.setListener(this) + bleManager.setListener(core) val phoneLockFilter = IntentFilter() phoneLockFilter.addAction(Intent.ACTION_SCREEN_ON) phoneLockFilter.addAction(Intent.ACTION_SCREEN_OFF) @@ -343,746 +124,98 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre phoneLockReceiverRegistered = true } - - fun setListener(listener: FaceclawBleCommunicatorListener?) { - this.listener = listener - emitState() - emitPhoneLockStateIfChanged(true) - } + fun setListener(listener: FaceclawBleCommunicatorListener?) = core.setListener(listener) fun start() { - synchronized(lock) { - if (running) { - return - } - running = true - userDisconnectRequested = false - reconnectHalted = false - shutdownRequested = false + if (core.start()) { activeInstance = this - val thread = Thread(this, "FaceclawBleCommunicator") - workerThread = thread - thread.start() } } - fun disconnect() { - /* On the normal path DashboardController already sent mode 11 after - * quiescing its producers. Also cover direct/early close callers here; - * a successful cleanup must remain the final BLE message. Older CFWs - * fall back to the standalone framebuffer-lease release. */ - if (!cfwCleanupDelivered && !sendCfwCleanup()) { - releaseFaceclawFramebufferLease() - } - val threadToJoin: Thread? - synchronized(lock) { - userDisconnectRequested = true - running = false - audioCaptureActive = false - audioPacketListener = null - threadToJoin = workerThread - } - setStateDisplay("disconnecting", "Disconnecting...") - interruptibleSleep.interrupt() - if (threadToJoin != null) { - threadToJoin.interrupt() - try { - threadToJoin.join(5_000) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - } - } - synchronized(lock) { - workerThread = null - resetSessionStateLocked() - clearAllMessagesLocked("disconnect") - // Unknown until the next connection's first push or settings poll. - silentMode = -1 - } - bleManager.disconnect(rightAddress) - bleManager.disconnect(leftAddress) - if (hasRingAddress()) { - bleManager.disconnect(ringAddress) - } - bleManager.close() - releaseG2ScreenWakeLock() - setStateDisplay("disconnected", "Disconnected.") - } + fun disconnect() = core.disconnect() fun close() { if (activeInstance === this) { activeInstance = null } - disconnect() - for (transport in cfwTransports) transport.close() + core.close() if (phoneLockReceiverRegistered) { phoneLockReceiverRegistered = false appContext.unregisterReceiver(phoneLockReceiver) } } - fun setG2ScreenOn(screenOn: Boolean) { - mainHandler.post { updateG2ScreenWakeLock(screenOn) } - } + fun setG2ScreenOn(screenOn: Boolean) = core.setG2ScreenOn(screenOn) - fun setFirmwareDebugFlags(enabled: Boolean) { - // Just record it; the drive loop emits the mode-7 control message when the - // display path is ready and idle, and re-emits when this value changes. - firmwareDebugFlagsEnabled = enabled - } + fun setFirmwareDebugFlags(enabled: Boolean) = core.setFirmwareDebugFlags(enabled) - fun startG2AudioCapture(listener: FaceclawAudioPacketListener?): Boolean { - if (listener == null) { - throw IllegalArgumentException("listener is required") - } - var magic = 0 - synchronized(lock) { - if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { - logLine("skip G2 mic enable; EvenHub display path not ready") - return false - } - audioPacketListener = listener - val message = createAudioControlMessageLocked(true) - magic = message.magic - pendingMessages.addFirst(message) - logLine("queue G2 mic enable") - } - interruptibleSleep.interrupt() - return waitForAudioControlAck(magic, "enable") - } + fun startG2AudioCapture(listener: FaceclawAudioPacketListener?): Boolean = core.startG2AudioCapture(listener) - fun stopG2AudioCapture() { - var magic = 0 - synchronized(lock) { - audioPacketListener = null - audioCaptureActive = false - clearMessagesOfKindLocked("audio-control") - if (running && sessionReady) { - val message = createAudioControlMessageLocked(false) - magic = message.magic - pendingMessages.addFirst(message) - logLine("queue G2 mic disable") - } - } - interruptibleSleep.interrupt() - if (magic != 0) { - waitForAudioControlAck(magic, "disable") - } - } + fun stopG2AudioCapture() = core.stopG2AudioCapture() - fun isSessionReady(): Boolean { - synchronized(lock) { - return running && sessionReady - } - } + fun isSessionReady(): Boolean = core.isSessionReady() - /** - * Whether the glasses mic is enabled right now. The enable lives in the - * current EvenHub session, so it dies with a transport drop, the charging - * case, or a suspend — silently, from the phone's point of view. Callers - * that track a capture across those events must check this rather than - * assume their earlier enable still holds. - */ - fun isAudioCaptureActive(): Boolean { - synchronized(lock) { - return running && sessionReady && !shutdownRequested && audioCaptureActive - } - } + /** See [GlassesSessionCore.isAudioCaptureActive]. */ + fun isAudioCaptureActive(): Boolean = core.isAudioCaptureActive() - /** - * Acquire/renew or release CFW's volatile wake-takeover lease on both - * arms. Delivery (not a protocol ACK) is awaited so a caller can ensure - * the fail-open firmware policy is installed before relying on wakeword - * interception or suspending EvenHub. - */ - fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean { - val generation: Int - synchronized(lock) { - faceclawWakeLeaseEnabled = enabled - if (!running || !sessionReady) { - return !enabled - } - generation = enqueueFaceclawWakeControlLocked( - if (enabled) BleProtocol.FACECLAW_WAKE_OP_ACQUIRE else BleProtocol.FACECLAW_WAKE_OP_RELEASE, - 0, - true - ) - if (!enabled) { - faceclawWakePendingNonce = -1 - } - } - interruptibleSleep.interrupt() - return waitForFaceclawWakeControlDelivery(generation, FACECLAW_WAKE_CONTROL_WAIT_MS) - } + fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean = core.setFaceclawWakeLeaseEnabled(enabled) - /** - * Wait until the recreated layout and retained compositor frame have both - * landed. If this wake came from CFW's deferred double tap, READY - * is then sent to both arms to cancel their stock-dashboard fallback. - */ - fun awaitEvenHubSessionReady(timeoutMs: Int): Boolean { - val deadline = SystemClock.elapsedRealtime() + Math.max(0, timeoutMs) - var readyGeneration = 0 - synchronized(lock) { - while (running && sessionReady) { - var frameReady = false - synchronized(desiredTilesLock) { - frameReady = desiredFingerprint.isNotEmpty() - && desiredFingerprint == displayedFingerprint - } - if (!shutdownRequested && fixedLayoutCreated && frameReady) { - if (faceclawWakePendingNonce >= 0) { - readyGeneration = enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_READY, - faceclawWakePendingNonce, - true - ) - faceclawWakePendingNonce = -1 - } - break - } - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - return false - } - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - return false - } - } - if (!running || !sessionReady) { - return false - } - } - if (readyGeneration != 0) { - interruptibleSleep.interrupt() - if (!waitForFaceclawWakeControlDelivery(readyGeneration, FACECLAW_WAKE_CONTROL_WAIT_MS)) { - logLine("wake READY delivery not confirmed before fallback deadline") - } - } - return true - } + fun awaitEvenHubSessionReady(timeoutMs: Int): Boolean = core.awaitEvenHubSessionReady(timeoutMs) - /** - * Enable or disable the IMU (accelerometer) report stream. Fire-and-forget: - * the control message is queued ahead of other traffic; readings arrive via - * registered FaceclawImuListeners. reportFrq is the requested sample rate - * (ignored on disable). - */ - fun setImuReportEnabled(enable: Boolean, reportFrq: Int) { - synchronized(lock) { - if (!running || !sessionReady) { - logLine("skip IMU " + (if (enable) "enable" else "disable") + "; session not ready") - return - } - clearMessagesOfKindLocked("imu-control") - val message = messageBuilder.enableOrDisableImu(enable, reportFrq) - message.onTimeout = MessageCallback { logLine("IMU control ack timeout") } - pendingMessages.addFirst(message) - logLine("queue IMU " + (if (enable) "enable freq=$reportFrq" else "disable")) - } - interruptibleSleep.interrupt() - } + fun setImuReportEnabled(enable: Boolean, reportFrq: Int) = core.setImuReportEnabled(enable, reportFrq) - /** - * Enable/disable the stock compass through CFW image-handler mode 10. The - * desired state is retained across reconnects; headings arrive through - * stock sid-0x08 navigation notifications and FaceclawCompassListeners. - */ - fun setCompassEnabled(enable: Boolean) { - setCompassEnabled("compass", enable) - } + fun setCompassEnabled(enable: Boolean) = core.setCompassEnabled(enable) - /** - * As above, on behalf of a named owner. The compass runs while at least - * one owner has enabled it; an owner disabling it only takes effect once - * no other owner still wants it. - */ - fun setCompassEnabled(owner: String?, enable: Boolean) { - synchronized(lock) { - val before = compassOwners.isNotEmpty() - if (enable) { - compassOwners.add(owner) - } else { - compassOwners.remove(owner) - } - val wanted = compassOwners.isNotEmpty() - if (wanted == before && compassControlLastSent == (if (wanted) 1 else 0)) { - logLine("compass " + (if (enable) "enable" else "disable") + " by " + owner - + "; state unchanged (owners=" + compassOwners + ")") - return - } - compassControlLastSent = -1 - clearMessagesOfKindLocked("compass-control") - if (running && sessionReady && !shutdownRequested && fixedLayoutCreated) { - enqueueCompassControlLocked(true, wanted) - } else { - logLine("defer compass " + (if (enable) "enable" else "disable") + "; display path not ready") - } - } - interruptibleSleep.interrupt() - } + fun setCompassEnabled(owner: String?, enable: Boolean) = core.setCompassEnabled(owner, enable) - /** - * Set the lens brightness. Fire-and-forget, like the IMU control: the - * message is queued ahead of other traffic and any not-yet-sent brightness - * message is superseded. When autoAdjust is true the ambient-light sensor - * drives brightness and brightnessLevel is ignored; otherwise - * brightnessLevel (0-100) is applied directly. - */ - fun setBrightness(autoAdjust: Boolean, brightnessLevel: Int) { - synchronized(lock) { - if (!running || !sessionReady) { - logLine("skip brightness set; session not ready") - return - } - clearMessagesOfKindLocked("brightness-control") - val message = messageBuilder.setBrightness(autoAdjust, brightnessLevel) - message.onTimeout = MessageCallback { logLine("brightness control ack timeout") } - pendingMessages.addFirst(message) - logLine("queue brightness " + (if (autoAdjust) "auto" else "level=$brightnessLevel")) - } - interruptibleSleep.interrupt() - } + fun setBrightness(autoAdjust: Boolean, brightnessLevel: Int) = core.setBrightness(autoAdjust, brightnessLevel) - /** - * Enable the stock wear detector, then ask CFW to emit its current cached - * state. The queue order matters: the query must run after the setting is - * applied, including on a fresh install where wear detection was disabled. - */ - fun enableWearDetectionAndRequestState() { - synchronized(lock) { - if (!running || !sessionReady) { - logLine("skip wear detector setup; session not ready") - return - } - clearMessagesOfKindLocked("wear-detection-control") - clearMessagesOfKindLocked("wear-query-control") - val queryLeft = messageBuilder.faceclawWearQuery(true) - val queryRight = messageBuilder.faceclawWearQuery(false) - val enable = messageBuilder.setWearDetection(true) - enable.onTimeout = MessageCallback { logLine("wear detection enable ack timeout") } - pendingMessages.addFirst(queryLeft) - pendingMessages.addFirst(queryRight) - pendingMessages.addFirst(enable) - logLine("queue wear detection enable + current-state query") - } - interruptibleSleep.interrupt() - } + fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState() - /** - * Start the BLE bandwidth benchmark: stream messageSize-byte no-op image - * payloads for durationMs, keeping up to windowSize messages awaiting ack - * at once, then leave the results for getBandwidthBenchmarkStatus(). - * Returns false when a run is already active or the image path is not - * ready. The duration clock starts at the first benchmark write, so - * traffic already queued ahead of the run doesn't count against it. - */ - fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean { - return startBandwidthBenchmarkWithLinkMode(messageSize, windowSize, durationMs, 0) - } + fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean = + core.startBandwidthBenchmark(messageSize, windowSize, durationMs) // 0: current link; 1: re-request HIGH; 2: request 2M; 3: both. fun startBandwidthBenchmarkWithLinkMode(messageSize: Int, windowSize: Int, - durationMs: Int, linkMode: Int): Boolean { - synchronized(lock) { - if (benchmarkActive || !running || !sessionReady || !fixedLayoutCreated - || shutdownRequested || chargingMode) { - logLine("skip bandwidth benchmark; already running or image path not ready") - return false - } - benchmarkMessageSize = Math.max(2, Math.min(messageSize, ConnectionOptions.IMAGE_FRAGMENT_SIZE)) - benchmarkWindowSize = Math.max(1, Math.min(windowSize, BENCHMARK_MAX_WINDOW)) - benchmarkDurationMs = Math.max(1_000, durationMs) - benchmarkLinkMode = linkMode and 3 - benchmarkLinkPending = true - benchmarkReadyAtMs = Long.MAX_VALUE - benchmarkStartAtMs = 0 - benchmarkDeadlineAtMs = Long.MAX_VALUE - benchmarkLastAckAtMs = 0 - benchmarkEndAtMs = 0 - benchmarkMessagesSent = 0 - benchmarkMessagesAcked = 0 - benchmarkTimeouts = 0 - benchmarkPayloadBytesAcked = 0 - benchmarkWireBytesAcked = 0 - benchmarkAborted = false - benchmarkActive = true - logLine("bandwidth benchmark start: size=" + benchmarkMessageSize - + "B window=" + benchmarkWindowSize + " duration=" + benchmarkDurationMs - + "ms linkMode=" + benchmarkLinkMode) - } - interruptibleSleep.interrupt() - return true - } + durationMs: Int, linkMode: Int): Boolean = + core.startBandwidthBenchmarkWithLinkMode(messageSize, windowSize, durationMs, linkMode) - /** - * Cancel an in-progress benchmark (benchmark page closed). Queued no-op - * messages are dropped; in-flight ones drain through their normal acks. - */ - fun cancelBandwidthBenchmark() { - synchronized(lock) { - if (!benchmarkActive) { - return - } - clearMessagesOfKindLocked("bandwidth") - finishBenchmarkLocked(true, "cancelled") - } - interruptibleSleep.interrupt() - } + fun cancelBandwidthBenchmark() = core.cancelBandwidthBenchmark() /** Status/results of the current or most recent benchmark run, as JSON. */ - fun getBandwidthBenchmarkStatus(): String { - synchronized(lock) { - val state = if (benchmarkActive) - (if (benchmarkStartAtMs == 0L) "starting" else "running") - else - (if (benchmarkEndAtMs != 0L) "done" else "idle") - val end = if (benchmarkActive) SystemClock.elapsedRealtime() else benchmarkEndAtMs - val elapsed = if (benchmarkStartAtMs == 0L) 0L else Math.max(0L, end - benchmarkStartAtMs) - try { - val status = org.json.JSONObject() - status.put("state", state) - status.put("messageSize", benchmarkMessageSize) - status.put("windowSize", benchmarkWindowSize) - status.put("linkMode", benchmarkLinkMode) - status.put("elapsedMs", elapsed) - status.put("messagesSent", benchmarkMessagesSent) - status.put("messagesAcked", benchmarkMessagesAcked) - status.put("timeouts", benchmarkTimeouts) - status.put("payloadBytesAcked", benchmarkPayloadBytesAcked) - status.put("wireBytesAcked", benchmarkWireBytesAcked) - status.put("aborted", benchmarkAborted) - return status.toString() - } catch (e: org.json.JSONException) { - return "{\"state\":\"idle\"}" - } - } - } + fun getBandwidthBenchmarkStatus(): String = core.getBandwidthBenchmarkStatus() - /** Pending + in-flight benchmark no-op messages. */ - private fun benchmarkOutstandingLocked(): Int { - var count = 0 - for (message in pendingMessages) { - if ("bandwidth" == message.kind) count++ - } - for (message in inFlightMessages) { - if ("bandwidth" == message.kind) count++ - } - return count - } + fun addImuListener(listener: FaceclawImuListener?) = core.addImuListener(listener) - /** - * Keep the benchmark stream fed: top the pending queue up so the send - * window never starves, stop enqueueing once the run expires (or a message - * times out), and finish the run when the last outstanding message drains. - */ - private fun maintainBenchmarkLocked(now: Long) { - if (!sessionReady || !fixedLayoutCreated || shutdownRequested) { - finishBenchmarkLocked(true, "session no longer ready") - return - } - if (benchmarkLinkPending || now < benchmarkReadyAtMs) { - return - } - if (benchmarkAborted || now >= benchmarkDeadlineAtMs) { - // The run is over: drop queued-but-unsent no-ops (sending them - // would stretch the run past its deadline) and finish once the - // in-flight tail has acked or timed out. - val pendingIterator = pendingMessages.iterator() - while (pendingIterator.hasNext()) { - val queued = pendingIterator.next() - if ("bandwidth" == queued.kind) { - pendingIterator.remove() - magicPool.release(queued.sid, queued.magic, queued.label, "benchmark over") - } - } - if (benchmarkOutstandingLocked() == 0) { - finishBenchmarkLocked(false, "complete") - } - return - } - // One more than the window so a fresh message is always ready to write - // the moment an ack frees a slot. - var outstanding = benchmarkOutstandingLocked() - while (outstanding <= benchmarkWindowSize) { - enqueueBenchmarkMessageLocked() - outstanding++ - } - } + fun removeImuListener(listener: FaceclawImuListener?) = core.removeImuListener(listener) - private fun finishBenchmarkLocked(aborted: Boolean, reason: String) { - if (!benchmarkActive) { - return - } - benchmarkActive = false - benchmarkAborted = benchmarkAborted or aborted - // Prefer the last ack as the end time so drain lag after the deadline - // doesn't dilute the throughput figure. - benchmarkEndAtMs = if (benchmarkLastAckAtMs != 0L) benchmarkLastAckAtMs else SystemClock.elapsedRealtime() - logLine("bandwidth benchmark " + (if (benchmarkAborted) "aborted" else "finished") + " (" + reason + "): " - + benchmarkMessagesAcked + "/" + benchmarkMessagesSent + " acked, " - + benchmarkPayloadBytesAcked + "B payload, " + benchmarkTimeouts + " timeouts") - } + fun addAmbientLightListener(listener: FaceclawAmbientLightListener?) = core.addAmbientLightListener(listener) - private fun enqueueBenchmarkMessageLocked() { - // Fresh bytes per message: the transport's persistent compression history - // would compress even a random payload if we reused it across the run. - val payload = ByteArray(benchmarkMessageSize) - benchmarkRandom.nextBytes(payload) - payload[0] = CFW_MSG_DIAGNOSTICS.toByte() // CFW diagnostic-control mode... - payload[1] = 0x7f.toByte() // ...with an unused sub-op: acked, no effect - val message = messageBuilder.imagePayload( - "bandwidth", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - "bandwidth no-op " + payload.size + "B", - connectionOptions.sendImagesToLeft) - val payloadBytes = payload.size - // Logical custom-message bytes; excludes length tag and packet framing. - val wireBytes = message.message.size - message.onSent = MessageCallback { - benchmarkMessagesSent++ - if (benchmarkStartAtMs == 0L) { - benchmarkStartAtMs = SystemClock.elapsedRealtime() - benchmarkDeadlineAtMs = benchmarkStartAtMs + benchmarkDurationMs - } - } - message.onAck = MessageCallback { - val ackedAtMs = SystemClock.elapsedRealtime() - benchmarkMessagesAcked++ - benchmarkPayloadBytesAcked += payloadBytes - benchmarkWireBytesAcked += wireBytes - benchmarkLastAckAtMs = ackedAtMs - // No-op payloads ride the image path, so the firmware resets its - // heartbeat timer on them just like real image messages. - lastHeartbeatAckedAtMs = ackedAtMs - } - message.onTimeout = MessageCallback { - benchmarkTimeouts++ - benchmarkAborted = true - logLine("bandwidth benchmark ack timeout") - } - pendingMessages.addLast(message) - } + fun removeAmbientLightListener(listener: FaceclawAmbientLightListener?) = core.removeAmbientLightListener(listener) - fun addImuListener(listener: FaceclawImuListener?) { - if (listener != null) { - imuListeners.add(listener) - } - } + fun queryAmbientLight() = core.queryAmbientLight() - fun removeImuListener(listener: FaceclawImuListener?) { - if (listener != null) { - imuListeners.remove(listener) - } - } - - fun addAmbientLightListener(listener: FaceclawAmbientLightListener?) { - if (listener != null) { - ambientLightListeners.add(listener) - } - } - - fun removeAmbientLightListener(listener: FaceclawAmbientLightListener?) { - if (listener != null) { - ambientLightListeners.remove(listener) - } - } - - private fun emitAmbientLight(body: ByteArray) { - if (ambientLightListeners.isEmpty()) { - return - } - val copy = Arrays.copyOf(body, body.size) - mainHandler.post { - for (alsListener in ambientLightListeners) { - try { - alsListener.onAmbientLight(copy) - } catch (t: Throwable) { - Log.w(TAG, "ambient light listener failed", t) - } - } - } - } - - /** Request one CFW ambient-light report (image-handler mode 16 op 0). */ - fun queryAmbientLight() { - synchronized(lock) { - enqueueAmbientLightControlLocked(byteArrayOf(CFW_MSG_AMBIENT_LIGHT.toByte(), 0.toByte()), "als query", false) - } - interruptibleSleep.interrupt() - } - - /** - * Start or stop CFW passive light-sensor polling (image-handler mode 16 - * ops 1/2). While polling, the firmware reads its OPT3001 every intervalMs - * (clamped 100..5000 by the firmware), never steps the panel brightness - * itself, and pushes a field-105 report when the reading moved by at least - * minDelta or heartbeatMs elapsed. bindToLease stops polling automatically - * when the Faceclaw framebuffer lease is released or lapses. Starting is - * idempotent and re-opens the sensor if the stock firmware closed it. - */ fun setAmbientLightPolling(enable: Boolean, intervalMs: Int, minDelta: Int, - heartbeatMs: Int, bindToLease: Boolean) { - val payload = if (enable) - byteArrayOf( - CFW_MSG_AMBIENT_LIGHT.toByte(), - 1.toByte(), - (if (bindToLease) 1 else 0).toByte(), - (intervalMs and 0xff).toByte(), - ((intervalMs shr 8) and 0xff).toByte(), - (minDelta and 0xff).toByte(), - ((minDelta shr 8) and 0xff).toByte(), - (heartbeatMs and 0xff).toByte(), - ((heartbeatMs shr 8) and 0xff).toByte(), - ) - else - byteArrayOf(CFW_MSG_AMBIENT_LIGHT.toByte(), 2.toByte()) - synchronized(lock) { - clearMessagesOfKindLocked("als-control") - enqueueAmbientLightControlLocked(payload, "als polling " + (if (enable) "start" else "stop"), true) - } - interruptibleSleep.interrupt() - } + heartbeatMs: Int, bindToLease: Boolean) = + core.setAmbientLightPolling(enable, intervalMs, minDelta, heartbeatMs, bindToLease) - private fun enqueueAmbientLightControlLocked(payload: ByteArray, label: String, priority: Boolean) { - if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { - logLine("skip $label; display path not ready") - return - } - val message = messageBuilder.imagePayload( - "als-control", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - label, - connectionOptions.sendImagesToLeft) - message.onTimeout = MessageCallback { logLine("$label ack timeout") } - if (priority) pendingMessages.addFirst(message) - else pendingMessages.addLast(message) - logLine("queue $label") - } + fun addMicStatusListener(listener: FaceclawMicStatusListener?) = core.addMicStatusListener(listener) - fun addMicStatusListener(listener: FaceclawMicStatusListener?) { - if (listener != null) { - micStatusListeners.add(listener) - } - } + fun removeMicStatusListener(listener: FaceclawMicStatusListener?) = core.removeMicStatusListener(listener) - fun removeMicStatusListener(listener: FaceclawMicStatusListener?) { - if (listener != null) { - micStatusListeners.remove(listener) - } - } + fun sendFaceclawMicControl(record: ByteArray?, label: String, rightTemple: Boolean, leftTemple: Boolean) = + core.sendFaceclawMicControl(record, label, rightTemple, leftTemple) - private fun emitMicStatus(body: ByteArray, address: String) { - if (micStatusListeners.isEmpty()) { - return - } - val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" - else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?" - val copy = Arrays.copyOf(body, body.size) - mainHandler.post { - for (micListener in micStatusListeners) { - try { - micListener.onMicStatus(copy, arm) - } catch (t: Throwable) { - Log.w(TAG, "mic status listener failed", t) - } - } - } - } + fun startG2AudioForwarding(listener: FaceclawAudioPacketListener?): Boolean = core.startG2AudioForwarding(listener) - /** - * Queue a CFW mic_control record (['M','C',ver,op,...]) as a settings - * field-103 write to both temples, or to a single one. Fire-and-forget: - * the firmware answers with a field-104 status notify per temple, which - * arrives through addMicStatusListener. - */ - fun sendFaceclawMicControl(record: ByteArray?, label: String, rightTemple: Boolean, leftTemple: Boolean) { - if (record == null || record.size < 4) { - return - } - synchronized(lock) { - if (!running || !sessionReady) { - logLine("skip mic control ($label); session not ready") - return - } - if (rightTemple) { - pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, false)) - } - if (leftTemple) { - pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, true)) - } - logLine("queue mic control $label") - } - interruptibleSleep.interrupt() - } + fun stopG2AudioForwarding() = core.stopG2AudioForwarding() - /** - * Forward render-characteristic audio packets to the listener WITHOUT - * sending the stock EvenHub audio-control enable. Used for the CFW - * mic_control streaming path, where capture is armed through settings - * field 103 and the temples emit 'SM' frames on the same characteristic - * that stock mono LC3 uses. Returns false when no session is up. - */ - fun startG2AudioForwarding(listener: FaceclawAudioPacketListener?): Boolean { - if (listener == null) { - throw IllegalArgumentException("listener is required") - } - synchronized(lock) { - if (!running || !sessionReady || shutdownRequested) { - logLine("skip G2 audio forwarding; session not ready") - return false - } - audioPacketListener = listener - audioCaptureActive = true - logLine("G2 audio forwarding enabled") - } - return true - } + fun addCompassListener(listener: FaceclawCompassListener?) = core.addCompassListener(listener) - fun stopG2AudioForwarding() { - synchronized(lock) { - audioPacketListener = null - audioCaptureActive = false - logLine("G2 audio forwarding disabled") - } - } - - /** - * Subscribe to compass events. Callbacks are delivered on the Looper of - * the thread that registered (falling back to the main thread), so app - * worker isolates can listen without a cross-thread hop into their JS. - */ - fun addCompassListener(listener: FaceclawCompassListener?) { - if (listener == null) { - return - } - val looper = Looper.myLooper() - val handler = if (looper != null) Handler(looper) else mainHandler - compassSubscriptions.add(CompassSubscription(listener, handler)) - } - - fun removeCompassListener(listener: FaceclawCompassListener?) { - if (listener == null) { - return - } - for (subscription in compassSubscriptions) { - if (subscription.listener === listener) { - compassSubscriptions.remove(subscription) - } - } - } + fun removeCompassListener(listener: FaceclawCompassListener?) = core.removeCompassListener(listener) /** Set the compositor's output frame size. Call before configuring surfaces. */ - fun configureCompositorScreen(width: Int, height: Int) { - compositor.configureScreen(width, height) - } + fun configureCompositorScreen(width: Int, height: Int) = core.configureCompositorScreen(width, height) /** * The current composited screen as a phone-UI preview bitmap, or null @@ -1096,7 +229,7 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre /** As above; `green` renders the preview green-on-black (Settings > Phone display > Preview color). */ fun getCompositePreviewBitmap(brightenGamma: Double, green: Boolean): android.graphics.Bitmap? { - val composite = compositor.previewComposite() ?: return null + val composite = core.previewComposite() ?: return null return PreviewBitmapUtil.fromGray( java.nio.ByteBuffer.wrap(composite.gray), composite.width, composite.height, brightenGamma, green) } @@ -1104,7 +237,7 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre /** Save the current composite as a 4-bit grayscale PNG; returns the path or "". */ @Throws(java.io.IOException::class) fun saveCompositePngScreenshot(): String { - val composite = compositor.previewComposite() ?: return "" + val composite = core.previewComposite() ?: return "" return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height) } @@ -1115,7 +248,7 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre */ @Throws(java.io.IOException::class) fun saveCompositePngScreenshot(cropX: Int, cropY: Int, cropWidth: Int, cropHeight: Int): String { - val composite = compositor.previewComposite() ?: return "" + val composite = core.previewComposite() ?: return "" val x = Math.max(0, cropX) val y = Math.max(0, cropY) val width = Math.min(composite.width - x, cropWidth - (x - cropX)) @@ -1138,7 +271,7 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre /** Capture the current composite into the active recording; no-op when idle. */ fun recordScreenFrame() { val recorder = screenRecorder ?: return - val composite = compositor.previewComposite() ?: return + val composite = core.previewComposite() ?: return recorder.addFrame(composite.gray, composite.width, composite.height, System.currentTimeMillis()) } @@ -1151,74 +284,30 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre return "" } if (recorder.isOverflowed()) { - logLine("screen recording hit its frame cap; the tail was dropped") + Log.i(TAG, "screen recording hit its frame cap; the tail was dropped") } return recorder.save(appContext) } - /** - * Show or hide a compositor surface, immediately submitting the resulting - * frame. Recompositing here (rather than waiting for the next surface - * update) is what makes a just-foregrounded window's retained frame - * actually appear — otherwise a static window (e.g. the terminal hub) whose - * frame landed while briefly hidden would stay blank until its next repaint. - */ - fun setSurfaceVisible(id: String, visible: Boolean) { - // Its own frame: this recomposite is a real screen update with real - // latency, and without one it would show up in other frames' logs only - // as an anonymous "superseded by frame#0". - val frameId = FrameTimings.getInstance().startFrame( - "compositor:visible $id=$visible") - compositor.setSurfaceVisible(id, visible) - val composite = compositor.composite() - val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) - storeDesiredComposite(composite, packed, 0, frameId) - } + fun setSurfaceVisible(id: String, visible: Boolean) = core.setSurfaceVisible(id, visible) - /** - * Blank (screen off) or unblank the composited output, immediately - * submitting the resulting frame. Retained surface state is untouched, so - * unblanking restores the previous screen content without repaints. - */ - fun setScreenBlanked(blanked: Boolean) { - val frameId = FrameTimings.getInstance().startFrame( - "compositor:" + (if (blanked) "blank" else "unblank")) - compositor.setBlanked(blanked) - val composite = compositor.composite() - val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) - storeDesiredComposite(composite, packed, 0, frameId) - } + fun setScreenBlanked(blanked: Boolean) = core.setScreenBlanked(blanked) - /** - * Create or reconfigure a compositor surface. transparency is one of the - * SurfaceCompositor.TRANSPARENCY_* constants. Geometry changes take effect - * when the next frame is submitted. - */ - fun configureSurface(id: String?, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) { - compositor.configureSurface(id, x, y, width, height, zOrder, transparency) - } + fun configureSurface(id: String?, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) = + core.configureSurface(id, x, y, width, height, zOrder, transparency) - fun removeSurface(id: String) { - compositor.removeSurface(id) - } + fun removeSurface(id: String) = core.removeSurface(id) /** Stage an immutable shell snapshot alongside the retained app screen. */ - fun submitShellScene(bytes: java.nio.ByteBuffer, paintMs: Int, frameId: Int) { - compositor.setShellScene(AndroidByteReader(bytes)) - val composite = compositor.composite() - storeDesiredComposite(composite, BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height), paintMs, frameId) - } + fun submitShellScene(bytes: java.nio.ByteBuffer, paintMs: Int, frameId: Int) = + core.submitShellScene(AndroidByteReader(bytes), paintMs, frameId) /** Legacy compositor dimming for callers without a shell scene. */ - fun setUnderlayDim(belowZOrder: Int, factor256: Int) { - compositor.setUnderlayDim(belowZOrder, factor256) - } + fun setUnderlayDim(belowZOrder: Int, factor256: Int) = core.setUnderlayDim(belowZOrder, factor256) /** * Apply an update to one compositor surface and submit the recomposited - * screen as the desired frame. The update covers the rect (rectX, rectY, - * rectWidth, rectHeight) in surface-local coordinates; contentFingerprint - * identifies the surface's full content after the update. + * screen as the desired frame (see [GlassesSessionCore.submitSurfaceFrame]). * * pixels8bpp arrives as a ByteBuffer because NativeScript marshals a JS * ArrayBuffer to one without the per-element bridge copy that a byte[] @@ -1239,13 +328,7 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre contentFingerprint, paintMs, frameId, null) } - /** - * As above, with the frame's glyph draws (see SurfaceCompositor's glyph - * overload for the buffer format): the surface's full text content as - * structured draws, letting the resource-cache planner ship glyphs as - * on-glasses cached draws instead of pixels. Null when the submitter has - * no glyph metadata; the pixels alone remain fully correct. - */ + /** As above, with the frame's glyph draws (null when the submitter has no glyph metadata). */ fun submitSurfaceFrame( pixels8bpp: java.nio.ByteBuffer, surfaceId: String, @@ -1258,2759 +341,28 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre frameId: Int, glyphs: java.nio.ByteBuffer? ) { - Log.i(TAG, "Received an updated frame for surface $surfaceId") - FrameTimings.getInstance().log(frameId, "surface " + surfaceId + " updated rect=" - + rectWidth + "x" + rectHeight + "+" + rectX + "+" + rectY - + (if (glyphs == null) " (no glyph draws)" else "")) - FrameTimings.getInstance().spanStart(frameId, "composite") - val composite = compositor.applyAndComposite( - surfaceId, AndroidByteReader(pixels8bpp), rectX, rectY, rectWidth, rectHeight, contentFingerprint, - if (glyphs == null) null else AndroidByteReader(glyphs)) - FrameTimings.getInstance().spanEnd(frameId, "composite") - // Pack the composited 8bpp buffer down to the headerless 4bpp frame - // format the wire planners consume; BMP framing is added later only for - // the uncompressed fallback. - FrameTimings.getInstance().spanStart(frameId, "pack-4bpp") - val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) - FrameTimings.getInstance().spanEnd(frameId, "pack-4bpp") - storeDesiredComposite(composite, packed, paintMs, frameId) + core.submitSurfaceFrame(AndroidByteReader(pixels8bpp), surfaceId, rectX, rectY, rectWidth, rectHeight, + contentFingerprint, paintMs, frameId, if (glyphs == null) null else AndroidByteReader(glyphs)) } - /** Store a composite as the desired frame unless a newer one won the race. */ - private fun storeDesiredComposite(composite: SurfaceCompositor.Composite, packed: ByteArray, paintMs: Int, frameId: Int) { - var supersededFrameId = 0 - var stale = false - synchronized(desiredTilesLock) { - if (composite.seq <= lastStoredCompositeSeq) { - // A concurrent submission composited after us and stored first; - // its composite already includes this surface update. - stale = true - } else { - lastStoredCompositeSeq = composite.seq - supersededFrameId = desiredFrameId - desiredPacked = packed - desiredWidth = composite.width - desiredHeight = composite.height - desiredFingerprint = composite.fingerprint - desiredPaintMs = paintMs - desiredFrameId = frameId - desiredDraws = composite.draws - desiredShellScene = composite.shellScene - } - } - if (stale) { - finishFrame(frameId, "discarded: composite superseded before store") - return - } - if (supersededFrameId != 0 && supersededFrameId != frameId) { - finishFrame(supersededFrameId, "discarded: superseded by frame#$frameId before send") - } - FrameTimings.getInstance().log(frameId, "image submitted as desired frame") - interruptibleSleep.interrupt() - } - - /** - * Play a tone sequence via CFW load_image_z mode 5 kind 4. The payload is - * the complete wire buffer ([5][4][nSteps][freqLo,freqHi,duty,msLo,msHi]*n, - * up to 48 steps), built on the TS side; it rides the arbitrary-payload - * image path like the other mode-5 controls. - */ + /** Play a tone sequence via CFW load_image_z mode 5 kind 4 (payload built on the TS side). */ fun playBuzzerSequence(payload: java.nio.ByteBuffer?) { - synchronized(lock) { - if (!running || !sessionReady || !fixedLayoutCreated) { - logLine("skip buzzer sequence; session not ready") - return - } - val bytes = ByteArray(if (payload == null) 0 else payload.remaining()) - if (payload != null) { - payload.get(bytes) - } - if (bytes.size < 3) { - logLine("skip buzzer sequence; empty payload") - return - } - val message = messageBuilder.imagePayload( - DASHBOARD_TILE, - nextMapSessionId(), - bytes, - "buzzer sequence " + bytes.size + "B", - connectionOptions.sendImagesToLeft - ) - message.onTimeout = MessageCallback { - handleTransportFailure("buzzer sequence ack timeout") - } - pendingMessages.addLast(message) - logLine("queue " + message.label) + val bytes = ByteArray(if (payload == null) 0 else payload.remaining()) + if (payload != null) { + payload.get(bytes) } - interruptibleSleep.interrupt() + core.playBuzzerSequence(bytes) } - fun sendShutdown(exitMode: Int): Boolean { - return sendShutdownInternal(exitMode, true) - } - - /** - * Send CFW image-handler mode 11 after quiescing normal traffic. A successful - * return means the cleanup was ACKed and no later Faceclaw message should be - * emitted before closing BLE. Unsupported/older CFWs return false so callers - * can use the legacy shutdown-and-lease-release path. - */ - fun sendCfwCleanup(): Boolean { - val magic: Int - synchronized(lock) { - if (cfwCleanupDelivered) { - return true - } - if (!customFirmwareDetected || !running || !sessionReady - || shutdownRequested || !fixedLayoutCreated) { - logLine("skip CFW cleanup; mode 11 unavailable or image path not ready") - return false - } - - /* Stop auto-renewals, heartbeats, image generation, and control - * retries, then discard everything that has not reached BLE yet. */ - shutdownRequested = true - lastCfwCleanupAckMagic = 0 - clearPendingMessagesLocked("CFW cleanup requested") - logLine("quiescing transport for CFW cleanup") - } - interruptibleSleep.interrupt() - - /* WINDOW_SIZE can exceed one, so merely appending cleanup would allow it - * to overlap previously-written image fragments. Wait until all of those - * ACK or time out; shutdownRequested prevents the drive loop from adding - * any fresh automatic traffic meanwhile. */ - val drainDeadline = SystemClock.elapsedRealtime() + CFW_CLEANUP_WAIT_MS - synchronized(lock) { - while (running && sessionReady && !inFlightMessages.isEmpty()) { - val remaining = drainDeadline - SystemClock.elapsedRealtime() - if (remaining <= 0) break - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - break - } - } - if (!running || !sessionReady || !inFlightMessages.isEmpty()) { - shutdownRequested = false - logLine("CFW cleanup could not drain prior traffic") - return false - } - - /* External producers are expected to be stopped by the caller, but - * clear once more at the barrier so cleanup is definitely last. */ - clearPendingMessagesLocked("CFW cleanup barrier") - val message = messageBuilder.cfwCleanup( - DASHBOARD_TILE, - nextMapSessionId(), - connectionOptions.sendImagesToLeft - ) - magic = message.magic - message.onAck = MessageCallback { - lastCfwCleanupAckMagic = message.magic - cfwCleanupDelivered = true - compassMaybeOn = false - faceclawWakeLeaseEnabled = false - logLine("CFW cleanup completed") - } - message.onTimeout = MessageCallback { logLine("CFW cleanup ack timeout") } - pendingMessages.addLast(message) - logLine("queue CFW cleanup") - } - interruptibleSleep.interrupt() - - val deadline = SystemClock.elapsedRealtime() + CFW_CLEANUP_WAIT_MS - synchronized(lock) { - while (running - && sessionReady - && lastCfwCleanupAckMagic != magic - && hasPendingOrInflightMagicLocked(magic)) { - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) break - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - break - } - } - val acked = lastCfwCleanupAckMagic == magic - if (!acked) shutdownRequested = false - return acked - } - } - - /** - * End the EvenHub page while retaining both arm GATT connections and all - * notification subscriptions. A missed ACK is intentionally non-fatal: - * reconnecting Bluetooth here would defeat the power-saving mode. - */ - fun suspendEvenHubSession(): Boolean { - // Ending the plugin task releases the fb lease, which frees the - // on-glasses resource cache; forget it phone-side either way (a lost - // ack may still have taken effect). - synchronized(lock) { - resourceCache.reset() - } - if (sendShutdownInternal(0, false)) { - return true - } - synchronized(lock) { - // A shutdown ACK can be lost even though the command took effect. - // If the transport remains intentionally quiesced, callers still - // need to remember to run the resume path on the next wake. - return running && sessionReady && shutdownRequested - } - } - - /** - * Start a fresh EvenHub plugin task on the existing BLE transport, then let - * the session driver create the layout, warm up the image path, and send - * the desired frame. - */ - fun resumeEvenHubSession(): Boolean { - var claimGeneration = 0 - synchronized(lock) { - if (!running || !sessionReady || chargingMode) { - logLine("skip EvenHub resume; transport not ready") - return false - } - if (!shutdownRequested) { - return true - } - if (faceclawWakePendingNonce >= 0 - && hasPendingOrInflightKindLocked("wake-lease-control")) { - claimGeneration = faceclawWakeControlGeneration - } - logLine("replaying session prelude for EvenHub resume") - } - - // A custom double-tap wake has only a short unclaimed fail-open - // deadline. Let the worker put CLAIM on both arms before the direct - // prelude write begins. - if (claimGeneration != 0) { - waitForFaceclawWakeControlDelivery(claimGeneration, 500) - } - - try { - // Empty-name Cmd=9 tears down the whole plugin task, not just its - // image container. Re-run the launch prelude before Cmd=0 CREATE. - sendPrelude(true) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - handleTransportFailure("EvenHub resume prelude interrupted") - return false - } catch (t: Throwable) { - logLine("EvenHub resume prelude failed: " + safeMessage(t)) - handleTransportFailure("EvenHub resume prelude failed") - return false - } - - synchronized(lock) { - if (!running || !sessionReady || chargingMode) { - return false - } - shutdownRequested = false - fixedLayoutCreated = false - startupProbePending = false - audioCaptureActive = false - clearAllMessagesPreservingWakeLeaseLocked("EvenHub resume") - displayedFingerprint = "" - imageRetryAfterMs = 0 - lastHeartbeatSentAtMs = 0 - lastHeartbeatAckedAtMs = 0 - logLine("EvenHub session resume requested") - } - interruptibleSleep.interrupt() - return true - } - - private fun sendShutdownInternal(exitMode: Int, reconnectOnTimeout: Boolean): Boolean { - val magic: Int - val startedAtMs = SystemClock.elapsedRealtime() - synchronized(lock) { - if (!running || !sessionReady) { - logLine("skip shutdown; session not ready") - return false - } - if (shutdownRequested) { - return true - } - shutdownRequested = true - // Magic values wrap, so an ACK from a much older suspend must not - // satisfy this request after enough sleep/wake cycles. - lastShutdownAckMagic = 0 - clearPendingMessagesLocked("shutdown requested") - val message = messageBuilder.shutdown(exitMode) - magic = message.magic - message.onAck = MessageCallback { - lastShutdownAckMagic = message.magic - fixedLayoutCreated = false - displayedFingerprint = "" - } - message.onTimeout = MessageCallback { - if (reconnectOnTimeout) { - handleTransportFailure("shutdown ack timeout") - } else { - logLine("EvenHub shutdown ack timeout; keeping BLE connected") - } - } - pendingMessages.addFirst(message) - logLine("queue shutdown") - // The stock compass keeps the magnetometer sampling independently of - // the plugin task, so ending the page does not stop it. Force a - // disable ahead of the shutdown command whenever it may be running: - // this also covers a disable that was wiped by the queue flush above - // or whose ack was lost, and the charging-mode/exit paths where the - // Compass window never got a chance to release it. - if (compassMaybeOn && fixedLayoutCreated) { - enqueueCompassControlLocked(true, false) - } - } - interruptibleSleep.interrupt() + fun sendShutdown(exitMode: Int): Boolean = core.sendShutdown(exitMode) - val ackDeadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + 500 - synchronized(lock) { - while (running - && sessionReady - && lastShutdownAckMagic != magic - && lastShutdownExitAtMs < startedAtMs - && hasPendingOrInflightMagicLocked(magic)) { - val remaining = ackDeadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - break - } - } - val acked = lastShutdownAckMagic == magic - if (acked) { - val exitDeadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + 500 - while (running && sessionReady && lastShutdownExitAtMs < startedAtMs) { - val remaining = exitDeadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - break - } - } - } - return acked || lastShutdownExitAtMs >= startedAtMs - } - } - - private fun waitForAudioControlAck(magic: Int, operation: String): Boolean { - val deadline = SystemClock.elapsedRealtime() + ConnectionOptions.ACK_TIMEOUT_MS + ConnectionOptions.WRITE_TIMEOUT_MS + 500 - synchronized(lock) { - while (running && sessionReady && lastAudioControlAckMagic != magic && hasPendingOrInflightMagicLocked(magic)) { - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - break - } - } - val acked = lastAudioControlAckMagic == magic - if (!acked) { - if ("enable" == operation) { - audioPacketListener = null - audioCaptureActive = false - } - logLine("G2 mic $operation ack timeout") - } - return acked - } - } - - - override fun run() { - logLine(String.format(Locale.US, "communicator start R=%s L=%s ring=%s", rightAddress, leftAddress, ringAddress)) - while (true) { - try { - if (!running) { - Log.w(TAG, "Exiting event looop") - break - } - emitPhoneLockStateIfChanged(false) - if (!sessionReady) { - if (reconnectHalted) { - interruptibleSleep.sleep(ConnectionOptions.IDLE_SLEEP_MS.toLong()) - continue - } - val now = SystemClock.elapsedRealtime() - if (now < reconnectAfterMs) { - interruptibleSleep.sleep(Math.min(ConnectionOptions.IDLE_SLEEP_MS.toLong(), reconnectAfterMs - now)) - continue - } - Log.w(TAG, "Attempting to connect") - connectLoopOnce() - continue - } - - if (shouldAttemptRingConnect()) { - tryConnectRing("retry") - continue - } - - val sleepMs = driveSession() - if (sleepMs > 0) { - interruptibleSleep.sleep(sleepMs) - } - } catch (t: Throwable) { - logLine("communicator loop error: " + safeMessage(t)) - handleTransportFailure("loop error") - } - } - logLine("communicator stop") - } - - override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { - if (address == null || characteristicUuid == null || data == null) { - return - } - val uuid = characteristicUuid.lowercase(Locale.US) - if (isDirectRingNotification(address, uuid)) { - handleDirectRingNotification(uuid, data) - return - } - if (BleProtocol.RENDER_NOTIFY_UUID == uuid) { - handleRenderNotification(address, data) - return - } - if (BleProtocol.NOTIFY_CHAR_UUID != uuid) { - return - } - if (data.size >= 7 && (data[6].toInt() and 255) == CfwTransport.SID) { - val acks = CfwTransport.parseAcks(data) ?: return - synchronized(lock) { - lastIncomingAtMs = SystemClock.elapsedRealtime() - for (ack in acks) { - for (message in inFlightMessages) { - val ingress = if (message.isLeftArmMessage) leftAddress else rightAddress - if (message.sid == CfwTransport.SID && address.equals(ingress, ignoreCase = true) && message.magic == ack.streamId) { - message.acceptCfwAck(ack) - Log.i(TAG, "CFW " + (if (ack.nack) "NACK" else "ACK") + " id=" + ack.streamId - + " ordinal=" + ack.messageId + " lens=" + ack.lens + " txseq=" + (data[2].toInt() and 255) - + " redundant=" + (ack !== acks[0]) - + " size=" + ack.size + " crc=" + ack.checksum - + " expected=" + message.message.size + "/" + message.cfwChecksum - + " ackedLenses=" + message.cfwAckLenses - + " ageMs=" + (lastIncomingAtMs - message.sentAtMs)) - message.ackPayload = Arrays.copyOf(data, data.size) - break - } - } - } - drainCfwAcknowledgementsLocked() - } - interruptibleSleep.interrupt() - return - } - Log.d(TAG, "onNotification: address=" + address + " characteristicUuid=" + characteristicUuid + " data.length=" + data.size) - val frame = BleProtocol.parseFrame(data) - val decodedWearState = BleProtocol.parseWearState(frame) - val compassEvent = if (address.equals(rightAddress, ignoreCase = true)) - BleProtocol.parseCompassEvent(frame) - else - null - var emitWearState = false - var event: G2Event? = null - synchronized(lock) { - lastIncomingAtMs = SystemClock.elapsedRealtime() - if (decodedWearState >= 0 && decodedWearState != wearState) { - wearState = decodedWearState - emitWearState = true - } - var faceclawWakeNotification = false - if (shutdownRequested - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING - && address.equals(rightAddress, ignoreCase = true)) { - val wakeNonce = BleProtocol.parseFaceclawWakeEvent(frame.pb) - if (wakeNonce >= 0) { - faceclawWakePendingNonce = wakeNonce - enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_CLAIM, - wakeNonce, - true - ) - faceclawWakeNotification = true - lastConnectionOrInputAtMs = lastIncomingAtMs - // The event type says which gesture woke the glasses: TS - // gives a head-up the Glanceboard and a double tap the - // regular UI. The claim handshake is the same for both. - val headUp = BleProtocol.parseFaceclawWakeEventCode(frame.pb) == - BleProtocol.FACECLAW_WAKE_EVENT_HEAD_UP - event = G2Event( - "display-wake", - "", - if (headUp) BleProtocol.EVENT_HEAD_UP else BleProtocol.EVENT_DOUBLE_CLICK, - 0, - 0 - ) - logLine("claimed deferred dashboard wake nonce=" + wakeNonce - + (if (headUp) " (head-up)" else "")) - } - } - if (!faceclawWakeNotification - && shutdownRequested - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING - && address.equals(rightAddress, ignoreCase = true)) { - // CFW idle-gesture forwarding (firmware revision 2+): with no - // EvenHub page the stock display thread drops taps, long - // presses and releases; the CFW reports them on the settings - // sid while our wake lease is held. Deliver them as the - // sys-events a live page would have produced, so TS treats a - // sleep-time tap or hold exactly like one during soft sleep - // (the Glanceboard). - val gesture = BleProtocol.parseFaceclawGestureEvent(frame.pb) - if (gesture != null) { - lastConnectionOrInputAtMs = lastIncomingAtMs - event = G2Event("sys-event", "", gesture.eventType, gesture.eventSource, 0) - logLine("idle gesture forwarded by CFW: type=" + gesture.eventType - + " source=" + gesture.eventSource) - } - } - if (!faceclawWakeNotification - && event == null - && shutdownRequested - && address.equals(rightAddress, ignoreCase = true) - && BleProtocol.isDisplayWakeStateChange(frame)) { - // With no EvenHub page, ring/arm double-taps are handled by the - // stock display lifecycle and surface only as this state ping. - // Translate it back into an input event so TS can wake the shell - // and recreate the page. - event = G2Event( - "display-wake", - "", - BleProtocol.EVENT_DOUBLE_CLICK, - 0, - 0 - ) - } - if (!faceclawWakeNotification - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING) { - // Mode-17 query notifications; settings READs are handled by - // createBatteryQueryMessageLocked so headset/ring update together. - if (address.equals(rightAddress, ignoreCase = true) - && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { - val ring = BleProtocol.parseRingBattery(frame.pb) - if (ring != null) { - ringBattery = ring.battery - ringCharging = ring.charging - emitBatteryState(headsetBattery, headsetCharging) - } - } - // CFW mic status (field 104) rides both standalone pushes and - // settings read acks, from each temple on its own link. - val micStatus = BleProtocol.parseFaceclawMicStatus(frame.pb) - if (micStatus != null) { - emitMicStatus(micStatus, address) - } - } - if (!faceclawWakeNotification - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING) { - // CFW ambient-light report (field 105) from the master temple. - val alsReport = BleProtocol.parseFaceclawAlsReport(frame.pb) - if (alsReport != null) { - emitAmbientLight(alsReport) - } - } - if (!faceclawWakeNotification - && decodedWearState < 0 - && frame.ok - && frame.sid == BleProtocol.SID_UI_SETTING) { - // Device-initiated settings push. It carries a magic the glasses - // chose, so it would otherwise fall through to resolveAckLocked, - // match nothing, and be logged as an unexpected ack. - val pushedSilentMode = BleProtocol.parseSilentModePush(frame.pb) - if (pushedSilentMode >= 0) { - updateSilentModeLocked(pushedSilentMode > 0) - return - } - } - if (!faceclawWakeNotification - && decodedWearState < 0 - && frame.ok - && frame.msgSeq >= 0 - && frame.flag != BleProtocol.FLAG_NOTIFY - && frame.flag != BleProtocol.FLAG_NOTIFY_ALT) { - lastAckAtMs = lastIncomingAtMs - resolveAckLocked(frame.sid, frame.msgSeq, frame.pb) - } - if (!faceclawWakeNotification - && event == null - && frame.ok - && address.equals(rightAddress, ignoreCase = true) - && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { - var decoded = G2Event.decode(frame) - if (decoded != null - && "sys-event" == decoded.kind - && decoded.eventType == BleProtocol.EVENT_HEAD_UP) { - // CFW forwards the IMU head-up while our page is on screen - // (soft sleep). Surface it as the same wake-only input the - // deferred head-up wake produces from a dark display. - decoded = G2Event("display-wake", "", BleProtocol.EVENT_HEAD_UP, decoded.eventSource, 0) - logLine("head-up forwarded by CFW while page on screen") - } - event = decoded - if (decoded != null) { - // Pure IMU samples arrive continuously; don't let them count - // as user input (which would starve battery polling). - val pureImuSample = "sys-event" == decoded.kind - && decoded.eventType == BleProtocol.EVENT_IMU_DATA_REPORT - if (!pureImuSample) { - lastConnectionOrInputAtMs = lastIncomingAtMs - } - if ("list-click" == decoded.kind || "text-click" == decoded.kind) { - // Container-routed touchpad input reached us, so the - // firmware is dispatching input: silent mode is off, - // whether or not its end-of-silent push arrived. - updateSilentModeLocked(false) - } - if ("sys-event" == decoded.kind) { - if (decoded.eventType == BleProtocol.EVENT_FOREGROUND_EXIT || decoded.eventType == BleProtocol.EVENT_ABNORMAL_EXIT || decoded.eventType == BleProtocol.EVENT_SYSTEM_EXIT) { - if (shutdownRequested) { - lastShutdownExitAtMs = SystemClock.elapsedRealtime() - } - fixedLayoutCreated = false - displayedFingerprint = "" - clearAllMessagesLocked("firmware exit event") - } - } - } - } - } - interruptibleSleep.interrupt() - if (emitWearState) { - logLine(if (decodedWearState > 0) "wear state ON_HEAD" else "wear state OFF_HEAD") - emitWearState(decodedWearState > 0) - } - if (compassEvent != null) { - emitCompassEvent(compassEvent) - } - val finalEvent = event - if (finalEvent != null) { - if (finalEvent.hasImu) { - emitImuData(finalEvent.imuX, finalEvent.imuY, finalEvent.imuZ, finalEvent.eventSource) - } - // A standalone IMU_DATA_REPORT is a sensor sample, not a gesture: - // deliver it only to IMU listeners, skipping the input pipeline (and - // its per-frame latency bookkeeping) to avoid flooding it. - val pureImuSample = "sys-event" == finalEvent.kind - && finalEvent.eventType == BleProtocol.EVENT_IMU_DATA_REPORT - if (!pureImuSample) { - val frameId = FrameTimings.getInstance().startFrame( - "input:" + finalEvent.kind + " type=" + finalEvent.eventType + " src=" + finalEvent.eventSource) - FrameTimings.getInstance().log(frameId, "input event decoded from BLE notification") - emitRingEvent(finalEvent, frameId) - } - } - } - - private fun handleDirectRingNotification(characteristicUuid: String, data: ByteArray) { - val decoded = FaceclawRingEventDecoder.decode(data) - if (decoded == null) { - Log.d(TAG, "direct ring notify ignored: characteristicUuid=" + characteristicUuid + " raw=" + hex(data)) - return - } + fun sendCfwCleanup(): Boolean = core.sendCfwCleanup() - val event = decoded.event - val arrivalMs = SystemClock.elapsedRealtime() - synchronized(lock) { - lastIncomingAtMs = arrivalMs - lastConnectionOrInputAtMs = arrivalMs - } - logLine("direct ring " + decoded.label + " " + decoded.detail + " raw=" + hex(data)) - val frameId = FrameTimings.getInstance().startFrame("input:ring:" + decoded.label) - FrameTimings.getInstance().log(frameId, "input event decoded from direct ring notification") - emitRingEvent(event, frameId) - interruptibleSleep.interrupt() - } - - private fun handleRenderNotification(address: String, data: ByteArray) { - val listenerToCall: FaceclawAudioPacketListener? - val arrivalMs = SystemClock.elapsedRealtime() - synchronized(lock) { - lastIncomingAtMs = arrivalMs - listenerToCall = if (audioCaptureActive) audioPacketListener else null - } - if (listenerToCall == null) { - return - } - val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?" - try { - listenerToCall.onAudioPacket(Arrays.copyOf(data, data.size), arm, arrivalMs) - } catch (t: Throwable) { - logLine("G2 mic packet listener failed: " + safeMessage(t)) - } - } - - override fun onConnectionStateChange(address: String?, connected: Boolean) { - synchronized(lock) { - if (address == null) { - return - } - if (isConfiguredRingAddress(address)) { - ringConnected = connected - ringNotificationsReady = false - if (!connected) { - ringReconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RING_RECONNECT_DELAY_MS - } - logLine(if (connected) "direct ring BLE connected" else "direct ring BLE disconnected") - return - } - if (address.equals(rightAddress, ignoreCase = true)) { - rightConnected = connected - } else if (address.equals(leftAddress, ignoreCase = true)) { - leftConnected = connected - } else { - return - } - if (!connected) { - sessionReady = false - fixedLayoutCreated = false - startupProbePending = false - chargingMode = false - audioCaptureActive = false - audioPacketListener = null - clearAllMessagesLocked("connection lost") - displayedFingerprint = "" - if (!reconnectHalted) { - reconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RECONNECT_DELAY_MS - } - } - } - interruptibleSleep.interrupt() - if (connected) { - setStateDisplay("connected", "Connected.") - } else if (!reconnectHalted) { - // While parked on a missing bond, keep the "unpaired" display: this - // callback is just the teardown of the arm that did connect. - setStateDisplay("connecting", "Connecting to the glasses...") - } - } - - @Throws(InterruptedException::class) - private fun connectLoopOnce() { - setStateDisplay("connecting", "Connecting to the glasses...") - try { - connectArm(rightAddress, true) - connectArm(leftAddress, true) - if (!sleepDuringConnectSettling(800)) { - return - } - authenticateArms() - sendPrelude() - - synchronized(lock) { - sessionReady = true - // A fresh transport prelude always starts an active EvenHub - // lifecycle, even if the previous connection dropped while - // its page was intentionally suspended. - shutdownRequested = false - fixedLayoutCreated = false - clearAllMessagesLocked("session ready") - displayedFingerprint = "" - lastAckAtMs = SystemClock.elapsedRealtime() - lastIncomingAtMs = lastAckAtMs - lastConnectionOrInputAtMs = lastAckAtMs - lastSessionReadyAtMs = lastAckAtMs - lastBatteryRefreshAtMs = 0 - imageRetryAfterMs = 0 - lastHeartbeatSentAtMs = 0 - lastHeartbeatAckedAtMs = 0 - consecutiveAckTimeouts = 0 - lastAudioControlAckMagic = 0 - audioCaptureActive = false - faceclawWakePendingNonce = -1 - cfwCleanupDelivered = false - for (transport in cfwTransports) transport.reset() - lastCfwCleanupAckMagic = 0 - lastFaceclawWakeLeaseQueuedAtMs = 0 - lastFaceclawFramebufferLeaseQueuedAtMs = 0 - enqueueFaceclawFramebufferControlLocked( - BleProtocol.FACECLAW_FB_OP_ACQUIRE, - true - ) - if (faceclawWakeLeaseEnabled) { - enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, - 0, - true - ) - } - } - setStateDisplay("connected", "Connected.") - logLine("session ready") - synchronized(lock) { - // Query settings promptly on the first session so firmware - // version/extension (and battery) arrive without waiting for - // the input-quiet battery poll. The settings response doubles as - // the firmware-compatibility check surfaced during onboarding. - if (!firmwareInfoQueried) { - firmwareInfoQueried = true - lastBatteryRefreshAtMs = SystemClock.elapsedRealtime() - pendingMessages.addLast(createBatteryQueryMessageLocked()) - logLine("queue settings query for firmware info") - } - } - tryConnectRing("initial") - } catch (t: Throwable) { - logLine("connect failed: " + safeMessage(t)) - val unpairedArm = firstUnpairedArm() - if (unpairedArm != null) { - handleUnpairedFailure(unpairedArm) - } else { - handleTransportFailure("connect failed") - } - } - } - - @Throws(InterruptedException::class) - private fun sleepDuringConnectSettling(delayMs: Long): Boolean { - val deadline = SystemClock.elapsedRealtime() + delayMs - synchronized(lock) { - while (running && !userDisconnectRequested) { - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - return true - } - lock.wait(Math.min(remaining, 100L)) - } - return false - } - } - - private fun connectArm(address: String, enableRenderNotify: Boolean) { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw IllegalStateException("connect failed: $address") - } - // requestConnectionPriority has no callback in this Android compile target, so there is - // no reliable completion point to keep it in the global GATT operation pipeline. But it's - // important enough for performance that we call it anyways. - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) - - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) - - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw IllegalStateException("discoverServices failed: $address") - } - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - throw IllegalStateException("enableNotifications failed: " + address + " " + BleProtocol.NOTIFY_CHAR_UUID) - } - if (enableRenderNotify) { - bleManager.enableNotifications(address, BleProtocol.RENDER_NOTIFY_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS) - } - synchronized(lock) { - if (address.equals(rightAddress, ignoreCase = true)) { - rightConnected = true - } else if (address.equals(leftAddress, ignoreCase = true)) { - leftConnected = true - } - } - } - - private fun shouldAttemptRingConnect(): Boolean { - if (!hasRingAddress()) { - return false - } - val now = SystemClock.elapsedRealtime() - synchronized(lock) { - return running - && sessionReady - && !ringNotificationsReady - && now >= ringReconnectAfterMs - && pendingMessages.isEmpty() - && inFlightMessages.isEmpty() - } - } - - private fun tryConnectRing(reason: String) { - if (!hasRingAddress()) { - return - } - try { - connectRing() - } catch (t: Throwable) { - synchronized(lock) { - ringConnected = false - ringNotificationsReady = false - ringReconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RING_RECONNECT_DELAY_MS - } - logLine("direct ring connect failed (" + reason + "): " + safeMessage(t)) - } - } - - private fun connectRing() { - logLine("connecting direct ring $ringAddress") - if (!bleManager.connect(ringAddress, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw IllegalStateException("connect failed: $ringAddress") - } - - bleManager.requestConnectionPriority(ringAddress, BluetoothGatt.CONNECTION_PRIORITY_HIGH) - bleManager.requestMtu(ringAddress, ConnectionOptions.RING_DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) - - if (!bleManager.discoverServices(ringAddress, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw IllegalStateException("discoverServices failed: $ringAddress") - } - - val phoneNotify = enableRingNotification(BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID) - val dataNotify = enableRingNotification(BleProtocol.R1_NOTIFY_CHAR_UUID) - if (!phoneNotify && !dataNotify) { - throw IllegalStateException("no R1 notify characteristic subscribed") - } - - synchronized(lock) { - ringConnected = true - ringNotificationsReady = true - ringReconnectAfterMs = 0 - } - logLine("direct ring ready phoneNotify=$phoneNotify dataNotify=$dataNotify") - } - - private fun enableRingNotification(characteristicUuid: String): Boolean { - try { - return bleManager.enableNotifications( - ringAddress, - characteristicUuid, - true, - ConnectionOptions.DESCRIPTOR_TIMEOUT_MS - ) - } catch (t: Throwable) { - Log.d(TAG, "direct ring notify subscribe skipped: " + characteristicUuid + " " + safeMessage(t)) - return false - } - } - - /** - * Complete the sid-0x80 security-auth exchange on both freshly opened arm - * connections. Firmware 2.2.9 answers no queries until it completes over an - * encrypted link and closes unauthenticated links after ~30 s (see - * ../notes/ble-connections-2.2.9.md); on an unbonded phone the exchange is - * also what triggers SMP pairing. Deliberately soft: on timeout we log and - * continue rather than fail the connect — the custom firmware's response - * behavior is not yet hardware-verified, and on stock firmware an - * unanswered auth just means the prelude fails exactly as it did before. - * A pairing prompt accepted after our window still bonds at the OS level, - * so the next reconnect attempt authenticates promptly. - */ - @Throws(InterruptedException::class) - private fun authenticateArms() { - val right = messageBuilder.securityAuth(false) - val left = messageBuilder.securityAuth(true) - val now = SystemClock.elapsedRealtime() - for (message in arrayOf(right, left)) { - message.onAck = MessageCallback { - } - message.onTimeout = MessageCallback { - } - message.sentAtMs = now - writeMessage(message) - } - val deadline = SystemClock.elapsedRealtime() + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS - while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { - synchronized(lock) { - if (!running || userDisconnectRequested || inFlightMessages.isEmpty()) { - break - } - } - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - interruptibleSleep.sleep(Math.min(remaining, 100L)) - } - synchronized(lock) { - if (!inFlightMessages.isEmpty()) { - clearInFlightMessagesLocked("security auth timeout") - logLine("security auth not acknowledged; continuing (2.2.9 stock requires it; older/custom firmware may not answer)") - return - } - } - val rightOk = BleProtocol.isAuthenticationSuccess(right.ackPayload, right.magic) - val leftOk = BleProtocol.isAuthenticationSuccess(left.ackPayload, left.magic) - logLine("security auth R=" + (if (rightOk) "ok" else "unconfirmed") + " L=" + (if (leftOk) "ok" else "unconfirmed")) - } - - @Throws(InterruptedException::class) - private fun sendPrelude() { - sendPrelude(false) - } - - @Throws(InterruptedException::class) - private fun sendPrelude(preserveWakeLeaseControls: Boolean) { - synchronized(lock) { - if (preserveWakeLeaseControls) { - clearAllMessagesPreservingWakeLeaseLocked("prelude") - } else { - clearAllMessagesLocked("prelude") - } - } - val now = SystemClock.elapsedRealtime() - val prelude = messageBuilder.prelude() - prelude.onAck = MessageCallback { - } - prelude.onTimeout = MessageCallback { - handleTransportFailure("ack timeout") - } - prelude.sentAtMs = now - writeMessage(prelude) - - val deadline = SystemClock.elapsedRealtime() + ConnectionOptions.PRELUDE_TIMEOUT_MS - while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { - synchronized(lock) { - if (!running || userDisconnectRequested || inFlightMessages.isEmpty()) { - break - } - } - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - interruptibleSleep.sleep(Math.min(remaining, 100L)) - } - synchronized(lock) { - if (!inFlightMessages.isEmpty()) { - clearInFlightMessagesLocked("prelude timeout") - throw IllegalStateException("prelude ack timeout") - } - } - } - - private fun driveSession(): Long { - //Log.d(TAG, "driveSession called (pendingMessages.size=" + pendingMessages.size() + " inFlightMessages.size=" + inFlightMessages.size() + ")"); - while (true) { - // Run on the sender thread, outside `lock`: Bluetooth API calls can - // wait on the global GATT lock, and callbacks need the session lock. - // Keep negotiation outside the timed stream. A fixed settling period - // is only an experiment boundary; HCI must confirm actual parameters. - var linkMode = -1 - var benchmarkAddresses: Array? = null - synchronized(lock) { - if (benchmarkActive && benchmarkLinkPending) { - benchmarkLinkPending = false - linkMode = benchmarkLinkMode - benchmarkAddresses = arrayOf(leftAddress, rightAddress) - } - } - val addressesToPrepare = benchmarkAddresses - if (addressesToPrepare != null) { - for (address in addressesToPrepare) { - try { - bleManager.prepareBenchmarkLink(address, linkMode) - } catch (error: RuntimeException) { - logLine("benchmark link request failed: " + safeMessage(error)) - } - } - synchronized(lock) { - // Cancellation/new-run races leave the new run pending; its - // own preparation will replace this deadline before sending. - benchmarkReadyAtMs = SystemClock.elapsedRealtime() + 1_000 - } - } - var messageToWrite: OutboundMessage? = null - var messageToPrewrite: OutboundMessage? = null - val now = SystemClock.elapsedRealtime() - - maybeFinishNoChangeDesiredFrame() - - synchronized(lock) { - drainCfwAcknowledgementsLocked() - if (cfwCleanupDelivered) { - /* Successful mode 11 must be the last Faceclaw write. Drop - * anything a late external producer attempted to enqueue - * while DashboardController was closing the transport. */ - clearPendingMessagesLocked("after CFW cleanup") - return 250 - } - if (sessionReady - && now - lastFaceclawFramebufferLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS - && !hasPendingOrInflightKindLocked("framebuffer-lease-control")) { - enqueueFaceclawFramebufferControlLocked( - BleProtocol.FACECLAW_FB_OP_ACQUIRE, - false - ) - } - if (faceclawWakeLeaseEnabled - && sessionReady - && now - lastFaceclawWakeLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS - && !hasPendingOrInflightKindLocked("wake-lease-control")) { - enqueueFaceclawWakeControlLocked( - BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, - 0, - false - ) - } - if (!inFlightMessages.isEmpty()) { - val oldest = inFlightMessages.peekFirst() - val replay = CfwMessageWindow.replayWindow(inFlightMessages, now) - if (!replay.isEmpty()) { - logLine("CFW recovery: replay " + replay.size - + " unresolved message(s) from id=" + replay[0].magic) - for (candidate in replay) { - if (candidate.cfwRetries >= CfwMessageWindow.MAX_RETRIES) { - handleTransportFailure("CFW recovery retry limit") - return 0 - } - logLine("CFW replay id=" + candidate.magic + " label=" + candidate.label - + " cause=" + (if (candidate.cfwRetryPending) "NACK" - else if (candidate.cfwAckLenses == CfwTransport.BOTH) "ordered tail" else "missing ACK") - + " ackedLenses=" + candidate.cfwAckLenses - + " ageMs=" + (now - candidate.sentAtMs)) - inFlightMessages.remove(candidate) - magicPool.release(candidate.sid, candidate.magic, candidate.label, "CFW replay") - candidate.prepareCfwReplay(magicPool.allocate()) - } - for (i in replay.indices.reversed()) pendingMessages.addFirst(replay[i]) - return 0 - } - if (oldest != null && oldest.ackDeadlineAtMs <= now) { - Log.i(TAG, "message timed out: " + oldest.label) - inFlightMessages.removeFirst() - logLine("message timed out: " + oldest.label + " sid=" + oldest.sid - + " id=" + oldest.magic + " ackedLenses=" + oldest.cfwAckLenses - + " ageMs=" + (now - oldest.sentAtMs)) - magicPool.release(oldest.sid, oldest.magic, oldest.label, "timeout") - if (oldest.sid == CfwTransport.SID) - cfwTransports[if (oldest.isLeftArmMessage) 0 else 1].reset() - handleAckTimeoutLocked(oldest) - return 0 - } - if (connectionOptions.WINDOW_SIZE <= 1 - && sessionReady - && prewrittenMessage == null - && !pendingMessages.isEmpty() - && canPrewriteCandidate(pendingMessages.peekFirst()) - && !shouldBlockPrewriteForHeartbeatLocked(now)) { - // Only the serial (window==1) path pre-sends the all-but-last - // packet; with a real window we just send the next message fully. - messageToPrewrite = pendingMessages.peekFirst() - } - } - - if (chargingMode) { - // Glasses are in the case: no display traffic, only battery - // polls (which also detect the end of charging). - finishDesiredFrameLocked("discarded: glasses charging") - if (sessionReady && inFlightMessages.isEmpty() && !pendingMessages.isEmpty()) { - messageToWrite = pendingMessages.removeFirst() - Log.i(TAG, "sending pending message (charging): " + messageToWrite!!.label) - } else if (sessionReady && pendingMessages.isEmpty() && inFlightMessages.isEmpty() - && now - lastBatteryRefreshAtMs >= ConnectionOptions.CHARGING_BATTERY_POLL_MS) { - Log.i(TAG, "Writing charging-mode battery poll") - messageToWrite = createBatteryQueryMessageLocked() - lastBatteryRefreshAtMs = now - } else { - return 1_000 - } - } else { - if (messageToPrewrite == null - && !shutdownRequested - && !fixedLayoutCreated - && pendingMessages.isEmpty() - && inFlightMessages.isEmpty()) { - Log.i(TAG, "enqueueing create layout") - enqueueCreateLayoutLocked() - } else if (messageToPrewrite != null) { - // Prewrite outside the lock; the logical message remains pending until - // its final BLE frame is sent after the current protocol ACK. - } - if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated - && (if (firmwareDebugFlagsEnabled) 2 else 1) != firmwareDebugFlagsLastSent - && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { - Log.i(TAG, "enqueueing firmware debug flags " + (if (firmwareDebugFlagsEnabled) "show" else "hide")) - enqueueFirmwareDebugFlagsLocked() - } - - if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated - && (if (compassOwners.isEmpty()) 0 else 1) != compassControlLastSent - && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { - val wanted = compassOwners.isNotEmpty() - Log.i(TAG, "enqueueing compass " + (if (wanted) "enable" else "disable")) - enqueueCompassControlLocked(false, wanted) - } - - if (benchmarkActive) { - maintainBenchmarkLocked(now) - } - - // Up to WINDOW_SIZE messages may be in flight at once (full - // pipelining); a slot frees when an ack arrives. An active - // bandwidth benchmark measures its own selected window instead. - val windowHasRoom = inFlightMessages.size < - Math.max(1, if (benchmarkActive) benchmarkWindowSize else connectionOptions.WINDOW_SIZE) - // A frame ready to send right now: don't inject a fresh - // heartbeat in front of it (the image's own ack resets the - // firmware heartbeat timer, so the heartbeat is redundant). - // "Ready" covers both a fresh composite still to be planned - // and a planned image already queued but not yet written -- - // enqueueing sets lastEnqueuedFingerprint, so testing only - // the desired fingerprint left the queued-but-unwritten - // window unprotected and a heartbeat that came due there - // cost the frame a full ack round trip (measured 124ms on - // frame#232 of the 2026-08-20 02:27 capture). - // A benchmark run counts as image traffic here for the same - // reason: its acks reset the firmware heartbeat timer, so a - // fresh heartbeat in front of it is redundant. - val imageWaiting = !shutdownRequested && fixedLayoutCreated - && !hasPendingOrInflightKindLocked("heartbeat") - && (benchmarkActive - || (now >= imageRetryAfterMs - && (hasPendingImageLocked() - || getDesiredFingerprint() != lastEnqueuedFingerprint))) - noteImageStallLocked(now, windowHasRoom) - if (messageToPrewrite == null && handleHeartbeat(imageWaiting)) { - return ConnectionOptions.IDLE_SLEEP_MS.toLong() - } - - if (messageToPrewrite == null && sessionReady && windowHasRoom && !pendingMessages.isEmpty() - && CfwMessageWindow.canSend(inFlightMessages, pendingMessages.peekFirst()!!)) { - messageToWrite = pendingMessages.removeFirst() - Log.i(TAG, "sending pending message: " + messageToWrite!!.label) - } else if (messageToPrewrite == null && !shutdownRequested && !benchmarkActive - && fixedLayoutCreated - && windowHasRoom && !hasPendingImageLocked() - && now >= imageRetryAfterMs - && getDesiredFingerprint() != lastEnqueuedFingerprint) { - // Enqueue the next frame's delta against lastEnqueuedPacked - // (what the shadow will be), so it can pipeline behind an - // image still awaiting its ack. - Log.i(TAG, "Enqueued image update") - enqueueDesiredImageLocked() - return 0 - } else if (messageToPrewrite == null && shouldPollBatteryLocked(now)) { - Log.i(TAG, "Writing battery query") - messageToWrite = createBatteryQueryMessageLocked() - lastBatteryRefreshAtMs = now - } else if (messageToPrewrite == null && (!pendingMessages.isEmpty() || !inFlightMessages.isEmpty())) { - return ConnectionOptions.IDLE_SLEEP_MS.toLong() - } else if (messageToPrewrite == null) { - return 250 - } - } - } - - val prewrite = messageToPrewrite - if (prewrite != null) { - if (prewriteMessage(prewrite)) { - return 0 - } - return ConnectionOptions.IDLE_SLEEP_MS.toLong() - } - - val write = messageToWrite!! - if (!writeMessage(write)) { - synchronized(lock) { - if (removePreparedMessageLocked(write) || write.magic == 0) { - handleTransportFailure("write failed") - } - } - return 0 - } - } - } - - /** - * If the desired image already matches what the glasses display, nothing will - * ever be enqueued for it, so finish its frame now (otherwise the TS side - * would block on it until its backpressure timeout). - */ - private fun maybeFinishNoChangeDesiredFrame() { - var frameIdToFinish = 0 - synchronized(lock) { - synchronized(desiredTilesLock) { - if (desiredFrameId != 0 && lastEnqueuedFingerprint.isNotEmpty() && desiredFingerprint == lastEnqueuedFingerprint) { - frameIdToFinish = desiredFrameId - desiredFrameId = 0 - } - } - } - if (frameIdToFinish != 0) { - finishFrame(frameIdToFinish, "discarded: no change from displayed image") - } - } - - private fun shouldBlockPrewriteForHeartbeatLocked(now: Long): Boolean { - if (shutdownRequested || !fixedLayoutCreated) { - return false - } - return hasPendingOrInflightKindLocked("heartbeat") - || now - lastHeartbeatAckedAtMs >= ConnectionOptions.HEARTBEAT_READY_MS - } - - private fun canPrewriteCandidate(message: OutboundMessage?): Boolean { - if (message == null || message.sid == CfwTransport.SID || !message.isLeftArmMessage) { - return false - } - if ("image" != message.kind) { - return false - } - return message.message.size + 2 > 232 - } - - private fun handleHeartbeat(imageWaiting: Boolean): Boolean { - val now = SystemClock.elapsedRealtime() - val heartbeatEligible = !shutdownRequested && fixedLayoutCreated - val heartbeatPending = heartbeatEligible && hasPendingOrInflightKindLocked("heartbeat") - val heartbeatElapsedMs = now - lastHeartbeatAckedAtMs - val heartbeatReady = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS - val heartbeatUrgent = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_URGENT_MS - val heartbeatBlocksLeftWrites = heartbeatReady || heartbeatPending - - if (heartbeatReady && !heartbeatPending && inFlightMessages.isEmpty()) { - if (imageWaiting && !heartbeatUrgent) { - // Defer to the waiting frame: sending it now satisfies the - // firmware heartbeat deadline (its ack resets the timer), and - // the heartbeat still fires once we reach the URGENT threshold - // if rendering goes quiet again. Preserves the pending-heartbeat - // inter-lens-sync invariant below (that path is untouched). - return false - } - Log.i(TAG, "Writing heartbeat") - val heartbeatMessage = createHeartbeatMessage() - lastHeartbeatSentAtMs = now - writeMessage(heartbeatMessage) - return true - } else if (heartbeatUrgent) { - return true - } else if (heartbeatPending) { - // Don't send other message types while a heartbeat is pending because that - // can lead to inter-lens sync issues - return true - } - - return false - } - - private fun createHeartbeatMessage(): OutboundMessage { - val message = messageBuilder.heartbeat() - message.onAck = MessageCallback { - synchronized(lock) { - lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime() - } - } - message.onTimeout = MessageCallback { - // If a heartbeat fails to ack and we're over the heartbeat deadline, assume the connection is failed and reconnect. - // Otherwise ignore it, which will cause a retransmission attempt. - val isPastDeadline: Boolean - synchronized(lock) { - isPastDeadline = SystemClock.elapsedRealtime() - lastHeartbeatSentAtMs >= ConnectionOptions.HEARTBEAT_FAILURE_DEADLINE_MS - } - if (isPastDeadline) { - handleTransportFailure("heartbeat ack timeout") - } - } - return message - } - - - private fun writeMessage(message: OutboundMessage): Boolean { - val now = SystemClock.elapsedRealtime() - message.writeStartedAtMs = now - message.sentAtMs = now - message.ackDeadlineAtMs = now + message.ackTimeoutMs + ConnectionOptions.WRITE_TIMEOUT_MS - if (message.magic != 0) { - synchronized(lock) { - inFlightMessages.addLast(message) - } - } - if (message.imageUpdateId > 0 && message.imageMessageNumber == 1) { - synchronized(lock) { - val stats = imageUpdateStats[message.imageUpdateId] - if (stats != null && stats.firstWriteStartedAtMs <= 0) { - stats.firstWriteStartedAtMs = now - } - } - } - - val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress - val frames: List - if (prewrittenMessage != null && prewrittenMessage !== message) { - if (!spoilPrewrittenMessage("before " + message.label)) { - return false - } - } - if (prewrittenMessage === message) { - frames = Collections.singletonList(prewrittenFrames[prewrittenFrames.size - 1]) - prewrittenMessage = null - prewrittenFrames = Collections.emptyList() - } else if (message.sid == CfwTransport.SID) { - if (message.cfwRetries > 0) cfwTransports[if (message.isLeftArmMessage) 0 else 1].reset() - frames = cfwTransports[if (message.isLeftArmMessage) 0 else 1].encode( - message.message, message.magic, CfwTransport.BOTH, - bleManager.getNegotiatedMtu(writeAddress)) - } else { - frames = BleProtocol.framePb( - message.message, - message.sid, - message.flag, - nextTransportSeq++ - ) - } - val result = bleManager.writeFrames( - writeAddress, - BleProtocol.WRITE_CHAR_UUID, - frames, - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS - ) - - synchronized(lock) { - val sentAtMs = SystemClock.elapsedRealtime() - message.sentAtMs = sentAtMs - message.ackDeadlineAtMs = sentAtMs + message.ackTimeoutMs - logImageUpdateSendLandmarkLocked(message) - val onSent = message.onSent - if (result && onSent != null) { - onSent.run() - lock.notifyAll() - } - } - - if (!result && message.sid == CfwTransport.SID) - cfwTransports[if (message.isLeftArmMessage) 0 else 1].reset() - return result - } - - private fun prewriteMessage(message: OutboundMessage): Boolean { - if (prewrittenMessage === message) { - return true - } - if (prewrittenMessage != null && !spoilPrewrittenMessage("before prewrite " + message.label)) { - return false - } - if (!canPrewriteCandidate(message)) { - return false - } - - val frames: List = BleProtocol.framePb( - message.message, - message.sid, - message.flag, - nextTransportSeq++ - ) - if (frames.size <= 1) { - return false - } - - val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress - val prefixFrames = frames.subList(0, frames.size - 1) - val result = bleManager.writeFrames( - writeAddress, - BleProtocol.WRITE_CHAR_UUID, - prefixFrames, - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS - ) - if (!result) { - return false - } - - prewrittenMessage = message - prewrittenFrames = ArrayList(frames) - logLine("prewrote " + message.label + " frames=" + prefixFrames.size + "/" + frames.size) - return true - } - - private fun spoilPrewrittenMessage(reason: String): Boolean { - val message = prewrittenMessage - if (message == null || prewrittenFrames.isEmpty()) { - prewrittenMessage = null - prewrittenFrames = Collections.emptyList() - return true - } - val finalFrame = Arrays.copyOf( - prewrittenFrames[prewrittenFrames.size - 1], - prewrittenFrames[prewrittenFrames.size - 1].size - ) - if (finalFrame.size > 8) { - finalFrame[finalFrame.size - 1] = (finalFrame[finalFrame.size - 1].toInt() xor 0xff).toByte() - } - prewrittenMessage = null - prewrittenFrames = Collections.emptyList() - - val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress - logLine("spoiling prewritten " + message.label + ": " + reason) - return bleManager.writeFrames( - writeAddress, - BleProtocol.WRITE_CHAR_UUID, - Collections.singletonList(finalFrame), - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS - ) - } - - private fun removePreparedMessageLocked(message: OutboundMessage?): Boolean { - if (message == null || message.magic == 0) { - return false - } - val iterator = inFlightMessages.iterator() - while (iterator.hasNext()) { - if (iterator.next() === message) { - iterator.remove() - magicPool.release(message.sid, message.magic, message.label, "write failed") - return true - } - } - return false - } - - - /** Also drain on the worker: a clear/timeout may have removed a blocking - * head since the last notification. Fully ACKed controls must never reach - * the generic timeout path just because no further BLE reply arrived. */ - private fun drainCfwAcknowledgementsLocked() { - while (true) { - val first = CfwMessageWindow.acknowledgedHead(inFlightMessages) ?: return - lastAckAtMs = SystemClock.elapsedRealtime() - resolveAckLocked(first, first.ackPayload) - } - } - - private fun resolveAckLocked(sid: Int, magic: Int, pb: ByteArray?) { - val iterator = inFlightMessages.iterator() - while (iterator.hasNext()) { - val message = iterator.next() - if (message.sid == sid && message.magic == magic) { - resolveAckLocked(message, pb) - return - } - } - recordUnexpectedAckLocked(sid, magic) - } - - private fun resolveAckLocked(message: OutboundMessage, pb: ByteArray?) { - Log.i(TAG, "Got ACK for " + message.label + "(sid=" + message.sid + ", id=" + message.magic + ")") - inFlightMessages.remove(message) - message.ackPayload = if (pb == null) ByteArray(0) else Arrays.copyOf(pb, pb.size) - magicPool.release(message.sid, message.magic, message.label, "ack") - val onAck = message.onAck - if (onAck != null) { - onAck.run() - } - consecutiveAckTimeouts = 0 - // onAck may have just satisfied a waiter blocked on lock.wait() (e.g. - // awaitEvenHubSessionReady polling fixedLayoutCreated/displayedFingerprint - // after a create-layout or image ack). Without this, that waiter only - // notices on its own up-to-100ms poll tick, adding avoidable latency to - // every EvenHub wake. Always called with lock held (see call site). - lock.notifyAll() - } - - private fun logImageUpdateSendLandmarkLocked(message: OutboundMessage) { - if (message.imageUpdateId <= 0) { - return - } - val stats = imageUpdateStats[message.imageUpdateId] - val frameId = if (stats == null) 0 else stats.frameId - if (message.imageMessageNumber == 1) { - if (stats != null && stats.firstWriteStartedAtMs <= 0) { - stats.firstWriteStartedAtMs = if (message.writeStartedAtMs > 0) message.writeStartedAtMs else message.sentAtMs - } - FrameTimings.getInstance().log(frameId, "first bluetooth packet sent") - logImageUpdateLandmarkLocked("first bluetooth message sent", message, message.sentAtMs) - } - if (message.imageMessageNumber == message.imageMessageCount) { - FrameTimings.getInstance().log(frameId, - "last bluetooth packet sent (message " + message.imageMessageNumber + "/" + message.imageMessageCount + ")") - logImageUpdateLandmarkLocked("last bluetooth message sent", message, message.sentAtMs) - } - } - - private fun logImageUpdateAckLandmarkLocked(message: OutboundMessage) { - if (message.imageUpdateId <= 0 || message.imageMessageNumber != message.imageMessageCount) { - return - } - val ackedAtMs = SystemClock.elapsedRealtime() - FaceclawBleManager.recordDisplayFrameSent() - val stats = imageUpdateStats.remove(message.imageUpdateId) - if (stats != null && stats.firstWriteStartedAtMs > 0) { - emitFrameMetrics(stats.paintMs, Math.max(0L, ackedAtMs - stats.firstWriteStartedAtMs).toInt(), stats.tileCount) - } - if (stats != null) { - finishFrame(stats.frameId, "sent") - } - logImageUpdateLandmarkLocked("last bluetooth message acked", message, ackedAtMs) - } - - /** Remove the stats entry for an image update that will not complete, finishing its frame. */ - private fun discardImageUpdateStatsLocked(imageUpdateId: Int, reason: String) { - if (imageUpdateId <= 0) { - return - } - val stats = imageUpdateStats.remove(imageUpdateId) - if (stats != null) { - finishFrame(stats.frameId, "discarded: $reason") - } - } - - private fun logImageUpdateLandmarkLocked(event: String, message: OutboundMessage, elapsedMs: Long) { - logLine("image update#" + message.imageUpdateId + " " + event - + " at " + timestamp(elapsedMs) - + " message=" + message.imageMessageNumber + "/" + message.imageMessageCount - + " label=" + message.label) - } - - private fun enqueueCreateLayoutLocked() { - // New session: re-assert the firmware-debug-flags overlay once - // the layout is ready (the mode-7 send is gated on this having reset). - firmwareDebugFlagsLastSent = -1 - val message = messageBuilder.createLayout() - message.onAck = MessageCallback { - startupProbePending = false - clearMessagesOfKindLocked("startup-text-probe") - fixedLayoutCreated = true - displayedFingerprint = "" - } - message.onTimeout = MessageCallback { - if (startupProbePending) { - logLine("create layout timed out while startup text probe is pending") - if (hasPendingOrInflightKindLocked("startup-text-probe")) { - return@MessageCallback - } - startupProbePending = false - } - handleTransportFailure("ack timeout") - } - pendingMessages.addLast(message) - logLine("queue create layout") - } + fun suspendEvenHubSession(): Boolean = core.suspendEvenHubSession() - private fun enqueueStartupProbeLocked() { - enqueueCreateLayoutLocked() + fun resumeEvenHubSession(): Boolean = core.resumeEvenHubSession() - val message = messageBuilder.startupTextProbe() - message.onAck = MessageCallback { - startupProbePending = false - clearMessagesOfKindLocked("create-layout") - fixedLayoutCreated = true - displayedFingerprint = "" - logLine("existing dashboard layout accepted text probe") - } - message.onTimeout = MessageCallback { - startupProbePending = false - if (hasPendingOrInflightKindLocked("create-layout")) { - return@MessageCallback - } - handleTransportFailure("ack timeout") - } - pendingMessages.addLast(message) - startupProbePending = true - logLine("queue startup text probe") - } - - /** - * Send the CFW mode-7 diagnostic-flag control op through the private stream: - * [7][2] to show the on-glasses debug-flag overlay, [7][1] to hide it. Uses the - * arbitrary-payload custom path (no bmp/dedup/frame-timing interaction). - */ - private fun enqueueFirmwareDebugFlagsLocked() { - val show = firmwareDebugFlagsEnabled - val sub = if (show) 2 else 1 - val payload = byteArrayOf(CFW_MSG_DIAGNOSTICS.toByte(), sub.toByte()) - val message = messageBuilder.imagePayload( - DASHBOARD_TILE, nextMapSessionId(), payload, - "fw-debug-flags " + (if (show) "show" else "hide"), - connectionOptions.sendImagesToLeft) - pendingMessages.addLast(message) - firmwareDebugFlagsLastSent = sub - logLine("queue firmware debug flags " + (if (show) "show" else "hide")) - } - - /** - * Send CFW image-handler mode 10. Enable uses the configurable form - * [10][2][interval-ms LE16][minimum-change-degrees LE16]; disable remains [10][0]. - */ - private fun enqueueCompassControlLocked(priority: Boolean, enable: Boolean) { - val sentState = if (enable) 1 else 0 - val payload = if (enable) - byteArrayOf( - CFW_MSG_COMPASS.toByte(), - 2.toByte(), - (COMPASS_REPORT_INTERVAL_MS and 0xff).toByte(), - ((COMPASS_REPORT_INTERVAL_MS shr 8) and 0xff).toByte(), - (COMPASS_MIN_CHANGE_DEGREES and 0xff).toByte(), - ((COMPASS_MIN_CHANGE_DEGREES shr 8) and 0xff).toByte(), - ) - else - byteArrayOf(CFW_MSG_COMPASS.toByte(), 0.toByte()) - val message = messageBuilder.imagePayload( - "compass-control", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - "compass " + (if (enable) "enable" else "disable"), - connectionOptions.sendImagesToLeft) - message.onTimeout = MessageCallback { - compassControlLastSent = -1 - logLine("compass control ack timeout") - } - if (enable) { - compassMaybeOn = true - } else { - message.onAck = MessageCallback { compassMaybeOn = false } - } - if (priority) pendingMessages.addFirst(message) - else pendingMessages.addLast(message) - compassControlLastSent = sentState - logLine("queue " + message.label) - } - - private fun enqueueDesiredImageLocked() { - val fingerprint = getDesiredFingerprint() - val packedSnapshot: ByteArray? - val width: Int - val height: Int - val paintMs: Int - val frameId: Int - val draws: Array? - val scene: ShellScene - synchronized(desiredTilesLock) { - packedSnapshot = desiredPacked - width = desiredWidth - height = desiredHeight - paintMs = desiredPaintMs - frameId = desiredFrameId - draws = desiredDraws - scene = desiredShellScene - desiredFrameId = 0 - } - val packedFrame: ByteArray = packedSnapshot ?: ByteArray(0) - if (customFirmwareDetected && packedFrame.size > 0) { - val rendered = scenePlanner.plan(packedFrame, width, height, draws, scene, nextImageFrameId, - connectionOptions.TEXTURE_CACHE_FRAMES, connectionOptions.INCREMENTAL_FRAMES, - connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS) - nextImageFrameId = rendered.nextFid - val commands = rendered.commands - for (i in 0 until commands.size - 1) enqueueResourceCommandLocked(commands[i]) - val plan = BleImageOptimizer.TileImagePlan( - 0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId(), commands[commands.size - 1]) - finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId) - return - } - - FrameTimings.getInstance().spanStart(frameId, "compress-and-plan") - // Incremental (mode 3 bounding box) update against the last ENQUEUED frame - // (the base the firmware shadow will hold when this update is applied). - // lastEnqueuedPacked is cleared whenever the image pipeline is cleared, so - // a non-empty value means the display base is trusted. - var incrementalPayload: ByteArray? = null - var incrementalLog: String? = null - if (connectionOptions.INCREMENTAL_FRAMES && lastEnqueuedPacked.size > 0 - && lastEnqueuedWidth == width && lastEnqueuedHeight == height) { - val baseFid = nextImageFrameId - val single = - BleImageOptimizer.buildIncrementalImagePayload(lastEnqueuedPacked, packedFrame, width, height, baseFid) - if (single != null) { - incrementalPayload = single.payload - // advance only when a delta is actually emitted, so consecutive - // deltas carry consecutive ids (CFW skip/reorder detection) - nextImageFrameId = if (nextImageFrameId >= 0xfffe) 1 else nextImageFrameId + 1 - incrementalLog = "incremental update bbox=" + - ((single.payload[3].toInt() and 0xff) * 4) + "x" + ((single.payload[4].toInt() and 0xff) * 2) + - "+" + ((single.payload[1].toInt() and 0xff) * 4) + "+" + ((single.payload[2].toInt() and 0xff) * 2) + - " changed=" + single.changedBytes + "/" + single.boxBytes + "B" + - " clusters=" + single.clusterCount - - // When the bounding box spans multiple clusters or is sizeable, try - // splitting into tight rects (CFW mode-8). Only replace the single - // box if the multi-rect message is actually smaller on the wire. - if (connectionOptions.MULTI_RECT_FRAMES - && (single.clusterCount > 1 || single.payload.size > ConnectionOptions.MULTI_RECT_MIN_PAYLOAD)) { - val multi = BleImageOptimizer.buildMultiRectImagePayload( - lastEnqueuedPacked, packedFrame, width, height, baseFid, ConnectionOptions.MULTI_RECT_MAX_RECTS) - if (multi != null && multi.payload.size < single.payload.size) { - incrementalPayload = multi.payload - nextImageFrameId = multi.nextFid // rectCount fids consumed - incrementalLog = "multi-rect update n=" + multi.rectCount + - " covered=" + multi.coveredBytes + "B" + - " payload=" + multi.payload.size + "B (vs bbox " + single.payload.size + "B)" - } - } - } - } - val plan = if (incrementalPayload != null) - BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId(), incrementalPayload) - else - BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId()) - FrameTimings.getInstance().spanEnd(frameId, "compress-and-plan") - if (incrementalLog != null) { - FrameTimings.getInstance().log(frameId, incrementalLog) - } - finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId) - } - - /** Queue complete private commands, advance the delta base, and retain frame/ACK bookkeeping. */ - private fun finishEnqueueDesiredImageLocked( - plan: BleImageOptimizer.TileImagePlan, fingerprint: String, paintMs: Int, frameId: Int) { - val updateId = nextImageUpdateId++ - val commands: MutableList = ArrayList() - if (plan.payload.size <= CfwTransport.MAX_MESSAGE) { - commands.add(plan.payload) - } else { - // A noisy full frame can exceed the stream record limit. Repaint it - // with independently decodable RLE bands below the decoded-message limit. - commands.addAll(BleImageOptimizer.encodeFullFrameBands( - plan.packed!!, plan.width, plan.height, nextImageFrameId)) - for (i in 0 until commands.size) { - nextImageFrameId = if (nextImageFrameId >= 0xfffe) 1 else nextImageFrameId + 1 - } - } - val messageCount = commands.size - imageUpdateStats[updateId] = BleImageOptimizer.ImageUpdateStats(paintMs, 1, frameId) - for (i in 0 until commands.size) { - enqueueCustomImageLocked(plan, commands[i], fingerprint, updateId, i + 1, messageCount) - } - // This frame is now the base for the next delta (it will be the firmware - // shadow once applied), even though it hasn't been acked yet — that is what - // lets the next frame pipeline behind it. plan.packed is the full frame; - // frames are immutable by convention, so referencing it is safe. - lastEnqueuedPacked = plan.packed!! - lastEnqueuedWidth = plan.width - lastEnqueuedHeight = plan.height - lastEnqueuedFingerprint = fingerprint - - FrameTimings.getInstance().log(frameId, "queued image update#" + updateId - + " messages=" + messageCount + " payload=" + plan.payload.size + "B") - logLine("queue image update#" + updateId + " fingerprint=" + fingerprint - + " messages=" + messageCount) - } - - /** - * Enqueue one resource eviction/upload command ahead of the image message that - * references its glyphs (the transport is FIFO, so no ack round trip is - * needed before use). A timeout means the on-glasses cache state is - * unknown; forget everything phone-side (glyphs re-upload lazily) and let - * the accompanying image update's own timeout drive the frame resync. - */ - private fun enqueueResourceCommandLocked(payload: ByteArray) { - val message = messageBuilder.imagePayload( - "resources", - DASHBOARD_TILE, - nextMapSessionId(), - payload, - "resource command " + payload.size + "B", - connectionOptions.sendImagesToLeft) - message.onTimeout = MessageCallback { - resourceCache.reset() - logLine("resource command ack timeout; resource cache state reset") - } - pendingMessages.addLast(message) - logLine("queue " + message.label) - } - - private fun enqueueCustomImageLocked( - plan: BleImageOptimizer.TileImagePlan, - payload: ByteArray, - fingerprint: String, - updateId: Int, - messageNumber: Int, - messageCount: Int - ) { - val message = messageBuilder.customMessage("image", payload, - "image " + plan.tile.name + "#" + messageNumber, plan.tileIndex, connectionOptions.sendImagesToLeft) - message.setImageUpdatePosition(updateId, messageNumber, messageCount) - message.onAck = MessageCallback { - imageRetryAfterMs = 0 - // Firmware >= 2.2.4.34 resets its heartbeat timer when it receives - // image messages (not just heartbeats), so an acked image fragment - // satisfies the heartbeat deadline and heartbeats stop contending - // with active rendering. - lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime() - logImageUpdateAckLandmarkLocked(message) - var imageStillInFlight = false - for (inFlight in inFlightMessages) { - if ("image" == inFlight.kind) { - imageStillInFlight = true - break - } - } - if (!imageStillInFlight) { - var imageStillQueued = false - for (queued in pendingMessages) { - if ("image" == queued.kind) { - imageStillQueued = true - break - } - } - if (!imageStillQueued) { - displayedFingerprint = fingerprint - } - } - } - message.onTimeout = MessageCallback { - discardImageUpdateStatsLocked(message.imageUpdateId, "image ack timeout (will retry)") - clearMessagesOfKindLocked("image") - displayedFingerprint = "" - imageRetryAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.IMAGE_RETRY_DELAY_MS - } - pendingMessages.addLast(message) - } - - private fun createAudioControlMessageLocked(enable: Boolean): OutboundMessage { - val message = messageBuilder.enableOrDisableMic(enable) - message.onAck = MessageCallback { - lastAudioControlAckMagic = message.magic - audioCaptureActive = message.label?.contains("enable") == true - logLine(if (audioCaptureActive) "G2 mic enabled" else "G2 mic disabled") - } - message.onTimeout = MessageCallback { - handleTransportFailure("audio control ack timeout") - } - return message - } - - private fun shouldPollBatteryLocked(now: Long): Boolean { - return !shutdownRequested - && sessionReady - && pendingMessages.isEmpty() - && inFlightMessages.isEmpty() - && now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS - && (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS) - } - - private fun createBatteryQueryMessageLocked(): OutboundMessage { - val message = messageBuilder.batteryQuery() - message.onAck = MessageCallback { - val ring = BleProtocol.parseRingBattery(message.ackPayload) - // Old firmware and missing/malformed extensions must clear any prior reading. - ringBattery = if (ring == null) -1 else ring.battery - ringCharging = if (ring == null) -1 else ring.charging - val snapshot = BleProtocol.parseSettingsBattery(message.ackPayload) - if (snapshot != null) { - headsetBattery = snapshot.battery - headsetCharging = snapshot.charging - emitBatteryState(headsetBattery, headsetCharging) - if (snapshot.silentMode >= 0) { - // Backstop for the push in onNotification: the firmware is - // confirmed to push silent-mode-on, but the off transition is - // not, so re-read the authoritative value on every poll. - updateSilentModeLocked(snapshot.silentMode > 0) - } - updateChargingModeLocked(snapshot.charging > 0, snapshot.battery) - } - val firmwareInfo = BleProtocol.parseSettingsFirmwareInfo(message.ackPayload) - if (firmwareInfo != null) { - customFirmwareDetected = firmwareInfo.isFaceclawFirmware() - emitFirmwareInfo(firmwareInfo) - } - } - message.onTimeout = MessageCallback { - logLine("Battery query timed out") - } - return message - } - - /** - * Track silent mode, which the wearer toggles by long-pressing both - * touchpads at once. While it is on the firmware refuses input events and - * app launches and powers the display down, so the glasses look dead even - * though the BLE session is healthy; the phone UI says so explicitly. - */ - private fun updateSilentModeLocked(silent: Boolean) { - val next = if (silent) 1 else 0 - if (silentMode == next) { - return - } - silentMode = next - logLine(if (silent) "glasses entered silent mode" else "glasses left silent mode") - emitSilentMode(silent) - } - - /** - * Track whether the glasses are in the charging case. Charging means nobody - * is wearing them: display communication pauses (no heartbeats, so the - * firmware tears down its EvenHub context on its own) and only battery polls - * continue. When charging stops, tear the transport down and let the normal - * reconnect loop rebuild the session, layout, and first frame. - */ - private fun updateChargingModeLocked(charging: Boolean, battery: Int) { - if (charging == chargingMode) { - if (chargingMode) { - setStateDisplay("charging", chargingStatusText(battery)) - } - return - } - if (charging) { - chargingMode = true - clearAllMessagesLocked("glasses charging") - fixedLayoutCreated = false - startupProbePending = false - displayedFingerprint = "" - finishDesiredFrameLocked("discarded: glasses charging") - logLine("glasses are charging; pausing display communication") - setStateDisplay("charging", chargingStatusText(battery)) - } else { - chargingMode = false - logLine("glasses removed from charger; reconnecting") - handleTransportFailure("charging ended") - } - } - - /** - * Record, into the frame that is waiting, why it did not go out on this - * pass of the send loop. Without this the export shows a bare multi-second - * jump between "image submitted as desired frame" and the first BLE - * packet, with no hint whether we were blocked on a heartbeat, the - * BLE window, or another message queued ahead. Deduped on (frame, reason), - * so a frame stalled for seconds gets one line per state change rather - * than one per loop pass. - */ - private fun noteImageStallLocked(now: Long, windowHasRoom: Boolean) { - var frameId: Int - synchronized(desiredTilesLock) { - frameId = desiredFrameId - } - val reason: String? - if (frameId != 0 && getDesiredFingerprint() != lastEnqueuedFingerprint) { - reason = describeEnqueueBlockerLocked(now, windowHasRoom) - } else { - // Nothing waiting to be planned; an already-planned image may still - // be queued behind other traffic. - val queuedImage = firstPendingImageLocked() - frameId = if (queuedImage == null) 0 else imageUpdateFrameIdLocked(queuedImage.imageUpdateId) - reason = if (queuedImage == null) null else describeWriteBlockerLocked(now, windowHasRoom, queuedImage) - } - if (frameId == 0 || reason == null) { - stallFrameId = 0 - stallReason = "" - return - } - if (frameId == stallFrameId && reason == stallReason) { - return - } - stallFrameId = frameId - stallReason = reason - FrameTimings.getInstance().log(frameId, "waiting to send: $reason") - } - - /** Why the desired composite has not been turned into wire messages yet, or null. */ - private fun describeEnqueueBlockerLocked(now: Long, windowHasRoom: Boolean): String? { - if (shutdownRequested) { - return "shutdown requested" - } - if (!sessionReady) { - return "BLE session not ready" - } - if (!fixedLayoutCreated) { - return "display layout not created yet" - } - if (now < imageRetryAfterMs) { - return "image retry backoff (" + (imageRetryAfterMs - now) + "ms left)" - } - if (hasPendingImageLocked()) { - return "an earlier image is still queued" - } - if (!windowHasRoom) { - return "BLE window full (" + inFlightMessages.size + " message(s) in flight)" - } - if (hasPendingOrInflightKindLocked("heartbeat")) { - return "heartbeat in flight" - } - if (!pendingMessages.isEmpty()) { - return pendingMessages.size.toString() + " message(s) queued ahead, next " + - pendingMessages.peekFirst().label - } - return null - } - - /** Why a planned image message has not been written to BLE yet, or null. */ - private fun describeWriteBlockerLocked(now: Long, windowHasRoom: Boolean, queuedImage: OutboundMessage): String? { - if (!sessionReady) { - return "BLE session not ready" - } - if (!windowHasRoom) { - return "BLE window full (" + inFlightMessages.size + " message(s) in flight)" - } - if (hasPendingOrInflightKindLocked("heartbeat")) { - return "heartbeat in flight" - } - // handleHeartbeat is a barrier: while one is due it holds back every - // other write, so a frame queued at the wrong moment waits a heartbeat - // round trip. Reported explicitly because it is otherwise invisible -- - // heartbeats belong to no frame. - val heartbeatElapsedMs = now - lastHeartbeatAckedAtMs - if (fixedLayoutCreated && !shutdownRequested - && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS) { - return "heartbeat due (" + heartbeatElapsedMs + "ms since the last one acked)" - } - val head = pendingMessages.peekFirst() - if (head != null && head !== queuedImage) { - return "queued behind " + head.label - } - return null - } - - private fun firstPendingImageLocked(): OutboundMessage? { - for (message in pendingMessages) { - if (message.imageUpdateId > 0) { - return message - } - } - return null - } - - private fun imageUpdateFrameIdLocked(imageUpdateId: Int): Int { - val stats = imageUpdateStats[imageUpdateId] - return if (stats == null) 0 else stats.frameId - } - - private fun finishDesiredFrameLocked(outcome: String) { - val frameIdToFinish: Int - synchronized(desiredTilesLock) { - frameIdToFinish = desiredFrameId - desiredFrameId = 0 - } - finishFrame(frameIdToFinish, outcome) - } - - private fun hasPendingOrInflightKindLocked(kind: String): Boolean { - for (queued in pendingMessages) { - if (kind == queued.kind) { - return true - } - } - for (inFlight in inFlightMessages) { - if (kind == inFlight.kind) { - return true - } - } - return false - } - - private fun hasPendingOrInflightMagicLocked(magic: Int): Boolean { - for (queued in pendingMessages) { - if (queued.magic == magic) { - return true - } - } - for (inFlight in inFlightMessages) { - if (inFlight.magic == magic) { - return true - } - } - return false - } - - private fun hasPendingMagicLocked(sid: Int, magic: Int): Boolean { - for (queued in pendingMessages) { - if (queued.sid == sid && queued.magic == magic) { - return true - } - } - return false - } - - private fun handleAckTimeoutLocked(message: OutboundMessage) { - consecutiveAckTimeouts += 1 - - val onTimeout = message.onTimeout - if (onTimeout != null) { - onTimeout.run() - } - - if (consecutiveAckTimeouts > ConnectionOptions.MAX_CONSECUTIVE_ACK_TIMEOUTS) { - handleTransportFailure("too many ack timeouts") - } - } - - /** - * Replace any stale lease control with one right-arm and one left-arm - * fire-and-forget write. With priority=true the right arm is sent first so - * CLAIM reaches the lens that originated the deferred wake immediately. - */ - private fun enqueueFaceclawWakeControlLocked(operation: Int, nonce: Int, priority: Boolean): Int { - clearMessagesOfKindLocked("wake-lease-control") - val generation = ++faceclawWakeControlGeneration - faceclawWakeControlSentCount = 0 - if (operation == BleProtocol.FACECLAW_WAKE_OP_ACQUIRE) { - lastFaceclawWakeLeaseQueuedAtMs = SystemClock.elapsedRealtime() - } - val onSent = MessageCallback { - if (faceclawWakeControlGeneration == generation) { - faceclawWakeControlSentCount += 1 - } - } - val right = messageBuilder.faceclawWakeControl(operation, nonce, false) - val left = messageBuilder.faceclawWakeControl(operation, nonce, true) - right.onSent = onSent - left.onSent = onSent - if (priority) { - pendingMessages.addFirst(left) - pendingMessages.addFirst(right) - } else { - pendingMessages.addLast(right) - pendingMessages.addLast(left) - } - logLine("queue " + right.label + " + L") - return generation - } - - private fun waitForFaceclawWakeControlDelivery(generation: Int, timeoutMs: Long): Boolean { - val deadline = SystemClock.elapsedRealtime() + Math.max(0L, timeoutMs) - synchronized(lock) { - while (running - && sessionReady - && faceclawWakeControlGeneration == generation - && faceclawWakeControlSentCount < 2) { - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - break - } - } - return faceclawWakeControlGeneration == generation - && faceclawWakeControlSentCount >= 2 - } - } - - /** - * Acquire/renew or release CFW's independent direct-framebuffer repaint - * guard on both arms. It is separate from the optional idle-wake lease: - * every Faceclaw display session needs this guard while its EvenHub layout - * contains swipe-capturing stock widgets. - */ - private fun enqueueFaceclawFramebufferControlLocked(operation: Int, priority: Boolean): Int { - clearMessagesOfKindLocked("framebuffer-lease-control") - val generation = ++faceclawFramebufferControlGeneration - faceclawFramebufferControlSentCount = 0 - if (operation == BleProtocol.FACECLAW_FB_OP_ACQUIRE) { - lastFaceclawFramebufferLeaseQueuedAtMs = SystemClock.elapsedRealtime() - } - val onSent = MessageCallback { - if (faceclawFramebufferControlGeneration == generation) { - faceclawFramebufferControlSentCount += 1 - } - } - val right = messageBuilder.faceclawFramebufferControl(operation, false) - val left = messageBuilder.faceclawFramebufferControl(operation, true) - right.onSent = onSent - left.onSent = onSent - if (priority) { - pendingMessages.addFirst(left) - pendingMessages.addFirst(right) - } else { - pendingMessages.addLast(right) - pendingMessages.addLast(left) - } - logLine("queue " + right.label + " + L") - return generation - } - - private fun waitForFaceclawFramebufferControlDelivery(generation: Int, timeoutMs: Long): Boolean { - val deadline = SystemClock.elapsedRealtime() + Math.max(0L, timeoutMs) - synchronized(lock) { - while (running - && sessionReady - && faceclawFramebufferControlGeneration == generation - && faceclawFramebufferControlSentCount < 2) { - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - try { - lock.wait(Math.min(remaining, 100L)) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - break - } - } - return faceclawFramebufferControlGeneration == generation - && faceclawFramebufferControlSentCount >= 2 - } - } - - private fun releaseFaceclawFramebufferLease(): Boolean { - val generation: Int - synchronized(lock) { - if (!running || !sessionReady) { - return true - } - generation = enqueueFaceclawFramebufferControlLocked( - BleProtocol.FACECLAW_FB_OP_RELEASE, - true - ) - } - interruptibleSleep.interrupt() - return waitForFaceclawFramebufferControlDelivery( - generation, - FACECLAW_WAKE_CONTROL_WAIT_MS - ) - } - - private fun clearMessagesOfKindLocked(kind: String) { - val pendingIterator = pendingMessages.iterator() - while (pendingIterator.hasNext()) { - val message = pendingIterator.next() - if (kind == message.kind) { - pendingIterator.remove() - discardPrewriteIfMatchesLocked(message) - if ("image" == kind) { - discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared ($kind)") - } - magicPool.release(message.sid, message.magic, message.label, "cleared pending $kind") - } - } - val inFlightIterator = inFlightMessages.iterator() - while (inFlightIterator.hasNext()) { - val message = inFlightIterator.next() - if (kind == message.kind) { - inFlightIterator.remove() - if ("image" == kind) { - discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared ($kind)") - } - magicPool.release(message.sid, message.magic, message.label, "cleared inflight $kind") - } - } - if ("image" == kind) { - // The image pipeline was flushed (e.g. ack timeout -> keyframe resync): - // drop the pipelined delta base so the next image is a full keyframe. - lastEnqueuedPacked = ByteArray(0) - lastEnqueuedFingerprint = "" - } - } - - private fun clearAllMessagesLocked(reason: String) { - clearPendingMessagesLocked(reason) - clearInFlightMessagesLocked(reason) - // The image pipeline is gone: drop the pipelined delta base so the next - // image is a full keyframe rather than a delta onto a stale base. - lastEnqueuedPacked = ByteArray(0) - lastEnqueuedFingerprint = "" - // Queued resource commands (if any) were dropped with the rest, and the - // session churn behind a full clear may have freed the on-glasses - // cache; forget it phone-side so glyphs re-upload lazily. - resourceCache.reset() - } - - /** - * A custom wake queues CLAIM before NativeScript asks for a resume. Keep - * that private control while flushing stale EvenHub traffic around the - * direct prelude write. - */ - private fun clearAllMessagesPreservingWakeLeaseLocked(reason: String) { - val pendingIterator = pendingMessages.iterator() - while (pendingIterator.hasNext()) { - val message = pendingIterator.next() - if ("wake-lease-control" == message.kind) { - continue - } - pendingIterator.remove() - discardPrewriteIfMatchesLocked(message) - discardImageUpdateStatsLocked( - message.imageUpdateId, - "pending messages cleared: $reason" - ) - magicPool.release( - message.sid, - message.magic, - message.label, - "cleared pending: $reason" - ) - } - clearInFlightMessagesLocked(reason) - lastEnqueuedPacked = ByteArray(0) - lastEnqueuedFingerprint = "" - resourceCache.reset() - } - - /** Any image update whose fragments are still queued (not yet sent). */ - private fun hasPendingImageLocked(): Boolean { - for (message in pendingMessages) { - if ("image" == message.kind) { - return true - } - } - return false - } - - private fun clearPendingMessagesLocked(reason: String) { - while (!pendingMessages.isEmpty()) { - val message = pendingMessages.removeFirst() - discardPrewriteIfMatchesLocked(message) - discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared: $reason") - magicPool.release(message.sid, message.magic, message.label, "cleared pending: $reason") - } - } - - private fun clearInFlightMessagesLocked(reason: String) { - while (!inFlightMessages.isEmpty()) { - val message = inFlightMessages.removeFirst() - discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared: $reason") - magicPool.release(message.sid, message.magic, message.label, "cleared inflight: $reason") - } - } - - private fun discardPrewriteIfMatchesLocked(message: OutboundMessage?) { - if (message != null && message === prewrittenMessage) { - prewrittenMessage = null - prewrittenFrames = Collections.emptyList() - } - } - - private fun recordUnexpectedAckLocked(sid: Int, magic: Int) { - if (magic < BleMagicPool.MIN_MAGIC || magic > BleMagicPool.MAX_MAGIC) { - return - } - val previous = magicPool.getReleaseRecord(sid, magic) - if (previous == null) { - val pendingNote = if (hasPendingMagicLocked(sid, magic)) " while that magic is only pending locally" else "" - logLine("unexpected ACK sid=" + sid + " magic=" + magic + pendingNote - + "; possible Even app BLE contention") - return - } - if ("timeout" == previous.reason) { - logLine("late ACK after timeout sid=" + sid + " magic=" + magic - + " label=" + previous.label - + "; ACK timeout may be too short") - return - } - if ("ack" == previous.reason) { - logLine("duplicate ACK for already-acked message sid=" + sid + " magic=" + magic - + " label=" + previous.label - + "; possible Even app BLE contention") - return - } - logLine("late ACK for released message sid=" + sid + " magic=" + magic - + " label=" + previous.label - + " release=" + previous.reason) - } - - /** The address of a configured arm Android no longer holds a bond for, or null. */ - private fun firstUnpairedArm(): String? { - if (!bleManager.isBonded(rightAddress)) return rightAddress - if (!bleManager.isBonded(leftAddress)) return leftAddress - return null - } - - /** - * A connect failure while an arm's bond is missing (the pairing was - * forgotten in Android settings, or the address was typed in by hand and - * never paired) will repeat forever, so instead of scheduling a retry, - * park the worker loop and tell the user to re-pair. Only an explicit - * connect (which builds a fresh communicator) starts a new attempt. - */ - private fun handleUnpairedFailure(address: String) { - Log.e(TAG, "Connect failed and $address is not paired; suspending reconnect") - synchronized(lock) { - reconnectHalted = true - sessionReady = false - fixedLayoutCreated = false - startupProbePending = false - shutdownRequested = false - chargingMode = false - imageRetryAfterMs = 0 - displayedFingerprint = "" - faceclawWakePendingNonce = -1 - lastFaceclawWakeLeaseQueuedAtMs = 0 - faceclawWakeControlSentCount = 0 - clearAllMessagesLocked("arm not paired: $address") - reconnectAfterMs = Long.MAX_VALUE - bleManager.disconnect(rightAddress) - bleManager.disconnect(leftAddress) - } - if (!userDisconnectRequested) { - setStateDisplay( - "unpaired", - "The glasses (" + address + ") are not paired with this phone." - + " Use \"Pair glasses\" to pair them again, then connect." - ) - } - interruptibleSleep.interrupt() - } - - private fun handleTransportFailure(reason: String?) { - Log.e(TAG, "Transport failure: $reason") - synchronized(lock) { - maybeEmitEvenAppConflictLocked(reason) - finishBenchmarkLocked(true, "transport failure") - sessionReady = false - fixedLayoutCreated = false - startupProbePending = false - shutdownRequested = false - chargingMode = false - imageRetryAfterMs = 0 - displayedFingerprint = "" - faceclawWakePendingNonce = -1 - lastFaceclawWakeLeaseQueuedAtMs = 0 - faceclawWakeControlSentCount = 0 - clearAllMessagesLocked("transport failure: $reason") - reconnectAfterMs = SystemClock.elapsedRealtime() + ConnectionOptions.RECONNECT_DELAY_MS - bleManager.disconnect(rightAddress) - bleManager.disconnect(leftAddress) - } - if (!userDisconnectRequested) { - setStateDisplay("retrying", if (reason == null || reason.isEmpty()) "Reconnecting..." else "Reconnecting after $reason") - } - interruptibleSleep.interrupt() - } - - private fun resetSessionStateLocked() { - ringBattery = -1 - ringCharging = -1 - sessionReady = false - shutdownRequested = false - fixedLayoutCreated = false - chargingMode = false - rightConnected = false - leftConnected = false - ringConnected = false - ringNotificationsReady = false - reconnectAfterMs = 0 - reconnectHalted = false - ringReconnectAfterMs = 0 - lastAckAtMs = 0 - lastIncomingAtMs = 0 - lastHeartbeatSentAtMs = 0 - lastSessionReadyAtMs = 0 - consecutiveAckTimeouts = 0 - lastAudioControlAckMagic = 0 - audioCaptureActive = false - audioPacketListener = null - compassControlLastSent = -1 - // A dead transport orphans any glasses-side compass state; the fresh - // session re-asserts the desired state once its layout is ready. - compassMaybeOn = false - faceclawWakePendingNonce = -1 - lastFaceclawWakeLeaseQueuedAtMs = 0 - faceclawWakeControlSentCount = 0 - cfwCleanupDelivered = false - for (transport in cfwTransports) transport.reset() - lastCfwCleanupAckMagic = 0 - wearState = -1 - displayedFingerprint = "" - // Deliberately not clearing silentMode: it is a property of the glasses, - // not of our session, and silent mode blocks app launches, so it can be - // the very cause of the session teardown that got us here. - } - - private fun emitRingEvent(event: G2Event, frameId: Int) { - val current = listener - if (current == null) { - FrameTimings.getInstance().finishFrame(frameId, "discarded: no listener attached") - return - } - val containerNameSnapshot = event.containerName - mainHandler.post { - FrameTimings.getInstance().log(frameId, "dispatching input event on main thread") - try { - current.onRingEvent(event.kind, containerNameSnapshot, event.eventType, event.eventSource, event.systemExitReasonCode, frameId, - event.ringTick, event.ringType, event.ringAux, event.ringSpeed) - } catch (t: Throwable) { - Log.w(TAG, "listener onRingEvent failed", t) - FrameTimings.getInstance().finishFrame(frameId, "discarded: listener onRingEvent failed") - } - } - } - - /** Finish a frame owned by the communicator and tell the TS side, which may be awaiting it. */ - private fun finishFrame(frameId: Int, outcome: String) { - if (frameId <= 0) { - return - } - FrameTimings.getInstance().finishFrame(frameId, outcome) - val current = listener ?: return - mainHandler.post { - try { - current.onFrameFinished(frameId, outcome) - } catch (t: Throwable) { - Log.w(TAG, "listener onFrameFinished failed", t) - } - } - } - - private fun emitImuData(x: Double, y: Double, z: Double, eventSource: Int) { - if (imuListeners.isEmpty()) { - return - } - mainHandler.post { - for (imuListener in imuListeners) { - try { - imuListener.onImuData(x, y, z, eventSource) - } catch (t: Throwable) { - Log.w(TAG, "listener onImuData failed", t) - } - } - } - } - - private fun emitCompassEvent(event: BleProtocol.CompassEvent) { - if (event.diagnosticFlags >= 0) { - val sources = arrayOf("unknown", "GRV", "GMRV", "RV") - Log.i("FaceclawCompass", "heading=" + event.headingDegrees - + " magneticAccuracy=" + event.magneticAccuracy - + " magneticAnomalies=" + event.magneticAnomalies - + " orientationSource=" + sources[event.orientationSource] - + " flags=0x" + Integer.toHexString(event.diagnosticFlags) - + " sampleTimeMs=" + event.sampleTimeMs) - } - for (subscription in compassSubscriptions) { - subscription.handler.post { - try { - subscription.listener.onCompassEvent(event.command, event.headingDegrees, - event.magneticAccuracy, event.magneticAnomalies, event.orientationSource, - event.diagnosticFlags, event.sampleTimeMs) - } catch (t: Throwable) { - Log.w(TAG, "listener onCompassEvent failed", t) - } - } - } - } - - private fun emitSilentMode(silent: Boolean) { - val current = listener ?: return - mainHandler.post { - try { - current.onSilentMode(silent) - } catch (t: Throwable) { - Log.w(TAG, "listener onSilentMode failed", t) - } - } - } - - private fun emitWearState(wearing: Boolean) { - val current = listener ?: return - mainHandler.post { - try { - current.onWearState(wearing) - } catch (t: Throwable) { - Log.w(TAG, "listener onWearState failed", t) - } - } - } - - private fun emitPhoneLockStateIfChanged(force: Boolean) { - val locked: Boolean - synchronized(lock) { - val now = SystemClock.elapsedRealtime() - if (!force && now - lastPhoneLockCheckAtMs < 1_000) return - lastPhoneLockCheckAtMs = now - locked = keyguardManager != null && keyguardManager.isDeviceLocked - val value = if (locked) 1 else 0 - if (!force && value == phoneLockState) return - phoneLockState = value - } - val current = listener ?: return - mainHandler.post { - try { - current.onPhoneLockState(locked) - } catch (t: Throwable) { - Log.w(TAG, "listener onPhoneLockState failed", t) - } - } - } - - private fun emitBatteryState(headsetBattery: Int, headsetCharging: Int) { - val reportedRingBattery = ringBattery - val reportedRingCharging = ringCharging - val current = listener ?: return - mainHandler.post { - try { - current.onBatteryState(headsetBattery, headsetCharging, reportedRingBattery, reportedRingCharging) - } catch (t: Throwable) { - Log.w(TAG, "listener onBatteryState failed", t) - } - } - } - - private fun emitFirmwareInfo(info: BleProtocol.FirmwareInfo) { - val current = listener ?: return - mainHandler.post { - try { - current.onFirmwareInfo(info.leftVersion, info.rightVersion, info.extension) - } catch (t: Throwable) { - Log.w(TAG, "listener onFirmwareInfo failed", t) - } - } - } - - private fun emitFrameMetrics(paintMs: Int, transmitMs: Int, tileCount: Int) { - val current = listener ?: return - mainHandler.post { - try { - current.onFrameMetrics(paintMs, transmitMs, tileCount) - } catch (t: Throwable) { - Log.w(TAG, "listener onFrameMetrics failed", t) - } - } - } - - private fun maybeEmitEvenAppConflictLocked(reason: String?) { - if ("write failed" != reason) { - return - } - val now = SystemClock.elapsedRealtime() - if (lastSessionReadyAtMs <= 0 || now - lastSessionReadyAtMs > ConnectionOptions.EVEN_APP_WRITE_FAILURE_WINDOW_MS) { - return - } - if (lastEvenAppConflictAtMs > 0 && now - lastEvenAppConflictAtMs < 60_000) { - return - } - if (!FaceclawEvenAppDetector.isEvenNotificationActive(appContext)) { - return - } - lastEvenAppConflictAtMs = now - emitEvenAppConflict("The Even Realities app still appears to be running. It can hold the glasses BLE link and cause Faceclaw write failures. Open its app settings and force stop it, then reconnect Faceclaw.") - } - - private fun emitEvenAppConflict(message: String?) { - val current = listener ?: return - val messageSnapshot = message ?: "" - mainHandler.post { - try { - current.onEvenAppConflict(messageSnapshot) - } catch (t: Throwable) { - Log.w(TAG, "listener onEvenAppConflict failed", t) - } - } - } - - private fun setStateDisplay(nextPhase: String, nextStatus: String) { - synchronized(lock) { - phase = nextPhase - status = nextStatus - } - emitState() - } - - private fun emitState() { - val current = listener ?: return - val phaseSnapshot: String - val statusSnapshot: String - synchronized(lock) { - phaseSnapshot = phase - statusSnapshot = status - } - mainHandler.post { - try { - current.onStateChange(phaseSnapshot, statusSnapshot) - } catch (t: Throwable) { - Log.w(TAG, "listener onStateChange failed", t) - } - } - } + // --------------------------------------------------------------------- private fun updateG2ScreenWakeLock(screenOn: Boolean) { if (screenOn) { @@ -4022,51 +374,14 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre } if (!wakeLock.isHeld) { wakeLock.acquire() - logLine("G2 screen wake lock acquired") + Log.i(TAG, "G2 screen wake lock acquired") } return } - releaseG2ScreenWakeLock() - } - - private fun releaseG2ScreenWakeLock() { val wakeLock = g2ScreenWakeLock if (wakeLock != null && wakeLock.isHeld) { wakeLock.release() - logLine("G2 screen wake lock released") - } - } - - private fun logLine(line: String) { - Log.i(TAG, line) - } - - private fun nextMapSessionId(): Int { - val id = nextMapSessionId - val increment = if (connectionOptions.skipSessionIds) 2 else 1 - nextMapSessionId = (nextMapSessionId + increment) and 0xff - return id - } - - private fun hasRingAddress(): Boolean { - return ringAddress.trim().isNotEmpty() - } - - private fun isConfiguredRingAddress(address: String?): Boolean { - return hasRingAddress() && address != null && address.equals(ringAddress, ignoreCase = true) - } - - private fun isDirectRingNotification(address: String?, characteristicUuid: String?): Boolean { - if (!isConfiguredRingAddress(address) || characteristicUuid == null) { - return false - } - return BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID == characteristicUuid - || BleProtocol.R1_NOTIFY_CHAR_UUID == characteristicUuid - } - - private fun getDesiredFingerprint(): String { - synchronized(desiredTilesLock) { - return desiredFingerprint + Log.i(TAG, "G2 screen wake lock released") } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt index c0cc2e04..d985766e 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawCaptionEngine.kt @@ -2,455 +2,74 @@ package com.faceclaw.app import android.os.Handler import android.os.Looper -import android.util.Log - -import com.k2fsa.sherpa.onnx.FeatureConfig -import com.k2fsa.sherpa.onnx.OfflineModelConfig -import com.k2fsa.sherpa.onnx.OfflineMoonshineModelConfig -import com.k2fsa.sherpa.onnx.OfflineRecognizer -import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig -import com.k2fsa.sherpa.onnx.OfflineRecognizerResult -import com.k2fsa.sherpa.onnx.OfflineStream import java.io.File -import java.util.ArrayDeque -import java.util.Arrays /** - * Continuous captioning over the decoded mic PCM: segments speech into - * utterances with an adaptive energy gate, transcribes each utterance with - * the on-device Moonshine model, and attaches a speaker voice-print per - * utterance. PCM is pushed in from the TS side (which owns mic arbitration - * and any beam-direction gating), so this engine has no BLE dependencies. + * Continuous captioning over the decoded mic PCM: the shared [CaptionSession] segments speech + * into utterances with an adaptive energy gate, transcribes each with the on-device Moonshine + * model and attaches a speaker voice-print. This Android class only supplies the sherpa-onnx + * recognizer and speaker model and delivers callbacks on the main thread. PCM is pushed in + * from the TS side (which owns mic arbitration and any beam-direction gating), so the engine + * has no BLE dependencies. * - * Utterance boundaries are measured on the sample clock, not the wall clock: - * BLE delivers mic packets in bursts, so elapsed real time overestimates the - * audio heard. The TS side converts startMs/endMs to wall-clock times using - * the engine start timestamp. + * Utterance boundaries are measured on the sample clock, not the wall clock; the TS side + * converts startMs/endMs to wall-clock times using the engine start timestamp. */ class FaceclawCaptionEngine { - companion object { - private const val TAG = "FaceclawCaptions" - private const val SAMPLE_RATE = 16000 - private const val FEATURE_DIM = 80 - private const val MAX_QUEUE_PACKETS = 200 + private val mainHandler = Handler(Looper.getMainLooper()) - // Segmentation: RMS thresholds relative to a rolling noise floor, in the - // same spirit as FaceclawVoiceController.EndpointDetector but recurring. - private const val ONSET_FACTOR = 3.0 - private const val RELEASE_FACTOR = 1.8 - private const val MIN_RMS = 220.0 - private const val NOISE_EMA_ALPHA = 0.05 - private const val PRE_ROLL_MS = 400 - private const val DEFAULT_SILENCE_MS = 800 - private const val MIN_UTTERANCE_MS = 350 - private const val MAX_UTTERANCE_MS = 15000 - // Moonshine v2 fails past ~9.1 s of input; decode long utterances in - // segments cut at the quietest window (mirrors FaceclawVoiceController). - private const val DECODE_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8 - private const val CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2 - private const val CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000 - private const val NORMALIZE_TARGET_PEAK = 0.9f - private const val NORMALIZE_MAX_GAIN = 30f - // Voice-prints degrade on very long inputs; embed at most the first 10 s. - private const val EMBED_MAX_SAMPLES = SAMPLE_RATE * 10 + private val host = object : CaptionHost { + override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } } + + override fun loadTranscriber(modelDir: String): OfflineTranscriber? { + if (!File(modelDir, "tokens.txt").exists()) { + return null + } + return AndroidSpeechEngines.SherpaTranscriber( + AndroidSpeechEngines.recognizerConfig(File(modelDir), VoiceModelKind.MOONSHINE)) + } + + override fun loadEmbedder(modelPath: String): SpeakerEmbedder? { + if (!File(modelPath).exists()) { + return null + } + val speakerId = FaceclawSpeakerId(modelPath) + speakerId.ensureLoaded() + return speakerId + } } - private val mainHandler = Handler(Looper.getMainLooper()) - private val lock = Any() - private val queueLock = Any() - private val queue = ArrayDeque() - - @Volatile - private var listener: FaceclawCaptionEngineListener? = null - @Volatile - private var asrModelDir: String? = null - @Volatile - private var speakerModelPath: String? = null - @Volatile - private var silenceMs = DEFAULT_SILENCE_MS - private var workerThread: Thread? = null - @Volatile - private var started = false - - private var recognizer: OfflineRecognizer? = null - private var speakerId: FaceclawSpeakerId? = null - - // Segmentation state (worker thread only). - private var totalSamples: Long = 0 - private var noiseFloor = 0.0 - private var inUtterance = false - private var utteranceStartSample: Long = 0 - private var silenceRunSamples: Long = 0 - private var utterancePeakRms = 0.0 - private var utterance = ShortArray(SAMPLE_RATE * (MAX_UTTERANCE_MS / 1000)) - private var utteranceLength = 0 - private val preRoll = ShortArray(SAMPLE_RATE * PRE_ROLL_MS / 1000) - private var preRollLength = 0 + private val session = CaptionSession(host) fun setListener(listener: FaceclawCaptionEngineListener?) { - this.listener = listener + session.setListener(listener) } /** Directory holding the Moonshine model files, or null to disable ASR. */ fun setAsrModelDir(dir: String?) { - this.asrModelDir = dir + session.setAsrModelDir(dir) } /** Speaker-embedding ONNX model path, or null to disable voice-prints. */ fun setSpeakerModelPath(path: String?) { - this.speakerModelPath = path + session.setSpeakerModelPath(path) } fun setSilenceMs(ms: Int) { - this.silenceMs = Math.max(200, Math.min(3000, ms)) + session.setSilenceMs(ms) } fun start() { - synchronized(lock) { - if (started) { - return - } - started = true - workerThread = Thread(Runnable { runLoop() }, "FaceclawCaptionEngine") - workerThread!!.start() - } + session.start() } fun stop() { - val threadToJoin: Thread? - synchronized(lock) { - if (!started) { - return - } - started = false - threadToJoin = workerThread - workerThread = null - } - synchronized(queueLock) { - (queueLock as java.lang.Object).notifyAll() - } - if (threadToJoin != null) { - threadToJoin.interrupt() - if (Thread.currentThread() !== threadToJoin) { - try { - threadToJoin.join(2000) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - } - } - } + session.stop() } /** Push decoded 16 kHz mono S16LE PCM (any chunking). */ fun acceptPcm(pcm16le: ByteArray?) { - if (!started || pcm16le == null || pcm16le.size < 2) { - return - } - synchronized(queueLock) { - if (queue.size >= MAX_QUEUE_PACKETS) { - queue.removeFirst() - } - queue.addLast(pcm16le) - (queueLock as java.lang.Object).notifyAll() - } - } - - private fun runLoop() { - try { - loadModels() - resetSegmentation() - while (started && !Thread.currentThread().isInterrupted) { - val chunk = takeChunk() - if (chunk == null) { - continue - } - processChunk(chunk) - } - // Flush a trailing utterance so its text isn't lost on stop. - if (inUtterance && utteranceLength > 0) { - finalizeUtterance() - } - } catch (t: Throwable) { - Log.e(TAG, "caption engine failed", t) - emitStatus("Captions failed: " + t.message) - } finally { - releaseModels() - } - } - - private fun loadModels() { - val modelDir = asrModelDir - if (modelDir != null && File(modelDir, "tokens.txt").exists()) { - emitStatus("Loading caption model...") - recognizer = OfflineRecognizer(OfflineRecognizerConfig.builder() - .setFeatureConfig(FeatureConfig.builder() - .setSampleRate(SAMPLE_RATE) - .setFeatureDim(FEATURE_DIM) - .build()) - .setModelConfig(OfflineModelConfig.builder() - .setMoonshine(OfflineMoonshineModelConfig.builder() - .setEncoder(File(modelDir, "encoder_model.ort").absolutePath) - .setMergedDecoder(File(modelDir, "decoder_model_merged.ort").absolutePath) - .build()) - .setTokens(File(modelDir, "tokens.txt").absolutePath) - .setNumThreads(1) - .build()) - .build()) - } else { - recognizer = null - } - val embedModel = speakerModelPath - if (embedModel != null && File(embedModel).exists()) { - speakerId = FaceclawSpeakerId(embedModel) - speakerId!!.ensureLoaded() - } else { - speakerId = null - } - emitStatus(if (recognizer != null) "Captions listening..." else "Captions listening (no ASR model)...") - } - - private fun releaseModels() { - if (recognizer != null) { - recognizer!!.release() - recognizer = null - } - if (speakerId != null) { - speakerId!!.close() - speakerId = null - } - } - - private fun takeChunk(): ByteArray? { - synchronized(queueLock) { - while (started && queue.isEmpty()) { - try { - (queueLock as java.lang.Object).wait(250) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - return null - } - } - return queue.pollFirst() - } - } - - private fun resetSegmentation() { - totalSamples = 0 - noiseFloor = 0.0 - inUtterance = false - utteranceLength = 0 - preRollLength = 0 - silenceRunSamples = 0 - utterancePeakRms = 0.0 - } - - private fun processChunk(chunk: ByteArray) { - val count = chunk.size / 2 - val pcm = ShortArray(count) - var sumSquares = 0.0 - for (i in 0 until count) { - val s = ((chunk[i * 2].toInt() and 0xff) or (chunk[i * 2 + 1].toInt() shl 8)).toShort() - pcm[i] = s - sumSquares += s.toDouble() * s - } - val rms = Math.sqrt(sumSquares / Math.max(1, count)) - totalSamples += count.toLong() - - if (!inUtterance) { - // Track the noise floor only while idle so speech doesn't raise it. - noiseFloor = if (noiseFloor == 0.0) rms else noiseFloor * (1 - NOISE_EMA_ALPHA) + rms * NOISE_EMA_ALPHA - val threshold = Math.max(noiseFloor, MIN_RMS) - if (rms >= threshold * ONSET_FACTOR) { - inUtterance = true - utteranceLength = 0 - silenceRunSamples = 0 - utterancePeakRms = rms - appendUtterance(preRoll, preRollLength) - utteranceStartSample = Math.max(0L, totalSamples - count - preRollLength) - appendUtterance(pcm, count) - emitSpeechStart(utteranceStartSample * 1000 / SAMPLE_RATE) - } else { - appendPreRoll(pcm, count) - } - return - } - - appendUtterance(pcm, count) - utterancePeakRms = Math.max(utterancePeakRms, rms) - val threshold = Math.max(noiseFloor, MIN_RMS) - if (rms < threshold * RELEASE_FACTOR) { - silenceRunSamples += count.toLong() - } else { - silenceRunSamples = 0 - } - val utteranceMs = utteranceLength.toLong() * 1000 / SAMPLE_RATE - val silenceEnded = silenceRunSamples * 1000L / SAMPLE_RATE >= silenceMs - if (silenceEnded || utteranceMs >= MAX_UTTERANCE_MS) { - finalizeUtterance() - inUtterance = false - preRollLength = 0 - } - } - - private fun appendPreRoll(pcm: ShortArray, count: Int) { - // Keep the last PRE_ROLL_MS of idle audio so onset consonants survive. - if (count >= preRoll.size) { - System.arraycopy(pcm, count - preRoll.size, preRoll, 0, preRoll.size) - preRollLength = preRoll.size - return - } - val keep = Math.min(preRollLength, preRoll.size - count) - System.arraycopy(preRoll, preRollLength - keep, preRoll, 0, keep) - System.arraycopy(pcm, 0, preRoll, keep, count) - preRollLength = keep + count - } - - private fun appendUtterance(pcm: ShortArray, count: Int) { - val room = utterance.size - utteranceLength - val copied = Math.min(room, count) - if (copied > 0) { - System.arraycopy(pcm, 0, utterance, utteranceLength, copied) - utteranceLength += copied - } - } - - private fun finalizeUtterance() { - val length = utteranceLength - val startMs = utteranceStartSample * 1000 / SAMPLE_RATE - val endMs = (utteranceStartSample + length) * 1000 / SAMPLE_RATE - if (endMs - startMs < MIN_UTTERANCE_MS) { - return - } - val text = recognizeUtterance(length) - val embedding = embedUtterance(length) - emitUtterance(text, embedding, startMs, endMs, utterancePeakRms) - } - - private fun recognizeUtterance(length: Int): String { - if (recognizer == null || length <= 0) { - return "" - } - val joined = StringBuilder() - var offset = 0 - while (offset < length) { - val remaining = length - offset - var segment = Math.min(remaining, DECODE_SEGMENT_MAX_SAMPLES) - if (remaining > DECODE_SEGMENT_MAX_SAMPLES) { - segment = findQuietCut(offset, segment) - } - val part = recognizeRange(offset, segment) - if (part.length > 0) { - if (joined.length > 0 && ".,!?;:%)]}".indexOf(part[0]) < 0) { - joined.append(' ') - } - joined.append(part) - } - offset += segment - } - return joined.toString().trim() - } - - /** - * End a decode segment at the center of the quietest window near its end - * so the cut lands between words (same approach as the PTT controller). - */ - private fun findQuietCut(offset: Int, segment: Int): Int { - val searchStart = Math.max(0, segment - CUT_SEARCH_SAMPLES) - val win = CUT_WINDOW_SAMPLES - if (segment - searchStart <= win) { - return segment - } - var sum = 0.0 - for (i in searchStart until searchStart + win) { - val s = utterance[offset + i].toDouble() - sum += s * s - } - var best = sum - var bestStart = searchStart - var start = searchStart + 1 - while (start + win <= segment) { - val dropped = utterance[offset + start - 1].toDouble() - val added = utterance[offset + start + win - 1].toDouble() - sum += added * added - dropped * dropped - if (sum < best) { - best = sum - bestStart = start - } - start++ - } - return bestStart + win / 2 - } - - private fun recognizeRange(offset: Int, count: Int): String { - val samples = FloatArray(count) - var peak = 0f - for (i in 0 until count) { - val v = utterance[offset + i] / 32768.0f - samples[i] = v - val a = Math.abs(v) - if (a > peak) { - peak = a - } - } - if (peak > 0f) { - val gain = Math.min(NORMALIZE_TARGET_PEAK / peak, NORMALIZE_MAX_GAIN) - if (gain > 1f) { - for (i in 0 until count) { - samples[i] *= gain - } - } - } - val recognizer = this.recognizer!! - val stream: OfflineStream = recognizer.createStream() - try { - stream.acceptWaveform(samples, SAMPLE_RATE) - recognizer.decode(stream) - val result: OfflineRecognizerResult? = recognizer.getResult(stream) - val raw: String? = if (result == null) "" else result.text - return raw?.trim() ?: "" - } finally { - stream.release() - } - } - - private fun embedUtterance(length: Int): FloatArray? { - val currentSpeakerId = speakerId - if (currentSpeakerId == null || length <= 0) { - return null - } - val count = Math.min(length, EMBED_MAX_SAMPLES) - val le = ByteArray(count * 2) - for (i in 0 until count) { - val s = utterance[i].toInt() - le[i * 2] = (s and 0xff).toByte() - le[i * 2 + 1] = ((s shr 8) and 0xff).toByte() - } - return currentSpeakerId.embed(le, SAMPLE_RATE) - } - - private fun emitUtterance(text: String?, embedding: FloatArray?, startMs: Long, endMs: Long, peakRms: Double) { - val currentListener = listener - if (currentListener == null) { - return - } - val embeddingCopy = if (embedding == null) null else Arrays.copyOf(embedding, embedding.size) - mainHandler.post { currentListener.onUtterance(text, embeddingCopy, startMs, endMs, peakRms) } - } - - private fun emitSpeechStart(startMs: Long) { - val currentListener = listener - if (currentListener == null) { - return - } - mainHandler.post { currentListener.onSpeechStart(startMs) } - } - - private fun emitStatus(status: String?) { - val currentListener = listener - if (currentListener == null) { - return - } - mainHandler.post { currentListener.onStatus(status) } + session.acceptPcm(pcm16le) } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt index d9002ede..2d9f316f 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawConversationStore.kt @@ -13,8 +13,6 @@ import org.json.JSONException import org.json.JSONObject import java.io.File -import java.nio.ByteBuffer -import java.nio.ByteOrder import java.util.ArrayList /** @@ -47,41 +45,6 @@ class FaceclawConversationStore private constructor(context: Context) : SQLiteOp } } - // ---- blob helpers ---- - - private fun blobToFloats(blob: ByteArray?): FloatArray? { - if (blob == null || blob.size < 4 || blob.size % 4 != 0) { - return null - } - val buffer = ByteBuffer.wrap(blob).order(ByteOrder.LITTLE_ENDIAN) - val out = FloatArray(blob.size / 4) - for (i in out.indices) { - out[i] = buffer.getFloat() - } - return out - } - - private fun floatsToBlob(values: FloatArray): ByteArray { - val buffer = ByteBuffer.allocate(values.size * 4).order(ByteOrder.LITTLE_ENDIAN) - for (v in values) { - buffer.putFloat(v) - } - return buffer.array() - } - - private fun l2NormalizeInPlace(v: FloatArray) { - var sum = 0.0 - for (x in v) { - sum += x.toDouble() * x - } - val norm = Math.sqrt(sum) - if (norm <= 0) { - return - } - for (i in v.indices) { - v[i] = (v[i] / norm).toFloat() - } - } } override fun onCreate(db: SQLiteDatabase) { @@ -567,7 +530,7 @@ class FaceclawConversationStore private constructor(context: Context) : SQLiteOp fun updateSpeakerEmbedding(speakerId: Long, embeddingBase64: String?, maxCount: Int) { try { val incoming = Base64.decode(embeddingBase64, Base64.NO_WRAP) - val update = blobToFloats(incoming) + val update = SpeakerEmbeddings.blobToFloats(incoming) if (update == null) { return } @@ -578,28 +541,16 @@ class FaceclawConversationStore private constructor(context: Context) : SQLiteOp arrayOf(speakerId.toString())) try { if (c.moveToFirst()) { - current = if (c.isNull(0)) null else blobToFloats(c.getBlob(0)) + current = if (c.isNull(0)) null else SpeakerEmbeddings.blobToFloats(c.getBlob(0)) count = c.getInt(1) } } finally { c.close() } - val merged: FloatArray - if (current == null || current.size != update.size) { - merged = update - count = 1 - } else { - val effective = Math.min(count, Math.max(1, maxCount)) - merged = FloatArray(current.size) - for (i in merged.indices) { - merged[i] = (current[i] * effective + update[i]) / (effective + 1) - } - l2NormalizeInPlace(merged) - count = count + 1 - } + val centroid = SpeakerEmbeddings.runningMean(current, count, update, maxCount) val values = ContentValues() - values.put("embedding", floatsToBlob(merged)) - values.put("embedding_count", count) + values.put("embedding", SpeakerEmbeddings.floatsToBlob(centroid.embedding)) + values.put("embedding_count", centroid.count) values.put("last_heard_at", System.currentTimeMillis()) writableDatabase.update("speakers", values, "id=?", arrayOf(speakerId.toString())) @@ -630,7 +581,7 @@ class FaceclawConversationStore private constructor(context: Context) : SQLiteOp try { while (c.moveToNext()) { val id = c.getLong(0) - val embedding = if (c.isNull(1)) null else blobToFloats(c.getBlob(1)) + val embedding = if (c.isNull(1)) null else SpeakerEmbeddings.blobToFloats(c.getBlob(1)) val count = c.getInt(2) if (id == fromId) { from = embedding @@ -644,21 +595,10 @@ class FaceclawConversationStore private constructor(context: Context) : SQLiteOp } finally { c.close() } - var merged: FloatArray? = into - if (from != null && into != null && from.size == into.size) { - val blended = FloatArray(into.size) - val total = Math.max(1, fromCount + intoCount) - for (i in blended.indices) { - blended[i] = (into[i] * intoCount + from[i] * fromCount) / total - } - l2NormalizeInPlace(blended) - merged = blended - } else if (into == null) { - merged = from - } + val merged = SpeakerEmbeddings.blend(from, fromCount, into, intoCount) val values = ContentValues() if (merged != null) { - values.put("embedding", floatsToBlob(merged)) + values.put("embedding", SpeakerEmbeddings.floatsToBlob(merged)) values.put("embedding_count", fromCount + intoCount) } if (fromWearer) { @@ -677,7 +617,7 @@ class FaceclawConversationStore private constructor(context: Context) : SQLiteOp val hasInsights = !c2.isNull(0) && !c2.getString(0).isEmpty() if (c2.position == 0) { targetHasInsights = hasInsights - } else if (!targetHasInsights && hasInsights) { + } else if (SpeakerEmbeddings.shouldAdoptInsights(targetHasInsights, hasInsights)) { values.put("last_recap", c2.getString(0)) values.put("action_items", if (c2.isNull(1)) "" else c2.getString(1)) values.put("facts", if (c2.isNull(2)) "" else c2.getString(2)) diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt index 9d734da2..5568a6ce 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDeviceInfoProbe.kt @@ -1,99 +1,44 @@ package com.faceclaw.app -import android.bluetooth.BluetoothDevice -import android.bluetooth.BluetoothGatt import android.content.Context import android.os.Handler import android.os.Looper -import android.os.SystemClock -import android.util.Log - -import java.util.HashSet -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit /** - * Connects to the glasses (stock-firmware compatible), reads the device-info / - * settings response, and reports the firmware versions plus the firmware- - * extension string (empty on stock firmware). Used by onboarding to decide whether to - * flash. Reuses FaceclawBleManager + BleProtocol; owns its own connection and - * runs on a single worker thread. Shows nothing on the lens. + * Android host for the shared [DeviceInfoProbeFlow]: owns the GATT link (AndroidStockLink), + * the worker thread the flow runs on, and delivers listener callbacks on the main thread. + * Public API unchanged for the TypeScript wrapper (app/native/device-info-probe.ts). */ -class FaceclawDeviceInfoProbe(context: Context, rightAddress: String?, leftAddress: String?) : FaceclawBleListener { - companion object { - private const val TAG = "FaceclawDeviceInfo" - private const val QUERY_TIMEOUT_MS = 4_000 - /** Connect + auth attempts per arm; a link that drops mid-pairing is retried once the bond settles. */ - private const val ARM_ATTEMPTS = 3 - private const val ARM_RETRY_DELAY_MS = 1_000 - /** - * Upper bound on waiting for the auth success while Android reports the arm - * as BOND_BONDING — i.e. an OS pairing dialog may be sitting there waiting - * for the user, which can take a lot longer than the normal 30 s window. - */ - private const val PAIRING_WAIT_CAP_MS = 90_000 - /** After a fresh bond, how long the firmware gets to notify success on its own before the request is re-sent. */ - private const val POST_BOND_GRACE_MS = 2_000 - private const val POLL_MS = 250 - - private fun bondStateName(state: Int): String { - return when (state) { - BluetoothDevice.BOND_NONE -> "none" - BluetoothDevice.BOND_BONDING -> "bonding" - BluetoothDevice.BOND_BONDED -> "bonded" - else -> "unknown" - } - } - } - - private val context: Context - private val rightAddress: String - private val leftAddress: String - private val bleManager: FaceclawBleManager +class FaceclawDeviceInfoProbe(context: Context, rightAddress: String?, leftAddress: String?) { + private val link = AndroidStockLink(context.applicationContext) private val mainHandler = Handler(Looper.getMainLooper()) - private val lock = Any() - private var nextSeq = 0x40 - private var nextMagic = 100 - - private var awaitSid = -1 - private var awaitMagic = -1 - private var awaitPb: ByteArray? = null - private var awaitLatch: CountDownLatch? = null - - /** - * Security-auth wait, kept separate from the generic ack wait: only the - * firmware's SUCCESS result (empty result message) may satisfy it. The - * firmware answers the request as soon as it arrives, but with a - * non-success result until the link is encrypted; accepting that first - * reply as "the ack" is what let the probe move on to the other arm while - * Android's pairing dialog for this one was still up. - */ - private val authMagics: MutableSet = HashSet() - private var authLatch: CountDownLatch? = null - - /** - * A sid-0x09 frame that carried firmware versions without matching the - * awaited magic — some firmware pushes the settings snapshot on a magic it - * picked itself instead of (or in addition to) acking the read. - */ - @Volatile - private var unsolicitedSettingsPb: ByteArray? = null @Volatile private var listener: FaceclawDeviceInfoProbeListener? = null + @Volatile private var worker: Thread? = null - @Volatile - private var cancelled = false - init { - this.context = context.applicationContext - this.rightAddress = rightAddress ?: "" - this.leftAddress = leftAddress ?: "" - this.bleManager = FaceclawBleManager(this.context) - this.bleManager.setListener(this) - } + private val flow = + DeviceInfoProbeFlow( + link, + rightAddress ?: "", + leftAddress ?: "", + object : FaceclawDeviceInfoProbeListener { + override fun onLog(line: String?) { + android.util.Log.i(DeviceInfoProbeFlow.TAG, line ?: "") + post { it.onLog(line) } + } + + override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") } + + override fun onResult(leftVersion: String?, rightVersion: String?, extension: String?) = + post { it.onResult(leftVersion, rightVersion, extension) } + + override fun onError(message: String?) = post { it.onError(message ?: "") } + }, + ) fun setListener(listener: FaceclawDeviceInfoProbeListener?) { this.listener = listener @@ -104,525 +49,29 @@ class FaceclawDeviceInfoProbe(context: Context, rightAddress: String?, leftAddre if (worker != null) { return } - val w = Thread({ run() }, "faceclaw-device-info") + val w = Thread({ flow.run() }, "faceclaw-device-info") worker = w w.start() } } fun cancel() { - cancelled = true - val w = worker - if (w != null) { - w.interrupt() - } + flow.cancel() } fun close() { cancel() try { - bleManager.close() + link.close() } catch (ignored: Exception) { } } - private fun run() { - try { - if (rightAddress.trim().isEmpty()) { - emitError("No right-arm address configured.") - return - } - - val haveLeft = !leftAddress.trim().isEmpty() && !leftAddress.equals(rightAddress, ignoreCase = true) - - // Bring up and authenticate BOTH arms before asking for versions. - // Each arm is its own peripheral with its own bond, so on a fresh - // phone each raises its own pairing prompt; completing both here - // means the flash step (and the app proper) find both bonds in - // place. Strictly one arm at a time: Android pairs with one device - // at a time, and a second arm connected while the first was still - // pairing has been seen to drop within a second and never pair - // (2026-09-11 logcat). - var rightAuthenticated = bringUpArm(rightAddress, "right") - var leftAuthenticated = false - if (haveLeft && !cancelled) { - leftAuthenticated = bringUpArm(leftAddress, "left") - } - if (cancelled) { - emitError("Cancelled.") - return - } - if (!bleManager.isConnected(rightAddress)) { - // The right lens may have dropped while the left one paired; - // it is bonded by now, so this comes back quickly. - emitLog("right lens disconnected while the left lens was set up; reconnecting") - rightAuthenticated = bringUpArm(rightAddress, "right") - if (cancelled) { - emitError("Cancelled.") - return - } - } - - var ack: ByteArray? = null - var rightFailure: String? = null - try { - ack = queryArm(rightAddress, "right", rightAuthenticated) - } catch (e: IllegalStateException) { - rightFailure = if (e.message == null) e.toString() else e.message - emitLog("right-lens query failed: $rightFailure") - } - // The right lens is the documented control endpoint, but a silent - // right lens has been observed on stock 2.2.9 even after a - // successful security auth — run the same probe against the left - // lens rather than giving up, and log which lens answered. - if (ack == null && !cancelled && haveLeft) { - emitLog("right lens did not answer the settings query; probing the left lens") - try { - ack = queryArm(leftAddress, "left", leftAuthenticated) - } catch (e: Exception) { - emitLog("left-lens probe failed: " + (if (e.message == null) e.toString() else e.message)) - } - } - if (cancelled) { - emitError("Cancelled.") - return - } - if (ack == null) { - throw IllegalStateException(if (rightFailure != null) - rightFailure - else "no response to the device-info query on either lens — check `adb logcat -s " - + TAG + "` for the frame trace") - } - - val info: BleProtocol.FirmwareInfo? = BleProtocol.parseSettingsFirmwareInfo(ack) - val left = if (info == null) "" else info.leftVersion - val right = if (info == null) "" else info.rightVersion - val extension = if (info == null) "" else info.extension - emitLog("device-info: L=$left R=$right ext=[$extension]") - emitResult(left, right, extension) - } catch (e: Exception) { - val message = if (cancelled) "Cancelled." else (if (e.message == null) e.toString() else e.message) - emitError(message) - } finally { - try { - bleManager.close() - } catch (ignored: Exception) { - } - } - } - - /** - * Connect to one arm and complete its security-auth exchange, retrying - * when the link drops mid-pairing. Returns whether the auth success was - * seen (false = connected but unconfirmed, tolerated because the custom - * firmware's response to the exchange is not yet hardware-verified); - * throws when the arm cannot be brought up at all. - */ - @Throws(InterruptedException::class) - private fun bringUpArm(address: String, label: String): Boolean { - var lastFailure: String? = null - var attempt = 1 - while (attempt <= ARM_ATTEMPTS && !cancelled) { - if (attempt > 1) { - // A link Android dropped while it was still pairing comes back - // once the bond settles; reconnecting sooner just fails again. - waitForBondToSettle(address, label) - if (cancelled) { - break - } - emitLog("retrying the $label lens (attempt $attempt/$ARM_ATTEMPTS): $lastFailure") - Thread.sleep(ARM_RETRY_DELAY_MS.toLong()) - } - emitState("connecting", label) - try { - connectArm(address) - } catch (e: IllegalStateException) { - lastFailure = if (e.message == null) e.toString() else e.message - emitLog("$label lens: $lastFailure") - attempt++ - continue - } - if (cancelled) { - break - } - - // Firmware 2.2.9 answers no queries until the security-auth - // exchange completes over an encrypted link; on a phone with no - // existing bond this is also what triggers SMP pairing (and its OS - // prompt), so it must come before the prelude and query. - emitState("authenticating", label) - val result = authenticate(address, label) - if (result == AuthResult.SUCCESS) { - return true - } - if (result == AuthResult.UNCONFIRMED) { - return false - } - lastFailure = "link dropped during authentication" - attempt++ - } - if (cancelled) { - return false - } - throw IllegalStateException("could not connect to the $label lens ($address): " - + lastFailure + " — if Android showed a Bluetooth pairing request, accept it and try again") - } - - private enum class AuthResult { SUCCESS, UNCONFIRMED, LINK_DROPPED } - - /** - * Send the sid-0x80 authentication request and wait for the firmware's - * SUCCESS notification, which only arrives once the link is encrypted. - * On an unbonded phone that means waiting through Android's pairing flow - * (BOND_BONDING, possibly with a dialog up), so the wait is extended while - * the OS reports pairing in progress and the request is re-sent once - * after a fresh bond in case the pre-pairing write was dropped. Bond - * state is polled rather than awaited via broadcast; 250 ms granularity - * is plenty here. - */ - @Throws(InterruptedException::class) - private fun authenticate(address: String, label: String): AuthResult { - val start = SystemClock.elapsedRealtime() - var deadline = start + ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS - val hardDeadline = start + PAIRING_WAIT_CAP_MS - val latch = CountDownLatch(1) - synchronized(lock) { - authMagics.clear() - authLatch = latch - } - val initialBond = bleManager.getBondState(address) - emitLog("security auth: $label lens, Android bond state " + bondStateName(initialBond)) - try { - var sends = 0 - var lastSendFailed = false - var nextSendAt = start - var bondedAt = -1L - var resentAfterBond = false - var loggedBonding = false - while (!cancelled) { - val now = SystemClock.elapsedRealtime() - val bond = bleManager.getBondState(address) - - if (bond == BluetoothDevice.BOND_BONDING) { - // OS pairing in progress — the firmware will answer once the - // link is encrypted. Don't write, don't give up, don't move - // on to the other arm. - if (!loggedBonding) { - emitLog("Android is pairing with the $label lens; waiting for the user to accept") - loggedBonding = true - } - if (now >= hardDeadline) { - break - } - } else { - if (bond == BluetoothDevice.BOND_BONDED && initialBond != BluetoothDevice.BOND_BONDED - && bondedAt < 0) { - bondedAt = now - emitLog("Android bond established with the $label lens; waiting for the auth success") - deadline = Math.max(deadline, now + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS) - } - val wantSend = sends == 0 - || (lastSendFailed && sends < 3 && now >= nextSendAt) - || (bondedAt >= 0 && !resentAfterBond && now - bondedAt >= POST_BOND_GRACE_MS) - if (wantSend) { - if (bondedAt >= 0) { - resentAfterBond = true - if (sends > 0) { - emitLog("re-sending the auth request after pairing ($label lens)") - } - } - lastSendFailed = !sendAuthRequest(address) - sends++ - nextSendAt = SystemClock.elapsedRealtime() + ARM_RETRY_DELAY_MS - if (lastSendFailed && !bleManager.isConnected(address)) { - return AuthResult.LINK_DROPPED - } - } - if (now >= deadline) { - break - } - } - - if (latch.await(POLL_MS.toLong(), TimeUnit.MILLISECONDS)) { - emitLog("security auth complete: $label lens ($address)") - return AuthResult.SUCCESS - } - if (!bleManager.isConnected(address)) { - emitLog("security auth: $label lens disconnected while waiting" - + (if (bond == BluetoothDevice.BOND_BONDING) " (Android was still pairing)" else "")) - return AuthResult.LINK_DROPPED - } - } - if (cancelled) { - return AuthResult.UNCONFIRMED - } - emitLog("security auth unconfirmed: $label lens ($address), Android bond state " - + bondStateName(bleManager.getBondState(address))) - return AuthResult.UNCONFIRMED - } finally { - synchronized(lock) { - authLatch = null - authMagics.clear() - } - } - } - - private fun sendAuthRequest(address: String): Boolean { - val magic = allocMagic() - val seq: Int - synchronized(lock) { - authMagics.add(magic) - seq = nextSeq++ and 0xff - } - val payload = BleProtocol.buildAuthenticationRequest(magic) - emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d", - address, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, magic, seq, payload.size)) - val frames = BleProtocol.framePb(payload, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, seq) - var written: Boolean - try { - written = bleManager.writeFrames( - address, BleProtocol.WRITE_CHAR_UUID, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS) - } catch (e: IllegalStateException) { - // "Not connected" — the link went away underneath us. - written = false - } - if (!written) { - emitLog("tx write FAILED sid=0x80 ($address)") - } - return written - } - - /** Block while Android reports this arm as BOND_BONDING (pairing dialog up / SMP in flight). */ - @Throws(InterruptedException::class) - private fun waitForBondToSettle(address: String, label: String) { - val cap = SystemClock.elapsedRealtime() + PAIRING_WAIT_CAP_MS - var logged = false - while (!cancelled && bleManager.getBondState(address) == BluetoothDevice.BOND_BONDING - && SystemClock.elapsedRealtime() < cap) { - if (!logged) { - emitLog("waiting for Android to finish pairing with the $label lens before reconnecting") - logged = true - } - Thread.sleep(POLL_MS.toLong()) - } - } - - /** - * Prelude + settings read on an already connected/authenticated lens. - * Returns the settings ack protobuf, an unsolicited settings push that - * carried firmware versions, or null when the lens never answered the read. - * Throws on prelude failure; the caller wraps the fallback lens's attempt - * so its failure cannot mask the primary lens's outcome. - */ - @Throws(InterruptedException::class) - private fun queryArm(address: String, label: String, authenticated: Boolean): ByteArray? { - if (cancelled) { - return null - } - - emitState("querying", label) - // Session prelude, then a settings/device-info read (both arms' - // versions and the firmware-extension string ride back in one response). - if (writeAndAwaitAck(address, BleProtocol.PRELUDE_ACK_SID, BleProtocol.FLAG_REQUEST, - BleProtocol.PRELUDE_ACK_MAGIC, BleProtocol.PRELUDE_F5872_PAYLOAD, - ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) { - throw IllegalStateException("session prelude not acked ($label lens)" - + (if (authenticated) "" else "; authentication did not complete —" - + " if Android shows a Bluetooth pairing request, accept it and try again")) - } - - // Two attempts: the first read straight after a fresh pairing has been - // seen to go unanswered while a later one succeeds. - var attempt = 0 - while (attempt < 2 && !cancelled) { - val magic = allocMagic() - val ack = writeAndAwaitAck(address, BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST, - magic, BleProtocol.buildSettingsQuery(magic), QUERY_TIMEOUT_MS) - if (ack != null) { - return ack - } - // A push with the firmware versions on the device's own magic is - // as good as the ack we asked for. - val pushed = unsolicitedSettingsPb - if (pushed != null) { - emitLog("using unsolicited settings push instead of the read ack ($label lens)") - return pushed - } - emitLog("settings query attempt " + (attempt + 1) + " unanswered (" + label + " lens)") - attempt++ - } - return null - } - - private fun connectArm(address: String) { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw IllegalStateException("connect failed") - } - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw IllegalStateException("service discovery failed") - } - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - throw IllegalStateException("could not subscribe to notifications") - } - } - - @Throws(InterruptedException::class) - private fun writeAndAwaitAck(address: String, sid: Int, flag: Int, magic: Int, payload: ByteArray, timeoutMs: Int): ByteArray? { - val latch = CountDownLatch(1) - synchronized(lock) { - awaitSid = sid - awaitMagic = magic - awaitPb = null - awaitLatch = latch - } - val seq: Int - synchronized(lock) { - seq = nextSeq++ and 0xff - } - emitLog(String.format("tx %s sid=0x%02x flag=0x%02x magic=%d seq=0x%02x len=%d", - address, sid, flag, magic, seq, payload.size)) - val frames = BleProtocol.framePb(payload, sid, flag, seq) - val written = bleManager.writeFrames( - address, BleProtocol.WRITE_CHAR_UUID, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS) - if (!written) { - emitLog("tx write FAILED sid=0x" + Integer.toHexString(sid)) - synchronized(lock) { - awaitLatch = null - } - return null - } - val acked = latch.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS) - synchronized(lock) { - awaitLatch = null - return if (acked) awaitPb else null - } - } - - override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { - if (!BleProtocol.NOTIFY_CHAR_UUID.equals(characteristicUuid, ignoreCase = true)) { - return - } - // One notification value can carry several envelope frames back to - // back; reading only the first would silently drop the rest. - val frames = BleProtocol.splitFrames(data) - if (frames.size > 1) { - emitLog("rx " + address + " value carries " + frames.size + " frames (raw " + data!!.size + " bytes)") - } - for (buf in frames) { - handleFrame(address, buf, data!!.size) - } - } - - private fun handleFrame(address: String?, buf: ByteArray, rawValueLength: Int) { - val frame = BleProtocol.parseFrame(buf) - if (!frame.ok) { - emitLog("rx " + address + " unparseable frame len=" + buf.size + " (raw value " + rawValueLength + ")" - + " head=" + FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(buf, Math.min(16, buf.size)))) - return - } - // Log every control frame while diagnosing 2.2.9: sid/flag/type/magic - // plus a payload prefix is enough to reconstruct what the lens said. - val declared = if (buf.size > 3) buf[3].toInt() and 0xff else 0 - val truncated = if (buf.size < 8 + declared) " TRUNCATED(declared=$declared)" else "" - emitLog(String.format("rx %s sid=0x%02x flag=0x%02x type=%d magic=%d frag=%d/%d len=%d%s pb=%s", - address, frame.sid, frame.flag, frame.msgType, frame.msgSeq, - if (buf.size > 5) buf[5].toInt() and 0xff else 0, if (buf.size > 4) buf[4].toInt() and 0xff else 0, frame.pb.size, truncated, - FaceclawFirmwareUtil.bytesToHex(java.util.Arrays.copyOf(frame.pb, Math.min(48, frame.pb.size))))) - if (frame.sid == BleProtocol.SID_UI_SETTING - && BleProtocol.parseSettingsFirmwareInfo(frame.pb) != null) { - // Any settings frame carrying firmware versions answers the probe's - // question, whether or not it matches the magic we asked with. - unsolicitedSettingsPb = frame.pb - } - if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { - // Async event, not an ack. This includes the lens's own periodic - // sid-0x80 notifies (device-chosen magic, non-empty result). - return - } - if (frame.sid == BleProtocol.SID_SECURITY_AUTH) { - var success = false - var ours = false - synchronized(lock) { - val currentLatch = authLatch - if (currentLatch != null) { - ours = authMagics.contains(frame.msgSeq) - for (magic in authMagics) { - if (BleProtocol.isAuthenticationSuccess(frame.pb, magic)) { - success = true - currentLatch.countDown() - break - } - } - } - } - if (ours && !success) { - // Expected before the link is encrypted: the firmware answers - // the request straight away with a non-success result and - // sends the real success once pairing/encryption completes. - emitLog("auth reply for magic " + frame.msgSeq + " is not the success result; still waiting") - } - return - } - synchronized(lock) { - val currentLatch = awaitLatch - if (currentLatch != null && frame.sid == awaitSid && frame.msgSeq == awaitMagic) { - awaitPb = frame.pb - currentLatch.countDown() - } - } - } - - override fun onConnectionStateChange(address: String?, connected: Boolean) { - if (!connected) { - Log.i(TAG, "disconnected: $address") - } - } - - private fun allocMagic(): Int { - synchronized(lock) { - val magic = nextMagic - nextMagic = if (nextMagic >= 255) 100 else nextMagic + 1 - return magic - } - } - - private fun emitLog(line: String) { - Log.i(TAG, line) + private fun post(action: (FaceclawDeviceInfoProbeListener) -> Unit) { mainHandler.post { val current = listener if (current != null) { - current.onLog(line) - } - } - } - - private fun emitState(state: String, detail: String?) { - val safeDetail = detail ?: "" - mainHandler.post { - val current = listener - if (current != null) { - current.onState(state, safeDetail) - } - } - } - - private fun emitResult(left: String, right: String, extension: String) { - mainHandler.post { - val current = listener - if (current != null) { - current.onResult(left, right, extension) - } - } - } - - private fun emitError(message: String?) { - val safeMessage = message ?: "" - mainHandler.post { - val current = listener - if (current != null) { - current.onError(safeMessage) + action(current) } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt index 95cd7e98..86c911d6 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawDiarizer.kt @@ -129,17 +129,19 @@ class FaceclawDiarizer( val file = File(path) val fileLength = file.length() DataInputStream(FileInputStream(file)).use { `in` -> - val header = ByteArray(44) - `in`.readFully(header) - if (header[0] != 'R'.code.toByte() || header[1] != 'I'.code.toByte() || header[8] != 'W'.code.toByte()) { - throw IOException("not a WAV file") + // Shared RIFF walk (handles extra chunks and unpatched data sizes); the + // stream is then positioned at the first PCM sample. + val prefix = ByteArray(Math.min(fileLength, WavPcmReader.HEADER_PREFIX_BYTES.toLong()).toInt()) + `in`.readFully(prefix) + val info = try { + WavPcmReader.parseHeader(prefix, fileLength) + } catch (e: IllegalArgumentException) { + throw IOException(e.message ?: "not a WAV file") } - val channels = (header[22].toInt() and 0xff) or (header[23].toInt() shl 8) - val bits = (header[34].toInt() and 0xff) or (header[35].toInt() shl 8) - if (channels != 1 || bits != 16) { + if (info.channels != 1) { throw IOException("only 16-bit mono WAV is supported") } - val dataBytes = fileLength - 44 + val dataBytes = info.dataBytes val count = Math.min(dataBytes / 2, Int.MAX_VALUE.toLong()).toInt() val samples = FloatArray(count) val chunk = ByteArray(65536) @@ -147,6 +149,21 @@ class FaceclawDiarizer( var carried = 0 var carriedByte: Byte = 0 var read = 0 + // The prefix already holds the start of the PCM data; consume it first. + val prefixData = prefix.size - info.dataOffset.toInt() + if (prefixData > 0) { + val pairs = prefixData / 2 + var i = 0 + while (i < pairs && sampleIndex < count) { + val base = info.dataOffset.toInt() + i * 2 + samples[sampleIndex++] = AudioSegmentation.pcm16le(prefix[base], prefix[base + 1]) / 32768.0f + i++ + } + if ((prefixData and 1) == 1) { + carried = 1 + carriedByte = prefix[prefix.size - 1] + } + } while (sampleIndex < count && `in`.read(chunk).also { read = it } > 0) { var offset = 0 if (carried == 1) { diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt index bec2b8a3..af821b0b 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewClient.kt @@ -15,7 +15,6 @@ import java.io.FileInputStream import java.io.IOException import java.io.InputStream import java.nio.charset.StandardCharsets -import java.util.Locale /** * Serves an unpacked EvenHub app's files to its WebView from a fake per-app @@ -52,25 +51,25 @@ class FaceclawEvenHubWebViewClient( if (url == null || host != url.host) { return null // External hosts: normal network handling. } - var path = url.path - if (path == null || path.isEmpty() || path == "/") { - path = "/index.html" - } + val path = url.path try { + // Path rules, MIME table and shim injection are shared (EvenHubAssetServer); + // the canonical-file check below additionally defeats symlinks. + val asset = EvenHubAssetServer.resolve(path) val root = File(rootDir).canonicalFile - val target = File(root, path.substring(1)).canonicalFile - if (!target.path.startsWith(root.path) || !target.isFile) { + val target = asset?.let { File(root, it.relativePath).canonicalFile } + if (asset == null || target == null || !EvenHubAssetServer.isInsideRoot(root.path, target.path) || !target.isFile) { Log.w(TAG, "404 $path") return WebResourceResponse( "text/plain", "utf-8", ByteArrayInputStream("not found".toByteArray(StandardCharsets.UTF_8))) } - val mime = mimeTypeFor(target.name) - if (mime == "text/html") { - return WebResourceResponse(mime, "utf-8", ByteArrayInputStream(injectIntoHtml(target))) + if (asset.isHtml) { + val html = EvenHubAssetServer.injectIntoHtml(String(readAll(target), StandardCharsets.UTF_8), injectScript) + return WebResourceResponse(asset.mime, "utf-8", ByteArrayInputStream(html.toByteArray(StandardCharsets.UTF_8))) } val stream: InputStream = FileInputStream(target) - return WebResourceResponse(mime, null, stream) + return WebResourceResponse(asset.mime, null, stream) } catch (e: IOException) { Log.e(TAG, "serve failed for $path", e) return WebResourceResponse( @@ -94,30 +93,9 @@ class FaceclawEvenHubWebViewClient( } } - @Throws(IOException::class) - private fun injectIntoHtml(file: File): ByteArray { - val raw = readAll(file) - val html = String(raw, StandardCharsets.UTF_8) - val tag = "" - // After if present, else before everything. - val headIndex = indexOfIgnoreCase(html, "= 0) { - val close = html.indexOf('>', headIndex) - if (close >= 0) { - return (html.substring(0, close + 1) + tag + html.substring(close + 1)) - .toByteArray(StandardCharsets.UTF_8) - } - } - return (tag + html).toByteArray(StandardCharsets.UTF_8) - } - companion object { private const val TAG = "FaceclawEvenHub" - private fun indexOfIgnoreCase(haystack: String, needle: String): Int { - return haystack.lowercase(Locale.ROOT).indexOf(needle) - } - @Throws(IOException::class) private fun readAll(file: File): ByteArray { val input = FileInputStream(file) @@ -134,25 +112,5 @@ class FaceclawEvenHubWebViewClient( input.close() } } - - private fun mimeTypeFor(name: String): String { - val lower = name.lowercase(Locale.ROOT) - if (lower.endsWith(".html") || lower.endsWith(".htm")) return "text/html" - if (lower.endsWith(".js") || lower.endsWith(".mjs")) return "application/javascript" - if (lower.endsWith(".css")) return "text/css" - if (lower.endsWith(".json")) return "application/json" - if (lower.endsWith(".png")) return "image/png" - if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "image/jpeg" - if (lower.endsWith(".gif")) return "image/gif" - if (lower.endsWith(".svg")) return "image/svg+xml" - if (lower.endsWith(".webp")) return "image/webp" - if (lower.endsWith(".ico")) return "image/x-icon" - if (lower.endsWith(".wasm")) return "application/wasm" - if (lower.endsWith(".woff")) return "font/woff" - if (lower.endsWith(".woff2")) return "font/woff2" - if (lower.endsWith(".ttf")) return "font/ttf" - if (lower.endsWith(".txt") || lower.endsWith(".map")) return "text/plain" - return "application/octet-stream" - } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt index 714b3377..6169c965 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFirmwareFlasher.kt @@ -1,185 +1,54 @@ package com.faceclaw.app -import android.bluetooth.BluetoothGatt import android.content.Context import android.os.Handler import android.os.Looper -import android.os.SystemClock -import android.util.Log - -import java.io.ByteArrayOutputStream -import java.io.FileInputStream -import java.io.IOException -import java.nio.charset.StandardCharsets -import java.util.ArrayList -import java.util.Arrays -import java.util.concurrent.CountDownLatch -import java.util.concurrent.LinkedBlockingQueue -import java.util.concurrent.TimeUnit -import java.util.concurrent.TimeoutException /** - * Ports g2flash.py's OTA flash procedure to Android. Streams the EVENOTA - * firmware container to each lens over the firmware-data service using the - * aa21 envelope (BleProtocol.framePb) and the c0/c1 control/data protocol. - * - * Each lens connection completes the sid-0x80 security-auth exchange before - * OTA BEGIN — firmware 2.2.9 closes unauthenticated links ~30 s in, killing - * the transfer mid-component. No control-channel traffic is injected during - * the transfer itself: official OTA captures show none between BEGIN and the - * final END, heartbeats demonstrably do not satisfy the 2.2.9 deadline, and a - * concurrent control writer would interleave with the marker/data - * transactions. (See ../notes/ble-connections-2.2.9.md.) - * - * Lenses are flashed one at a time (left, then right). Finishing either lens - * reboots BOTH lenses, so the second lens is briefly unreachable — the reconnect - * for it uses a generous window rather than failing fast. - * - * Separate from FaceclawBleCommunicator on purpose: this speaks the stock OTA - * protocol and must run before the custom firmware exists. It reuses the GATT - * wrapper (FaceclawBleManager) and framing (BleProtocol). + * Android host for the shared [OtaFlashFlow] (g2flash.py's OTA procedure over the stock + * firmware-data service): owns the GATT link (AndroidStockLink) and the worker thread, and + * delivers listener callbacks on the main thread. Separate from FaceclawBleCommunicator on + * purpose: this speaks the stock OTA protocol and must run before the custom firmware exists. + * Public API unchanged for app/native/firmware-flasher.ts. */ -class FaceclawFirmwareFlasher(context: Context, rightAddress: String?, leftAddress: String?, firmwarePath: String?) : FaceclawBleListener { - companion object { - private const val TAG = "FaceclawFlasher" - - // OTA message types (envelope sid byte) and control opcodes. - private const val SID_CTRL = 0xc0 - private const val SID_DATA = 0xc1 - private const val FLAG_OTA = 0x00 - private const val OP_BEGIN = 0x00 - private const val OP_FILE_CHECK = 0x01 - private const val OP_BLOCK = 0x02 - private const val OP_END = 0x03 - - private const val BLOCK_SIZE = 4096 - private const val BLOCK_ACK_TIMEOUT_MS = 4_000 - private const val CTRL_ACK_TIMEOUT_MS = 8_000 - private const val BLOCK_NAK_RETRIES = 3 - private const val COMPONENT_RETRIES = 3 - - // Reconnect windows. The first lens connects from an idle device; the second - // must ride out the post-first-lens reboot of both lenses. - private const val FIRST_LENS_CONNECT_WINDOW_MS = 30_000 - private const val SECOND_LENS_CONNECT_WINDOW_MS = 120_000 - private const val REBOOT_SETTLE_MS = 5_000 - private const val NOTIFY_SETTLE_MS = 2_500 - private const val RETRY_DELAY_MS = 2_500 - - // END ack statuses that mean "component accepted": SUCCESS, UPDATING, SYS_RESTART. - private val END_OK = intArrayOf(0, 8, 9) - - // Firmware layout expectations (mirrors g2flash.py). Firmware 2.2.4 has 5 - // components; 2.2.6 has 6. - private const val MIN_SEGMENTS = 5 - private const val MAX_SEGMENTS = 6 - private const val REQUIRED_SEGMENT = "ota/s200_firmware_ota.bin" - private const val APP_LOAD_ADDR = 0x00438000L - private const val APP_MAX_END = 0x007F0000L - private const val APP_PREAMBLE = 0x20 - - // ---- firmware container parsing / validation ----------------------------- - - private val EMPTY = ByteArray(0) - - // ---- helpers ------------------------------------------------------------- - - private fun isEndOk(status: Int): Boolean { - for (ok in END_OK) { - if (ok == status) { - return true - } - } - return false - } - - private fun readFile(path: String): ByteArray { - try { - FileInputStream(path).use { fis -> - val out = ByteArrayOutputStream() - val buf = ByteArray(65536) - var read: Int - while (fis.read(buf).also { read = it } >= 0) { - out.write(buf, 0, read) - } - return out.toByteArray() - } - } catch (e: IOException) { - throw IllegalStateException("could not read firmware: " + e.message, e) - } - } - - private fun readU32(buf: ByteArray, offset: Int): Long { - return (buf[offset].toLong() and 0xffL) or - ((buf[offset + 1].toLong() and 0xffL) shl 8) or - ((buf[offset + 2].toLong() and 0xffL) shl 16) or - ((buf[offset + 3].toLong() and 0xffL) shl 24) - } - - private fun readCString(buf: ByteArray, offset: Int, maxLen: Int): String { - var end = offset - val limit = Math.min(buf.size, offset + maxLen) - while (end < limit && buf[end].toInt() != 0) { - end++ - } - return String(buf, offset, end - offset, StandardCharsets.ISO_8859_1) - } - - private val CRC32C_TABLE: IntArray = buildCrc32cTable() - - private fun buildCrc32cTable(): IntArray { - val table = IntArray(256) - for (b in 0 until 256) { - var c = b shl 24 - for (i in 0 until 8) { - c = if ((c and 0x80000000.toInt()) != 0) (c shl 1) xor 0x1edc6f41 else c shl 1 - } - table[b] = c - } - return table - } - - /** CRC-32C, MSB-first, init 0, no final xor (matches g2flash.py crc32c_msb). */ - private fun crc32cMsb(data: ByteArray): Int { - var crc = 0 - for (value in data) { - crc = (crc shl 8) xor CRC32C_TABLE[((crc ushr 24) xor (value.toInt() and 0xff)) and 0xff] - } - return crc - } - } - - private val context: Context - private val leftAddress: String - private val rightAddress: String - private val firmwarePath: String - private val bleManager: FaceclawBleManager +class FaceclawFirmwareFlasher(context: Context, rightAddress: String?, leftAddress: String?, firmwarePath: String?) { + private val link = AndroidStockLink(context.applicationContext) private val mainHandler = Handler(Looper.getMainLooper()) - private val lock = Any() - private val dataAcks = LinkedBlockingQueue() @Volatile private var listener: FaceclawFirmwareFlasherListener? = null + @Volatile private var worker: Thread? = null - @Volatile - private var cancelled = false - private var nextSeq = 0 - private var nextAuthMagic = 0x60 - private var pendingAuthMagic = -1 - private var authLatch: CountDownLatch? = null - private var authAckPb: ByteArray? = null + private val flow = + OtaFlashFlow( + link, + rightAddress ?: "", + leftAddress ?: "", + firmwarePath ?: "", + object : FaceclawFirmwareFlasherListener { + override fun onLog(line: String?) { + android.util.Log.i(OtaFlashFlow.TAG, line ?: "") + post { it.onLog(line) } + } - init { - this.context = context.applicationContext - this.rightAddress = rightAddress ?: "" - this.leftAddress = leftAddress ?: "" - this.firmwarePath = firmwarePath ?: "" - this.bleManager = FaceclawBleManager(this.context) - this.bleManager.setListener(this) - } + override fun onProgress( + lens: String?, + componentIndex: Int, + componentCount: Int, + blockIndex: Int, + blockCount: Int, + bytesSent: Long, + bytesTotal: Long, + ) = post { it.onProgress(lens, componentIndex, componentCount, blockIndex, blockCount, bytesSent, bytesTotal) } + + override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") } + + override fun onComplete(success: Boolean, detail: String?) = post { it.onComplete(success, detail ?: "") } + }, + ) fun setListener(listener: FaceclawFirmwareFlasherListener?) { this.listener = listener @@ -190,517 +59,29 @@ class FaceclawFirmwareFlasher(context: Context, rightAddress: String?, leftAddre if (worker != null) { return } - val w = Thread({ run() }, "faceclaw-flasher") + val w = Thread({ flow.run() }, "faceclaw-flasher") worker = w w.start() } } fun cancel() { - cancelled = true - val w = worker - if (w != null) { - w.interrupt() - } + flow.cancel() } fun close() { cancel() try { - bleManager.close() + link.close() } catch (ignored: Exception) { } } - private fun run() { - try { - if (leftAddress.trim().isEmpty() || rightAddress.trim().isEmpty()) { - throw IllegalStateException("Both lens addresses are required to flash.") - } - - emitState("validating", "") - val img = readFile(firmwarePath) - val segs = validate(img) - emitLog("firmware validated: " + segs.size + " components, " + img.size + " bytes") - - flashLens("left", leftAddress, img, segs, FIRST_LENS_CONNECT_WINDOW_MS) - if (cancelled) { - emitState("error", "Cancelled.") - emitComplete(false, "Cancelled after the left lens.") - return - } - - emitState("rebooting", "Left lens done. Both lenses reboot briefly; reconnecting for the right lens.") - sleepInterruptibly(REBOOT_SETTLE_MS) - flashLens("right", rightAddress, img, segs, SECOND_LENS_CONNECT_WINDOW_MS) - - emitState("done", "") - emitComplete(true, "Both lenses flashed. The glasses are rebooting into the custom firmware.") - } catch (e: Exception) { - var message = if (e.message == null) e.toString() else e.message - if (cancelled) { - message = "Cancelled." - } - emitState("error", message) - emitComplete(false, message) - } finally { - teardown() - } - } - - @Throws(TimeoutException::class) - private fun flashLens(lens: String, address: String, img: ByteArray, segs: List, connectWindowMs: Int) { - emitState("connecting", lens) - connectLensResilient(lens, address, connectWindowMs) - sleepInterruptibly(NOTIFY_SETTLE_MS) - drainAcks() - // Fresh envelope counter for the OTA stream (the auth exchange during - // bring-up used its own); mirrors the stock sequence. - resetSeq() - - emitState("flashing", lens) - val beginStatus = sendCtrlAndWait(address, OP_BEGIN, EMPTY, CTRL_ACK_TIMEOUT_MS) - if (!isEndOk(beginStatus)) { - emitLog("warning: unexpected begin status $beginStatus; continuing") - } - // Progress is reported in bytes across the whole image: the segments - // are one large firmware blob plus several small ones, so a bar - // stepped per segment would sit still through the big one and then - // sprint through the rest. - var totalBytes = 0L - for (seg in segs) { - totalBytes += seg.ps - } - var bytesBefore = 0L - for (i in segs.indices) { - if (cancelled) { - throw IllegalStateException("Cancelled.") - } - flashComponentWithRetry(lens, address, i, segs.size, segs[i], img, bytesBefore, totalBytes) - bytesBefore += segs[i].ps - } - emitLog("$lens lens: all components verified") - try { - bleManager.disconnect(address) - } catch (ignored: Exception) { - } - } - - private fun flashComponentWithRetry(lens: String, address: String, index: Int, count: Int, seg: Segment, img: ByteArray, - bytesBefore: Long, totalBytes: Long) { - for (attempt in 0 until COMPONENT_RETRIES) { - if (attempt > 0) { - emitLog(seg.name + ": re-flash attempt " + (attempt + 1) + "/" + COMPONENT_RETRIES) - } - var endStatus: Int - try { - endStatus = flashComponent(lens, address, index, count, seg, img, bytesBefore, totalBytes) - } catch (e: TimeoutException) { - emitLog(seg.name + ": block phase failed: " + e.message) - endStatus = -1 - } catch (e: RuntimeException) { - emitLog(seg.name + ": block phase failed: " + e.message) - endStatus = -1 - } - if (isEndOk(endStatus)) { - emitLog(seg.name + ": END verify OK (status " + endStatus + ")") - return - } - if (endStatus >= 0) { - emitLog(seg.name + ": END verify FAILED (status " + endStatus + ")") - } - drainAcks() - sleepInterruptibly(1_500) - } - throw IllegalStateException("component " + seg.name + " failed after " + COMPONENT_RETRIES + " attempts") - } - - @Throws(TimeoutException::class) - private fun flashComponent(lens: String, address: String, index: Int, count: Int, seg: Segment, img: ByteArray, - bytesBefore: Long, totalBytes: Long): Int { - val sub = Arrays.copyOfRange(img, seg.off, seg.off + 128) - val ps = seg.ps - val payloadStart = seg.off + 128 - - val checkStatus = sendCtrlAndWait(address, OP_FILE_CHECK, sub, CTRL_ACK_TIMEOUT_MS) - if (checkStatus != 0) { - throw IllegalStateException("FILE_CHECK rejected status=$checkStatus") - } - - val blockCount = (ps + BLOCK_SIZE - 1) / BLOCK_SIZE - for (b in 0 until blockCount) { - if (cancelled) { - throw IllegalStateException("Cancelled.") - } - val start = payloadStart + b * BLOCK_SIZE - val end = Math.min(start + BLOCK_SIZE, payloadStart + ps) - val block = Arrays.copyOfRange(img, start, end) - - var accepted = false - for (tries in 0 until BLOCK_NAK_RETRIES) { - val status = sendBlock(address, block) // throws TimeoutException -> component re-flash - if (status == 0) { - accepted = true - break - } - emitLog(seg.name + ": block " + b + "/" + blockCount + " NAK=" + status - + " resend " + (tries + 1) + "/" + BLOCK_NAK_RETRIES) - } - if (!accepted) { - throw IllegalStateException("block " + b + " NAK'd " + BLOCK_NAK_RETRIES + " times") - } - if (b % 20 == 0 || b == blockCount - 1) { - val bytesSent = bytesBefore + Math.min((b + 1).toLong() * BLOCK_SIZE, ps.toLong()) - emitProgress(lens, index + 1, count, b + 1, blockCount, bytesSent, totalBytes) - } - } - emitLog(seg.name + ": data phase done; sending END") - return sendCtrlAndWait(address, OP_END, EMPTY, CTRL_ACK_TIMEOUT_MS) - } - - /** Send one 4 KB block as a marker + data pair sharing one envelope seq. */ - @Throws(TimeoutException::class) - private fun sendBlock(address: String, block: ByteArray): Int { - val seq = nextSeq() - drainAcks() - writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_CTRL, byteArrayOf(OP_BLOCK.toByte()), seq) - writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_DATA, block, seq) - return waitAck(OP_BLOCK, BLOCK_ACK_TIMEOUT_MS) - } - - @Throws(TimeoutException::class) - private fun sendCtrlAndWait(address: String, op: Int, data: ByteArray, timeoutMs: Int): Int { - val seq = nextSeq() - drainAcks() - val payload = ByteArray(1 + data.size) - payload[0] = op.toByte() - System.arraycopy(data, 0, payload, 1, data.size) - writeOta(address, BleProtocol.OTA_DATA_WRITE_UUID, SID_CTRL, payload, seq) - return waitAck(op, timeoutMs) - } - - private fun writeOta(address: String, writeChar: String, sid: Int, payload: ByteArray, seq: Int): Boolean { - val frames = BleProtocol.framePb(payload, sid, FLAG_OTA, seq) - return bleManager.writeFrames( - address, writeChar, frames, AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), ConnectionOptions.WRITE_TIMEOUT_MS) - } - - @Throws(TimeoutException::class) - private fun waitAck(wantOp: Int, timeoutMs: Int): Int { - val deadline = SystemClock.elapsedRealtime() + timeoutMs - while (true) { - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - break - } - val pb: ByteArray? - try { - pb = dataAcks.poll(remaining, TimeUnit.MILLISECONDS) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - throw TimeoutException("interrupted waiting for ack op=$wantOp") - } - if (pb == null) { - break - } - if (pb.size >= 2 && (pb[0].toInt() and 0xff) == wantOp) { - return pb[1].toInt() and 0xff - } - // Different opcode (e.g. a late ack from a prior stage) — ignore, keep waiting. - } - throw TimeoutException("no ack op=0x" + Integer.toHexString(wantOp) + " within " + timeoutMs + "ms") - } - - // ---- connection ---------------------------------------------------------- - - private fun connectLensResilient(lens: String, address: String, windowMs: Int) { - val deadline = SystemClock.elapsedRealtime() + windowMs - var lastError: String? = "unknown" - var attempt = 0 - while (SystemClock.elapsedRealtime() < deadline && !cancelled) { - attempt++ - try { - if (bringUpLens(address)) { - emitLog("connected $lens lens (attempt $attempt)") - return - } - lastError = "connect/discover incomplete" - } catch (e: Exception) { - lastError = if (e.message == null) e.toString() else e.message - } - emitLog("$lens connect attempt $attempt failed ($lastError); retrying...") - try { - bleManager.disconnect(address) - } catch (ignored: Exception) { - } - sleepInterruptibly(RETRY_DELAY_MS) - } - if (cancelled) { - throw IllegalStateException("Cancelled.") - } - throw IllegalStateException("could not reach $lens lens: $lastError") - } - - private fun bringUpLens(address: String): Boolean { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - return false - } - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - return false - } - // Control-channel notify carries the auth response; mandatory. - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - return false - } - if (!bleManager.enableNotifications(address, BleProtocol.OTA_DATA_NOTIFY_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - return false - } - if (!authenticate(address)) { - throw IllegalStateException( - "security auth not acknowledged — if Android shows a Bluetooth pairing request, accept it") - } - return true - } - - /** - * Complete the sid-0x80 security-auth exchange on this connection. On an - * unbonded phone this triggers SMP pairing (possibly with an OS prompt), - * so the wait is generous. Must succeed before any OTA traffic. - */ - private fun authenticate(address: String): Boolean { - val magic: Int - val latch = CountDownLatch(1) - synchronized(lock) { - magic = nextAuthMagic - nextAuthMagic = if (nextAuthMagic >= 0x7f) 0x60 else nextAuthMagic + 1 - pendingAuthMagic = magic - authAckPb = null - authLatch = latch - } - try { - if (!writeOta(address, BleProtocol.WRITE_CHAR_UUID, BleProtocol.SID_SECURITY_AUTH, - BleProtocol.buildAuthenticationRequest(magic), nextSeq())) { - emitLog("auth write failed: $address") - return false - } - val signalled: Boolean - try { - signalled = latch.await(ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - return false - } - val pb: ByteArray? - synchronized(lock) { - pb = authAckPb - } - if (!signalled || !BleProtocol.isAuthenticationSuccess(pb, magic)) { - emitLog("security auth not acknowledged (" + address - + ") — if Android shows a Bluetooth pairing request, accept it") - return false - } - emitLog("security auth complete: $address") - return true - } finally { - synchronized(lock) { - pendingAuthMagic = -1 - authLatch = null - } - } - } - - // ---- firmware container parsing / validation ----------------------------- - - private class Segment( - @JvmField val off: Int, - @JvmField val ps: Int, - @JvmField val crc: Long, - @JvmField val name: String - ) - - private fun parseSegments(img: ByteArray): List { - if (img.size < 0x40) { - throw IllegalStateException("file is too small to be a firmware image") - } - val n = readU32(img, 8) - if (n <= 0 || n > 64) { - throw IllegalStateException("implausible component count $n (corrupt image?)") - } - val segs = ArrayList() - var i = 0 - while (i < n) { - val base = 0x40 + i * 16 - val crc = readU32(img, base + 12) - val off = readU32(img, base + 4).toInt() - if (off + 128 > img.size) { - throw IllegalStateException("segment $i subheader runs past end of file") - } - val ps = readU32(img, off + 8).toInt() - val name = readCString(img, off + 48, 80) - segs.add(Segment(off, ps, crc, name)) - i++ - } - return segs - } - - private fun validate(img: ByteArray): List { - val segs = parseSegments(img) - if (segs.size < MIN_SEGMENTS || segs.size > MAX_SEGMENTS) { - throw IllegalStateException( - "expected " + MIN_SEGMENTS + "-" + MAX_SEGMENTS + " components, found " + segs.size) - } - var main: Segment? = null - for (s in segs) { - val payload = Arrays.copyOfRange(img, s.off + 128, s.off + 128 + s.ps) - val calc = crc32cMsb(payload).toLong() and 0xffffffffL - val subCrc = readU32(img, s.off + 12) - if (calc != s.crc || calc != subCrc) { - throw IllegalStateException("component " + s.name + " CRC32C is stale (image not checksum-fixed)") - } - if (REQUIRED_SEGMENT == s.name) { - main = s - } - } - if (main == null) { - throw IllegalStateException("required component $REQUIRED_SEGMENT not found") - } - checkMainAppFitsMram(img, main) - return segs - } - - private fun checkMainAppFitsMram(img: ByteArray, main: Segment) { - if (main.ps < APP_PREAMBLE) { - throw IllegalStateException("main-app payload is smaller than its preamble") - } - val loadAddr = readU32(img, main.off + 128 + 0x14) - val preLen = readU32(img, main.off + 128) and 0xFFFFFFL - if (loadAddr != APP_LOAD_ADDR) { - throw IllegalStateException( - "main-app preamble load address is 0x" + java.lang.Long.toHexString(loadAddr) - + ", expected 0x" + java.lang.Long.toHexString(APP_LOAD_ADDR)) - } - if (preLen != main.ps.toLong()) { - throw IllegalStateException( - "main-app preamble length (" + preLen + ") != staged payload size (" + main.ps + ")") - } - val progEnd = APP_LOAD_ADDR + main.ps - APP_PREAMBLE - if (progEnd > APP_MAX_END) { - val over = progEnd - APP_MAX_END - throw IllegalStateException( - "main-app is too large: programmed region ends at 0x" + java.lang.Long.toHexString(progEnd) - + ", " + over + " bytes past the safe MRAM ceiling — refusing to flash (brick risk)") - } - } - - // ---- listener callbacks -------------------------------------------------- - - override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { - if (BleProtocol.NOTIFY_CHAR_UUID.equals(characteristicUuid, ignoreCase = true)) { - // Control channel: only the security-auth response is awaited here. - // A value can carry several envelope frames back to back (e.g. the - // response packed with one of the lens's own sid-0x80 notifies). - for (buf in BleProtocol.splitFrames(data)) { - val frame = BleProtocol.parseFrame(buf) - if (frame.ok && frame.sid == BleProtocol.SID_SECURITY_AUTH) { - synchronized(lock) { - val currentLatch = authLatch - if (currentLatch != null && frame.msgSeq == pendingAuthMagic) { - authAckPb = frame.pb - currentLatch.countDown() - } - } - } - } - return - } - if (!BleProtocol.OTA_DATA_NOTIFY_UUID.equals(characteristicUuid, ignoreCase = true)) { - return // OTA acks arrive on the data-notify char - } - val frame = BleProtocol.parseFrame(data) - if (!frame.ok || frame.pb.size < 2) { - return - } - dataAcks.add(Arrays.copyOf(frame.pb, Math.min(frame.pb.size, 2))) - } - - override fun onConnectionStateChange(address: String?, connected: Boolean) { - if (!connected) { - Log.i(TAG, "disconnected: $address") - } - } - - // ---- helpers ------------------------------------------------------------- - - private fun teardown() { - try { - bleManager.close() - } catch (ignored: Exception) { - } - } - - private fun resetSeq() { - synchronized(lock) { - nextSeq = 0 - } - } - - private fun nextSeq(): Int { - synchronized(lock) { - nextSeq = (nextSeq + 1) and 0xff - return nextSeq - } - } - - private fun drainAcks() { - dataAcks.clear() - } - - private fun sleepInterruptibly(ms: Int) { - try { - Thread.sleep(ms.toLong()) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - } - } - - private fun emitLog(line: String) { - Log.i(TAG, line) + private fun post(action: (FaceclawFirmwareFlasherListener) -> Unit) { mainHandler.post { val current = listener if (current != null) { - current.onLog(line) - } - } - } - - private fun emitProgress(lens: String, componentIndex: Int, componentCount: Int, blockIndex: Int, blockCount: Int, - bytesSent: Long, bytesTotal: Long) { - mainHandler.post { - val current = listener - if (current != null) { - current.onProgress(lens, componentIndex, componentCount, blockIndex, blockCount, bytesSent, bytesTotal) - } - } - } - - private fun emitState(state: String, detail: String?) { - val safeDetail = detail ?: "" - mainHandler.post { - val current = listener - if (current != null) { - current.onState(state, safeDetail) - } - } - } - - private fun emitComplete(success: Boolean, detail: String?) { - val safeDetail = detail ?: "" - mainHandler.post { - val current = listener - if (current != null) { - current.onComplete(success, safeDetail) + action(current) } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt index b3cf1d83..37ad4593 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.kt @@ -1,110 +1,53 @@ package com.faceclaw.app -import android.bluetooth.BluetoothGatt import android.content.Context import android.os.Handler import android.os.Looper -import android.util.Log - -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.CountDownLatch -import java.util.concurrent.Executors -import java.util.concurrent.ScheduledExecutorService -import java.util.concurrent.TimeUnit /** - * A minimal, stock-firmware-compatible BLE communicator used only to show the - * pre-flash confirmation prompt on the glasses and read back the user's Yes/No - * choice. It is deliberately separate from FaceclawBleCommunicator: the main - * app assumes the custom firmware (image containers, compositor, etc.), whereas - * this must work on unmodified glasses, so it speaks only the stock subset — - * session prelude, a text container, a list container, and heartbeats. No - * images. - * - * It reuses the low-level GATT wrapper (FaceclawBleManager) and the framing / - * protobuf helpers (BleProtocol), but owns its own GATT connection and runs its - * whole lifecycle on a single worker thread. It expects the main app to be - * disconnected while it runs (onboarding, before flashing). - * - * Both arms are connected and security-authenticated up front, even though the - * prompt itself only needs the right arm (the lenses relay messages to each - * other, and acks/events only ever come from the right arm): on an unbonded - * phone the auth exchange is what raises the OS pairing prompt, and doing both - * here means both prompts appear at the start rather than one popping up half - * way through flashing the second lens. While connected, each arm's battery - * level is read (they are independent batteries) so the caller can refuse to - * flash on a low charge. - * - * With `skipPrompt` the on-glasses confirmation is not shown: the flow is just - * connect + auth + battery read + result(approved). Used to re-check the - * battery after the user has already confirmed once. + * Android host for the shared [FlashPromptFlow] (the stock-firmware pre-flash Yes/No prompt + * plus battery read): owns the GATT link (AndroidStockLink) and the worker thread, and + * delivers listener callbacks on the main thread. It expects the main app to be disconnected + * while it runs (onboarding, before flashing). Public API unchanged for + * app/native/flash-prompt-communicator.ts. */ class FaceclawFlashPromptCommunicator( - context: Context, rightAddress: String?, leftAddress: String?, warningText: String?, skipPrompt: Boolean) : FaceclawBleListener { - companion object { - private const val TAG = "FaceclawFlashPrompt" - - private const val TEXT_NAME = "flashwarn" - private const val LIST_NAME = "flashmenu" - private const val TEXT_CONTAINER_ID = 1 - private const val LIST_CONTAINER_ID = 2 - // Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid. - private val ITEMS = arrayOf("No, cancel", "Yes, flash") - - private const val HEARTBEAT_INTERVAL_MS = 4_000 - private const val SELECTION_TIMEOUT_MS = 120_000 - private const val CREATE_ACK_TIMEOUT_MS = 3_000 - private const val BATTERY_ACK_TIMEOUT_MS = 3_000 - - private fun ackKey(sid: Int, magic: Int): String { - return "$sid:$magic" - } - } - - private val context: Context - private val rightAddress: String - private val leftAddress: String - private val warningText: String - private val skipPrompt: Boolean - private val bleManager: FaceclawBleManager + context: Context, + rightAddress: String?, + leftAddress: String?, + warningText: String?, + skipPrompt: Boolean, +) { + private val link = AndroidStockLink(context.applicationContext) private val mainHandler = Handler(Looper.getMainLooper()) - private val lock = Any() - private val pendingAcks = ConcurrentHashMap() - private val ackPayloads = ConcurrentHashMap() - private val selectionLatch = CountDownLatch(1) @Volatile private var listener: FaceclawFlashPromptListener? = null + @Volatile private var worker: Thread? = null - @Volatile - private var cancelled = false - @Volatile - private var finished = false - @Volatile - private var rightConnected = false - @Volatile - private var leftConnected = false - @Volatile - private var rightLost = false - @Volatile - private var approved: Boolean? = null - @Volatile - private var heartbeatExecutor: ScheduledExecutorService? = null - private var nextMagic = 100 - private var nextSeq = 0x40 + private val flow = + FlashPromptFlow( + link, + rightAddress ?: "", + leftAddress ?: "", + warningText ?: "", + skipPrompt, + object : FaceclawFlashPromptListener { + override fun onLog(line: String?) { + android.util.Log.i(FlashPromptFlow.TAG, line ?: "") + post { it.onLog(line) } + } - init { - this.context = context.applicationContext - this.rightAddress = rightAddress ?: "" - this.leftAddress = leftAddress ?: "" - this.warningText = warningText ?: "" - this.skipPrompt = skipPrompt - this.bleManager = FaceclawBleManager(this.context) - this.bleManager.setListener(this) - } + override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") } + + override fun onBattery(rightPercent: Int, leftPercent: Int) = post { it.onBattery(rightPercent, leftPercent) } + + override fun onResult(approved: Boolean) = post { it.onResult(approved) } + }, + ) fun setListener(listener: FaceclawFlashPromptListener?) { this.listener = listener @@ -115,7 +58,7 @@ class FaceclawFlashPromptCommunicator( if (worker != null) { return } - val w = Thread({ run() }, "faceclaw-flash-prompt") + val w = Thread({ flow.run() }, "faceclaw-flash-prompt") worker = w w.start() } @@ -123,443 +66,22 @@ class FaceclawFlashPromptCommunicator( /** Abort the prompt (e.g. the user backed out on the phone). */ fun cancel() { - cancelled = true - selectionLatch.countDown() - val w = worker - if (w != null) { - w.interrupt() - } + flow.cancel() } fun close() { cancel() - stopHeartbeat() try { - bleManager.close() + link.close() } catch (ignored: Exception) { } } - private fun run() { - try { - if (rightAddress.trim().isEmpty()) { - emitState("error", "No right-arm address configured.") - return - } - - emitState("connecting", "") - connectArm(rightAddress, "right") - rightConnected = true - if (cancelled) { - teardown() - return - } - if (!leftAddress.trim().isEmpty()) { - connectArm(leftAddress, "left") - leftConnected = true - if (cancelled) { - teardown() - return - } - } - - emitState("connected", "") - // Auth both arms now (pairing prompts, if any, happen here) before - // anything else, so both bonds exist by the time flashing starts. - authenticateArm(rightAddress, "right") - if (leftConnected) { - authenticateArm(leftAddress, "left") - } - if (cancelled) { - teardown() - return - } - sendPrelude(rightAddress) - - if (!skipPrompt) { - showPrompt(rightAddress) - startHeartbeat() - emitState("prompting", "") - - selectionLatch.await(SELECTION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS) - stopHeartbeat() - - if (cancelled) { - emitState("cancelled", "") - teardown() - return - } - if (approved == null) { - if (rightLost) { - emitState("disconnected", "Lost connection to the glasses.") - } else { - emitState("timeout", "No response from the glasses.") - } - teardown() - return - } - try { - sendShutdown() - } catch (ignored: Exception) { - } - if (approved != true) { - emitResult(false) - emitState("result", "declined") - teardown() - return - } - } - - // Approved (or prompt skipped): read each arm's battery while the - // links are still up, then report the result. - emitState("battery", "") - readBatteries() - if (cancelled) { - emitState("cancelled", "") - teardown() - return - } - if (rightLost) { - emitState("disconnected", "Lost connection to the glasses.") - teardown() - return - } - finished = true - emitResult(true) - emitState("result", "approved") - teardown() - } catch (e: Exception) { - stopHeartbeat() - if (!cancelled) { - val message = if (e.message == null) e.toString() else e.message - emitState("error", message) - } - teardown() - } - } - - private fun connectArm(address: String, arm: String) { - if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { - throw IllegalStateException("could not connect to the $arm arm ($address)") - } - bleManager.requestConnectionPriority(address, BluetoothGatt.CONNECTION_PRIORITY_HIGH) - bleManager.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) - if (!bleManager.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { - throw IllegalStateException("discoverServices failed: $arm arm ($address)") - } - if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { - throw IllegalStateException("enableNotifications failed: $arm arm ($address)") - } - emitLog("connected $arm arm") - } - - /** - * Security-auth exchange on sid=0x80: firmware 2.2.9 will not run a - * session (and closes the link after ~30 s) without it, and on an - * unbonded phone this is what triggers SMP pairing, so it may sit - * waiting on an OS pairing prompt. - */ - @Throws(InterruptedException::class) - private fun authenticateArm(address: String, arm: String) { - val authMagic = allocMagic() - val authAck = writeAndAwaitAck( - address, - BleProtocol.SID_SECURITY_AUTH, - BleProtocol.FLAG_SECURITY_AUTH, - authMagic, - BleProtocol.buildAuthenticationRequest(authMagic), - ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS) - if (authAck == null || !BleProtocol.isAuthenticationSuccess(authAck, authMagic)) { - throw IllegalStateException( - "could not authenticate with the $arm arm ($address" - + ") — if Android shows a Bluetooth pairing request, accept it and try again") - } - emitLog("security auth complete: $arm arm") - } - - /** Mandatory session prelude on sid=0x01 (app-launch). Right arm only; it relays. */ - @Throws(InterruptedException::class) - private fun sendPrelude(address: String) { - if (writeAndAwaitAck( - address, - BleProtocol.PRELUDE_ACK_SID, - BleProtocol.FLAG_REQUEST, - BleProtocol.PRELUDE_ACK_MAGIC, - BleProtocol.PRELUDE_F5872_PAYLOAD, - ConnectionOptions.PRELUDE_TIMEOUT_MS) == null) { - throw IllegalStateException("session prelude not acked: $address") - } - } - - @Throws(InterruptedException::class) - private fun showPrompt(address: String) { - // Create the prompt page (warning text + No/Yes list) on sid=0xe0 Cmd=0. - // Two attempts: on 2.2.9 the first request sent right after the - // prelude can be dropped while the lens emits its own sid-0x80 - // notifications (observed with the device-info settings read). - var pageAck: ByteArray? = null - var attempt = 0 - while (attempt < 2 && pageAck == null && !cancelled) { - val magic = allocMagic() - val page = BleProtocol.buildCreatePromptPage( - magic, TEXT_NAME, TEXT_CONTAINER_ID, warningText, LIST_NAME, LIST_CONTAINER_ID, ITEMS) - pageAck = writeAndAwaitAck(address, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, magic, page, CREATE_ACK_TIMEOUT_MS) - if (pageAck == null) { - emitLog("prompt page attempt " + (attempt + 1) + " unacked: " + address) - } - attempt++ - } - if (pageAck == null) { - throw IllegalStateException("prompt page not acked: $address") - } - emitLog("prompt page shown on $address") - } - - /** - * Read each arm's battery via a sid-0x09 settings read on that arm's own - * link (the arms have independent batteries and each answers with its - * own). An arm that does not answer reports -1; the caller decides what - * to do with a partial reading. - */ - @Throws(InterruptedException::class) - private fun readBatteries() { - val right = if (rightConnected) readBattery(rightAddress, "right") else -1 - val left = if (leftConnected) readBattery(leftAddress, "left") else -1 - emitLog("battery R=" + (if (right < 0) "?" else "$right%") + " L=" + (if (left < 0) "?" else "$left%")) - emitBattery(right, left) - } - - @Throws(InterruptedException::class) - private fun readBattery(address: String, arm: String): Int { - var attempt = 0 - while (attempt < 2 && !cancelled) { - val magic = allocMagic() - val ack = writeAndAwaitAck( - address, - BleProtocol.SID_UI_SETTING, - BleProtocol.FLAG_REQUEST, - magic, - BleProtocol.buildSettingsQuery(magic), - BATTERY_ACK_TIMEOUT_MS) - if (ack == null) { - emitLog("battery read attempt " + (attempt + 1) + " unacked: " + arm + " arm") - attempt++ - continue - } - val snapshot: BleProtocol.BatterySnapshot? = BleProtocol.parseSettingsBattery(ack) - if (snapshot != null) { - return snapshot.battery - } - emitLog("battery read ack had no battery field: $arm arm") - attempt++ - } - return -1 - } - - /** Write and wait for the matching ack; returns the ack's protobuf (may be empty), or null on timeout/write failure. */ - @Throws(InterruptedException::class) - private fun writeAndAwaitAck(address: String, sid: Int, flag: Int, magic: Int, payload: ByteArray, timeoutMs: Int): ByteArray? { - val latch = CountDownLatch(1) - val key = ackKey(sid, magic) - pendingAcks[key] = latch - try { - if (!writeFrame(address, sid, flag, payload)) { - return null - } - if (!latch.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS)) { - return null - } - val pb = ackPayloads[key] - return pb ?: ByteArray(0) - } finally { - pendingAcks.remove(key, latch) - ackPayloads.remove(key) - } - } - - private fun writeFrame(address: String, sid: Int, flag: Int, payload: ByteArray): Boolean { - val seq: Int - synchronized(lock) { - seq = nextSeq++ and 0xff - } - val frames = BleProtocol.framePb(payload, sid, flag, seq) - return bleManager.writeFrames( - address, - BleProtocol.WRITE_CHAR_UUID, - frames, - AndroidProtocolPlatform.writeType(ConnectionOptions.WRITE_MODE), - ConnectionOptions.WRITE_TIMEOUT_MS) - } - - private fun startHeartbeat() { - stopHeartbeat() - val executor = Executors.newSingleThreadScheduledExecutor { runnable -> - val t = Thread(runnable, "faceclaw-flash-hb") - t.isDaemon = true - t - } - heartbeatExecutor = executor - executor.scheduleWithFixedDelay( - { sendHeartbeat() }, HEARTBEAT_INTERVAL_MS.toLong(), HEARTBEAT_INTERVAL_MS.toLong(), TimeUnit.MILLISECONDS) - } - - private fun sendHeartbeat() { - if (finished || cancelled) { - return - } - try { - val heartbeat = BleProtocol.buildHeartbeat(allocMagic()) - if (rightConnected) { - writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat) - } - } catch (e: Exception) { - Log.w(TAG, "heartbeat failed: " + e.message) - } - } - - private fun stopHeartbeat() { - val executor = heartbeatExecutor - heartbeatExecutor = null - if (executor != null) { - executor.shutdownNow() - } - } - - private fun sendShutdown() { - val shutdown = BleProtocol.buildShutdown(allocMagic(), 0) - if (rightConnected) { - writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown) - } - } - - private fun teardown() { - finished = true - stopHeartbeat() - try { - bleManager.close() - } catch (ignored: Exception) { - } - rightConnected = false - leftConnected = false - } - - override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { - if (!BleProtocol.NOTIFY_CHAR_UUID.equals(characteristicUuid, ignoreCase = true)) { - return - } - // A value can carry several envelope frames back to back. - for (buf in BleProtocol.splitFrames(data)) { - handleFrame(address, buf) - } - } - - private fun handleFrame(address: String?, buf: ByteArray) { - val frame = BleProtocol.parseFrame(buf) - if (!frame.ok) { - return - } - if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { - handleEvent(frame) - return - } - if (frame.msgSeq >= 0) { - val key = ackKey(frame.sid, frame.msgSeq) - val latch = pendingAcks[key] - if (latch != null) { - ackPayloads[key] = frame.pb - latch.countDown() - } - } - } - - private fun handleEvent(frame: BleProtocol.ParsedFrame) { - val selection: BleProtocol.ListSelection? = BleProtocol.parseListSelection(frame) - if (selection == null || LIST_NAME != selection.containerName) { - return - } - // Only a confirmed click is a decision; scroll/highlight changes are ignored. - if (selection.eventType != BleProtocol.EVENT_CLICK) { - return - } - val itemName = selection.itemName - val yes = selection.itemIndex == 1 - || (itemName != null && itemName.lowercase().startsWith("yes")) - synchronized(lock) { - if (finished) { - return - } - finished = true - approved = yes - } - emitLog("selection: " + (if (yes) "flash" else "cancel") + " (index " + selection.itemIndex + ")") - selectionLatch.countDown() - } - - override fun onConnectionStateChange(address: String?, connected: Boolean) { - if (connected) { - return - } - if (address!!.equals(leftAddress, ignoreCase = true)) { - // The prompt itself only needs the right arm; a dropped left link - // just means no left battery reading. - leftConnected = false - emitLog("left arm disconnected") - return - } - if (address.equals(rightAddress, ignoreCase = true)) { - rightConnected = false - synchronized(lock) { - if (!finished && !cancelled) { - rightLost = true - finished = true - selectionLatch.countDown() - } - } - } - } - - private fun allocMagic(): Int { - synchronized(lock) { - val magic = nextMagic - nextMagic = if (nextMagic >= 255) 100 else nextMagic + 1 - return magic - } - } - - private fun emitLog(line: String) { - Log.i(TAG, line) + private fun post(action: (FaceclawFlashPromptListener) -> Unit) { mainHandler.post { val current = listener if (current != null) { - current.onLog(line) - } - } - } - - private fun emitState(state: String, detail: String?) { - val safeDetail = detail ?: "" - mainHandler.post { - val current = listener - if (current != null) { - current.onState(state, safeDetail) - } - } - } - - private fun emitBattery(rightPercent: Int, leftPercent: Int) { - mainHandler.post { - val current = listener - if (current != null) { - current.onBattery(rightPercent, leftPercent) - } - } - } - - private fun emitResult(approvedResult: Boolean) { - mainHandler.post { - val current = listener - if (current != null) { - current.onResult(approvedResult) + action(current) } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt index 6e5a2855..9f26efab 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawHttp.kt @@ -7,27 +7,18 @@ import okhttp3.Request import okhttp3.Response /** - * Shared HTTP identity for the Java networking helpers. The version lives in + * Android okhttp face of the shared HTTP identity. The version lives in * app/version.ts, so the TypeScript side pushes the real string in at startup - * (see installNativeUserAgent in app/util/http.ts); the default below is only - * a fallback for requests that somehow beat that call. + * (see installNativeUserAgent in app/util/http.ts); the value itself is held + * by the shared HttpIdentity so every platform's networking reads one string. */ class FaceclawHttp private constructor() { companion object { - @Volatile - private var userAgent = "Faceclaw" + @JvmStatic + fun setUserAgent(value: String?) = HttpIdentity.setUserAgent(value) @JvmStatic - fun setUserAgent(value: String?) { - if (value != null && !value.trim().isEmpty()) { - userAgent = value.trim() - } - } - - @JvmStatic - fun getUserAgent(): String { - return userAgent - } + fun getUserAgent(): String = HttpIdentity.getUserAgent() /** Stamps our User-Agent on any request that doesn't already carry one. */ @JvmStatic @@ -39,7 +30,7 @@ class FaceclawHttp private constructor() { if (request.header("User-Agent") != null) { return chain.proceed(request) } - return chain.proceed(request.newBuilder().header("User-Agent", userAgent).build()) + return chain.proceed(request.newBuilder().header("User-Agent", HttpIdentity.getUserAgent()).build()) } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt index ce53c010..1028f3bf 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawLc3Decoder.kt @@ -2,23 +2,23 @@ package com.faceclaw.app import android.util.Log +/** + * Android LC3 decoder for G2 microphone packets: the liblc3 JNI codec behind the shared + * [Lc3PacketFramer], which owns the counter/duplicate/trailer logic and statistics. + */ class FaceclawLc3Decoder { companion object { private const val TAG = "FaceclawLc3" - const val SAMPLE_RATE = 16000 - const val FRAME_US = 10000 - const val FRAME_BYTES = 40 - const val FRAMES_PER_PACKET = 5 - const val PACKET_BYTES = 205 - const val COUNTER_OFFSET = 204 - const val SAMPLES_PER_FRAME = 160 - const val SAMPLES_PER_PACKET = FRAMES_PER_PACKET * SAMPLES_PER_FRAME - // Trailer layout (firmware service_audio.c): after the 200 LC3 bytes the - // glasses DSP appends two signed 16-bit LE values computed on the raw - // stereo capture before the mono downmix — a signal-strength ratio and the - // asin-derived direction-of-arrival in degrees — then the packet counter. - const val SSR_OFFSET = 200 - const val ANGLE_OFFSET = 202 + const val SAMPLE_RATE = Lc3PacketFramer.SAMPLE_RATE + const val FRAME_US = Lc3PacketFramer.FRAME_US + const val FRAME_BYTES = Lc3PacketFramer.FRAME_BYTES + const val FRAMES_PER_PACKET = Lc3PacketFramer.FRAMES_PER_PACKET + const val PACKET_BYTES = Lc3PacketFramer.PACKET_BYTES + const val COUNTER_OFFSET = Lc3PacketFramer.COUNTER_OFFSET + const val SAMPLES_PER_FRAME = Lc3PacketFramer.SAMPLES_PER_FRAME + const val SAMPLES_PER_PACKET = Lc3PacketFramer.SAMPLES_PER_PACKET + const val SSR_OFFSET = Lc3PacketFramer.SSR_OFFSET + const val ANGLE_OFFSET = Lc3PacketFramer.ANGLE_OFFSET init { System.loadLibrary("faceclaw_lc3") @@ -32,17 +32,15 @@ class FaceclawLc3Decoder { private external fun nativeDestroy(handle: Long) } - private var nativeHandle: Long - private var lastCounter = -1 - private var realPackets: Long = 0 - private var duplicatePackets: Long = 0 - private var missingPackets: Long = 0 - private var decodeErrors: Long = 0 - private var lastSsr = 0 - private var lastAngleDegrees = 0 + private var nativeHandle: Long = nativeCreate(FRAME_US, SAMPLE_RATE) + private val framer = Lc3PacketFramer(object : Lc3Codec { + override fun decodeFrames(packet: ByteArray, offset: Int, length: Int, pcmOut: ShortArray): Int { + // The JNI entry decodes the five 40-byte frames at the start of the packet. + return nativeDecodePacket(nativeHandle, packet, pcmOut) + } + }) init { - nativeHandle = nativeCreate(FRAME_US, SAMPLE_RATE) if (nativeHandle == 0L) { throw IllegalStateException("Could not create LC3 decoder") } @@ -54,70 +52,30 @@ class FaceclawLc3Decoder { throw IllegalStateException("LC3 decoder is closed") } if (packet == null || packet.size != PACKET_BYTES) { - decodeErrors++ Log.w(TAG, "unexpected G2 audio packet length=" + (packet?.size ?: -1)) - return 0 } - if (pcmOut == null || pcmOut.size < SAMPLES_PER_PACKET) { - throw IllegalArgumentException("pcmOut must hold $SAMPLES_PER_PACKET samples") - } - - val counter = packet[COUNTER_OFFSET].toInt() and 0xff - if (lastCounter >= 0) { - val gap = (counter - lastCounter) and 0xff - if (gap == 0) { - duplicatePackets++ - return 0 - } - val missing = gap - 1 - if (missing > 0) { - missingPackets += missing.toLong() - } - } - - val decoded = nativeDecodePacket(nativeHandle, packet, pcmOut) - if (decoded <= 0) { - decodeErrors++ - return 0 - } - realPackets++ - lastCounter = counter - lastSsr = ((packet[SSR_OFFSET].toInt() and 0xff) or (packet[SSR_OFFSET + 1].toInt() shl 8)).toShort().toInt() - lastAngleDegrees = ((packet[ANGLE_OFFSET].toInt() and 0xff) or (packet[ANGLE_OFFSET + 1].toInt() shl 8)).toShort().toInt() - return decoded + return framer.decodePacket(packet, pcmOut) } /** Firmware signal-strength ratio from the most recent decoded packet. */ @Synchronized - fun getLastSsr(): Int { - return lastSsr - } + fun getLastSsr(): Int = framer.lastSsr /** Firmware direction-of-arrival (signed degrees) from the most recent decoded packet. */ @Synchronized - fun getLastAngleDegrees(): Int { - return lastAngleDegrees - } + fun getLastAngleDegrees(): Int = framer.lastAngleDegrees @Synchronized - fun getRealPackets(): Long { - return realPackets - } + fun getRealPackets(): Long = framer.realPackets @Synchronized - fun getDuplicatePackets(): Long { - return duplicatePackets - } + fun getDuplicatePackets(): Long = framer.duplicatePackets @Synchronized - fun getMissingPackets(): Long { - return missingPackets - } + fun getMissingPackets(): Long = framer.missingPackets @Synchronized - fun getDecodeErrors(): Long { - return decodeErrors - } + fun getDecodeErrors(): Long = framer.decodeErrors @Synchronized fun close() { diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt index 376175d8..96cb52ff 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawModelDownloader.kt @@ -2,13 +2,11 @@ package com.faceclaw.app import android.os.Handler import android.os.Looper -import android.util.Log import java.io.File import java.io.FileInputStream import java.io.FileOutputStream -import java.io.IOException -import java.security.MessageDigest +import java.io.InputStream import java.util.concurrent.TimeUnit import okhttp3.Call @@ -17,10 +15,10 @@ import okhttp3.Request /** * Large-file downloader for on-phone model weights (multi-GB, from Hugging - * Face). Downloads to ".part" with HTTP Range resume across app - * restarts, verifies a pinned sha256 (hashed incrementally, including the - * resumed prefix), then renames into place. Listener callbacks are posted to - * the constructing thread's Looper, like the other Faceclaw bridges. + * Face). The resume/hash/verify/rename policy is the shared ResumableDownload; + * this class supplies okhttp, java.io storage, the worker thread, and posts + * listener callbacks to the constructing thread's Looper, like the other + * Faceclaw bridges. */ class FaceclawModelDownloader( url: String, @@ -30,35 +28,31 @@ class FaceclawModelDownloader( listener: FaceclawModelDownloaderListener? ) { private val callbackHandler: Handler - private val url: String - private val destFile: File - private val partFile: File - private val expectedSha256: String - private val expectedTotalBytes: Long - private val listener: FaceclawModelDownloaderListener - - @Volatile - private var cancelled = false - @Volatile - private var call: Call? = null + private val transport = OkHttpTransport() + private val download: ResumableDownload private var worker: Thread? = null init { if (listener == null) throw IllegalArgumentException("listener is required") val looper = Looper.myLooper() this.callbackHandler = Handler(looper ?: Looper.getMainLooper()) - this.url = url - this.destFile = File(destPath) - this.partFile = File("$destPath.part") - this.expectedSha256 = expectedSha256?.lowercase() ?: "" - this.expectedTotalBytes = expectedTotalBytes - this.listener = listener + val posted = object : FaceclawModelDownloaderListener { + override fun onProgress(bytesDownloaded: Long, totalBytes: Long) { + callbackHandler.post { listener.onProgress(bytesDownloaded, totalBytes) } + } + + override fun onDone(path: String?) { + callbackHandler.post { listener.onDone(path) } + } + + override fun onError(message: String?) { + callbackHandler.post { listener.onError(message) } + } + } + download = ResumableDownload(url, File(destPath).absolutePath, expectedSha256, expectedTotalBytes, transport, FileStorage, posted) } companion object { - private const val TAG = "FaceclawModelDl" - private const val PROGRESS_INTERVAL_MS = 500L - @Volatile private var sharedClient: OkHttpClient? = null @@ -79,120 +73,76 @@ class FaceclawModelDownloader( } fun start() { - val thread = Thread({ run() }, "FaceclawModelDl") + val thread = Thread({ download.run() }, "FaceclawModelDl") worker = thread thread.start() } /** Stops the download but keeps the .part file so a later start() resumes. */ fun cancel() { - cancelled = true - val current = call - current?.cancel() + download.cancel() + transport.call?.cancel() } - private fun run() { - try { - if (destFile.exists() && destFile.length() > 0) { - post { listener.onDone(destFile.absolutePath) } - return - } - destFile.parentFile.mkdirs() - - var digest = MessageDigest.getInstance("SHA-256") - var offset = 0L - if (partFile.exists()) { - offset = hashExistingPrefix(digest) - if (cancelled) return - } + /** One call at a time per downloader, so cancel() can abort a connect in progress. */ + private class OkHttpTransport : DownloadTransport { + @Volatile + var call: Call? = null + override fun open(url: String, rangeFrom: Long): DownloadResponse { val builder = Request.Builder().url(url) - if (offset > 0) builder.header("Range", "bytes=$offset-") - val newCall = getClient().newCall(builder.build()) - call = newCall + if (rangeFrom > 0) builder.header("Range", "bytes=$rangeFrom-") + val call: Call = getClient().newCall(builder.build()) + this.call = call + val response = call.execute() + val body = response.body + val input: InputStream? = body?.byteStream() + return object : DownloadResponse { + override val code: Int = response.code + override val contentLength: Long = body?.contentLength() ?: -1L - newCall.execute().use { response -> - val body = response.body - if (!response.isSuccessful || body == null) { - postError("Model download failed: HTTP " + response.code) - return - } - val resumed = response.code == 206 - if (offset > 0 && !resumed) { - // Server ignored the Range header; start over. - offset = 0L - digest = MessageDigest.getInstance("SHA-256") - } - val total = if (expectedTotalBytes > 0) expectedTotalBytes - else (if (body.contentLength() > 0) offset + body.contentLength() else -1L) + override fun read(buffer: ByteArray): Int = input?.read(buffer) ?: -1 - FileOutputStream(partFile, resumed).use { out -> - body.byteStream().use { input -> - val buffer = ByteArray(1 shl 16) - var done = offset - var lastProgressAt = 0L - var read: Int - while (input.read(buffer).also { read = it } != -1) { - if (cancelled) return - out.write(buffer, 0, read) - digest.update(buffer, 0, read) - done += read - val now = System.currentTimeMillis() - if (now - lastProgressAt >= PROGRESS_INTERVAL_MS) { - lastProgressAt = now - val doneFinal = done - val totalFinal = total - post { listener.onProgress(doneFinal, totalFinal) } - } - } - } + override fun close() { + call.cancel() + response.close() } } - - if (expectedTotalBytes > 0 && partFile.length() != expectedTotalBytes) { - postError("Model download ended early (" + partFile.length() + " of " - + expectedTotalBytes + " bytes); try again to resume") - return - } - val actualSha = FaceclawFirmwareUtil.bytesToHex(digest.digest()) - if (!expectedSha256.isEmpty() && actualSha != expectedSha256) { - partFile.delete() - postError("Model download was corrupted (checksum mismatch); download it again") - return - } - if (!partFile.renameTo(destFile)) { - postError("Could not move the downloaded model into place") - return - } - post { listener.onDone(destFile.absolutePath) } - } catch (e: Exception) { - if (cancelled) return - Log.w(TAG, "download failed", e) - postError("Model download failed: $e") } } - /** Hash the already-downloaded prefix so the final digest covers the whole file. */ - @Throws(IOException::class) - private fun hashExistingPrefix(digest: MessageDigest): Long { - var hashed = 0L - FileInputStream(partFile).use { input -> - val buffer = ByteArray(1 shl 16) - var read: Int - while (input.read(buffer).also { read = it } != -1) { - if (cancelled) return hashed - digest.update(buffer, 0, read) - hashed += read + private object FileStorage : DownloadStorage { + override fun length(path: String): Long = File(path).let { if (it.exists()) it.length() else -1L } + + override fun prepareParent(path: String) { + File(path).parentFile?.mkdirs() + } + + override fun openWrite(path: String, append: Boolean): FileSink { + val out = FileOutputStream(path, append) + return object : FileSink { + override fun write(bytes: ByteArray, offset: Int, length: Int) = out.write(bytes, offset, length) + + override fun close() = out.close() } } - return hashed - } - private fun post(runnable: Runnable) { - callbackHandler.post(runnable) - } + override fun readAll(path: String, consumer: (ByteArray, Int) -> Boolean): Long { + var consumed = 0L + FileInputStream(path).use { input -> + val buffer = ByteArray(1 shl 16) + while (true) { + val read = input.read(buffer) + if (read < 0) break + if (!consumer(buffer, read)) break + consumed += read + } + } + return consumed + } - private fun postError(message: String) { - post { listener.onError(message) } + override fun rename(from: String, to: String): Boolean = File(from).renameTo(File(to)) + + override fun delete(path: String): Boolean = File(path).delete() } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt index 358098ab..10203b7c 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawRemoteInput.kt @@ -2,20 +2,19 @@ package com.faceclaw.app import android.os.Handler import android.os.Looper -import java.io.ByteArrayOutputStream +import java.io.IOException import java.net.InetAddress import java.net.NetworkInterface -import java.util.Collections -import org.json.JSONArray import java.net.ServerSocket import java.net.Socket -import java.nio.charset.StandardCharsets -import java.nio.ByteBuffer -import java.security.MessageDigest import java.security.SecureRandom -import org.json.JSONObject +import java.util.Collections -/** Explicit-address, bounded input port. Complete requests notify JS on the main thread. */ +/** + * Explicit-address, bounded input port. The request state machine lives in the shared + * [RemoteInputSession]; this adapter supplies java.net sockets, SecureRandom and main-thread + * delivery, and keeps the JVM API TypeScript calls (app/native/remote-input.ts). + */ class FaceclawRemoteInput { companion object { private val INSTANCE = FaceclawRemoteInput() @@ -23,130 +22,91 @@ class FaceclawRemoteInput { @JvmStatic fun interfaces(): String { - val result = JSONArray() + val all = ArrayList() try { for (device in Collections.list(NetworkInterface.getNetworkInterfaces())) { - if (!device.isUp) continue for (address in Collections.list(device.inetAddresses)) { - if (address.isLoopbackAddress || address.isLinkLocalAddress || address.isAnyLocalAddress) continue - result.put(JSONObject().put("name", device.name).put("address", address.hostAddress) - .put("pointToPoint", device.isPointToPoint)) + all.add(InterfaceAddress( + interfaceName = device.name, + address = address.hostAddress ?: continue, + up = device.isUp, + pointToPoint = device.isPointToPoint, + loopback = address.isLoopbackAddress, + linkLocal = address.isLinkLocalAddress, + anyLocal = address.isAnyLocalAddress, + )) } } } catch (ignored: Exception) {} - return result.toString() - } - - private fun hex(bytes: ByteArray): String { - val result = StringBuilder(bytes.size * 2) - for (b in bytes) result.append(String.format(java.util.Locale.ROOT, "%02x", b.toInt() and 255)) - return result.toString() + return RemoteInputSession.interfacesJson(all) } } - private var server: ServerSocket? = null - private var client: Socket? = null - private var pending: String? = null - private var reply: String? = null - private var nextId = 0L - private var requestId = 0L - private var deadline = 0L + private val mainHandler = Handler(Looper.getMainLooper()) - private var requestListener: Runnable? = null + private val session = RemoteInputSession( + port = AndroidLocalServerPort, + random = object : RandomSource { + private val secureRandom = SecureRandom() + override fun nextBytes(count: Int): ByteArray = ByteArray(count).also { secureRandom.nextBytes(it) } + }, + dispatch = { action -> mainHandler.post(action) }, + platform = AndroidProtocolPlatform, + ) - @Synchronized fun setRequestListener(listener: Runnable?) { requestListener = listener } + fun setRequestListener(listener: Runnable?) { session.setRequestListener(listener?.let { { it.run() } }) } - private fun notifyRequestReady(id: Long) { - // Called with this monitor held; posting avoids entering JS on the socket thread. - mainHandler.post { - val callback: Runnable? - synchronized(this) { - if (requestId != id || pending == null || System.currentTimeMillis() >= deadline) return@post - callback = requestListener - } - callback?.run() - } - } + fun start(port: Int): String { return startAddress(port, "127.0.0.1") } + fun startAddress(port: Int, address: String): String = session.start(port, address) + fun stop() = session.stop() + fun nextRequest(): String? = session.nextRequest() + fun complete(id: Long, value: String?) = session.complete(id, value) + fun randomSecret(): String = session.randomSecret() + fun hash(value: String): String = RemoteInputSession.tokenHash(value) +} - @Synchronized fun start(port: Int): String { return startAddress(port, "127.0.0.1") } - @Synchronized fun startAddress(port: Int, address: String): String { - if (server != null) return "" - try { - // Numeric local addresses only; never resolve hostnames or bind a wildcard. - if (!address.matches(Regex("[0-9.]+|[0-9a-fA-F]*:[0-9a-fA-F:.]*(%[a-zA-Z0-9_.-]+)?"))) return "Invalid local address." +private object AndroidLocalServerPort : LocalServerPort { + override fun isLocalUnicastAddress(address: String): Boolean { + return try { + // Numeric literals only reach here, so getByName never resolves a hostname. val local = InetAddress.getByName(address) - if (local.isAnyLocalAddress || local.isMulticastAddress || NetworkInterface.getByInetAddress(local) == null) - return "Address is not assigned to a local interface." - val listener = ServerSocket(port, 8, local) - server = listener - val thread = Thread({ serve(listener) }, "FaceclawInput") - thread.isDaemon = true - thread.start() - return "" - } catch (e: Exception) { return "Could not open local input port $port." } - } - @Synchronized fun stop() { - try { server?.close() } catch (ignored: Exception) {} - try { client?.close() } catch (ignored: Exception) {} - server = null; client = null; pending = null; requestId = 0; reply = null - (this as java.lang.Object).notifyAll() - } - @Synchronized fun nextRequest(): String? { - if (System.currentTimeMillis() >= deadline) { pending = null; return null } - val result = pending; pending = null; return result - } - @Synchronized fun complete(id: Long, value: String?) { - if (id == requestId && System.currentTimeMillis() < deadline) { reply = value; (this as java.lang.Object).notifyAll() } - } - private fun serve(listener: ServerSocket) { - while (!listener.isClosed) { - try { - listener.accept().use { socket -> - synchronized(this) { if (server !== listener) return; client = socket } - socket.soTimeout = 5000 - socket.tcpNoDelay = true - val readDeadline = System.currentTimeMillis() + 5000 - val body = ByteArrayOutputStream() - var b = -1 - while (true) { - val remaining = readDeadline - System.currentTimeMillis() - if (remaining <= 0) throw Exception("Read timeout") - socket.soTimeout = remaining.toInt() - b = socket.getInputStream().read() - if (b == -1 || b == '\n'.code) break - if (body.size() >= 65536) throw Exception("Invalid frame") - body.write(b) - } - if (b != '\n'.code) return@use - val text = StandardCharsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(body.toByteArray())).toString() - val response: String - synchronized(this) { - if (server !== listener) return - requestId = ++nextId - deadline = System.currentTimeMillis() + 5000 - reply = null - pending = JSONObject().put("id", requestId).put("expiresAt", deadline) - .put("body", text).toString() - notifyRequestReady(requestId) - while (reply == null && server === listener && System.currentTimeMillis() < deadline) { - (this as java.lang.Object).wait(Math.max(1L, deadline - System.currentTimeMillis())) - } - response = reply ?: "{\"ok\":false,\"error\":\"timeout\",\"message\":\"Faceclaw did not respond in time.\"}" - if (server === listener) { pending = null; reply = null; requestId = 0 } - } - socket.getOutputStream().write((response + "\n").toByteArray(StandardCharsets.UTF_8)) - } - } catch (ignored: Exception) { - // Never log request bodies: they contain credentials and possibly private text. - } finally { - synchronized(this) { if (server === listener) client = null } - } + !(local.isAnyLocalAddress || local.isMulticastAddress || NetworkInterface.getByInetAddress(local) == null) + } catch (e: Exception) { + false } } - fun randomSecret(): String { - val bytes = ByteArray(32); SecureRandom().nextBytes(bytes); return hex(bytes) - } - fun hash(value: String): String { - try { return hex(MessageDigest.getInstance("SHA-256").digest(value.toByteArray(StandardCharsets.UTF_8))) } - catch (e: Exception) { throw IllegalStateException("SHA-256 unavailable", e) } + + override fun bind(address: String, port: Int): RemoteInputListener { + val server = ServerSocket(port, 8, InetAddress.getByName(address)) + return object : RemoteInputListener { + override fun accept(): RemoteInputConnection? { + val socket = try { server.accept() } catch (e: IOException) { return null } + return AndroidConnection(socket) + } + override val isClosed: Boolean get() = server.isClosed + override fun close() = server.close() + } } } + +private class AndroidConnection(private val socket: Socket) : RemoteInputConnection { + init { + socket.soTimeout = 5000 + socket.tcpNoDelay = true + } + + override fun readByte(timeoutMs: Long): Int { + return try { + socket.soTimeout = timeoutMs.coerceIn(1L, Int.MAX_VALUE.toLong()).toInt() + socket.getInputStream().read() + } catch (e: IOException) { + -1 + } + } + + override fun write(bytes: ByteArray) { + socket.getOutputStream().write(bytes) + socket.getOutputStream().flush() + } + + override fun close() = socket.close() +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt index abd6d7c1..6a6b1450 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSettings.kt @@ -4,9 +4,6 @@ import android.content.Context import android.content.SharedPreferences import android.os.Handler import android.os.Looper -import android.util.Log - -import java.util.concurrent.CopyOnWriteArrayList /** * App settings store shared by every JS isolate (main thread and app @@ -22,16 +19,26 @@ import java.util.concurrent.CopyOnWriteArrayList * NativeScript worker threads run a message loop, so both the main thread * and workers have a Looper; a listener registered from a Looper-less thread * is accepted but never notified (it can still read fresh values on demand). + * The reads/writes and the fan-out live in the shared SettingsChangeHub. */ class FaceclawSettings private constructor(context: Context) { private val prefs: SharedPreferences = context.applicationContext .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) - private val listeners = CopyOnWriteArrayList() + private val hub = SettingsChangeHub(object : SettingsStorage { + override fun getString(key: String?, defaultValue: String?): String? = prefs.getString(key, defaultValue) - private class ListenerEntry(val listener: FaceclawSettingsListener, val handler: Handler?) + override fun putString(key: String?, value: String?) { + prefs.edit().putString(key, value).apply() + } + + override fun getBoolean(key: String?, defaultValue: Boolean): Boolean = prefs.getBoolean(key, defaultValue) + + override fun putBoolean(key: String?, value: Boolean) { + prefs.edit().putBoolean(key, value).apply() + } + }) companion object { - private const val TAG = "FaceclawSettings" private const val PREFS_NAME = "faceclaw_settings" @Volatile private var instance: FaceclawSettings? = null @@ -58,23 +65,13 @@ class FaceclawSettings private constructor(context: Context) { } } - fun getString(key: String?, defaultValue: String?): String? { - return prefs.getString(key, defaultValue) - } + fun getString(key: String?, defaultValue: String?): String? = hub.getString(key, defaultValue) - fun setString(key: String?, value: String?) { - prefs.edit().putString(key, value).apply() - notifyChanged(key) - } + fun setString(key: String?, value: String?) = hub.setString(key, value) - fun getBoolean(key: String?, defaultValue: Boolean): Boolean { - return prefs.getBoolean(key, defaultValue) - } + fun getBoolean(key: String?, defaultValue: Boolean): Boolean = hub.getBoolean(key, defaultValue) - fun setBoolean(key: String?, value: Boolean) { - prefs.edit().putBoolean(key, value).apply() - notifyChanged(key) - } + fun setBoolean(key: String?, value: Boolean) = hub.setBoolean(key, value) /** * Register a change listener. Must be called from the thread whose @@ -83,30 +80,9 @@ class FaceclawSettings private constructor(context: Context) { */ fun registerListener(listener: FaceclawSettingsListener) { val looper = Looper.myLooper() - if (looper == null) { - Log.w(TAG, "settings listener registered from a Looper-less thread; it will never be notified") - } - listeners.add(ListenerEntry(listener, if (looper != null) Handler(looper) else null)) + val handler = if (looper != null) Handler(looper) else null + hub.register(listener, if (handler != null) SettingsDispatcher { action -> handler.post(action) } else null) } - fun unregisterListener(listener: FaceclawSettingsListener?) { - for (entry in listeners) { - if (entry.listener === listener) { - listeners.remove(entry) - } - } - } - - private fun notifyChanged(key: String?) { - for (entry in listeners) { - val handler = entry.handler ?: continue - handler.post { - try { - entry.listener.onSettingChanged(key) - } catch (e: Exception) { - Log.w(TAG, "settings listener failed for key $key", e) - } - } - } - } + fun unregisterListener(listener: FaceclawSettingsListener?) = hub.unregister(listener) } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt index 5cbf7bd2..87dd6c22 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSpeakerId.kt @@ -11,28 +11,9 @@ import com.k2fsa.sherpa.onnx.SpeakerEmbeddingExtractorConfig * utterance; matching/enrollment happens on the TS side (cosine similarity * against the stored speaker profiles). */ -class FaceclawSpeakerId(private val modelPath: String?) { +class FaceclawSpeakerId(private val modelPath: String?) : SpeakerEmbedder { companion object { private const val TAG = "FaceclawSpeakerId" - - @JvmStatic - private fun l2Normalize(v: FloatArray?): FloatArray? { - if (v == null) { - return null - } - var sum = 0.0 - for (x in v) { - sum += x.toDouble() * x - } - val norm = Math.sqrt(sum) - if (norm <= 0) { - return v - } - for (i in v.indices) { - v[i] = (v[i] / norm).toFloat() - } - return v - } } private var extractor: SpeakerEmbeddingExtractor? = null @@ -71,20 +52,18 @@ class FaceclawSpeakerId(private val modelPath: String?) { * is too short to embed (under ~0.5 s). */ @Synchronized - fun embed(pcm16le: ByteArray?, sampleRate: Int): FloatArray? { - if (pcm16le == null || pcm16le.size < sampleRate) { + override fun embed(pcm16le: ByteArray, sampleRate: Int): FloatArray? = embedNullable(pcm16le, sampleRate) + + @Synchronized + fun embedNullable(pcm16le: ByteArray?, sampleRate: Int): FloatArray? { + if (pcm16le == null || !VoicePrint.isLongEnoughToEmbed(pcm16le.size, sampleRate)) { return null } if (!ensureLoaded()) { return null } val extractor = this.extractor!! - val count = pcm16le.size / 2 - val samples = FloatArray(count) - for (i in 0 until count) { - val s = ((pcm16le[i * 2].toInt() and 0xff) or (pcm16le[i * 2 + 1].toInt() shl 8)).toShort() - samples[i] = s / 32768.0f - } + val samples = AudioSegmentation.pcm16leToFloat(pcm16le) var stream: OnlineStream? = null try { stream = extractor.createStream() @@ -94,7 +73,7 @@ class FaceclawSpeakerId(private val modelPath: String?) { return null } val embedding = extractor.compute(stream) - return l2Normalize(embedding) + return VoicePrint.l2Normalize(embedding) } catch (t: Throwable) { Log.w(TAG, "embedding failed", t) return null @@ -105,6 +84,8 @@ class FaceclawSpeakerId(private val modelPath: String?) { } } + override fun release() = close() + @Synchronized fun close() { val extractor = this.extractor diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt index cf7a9514..245ebc95 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSseRequest.kt @@ -4,7 +4,6 @@ import android.os.Handler import android.os.Looper import android.util.Log -import java.io.BufferedReader import java.io.IOException import java.util.concurrent.TimeUnit @@ -23,6 +22,10 @@ import okhttp3.Response * is delivered line by line as it arrives, so the JS side can parse SSE * events incrementally. Like FaceclawWebSocket, listener callbacks are posted * to the Looper of the thread that constructed this object. + * + * The line splitting, error-body and overflow policy live in the shared + * SseStream; this class only supplies okhttp as the transport and the Handler + * delivery. */ class FaceclawSseRequest /** @@ -32,7 +35,8 @@ class FaceclawSseRequest */ constructor(url: String?, jsonBody: String?, headers: Array?, listener: FaceclawSseListener?) { private val callbackHandler: Handler - private val call: Call + private val stream = SseStream() + private val transfer: Cancellable @Volatile private var cancelled = false @@ -45,63 +49,49 @@ constructor(url: String?, jsonBody: String?, headers: Array?, listener: } val looper = Looper.myLooper() callbackHandler = Handler(looper ?: Looper.getMainLooper()) - val builder = Request.Builder() - .url(url.trim()) - .post((jsonBody ?: "").toRequestBody(JSON)) - if (headers != null) { - var i = 0 - while (i + 1 < headers.size) { - val name = headers[i] - val value = headers[i + 1] - if (name != null && !name.isEmpty() && value != null) { - builder.addHeader(name, value) - } - i += 2 - } - } - call = getClient().newCall(builder.build()) - call.enqueue(object : Callback { - override fun onFailure(call: Call, e: IOException) { - postFailure(listener, e.toString()) + val sink = object : ChunkSink { + override fun onStatus(code: Int) { + stream.onStatus(code) } - override fun onResponse(call: Call, response: Response) { - try { - response.body.use { body -> - if (!response.isSuccessful) { - val code = response.code - var errorBody = "" - try { - errorBody = body?.string() ?: "" - } catch (e: IOException) { - Log.w(TAG, "error body read failed", e) - } - val finalBody = errorBody - post { listener.onHttpError(code, finalBody) } - return - } - if (body == null) { - post { listener.onComplete() } - return - } - val reader = BufferedReader(body.charStream()) - var line: String? - while (reader.readLine().also { line = it } != null) { - val finalLine = line - post { listener.onLine(finalLine) } - } - post { listener.onComplete() } - } - } catch (e: IOException) { - postFailure(listener, e.toString()) - } + override fun onChunk(bytes: ByteArray, offset: Int, length: Int) { + stream.onChunk(bytes, offset, length) + drain(listener) } - }) + + override fun onComplete() { + stream.onComplete() + drain(listener) + } + + override fun onFailure(message: String) { + stream.onFailure(message) + drain(listener) + } + } + transfer = OkHttpStreaming.post(url.trim(), jsonBody ?: "", SseStream.unpackHeaders(headers), sink) } fun cancel() { cancelled = true - call.cancel() + stream.cancel() + transfer.cancel() + } + + /** Hands every queued event to the listener on the constructing thread, in order. */ + private fun drain(listener: FaceclawSseListener) { + val events = stream.takeEvents() + if (events.isEmpty()) return + post { + for (event in events) { + if (cancelled) return@post + try { + SseStream.deliver(event, listener) + } catch (t: Throwable) { + Log.w(TAG, "listener callback failed", t) + } + } + } } private fun post(runnable: Runnable) { @@ -112,19 +102,47 @@ constructor(url: String?, jsonBody: String?, headers: Array?, listener: if (cancelled) { return@post } - try { - runnable.run() - } catch (t: Throwable) { - Log.w(TAG, "listener callback failed", t) - } + runnable.run() } } - private fun postFailure(listener: FaceclawSseListener, message: String) { - if (cancelled) { - return + /** okhttp transport: enqueues the call and feeds the body to the sink in chunks. */ + private object OkHttpStreaming : StreamingHttp { + override fun post(url: String, body: String, headers: List>, sink: ChunkSink): Cancellable { + val builder = Request.Builder() + .url(url) + .post(body.toRequestBody(JSON)) + for ((name, value) in headers) builder.addHeader(name, value) + val call = getClient().newCall(builder.build()) + call.enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) { + sink.onFailure(e.toString()) + } + + override fun onResponse(call: Call, response: Response) { + try { + response.use { + sink.onStatus(response.code) + val input = response.body?.byteStream() + if (input != null) { + val buffer = ByteArray(8192) + while (true) { + val read = input.read(buffer) + if (read < 0) break + if (read > 0) sink.onChunk(buffer, 0, read) + } + } + sink.onComplete() + } + } catch (e: IOException) { + sink.onFailure(e.toString()) + } + } + }) + return object : Cancellable { + override fun cancel() = call.cancel() + } } - post { listener.onFailure(message) } } companion object { @@ -141,9 +159,14 @@ constructor(url: String?, jsonBody: String?, headers: Array?, listener: // Streaming responses can pause between events (e.g. while // the model thinks), so the read timeout is generous. The // Anthropic API sends periodic ping events well within it. + // Redirects are not followed: provider credentials in the + // headers must never be forwarded to another endpoint (a + // 3xx surfaces to the listener as an HTTP error instead). sharedClient = OkHttpClient.Builder() .connectTimeout(15, TimeUnit.SECONDS) .readTimeout(180, TimeUnit.SECONDS) + .followRedirects(false) + .followSslRedirects(false) .addInterceptor(FaceclawHttp.userAgentInterceptor()) .build() } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt index 7c8be12c..b5108f48 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawSystemStatusIconProvider.kt @@ -14,10 +14,10 @@ import android.util.Log import java.io.ByteArrayOutputStream import java.lang.reflect.Method +/** Reads Wi-Fi/cell/hotspot state; the icon artwork is the shared StatusIconArt. */ class FaceclawSystemStatusIconProvider private constructor() { companion object { private const val TAG = "FaceclawStatusIcons" - private const val ICON_SIZE = 24 @JvmStatic fun getSystemStatusIconGrays(context: Context?, iconSize: Int): ByteArray { @@ -30,16 +30,16 @@ class FaceclawSystemStatusIconProvider private constructor() { val wifiLevel = getWifiLevel(appContext) if (wifiLevel >= 0) { - append(out, scaleIcon(drawWifiIcon(wifiLevel), size)) + append(out, StatusIconArt.scale(StatusIconArt.wifi(wifiLevel), size)) } val cellLevel = getCellLevel(appContext) if (cellLevel >= 0) { - append(out, scaleIcon(drawCellIcon(cellLevel), size)) + append(out, StatusIconArt.scale(StatusIconArt.cell(cellLevel), size)) } if (isHotspotEnabled(appContext)) { - append(out, scaleIcon(drawHotspotIcon(), size)) + append(out, StatusIconArt.scale(StatusIconArt.hotspot(), size)) } return out.toByteArray() @@ -106,86 +106,6 @@ class FaceclawSystemStatusIconProvider private constructor() { return rssi > -127 && rssi < 0 } - private fun drawWifiIcon(level: Int): ByteArray { - val icon = ByteArray(ICON_SIZE * ICON_SIZE) - val cx = 12 - val cy = 18 - fillRect(icon, cx - 1, cy - 1, 3, 3, 230) - val radii = intArrayOf(5, 9, 13, 17) - for (index in radii.indices) { - if (level <= index) { - continue - } - drawWifiArc(icon, cx, cy, radii[index], 210) - } - return icon - } - - private fun drawWifiArc(icon: ByteArray, cx: Int, cy: Int, radius: Int, value: Int) { - val inner = (radius - 1) * (radius - 1) - val outer = (radius + 1) * (radius + 1) - for (y in 0 until ICON_SIZE) { - for (x in 0 until ICON_SIZE) { - val dx = x - cx - val dy = y - cy - val dist = dx * dx + dy * dy - if (dy <= 0 && dist >= inner && dist <= outer && Math.abs(dx) <= radius) { - setPixel(icon, x, y, value) - } - } - } - } - - private fun drawCellIcon(level: Int): ByteArray { - val icon = ByteArray(ICON_SIZE * ICON_SIZE) - for (bar in 0 until 4) { - val x = 5 + bar * 4 - val height = 5 + bar * 4 - val value = if (level > bar) 220 else 55 - fillRect(icon, x, 20 - height, 3, height, value) - } - return icon - } - - private fun drawHotspotIcon(): ByteArray { - val icon = ByteArray(ICON_SIZE * ICON_SIZE) - fillRect(icon, 11, 17, 3, 3, 230) - drawWifiArc(icon, 12, 19, 7, 210) - drawWifiArc(icon, 12, 19, 12, 210) - fillRect(icon, 6, 5, 12, 2, 170) - return icon - } - - private fun scaleIcon(source: ByteArray, size: Int): ByteArray { - if (size == ICON_SIZE) { - return source - } - val scaled = ByteArray(size * size) - for (y in 0 until size) { - val sy = Math.min(ICON_SIZE - 1, (y * ICON_SIZE) / size) - for (x in 0 until size) { - val sx = Math.min(ICON_SIZE - 1, (x * ICON_SIZE) / size) - scaled[y * size + x] = source[sy * ICON_SIZE + sx] - } - } - return scaled - } - - private fun fillRect(icon: ByteArray, x: Int, y: Int, width: Int, height: Int, value: Int) { - for (row in y until y + height) { - for (col in x until x + width) { - setPixel(icon, col, row, value) - } - } - } - - private fun setPixel(icon: ByteArray, x: Int, y: Int, value: Int) { - if (x < 0 || y < 0 || x >= ICON_SIZE || y >= ICON_SIZE) { - return - } - icon[y * ICON_SIZE + x] = Math.max(0, Math.min(255, value)).toByte() - } - private fun append(out: ByteArrayOutputStream, bytes: ByteArray) { out.write(bytes, 0, bytes.size) } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt index 0e59e435..ad0531bb 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.kt @@ -3,52 +3,21 @@ package com.faceclaw.app import android.content.Context import android.os.Handler import android.os.Looper -import android.os.SystemClock import android.util.Log -import com.k2fsa.sherpa.onnx.FeatureConfig -import com.k2fsa.sherpa.onnx.OfflineModelConfig -import com.k2fsa.sherpa.onnx.OfflineMoonshineModelConfig -import com.k2fsa.sherpa.onnx.OfflineRecognizer -import com.k2fsa.sherpa.onnx.OfflineRecognizerConfig -import com.k2fsa.sherpa.onnx.OfflineRecognizerResult -import com.k2fsa.sherpa.onnx.OfflineStream -import com.k2fsa.sherpa.onnx.OfflineWhisperModelConfig - import java.io.File -import java.nio.charset.StandardCharsets -import java.util.ArrayDeque -import java.util.Arrays +/** + * Android host for the shared [VoiceCaptureSession]: supplies the glasses packet source (the + * BLE communicator), the phone microphone, the sherpa-onnx recognizer and speaker model, model + * directory lookup, recording storage, and main-thread callback delivery. The capture pipeline + * itself (packet queue, beam gate, endpointing, segmented transcript, verification) is shared + * with iOS. + */ class FaceclawVoiceController(context: Context) { companion object { private const val TAG = "FaceclawVoice" private const val SAMPLE_RATE = 16000 - private const val FEATURE_DIM = 80 - private const val MAX_AUDIO_QUEUE_PACKETS = 80 - private const val EXPECTED_PACKET_INTERVAL_MS = 50 - private const val LATE_PACKET_INTERVAL_MS = 90 - private const val STATS_INTERVAL_MS = 5_000 - // Push-to-talk utterance boundaries come from the button. We re-decode the - // current audio segment in full for each live partial and emit the complete - // utterance text (REPLACE, never a delta). The sherpa Moonshine v2 decoder - // used here fails once a single input grows past roughly 9.1 seconds, so - // longer utterances are committed in model-safe segments. - private const val TRANSCRIPT_DECODE_INTERVAL_MS = 700 - private const val TRANSCRIPT_MIN_SAMPLES = SAMPLE_RATE / 3 - private const val TRANSCRIPT_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8 - // When a segment fills, cut at the quietest window within the last - // TRANSCRIPT_CUT_SEARCH_SAMPLES rather than mid-word at the 8s mark; the - // audio after the cut carries over into the next segment. - private const val TRANSCRIPT_CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2 - private const val TRANSCRIPT_CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000 - // Glasses-mic PCM peaks around 0.1 full scale, and at that level the - // quantized Moonshine model often returns empty or garbled text. Boost - // each decode window toward this peak, with a gain cap so near-silent - // buffers aren't amplified into pure noise. - private const val TRANSCRIPT_NORMALIZE_TARGET_PEAK = 0.9f - private const val TRANSCRIPT_NORMALIZE_MAX_GAIN = 30f - private const val TRANSCRIPT_LOG_PREVIEW_CHARS = 80 // Model directory shared with the TS-side download flow (asr-model.ts), // which fetches the Moonshine files here on demand; they are no longer // bundled in the APK. @@ -66,62 +35,18 @@ class FaceclawVoiceController(context: Context) { // Second on-device model: sherpa-onnx's offline Whisper backend (base.en, // int8-quantized -- see the model-choice note in asr-model.ts). Directory // shared with the TS-side download flow, same convention as ASR_MODEL_DIR. - // - // On every call, sherpa-onnx (offline-recognizer-whisper-impl.h, v1.13.0) - // runs Whisper's encoder over the whole buffer plus 1000 frames (~10s) of - // zero tail padding, capped at 30s. Re-decoding on Moonshine's - // TRANSCRIPT_DECODE_INTERVAL_MS live-partial cadence would repeat that - // encode, growing with the utterance, roughly 1.4x/second while the user is - // still speaking, so onboardModelKind gates that loop off for Whisper -- - // see processRecognizer(). Whisper is also known to hallucinate text on - // near-silent input; recognizeTranscriptSegment() gates that too. + // Whisper re-encodes the whole buffer on every call, so the shared session + // skips live partials for it; see VoiceCaptureSession.processRecognizer. private const val ASR_WHISPER_MODEL_DIR = "sherpa-onnx-whisper-base-en-int8" private val ASR_WHISPER_MODEL_FILES = arrayOf( "base.en-encoder.int8.onnx", "base.en-decoder.int8.onnx", "base.en-tokens.txt" ) - // Below this peak amplitude (pre-normalization, of a full-scale +/-1.0f - // buffer) a segment is treated as silence and never reaches the Whisper - // recognizer at all, rather than risking a hallucinated non-answer. Picked - // conservatively low (well under typical mic noise floor already seen in - // this pipeline's normalization target) -- UNTESTED on real hardware, tune - // against real glasses captures rather than trusting this number. - private const val WHISPER_SILENCE_PEAK_THRESHOLD = 0.01f - - // Speaker verification against the enrolled wearer voice-print ("my voice - // only" command gating). Configured before start(); the utterance PCM is - // buffered (capped) and verified once at session end. - private const val VERIFY_MAX_SAMPLES = SAMPLE_RATE * 10 - private const val VERIFY_MIN_SAMPLES = SAMPLE_RATE - // 50 ms chunks match the G2 packet cadence the rest of the pipeline // (endpointing, transcript pacing) is tuned for. private const val PHONE_MIC_CHUNK_SAMPLES = SAMPLE_RATE / 20 - @JvmStatic - private fun buildWavHeader(pcmBytes: Int, sampleRate: Int, channels: Int, bitsPerSample: Int): ByteArray { - val byteRate = sampleRate * channels * bitsPerSample / 8 - val blockAlign = channels * bitsPerSample / 8 - val dataSize = pcmBytes - val riffSize = 36 + dataSize - val b = java.nio.ByteBuffer.allocate(44).order(java.nio.ByteOrder.LITTLE_ENDIAN) - b.put("RIFF".toByteArray(StandardCharsets.US_ASCII)) - b.putInt(riffSize) - b.put("WAVE".toByteArray(StandardCharsets.US_ASCII)) - b.put("fmt ".toByteArray(StandardCharsets.US_ASCII)) - b.putInt(16) // PCM fmt chunk size - b.putShort(1.toShort()) // PCM - b.putShort(channels.toShort()) - b.putInt(sampleRate) - b.putInt(byteRate) - b.putShort(blockAlign.toShort()) - b.putShort(bitsPerSample.toShort()) - b.put("data".toByteArray(StandardCharsets.US_ASCII)) - b.putInt(dataSize) - return b.array() - } - @JvmStatic private fun deleteRecursively(file: File) { if (!file.exists()) { @@ -136,46 +61,6 @@ class FaceclawVoiceController(context: Context) { file.delete() } - @JvmStatic - private fun peakAmplitude(samples: FloatArray): Float { - var peak = 0f - for (s in samples) { - val a = Math.abs(s) - if (a > peak) { - peak = a - } - } - return peak - } - - @JvmStatic - private fun normalizePeak(samples: FloatArray) { - val peak = peakAmplitude(samples) - if (peak <= 0f) { - return - } - val gain = Math.min(TRANSCRIPT_NORMALIZE_TARGET_PEAK / peak, TRANSCRIPT_NORMALIZE_MAX_GAIN) - if (gain <= 1f) { - return - } - for (i in samples.indices) { - samples[i] *= gain - } - } - - @JvmStatic - private fun joinTranscript(prefix: String?, suffix: String?): String { - if (prefix == null || prefix.length == 0) { - return suffix ?: "" - } - if (suffix == null || suffix.length == 0) { - return prefix - } - val first = suffix[0] - val attachesToPrevious = ".,!?;:%)]}".indexOf(first) >= 0 - return prefix + (if (attachesToPrevious) "" else " ") + suffix - } - // The 28 MB embedding model takes seconds to load; keep one instance // across capture sessions so verification adds only the embed time. private var sharedSpeakerId: FaceclawSpeakerId? = null @@ -195,93 +80,68 @@ class FaceclawVoiceController(context: Context) { } } - private enum class VoiceInputMode { - ONBOARD, // on-phone transcription (Moonshine or Whisper; see onboardModelKind) - CLOUD // decode locally, emit PCM for a cloud recognizer on the TS side - } - - /** Which on-device model ONBOARD mode uses. Set via setOnboardModelKind() before start(). */ - private enum class OnboardModelKind { - MOONSHINE, - WHISPER - } - private val appContext: Context = context.applicationContext private val mainHandler = Handler(Looper.getMainLooper()) - private val lock = Any() - private val audioQueueLock = Any() - private val audioQueue = ArrayDeque() - @Volatile - private var listener: FaceclawVoiceControllerListener? = null @Volatile private var communicator: FaceclawBleCommunicator? = null - private var workerThread: Thread? = null - @Volatile - private var started = false - // Set once the worker has the glasses mic enabled for this session. - // Read and written under `lock`, so it flips with `started` atomically. - private var audioStarted = false - // Capture from the phone's own microphone instead of the G2 over BLE - // (preview-only mode, where no glasses are connected). Latched into - // activePhoneMic at start() (under `lock`) so a mid-session setter call - // can't switch pipelines underneath the worker. - @Volatile - private var usePhoneMic = false - private var activePhoneMic = false - private var mode = VoiceInputMode.CLOUD - @Volatile - private var onboardModelKind = OnboardModelKind.MOONSHINE - private var recognizer: OfflineRecognizer? = null - private var lc3Decoder: FaceclawLc3Decoder? = null - private val transcriptSamples = FloatArray(TRANSCRIPT_SEGMENT_MAX_SAMPLES) - private var transcriptSampleCount = 0 - private var committedTranscriptSampleCount: Long = 0 - private var committedTranscript = "" - private var currentSegmentTranscript = "" - private var lastTranscriptDecodeAtMs: Long = 0 - private var lastTranscript = "" - @Volatile - private var saveRecordings = false - @Volatile - private var endpointing = false - private val endpointDetector = VoiceEndpointDetector() - private var recordingPcm: java.io.ByteArrayOutputStream? = null - // Speaker verification against the enrolled wearer voice-print ("my voice - // only" command gating). Configured before start(); the utterance PCM is - // buffered (capped) and verified once at session end. - @Volatile - private var verifySpeakerModelPath: String? = null - @Volatile - private var verifyWearerEmbedding: FloatArray? = null - @Volatile - private var verifyThreshold = 0.8f - private var verifyBuffer: ShortArray? = null - private var verifyCount = 0 - // Global mic processing (Microphones app config): spectral noise - // suppression and firmware-DoA beam gating, applied to every capture - // session that opts in (assistant push-to-talk, Transcribe, hands-free). - // The raw tap opts out — raw means raw, and the Microphones session does - // its own beam-compensated processing on that path. - @Volatile - private var suppressionEnabled = false - @Volatile - private var beamFilterEnabled = false - @Volatile - private var beamCenterDeg = 0 - @Volatile - private var beamHalfWidthDeg = 180 - private var suppressor: FaceclawNoiseSuppressor? = null - private var queuedPackets: Long = 0 - private var queueDroppedPackets: Long = 0 - private var decodedSamples: Long = 0 - private var latePackets: Long = 0 - private var wrongArmPackets: Long = 0 - private var lastPacketArrivalMs: Long = 0 - private var maxInterPacketMs: Long = 0 - private var lastStatsAtMs: Long = 0 + + private val host = object : VoiceCaptureHost { + override val dispatcher = CallbackDispatcher { action -> mainHandler.post { action() } } + + override fun onSessionStarting() { + deleteLegacyKwsFiles() + } + + override fun isG2SessionReady(): Boolean { + val currentCommunicator = communicator + return currentCommunicator != null && currentCommunicator.isSessionReady() + } + + override fun isG2AudioCaptureActive(): Boolean { + val currentCommunicator = communicator + return currentCommunicator != null && currentCommunicator.isAudioCaptureActive() + } + + override fun g2AudioSource(): PacketAudioSource? { + val currentCommunicator = communicator ?: return null + return object : PacketAudioSource { + override fun start(listener: FaceclawAudioPacketListener): Boolean = + currentCommunicator.startG2AudioCapture(listener) + + override fun stop() = currentCommunicator.stopG2AudioCapture() + + override fun isActive(): Boolean = currentCommunicator.isAudioCaptureActive() + } + } + + override fun createPacketDecoder(): AudioPacketDecoder = AndroidSpeechEngines.Lc3DecoderAdapter() + + override fun openPhoneMic(): PcmAudioSource? = AndroidSpeechEngines.openPhoneMic(PHONE_MIC_CHUNK_SAMPLES) + + override fun hasTranscriberModel(kind: VoiceModelKind): Boolean = findAsrModelDir(kind) != null + + override fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber { + val modelDir = findAsrModelDir(kind) ?: throw IllegalStateException("voice model missing") + return AndroidSpeechEngines.SherpaTranscriber(AndroidSpeechEngines.recognizerConfig(modelDir, kind)) + } + + override fun speakerEmbedder(modelPath: String): SpeakerEmbedder { + val cached = cachedSpeakerId(modelPath) + // The cached model outlives the session; never release it here. + return object : SpeakerEmbedder { + override fun embed(pcm16le: ByteArray, sampleRate: Int): FloatArray? = cached.embed(pcm16le, sampleRate) + + override fun release() {} + } + } + + override fun recordingSink(): RecordingSink = RecordingSink { pcmBytes, sampleRate -> saveRecording(pcmBytes, sampleRate) } + } + + private val session = VoiceCaptureSession(host) fun setListener(listener: FaceclawVoiceControllerListener?) { - this.listener = listener + session.setListener(listener) } fun setCommunicator(communicator: FaceclawBleCommunicator?) { @@ -290,23 +150,22 @@ class FaceclawVoiceController(context: Context) { /** Source the next capture from the phone microphone (no glasses paired). */ fun setUsePhoneMic(usePhoneMic: Boolean) { - this.usePhoneMic = usePhoneMic + session.setUsePhoneMic(usePhoneMic) } /** When true, the decoded mic PCM for each session is saved as a WAV. */ fun setSaveRecordings(saveRecordings: Boolean) { - this.saveRecordings = saveRecordings + session.setSaveRecordings(saveRecordings) } /** * Which on-device model {@link #start}("onboard") should load: "whisper" * selects the second on-device model (sherpa-onnx offline Whisper); any - * other value (including null/absent) keeps the existing Moonshine model, - * so callers that never call this see unchanged behavior. Must be set - * before {@link #start}; has no effect in CLOUD mode. + * other value (including null/absent) keeps the existing Moonshine model. + * Must be set before {@link #start}; has no effect in CLOUD mode. */ fun setOnboardModelKind(kind: String?) { - this.onboardModelKind = if ("whisper" == kind) OnboardModelKind.WHISPER else OnboardModelKind.MOONSHINE + session.setOnboardModelKind(kind) } /** @@ -315,7 +174,7 @@ class FaceclawVoiceController(context: Context) { * button release to end the utterance. Must be set before {@link #start}. */ fun setEndpointing(endpointing: Boolean) { - this.endpointing = endpointing + session.setEndpointing(endpointing) } /** @@ -325,19 +184,16 @@ class FaceclawVoiceController(context: Context) { * to disable. */ fun setSpeakerVerification(speakerModelPath: String?, wearerEmbedding: FloatArray?, threshold: Float) { - this.verifySpeakerModelPath = speakerModelPath - this.verifyWearerEmbedding = wearerEmbedding - this.verifyThreshold = if (threshold > 0) threshold else 0.8f + session.setSpeakerVerification(speakerModelPath, wearerEmbedding, threshold) } fun clearSpeakerVerification() { - this.verifySpeakerModelPath = null - this.verifyWearerEmbedding = null + session.clearSpeakerVerification() } /** Spectral noise suppression on the decoded stream. Safe to flip mid-run. */ fun setNoiseSuppression(enabled: Boolean) { - this.suppressionEnabled = enabled + session.setNoiseSuppression(enabled) } /** @@ -347,62 +203,15 @@ class FaceclawVoiceController(context: Context) { * consumer sees them. Safe to update mid-run. */ fun setBeamFilter(enabled: Boolean, centerDeg: Int, halfWidthDeg: Int) { - this.beamFilterEnabled = enabled - this.beamCenterDeg = centerDeg - this.beamHalfWidthDeg = Math.max(5, Math.min(180, halfWidthDeg)) - } - - private fun withinBeam(angleDegrees: Int): Boolean { - var delta = angleDegrees - beamCenterDeg - while (delta > 180) delta -= 360 - while (delta < -180) delta += 360 - return Math.abs(delta) <= beamHalfWidthDeg - } - - private fun applySuppression(pcm: ShortArray, count: Int) { - try { - if (suppressor == null) { - suppressor = FaceclawNoiseSuppressor(SAMPLE_RATE) - } - val le = ByteArray(count * 2) - for (i in 0 until count) { - le[i * 2] = (pcm[i].toInt() and 0xff).toByte() - le[i * 2 + 1] = ((pcm[i].toInt() shr 8) and 0xff).toByte() - } - val cleaned = suppressor!!.process(le)!! - val cleanedCount = Math.min(count, cleaned.size / 2) - for (i in 0 until cleanedCount) { - pcm[i] = ((cleaned[i * 2].toInt() and 0xff) or (cleaned[i * 2 + 1].toInt() shl 8)).toShort() - } - } catch (t: Throwable) { - Log.w(TAG, "noise suppression failed; passing audio through", t) - suppressionEnabled = false - } + session.setBeamFilter(enabled, centerDeg, halfWidthDeg) } fun start(requestedMode: String?) { - start(requestedMode, 0) + session.start(requestedMode, 0) } fun start(requestedMode: String?, captureId: Int) { - synchronized(lock) { - if (started) { - emitStatus("Voice control is already listening.") - emitStopped(captureId) - return - } - if (!usePhoneMic && (communicator == null || !communicator!!.isSessionReady())) { - emitStatus("Voice control needs an active G2 connection.") - emitStopped(captureId) - return - } - mode = parseMode(requestedMode) - activePhoneMic = usePhoneMic - started = true - audioStarted = false - workerThread = Thread(Runnable { runLoop(captureId) }, "FaceclawVoiceController") - workerThread!!.start() - } + session.start(requestedMode, captureId) } /** @@ -412,223 +221,39 @@ class FaceclawVoiceController(context: Context) { * worker that will never see another packet. Anything deciding whether to * (re)start capture must ask this rather than assume its own bookkeeping. */ - fun isCapturing(): Boolean { - val audioUp: Boolean - val phoneMic: Boolean - synchronized(lock) { - if (!started) { - return false - } - audioUp = audioStarted - phoneMic = activePhoneMic - } - if (!audioUp) { - // The worker is still bringing the mic up; report it as running so - // a concurrent request shares it instead of restarting it. - return true - } - if (phoneMic) { - // AudioRecord has no session to lose the enable to; it runs until stop(). - return true - } - val currentCommunicator = communicator - return currentCommunicator != null && currentCommunicator.isAudioCaptureActive() - } + fun isCapturing(): Boolean = session.isCapturing() fun stop() { - val threadToJoin: Thread? - synchronized(lock) { - if (!started) { - return - } - started = false - threadToJoin = workerThread - } - stopG2Audio() - synchronized(audioQueueLock) { - (audioQueueLock as java.lang.Object).notifyAll() - } - if (threadToJoin != null) { - threadToJoin.interrupt() - if (Thread.currentThread() !== threadToJoin) { - try { - threadToJoin.join(1500) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - } - } - } + session.stop() } fun close() { stop() } - private fun parseMode(requestedMode: String?): VoiceInputMode { - if ("cloud" == requestedMode) { - return VoiceInputMode.CLOUD - } - return VoiceInputMode.ONBOARD - } - - private fun runLoop(captureId: Int) { - try { - deleteLegacyKwsFiles() - val currentMode = mode - val currentOnboardKind = onboardModelKind - if (currentMode == VoiceInputMode.ONBOARD) { - val modelDir = findAsrModelDir(currentOnboardKind) - if (modelDir == null) { - emitStatus("Voice model not downloaded (see Settings > Voice).") - return - } - emitStatus("Loading transcription model...") - recognizer = OfflineRecognizer(buildRecognizerConfig(modelDir, currentOnboardKind)) - resetTranscriptState() - lastTranscript = "" - } - endpointDetector.reset() - if (suppressor != null) { - suppressor!!.reset() - } - recordingPcm = if (saveRecordings) java.io.ByteArrayOutputStream(SAMPLE_RATE * 2 * 4) else null - val verifying = verifySpeakerModelPath != null && verifyWearerEmbedding != null - verifyBuffer = if (verifying) ShortArray(VERIFY_MAX_SAMPLES) else null - verifyCount = 0 - if (activePhoneMic) { - val record = openPhoneMic() - if (record == null) { - emitStatus("Could not start the phone microphone.") - return - } - synchronized(lock) { - audioStarted = true - } - emitStatus(if (currentMode == VoiceInputMode.CLOUD) - "Listening (cloud)..." - else - "Listening...") - try { - processPhoneAudio(record) - } finally { - try { - record.stop() - } catch (ignored: Throwable) { - // Already stopped or never recording; release below either way. - } - record.release() - } - } else { - lc3Decoder = FaceclawLc3Decoder() - if (!startG2Audio()) { - emitStatus("Could not start G2 microphone input.") - return - } - synchronized(lock) { - audioStarted = true - } - emitStatus(if (currentMode == VoiceInputMode.CLOUD) - "Listening (cloud)..." - else - "Listening...") - processG2Audio() - } - // Verification result must precede the final transcript so the - // TS bridge can suppress a non-wearer command before it is acted - // on (the callbacks are posted in order to the main handler). - runSpeakerVerification() - // Button released / stop requested: emit one final full-utterance - // transcript so the UI can freeze it. - if (currentMode == VoiceInputMode.ONBOARD) { - decodeTranscript(true) - } - } catch (error: Throwable) { - Log.e(TAG, "Voice control failed", error) - emitStatus("Voice control failed: " + error.message) - } finally { - stopG2Audio() - writeRecordingIfAny() - releaseSherpa() - releaseLc3() - synchronized(lock) { - started = false - audioStarted = false - workerThread = null - } - emitStopped(captureId) - } - } - - private fun appendRecording(pcm: ShortArray, count: Int) { - val out = recordingPcm - if (out == null) { - return - } - for (i in 0 until count) { - val s = pcm[i].toInt() - out.write(s and 0xff) - out.write((s shr 8) and 0xff) - } - } - /** Save the session's decoded mic PCM as a 16 kHz mono 16-bit WAV. */ - private fun writeRecordingIfAny() { - val out = recordingPcm - recordingPcm = null - if (out == null || out.size() == 0) { - return - } + private fun saveRecording(pcmBytes: ByteArray, sampleRate: Int) { try { - val pcmBytes = out.toByteArray() - val dir = java.io.File(appContext.getExternalFilesDir(null), "voice-recordings") + val dir = File(appContext.getExternalFilesDir(null), "voice-recordings") if (!dir.exists() && !dir.mkdirs()) { Log.w(TAG, "could not create voice-recordings dir") return } val stamp = java.text.SimpleDateFormat("yyyyMMdd-HHmmss-SSS", java.util.Locale.US) .format(java.util.Date()) - val file = java.io.File(dir, "voice-$stamp.wav") + val file = File(dir, "voice-$stamp.wav") java.io.FileOutputStream(file).use { fos -> - fos.write(buildWavHeader(pcmBytes.size, SAMPLE_RATE, 1, 16)) + fos.write(BinaryEncoding.wavHeader(pcmBytes.size, sampleRate, 1)) fos.write(pcmBytes) } Log.i(TAG, "saved voice recording " + file.absolutePath + " samples=" + (pcmBytes.size / 2) - + " sec=" + String.format(java.util.Locale.US, "%.2f", pcmBytes.size / 2.0 / SAMPLE_RATE)) + + " sec=" + String.format(java.util.Locale.US, "%.2f", pcmBytes.size / 2.0 / sampleRate)) } catch (t: Throwable) { Log.w(TAG, "failed to save voice recording", t) } } - private fun buildRecognizerConfig(modelDir: File, kind: OnboardModelKind): OfflineRecognizerConfig { - val modelConfig = OfflineModelConfig.builder() - .setNumThreads(1) - if (kind == OnboardModelKind.WHISPER) { - modelConfig - .setWhisper(OfflineWhisperModelConfig.builder() - .setEncoder(File(modelDir, "base.en-encoder.int8.onnx").absolutePath) - .setDecoder(File(modelDir, "base.en-decoder.int8.onnx").absolutePath) - .setLanguage("en") - .setTask("transcribe") - .build()) - .setTokens(File(modelDir, "base.en-tokens.txt").absolutePath) - } else { - modelConfig - .setMoonshine(OfflineMoonshineModelConfig.builder() - .setEncoder(File(modelDir, "encoder_model.ort").absolutePath) - .setMergedDecoder(File(modelDir, "decoder_model_merged.ort").absolutePath) - .build()) - .setTokens(File(modelDir, "tokens.txt").absolutePath) - } - return OfflineRecognizerConfig.builder() - .setFeatureConfig(FeatureConfig.builder() - .setSampleRate(SAMPLE_RATE) - .setFeatureDim(FEATURE_DIM) - .build()) - .setModelConfig(modelConfig.build()) - .build() - } - /** * The on-device model directory for the given kind, populated by the * download flow in asr-model.ts (releases before 0.5.0 copied the @@ -636,8 +261,8 @@ class FaceclawVoiceController(context: Context) { * already complete for that model). Null when any expected file is * missing, i.e. the model still needs to be downloaded. */ - private fun findAsrModelDir(kind: OnboardModelKind): File? { - val whisper = kind == OnboardModelKind.WHISPER + private fun findAsrModelDir(kind: VoiceModelKind): File? { + val whisper = kind == VoiceModelKind.WHISPER val dirName = if (whisper) ASR_WHISPER_MODEL_DIR else ASR_MODEL_DIR val fileNames = if (whisper) ASR_WHISPER_MODEL_FILES else ASR_MODEL_FILES val modelDir = File(appContext.filesDir, ASR_ROOT + File.separator + dirName) @@ -657,530 +282,4 @@ class FaceclawVoiceController(context: Context) { Log.w(TAG, "failed to delete legacy wake-word files", t) } } - - private fun startG2Audio(): Boolean { - val currentCommunicator = communicator - if (currentCommunicator == null) { - return false - } - resetAudioStats() - synchronized(audioQueueLock) { - audioQueue.clear() - } - return currentCommunicator.startG2AudioCapture(object : FaceclawAudioPacketListener { - override fun onAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { - queueAudioPacket(data, arm, arrivalMs) - } - }) - } - - private fun processG2Audio() { - val pcm = ShortArray(FaceclawLc3Decoder.SAMPLES_PER_PACKET) - while (started && !Thread.currentThread().isInterrupted) { - val currentDecoder = lc3Decoder - if (currentDecoder == null) { - return - } - - val packet = takeAudioPacket() - if (packet == null) { - continue - } - - val count = currentDecoder.decodePacket(packet.data, pcm) - if (count <= 0) { - maybeEmitAudioStats(false) - continue - } - decodedSamples += count.toLong() - // Global mic processing from the Microphones app config: the - // beam filter drops packets whose firmware direction-of-arrival - // falls outside the listening wedge (isolating the aimed talker - // for every consumer, recognition included), and the spectral - // noise suppressor cleans what remains before it reaches the - // recognizer, cloud PCM, endpointing, or speaker verification. - val angleDegrees = currentDecoder.getLastAngleDegrees() - val ssr = currentDecoder.getLastSsr() - if (beamFilterEnabled && ssr > 0 && !withinBeam(angleDegrees)) { - emitFrameMeta(angleDegrees, ssr) - maybeEmitAudioStats(false) - continue - } - processPcmChunk(pcm, count, angleDegrees, ssr, true) - maybeEmitAudioStats(false) - } - } - - /** - * Per-chunk processing shared by the G2 and phone-mic paths, downstream of - * decode and the beam filter. hasFrameMeta is false for the phone mic, - * which has no firmware DSP metadata to report. - */ - private fun processPcmChunk(pcm: ShortArray, count: Int, angleDegrees: Int, ssr: Int, hasFrameMeta: Boolean) { - if (suppressionEnabled) { - applySuppression(pcm, count) - } - if (recordingPcm != null) { - appendRecording(pcm, count) - } - val verifyBuffer = this.verifyBuffer - if (verifyBuffer != null && verifyCount < VERIFY_MAX_SAMPLES) { - val copied = Math.min(count, VERIFY_MAX_SAMPLES - verifyCount) - System.arraycopy(pcm, 0, verifyBuffer, verifyCount, copied) - verifyCount += copied - } - if (endpointing && endpointDetector.accept(pcm, count)) { - emitSpeechEnd() - } - // PCM and frame metadata flow in every mode so levels, recording, - // and the Microphones radar keep working alongside onboard ASR. - emitPcm(pcm, count) - if (hasFrameMeta) { - emitFrameMeta(angleDegrees, ssr) - } - if (mode != VoiceInputMode.CLOUD) { - val samples = FloatArray(count) - for (i in 0 until count) { - samples[i] = pcm[i] / 32768.0f - } - processRecognizer(samples) - } - } - - /** - * Open the phone's own microphone at the pipeline's native format - * (16 kHz mono PCM16), or null when it cannot start — the permission is - * missing (SecurityException) or the device refuses the configuration. - */ - private fun openPhoneMic(): android.media.AudioRecord? { - var record: android.media.AudioRecord? = null - try { - val minBytes = android.media.AudioRecord.getMinBufferSize( - SAMPLE_RATE, - android.media.AudioFormat.CHANNEL_IN_MONO, - android.media.AudioFormat.ENCODING_PCM_16BIT) - val bufferBytes = Math.max(minBytes, PHONE_MIC_CHUNK_SAMPLES * 2 * 4) - record = android.media.AudioRecord( - android.media.MediaRecorder.AudioSource.VOICE_RECOGNITION, - SAMPLE_RATE, - android.media.AudioFormat.CHANNEL_IN_MONO, - android.media.AudioFormat.ENCODING_PCM_16BIT, - bufferBytes) - if (record.state != android.media.AudioRecord.STATE_INITIALIZED) { - record.release() - return null - } - record.startRecording() - if (record.recordingState != android.media.AudioRecord.RECORDSTATE_RECORDING) { - record.release() - return null - } - return record - } catch (t: Throwable) { - Log.w(TAG, "phone mic open failed", t) - if (record != null) { - record.release() - } - return null - } - } - - /** - * Phone-mic capture loop: no LC3 decode, no arm bookkeeping, no frame - * metadata — AudioRecord already delivers the pipeline's PCM format. The - * blocking read returns every chunk (50 ms), which bounds how long a - * stop() waits for the loop to notice `started` dropped. - */ - private fun processPhoneAudio(record: android.media.AudioRecord) { - val pcm = ShortArray(PHONE_MIC_CHUNK_SAMPLES) - while (started && !Thread.currentThread().isInterrupted) { - val read = record.read(pcm, 0, pcm.size) - if (read < 0) { - Log.w(TAG, "phone mic read failed: $read") - return - } - if (read == 0) { - continue - } - decodedSamples += read.toLong() - processPcmChunk(pcm, read, 0, 0, false) - } - } - - private fun processRecognizer(samples: FloatArray) { - appendTranscriptSamples(samples) - // Each Whisper call re-encodes the whole buffer plus ~10s of tail - // padding (see the ASR_WHISPER_* comment above), - // so it skips the live-partial redecode Moonshine does on this - // interval and only decodes when a segment commits (8s buffer fill) - // or the utterance ends (decodeTranscript(true) in runLoop()). This - // means no live preview text while speaking in Whisper mode -- status - // stays "Listening..." until release. This is a deliberate tradeoff. - if (onboardModelKind == OnboardModelKind.WHISPER) { - return - } - val now = SystemClock.elapsedRealtime() - if (transcriptSampleCount >= TRANSCRIPT_MIN_SAMPLES - && now - lastTranscriptDecodeAtMs >= TRANSCRIPT_DECODE_INTERVAL_MS) { - decodeTranscript(false) - lastTranscriptDecodeAtMs = now - } - } - - private fun appendTranscriptSamples(samples: FloatArray) { - var sourceOffset = 0 - while (sourceOffset < samples.size) { - val available = TRANSCRIPT_SEGMENT_MAX_SAMPLES - transcriptSampleCount - val count = Math.min(available, samples.size - sourceOffset) - System.arraycopy(samples, sourceOffset, transcriptSamples, transcriptSampleCount, count) - transcriptSampleCount += count - sourceOffset += count - - if (transcriptSampleCount == TRANSCRIPT_SEGMENT_MAX_SAMPLES) { - commitTranscriptSegment() - } - } - } - - /** - * Decode the current model-safe segment and emit the best transcript of the - * complete utterance (REPLACE semantics — the caller displays it as-is). - */ - private fun decodeTranscript(isFinal: Boolean) { - if (recognizer == null || transcriptSampleCount <= 0) { - if (isFinal) { - emitTranscript(lastTranscript, true) - } - return - } - val segmentSampleCount = transcriptSampleCount - var segmentText = recognizeTranscriptSegment(segmentSampleCount) - if (segmentText.length > 0) { - currentSegmentTranscript = segmentText - } else { - segmentText = currentSegmentTranscript - } - val text = joinTranscript(committedTranscript, segmentText) - lastTranscript = text - logTranscriptDecode(isFinal, segmentSampleCount, text) - emitTranscript(text, isFinal) - } - - /** - * Finalize a full segment before accepting more audio. This keeps every - * Moonshine invocation below its failing sequence length while retaining - * all earlier text in the replace-semantics preview. - */ - private fun commitTranscriptSegment() { - val cut = findSegmentCutPoint() - var segmentText = recognizeTranscriptSegment(cut) - if (segmentText.length == 0) { - // Fallback text came from partial decodes of the full buffer, so it - // may include words from the carried-over tail; rare now that decode - // windows are peak-normalized. - segmentText = currentSegmentTranscript - } - committedTranscript = joinTranscript(committedTranscript, segmentText) - currentSegmentTranscript = "" - committedTranscriptSampleCount += cut.toLong() - val tail = transcriptSampleCount - cut - System.arraycopy(transcriptSamples, cut, transcriptSamples, 0, tail) - transcriptSampleCount = tail - lastTranscript = committedTranscript - lastTranscriptDecodeAtMs = SystemClock.elapsedRealtime() - logTranscriptDecode(false, cut, committedTranscript) - emitTranscript(committedTranscript, false) - } - - /** - * Pick where to end the committed segment: the center of the quietest - * window within the search region at the end of the buffer, so the cut - * lands between words instead of splitting one. - */ - private fun findSegmentCutPoint(): Int { - val count = transcriptSampleCount - val searchStart = Math.max(0, count - TRANSCRIPT_CUT_SEARCH_SAMPLES) - val win = TRANSCRIPT_CUT_WINDOW_SAMPLES - if (count - searchStart <= win) { - return count - } - var sum = 0.0 - for (i in searchStart until searchStart + win) { - sum += transcriptSamples[i].toDouble() * transcriptSamples[i] - } - var best = sum - var bestStart = searchStart - var start = searchStart + 1 - while (start + win <= count) { - val dropped = transcriptSamples[start - 1] - val added = transcriptSamples[start + win - 1] - sum += added.toDouble() * added - dropped.toDouble() * dropped - if (sum < best) { - best = sum - bestStart = start - } - start++ - } - return bestStart + win / 2 - } - - private fun recognizeTranscriptSegment(sampleCount: Int): String { - val currentRecognizer = recognizer - if (currentRecognizer == null || sampleCount <= 0) { - return "" - } - val segment = Arrays.copyOf(transcriptSamples, sampleCount) - // Whisper hallucinates text on near-silent input (a known quirk of the - // model, not this pipeline); gate it on the PRE-normalization peak, since - // normalizePeak() below would otherwise amplify true silence right up to - // the target level and hide the very thing being checked for. Moonshine - // does not share this failure mode in practice, so it is left unchanged. - if (onboardModelKind == OnboardModelKind.WHISPER && peakAmplitude(segment) < WHISPER_SILENCE_PEAK_THRESHOLD) { - return "" - } - normalizePeak(segment) - val offlineStream: OfflineStream = currentRecognizer.createStream() - try { - offlineStream.acceptWaveform(segment, SAMPLE_RATE) - currentRecognizer.decode(offlineStream) - val result: OfflineRecognizerResult? = currentRecognizer.getResult(offlineStream) - val raw: String? = if (result == null) "" else result.text - return raw?.trim() ?: "" - } finally { - offlineStream.release() - } - } - - private fun logTranscriptDecode(isFinal: Boolean, segmentSampleCount: Int, text: String) { - val totalAudioSec = - (committedTranscriptSampleCount + transcriptSampleCount) / SAMPLE_RATE.toDouble() - val preview = if (text.length <= TRANSCRIPT_LOG_PREVIEW_CHARS) - text else text.substring(0, TRANSCRIPT_LOG_PREVIEW_CHARS) + "..." - Log.i(TAG, (if (onboardModelKind == OnboardModelKind.WHISPER) "Whisper" else "Moonshine") + " decode final=" + isFinal - + " audioSec=" + String.format(java.util.Locale.US, "%.2f", totalAudioSec) - + " segmentAudioSec=" + String.format(java.util.Locale.US, "%.2f", segmentSampleCount / SAMPLE_RATE.toDouble()) - + " textLen=" + text.length + " text=\"" + preview + "\"") - } - - private fun resetTranscriptState() { - transcriptSampleCount = 0 - committedTranscriptSampleCount = 0 - committedTranscript = "" - currentSegmentTranscript = "" - lastTranscriptDecodeAtMs = 0 - } - - private fun emitPcm(pcm: ShortArray, count: Int) { - val currentListener = listener - if (currentListener == null || count <= 0) { - return - } - val le = ByteArray(count * 2) - for (i in 0 until count) { - val s = pcm[i].toInt() - le[i * 2] = (s and 0xff).toByte() - le[i * 2 + 1] = ((s shr 8) and 0xff).toByte() - } - mainHandler.post { currentListener.onPcm(le) } - } - - /** - * Embed the session's buffered utterance and compare it to the enrolled - * wearer voice-print. Fails open: a session too short to verify, or a - * model that will not load, counts as the wearer rather than silencing - * every command. - */ - private fun runSpeakerVerification() { - val buffer = verifyBuffer - val wearer = verifyWearerEmbedding - val modelPath = verifySpeakerModelPath - verifyBuffer = null - if (buffer == null || wearer == null || modelPath == null) { - return - } - if (verifyCount < VERIFY_MIN_SAMPLES) { - emitSpeakerVerified(true, 0f) - return - } - val speakerId = cachedSpeakerId(modelPath) - try { - val le = ByteArray(verifyCount * 2) - for (i in 0 until verifyCount) { - val s = buffer[i].toInt() - le[i * 2] = (s and 0xff).toByte() - le[i * 2 + 1] = ((s shr 8) and 0xff).toByte() - } - val embedding = speakerId.embed(le, SAMPLE_RATE) - if (embedding == null || embedding.size != wearer.size) { - emitSpeakerVerified(true, 0f) - return - } - var dot = 0.0 - for (i in embedding.indices) { - dot += embedding[i].toDouble() * wearer[i] - } - val isWearer = dot >= verifyThreshold - Log.i(TAG, "speaker verification similarity=" + String.format(java.util.Locale.US, "%.3f", dot) - + " threshold=" + verifyThreshold + " isWearer=" + isWearer) - emitSpeakerVerified(isWearer, dot.toFloat()) - } catch (t: Throwable) { - Log.w(TAG, "speaker verification failed", t) - emitSpeakerVerified(true, 0f) - } - } - - private fun emitSpeakerVerified(isWearer: Boolean, similarity: Float) { - val currentListener = listener - if (currentListener == null) { - return - } - mainHandler.post { currentListener.onSpeakerVerified(isWearer, similarity) } - } - - private fun emitFrameMeta(angleDegrees: Int, ssr: Int) { - val currentListener = listener - if (currentListener == null) { - return - } - mainHandler.post { currentListener.onFrameMeta(angleDegrees, ssr) } - } - - private fun emitSpeechEnd() { - val currentListener = listener - if (currentListener == null) { - return - } - mainHandler.post { currentListener.onSpeechEnd() } - } - - private fun emitStopped(captureId: Int) { - val currentListener = listener - if (currentListener != null) { - mainHandler.post { currentListener.onStopped(captureId) } - } - } - - private fun stopG2Audio() { - val currentCommunicator = communicator - if (currentCommunicator != null) { - currentCommunicator.stopG2AudioCapture() - } - maybeEmitAudioStats(true) - } - - private fun releaseSherpa() { - if (recognizer != null) { - recognizer!!.release() - recognizer = null - } - } - - private fun releaseLc3() { - if (lc3Decoder != null) { - lc3Decoder!!.close() - lc3Decoder = null - } - } - - private fun queueAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { - if (!started || data == null) { - return - } - if ("L" != arm) { - wrongArmPackets++ - } - synchronized(audioQueueLock) { - if (audioQueue.size >= MAX_AUDIO_QUEUE_PACKETS) { - audioQueue.removeFirst() - queueDroppedPackets++ - } - audioQueue.addLast(AudioPacket(data, arm, arrivalMs)) - queuedPackets++ - if (lastPacketArrivalMs > 0) { - val delta = arrivalMs - lastPacketArrivalMs - if (delta > maxInterPacketMs) { - maxInterPacketMs = delta - } - if (delta > LATE_PACKET_INTERVAL_MS) { - latePackets++ - } - } - lastPacketArrivalMs = arrivalMs - (audioQueueLock as java.lang.Object).notifyAll() - } - } - - private fun takeAudioPacket(): AudioPacket? { - synchronized(audioQueueLock) { - while (started && audioQueue.isEmpty()) { - try { - (audioQueueLock as java.lang.Object).wait(250) - maybeEmitAudioStats(false) - } catch (e: InterruptedException) { - Thread.currentThread().interrupt() - return null - } - } - return audioQueue.pollFirst() - } - } - - private fun resetAudioStats() { - queuedPackets = 0 - queueDroppedPackets = 0 - decodedSamples = 0 - latePackets = 0 - wrongArmPackets = 0 - lastPacketArrivalMs = 0 - maxInterPacketMs = 0 - lastStatsAtMs = SystemClock.elapsedRealtime() - } - - private fun maybeEmitAudioStats(force: Boolean) { - val now = SystemClock.elapsedRealtime() - if (!force && now - lastStatsAtMs < STATS_INTERVAL_MS) { - return - } - lastStatsAtMs = now - val currentDecoder = lc3Decoder - val real = if (currentDecoder == null) 0L else currentDecoder.getRealPackets() - val duplicate = if (currentDecoder == null) 0L else currentDecoder.getDuplicatePackets() - val missing = if (currentDecoder == null) 0L else currentDecoder.getMissingPackets() - val decodeErrors = if (currentDecoder == null) 0L else currentDecoder.getDecodeErrors() - val status = "G2 mic packets=" + queuedPackets + - " decoded=" + real + - " missing=" + missing + - " duplicate=" + duplicate + - " late=" + latePackets + - " maxGapMs=" + maxInterPacketMs + - "\n" + - " queueDrop=" + queueDroppedPackets + - " decodeErrors=" + decodeErrors + - " wrongArm=" + wrongArmPackets + - " audioSec=" + String.format(java.util.Locale.US, "%.1f", decodedSamples / SAMPLE_RATE.toDouble()) - // Audio-pipeline stats are diagnostic; keep them in logcat only, out of - // the on-glasses voice UI. - Log.i(TAG, status.replace('\n', ' ') + " expectedIntervalMs=" + EXPECTED_PACKET_INTERVAL_MS) - } - - private fun emitStatus(status: String?) { - val currentListener = listener - if (currentListener == null) { - return - } - mainHandler.post { currentListener.onStatus(status) } - } - - private fun emitTranscript(text: String?, isFinal: Boolean) { - val currentListener = listener - if (currentListener == null) { - return - } - Log.i(TAG, "Emit transcript final=" + isFinal + " textLen=" + (text?.trim()?.length ?: 0)) - mainHandler.post { currentListener.onTranscript(text, isFinal) } - } - - private class AudioPacket(val data: ByteArray?, arm: String?, val arrivalMs: Long) { - val arm: String = arm ?: "?" - } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt index e6b717ec..fa33d1c3 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FontFileRenderer.kt @@ -11,7 +11,6 @@ import android.util.Log import java.io.File import java.io.RandomAccessFile import java.nio.ByteBuffer -import java.nio.ByteOrder import java.util.LinkedHashMap /** @@ -20,7 +19,9 @@ import java.util.LinkedHashMap * minikin/HarfBuzz. Output uses the same grayscale packet format as * ImageFileLoader ([widthLo, widthHi, heightLo, heightHi, pixels...], one * byte per pixel, row-major), which the TS side turns into a GrayImage and - * the compositor later quantizes to the 4bpp the firmware wants. + * the compositor later quantizes to the 4bpp the firmware wants. The packet + * layouts, gamma mapping and ink cropping are shared with iOS in GlyphPacket; + * only rasterization lives here. * * The gamma parameter maps antialiased coverage to output shade: * out = 255 * (coverage/255)^gamma. The G2 display response looks roughly @@ -88,27 +89,13 @@ class FontFileRenderer private constructor() { // keep at least the advance width so spacing stays truthful. var left = pad var right = pad + advance - val painted = paintedColumnRange(pixels, width, height) + val painted = GlyphPacket.paintedColumnRange(pixels, width, height) if (painted != null) { left = Math.min(left, painted[0]) right = Math.max(right, painted[1] + 1) } val outWidth = Math.max(1, right - left) - - val lut = gammaLut(gamma) - val out = ByteArray(4 + outWidth * height) - out[0] = (outWidth and 0xff).toByte() - out[1] = ((outWidth shr 8) and 0xff).toByte() - out[2] = (height and 0xff).toByte() - out[3] = ((height shr 8) and 0xff).toByte() - for (y in 0 until height) { - val srcRow = y * width - val dstRow = 4 + y * outWidth - for (x in 0 until outWidth) { - out[dstRow + x] = lut[pixels[srcRow + left + x].toInt() and 0xff] - } - } - return out + return GlyphPacket.packImageRegion(pixels, width, left, 0, outWidth, height, gamma) } catch (e: Exception) { Log.w(TAG, "text render failed: $path", e) return ByteArray(0) @@ -159,16 +146,7 @@ class FontFileRenderer private constructor() { val pixels = alpha8Pixels(bitmap, maxWidth, height) bitmap.recycle() - val lut = gammaLut(gamma) - val out = ByteArray(4 + pixels.size) - out[0] = (maxWidth and 0xff).toByte() - out[1] = ((maxWidth shr 8) and 0xff).toByte() - out[2] = (height and 0xff).toByte() - out[3] = ((height shr 8) and 0xff).toByte() - for (i in pixels.indices) { - out[4 + i] = lut[pixels[i].toInt() and 0xff] - } - return out + return GlyphPacket.packImage(pixels, maxWidth, height, gamma) } catch (e: Exception) { Log.w(TAG, "wrapped render failed: $path", e) return ByteArray(0) @@ -206,7 +184,7 @@ class FontFileRenderer private constructor() { val bounds = android.graphics.Rect() paint.getTextBounds(text, 0, text.length, bounds) if (bounds.isEmpty) { - return glyphCellPacket(advanceFixed, 0, 0, 0, 0, null) + return GlyphPacket.emptyGlyphCell(advanceFixed) } // getTextBounds can be off by a hair on AA edges; render with // padding, then trim to the actually painted box. @@ -224,40 +202,11 @@ class FontFileRenderer private constructor() { val pixels = alpha8Pixels(bitmap, bw, bh) bitmap.recycle() - var x0 = bw - var x1 = -1 - var y0 = bh - var y1 = -1 - for (y in 0 until bh) { - val row = y * bw - for (x in 0 until bw) { - if (pixels[row + x].toInt() != 0) { - if (x < x0) x0 = x - if (x > x1) x1 = x - if (y < y0) y0 = y - if (y > y1) y1 = y - } - } - } - if (x1 < x0) { - return glyphCellPacket(advanceFixed, 0, 0, 0, 0, null) - } - val width = x1 - x0 + 1 - val height = y1 - y0 + 1 + // Trim to the tight ink box; bearing/inkTop become pen- and + // line-relative inside the shared packer. val fm = paint.fontMetricsInt - val bearingX = x0 - penX - val inkTop = (-fm.ascent) + (y0 - baselineY) - - val lut = gammaLut(gamma) - val coverage = ByteArray(width * height) - for (y in 0 until height) { - val src = (y0 + y) * bw + x0 - val dst = y * width - for (x in 0 until width) { - coverage[dst + x] = lut[pixels[src + x].toInt() and 0xff] - } - } - return glyphCellPacket(advanceFixed, bearingX, inkTop, width, height, coverage) + return GlyphPacket.packGlyphCell( + advanceFixed, pixels, bw, bh, penX, baselineY, -fm.ascent, gamma) } catch (e: Exception) { Log.w(TAG, "glyph render failed: " + path + " U+" + Integer.toHexString(codePoint), e) return ByteArray(0) @@ -294,26 +243,6 @@ class FontFileRenderer private constructor() { return paint } - @JvmStatic - private fun glyphCellPacket( - advanceFixed: Int, bearingX: Int, inkTop: Int, width: Int, height: Int, coverage: ByteArray?): ByteArray { - val out = ByteArray(10 + (coverage?.size ?: 0)) - out[0] = (advanceFixed and 0xff).toByte() - out[1] = ((advanceFixed shr 8) and 0xff).toByte() - out[2] = (bearingX and 0xff).toByte() - out[3] = ((bearingX shr 8) and 0xff).toByte() - out[4] = (inkTop and 0xff).toByte() - out[5] = ((inkTop shr 8) and 0xff).toByte() - out[6] = (width and 0xff).toByte() - out[7] = ((width shr 8) and 0xff).toByte() - out[8] = (height and 0xff).toByte() - out[9] = ((height shr 8) and 0xff).toByte() - if (coverage != null) { - System.arraycopy(coverage, 0, out, 10, coverage.size) - } - return out - } - /** * Line metrics for a font at a pixel size, as "ascent descent lineGap" * (integers, pixels). Empty string if the font cannot be loaded. @@ -361,8 +290,21 @@ class FontFileRenderer private constructor() { */ @JvmStatic fun getFontName(path: String?): String { + if (path == null) { + return "" + } try { - return parseNameTable(path) + RandomAccessFile(path, "r").use { raf -> + return OpenTypeNames.parse(object : RandomAccessBytes { + override val length: Long + get() = raf.length() + + override fun read(offset: Long, into: ByteArray, count: Int) { + raf.seek(offset) + raf.readFully(into, 0, count) + } + }) + } } catch (e: Exception) { Log.w(TAG, "name table parse failed: $path", e) return "" @@ -431,144 +373,5 @@ class FontFileRenderer private constructor() { } return pixels } - - /** [first, last] painted (nonzero) column indexes, or null if blank. */ - @JvmStatic - private fun paintedColumnRange(pixels: ByteArray, width: Int, height: Int): IntArray? { - var first = width - var last = -1 - for (y in 0 until height) { - val row = y * width - var x = 0 - while (x < first) { - if (pixels[row + x].toInt() != 0) { - first = x - break - } - x++ - } - x = width - 1 - while (x > last) { - if (pixels[row + x].toInt() != 0) { - last = x - break - } - x-- - } - } - return if (last >= first) intArrayOf(first, last) else null - } - - @JvmStatic - private fun gammaLut(gammaIn: Double): ByteArray { - val lut = ByteArray(256) - var gamma = gammaIn - if (gamma <= 0) { - gamma = 1.0 - } - for (i in 0 until 256) { - lut[i] = Math.max(0, Math.min(255, - Math.round(255.0 * Math.pow(i / 255.0, gamma)).toInt())).toByte() - } - return lut - } - - // --- Minimal 'name' table reader (TTF/OTF/TTC) for preview titles --- - - @JvmStatic - @Throws(Exception::class) - private fun parseNameTable(path: String?): String { - RandomAccessFile(path, "r").use { raf -> - val fileSize = raf.length() - if (fileSize < 12) { - return "" - } - var offset = 0L - val tag = readU32(raf, 0) - if (tag == 0x74746366) { // 'ttcf': use the first face - if (readU32(raf, 8) < 1) { - return "" - } - offset = readU32(raf, 12).toLong() and 0xffffffffL - } - val numTables = readU16(raf, offset + 4) - var nameOffset = -1L - for (i in 0 until numTables) { - val rec = offset + 12 + i * 16L - if (rec + 16 > fileSize) { - return "" - } - if (readU32(raf, rec) == 0x6e616d65) { // 'name' - nameOffset = readU32(raf, rec + 8).toLong() and 0xffffffffL - break - } - } - if (nameOffset < 0 || nameOffset + 6 > fileSize) { - return "" - } - val count = readU16(raf, nameOffset + 2) - val stringStorage = nameOffset + readU16(raf, nameOffset + 4) - var family: String? = null - var style: String? = null - var preferredFamily: String? = null - var preferredStyle: String? = null - for (i in 0 until count) { - val rec = nameOffset + 6 + i * 12L - if (rec + 12 > fileSize) { - break - } - val platform = readU16(raf, rec) - val nameId = readU16(raf, rec + 6) - if (nameId != 1 && nameId != 2 && nameId != 16 && nameId != 17) { - continue - } - val length = readU16(raf, rec + 8) - val strOffset = stringStorage + readU16(raf, rec + 10) - if (strOffset + length > fileSize || length <= 0 || length > 512) { - continue - } - val data = ByteArray(length) - raf.seek(strOffset) - raf.readFully(data) - // Platform 0 (Unicode) and 3 (Windows) store UTF-16BE; - // platform 1 (Mac) is close enough to Latin-1 for names. - var value = if (platform == 1) - String(data, java.nio.charset.StandardCharsets.ISO_8859_1) - else String(data, java.nio.charset.StandardCharsets.UTF_16BE) - value = value.trim() - if (value.isEmpty()) { - continue - } - if (nameId == 1 && family == null) family = value - if (nameId == 2 && style == null) style = value - if (nameId == 16 && preferredFamily == null) preferredFamily = value - if (nameId == 17 && preferredStyle == null) preferredStyle = value - } - val outFamily = preferredFamily ?: family - val outStyle = preferredStyle ?: style - if (outFamily == null) { - return "" - } - return outFamily + "\n" + (outStyle ?: "") - } - } - - @JvmStatic - @Throws(Exception::class) - private fun readU16(raf: RandomAccessFile, offset: Long): Int { - raf.seek(offset) - val b = ByteArray(2) - raf.readFully(b) - return ByteBuffer.wrap(b).order(ByteOrder.BIG_ENDIAN).getShort().toInt() and 0xffff - } - - @JvmStatic - @Throws(Exception::class) - private fun readU32(raf: RandomAccessFile, offset: Long): Int { - raf.seek(offset) - val b = ByteArray(4) - raf.readFully(b) - return ByteBuffer.wrap(b).order(ByteOrder.BIG_ENDIAN).getInt() - } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt index fdf2ce4d..f59a9d56 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FrameTimings.kt @@ -9,33 +9,13 @@ import java.io.FileOutputStream import java.io.OutputStreamWriter import java.io.Writer import java.nio.charset.StandardCharsets -import java.text.SimpleDateFormat -import java.util.ArrayDeque -import java.util.ArrayList -import java.util.Collections -import java.util.Date -import java.util.LinkedHashMap -import java.util.Locale /** - * Per-frame timing instrumentation, shared between the Java BLE layer and the - * Typescript UI layer. A "frame" starts when we receive an input event (or a - * timer fires and we decide to redraw), and finishes when the resulting screen - * update has been fully transmitted to the glasses, is discarded unsent, or - * times out because nobody reported finishing it. - * - * Frames form a tree. One input event can fan out into several renders (the - * focused app's window plus the shell chrome, say), and each of those is its - * own frame linked back to the input frame that caused it via - * [startFrame]. The export nests descendants under their - * root and renders every line against the root's clock, so a single block - * shows the whole input-to-pixels story. Latency percentiles are measured over - * roots: root start to the first descendant that actually reached the glasses. - * - * All public methods are thread-safe and cheap enough to call from the BLE - * worker thread, the Android main thread, the JS thread, and app worker - * threads. Frame IDs are positive ints; 0 means "no frame" and is silently - * ignored everywhere, so callers do not need to null-check. + * Android facade over the shared [FrameTimingsCore] (per-frame latency + * instrumentation; see that class for the frame-tree model). This class keeps + * the process-wide singleton the BLE layer and TypeScript call by name, and owns + * the Android-only parts: the export directory derived from the Context and the + * daemon thread that sweeps timed-out frames and writes the export file. * * Statistics and full log lines for recent and slowest frames are periodically * exported to getExternalFilesDir()/frame-timings.txt, retrievable via @@ -43,131 +23,19 @@ import java.util.Locale */ class FrameTimings private constructor() { companion object { - private const val TAG = "FrameTimings" + private const val TAG = FrameTimingsCore.TAG private val INSTANCE = FrameTimings() - - /** Frames still open after this long are finished as "timeout". */ - private const val FRAME_TIMEOUT_MS = 30_000L - private const val EXPORT_INTERVAL_MS = 15_000L - private const val SWEEP_INTERVAL_MS = 5_000L - private const val RECENT_ROOTS_KEPT = 40 - private const val SLOWEST_ROOTS_KEPT = 20 - private const val SENT_DURATIONS_WINDOW = 512 - private const val MAX_LINES_PER_FRAME = 200 - /** - * Frames retained for ID lookup. Well above the number any export can - * reference, so a late log/span/finish call always finds its frame; frames - * older than this are unreachable and get collected. - */ - private const val FRAMES_RETAINED = 1024 private const val EXPORT_FILE_NAME = "frame-timings.txt" @JvmStatic fun getInstance(): FrameTimings { return INSTANCE } - - @JvmStatic - private fun percentileOfSorted(sorted: List, percentile: Int): Long { - val index = Math.ceil(percentile / 100.0 * sorted.size).toInt() - 1 - return sorted[Math.max(0, Math.min(sorted.size - 1, index))] - } - - @JvmStatic - private fun repeat(unit: String, times: Int): String { - val out = StringBuilder(unit.length * times) - for (i in 0 until times) { - out.append(unit) - } - return out.toString() - } - } - - private class Line( - val atMs: Long, // SystemClock.elapsedRealtime() - val thread: String, - val message: String? - ) - - private class Frame( - val id: Int, - var reason: String, - val startedAtMs: Long, // SystemClock.elapsedRealtime() - val startedWallClockMs: Long, - val parent: Frame? - ) { - val children: MutableList = ArrayList(0) - val lines: MutableList = ArrayList() - val openSpans: MutableMap = LinkedHashMap() - var finishedAtMs: Long = 0 - var outcome: String? = null // null while open; "sent", "discarded: ...", "timeout: ..." - /** Set on the root once some frame in its subtree reached the glasses. */ - var subtreeSentRecorded = false - - fun root(): Frame { - var frame: Frame = this - while (frame.parent != null) { - frame = frame.parent!! - } - return frame - } - - fun isOpen(): Boolean { - return outcome == null - } - - fun durationMs(): Long { - return finishedAtMs - startedAtMs - } - - fun wasSent(): Boolean { - val outcome = this.outcome - return outcome != null && outcome.startsWith("sent") - } - - /** Last moment anything in this subtree happened, for whole-tree duration. */ - fun subtreeEndAtMs(nowMs: Long): Long { - var end = if (isOpen()) nowMs else finishedAtMs - for (child in children) { - end = Math.max(end, child.subtreeEndAtMs(nowMs)) - } - return end - } - - fun subtreeHasOpenFrame(): Boolean { - if (isOpen()) { - return true - } - for (child in children) { - if (child.subtreeHasOpenFrame()) { - return true - } - } - return false - } } + /** The shared core; the glasses session core records frames into it directly. */ + val core = FrameTimingsCore(AndroidProtocolPlatform) private val lock = Any() - /** - * Every frame we still retain, keyed by ID: open frames plus enough - * history that late calls and the export can still resolve one. - */ - private val framesById: LinkedHashMap = - object : LinkedHashMap(64, 0.75f, false) { - override fun removeEldestEntry(eldest: MutableMap.MutableEntry): Boolean { - return size > FRAMES_RETAINED && !eldest.value.isOpen() - } - } - private val recentRoots = ArrayDeque() - private val slowestRoots: MutableList = ArrayList() - private val inputLatencies = ArrayDeque() - private val renderLatencies = ArrayDeque() - private var nextFrameId = 1 - private var framesStarted: Long = 0 - private var framesSent: Long = 0 - private var framesDiscarded: Long = 0 - private var framesTimedOut: Long = 0 - private var exportDirty = false private var exportDir: File? = null private var exportThread: Thread? = null @@ -189,245 +57,47 @@ class FrameTimings private constructor() { } /** Begin a root frame; reason is a short label like "input:sys-event type=0". */ - fun startFrame(reason: String?): Int { - return startFrame(reason, 0) - } + fun startFrame(reason: String?): Int = core.startFrame(reason) - /** - * Begin a frame caused by an existing one (parentFrameId; 0 for a root). - * The child is nested under its root in the export and its latency counts - * against the root, so an input event that fans out into an app render and - * a shell-chrome render reads as one timeline instead of three. - */ - fun startFrame(reason: String?, parentFrameId: Int): Int { - val now = SystemClock.elapsedRealtime() - val frame: Frame - synchronized(lock) { - val parent = framesById[parentFrameId] - frame = Frame(nextFrameId++, reason ?: "", now, - System.currentTimeMillis(), parent) - framesById[frame.id] = frame - framesStarted++ - if (parent != null) { - parent.children.add(frame) - addLineLocked(parent, now, "spawned frame#" + frame.id + " (" + frame.reason + ")") - } - } - return frame.id - } + /** Begin a frame caused by an existing one (parentFrameId; 0 for a root). */ + fun startFrame(reason: String?, parentFrameId: Int): Int = core.startFrame(reason, parentFrameId) - /** - * Append to a frame's label, for facts only known after it started (which - * app is in the foreground, which window a render is for). Shows up in the - * frame's header line, so the export is scannable without reading bodies. - */ - fun annotate(frameId: Int, text: String?) { - if (text == null || text.isEmpty()) { - return - } - synchronized(lock) { - val frame = framesById[frameId] - if (frame == null) { - return - } - frame.reason = if (frame.reason.isEmpty()) text else frame.reason + " " + text - } - } + /** Append to a frame's label, for facts only known after it started. */ + fun annotate(frameId: Int, text: String?) = core.annotate(frameId, text) - fun log(frameId: Int, message: String?) { - val now = SystemClock.elapsedRealtime() - synchronized(lock) { - val frame = openFrameLocked(frameId) - if (frame == null) { - return - } - addLineLocked(frame, now, message) - } - } + fun log(frameId: Int, message: String?) = core.log(frameId, message) - fun spanStart(frameId: Int, name: String) { - val now = SystemClock.elapsedRealtime() - synchronized(lock) { - val frame = openFrameLocked(frameId) - if (frame == null) { - return - } - frame.openSpans[name] = now - addLineLocked(frame, now, "span $name start") - } - } + fun spanStart(frameId: Int, name: String) = core.spanStart(frameId, name) - fun spanEnd(frameId: Int, name: String) { - val now = SystemClock.elapsedRealtime() - synchronized(lock) { - val frame = openFrameLocked(frameId) - if (frame == null) { - return - } - val startedAt = frame.openSpans.remove(name) - if (startedAt == null) { - addLineLocked(frame, now, "span $name end (start not recorded)") - } else { - addLineLocked(frame, now, "span " + name + " end (" + (now - startedAt) + "ms)") - } - } - } + fun spanEnd(frameId: Int, name: String) = core.spanEnd(frameId, name) /** * Finish a frame. Outcomes: "sent" (counted in latency percentiles), anything - * starting with "discarded", or "timeout". First finish wins; later calls for - * the same frame are ignored, so racing completion paths are safe. + * starting with "discarded", or "timeout". First finish wins. */ - fun finishFrame(frameId: Int, outcome: String?) { - val now = SystemClock.elapsedRealtime() - val finished: Frame - synchronized(lock) { - val frame = openFrameLocked(frameId) - if (frame == null) { - return - } - finishFrameLocked(frame, now, outcome ?: "discarded: no outcome given") - finished = frame - } - Log.i(TAG, "frame#" + finished.id + " [" + finished.reason + "] -> " + finished.outcome - + " in " + finished.durationMs() + "ms") - } + fun finishFrame(frameId: Int, outcome: String?) = core.finishFrame(frameId, outcome) /** One-line stats summary, e.g. for showing in the phone UI. */ - fun statsSummary(): String { - synchronized(lock) { - val input = percentilesLocked(inputLatencies) - return "frames started=" + framesStarted + " sent=" + framesSent + - " discarded=" + framesDiscarded + " timeout=" + framesTimedOut + - (if (input == null) - "" - else " | input-to-display p50=" + input[0] + "ms p90=" + input[1] + - "ms p99=" + input[2] + "ms max=" + input[3] + "ms") - } - } + fun statsSummary(): String = core.statsSummary() // --------------------------------------------------------------------- - /** The frame with this ID if it exists and is still open, else null. */ - private fun openFrameLocked(frameId: Int): Frame? { - if (frameId <= 0) { - return null - } - val frame = framesById[frameId] - return if (frame != null && frame.isOpen()) frame else null - } - - private fun addLineLocked(frame: Frame, now: Long, message: String?) { - if (frame.lines.size >= MAX_LINES_PER_FRAME) { - if (frame.lines.size == MAX_LINES_PER_FRAME) { - frame.lines.add(Line(now, Thread.currentThread().name, "... line cap reached")) - } - return - } - frame.lines.add(Line(now, Thread.currentThread().name, message)) - } - - private fun finishFrameLocked(frame: Frame, now: Long, outcome: String) { - frame.finishedAtMs = now - frame.outcome = outcome - for (open in frame.openSpans.entries) { - frame.lines.add(Line(now, Thread.currentThread().name, - "span " + open.key + " never ended (started at +" + - (open.value - frame.startedAtMs) + "ms)")) - } - frame.openSpans.clear() - addLineLocked(frame, now, "finished: $outcome") - - val root = frame.root() - if (frame.wasSent()) { - framesSent++ - // The user-visible latency is input (or timer) to the first pixels - // that actually reached the glasses, wherever in the tree that was. - if (!root.subtreeSentRecorded) { - root.subtreeSentRecorded = true - recordLatencyLocked(root, now - root.startedAtMs) - insertSlowestLocked(root) - } - } else if (outcome.startsWith("timeout")) { - framesTimedOut++ - } else { - framesDiscarded++ - } - - if (root === frame) { - recentRoots.addLast(frame) - while (recentRoots.size > RECENT_ROOTS_KEPT) { - recentRoots.removeFirst() - } - } - exportDirty = true - } - - private fun recordLatencyLocked(root: Frame, latencyMs: Long) { - val bucket = if (root.reason.startsWith("input:")) inputLatencies else renderLatencies - bucket.addLast(latencyMs) - while (bucket.size > SENT_DURATIONS_WINDOW) { - bucket.removeFirst() - } - } - - private fun insertSlowestLocked(root: Frame) { - if (!slowestRoots.contains(root)) { - slowestRoots.add(root) - } - // Sorted and trimmed at export time, when every subtree duration is final. - } - - /** {p50, p90, p99, max} over a rolling latency window, or null if empty. */ - private fun percentilesLocked(window: ArrayDeque): LongArray? { - if (window.isEmpty()) { - return null - } - val sorted: MutableList = ArrayList(window) - Collections.sort(sorted) - return longArrayOf( - percentileOfSorted(sorted, 50), - percentileOfSorted(sorted, 90), - percentileOfSorted(sorted, 99), - sorted[sorted.size - 1], - ) - } - - private fun sweepTimedOutFrames() { - val now = SystemClock.elapsedRealtime() - val timedOut: MutableList = ArrayList() - synchronized(lock) { - for (frame in ArrayList(framesById.values)) { - if (frame.isOpen() && now - frame.startedAtMs >= FRAME_TIMEOUT_MS) { - finishFrameLocked(frame, now, "timeout: never reported finished") - timedOut.add(frame) - } - } - } - for (frame in timedOut) { - Log.w(TAG, "frame#" + frame.id + " [" + frame.reason + "] timed out after " + - frame.durationMs() + "ms without being finished") - } - } - private fun exportLoop() { var lastExportAtMs = 0L while (true) { try { - Thread.sleep(SWEEP_INTERVAL_MS) + Thread.sleep(FrameTimingsCore.SWEEP_INTERVAL_MS) } catch (e: InterruptedException) { return } try { - sweepTimedOutFrames() + core.sweepTimedOut() val now = SystemClock.elapsedRealtime() - val shouldExport: Boolean - synchronized(lock) { - shouldExport = exportDirty && exportDir != null && now - lastExportAtMs >= EXPORT_INTERVAL_MS - } - if (shouldExport) { + val dir: File? + synchronized(lock) { dir = exportDir } + if (dir != null && core.isExportDirty && now - lastExportAtMs >= FrameTimingsCore.EXPORT_INTERVAL_MS) { lastExportAtMs = now - exportToFile() + exportToFile(dir) } } catch (t: Throwable) { Log.w(TAG, "export loop error", t) @@ -435,14 +105,8 @@ class FrameTimings private constructor() { } } - private fun exportToFile() { - val content: String - val dir: File - synchronized(lock) { - dir = exportDir ?: return - content = buildExportLocked() - exportDirty = false - } + private fun exportToFile(dir: File) { + val content = core.takeExport() ?: return val target = File(dir, EXPORT_FILE_NAME) val temp = File(dir, "$EXPORT_FILE_NAME.tmp") try { @@ -456,99 +120,4 @@ class FrameTimings private constructor() { Log.w(TAG, "failed to export frame timings", t) } } - - private fun buildExportLocked(): String { - val now = SystemClock.elapsedRealtime() - val wallClockFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US) - val out = StringBuilder(64 * 1024) - out.append("FrameTimings export at ").append(wallClockFormat.format(Date())).append('\n') - out.append(statsSummaryLocked()).append('\n') - out.append('\n') - out.append("Frames are trees: an input event's own frame is the root, and the renders it\n") - out.append("caused are indented under it with offsets measured from the root's start.\n") - out.append('\n') - - Collections.sort(slowestRoots, Comparator { a, b -> - java.lang.Long.compare(b.subtreeEndAtMs(now) - b.startedAtMs, a.subtreeEndAtMs(now) - a.startedAtMs) }) - while (slowestRoots.size > SLOWEST_ROOTS_KEPT) { - slowestRoots.removeAt(slowestRoots.size - 1) - } - - out.append("=== slowest frames that reached the glasses ===\n") - for (frame in slowestRoots) { - appendTreeLocked(out, frame, frame, wallClockFormat, now) - } - - out.append("=== recent frames (oldest first) ===\n") - for (frame in recentRoots) { - appendTreeLocked(out, frame, frame, wallClockFormat, now) - } - return out.toString() - } - - private fun statsSummaryLocked(): String { - val input = percentilesLocked(inputLatencies) - val render = percentilesLocked(renderLatencies) - val out = StringBuilder() - out.append("frames started=").append(framesStarted).append(" sent=").append(framesSent) - .append(" discarded=").append(framesDiscarded).append(" timeout=").append(framesTimedOut) - .append(" open=").append(openFrameCountLocked()) - appendPercentilesLocked(out, "input-to-display latency", inputLatencies.size, input) - appendPercentilesLocked(out, "render-to-display latency", renderLatencies.size, render) - return out.toString() - } - - private fun appendPercentilesLocked(out: StringBuilder, label: String, count: Int, percentiles: LongArray?) { - if (percentiles == null) { - return - } - out.append('\n').append(label).append(" (last ").append(count).append("): p50=") - .append(percentiles[0]).append("ms p90=").append(percentiles[1]) - .append("ms p99=").append(percentiles[2]).append("ms max=").append(percentiles[3]).append("ms") - } - - private fun openFrameCountLocked(): Int { - var open = 0 - for (frame in framesById.values) { - if (frame.isOpen()) { - open++ - } - } - return open - } - - /** Print a frame and its descendants, all timed against root's start. */ - private fun appendTreeLocked( - out: StringBuilder, frame: Frame, root: Frame, wallClockFormat: SimpleDateFormat, now: Long) { - var depth = 0 - var walk: Frame? = frame - while (walk !== root) { - depth++ - walk = walk!!.parent - } - val indent = repeat(" ", depth) - val startOffsetMs = frame.startedAtMs - root.startedAtMs - out.append(indent).append("frame#").append(frame.id) - .append(" [").append(frame.reason).append(']') - if (frame === root) { - out.append(" started ").append(wallClockFormat.format(Date(frame.startedWallClockMs))) - val totalMs = frame.subtreeEndAtMs(now) - frame.startedAtMs - out.append(" duration ").append(frame.durationMs()).append("ms") - if (!frame.children.isEmpty()) { - out.append(" (tree ").append(totalMs).append("ms") - .append(if (frame.subtreeHasOpenFrame()) ", still open" else "").append(')') - } - } else { - out.append(" started +").append(startOffsetMs).append("ms") - .append(" duration ").append(if (frame.isOpen()) "open" else (frame.durationMs().toString() + "ms")) - } - out.append(" outcome ").append(frame.outcome ?: "(open)").append('\n') - for (line in frame.lines) { - out.append(indent).append(String.format(Locale.US, " %+7dms [%s] %s", - line.atMs - root.startedAtMs, line.thread, line.message)).append('\n') - } - for (child in frame.children) { - appendTreeLocked(out, child, root, wallClockFormat, now) - } - } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt index da181f0d..efaf4ac4 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/IconRenderer.kt @@ -8,9 +8,6 @@ import android.util.Log import androidx.core.graphics.PathParser -import java.util.regex.Matcher -import java.util.regex.Pattern - /** * Renders a small subset of SVG (the shapes used by Lucide / simple Noun * Project icons: path, circle, ellipse, rect, line, polyline, polygon) to a @@ -18,13 +15,14 @@ import java.util.regex.Pattern * (Lucide style: fill="none", 2px stroke, round caps/joins); the returned * bytes are one coverage value per pixel (0=transparent .. 255=opaque white), * row-major, size*size. Called once per icon and cached on the TS side. + * + * Parsing, placement math and the coverage quantization are shared with iOS + * (SvgIconSource); this class only maps shapes onto android.graphics.Path and + * rasterizes them. */ class IconRenderer private constructor() { companion object { private const val TAG = "IconRenderer" - private val TAG_RE: Pattern = Pattern.compile("<(path|circle|ellipse|rect|line|polyline|polygon)\\b([^>]*)>") - private val VIEWBOX_RE: Pattern = Pattern.compile("viewBox\\s*=\\s*\"([^\"]*)\"") - private val SEPARATOR_RE: Pattern = Pattern.compile("[\\s,]+") @JvmStatic fun renderSvgGray(svg: String?, size: Int, strokeWidth: Float): ByteArray { @@ -32,27 +30,10 @@ class IconRenderer private constructor() { return ByteArray(0) } try { - var minX = 0f - var minY = 0f - var viewW = 24f - var viewH = 24f - val vb = VIEWBOX_RE.matcher(svg) - if (vb.find()) { - val parts = SEPARATOR_RE.split(vb.group(1)!!.trim()) - if (parts.size == 4) { - minX = java.lang.Float.parseFloat(parts[0]) - minY = java.lang.Float.parseFloat(parts[1]) - viewW = java.lang.Float.parseFloat(parts[2]) - viewH = java.lang.Float.parseFloat(parts[3]) - } - } - // Lucide-style icons are stroked outlines (fill="none"); everything - // else (Noun Project glyphs, brand logos) is a filled shape. - val stroked = svg.contains("fill=\"none\"") + val icon = SvgIconSource.parse(svg) ?: return ByteArray(0) val path = Path() - val m = TAG_RE.matcher(svg) - while (m.find()) { - appendElement(path, m.group(1)!!, m.group(2)!!) + for (shape in icon.shapes) { + appendShape(path, shape) } if (path.isEmpty) { return ByteArray(0) @@ -60,14 +41,14 @@ class IconRenderer private constructor() { val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888) val canvas = Canvas(bitmap) - val scale = Math.min(size / viewW, size / viewH) // Center the (square) viewBox in the bitmap, then map its origin. - canvas.translate((size - viewW * scale) / 2f, (size - viewH * scale) / 2f) - canvas.scale(scale, scale) - canvas.translate(-minX, -minY) + val placement = icon.placement(size) + canvas.translate(placement[0], placement[1]) + canvas.scale(placement[2], placement[2]) + canvas.translate(-icon.minX, -icon.minY) val paint = Paint(Paint.ANTI_ALIAS_FLAG) paint.color = 0xffffffff.toInt() - if (stroked) { + if (icon.stroked) { paint.style = Paint.Style.STROKE paint.strokeWidth = strokeWidth paint.strokeCap = Paint.Cap.ROUND @@ -79,117 +60,47 @@ class IconRenderer private constructor() { val pixels = IntArray(size * size) bitmap.getPixels(pixels, 0, size, 0, 0, size, size) - val gray = ByteArray(size * size) - for (i in pixels.indices) { - gray[i] = quantizeCoverage((pixels[i] ushr 24) and 0xff).toByte() // alpha = coverage - } - return gray + return SvgIconSource.quantizeArgb(pixels) // alpha = coverage } catch (e: Exception) { Log.w(TAG, "icon render failed", e) return ByteArray(0) } } - /** - * Snap antialiased coverage toward hard edges so the 4bpp frames sent - * over BLE deflate better: mostly-transparent and mostly-opaque pixels - * become exactly 0/255 (long runs, and 0 stays color-key transparent for - * bitBlt), and only genuinely half-covered edge pixels keep one mid gray. - * The packed frame then uses a 3-symbol alphabet instead of all 16 - * levels, at icon sizes this is visually near-identical. - */ @JvmStatic - private fun quantizeCoverage(alpha: Int): Int { - if (alpha < 64) return 0 - if (alpha >= 192) return 255 - return 128 - } - - @JvmStatic - private fun appendElement(path: Path, tag: String, attrs: String) { - when (tag) { - "path" -> { - val d = attr(attrs, "d") - if (d != null) { - val sub = PathParser.createPathFromPathData(d) - if (sub != null) { - path.addPath(sub) - } + private fun appendShape(path: Path, shape: SvgShape) { + when (shape) { + is SvgShape.PathData -> { + val sub = PathParser.createPathFromPathData(shape.d) + if (sub != null) { + path.addPath(sub) } } - "circle" -> { - val cx = num(attrs, "cx", 0f) - val cy = num(attrs, "cy", 0f) - val r = num(attrs, "r", 0f) - if (r > 0) path.addCircle(cx, cy, r, Path.Direction.CW) - } - "ellipse" -> { - val cx = num(attrs, "cx", 0f) - val cy = num(attrs, "cy", 0f) - val rx = num(attrs, "rx", 0f) - val ry = num(attrs, "ry", 0f) - if (rx > 0 && ry > 0) path.addOval(cx - rx, cy - ry, cx + rx, cy + ry, Path.Direction.CW) - } - "rect" -> { - val x = num(attrs, "x", 0f) - val y = num(attrs, "y", 0f) - val w = num(attrs, "width", 0f) - val h = num(attrs, "height", 0f) - var rx = num(attrs, "rx", 0f) - var ry = num(attrs, "ry", if (rx > 0) rx else 0f) - if (rx <= 0) rx = ry - if (ry <= 0) ry = rx - if (w > 0 && h > 0) { - if (rx > 0 || ry > 0) { - path.addRoundRect(x, y, x + w, y + h, rx, ry, Path.Direction.CW) - } else { - path.addRect(x, y, x + w, y + h, Path.Direction.CW) - } + is SvgShape.Circle -> path.addCircle(shape.cx, shape.cy, shape.r, Path.Direction.CW) + is SvgShape.Ellipse -> path.addOval( + shape.cx - shape.rx, shape.cy - shape.ry, shape.cx + shape.rx, shape.cy + shape.ry, Path.Direction.CW) + is SvgShape.Rect -> { + if (shape.rx > 0 || shape.ry > 0) { + path.addRoundRect(shape.x, shape.y, shape.x + shape.width, shape.y + shape.height, + shape.rx, shape.ry, Path.Direction.CW) + } else { + path.addRect(shape.x, shape.y, shape.x + shape.width, shape.y + shape.height, Path.Direction.CW) } } - "line" -> { - path.moveTo(num(attrs, "x1", 0f), num(attrs, "y1", 0f)) - path.lineTo(num(attrs, "x2", 0f), num(attrs, "y2", 0f)) + is SvgShape.Line -> { + path.moveTo(shape.x1, shape.y1) + path.lineTo(shape.x2, shape.y2) } - "polyline", "polygon" -> { - val points = attr(attrs, "points") - if (points != null) { - val nums = SEPARATOR_RE.split(points.trim()) - var started = false - var i = 0 - while (i + 1 < nums.size) { - val px = java.lang.Float.parseFloat(nums[i]) - val py = java.lang.Float.parseFloat(nums[i + 1]) - if (!started) { - path.moveTo(px, py) - started = true - } else { - path.lineTo(px, py) - } - i += 2 - } - if (tag == "polygon") path.close() + is SvgShape.Polyline -> { + val p = shape.points + path.moveTo(p[0], p[1]) + var i = 2 + while (i + 1 < p.size) { + path.lineTo(p[i], p[i + 1]) + i += 2 } + if (shape.closed) path.close() } - else -> { - } - } - } - - @JvmStatic - private fun attr(attrs: String, name: String): String? { - val m: Matcher = Pattern.compile("\\b" + name + "\\s*=\\s*\"([^\"]*)\"").matcher(attrs) - return if (m.find()) m.group(1) else null - } - - @JvmStatic - private fun num(attrs: String, name: String, fallback: Float): Float { - val value = attr(attrs, name) - if (value == null) return fallback - try { - return java.lang.Float.parseFloat(value.trim()) - } catch (e: NumberFormatException) { - return fallback } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt index d1b6c300..b73baee1 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/ImageFileLoader.kt @@ -10,7 +10,8 @@ import android.util.Log * pixels...] with one byte per pixel, row-major, or an empty array on * failure. FaceclawMediaController's album art shares bitmapToGrayPacket; * the TS side (app/native/image-files.ts) owns the shared photo-tone preset - * passed as (gamma, dither). + * passed as (gamma, dither). The pixel math (tone curve, alpha darkening, + * dither) lives in the shared GrayPacket so iOS produces identical bytes. */ class ImageFileLoader private constructor() { companion object { @@ -151,24 +152,7 @@ class ImageFileLoader private constructor() { } val pixels = IntArray(width * height) scaled.getPixels(pixels, 0, width, 0, 0, width, height) - val out = ByteArray(4 + width * height) - out[0] = (width and 0xff).toByte() - out[1] = ((width shr 8) and 0xff).toByte() - out[2] = (height and 0xff).toByte() - out[3] = ((height shr 8) and 0xff).toByte() - val tone = toneCurve(gamma) - for (i in pixels.indices) { - val p = pixels[i] - val a = (p ushr 24) and 0xff - val r = (p shr 16) and 0xff - val g = (p shr 8) and 0xff - val b = p and 0xff - out[4 + i] = tone[((r * 299 + g * 587 + b * 114) / 1000) * a / 255].toByte() - } - if (dither) { - ditherToDisplayLevels(out, 4, width, height) - } - return out + return GrayPacket.fromArgb(pixels, width, height, gamma, dither) } catch (e: Exception) { Log.w(TAG, "bitmap conversion failed", e) return ByteArray(0) @@ -177,70 +161,5 @@ class ImageFileLoader private constructor() { return ByteArray(0) } } - - /** 256-entry map of source gray to displayed gray for out = in^gamma. */ - @JvmStatic - private fun toneCurve(gamma: Float): IntArray { - val curve = IntArray(256) - for (v in 0 until 256) { - curve[v] = if (gamma == 1f) - v - else Math.round(255f * Math.pow((v / 255f).toDouble(), gamma.toDouble()).toFloat()) - } - return curve - } - - /** - * Floyd-Steinberg error diffusion onto the display's 16 gray levels, in - * place over an 8bpp plane. Serpentine scanning keeps the diffusion from - * building up a directional texture across wide flat areas. - * - * Level n is written back as n * 16 rather than the n * 17 it stands for - * so that BmpUtil's (v + 8) >> 4 reproduces n exactly; level 0 is written - * as 1, not 0, because 0 is the shell's color-key for transparent. - */ - @JvmStatic - private fun ditherToDisplayLevels(plane: ByteArray, offset: Int, width: Int, height: Int) { - var curr = FloatArray(width) - var next = FloatArray(width) - for (x in 0 until width) { - curr[x] = (plane[offset + x].toInt() and 0xff).toFloat() - } - for (y in 0 until height) { - val rowStart = offset + y * width - val nextStart = rowStart + width - val hasNext = y + 1 < height - for (x in 0 until width) { - next[x] = if (hasNext) (plane[nextStart + x].toInt() and 0xff).toFloat() else 0f - } - val leftToRight = (y and 1) == 0 - val start = if (leftToRight) 0 else width - 1 - val step = if (leftToRight) 1 else -1 - for (i in 0 until width) { - val x = start + i * step - val wanted = curr[x] - val level = Math.round(Math.min(255f, Math.max(0f, wanted)) / 17f) - val error = wanted - level * 17f - plane[rowStart + x] = (if (level == 0) 1 else level * 16).toByte() - val ahead = x + step - if (ahead >= 0 && ahead < width) { - curr[ahead] += error * (7f / 16f) - } - if (hasNext) { - if (ahead >= 0 && ahead < width) { - next[ahead] += error * (1f / 16f) - } - next[x] += error * (5f / 16f) - val behind = x - step - if (behind >= 0 && behind < width) { - next[behind] += error * (3f / 16f) - } - } - } - val swap = curr - curr = next - next = swap - } - } } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt index 96f98bda..54f31c42 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/PreviewBitmapUtil.kt @@ -9,34 +9,11 @@ import java.nio.ByteBuffer * grayscale buffer arrives as a ByteBuffer (NativeScript marshals a JS * ArrayBuffer to one without copying element-by-element); doing the * gray-to-ARGB expansion here keeps the 165KB-per-frame loop out of the - * JS/Java bridge, where it used to cost ~150ms per preview. + * JS/Java bridge, where it used to cost ~150ms per preview. The palette + * itself is the shared PreviewPalette. */ class PreviewBitmapUtil private constructor() { companion object { - private var cachedLut: IntArray? = null - private var cachedGammaBits: Long = 0 - private var cachedGreen: Boolean = false - - /** Reuse the current preview palette; rebuild only when gamma or color changes. */ - @JvmStatic - @Synchronized - private fun lookupTable(brightenGamma: Double, green: Boolean): IntArray { - val gammaBits = java.lang.Double.doubleToLongBits(brightenGamma) - val cached = cachedLut - if (cached != null && cachedGammaBits == gammaBits && cachedGreen == green) { - return cached - } - val lut = IntArray(256) - for (g in 0 until 256) { - val v = Math.max(0L, Math.min(255L, Math.round(255 * Math.pow(g / 255.0, brightenGamma)))).toInt() - lut[g] = if (green) (0xff000000.toInt() or (v shl 8)) else (0xff000000.toInt() or (v shl 16) or (v shl 8) or v) - } - cachedGammaBits = gammaBits - cachedGreen = green - cachedLut = lut - return lut - } - @JvmStatic fun fromGray(gray: ByteBuffer?, width: Int, height: Int, brightenGamma: Double): Bitmap { return fromGray(gray, width, height, brightenGamma, false) @@ -48,13 +25,9 @@ class PreviewBitmapUtil private constructor() { if (gray == null || width <= 0 || height <= 0 || gray.remaining() < width * height) { throw IllegalArgumentException("invalid gray preview buffer") } - val lut = lookupTable(brightenGamma, green) val bytes = ByteArray(width * height) gray.get(bytes) - val colors = IntArray(width * height) - for (i in colors.indices) { - colors[i] = lut[bytes[i].toInt() and 0xff] - } + val colors = PreviewPalette.expand(bytes, 0, width * height, brightenGamma, green) return Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888) } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt deleted file mode 100644 index 60153482..00000000 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.faceclaw.app - -import android.os.SystemClock - -class InterruptibleSleep { - private val lock = java.lang.Object() - private var interrupted = false - - fun sleep(ms: Long): Boolean { - val delayMs = Math.max(1L, ms) - val deadline = SystemClock.elapsedRealtime() + delayMs - synchronized(lock) { - // Consume (do not clear-and-ignore) an interrupt delivered before this - // sleep began. interrupt() runs on other threads with no lock held by - // the sleeper between driveSession() returning and sleep() starting, so - // clearing the flag at entry lost that wake and forced the worker to - // sleep the full interval — up to 250ms per idle frame. Honoring it - // costs at most one extra (cheap) driveSession pass. - if (interrupted) { - interrupted = false - return false - } - while (true) { - val remaining = deadline - SystemClock.elapsedRealtime() - if (remaining <= 0) { - return true - } - try { - lock.wait(remaining) - } catch (ignored: InterruptedException) { - interrupted = false - return false - } - if (interrupted) { - interrupted = false - return false - } - } - } - } - - fun interrupt() { - synchronized(lock) { - interrupted = true - lock.notifyAll() - } - } -} diff --git a/native/kotlin/README.md b/native/kotlin/README.md index e2939a80..40190770 100644 --- a/native/kotlin/README.md +++ b/native/kotlin/README.md @@ -8,7 +8,21 @@ local `@faceclaw/kotlin` plugin. Generated binaries and Gradle caches are ignore - `commonMain/kotlin`: wire protocol, fragmentation/reassembly, event decoding, image/RLE/texture planning, retained surface composition, glyph/image atlases, LVGL font parsing, spectral noise suppression, PNG/GIF/WAV encodings and - callback interfaces. + callback interfaces. Since 2026-09-22 also the platform-neutral cores behind + the Android adapters: `util/` (Json codec, FrameTimingsCore, concurrency + primitives, sha256/clock/log/file expects), `g2protocol/FirmwareImage`, + `audio/` (Lc3PacketFramer, AudioSegmentation, VoicePrint, WavPcmReader), + `graphics/` (GrayPacket, PreviewPalette, StatusIconArt, GlyphPacket, + OpenTypeNames, SvgIconSource), `net/` (HttpIdentity, SseStream, + ResumableDownload, RemoteInputSession), `evenhub/EvenHubAssetServer`, + `alarms/` (AlarmSchedule, AlarmRingingPolicy), `settings/SettingsChangeHub`, + the stock-firmware flows over a `StockLink` GATT port (`g2protocol/StockLinkSession`, + `DeviceInfoProbeFlow`, `FlashPromptFlow`, `OtaFlashFlow`), the full glasses session + (`g2protocol/session/GlassesSessionCore` over `SessionLink`/`SessionHost`) and the + voice/caption pipelines (`audio/VoiceCaptureSession`, `CaptionEngineCore`). + Cores take port interfaces (GATT link, storage, transport, dispatcher) and call + listeners synchronously; the Android adapters in `App_Resources` own threads, + Handler marshalling and OS APIs. See `notes/stage2-shared-kotlin-plan.md`. - `androidMain/kotlin`: monotonic clock, reentrant locks, JVM zlib and file I/O, zero-copy `ByteBuffer` readers, firmware hashing/file writes and WAV file storage. - `iosMain/kotlin`: monotonic clock, recursive locks, native zlib and POSIX file @@ -22,7 +36,9 @@ bulk buffer crossing without putting Java APIs in common code. iOS uses ## Platform boundaries -`ProtocolPlatform` supplies clocks, locks and persistent deflaters. `expect` / +`ProtocolPlatform` supplies clocks, locks, persistent deflaters and condition +variables (`ProtocolCondition`, NOT reentrant on iOS: NSCondition). `InterruptibleSleep`, +`Latch` and `BlockingQueue` in commonMain build on it. `expect` / `actual` functions select default platform services at compilation. Stateful transports and caches retain reentrant locking; callbacks still run on their caller's thread. The migration does not introduce implicit UI-thread dispatch. diff --git a/native/kotlin/migrated-java-sources.json b/native/kotlin/migrated-java-sources.json index dd32ffa3..6f65dba4 100644 --- a/native/kotlin/migrated-java-sources.json +++ b/native/kotlin/migrated-java-sources.json @@ -409,6 +409,6 @@ }, { "java": "com/faceclaw/app/util/InterruptibleSleep.java", - "kotlin": "App_Resources/Android/src/main/java/com/faceclaw/app/util/InterruptibleSleep.kt" + "kotlin": "native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Concurrency.kt" } ] diff --git a/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/PlatformUtil.android.kt b/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/PlatformUtil.android.kt new file mode 100644 index 00000000..fa5bb6a0 --- /dev/null +++ b/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/PlatformUtil.android.kt @@ -0,0 +1,57 @@ +package com.faceclaw.app + +import java.security.MessageDigest +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale + +actual class Sha256Digest actual constructor() { + private val digest = MessageDigest.getInstance("SHA-256") + + actual fun update(bytes: ByteArray, offset: Int, length: Int) = digest.update(bytes, offset, length) + + actual fun digest(): ByteArray = digest.digest() +} + +actual fun currentTimeMillis(): Long = System.currentTimeMillis() + +actual fun formatLocalTime(epochMs: Long, pattern: String): String = + SimpleDateFormat(pattern, Locale.US).format(Date(epochMs)) + +actual object PlatformLog { + actual fun i(tag: String, message: String) { + android.util.Log.i(tag, message) + } + + actual fun w(tag: String, message: String) { + android.util.Log.w(tag, message) + } + + actual fun e(tag: String, message: String, error: Throwable?) { + if (error != null) android.util.Log.e(tag, message, error) else android.util.Log.e(tag, message) + } +} + +actual fun startThread(name: String, daemon: Boolean, body: () -> Unit) { + val thread = Thread(body, name) + thread.isDaemon = daemon + thread.start() +} + +actual fun sleepMs(ms: Long) { + try { + Thread.sleep(ms) + } catch (ignored: InterruptedException) { + Thread.currentThread().interrupt() + } +} + +actual fun writeFileData(path: String, bytes: ByteArray) = java.io.File(path).writeBytes(bytes) + +actual fun fileExists(path: String): Boolean = java.io.File(path).exists() + +actual fun fileLength(path: String): Long = java.io.File(path).let { if (it.exists()) it.length() else -1L } + +actual fun deleteFile(path: String): Boolean = java.io.File(path).delete() + +actual fun renameFile(from: String, to: String): Boolean = java.io.File(from).renameTo(java.io.File(to)) diff --git a/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/g2protocol/AndroidProtocolPlatform.kt b/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/g2protocol/AndroidProtocolPlatform.kt index b5667e1d..96c8a4a1 100644 --- a/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/g2protocol/AndroidProtocolPlatform.kt +++ b/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/g2protocol/AndroidProtocolPlatform.kt @@ -20,6 +20,22 @@ object AndroidProtocolPlatform : ProtocolPlatform { override fun createDeflater(): ProtocolDeflater = AndroidDeflater() + override fun createCondition(): ProtocolCondition = + object : ProtocolCondition { + private val lock = ReentrantLock() + private val condition = lock.newCondition() + + override fun lock() = lock.lock() + + override fun unlock() = lock.unlock() + + override fun awaitMs(timeoutMs: Long) { + if (timeoutMs > 0) condition.await(timeoutMs, java.util.concurrent.TimeUnit.MILLISECONDS) + } + + override fun signalAll() = condition.signalAll() + } + @JvmStatic fun writeType(mode: GattWriteMode): Int = when (mode) { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/PlatformServices.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/PlatformServices.kt index 9d0f0dca..739c23e9 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/PlatformServices.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/PlatformServices.kt @@ -8,3 +8,15 @@ internal expect fun deflateData(bytes: ByteArray): ByteArray internal expect fun inflateData(bytes: ByteArray, size: Int): ByteArray internal expect fun readFileData(path: String): ByteArray + +/** Whole-file write (truncating); parent directories must exist. */ +expect fun writeFileData(path: String, bytes: ByteArray) + +expect fun fileExists(path: String): Boolean + +/** Size in bytes, or -1 when the file does not exist. */ +expect fun fileLength(path: String): Long + +expect fun deleteFile(path: String): Boolean + +expect fun renameFile(from: String, to: String): Boolean diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/SettingsDocument.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/SettingsDocument.kt index baf4af2c..ed240a09 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/SettingsDocument.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/SettingsDocument.kt @@ -5,7 +5,7 @@ class SettingsDocument private constructor(private val settings: Map value - is Map<*, *>, is List<*> -> SettingsJson.write(value) + is Map<*, *>, is List<*> -> Json.write(value) else -> fallback } fun getBoolean(key: String, fallback: Boolean): Boolean = settings[key] as? Boolean ?: fallback @@ -17,7 +17,7 @@ class SettingsDocument private constructor(private val settings: Map || parsed is List<*>) parsed else value } // Each entry migrates version N to N+1. Never rewrite unknown future schemas. @@ -45,7 +45,7 @@ class SettingsDocument private constructor(private val settings: Map ?: error("Expected config object") + val root = Json.parse(text) as? Map<*, *> ?: error("Expected config object") var schema = (root["schema"] as? JsonNumber)?.text?.toIntOrNull() ?: error("Missing schema") require(schema in 1..CURRENT_SCHEMA) { "Unsupported settings schema" } val raw = root["settings"] as? Map<*, *> ?: error("Missing settings") @@ -64,103 +64,7 @@ class SettingsDocument private constructor(private val settings: Map)["schema"] as JsonNumber).text != SettingsDocument.CURRENT_SCHEMA.toString() + ((Json.parse(text) as Map<*, *>)["schema"] as JsonNumber).text != SettingsDocument.CURRENT_SCHEMA.toString() }.getOrDefault(false) fun decode(text: String): SettingsDocument? = runCatching { SettingsDocument.decode(text) }.getOrNull() } - -private data class JsonNumber(val text: String) - -/** Strict JSON plus // and block comments and trailing commas, on both platforms. */ -private object SettingsJson { - private val numberPattern = Regex("-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?") - fun parse(text: String): Any? = Parser(text).parse() - fun write(value: Any?, pretty: Boolean = false, depth: Int = 0): String { - fun quoted(text: String): String = buildString { - append('"') - for (c in text) when (c) { - '"' -> append("\\\""); '\\' -> append("\\\\"); '\n' -> append("\\n"); '\r' -> append("\\r"); '\t' -> append("\\t") - else -> if (c < ' ') append("\\u" + c.code.toString(16).padStart(4, '0')) else append(c) - } - append('"') - } - fun collection(open: String, close: String, entries: List): String { - if (entries.isEmpty()) return open + close - return if (pretty) open + "\n" + entries.joinToString(",\n") { " ".repeat(depth + 1) + it } + "\n" + " ".repeat(depth) + close - else open + entries.joinToString(",") + close - } - return when (value) { - null -> "null" - is String -> quoted(value) - is Boolean -> value.toString() - is JsonNumber -> value.text - is List<*> -> collection("[", "]", value.map { write(it, pretty, depth + 1) }) - is Map<*, *> -> collection("{", "}", value.entries.map { quoted(it.key as String) + (if (pretty) ": " else ":") + write(it.value, pretty, depth + 1) }) - else -> error("Unsupported JSON value") - } - } - private class Parser(val text: String) { - var i = 0 - fun parse(): Any? { val result = value(0); space(); require(i == text.length); return result } - fun space() { - while (i < text.length) { - if (text[i] in " \r\n\t\uFEFF") { i++; continue } - if (text.startsWith("//", i)) { while (i < text.length && text[i] != '\n' && text[i] != '\r') i++; continue } - if (text.startsWith("/*", i)) { val end = text.indexOf("*/", i + 2); require(end >= 0); i = end + 2; continue } - break - } - } - fun take(c: Char): Boolean { space(); return if (i < text.length && text[i] == c) { i++; true } else false } - fun value(depth: Int): Any? { - require(depth < 64); space(); require(i < text.length) - return when (text[i]) { - '"' -> string() - '{' -> { - i++; val result = linkedMapOf() - if (!take('}')) while (true) { - space(); val key = string(); require(!result.containsKey(key)); require(take(':')) - result[key] = value(depth + 1) - if (take('}')) break - require(take(',')); if (take('}')) break - } - result - } - '[' -> { - i++; val result = mutableListOf() - if (!take(']')) while (true) { - result.add(value(depth + 1)); if (take(']')) break - require(take(',')); if (take(']')) break - } - result - } - 't' -> literal("true", true) - 'f' -> literal("false", false) - 'n' -> literal("null", null) - else -> { - val match = numberPattern.find(text, i) - require(match != null && match.range.first == i) - require(match.value.toDouble().isFinite()); i += match.value.length; JsonNumber(match.value) - } - } - } - fun literal(word: String, result: Any?): Any? { require(text.startsWith(word, i)); i += word.length; return result } - fun string(): String { - require(i < text.length && text[i++] == '"') - return buildString { - while (true) { - require(i < text.length); val c = text[i++] - if (c == '"') break - require(c >= ' ') - if (c != '\\') { append(c); continue } - require(i < text.length) - append(when (val escaped = text[i++]) { - '"', '\\', '/' -> escaped - 'b' -> '\b'; 'f' -> '\u000c'; 'n' -> '\n'; 'r' -> '\r'; 't' -> '\t' - 'u' -> { require(i + 4 <= text.length); val hex = text.substring(i, i + 4); require(hex.all { it in "0123456789abcdefABCDEF" }); val code = hex.toInt(16); i += 4; code.toChar() } - else -> error("Invalid escape") - }) - } - } - } - } -} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmRingingPolicy.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmRingingPolicy.kt new file mode 100644 index 00000000..26eb92f2 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmRingingPolicy.kt @@ -0,0 +1,275 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmField + +/** One item currently ringing. Subclassed by the Android service for its own bookkeeping. */ +open class RingingItem( + @JvmField val id: Long, + title: String?, + text: String?, + kind: String?, + snoozeMinutes: Int, + @JvmField val ringAtMs: Long, +) { + @JvmField val title: String = if (title == null || title.trim().isEmpty()) "Alarm" else title + @JvmField val text: String = text ?: "" + @JvmField val kind: String = kind ?: AlarmSchedule.KIND_ALARM + @JvmField val snoozeMinutes: Int = maxOf(1, snoozeMinutes) + @JvmField var deliveredAtMs: Long = 0 + @JvmField var escalated: Boolean = false + @JvmField var silenced: Boolean = false +} + +/** Delayed callbacks for the escalation timers; the owner's main thread on Android. */ +interface AlarmScheduler { + fun postDelayed(token: Any, delayMs: Long, action: () -> Unit) + + fun cancel(token: Any) + + fun cancelAll() +} + +/** Platform effects of ringing: notifications, sound, the schedule, and the journal. */ +interface RingingSink { + /** Show or refresh the item's notification (title/status wording comes from the item). */ + fun showNotification(item: RingingItem) + + /** The item is gone: drop its notification and any per-item resources. */ + fun itemRemoved(item: RingingItem) + + /** Something started ringing: keep the device awake for the escalation window. */ + fun ringingStarted() + + fun startSound() + + fun stopSound() + + /** Re-arm the item (a snooze) at [atMs]. */ + fun reschedule(item: RingingItem, atMs: Long, minutes: Int) + + /** Forget the item's schedule entry (a dismiss). */ + fun cancelSchedule(id: Long) + + fun recordPhoneAction(id: Long, action: String, minutes: Int) + + fun log(line: String) +} + +/** + * Ringing escalation. Each item starts silent on the phone (a notification only, the glasses do + * the ringing) and escalates to phone sound when the glasses cannot carry it: not connected, + * not on a head, charging, no delivery confirmation from the JS side within [DELIVERY_WAIT_MS], + * or no acknowledgement within [ACK_WAIT_MS] of delivery. Sound stops after [AUTO_SILENCE_MS] + * while the notification stays. The policy is process-wide; the platform host (a service on + * Android) attaches its scheduler and sink while it is alive. + */ +class AlarmRingingPolicy( + private val gate: GlassesStatusGate, + private val clock: () -> Long = ::currentTimeMillis, + platform: ProtocolPlatform = protocolPlatform(), +) { + private val lock = platform.createLock() + /** Ringing items, oldest first. */ + private val ringing = LinkedHashMap() + /** + * Signals that arrived before the ring request was processed (the JS engine fires, launches + * its window and reports delivery on the same thread the host queues behind), keyed by id + * with their arrival time. Consumed by [ring]. + */ + private val deliveredEarly = LinkedHashMap() + private val stoppedEarly = LinkedHashMap() + private var scheduler: AlarmScheduler? = null + private var sink: RingingSink? = null + + fun attach(scheduler: AlarmScheduler, sink: RingingSink) { + lock.withLock { + this.scheduler = scheduler + this.sink = sink + } + } + + fun detach() { + lock.withLock { + scheduler?.cancelAll() + scheduler = null + sink = null + } + } + + fun isRinging(id: Long): Boolean = lock.withLock { ringing.containsKey(id) } + + fun isAnythingRinging(): Boolean = lock.withLock { ringing.isNotEmpty() } + + fun snapshot(): List = lock.withLock { ArrayList(ringing.values) } + + /** + * The glasses report showing [id]. True when the item is ringing (the host should process + * the delivery); false when it is not yet known, in which case the signal is kept for a + * ring request that follows within [EARLY_SIGNAL_MAX_AGE_MS]. + */ + fun deliveredOrDefer(id: Long): Boolean = + lock.withLock { + if (ringing.containsKey(id)) true + else { + deliveredEarly[id] = clock() + false + } + } + + /** As [deliveredOrDefer], for an acknowledgement / cancellation. */ + fun stopOrDefer(id: Long): Boolean = + lock.withLock { + if (ringing.containsKey(id)) true + else { + stoppedEarly[id] = clock() + false + } + } + + /** An item came due (idempotent per id: a duplicate ring only refreshes the notification). */ + fun ring(item: RingingItem) { + if (item.id == 0L) return + lock.withLock { + val sink = sink ?: return + val existing = ringing[item.id] + if (existing != null) { + // The engine's JS timeout and the platform alarm both fired: one ring. + sink.showNotification(existing) + return + } + if (takeEarlySignal(stoppedEarly, item.id)) { + // Acknowledged or cancelled before this request was processed. + sink.log("ring " + item.id + " already acknowledged") + return + } + ringing[item.id] = item + sink.log("ring " + item.kind + " " + item.id + " (" + gate.description() + ")") + sink.ringingStarted() + sink.showNotification(item) + if (!gate.canCarryAlarm()) { + escalate(item, gate.description()) + return + } + if (takeEarlySignal(deliveredEarly, item.id)) { + markDelivered(item.id) + return + } + // The glasses could carry it: give the JS side a moment to confirm they are + // actually showing it, then hold for the acknowledgement. + scheduler?.postDelayed("delivery:" + item.id, DELIVERY_WAIT_MS) { + lock.withLock { + val current = ringing[item.id] + if (current != null && !current.escalated && current.deliveredAtMs == 0L) { + escalate(current, "not delivered to the glasses") + } + } + } + } + } + + fun markDelivered(id: Long) { + lock.withLock { + val item = ringing[id] + if (item == null || item.deliveredAtMs != 0L) return + item.deliveredAtMs = clock() + sink?.log("delivered $id to glasses") + scheduler?.postDelayed("ack:$id", ACK_WAIT_MS) { + lock.withLock { + val current = ringing[id] + if (current != null && !current.escalated) { + escalate(current, "not acknowledged on the glasses") + } + } + } + } + } + + private fun escalate(item: RingingItem, reason: String) { + if (item.escalated) return + item.escalated = true + val sink = sink ?: return + sink.log("phone sound for " + item.id + ": " + reason) + sink.showNotification(item) + sink.startSound() + scheduler?.postDelayed("silence:" + item.id, AUTO_SILENCE_MS) { + lock.withLock { + val current = ringing[item.id] + if (current != null && current.escalated && !current.silenced) { + current.silenced = true + this.sink?.log("auto-silenced " + current.id) + this.sink?.showNotification(current) + syncSound() + } + } + } + } + + /** Dismissed on the phone: journal it, stop it, and drop the schedule entry. */ + fun dismiss(id: Long) { + lock.withLock { + val item = ringing[id] ?: return + val sink = sink ?: return + sink.recordPhoneAction(id, "dismiss", 0) + removeItem(item) + // A one-off is over; the engine re-arms repeats. + sink.cancelSchedule(id) + } + } + + /** Snoozed on the phone: journal it, stop it, and re-arm on the phone directly so the snooze holds even with the JS side gone. */ + fun snooze(id: Long) { + lock.withLock { + val item = ringing[id] ?: return + val sink = sink ?: return + val minutes = item.snoozeMinutes + sink.recordPhoneAction(id, "snooze", minutes) + removeItem(item) + sink.reschedule(item, clock() + minutes * 60_000L, minutes) + } + } + + /** Stop an item without a phone action (acknowledged on the glasses / cancelled by the engine). */ + fun stopQuietly(id: Long, reason: String) { + lock.withLock { + val item = ringing[id] ?: return + sink?.log("$reason $id") + removeItem(item) + } + } + + /** Start or stop the sound to match whether any escalated, not-yet-silenced item exists. */ + fun syncSound() { + lock.withLock { + val sink = sink ?: return + if (ringing.values.any { it.escalated && !it.silenced }) sink.startSound() else sink.stopSound() + } + } + + fun cancelTimers() { + lock.withLock { scheduler?.cancelAll() } + } + + private fun removeItem(item: RingingItem) { + ringing.remove(item.id) + sink?.itemRemoved(item) + syncSound() + } + + /** Consume an early signal for the id; stale entries are dropped. */ + private fun takeEarlySignal(signals: MutableMap, id: Long): Boolean { + val at = signals.remove(id) + val now = clock() + signals.entries.removeAll { now - it.value > EARLY_SIGNAL_MAX_AGE_MS } + return at != null && now - at <= EARLY_SIGNAL_MAX_AGE_MS + } + + companion object { + /** How long to wait for the JS side to confirm the glasses are showing the item. */ + const val DELIVERY_WAIT_MS = 5_000L + /** How long after delivery to the glasses before the phone joins in. */ + const val ACK_WAIT_MS = 30_000L + /** Sound and vibration stop after this; the notification stays. */ + const val AUTO_SILENCE_MS = 10 * 60_000L + const val EARLY_SIGNAL_MAX_AGE_MS = 15_000L + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmSchedule.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmSchedule.kt new file mode 100644 index 00000000..6a8dceaf --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/alarms/AlarmSchedule.kt @@ -0,0 +1,235 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.jvm.JvmField +import kotlin.jvm.JvmStatic + +/** Key/value persistence for the alarm schedule, journal and log (device-protected prefs on Android). */ +interface AlarmStore { + fun read(key: String): String? + + fun write(key: String, value: String?) +} + +/** One scheduled item: the JS engine's item id, its wall-clock trigger time, and what to show. */ +class AlarmEntry( + @JvmField val id: Long, + @JvmField val at: Long, + title: String?, + text: String?, + kind: String?, + @JvmField val snoozeMinutes: Int, +) { + @JvmField val title: String = title ?: "" + @JvmField val text: String = text ?: "" + @JvmField val kind: String = kind ?: AlarmSchedule.KIND_ALARM + + fun toJson(): Map = + linkedMapOf( + "id" to JsonNumber.of(id), + "at" to JsonNumber.of(at), + "title" to title, + "text" to text, + "kind" to kind, + "snoozeMinutes" to JsonNumber.of(snoozeMinutes), + ) + + companion object { + @JvmStatic + fun fromJson(value: Any?): AlarmEntry? { + val map = value.asObject() ?: return null + return AlarmEntry( + map["id"].asLong() ?: 0L, + map["at"].asLong() ?: 0L, + map["title"].asString() ?: "", + map["text"].asString() ?: "", + map["kind"].asString() ?: AlarmSchedule.KIND_ALARM, + map["snoozeMinutes"].asInt() ?: 10, + ) + } + } +} + +/** + * The persisted alarm schedule, the phone-action journal and the diagnostics log, plus the + * replay / staleness policies. Everything the platform's alarm clock API does not own. + * Compound read-modify-write operations are serialized on one lock; the store itself only + * needs to be atomic per key. + */ +class AlarmSchedule( + private val store: AlarmStore, + private val clock: () -> Long = ::currentTimeMillis, + platform: ProtocolPlatform = protocolPlatform(), +) { + private val lock = platform.createLock() + + /** All entries, in stored order. */ + fun entries(): List = lock.withLock { readEntries() } + + fun find(id: Long): AlarmEntry? = lock.withLock { readEntries().firstOrNull { it.id == id } } + + /** Add or replace the entry with the same id (moved to the end). */ + fun put(entry: AlarmEntry) { + lock.withLock { + val next = readEntries().filter { it.id != entry.id } + entry + writeEntries(next) + } + } + + fun remove(id: Long) { + lock.withLock { writeEntries(readEntries().filter { it.id != id }) } + } + + /** + * Replay the schedule after a reboot, package update or clock change: entries already due + * ring now if inside the grace window, older ones are dropped as missed (and logged), the + * rest are handed to [arm]. Logs the outcome. + */ + fun replay(reason: String?, ring: (AlarmEntry) -> Unit, arm: (AlarmEntry) -> Unit) { + val scheduled = entries() + val now = clock() + var armed = 0 + for (entry in scheduled) { + if (entry.at <= now) { + if (now - entry.at <= LATE_GRACE_MS) { + ring(entry) + } else { + log("missed " + entry.kind + " " + entry.id + " (" + reason + ")") + remove(entry.id) + } + continue + } + arm(entry) + armed++ + } + log("rescheduled $armed ($reason)") + } + + /** The soonest future trigger time, or null when nothing is pending. */ + fun soonestPendingAt(now: Long = clock()): Long? = + entries().filter { it.at > now }.minOfOrNull { it.at } + + /** + * The schedule and the system alarm clock can disagree (a force-stop clears alarms but not + * the file). True when the soonest stored entry is not what the system reports as its next + * alarm clock; another app's sooner alarm is fine, only a later (or absent) one proves ours + * is missing. [systemNextAlarmAt] is null when the system has no alarm clock set. + */ + fun looksStale(systemNextAlarmAt: Long?, now: Long = clock()): Boolean { + val soonest = soonestPendingAt(now) ?: return false + return systemNextAlarmAt == null || systemNextAlarmAt > soonest + 1000 + } + + // ------------------------------------------------------------------ + // Phone-action journal (dismiss / snooze done on the phone, replayed by the JS engine) + + fun appendJournal(id: Long, action: String, minutes: Int) { + val event = linkedMapOf( + "id" to JsonNumber.of(id), + "action" to action, + "minutes" to JsonNumber.of(minutes), + "at" to JsonNumber.of(clock()), + ) + lock.withLock { + val journal = readArray(KEY_JOURNAL) + event + store.write(KEY_JOURNAL, Json.write(journal)) + } + log("phone " + action + " " + id + (if (minutes > 0) " ($minutes min)" else "")) + } + + /** Hand the journal over as a JSON array and clear it. */ + fun drainJournal(): String = + lock.withLock { + val text = Json.write(readArray(KEY_JOURNAL)) + store.write(KEY_JOURNAL, "[]") + text + } + + // ------------------------------------------------------------------ + // Diagnostics log (bounded, newest last) + + fun log(line: String) { + lock.withLock { + val existing = readArray(KEY_LOG).map { it.asString() ?: it?.toString() ?: "" } + val kept = existing.drop(maxOf(0, existing.size - (LOG_LINES - 1))) + store.write(KEY_LOG, Json.write(kept + (clock().toString() + " " + line))) + } + } + + fun readLog(): String = + lock.withLock { readArray(KEY_LOG).joinToString("\n") { it.asString() ?: it?.toString() ?: "" } } + + // ------------------------------------------------------------------ + + private fun readArray(key: String): List { + val raw = store.read(key) ?: return emptyList() + return runCatching { Json.parseArray(raw) }.getOrDefault(emptyList()) + } + + private fun readEntries(): List = readArray(KEY_SCHEDULED).mapNotNull { AlarmEntry.fromJson(it) } + + private fun writeEntries(entries: List) { + store.write(KEY_SCHEDULED, Json.write(entries.map { it.toJson() })) + } + + companion object { + const val KIND_TIMER = "timer" + const val KIND_ALARM = "alarm" + + const val KEY_SCHEDULED = "scheduled" + const val KEY_JOURNAL = "journal" + const val KEY_LOG = "log" + const val LOG_LINES = 60 + + /** + * A schedule entry found already past due (after a reboot, or when the process was + * asleep) rings if it is at most this late; older ones are dropped as missed. Matches + * the JS engine's grace window. + */ + const val LATE_GRACE_MS = 5 * 60_000L + + /** A stable per-item request code for platform alarm/notification identities. */ + @JvmStatic + fun requestCode(id: Long): Int = (id xor (id ushr 32)).toInt() and 0x7fffffff + } +} + +/** + * The last glasses status report pushed by the JS side. In memory only, so a dead process + * reads as "no glasses"; a report older than [MAX_AGE_MS] is not trusted either. + */ +class GlassesStatusGate(private val clock: () -> Long = ::currentTimeMillis) { + @Volatile private var connected = false + @Volatile private var worn = false + @Volatile private var charging = false + @Volatile private var statusAtMs = 0L + + fun set(connected: Boolean, worn: Boolean, charging: Boolean) { + this.connected = connected + this.worn = worn + this.charging = charging + statusAtMs = clock() + } + + /** True only when a fresh report says the glasses are connected, on a head, and not charging. */ + fun canCarryAlarm(): Boolean { + val at = statusAtMs + if (at == 0L || clock() - at > MAX_AGE_MS) return false + return connected && worn && !charging + } + + fun description(): String { + val at = statusAtMs + if (at == 0L) return "no glasses status" + if (clock() - at > MAX_AGE_MS) return "glasses status stale" + if (!connected) return "glasses not connected" + if (charging) return "glasses charging" + if (!worn) return "glasses not worn" + return "glasses worn" + } + + companion object { + /** A glasses status report older than this is not trusted (the JS side is probably gone). */ + const val MAX_AGE_MS = 3 * 60_000L + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/AudioSegmentation.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/AudioSegmentation.kt new file mode 100644 index 00000000..d1f98a4d --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/AudioSegmentation.kt @@ -0,0 +1,127 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic +import kotlin.math.abs +import kotlin.math.min +import kotlin.math.sqrt + +/** + * Sample-level helpers shared by the push-to-talk voice controller and the caption engine + * (previously two private copies each). All PCM is 16 kHz mono S16LE unless stated. + */ +object AudioSegmentation { + /** + * Where to end a decode segment: the center of the quietest [windowSamples]-long window + * within the last [searchSamples] of `samples[offset until offset + length]`, so the cut + * lands between words rather than splitting one. Returns [length] when the region is + * too short to search. + */ + @JvmStatic + fun quietestCutPoint(samples: FloatArray, length: Int, searchSamples: Int, windowSamples: Int): Int = + quietestCutPoint(length, searchSamples, windowSamples) { samples[it].toDouble() } + + @JvmStatic + fun quietestCutPoint(samples: ShortArray, offset: Int, length: Int, searchSamples: Int, windowSamples: Int): Int = + quietestCutPoint(length, searchSamples, windowSamples) { samples[offset + it].toDouble() } + + private inline fun quietestCutPoint(length: Int, searchSamples: Int, windowSamples: Int, sample: (Int) -> Double): Int { + val searchStart = maxOf(0, length - searchSamples) + val win = windowSamples + if (length - searchStart <= win) return length + var sum = 0.0 + for (i in searchStart until searchStart + win) { + val s = sample(i) + sum += s * s + } + var best = sum + var bestStart = searchStart + var start = searchStart + 1 + while (start + win <= length) { + val dropped = sample(start - 1) + val added = sample(start + win - 1) + sum += added * added - dropped * dropped + if (sum < best) { + best = sum + bestStart = start + } + start++ + } + return bestStart + win / 2 + } + + @JvmStatic + fun peakAmplitude(samples: FloatArray): Float = peakAmplitude(samples, samples.size) + + @JvmStatic + fun peakAmplitude(samples: FloatArray, count: Int): Float { + var peak = 0f + for (i in 0 until count) { + val a = abs(samples[i]) + if (a > peak) peak = a + } + return peak + } + + /** + * Scales [samples] in place so the peak reaches [targetPeak], with the gain capped at + * [maxGain]; audio already at or above the target is left untouched. + */ + @JvmStatic + fun normalizePeak(samples: FloatArray, targetPeak: Float, maxGain: Float) { + val peak = peakAmplitude(samples) + if (peak <= 0f) return + val gain = min(targetPeak / peak, maxGain) + if (gain <= 1f) return + for (i in samples.indices) samples[i] *= gain + } + + /** S16 samples to [-1, 1] floats. */ + @JvmStatic + fun pcm16ToFloat(samples: ShortArray, offset: Int, count: Int): FloatArray { + val out = FloatArray(count) + for (i in 0 until count) out[i] = samples[offset + i] / 32768.0f + return out + } + + /** S16LE bytes to [-1, 1] floats (an odd trailing byte is ignored). */ + @JvmStatic + fun pcm16leToFloat(bytes: ByteArray, offset: Int, byteCount: Int): FloatArray { + val count = byteCount / 2 + val out = FloatArray(count) + for (i in 0 until count) { + val base = offset + i * 2 + out[i] = pcm16le(bytes[base], bytes[base + 1]) / 32768.0f + } + return out + } + + @JvmStatic + fun pcm16leToFloat(bytes: ByteArray): FloatArray = pcm16leToFloat(bytes, 0, bytes.size) + + /** One little-endian S16 sample from its two bytes. */ + @JvmStatic + fun pcm16le(low: Byte, high: Byte): Short = ((low.toInt() and 0xff) or (high.toInt() shl 8)).toShort() + + /** S16 samples to S16LE bytes. */ + @JvmStatic + fun pcm16ToLittleEndian(samples: ShortArray, offset: Int, count: Int): ByteArray { + val le = ByteArray(count * 2) + for (i in 0 until count) { + val s = samples[offset + i].toInt() + le[i * 2] = (s and 0xff).toByte() + le[i * 2 + 1] = ((s shr 8) and 0xff).toByte() + } + return le + } + + /** Root-mean-square of `samples[offset until offset + count]` in S16 units. */ + @JvmStatic + fun rms(samples: ShortArray, offset: Int, count: Int): Double { + var sumSquares = 0.0 + for (i in 0 until count) { + val s = samples[offset + i].toDouble() + sumSquares += s * s + } + return sqrt(sumSquares / maxOf(1, count)) + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/CaptionEngineCore.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/CaptionEngineCore.kt new file mode 100644 index 00000000..6d18e7e6 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/CaptionEngineCore.kt @@ -0,0 +1,380 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.math.max +import kotlin.math.min +import kotlin.math.sqrt + +/** Receives segmenter events synchronously on the thread feeding [CaptionSegmenter.processChunk]. */ +interface CaptionSegmentSink { + fun onSpeechStart(startMs: Long) + + /** [samples] is the segmenter's own buffer, valid only for the duration of the call. */ + fun onUtterance(samples: ShortArray, length: Int, startMs: Long, endMs: Long, peakRms: Double) +} + +/** + * Splits decoded mic PCM into utterances with an adaptive energy gate: the noise floor is a + * rolling mean tracked while idle, onset fires at ONSET_FACTOR above it (keeping PRE_ROLL_MS of + * idle audio so leading consonants survive), and the utterance ends after [silenceMs] below + * RELEASE_FACTOR or at MAX_UTTERANCE_MS. Boundaries are measured on the 16 kHz sample clock, + * not the wall clock: BLE delivers mic packets in bursts. + */ +class CaptionSegmenter(private val sink: CaptionSegmentSink) { + companion object { + const val SAMPLE_RATE = 16000 + const val ONSET_FACTOR = 3.0 + const val RELEASE_FACTOR = 1.8 + const val MIN_RMS = 220.0 + const val NOISE_EMA_ALPHA = 0.05 + const val PRE_ROLL_MS = 400 + const val DEFAULT_SILENCE_MS = 800 + const val MIN_SILENCE_MS = 200 + const val MAX_SILENCE_MS = 3000 + const val MIN_UTTERANCE_MS = 350 + const val MAX_UTTERANCE_MS = 15000 + } + + @Volatile + var silenceMs = DEFAULT_SILENCE_MS + set(value) { + field = max(MIN_SILENCE_MS, min(MAX_SILENCE_MS, value)) + } + + private var totalSamples: Long = 0 + private var noiseFloor = 0.0 + private var inUtterance = false + private var utteranceStartSample: Long = 0 + private var silenceRunSamples: Long = 0 + private var utterancePeakRms = 0.0 + private val utterance = ShortArray(SAMPLE_RATE * (MAX_UTTERANCE_MS / 1000)) + private var utteranceLength = 0 + private val preRoll = ShortArray(SAMPLE_RATE * PRE_ROLL_MS / 1000) + private var preRollLength = 0 + + val isInUtterance: Boolean + get() = inUtterance + + fun reset() { + totalSamples = 0 + noiseFloor = 0.0 + inUtterance = false + utteranceLength = 0 + preRollLength = 0 + silenceRunSamples = 0 + utterancePeakRms = 0.0 + } + + /** Feeds one chunk of S16LE PCM bytes (any chunking). */ + fun processChunk(chunk: ByteArray) { + val count = chunk.size / 2 + val pcm = ShortArray(count) + for (i in 0 until count) { + pcm[i] = AudioSegmentation.pcm16le(chunk[i * 2], chunk[i * 2 + 1]) + } + processChunk(pcm, count) + } + + fun processChunk(pcm: ShortArray, count: Int) { + var sumSquares = 0.0 + for (i in 0 until count) { + val s = pcm[i].toDouble() + sumSquares += s * s + } + val rms = sqrt(sumSquares / max(1, count)) + totalSamples += count.toLong() + + if (!inUtterance) { + // Track the noise floor only while idle so speech doesn't raise it. + noiseFloor = if (noiseFloor == 0.0) rms else noiseFloor * (1 - NOISE_EMA_ALPHA) + rms * NOISE_EMA_ALPHA + val threshold = max(noiseFloor, MIN_RMS) + if (rms >= threshold * ONSET_FACTOR) { + inUtterance = true + utteranceLength = 0 + silenceRunSamples = 0 + utterancePeakRms = rms + appendUtterance(preRoll, preRollLength) + utteranceStartSample = max(0L, totalSamples - count - preRollLength) + appendUtterance(pcm, count) + sink.onSpeechStart(utteranceStartSample * 1000 / SAMPLE_RATE) + } else { + appendPreRoll(pcm, count) + } + return + } + + appendUtterance(pcm, count) + utterancePeakRms = max(utterancePeakRms, rms) + val threshold = max(noiseFloor, MIN_RMS) + if (rms < threshold * RELEASE_FACTOR) { + silenceRunSamples += count.toLong() + } else { + silenceRunSamples = 0 + } + val utteranceMs = utteranceLength.toLong() * 1000 / SAMPLE_RATE + val silenceEnded = silenceRunSamples * 1000L / SAMPLE_RATE >= silenceMs + if (silenceEnded || utteranceMs >= MAX_UTTERANCE_MS) { + finalizeUtterance() + inUtterance = false + preRollLength = 0 + } + } + + /** Emits a trailing utterance (if any) so its text isn't lost on stop. */ + fun flush() { + if (inUtterance && utteranceLength > 0) { + finalizeUtterance() + } + inUtterance = false + preRollLength = 0 + } + + private fun appendPreRoll(pcm: ShortArray, count: Int) { + // Keep the last PRE_ROLL_MS of idle audio so onset consonants survive. + if (count >= preRoll.size) { + pcm.copyInto(preRoll, 0, count - preRoll.size, count) + preRollLength = preRoll.size + return + } + val keep = min(preRollLength, preRoll.size - count) + preRoll.copyInto(preRoll, 0, preRollLength - keep, preRollLength) + pcm.copyInto(preRoll, keep, 0, count) + preRollLength = keep + count + } + + private fun appendUtterance(pcm: ShortArray, count: Int) { + val room = utterance.size - utteranceLength + val copied = min(room, count) + if (copied > 0) { + pcm.copyInto(utterance, utteranceLength, 0, copied) + utteranceLength += copied + } + } + + private fun finalizeUtterance() { + val length = utteranceLength + val startMs = utteranceStartSample * 1000 / SAMPLE_RATE + val endMs = (utteranceStartSample + length) * 1000 / SAMPLE_RATE + if (endMs - startMs < MIN_UTTERANCE_MS) { + return + } + sink.onUtterance(utterance, length, startMs, endMs, utterancePeakRms) + } +} + +/** + * Transcribes one utterance in model-safe segments cut at the quietest window (Moonshine v2 + * fails past ~9.1 s of input) and attaches a voice-print from at most its first 10 s. + */ +class UtteranceDecoder(private val transcriber: OfflineTranscriber?, private val embedder: SpeakerEmbedder?) { + companion object { + const val SAMPLE_RATE = 16000 + const val DECODE_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8 + const val CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2 + const val CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000 + const val NORMALIZE_TARGET_PEAK = 0.9f + const val NORMALIZE_MAX_GAIN = 30f + // Voice-prints degrade on very long inputs; embed at most the first 10 s. + const val EMBED_MAX_SAMPLES = SAMPLE_RATE * 10 + } + + val hasTranscriber: Boolean + get() = transcriber != null + + fun recognize(utterance: ShortArray, length: Int): String { + val recognizer = transcriber + if (recognizer == null || length <= 0) { + return "" + } + val joined = StringBuilder() + var offset = 0 + while (offset < length) { + val remaining = length - offset + var segment = min(remaining, DECODE_SEGMENT_MAX_SAMPLES) + if (remaining > DECODE_SEGMENT_MAX_SAMPLES) { + segment = AudioSegmentation.quietestCutPoint(utterance, offset, segment, CUT_SEARCH_SAMPLES, CUT_WINDOW_SAMPLES) + } + val samples = AudioSegmentation.pcm16ToFloat(utterance, offset, segment) + AudioSegmentation.normalizePeak(samples, NORMALIZE_TARGET_PEAK, NORMALIZE_MAX_GAIN) + val part = recognizer.recognize(samples, samples.size).trim() + if (part.isNotEmpty()) { + if (joined.isNotEmpty() && ".,!?;:%)]}".indexOf(part[0]) < 0) { + joined.append(' ') + } + joined.append(part) + } + offset += segment + } + return joined.toString().trim() + } + + fun embed(utterance: ShortArray, length: Int): FloatArray? { + val currentEmbedder = embedder + if (currentEmbedder == null || length <= 0) { + return null + } + val count = min(length, EMBED_MAX_SAMPLES) + return currentEmbedder.embed(AudioSegmentation.pcm16ToLittleEndian(utterance, 0, count), SAMPLE_RATE) + } + + fun release() { + transcriber?.release() + embedder?.release() + } +} + +/** Platform services for [CaptionSession]. */ +interface CaptionHost { + val dispatcher: CallbackDispatcher + + /** Loads the caption recognizer from [modelDir], or null when the model files are absent. */ + fun loadTranscriber(modelDir: String): OfflineTranscriber? + + /** Loads the speaker-embedding model, or null when the file is absent. */ + fun loadEmbedder(modelPath: String): SpeakerEmbedder? +} + +/** + * Continuous captioning over pushed mic PCM: queue, worker thread (owned here, via the shared + * [startThread]), model lifecycle, segmentation and per-utterance decode/embedding, with + * listener callbacks marshalled through the host dispatcher. + */ +class CaptionSession( + private val host: CaptionHost, + private val platform: ProtocolPlatform = protocolPlatform(), + private val threadName: String = "FaceclawCaptionEngine", + private val logError: (String, Throwable) -> Unit = { message, error -> PlatformLog.e(TAG, message, error) }, +) : CaptionSegmentSink { + companion object { + const val TAG = "FaceclawCaptions" + const val MAX_QUEUE_PACKETS = 200 + } + + private val lock = platform.createLock() + private val queue = DroppingPacketQueue(MAX_QUEUE_PACKETS, platform) + private val segmenter = CaptionSegmenter(this) + @Volatile + private var listener: FaceclawCaptionEngineListener? = null + @Volatile + private var asrModelDir: String? = null + @Volatile + private var speakerModelPath: String? = null + @Volatile + private var started = false + private var workerFinished: Latch? = null + @Volatile + private var workerThreadName: String? = null + private var decoder: UtteranceDecoder? = null + + fun setListener(listener: FaceclawCaptionEngineListener?) { + this.listener = listener + } + + fun setAsrModelDir(dir: String?) { + this.asrModelDir = dir + } + + fun setSpeakerModelPath(path: String?) { + this.speakerModelPath = path + } + + fun setSilenceMs(ms: Int) { + segmenter.silenceMs = ms + } + + fun start() { + lock.withLock { + if (started) { + return + } + started = true + val finished = Latch(1, platform) + workerFinished = finished + startThread(threadName, true) { runLoop(finished) } + } + } + + /** Stops and waits up to 2 s for the worker unless called from it. */ + fun stop() { + var finished: Latch? = null + var workerName: String? = null + lock.withLock { + if (!started) { + return + } + started = false + finished = workerFinished + workerName = workerThreadName + } + queue.wake() + if (finished != null && (workerName == null || currentThreadName() != workerName)) { + finished.await(2000) + } + } + + /** Push decoded 16 kHz mono S16LE PCM (any chunking). */ + fun acceptPcm(pcm16le: ByteArray?) { + if (!started || pcm16le == null || pcm16le.size < 2) { + return + } + queue.put(pcm16le) + } + + private fun runLoop(finished: Latch) { + workerThreadName = currentThreadName() + try { + loadModels() + segmenter.reset() + while (started) { + val chunk = queue.take(250) { started } ?: continue + segmenter.processChunk(chunk) + } + // Flush a trailing utterance so its text isn't lost on stop. + segmenter.flush() + } catch (t: Throwable) { + logError("caption engine failed", t) + emitStatus("Captions failed: " + t.message) + } finally { + decoder?.release() + decoder = null + lock.withLock { + workerFinished = null + workerThreadName = null + } + finished.countDown() + } + } + + private fun loadModels() { + val modelDir = asrModelDir + val transcriber = if (modelDir != null) { + emitStatus("Loading caption model...") + host.loadTranscriber(modelDir) + } else { + null + } + val embedModel = speakerModelPath + val embedder = if (embedModel != null) host.loadEmbedder(embedModel) else null + decoder = UtteranceDecoder(transcriber, embedder) + emitStatus(if (transcriber != null) "Captions listening..." else "Captions listening (no ASR model)...") + } + + override fun onSpeechStart(startMs: Long) { + val currentListener = listener ?: return + host.dispatcher.post { currentListener.onSpeechStart(startMs) } + } + + override fun onUtterance(samples: ShortArray, length: Int, startMs: Long, endMs: Long, peakRms: Double) { + val currentDecoder = decoder ?: return + val text = currentDecoder.recognize(samples, length) + val embedding = currentDecoder.embed(samples, length) + val currentListener = listener ?: return + val embeddingCopy = embedding?.copyOf() + host.dispatcher.post { currentListener.onUtterance(text, embeddingCopy, startMs, endMs, peakRms) } + } + + private fun emitStatus(status: String?) { + val currentListener = listener ?: return + host.dispatcher.post { currentListener.onStatus(status) } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/Lc3PacketFramer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/Lc3PacketFramer.kt new file mode 100644 index 00000000..71e9e660 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/Lc3PacketFramer.kt @@ -0,0 +1,93 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic + +/** Decodes the LC3 frames of one G2 packet into [pcmOut]; returns samples written, <= 0 on error. */ +interface Lc3Codec { + fun decodeFrames(packet: ByteArray, offset: Int, length: Int, pcmOut: ShortArray): Int +} + +/** + * G2 microphone packet framing shared by the Android JNI decoder and the iOS port: length + * check, counter-based duplicate/late/missing accounting, trailer parsing and statistics. + * The codec itself (liblc3) is injected. + * + * Both arms may relay the same packet, so a counter gap of 0 or >= 128 (a late copy, including + * across the 255 -> 0 wrap) is dropped before it can disturb the decoder's history. The + * former Android decoder only dropped gap == 0; this adopts the wrap-safe rule the iOS + * decoder already used. + */ +class Lc3PacketFramer(private val codec: Lc3Codec) { + companion object { + const val SAMPLE_RATE = 16000 + const val FRAME_US = 10000 + const val FRAME_BYTES = 40 + const val FRAMES_PER_PACKET = 5 + const val PACKET_BYTES = 205 + const val COUNTER_OFFSET = 204 + const val SAMPLES_PER_FRAME = 160 + const val SAMPLES_PER_PACKET = FRAMES_PER_PACKET * SAMPLES_PER_FRAME + const val LC3_BYTES = FRAME_BYTES * FRAMES_PER_PACKET + // Trailer layout (firmware service_audio.c): after the 200 LC3 bytes the + // glasses DSP appends two signed 16-bit LE values computed on the raw + // stereo capture before the mono downmix — a signal-strength ratio and the + // asin-derived direction-of-arrival in degrees — then the packet counter. + const val SSR_OFFSET = 200 + const val ANGLE_OFFSET = 202 + /** Counter gaps at or beyond this are late copies, not losses. */ + const val LATE_GAP = 128 + + @JvmStatic + fun readTrailerS16(packet: ByteArray, offset: Int): Int = + ((packet[offset].toInt() and 0xff) or (packet[offset + 1].toInt() shl 8)).toShort().toInt() + } + + private var lastCounter = -1 + var realPackets: Long = 0 + private set + var duplicatePackets: Long = 0 + private set + var missingPackets: Long = 0 + private set + var decodeErrors: Long = 0 + private set + /** Firmware signal-strength ratio from the most recent decoded packet. */ + var lastSsr: Int = 0 + private set + /** Firmware direction-of-arrival (signed degrees) from the most recent decoded packet. */ + var lastAngleDegrees: Int = 0 + private set + + /** + * Returns the number of PCM samples written to [pcmOut], or 0 when the packet was dropped + * (wrong length, duplicate/late, or codec failure; see the counters). + */ + fun decodePacket(packet: ByteArray?, pcmOut: ShortArray?): Int { + if (packet == null || packet.size != PACKET_BYTES) { + decodeErrors++ + return 0 + } + if (pcmOut == null || pcmOut.size < SAMPLES_PER_PACKET) { + throw IllegalArgumentException("pcmOut must hold $SAMPLES_PER_PACKET samples") + } + val counter = packet[COUNTER_OFFSET].toInt() and 0xff + if (lastCounter >= 0) { + val gap = (counter - lastCounter) and 0xff + if (gap == 0 || gap >= LATE_GAP) { + duplicatePackets++ + return 0 + } + missingPackets += (gap - 1).toLong() + } + val decoded = codec.decodeFrames(packet, 0, LC3_BYTES, pcmOut) + if (decoded <= 0) { + decodeErrors++ + return 0 + } + realPackets++ + lastCounter = counter + lastSsr = readTrailerS16(packet, SSR_OFFSET) + lastAngleDegrees = readTrailerS16(packet, ANGLE_OFFSET) + return decoded + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoiceCaptureSession.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoiceCaptureSession.kt new file mode 100644 index 00000000..33c81cf1 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoiceCaptureSession.kt @@ -0,0 +1,833 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.jvm.JvmStatic +import kotlin.math.abs +import kotlin.math.max +import kotlin.math.min + +/** Platform services the voice-capture session needs; supplied by the Android/iOS adapter. */ +interface VoiceCaptureHost { + val dispatcher: CallbackDispatcher + + /** Runs first on the worker thread of every session (Android deletes legacy model files here). */ + fun onSessionStarting() + + /** True when a glasses session can carry microphone packets (false when no communicator is set). */ + fun isG2SessionReady(): Boolean + + /** Whether the glasses are still delivering packets; see [VoiceCaptureSession.isCapturing]. */ + fun isG2AudioCaptureActive(): Boolean + + /** The glasses packet source, or null when no communicator is available. */ + fun g2AudioSource(): PacketAudioSource? + + fun createPacketDecoder(): AudioPacketDecoder + + /** Opens the phone microphone at 16 kHz mono PCM16, or null when it cannot start. */ + fun openPhoneMic(): PcmAudioSource? + + /** Whether the on-device model files for [kind] are present (downloaded). */ + fun hasTranscriberModel(kind: VoiceModelKind): Boolean + + /** Loads the recognizer for [kind]; throws when the model cannot be loaded. */ + fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber + + /** The speaker-embedding model at [modelPath] (may be shared/cached across sessions). */ + fun speakerEmbedder(modelPath: String): SpeakerEmbedder + + /** Where a saved recording goes, or null when recordings cannot be stored. */ + fun recordingSink(): RecordingSink? +} + +/** + * Voice-input capture pipeline shared by both platforms: LC3 packet queue with drop/late + * accounting, firmware-DoA beam gate, per-chunk processing (suppression, recording, speaker + * verification buffer, endpointing, PCM emit), the segmented on-device transcript machine with + * REPLACE-semantics partials, and speaker verification at session end. The session owns its + * worker thread (started through the shared [startThread]); listener callbacks go through the + * host's [CallbackDispatcher] so the adapter decides the delivery thread. + */ +class VoiceCaptureSession( + private val host: VoiceCaptureHost, + private val platform: ProtocolPlatform = protocolPlatform(), + private val threadName: String = "FaceclawVoiceController", + private val logInfo: (String) -> Unit = { PlatformLog.i(TAG, it) }, + private val logWarn: (String) -> Unit = { PlatformLog.w(TAG, it) }, + private val logError: (String, Throwable) -> Unit = { message, error -> PlatformLog.e(TAG, message, error) }, +) { + companion object { + const val TAG = "FaceclawVoice" + const val SAMPLE_RATE = 16000 + const val MAX_AUDIO_QUEUE_PACKETS = 80 + const val EXPECTED_PACKET_INTERVAL_MS = 50 + const val LATE_PACKET_INTERVAL_MS = 90 + const val STATS_INTERVAL_MS = 5_000 + // Push-to-talk utterance boundaries come from the button. We re-decode the + // current audio segment in full for each live partial and emit the complete + // utterance text (REPLACE, never a delta). The sherpa Moonshine v2 decoder + // used here fails once a single input grows past roughly 9.1 seconds, so + // longer utterances are committed in model-safe segments. + const val TRANSCRIPT_DECODE_INTERVAL_MS = 700 + const val TRANSCRIPT_MIN_SAMPLES = SAMPLE_RATE / 3 + const val TRANSCRIPT_SEGMENT_MAX_SAMPLES = SAMPLE_RATE * 8 + // When a segment fills, cut at the quietest window within the last + // TRANSCRIPT_CUT_SEARCH_SAMPLES rather than mid-word at the 8s mark; the + // audio after the cut carries over into the next segment. + const val TRANSCRIPT_CUT_SEARCH_SAMPLES = SAMPLE_RATE * 2 + const val TRANSCRIPT_CUT_WINDOW_SAMPLES = SAMPLE_RATE * 30 / 1000 + // Glasses-mic PCM peaks around 0.1 full scale, and at that level the + // quantized Moonshine model often returns empty or garbled text. Boost + // each decode window toward this peak, with a gain cap so near-silent + // buffers aren't amplified into pure noise. + const val TRANSCRIPT_NORMALIZE_TARGET_PEAK = 0.9f + const val TRANSCRIPT_NORMALIZE_MAX_GAIN = 30f + const val TRANSCRIPT_LOG_PREVIEW_CHARS = 80 + // Below this peak amplitude (pre-normalization, of a full-scale +/-1.0f + // buffer) a segment is treated as silence and never reaches the Whisper + // recognizer at all, rather than risking a hallucinated non-answer. Picked + // conservatively low (well under typical mic noise floor already seen in + // this pipeline's normalization target) -- UNTESTED on real hardware, tune + // against real glasses captures rather than trusting this number. + const val WHISPER_SILENCE_PEAK_THRESHOLD = 0.01f + // Speaker verification against the enrolled wearer voice-print ("my voice + // only" command gating). Configured before start(); the utterance PCM is + // buffered (capped) and verified once at session end. + const val VERIFY_MAX_SAMPLES = SAMPLE_RATE * 10 + const val VERIFY_MIN_SAMPLES = SAMPLE_RATE + const val DEFAULT_VERIFY_THRESHOLD = 0.8f + /** Samples per G2 packet; the decode buffer the worker reuses. */ + const val PACKET_SAMPLES = Lc3PacketFramer.SAMPLES_PER_PACKET + + /** Joins transcript pieces, attaching leading punctuation to the previous text. */ + @JvmStatic + fun joinTranscript(prefix: String?, suffix: String?): String { + if (prefix.isNullOrEmpty()) { + return suffix ?: "" + } + if (suffix.isNullOrEmpty()) { + return prefix + } + val first = suffix[0] + val attachesToPrevious = ".,!?;:%)]}".indexOf(first) >= 0 + return prefix + (if (attachesToPrevious) "" else " ") + suffix + } + + @JvmStatic + fun parseModelKind(kind: String?): VoiceModelKind = + if ("whisper" == kind) VoiceModelKind.WHISPER else VoiceModelKind.MOONSHINE + } + + enum class Mode { + ONBOARD, // on-phone transcription (Moonshine or Whisper; see onboardModelKind) + CLOUD, // decode locally, emit PCM for a cloud recognizer on the TS side + } + + private class AudioPacket(val data: ByteArray, arm: String?, val arrivalMs: Long) { + val arm: String = arm ?: "?" + } + + private val lock = platform.createLock() + private val audioQueue = DroppingPacketQueue(MAX_AUDIO_QUEUE_PACKETS, platform) + @Volatile + private var listener: FaceclawVoiceControllerListener? = null + @Volatile + private var started = false + // Set once the worker has the mic enabled for this session. Read and + // written under `lock`, so it flips with `started` atomically. + private var audioStarted = false + private var workerFinished: Latch? = null + @Volatile + private var workerThreadName: String? = null + // Capture from the phone's own microphone instead of the G2 over BLE + // (preview-only mode). Latched into activePhoneMic at start() (under `lock`) + // so a mid-session setter call can't switch pipelines underneath the worker. + @Volatile + private var usePhoneMic = false + private var activePhoneMic = false + private var mode = Mode.CLOUD + @Volatile + private var onboardModelKind = VoiceModelKind.MOONSHINE + private var recognizer: OfflineTranscriber? = null + private var packetDecoder: AudioPacketDecoder? = null + private val transcriptSamples = FloatArray(TRANSCRIPT_SEGMENT_MAX_SAMPLES) + private var transcriptSampleCount = 0 + private var committedTranscriptSampleCount: Long = 0 + private var committedTranscript = "" + private var currentSegmentTranscript = "" + private var lastTranscriptDecodeAtMs: Long = 0 + private var lastTranscript = "" + @Volatile + private var saveRecordings = false + @Volatile + private var endpointing = false + private val endpointDetector = VoiceEndpointDetector() + private var recordingPcm: ByteSink? = null + @Volatile + private var verifySpeakerModelPath: String? = null + @Volatile + private var verifyWearerEmbedding: FloatArray? = null + @Volatile + private var verifyThreshold = DEFAULT_VERIFY_THRESHOLD + private var verifyBuffer: ShortArray? = null + private var verifyCount = 0 + // Global mic processing (Microphones app config): spectral noise + // suppression and firmware-DoA beam gating, applied to every capture + // session that opts in. The raw tap opts out. + @Volatile + private var suppressionEnabled = false + @Volatile + private var beamFilterEnabled = false + @Volatile + private var beamCenterDeg = 0 + @Volatile + private var beamHalfWidthDeg = 180 + private var suppressor: FaceclawNoiseSuppressor? = null + private var queuedPackets: Long = 0 + private var decodedSamples: Long = 0 + private var latePackets: Long = 0 + private var wrongArmPackets: Long = 0 + private var lastPacketArrivalMs: Long = 0 + private var maxInterPacketMs: Long = 0 + private var lastStatsAtMs: Long = 0 + + fun setListener(listener: FaceclawVoiceControllerListener?) { + this.listener = listener + } + + fun setUsePhoneMic(usePhoneMic: Boolean) { + this.usePhoneMic = usePhoneMic + } + + fun setSaveRecordings(saveRecordings: Boolean) { + this.saveRecordings = saveRecordings + } + + fun setOnboardModelKind(kind: String?) { + this.onboardModelKind = parseModelKind(kind) + } + + fun setEndpointing(endpointing: Boolean) { + this.endpointing = endpointing + } + + fun setSpeakerVerification(speakerModelPath: String?, wearerEmbedding: FloatArray?, threshold: Float) { + this.verifySpeakerModelPath = speakerModelPath + this.verifyWearerEmbedding = wearerEmbedding + this.verifyThreshold = if (threshold > 0) threshold else DEFAULT_VERIFY_THRESHOLD + } + + fun clearSpeakerVerification() { + this.verifySpeakerModelPath = null + this.verifyWearerEmbedding = null + } + + fun setNoiseSuppression(enabled: Boolean) { + this.suppressionEnabled = enabled + } + + fun setBeamFilter(enabled: Boolean, centerDeg: Int, halfWidthDeg: Int) { + this.beamFilterEnabled = enabled + this.beamCenterDeg = centerDeg + this.beamHalfWidthDeg = max(5, min(180, halfWidthDeg)) + } + + /** Direction gating: true when [angleDegrees] lies within centerDeg ± halfWidthDeg (wrap-safe). */ + fun withinBeam(angleDegrees: Int): Boolean { + var delta = angleDegrees - beamCenterDeg + while (delta > 180) delta -= 360 + while (delta < -180) delta += 360 + return abs(delta) <= beamHalfWidthDeg + } + + private fun applySuppression(pcm: ShortArray, count: Int) { + try { + if (suppressor == null) { + suppressor = FaceclawNoiseSuppressor(SAMPLE_RATE) + } + val le = AudioSegmentation.pcm16ToLittleEndian(pcm, 0, count) + val cleaned = suppressor!!.process(le)!! + val cleanedCount = min(count, cleaned.size / 2) + for (i in 0 until cleanedCount) { + pcm[i] = AudioSegmentation.pcm16le(cleaned[i * 2], cleaned[i * 2 + 1]) + } + } catch (t: Throwable) { + logWarn("noise suppression failed; passing audio through (${t.message})") + suppressionEnabled = false + } + } + + fun start(requestedMode: String?) { + start(requestedMode, 0) + } + + fun start(requestedMode: String?, captureId: Int) { + lock.withLock { + if (started) { + emitStatus("Voice control is already listening.") + emitStopped(captureId) + return + } + if (!usePhoneMic && !host.isG2SessionReady()) { + emitStatus("Voice control needs an active G2 connection.") + emitStopped(captureId) + return + } + mode = parseMode(requestedMode) + activePhoneMic = usePhoneMic + started = true + audioStarted = false + val finished = Latch(1, platform) + workerFinished = finished + startThread(threadName, true) { runLoop(captureId, finished) } + } + } + + /** + * Whether mic audio is actually flowing. start() only records intent: the + * enable lives in the glasses' EvenHub session, so a transport drop or a + * session suspend can leave this session started with a worker that will + * never see another packet. + */ + fun isCapturing(): Boolean { + var audioUp = false + var phoneMic = false + lock.withLock { + if (!started) { + return false + } + audioUp = audioStarted + phoneMic = activePhoneMic + } + if (!audioUp) { + // The worker is still bringing the mic up; report it as running so + // a concurrent request shares it instead of restarting it. + return true + } + if (phoneMic) { + // The phone mic has no session to lose the enable to; it runs until stop(). + return true + } + return host.isG2AudioCaptureActive() + } + + /** + * Stops the session and waits up to 1.5 s for the worker to finish unless + * called from the worker itself. The worker checks the stop flag between + * packets (every packet or 250 ms wait) and between phone-mic reads (50 ms). + */ + fun stop() { + var finished: Latch? = null + var workerName: String? = null + lock.withLock { + if (!started) { + return + } + started = false + finished = workerFinished + workerName = workerThreadName + } + stopG2Audio() + audioQueue.wake() + if (finished != null && (workerName == null || currentThreadName() != workerName)) { + finished.await(1500) + } + } + + fun close() { + stop() + } + + private fun parseMode(requestedMode: String?): Mode { + if ("cloud" == requestedMode) { + return Mode.CLOUD + } + return Mode.ONBOARD + } + + private fun runLoop(captureId: Int, finished: Latch) { + workerThreadName = currentThreadName() + try { + host.onSessionStarting() + val currentMode = mode + val currentOnboardKind = onboardModelKind + if (currentMode == Mode.ONBOARD) { + if (!host.hasTranscriberModel(currentOnboardKind)) { + emitStatus("Voice model not downloaded (see Settings > Voice).") + return + } + emitStatus("Loading transcription model...") + recognizer = host.loadTranscriber(currentOnboardKind) + resetTranscriptState() + lastTranscript = "" + } + endpointDetector.reset() + suppressor?.reset() + recordingPcm = if (saveRecordings) ByteSink(SAMPLE_RATE * 2 * 4) else null + val verifying = verifySpeakerModelPath != null && verifyWearerEmbedding != null + verifyBuffer = if (verifying) ShortArray(VERIFY_MAX_SAMPLES) else null + verifyCount = 0 + if (activePhoneMic) { + val record = host.openPhoneMic() + if (record == null) { + emitStatus("Could not start the phone microphone.") + return + } + lock.withLock { audioStarted = true } + emitStatus(if (currentMode == Mode.CLOUD) "Listening (cloud)..." else "Listening...") + try { + processPhoneAudio(record) + } finally { + record.close() + } + } else { + packetDecoder = host.createPacketDecoder() + if (!startG2Audio()) { + emitStatus("Could not start G2 microphone input.") + return + } + lock.withLock { audioStarted = true } + emitStatus(if (currentMode == Mode.CLOUD) "Listening (cloud)..." else "Listening...") + processG2Audio() + } + // Verification result must precede the final transcript so the + // TS bridge can suppress a non-wearer command before it is acted + // on (the callbacks are posted in order to the dispatcher). + runSpeakerVerification() + // Button released / stop requested: emit one final full-utterance + // transcript so the UI can freeze it. + if (currentMode == Mode.ONBOARD) { + decodeTranscript(true) + } + } catch (error: Throwable) { + logError("Voice control failed", error) + emitStatus("Voice control failed: " + error.message) + } finally { + stopG2Audio() + writeRecordingIfAny() + releaseRecognizer() + releaseDecoder() + lock.withLock { + started = false + audioStarted = false + workerFinished = null + workerThreadName = null + } + emitStopped(captureId) + finished.countDown() + } + } + + private fun appendRecording(pcm: ShortArray, count: Int) { + val out = recordingPcm ?: return + out.write(AudioSegmentation.pcm16ToLittleEndian(pcm, 0, count)) + } + + private fun writeRecordingIfAny() { + val out = recordingPcm + recordingPcm = null + if (out == null || out.size() == 0) { + return + } + val sink = host.recordingSink() ?: return + try { + sink.save(out.toByteArray(), SAMPLE_RATE) + } catch (t: Throwable) { + logWarn("failed to save voice recording (${t.message})") + } + } + + private fun startG2Audio(): Boolean { + val source = host.g2AudioSource() ?: return false + resetAudioStats() + audioQueue.clear() + return source.start(object : FaceclawAudioPacketListener { + override fun onAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { + queueAudioPacket(data, arm, arrivalMs) + } + }) + } + + private fun processG2Audio() { + val pcm = ShortArray(PACKET_SAMPLES) + while (started) { + val currentDecoder = packetDecoder ?: return + val packet = takeAudioPacket() + if (packet == null) { + continue + } + val count = currentDecoder.decodePacket(packet.data, pcm) + if (count <= 0) { + maybeEmitAudioStats(false) + continue + } + decodedSamples += count.toLong() + // The beam filter drops packets whose firmware direction-of-arrival + // falls outside the listening wedge (isolating the aimed talker for + // every consumer, recognition included); the spectral noise + // suppressor then cleans what remains before it reaches the + // recognizer, cloud PCM, endpointing, or speaker verification. + val angleDegrees = currentDecoder.lastAngleDegrees + val ssr = currentDecoder.lastSsr + if (beamFilterEnabled && ssr > 0 && !withinBeam(angleDegrees)) { + emitFrameMeta(angleDegrees, ssr) + maybeEmitAudioStats(false) + continue + } + processPcmChunk(pcm, count, angleDegrees, ssr, true) + maybeEmitAudioStats(false) + } + } + + /** + * Per-chunk processing shared by the G2 and phone-mic paths, downstream of + * decode and the beam filter. hasFrameMeta is false for the phone mic, + * which has no firmware DSP metadata to report. + */ + internal fun processPcmChunk(pcm: ShortArray, count: Int, angleDegrees: Int, ssr: Int, hasFrameMeta: Boolean) { + if (suppressionEnabled) { + applySuppression(pcm, count) + } + if (recordingPcm != null) { + appendRecording(pcm, count) + } + val verifyBuffer = this.verifyBuffer + if (verifyBuffer != null && verifyCount < VERIFY_MAX_SAMPLES) { + val copied = min(count, VERIFY_MAX_SAMPLES - verifyCount) + pcm.copyInto(verifyBuffer, verifyCount, 0, copied) + verifyCount += copied + } + if (endpointing && endpointDetector.accept(pcm, count)) { + emitSpeechEnd() + } + // PCM and frame metadata flow in every mode so levels, recording, + // and the Microphones radar keep working alongside onboard ASR. + emitPcm(pcm, count) + if (hasFrameMeta) { + emitFrameMeta(angleDegrees, ssr) + } + if (mode != Mode.CLOUD) { + processRecognizer(AudioSegmentation.pcm16ToFloat(pcm, 0, count)) + } + } + + /** + * Phone-mic capture loop: no LC3 decode, no arm bookkeeping, no frame + * metadata. The blocking read returns every chunk (50 ms), which bounds how + * long a stop() waits for the loop to notice `started` dropped. + */ + private fun processPhoneAudio(record: PcmAudioSource) { + val pcm = ShortArray(SAMPLE_RATE / 20) + while (started) { + val read = record.read(pcm) + if (read < 0) { + logWarn("phone mic read failed: $read") + return + } + if (read == 0) { + continue + } + decodedSamples += read.toLong() + processPcmChunk(pcm, read, 0, 0, false) + } + } + + private fun processRecognizer(samples: FloatArray) { + appendTranscriptSamples(samples) + // Each Whisper call re-encodes the whole buffer plus ~10s of tail padding, + // so it skips the live-partial redecode Moonshine does on this interval and + // only decodes when a segment commits (8s buffer fill) or the utterance ends + // (decodeTranscript(true) in runLoop()). No live preview text in Whisper + // mode -- status stays "Listening..." until release. Deliberate tradeoff. + if (onboardModelKind == VoiceModelKind.WHISPER) { + return + } + val now = platform.elapsedRealtimeMs() + if (transcriptSampleCount >= TRANSCRIPT_MIN_SAMPLES && + now - lastTranscriptDecodeAtMs >= TRANSCRIPT_DECODE_INTERVAL_MS + ) { + decodeTranscript(false) + lastTranscriptDecodeAtMs = now + } + } + + private fun appendTranscriptSamples(samples: FloatArray) { + var sourceOffset = 0 + while (sourceOffset < samples.size) { + val available = TRANSCRIPT_SEGMENT_MAX_SAMPLES - transcriptSampleCount + val count = min(available, samples.size - sourceOffset) + samples.copyInto(transcriptSamples, transcriptSampleCount, sourceOffset, sourceOffset + count) + transcriptSampleCount += count + sourceOffset += count + if (transcriptSampleCount == TRANSCRIPT_SEGMENT_MAX_SAMPLES) { + commitTranscriptSegment() + } + } + } + + /** + * Decode the current model-safe segment and emit the best transcript of the + * complete utterance (REPLACE semantics — the caller displays it as-is). + */ + private fun decodeTranscript(isFinal: Boolean) { + if (recognizer == null || transcriptSampleCount <= 0) { + if (isFinal) { + emitTranscript(lastTranscript, true) + } + return + } + val segmentSampleCount = transcriptSampleCount + var segmentText = recognizeTranscriptSegment(segmentSampleCount) + if (segmentText.isNotEmpty()) { + currentSegmentTranscript = segmentText + } else { + segmentText = currentSegmentTranscript + } + val text = joinTranscript(committedTranscript, segmentText) + lastTranscript = text + logTranscriptDecode(isFinal, segmentSampleCount, text) + emitTranscript(text, isFinal) + } + + /** + * Finalize a full segment before accepting more audio. This keeps every + * Moonshine invocation below its failing sequence length while retaining + * all earlier text in the replace-semantics preview. + */ + private fun commitTranscriptSegment() { + val cut = AudioSegmentation.quietestCutPoint( + transcriptSamples, transcriptSampleCount, TRANSCRIPT_CUT_SEARCH_SAMPLES, TRANSCRIPT_CUT_WINDOW_SAMPLES, + ) + var segmentText = recognizeTranscriptSegment(cut) + if (segmentText.isEmpty()) { + // Fallback text came from partial decodes of the full buffer, so it + // may include words from the carried-over tail; rare now that decode + // windows are peak-normalized. + segmentText = currentSegmentTranscript + } + committedTranscript = joinTranscript(committedTranscript, segmentText) + currentSegmentTranscript = "" + committedTranscriptSampleCount += cut.toLong() + val tail = transcriptSampleCount - cut + transcriptSamples.copyInto(transcriptSamples, 0, cut, cut + tail) + transcriptSampleCount = tail + lastTranscript = committedTranscript + lastTranscriptDecodeAtMs = platform.elapsedRealtimeMs() + logTranscriptDecode(false, cut, committedTranscript) + emitTranscript(committedTranscript, false) + } + + private fun recognizeTranscriptSegment(sampleCount: Int): String { + val currentRecognizer = recognizer + if (currentRecognizer == null || sampleCount <= 0) { + return "" + } + val segment = transcriptSamples.copyOf(sampleCount) + // Whisper hallucinates text on near-silent input; gate it on the + // PRE-normalization peak, since normalizePeak() below would otherwise + // amplify true silence right up to the target level. Moonshine does not + // share this failure mode in practice, so it is left unchanged. + if (onboardModelKind == VoiceModelKind.WHISPER && + AudioSegmentation.peakAmplitude(segment) < WHISPER_SILENCE_PEAK_THRESHOLD + ) { + return "" + } + AudioSegmentation.normalizePeak(segment, TRANSCRIPT_NORMALIZE_TARGET_PEAK, TRANSCRIPT_NORMALIZE_MAX_GAIN) + return currentRecognizer.recognize(segment, segment.size).trim() + } + + private fun logTranscriptDecode(isFinal: Boolean, segmentSampleCount: Int, text: String) { + val totalAudioSec = (committedTranscriptSampleCount + transcriptSampleCount) / SAMPLE_RATE.toDouble() + val preview = if (text.length <= TRANSCRIPT_LOG_PREVIEW_CHARS) text + else text.substring(0, TRANSCRIPT_LOG_PREVIEW_CHARS) + "..." + logInfo( + (if (onboardModelKind == VoiceModelKind.WHISPER) "Whisper" else "Moonshine") + " decode final=" + isFinal + + " audioSec=" + formatFixed(totalAudioSec, 2) + + " segmentAudioSec=" + formatFixed(segmentSampleCount / SAMPLE_RATE.toDouble(), 2) + + " textLen=" + text.length + " text=\"" + preview + "\"", + ) + } + + private fun resetTranscriptState() { + transcriptSampleCount = 0 + committedTranscriptSampleCount = 0 + committedTranscript = "" + currentSegmentTranscript = "" + lastTranscriptDecodeAtMs = 0 + } + + private fun emitPcm(pcm: ShortArray, count: Int) { + val currentListener = listener + if (currentListener == null || count <= 0) { + return + } + val le = AudioSegmentation.pcm16ToLittleEndian(pcm, 0, count) + host.dispatcher.post { currentListener.onPcm(le) } + } + + /** + * Embed the session's buffered utterance and compare it to the enrolled + * wearer voice-print. Fails open: a session too short to verify, or a + * model that will not load, counts as the wearer rather than silencing + * every command. + */ + private fun runSpeakerVerification() { + val buffer = verifyBuffer + val wearer = verifyWearerEmbedding + val modelPath = verifySpeakerModelPath + verifyBuffer = null + if (buffer == null || wearer == null || modelPath == null) { + return + } + if (verifyCount < VERIFY_MIN_SAMPLES) { + emitSpeakerVerified(true, 0f) + return + } + try { + val embedder = host.speakerEmbedder(modelPath) + val le = AudioSegmentation.pcm16ToLittleEndian(buffer, 0, verifyCount) + val embedding = embedder.embed(le, SAMPLE_RATE) + if (embedding == null || embedding.size != wearer.size) { + emitSpeakerVerified(true, 0f) + return + } + val dot = VoicePrint.dot(embedding, wearer) + val isWearer = dot >= verifyThreshold + logInfo( + "speaker verification similarity=" + formatFixed(dot, 3) + + " threshold=" + verifyThreshold + " isWearer=" + isWearer, + ) + emitSpeakerVerified(isWearer, dot.toFloat()) + } catch (t: Throwable) { + logWarn("speaker verification failed (${t.message})") + emitSpeakerVerified(true, 0f) + } + } + + private fun emitSpeakerVerified(isWearer: Boolean, similarity: Float) { + val currentListener = listener ?: return + host.dispatcher.post { currentListener.onSpeakerVerified(isWearer, similarity) } + } + + private fun emitFrameMeta(angleDegrees: Int, ssr: Int) { + val currentListener = listener ?: return + host.dispatcher.post { currentListener.onFrameMeta(angleDegrees, ssr) } + } + + private fun emitSpeechEnd() { + val currentListener = listener ?: return + host.dispatcher.post { currentListener.onSpeechEnd() } + } + + private fun emitStopped(captureId: Int) { + val currentListener = listener ?: return + host.dispatcher.post { currentListener.onStopped(captureId) } + } + + private fun stopG2Audio() { + host.g2AudioSource()?.stop() + maybeEmitAudioStats(true) + } + + private fun releaseRecognizer() { + recognizer?.release() + recognizer = null + } + + private fun releaseDecoder() { + packetDecoder?.close() + packetDecoder = null + } + + /** Called from the BLE notification thread for every glasses mic packet. */ + fun queueAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { + if (!started || data == null) { + return + } + if ("L" != arm) { + wrongArmPackets++ + } + audioQueue.put(AudioPacket(data, arm, arrivalMs)) { + queuedPackets++ + if (lastPacketArrivalMs > 0) { + val delta = arrivalMs - lastPacketArrivalMs + if (delta > maxInterPacketMs) { + maxInterPacketMs = delta + } + if (delta > LATE_PACKET_INTERVAL_MS) { + latePackets++ + } + } + lastPacketArrivalMs = arrivalMs + } + } + + private fun takeAudioPacket(): AudioPacket? { + val packet = audioQueue.take(250) { started } + if (packet == null) { + maybeEmitAudioStats(false) + } + return packet + } + + private fun resetAudioStats() { + queuedPackets = 0 + decodedSamples = 0 + latePackets = 0 + wrongArmPackets = 0 + lastPacketArrivalMs = 0 + maxInterPacketMs = 0 + lastStatsAtMs = platform.elapsedRealtimeMs() + } + + /** Diagnostic packet accounting for tests and adapters. */ + class AudioStats( + val queuedPackets: Long, + val queueDroppedPackets: Long, + val latePackets: Long, + val wrongArmPackets: Long, + val maxInterPacketMs: Long, + val decodedSamples: Long, + ) + + fun audioStats(): AudioStats = AudioStats( + queuedPackets, audioQueue.droppedCount, latePackets, wrongArmPackets, maxInterPacketMs, decodedSamples, + ) + + private fun maybeEmitAudioStats(force: Boolean) { + val now = platform.elapsedRealtimeMs() + if (!force && now - lastStatsAtMs < STATS_INTERVAL_MS) { + return + } + lastStatsAtMs = now + val currentDecoder = packetDecoder + val real = currentDecoder?.realPackets ?: 0L + val duplicate = currentDecoder?.duplicatePackets ?: 0L + val missing = currentDecoder?.missingPackets ?: 0L + val decodeErrors = currentDecoder?.decodeErrors ?: 0L + val status = "G2 mic packets=" + queuedPackets + + " decoded=" + real + + " missing=" + missing + + " duplicate=" + duplicate + + " late=" + latePackets + + " maxGapMs=" + maxInterPacketMs + + " queueDrop=" + audioQueue.droppedCount + + " decodeErrors=" + decodeErrors + + " wrongArm=" + wrongArmPackets + + " audioSec=" + formatFixed(decodedSamples / SAMPLE_RATE.toDouble(), 1) + // Audio-pipeline stats are diagnostic; keep them in the log only, out of + // the on-glasses voice UI. + logInfo(status + " expectedIntervalMs=" + EXPECTED_PACKET_INTERVAL_MS) + } + + private fun emitStatus(status: String?) { + val currentListener = listener ?: return + host.dispatcher.post { currentListener.onStatus(status) } + } + + private fun emitTranscript(text: String?, isFinal: Boolean) { + val currentListener = listener ?: return + logInfo("Emit transcript final=" + isFinal + " textLen=" + (text?.trim()?.length ?: 0)) + host.dispatcher.post { currentListener.onTranscript(text, isFinal) } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePorts.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePorts.kt new file mode 100644 index 00000000..148c68a4 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePorts.kt @@ -0,0 +1,137 @@ +package com.faceclaw.app + +import kotlin.math.abs +import kotlin.math.round + +/** Which on-device model ONBOARD voice input loads. */ +enum class VoiceModelKind { + MOONSHINE, + WHISPER, +} + +/** + * Whole-utterance (offline) recognizer: each call decodes one complete buffer. The Android + * implementation wraps sherpa-onnx; a streaming recognizer (Apple Speech) could satisfy this + * by buffering and re-running, but the session's REPLACE-semantics partials assume re-decoding + * the same buffer is cheap enough on the MOONSHINE cadence. + */ +interface OfflineTranscriber { + /** Returns the trimmed text for [count] float samples at 16 kHz, or "" when nothing was recognized. */ + fun recognize(samples: FloatArray, count: Int): String + + fun release() +} + +/** Speaker voice-print extraction over 16 kHz mono S16LE PCM; null when unavailable or too short. */ +interface SpeakerEmbedder { + fun embed(pcm16le: ByteArray, sampleRate: Int): FloatArray? + + fun release() +} + +/** Marshals listener callbacks to the platform's UI/JS thread (Android: the main Handler). */ +fun interface CallbackDispatcher { + fun post(action: () -> Unit) +} + +/** Receives the session's decoded PCM once capture ends (Android saves a WAV file). */ +fun interface RecordingSink { + fun save(pcm16le: ByteArray, sampleRate: Int) +} + +/** A G2 microphone packet decoder (the shared [Lc3PacketFramer] over a platform LC3 codec). */ +interface AudioPacketDecoder { + fun decodePacket(packet: ByteArray?, pcmOut: ShortArray?): Int + + val lastAngleDegrees: Int + val lastSsr: Int + val realPackets: Long + val duplicatePackets: Long + val missingPackets: Long + val decodeErrors: Long + + fun close() +} + +/** Glasses microphone packets over BLE (Android: FaceclawBleCommunicator's capture API). */ +interface PacketAudioSource { + fun start(listener: FaceclawAudioPacketListener): Boolean + + fun stop() + + /** Whether the glasses are still delivering packets for this capture. */ + fun isActive(): Boolean +} + +/** The phone's own microphone delivering 16 kHz mono PCM16 in blocking reads. */ +interface PcmAudioSource { + /** Blocking read into [pcm]; returns samples read, 0 to retry, or a negative error. */ + fun read(pcm: ShortArray): Int + + fun close() +} + +/** Formats [value] with exactly [decimals] fraction digits (the shared stand-in for %.Nf). */ +fun formatFixed(value: Double, decimals: Int): String { + var scale = 1L + repeat(decimals) { scale *= 10 } + val scaled = round(abs(value) * scale).toLong() + val whole = scaled / scale + val fraction = scaled % scale + val sign = if (value < 0 && scaled != 0L) "-" else "" + return if (decimals == 0) "$sign$whole" else "$sign$whole." + fraction.toString().padStart(decimals, '0') +} + +/** + * Bounded FIFO between a producer thread and one consumer: when full the oldest item is + * dropped (counted). [take] waits up to [waitMs] and returns null on timeout or when [open] is + * false, so the consumer can poll a stop flag and emit periodic diagnostics. + */ +class DroppingPacketQueue(private val capacity: Int, platform: ProtocolPlatform = protocolPlatform()) { + private val condition = platform.createCondition() + private val items = ArrayDeque() + var droppedCount: Long = 0 + private set + + fun put(item: T) { + condition.withLock { + if (items.size >= capacity) { + items.removeFirst() + droppedCount++ + } + items.addLast(item) + condition.signalAll() + } + } + + /** Runs [action] while holding the queue lock, after enqueuing (used to update stats atomically). */ + fun put(item: T, action: () -> Unit) { + condition.withLock { + if (items.size >= capacity) { + items.removeFirst() + droppedCount++ + } + items.addLast(item) + action() + condition.signalAll() + } + } + + fun take(waitMs: Long, open: () -> Boolean): T? { + condition.withLock { + if (items.isEmpty() && open()) condition.awaitMs(waitMs) + return items.removeFirstOrNull() + } + } + + fun clear() { + condition.withLock { + items.clear() + droppedCount = 0 + } + } + + fun wake() { + condition.withLock { condition.signalAll() } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePrint.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePrint.kt new file mode 100644 index 00000000..b3a26c9d --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/VoicePrint.kt @@ -0,0 +1,104 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic +import kotlin.math.sqrt + +/** Voice-print (speaker embedding) vector math shared by extraction, verification and storage. */ +object VoicePrint { + /** L2-normalizes [v] in place and returns it; a null or zero vector is returned unchanged. */ + @JvmStatic + fun l2Normalize(v: FloatArray?): FloatArray? { + if (v == null) return null + var sum = 0.0 + for (x in v) sum += x.toDouble() * x + val norm = sqrt(sum) + if (norm <= 0) return v + for (i in v.indices) v[i] = (v[i] / norm).toFloat() + return v + } + + /** Dot product; on L2-normalized vectors this is the cosine similarity. */ + @JvmStatic + fun dot(a: FloatArray, b: FloatArray): Double { + require(a.size == b.size) { "embedding sizes differ: ${a.size} vs ${b.size}" } + var sum = 0.0 + for (i in a.indices) sum += a[i].toDouble() * b[i] + return sum + } + + /** Utterances shorter than this (~0.5 s of S16 mono at [sampleRate]) produce unreliable prints. */ + @JvmStatic + fun isLongEnoughToEmbed(pcm16leBytes: Int, sampleRate: Int): Boolean = pcm16leBytes >= sampleRate +} + +/** Persistence-side voice-print math: float32-LE blobs and centroid updates. */ +object SpeakerEmbeddings { + /** Decodes a float32-LE blob; null for a null, empty or misaligned blob. */ + @JvmStatic + fun blobToFloats(blob: ByteArray?): FloatArray? { + if (blob == null || blob.size < 4 || blob.size % 4 != 0) return null + val out = FloatArray(blob.size / 4) + for (i in out.indices) { + val base = i * 4 + val bits = (blob[base].toInt() and 0xff) or + ((blob[base + 1].toInt() and 0xff) shl 8) or + ((blob[base + 2].toInt() and 0xff) shl 16) or + ((blob[base + 3].toInt() and 0xff) shl 24) + out[i] = Float.fromBits(bits) + } + return out + } + + @JvmStatic + fun floatsToBlob(values: FloatArray): ByteArray { + val out = ByteArray(values.size * 4) + for (i in values.indices) { + val bits = values[i].toRawBits() + val base = i * 4 + out[base] = (bits and 0xff).toByte() + out[base + 1] = ((bits shr 8) and 0xff).toByte() + out[base + 2] = ((bits shr 16) and 0xff).toByte() + out[base + 3] = ((bits shr 24) and 0xff).toByte() + } + return out + } + + class Centroid(val embedding: FloatArray, val count: Int) + + /** + * Running-mean update of a speaker's centroid with one new print, with the existing + * weight capped at [maxCount] so a long session cannot drown the enrolled voice. A + * missing or differently sized current centroid is replaced by [update] (count 1). + */ + @JvmStatic + fun runningMean(current: FloatArray?, currentCount: Int, update: FloatArray, maxCount: Int): Centroid { + if (current == null || current.size != update.size) return Centroid(update, 1) + val effective = minOf(currentCount, maxOf(1, maxCount)) + val merged = FloatArray(current.size) + for (i in merged.indices) merged[i] = (current[i] * effective + update[i]) / (effective + 1) + VoicePrint.l2Normalize(merged) + return Centroid(merged, currentCount + 1) + } + + /** + * Blends two centroids weighted by their sample counts when both exist with the same + * size; otherwise keeps [into], falling back to [from] when [into] is missing. Null when + * neither exists. + */ + @JvmStatic + fun blend(from: FloatArray?, fromCount: Int, into: FloatArray?, intoCount: Int): FloatArray? { + if (from != null && into != null && from.size == into.size) { + val blended = FloatArray(into.size) + val total = maxOf(1, fromCount + intoCount) + for (i in blended.indices) blended[i] = (into[i] * intoCount + from[i] * fromCount) / total + VoicePrint.l2Normalize(blended) + return blended + } + return into ?: from + } + + /** When merging speakers, the target keeps its conversation insights; it adopts the source's only when it has none. */ + @JvmStatic + fun shouldAdoptInsights(targetHasInsights: Boolean, sourceHasInsights: Boolean): Boolean = + !targetHasInsights && sourceHasInsights +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/WavPcmReader.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/WavPcmReader.kt new file mode 100644 index 00000000..7fb7b2fd --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/audio/WavPcmReader.kt @@ -0,0 +1,66 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmField +import kotlin.jvm.JvmStatic + +/** RIFF/WAVE header walk shared by the AAC transcoder and the diarizer (16-bit PCM only). */ +object WavPcmReader { + /** Bytes of a WAV file the header walk needs at most; chunk payloads beyond it are skipped by offset. */ + const val HEADER_PREFIX_BYTES = 65536 + + class WavInfo( + @JvmField val sampleRate: Int, + @JvmField val channels: Int, + @JvmField val bitsPerSample: Int, + /** Byte offset of the first PCM sample. */ + @JvmField val dataOffset: Long, + /** PCM byte count; a zero-length data chunk (header never patched after a crash) is recovered from the file length. */ + @JvmField val dataBytes: Long, + ) + + /** + * Parses the fmt/data chunks from [prefix], the first bytes of a WAV file of [fileLength] + * bytes. Throws IllegalArgumentException for anything that is not 16-bit PCM WAV or whose + * data chunk header lies beyond the prefix. + */ + @JvmStatic + fun parseHeader(prefix: ByteArray, fileLength: Long): WavInfo { + require(prefix.size >= 12 && prefix[0] == 'R'.code.toByte() && prefix[1] == 'I'.code.toByte() && + prefix[2] == 'F'.code.toByte() && prefix[3] == 'F'.code.toByte() && + prefix[8] == 'W'.code.toByte() && prefix[9] == 'A'.code.toByte()) { "not a WAV file" } + var sampleRate = 0 + var channels = 0 + var bits = 0 + var offset = 12L + while (offset + 8 <= prefix.size) { + val at = offset.toInt() + val id = u32(prefix, at) + val size = u32(prefix, at + 4).toLong() and 0xffffffffL + offset += 8 + when (id) { + 0x20746d66 -> { // "fmt " + val available = minOf(size, 16L).toInt() + require(offset + available <= prefix.size) { "truncated fmt chunk" } + val f = offset.toInt() + val audioFormat = u16(prefix, f) + channels = u16(prefix, f + 2) + sampleRate = u32(prefix, f + 4) + bits = u16(prefix, f + 14) + require(audioFormat == 1 && bits == 16) { "only 16-bit PCM WAV is supported" } + offset += size + } + 0x61746164 -> { // "data" + require(sampleRate != 0) { "missing fmt or data chunk" } + val dataBytes = if (size > 0) size else fileLength - offset + return WavInfo(sampleRate, channels, bits, offset, maxOf(0L, dataBytes)) + } + else -> offset += size + } + } + throw IllegalArgumentException("missing fmt or data chunk") + } + + private fun u16(bytes: ByteArray, at: Int): Int = (bytes[at].toInt() and 0xff) or ((bytes[at + 1].toInt() and 0xff) shl 8) + + private fun u32(bytes: ByteArray, at: Int): Int = u16(bytes, at) or (u16(bytes, at + 2) shl 16) +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/evenhub/EvenHubAssetServer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/evenhub/EvenHubAssetServer.kt new file mode 100644 index 00000000..8125528e --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/evenhub/EvenHubAssetServer.kt @@ -0,0 +1,94 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic + +/** + * Offline asset resolution for an unpacked EvenHub app served from a fake per-app origin. + * Shared by the Android WebViewClient interceptor and the iOS WKURLSchemeHandler so both apply + * the same path rules, MIME table and bridge-shim injection. + */ +object EvenHubAssetServer { + /** A resolved request: [relativePath] is root-relative with no leading slash. */ + data class Asset(val relativePath: String, val mime: String) { + val isHtml: Boolean + get() = mime == "text/html" + } + + /** A loaded response body. */ + class Response(val mime: String, val bytes: ByteArray) + + /** + * Maps a decoded URL path to a root-relative file path, or null when it escapes the root. + * Empty and "/" paths serve index.html. Segments are normalised lexically ("." and ".."); + * platform adapters must still canonicalise the final file to defeat symlinks. + */ + @JvmStatic + fun resolve(urlPath: String?): Asset? { + val path = if (urlPath.isNullOrEmpty() || urlPath == "/") "/index.html" else urlPath + val segments = ArrayList() + for (segment in path.split('/')) { + when (segment) { + "", "." -> continue + ".." -> if (segments.isEmpty()) return null else segments.removeAt(segments.size - 1) + else -> segments.add(segment) + } + } + if (segments.isEmpty()) return null + val relative = segments.joinToString("/") + return Asset(relative, mimeTypeFor(segments.last())) + } + + /** True when [canonicalFile] lies inside [canonicalRoot] (both already canonicalised, no trailing slash). */ + @JvmStatic + fun isInsideRoot(canonicalRoot: String, canonicalFile: String): Boolean = + canonicalFile == canonicalRoot || canonicalFile.startsWith(canonicalRoot.trimEnd('/') + "/") + + /** + * Inserts the bridge shim right after `` when present, else before everything, so + * window.flutter_inappwebview exists before any app script runs. + */ + @JvmStatic + fun injectIntoHtml(html: String, injectScript: String): String { + val tag = "" + val headIndex = html.lowercase().indexOf("= 0) { + val close = html.indexOf('>', headIndex) + if (close >= 0) return html.substring(0, close + 1) + tag + html.substring(close + 1) + } + return tag + html + } + + /** Loads [asset] under [rootDir] with the shim spliced into HTML; null when the file is unreadable. */ + @JvmStatic + fun load(rootDir: String, asset: Asset, injectScript: String): Response? { + val path = rootDir.trimEnd('/') + "/" + asset.relativePath + if (!fileExists(path)) return null + val bytes = try { readFileData(path) } catch (e: Exception) { return null } + if (!asset.isHtml) return Response(asset.mime, bytes) + return Response(asset.mime, injectIntoHtml(bytes.decodeToString(), injectScript).encodeToByteArray()) + } + + /** Extension-based MIME lookup (the union of the Android and iOS tables). */ + @JvmStatic + fun mimeTypeFor(name: String): String { + val lower = name.lowercase() + val dot = lower.lastIndexOf('.') + val ext = if (dot >= 0) lower.substring(dot + 1) else "" + return MIME_TYPES[ext] ?: "application/octet-stream" + } + + private val MIME_TYPES = mapOf( + "html" to "text/html", "htm" to "text/html", + "js" to "text/javascript", "mjs" to "text/javascript", + "css" to "text/css", + "json" to "application/json", + "wasm" to "application/wasm", + "svg" to "image/svg+xml", + "png" to "image/png", "jpg" to "image/jpeg", "jpeg" to "image/jpeg", "gif" to "image/gif", + "webp" to "image/webp", "ico" to "image/x-icon", + "woff" to "font/woff", "woff2" to "font/woff2", "ttf" to "font/ttf", "otf" to "font/otf", + "txt" to "text/plain", "map" to "text/plain", + "xml" to "application/xml", "mp3" to "audio/mpeg", "wav" to "audio/wav", "ogg" to "audio/ogg", + "mp4" to "video/mp4", "webm" to "video/webm", + ) +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DeviceInfoProbeFlow.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DeviceInfoProbeFlow.kt new file mode 100644 index 00000000..906ce7e6 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DeviceInfoProbeFlow.kt @@ -0,0 +1,219 @@ +package com.faceclaw.app + +/** + * Connects to the glasses (stock-firmware compatible), reads the device-info / settings + * response, and reports the firmware versions plus the firmware-extension string (empty on + * stock firmware). Used by onboarding to decide whether to flash. Owns its own [StockLink] and + * runs [run] on the caller's worker thread; listener callbacks are synchronous on that thread + * (the platform adapter marshals them). Shows nothing on the lens. + */ +class DeviceInfoProbeFlow( + link: StockLink, + rightAddress: String, + leftAddress: String, + private val listener: FaceclawDeviceInfoProbeListener, + private val timings: StockFlowTimings = StockFlowTimings(), + platform: ProtocolPlatform = protocolPlatform(), +) { + companion object { + const val TAG = "FaceclawDeviceInfo" + + /** Connect + auth attempts per arm; a link that drops mid-pairing is retried once the bond settles. */ + const val ARM_ATTEMPTS = 3 + } + + private val rightAddress = rightAddress.trim() + private val leftAddress = leftAddress.trim() + private val sleeper = InterruptibleSleep(platform) + private val session = StockLinkSession(link, ::emitLog, timings, traceFrames = true, platform = platform) + + val cancelled: Boolean + get() = session.cancelled + + fun cancel() { + session.cancel() + sleeper.interrupt() + } + + fun run() { + try { + if (rightAddress.isEmpty()) { + emitError("No right-arm address configured.") + return + } + + val haveLeft = leftAddress.isNotEmpty() && !leftAddress.equals(rightAddress, ignoreCase = true) + + // Bring up and authenticate BOTH arms before asking for versions. Each arm is its + // own peripheral with its own bond, so on a fresh phone each raises its own pairing + // prompt; completing both here means the flash step (and the app proper) find both + // bonds in place. Strictly one arm at a time: Android pairs with one device at a + // time, and a second arm connected while the first was still pairing has been seen + // to drop within a second and never pair (2026-09-11 logcat). + var rightAuthenticated = bringUpArm(rightAddress, "right") + var leftAuthenticated = false + if (haveLeft && !cancelled) { + leftAuthenticated = bringUpArm(leftAddress, "left") + } + if (cancelled) { + emitError("Cancelled.") + return + } + if (!session.isConnected(rightAddress)) { + // The right lens may have dropped while the left one paired; it is bonded by + // now, so this comes back quickly. + emitLog("right lens disconnected while the left lens was set up; reconnecting") + rightAuthenticated = bringUpArm(rightAddress, "right") + if (cancelled) { + emitError("Cancelled.") + return + } + } + + var ack: ByteArray? = null + var rightFailure: String? = null + try { + ack = queryArm(rightAddress, "right", rightAuthenticated) + } catch (e: IllegalStateException) { + rightFailure = StockLinkSession.messageOf(e) + emitLog("right-lens query failed: $rightFailure") + } + // The right lens is the documented control endpoint, but a silent right lens has + // been observed on stock 2.2.9 even after a successful security auth — run the same + // probe against the left lens rather than giving up, and log which lens answered. + if (ack == null && !cancelled && haveLeft) { + emitLog("right lens did not answer the settings query; probing the left lens") + try { + ack = queryArm(leftAddress, "left", leftAuthenticated) + } catch (e: Exception) { + emitLog("left-lens probe failed: " + StockLinkSession.messageOf(e)) + } + } + if (cancelled) { + emitError("Cancelled.") + return + } + if (ack == null) { + throw IllegalStateException( + rightFailure + ?: ("no response to the device-info query on either lens — check `adb logcat -s " + TAG + "` for the frame trace") + ) + } + + val info = BleProtocol.parseSettingsFirmwareInfo(ack) + val left = info?.leftVersion ?: "" + val right = info?.rightVersion ?: "" + val extension = info?.extension ?: "" + emitLog("device-info: L=$left R=$right ext=[$extension]") + listener.onResult(left, right, extension) + } catch (e: Exception) { + emitError(if (cancelled) "Cancelled." else StockLinkSession.messageOf(e)) + } finally { + session.closeQuietly() + } + } + + /** + * Connect to one arm and complete its security-auth exchange, retrying when the link drops + * mid-pairing. Returns whether the auth success was seen (false = connected but + * unconfirmed, tolerated because the custom firmware's response to the exchange is not yet + * hardware-verified); throws when the arm cannot be brought up at all. + */ + private fun bringUpArm(address: String, label: String): Boolean { + var lastFailure: String? = null + var attempt = 1 + while (attempt <= ARM_ATTEMPTS && !cancelled) { + if (attempt > 1) { + // A link the OS dropped while it was still pairing comes back once the bond + // settles; reconnecting sooner just fails again. + session.waitForBondToSettle(address, label, sleeper) + if (cancelled) { + break + } + emitLog("retrying the $label lens (attempt $attempt/$ARM_ATTEMPTS): $lastFailure") + sleeper.sleep(timings.armRetryDelayMs.toLong()) + } + listener.onState("connecting", label) + try { + session.bringUp(address) + } catch (e: IllegalStateException) { + lastFailure = StockLinkSession.messageOf(e) + emitLog("$label lens: $lastFailure") + attempt++ + continue + } + if (cancelled) { + break + } + + // Firmware 2.2.9 answers no queries until the security-auth exchange completes over + // an encrypted link; on a phone with no existing bond this is also what triggers SMP + // pairing (and its OS prompt), so it must come before the prelude and query. + listener.onState("authenticating", label) + when (session.authenticate(address, label)) { + StockLinkSession.AuthResult.SUCCESS -> return true + StockLinkSession.AuthResult.UNCONFIRMED -> return false + StockLinkSession.AuthResult.LINK_DROPPED -> { + lastFailure = "link dropped during authentication" + attempt++ + } + } + } + if (cancelled) { + return false + } + throw IllegalStateException( + "could not connect to the $label lens ($address): " + lastFailure + + " — if the phone showed a Bluetooth pairing request, accept it and try again" + ) + } + + /** + * Prelude + settings read on an already connected/authenticated lens. Returns the settings + * ack protobuf, an unsolicited settings push that carried firmware versions, or null when + * the lens never answered the read. Throws on prelude failure; the caller wraps the fallback + * lens's attempt so its failure cannot mask the primary lens's outcome. + */ + private fun queryArm(address: String, label: String, authenticated: Boolean): ByteArray? { + if (cancelled) { + return null + } + listener.onState("querying", label) + // Session prelude, then a settings/device-info read (both arms' versions and the + // firmware-extension string ride back in one response). + session.sendPrelude( + address, + " ($label lens)" + + (if (authenticated) "" else "; authentication did not complete — if the phone shows a Bluetooth pairing request, accept it and try again"), + ) + + // Two attempts: the first read straight after a fresh pairing has been seen to go + // unanswered while a later one succeeds. + var attempt = 0 + while (attempt < 2 && !cancelled) { + val ack = session.readSettings(address, timings.queryTimeoutMs) + if (ack != null) { + return ack + } + // A push with the firmware versions on the device's own magic is as good as the + // ack we asked for. + val pushed = session.unsolicitedSettingsPb + if (pushed != null) { + emitLog("using unsolicited settings push instead of the read ack ($label lens)") + return pushed + } + emitLog("settings query attempt " + (attempt + 1) + " unanswered (" + label + " lens)") + attempt++ + } + return null + } + + // Log lines reach the platform log through the adapter's onLog (Android: logcat under TAG). + private fun emitLog(line: String) { + listener.onLog(line) + } + + private fun emitError(message: String) { + listener.onError(message) + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt new file mode 100644 index 00000000..a1c62bce --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt @@ -0,0 +1,167 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmField +import kotlin.jvm.JvmStatic + +/** + * Stock EVENOTA container layout, validation and CRC-32C, shared by the Android flasher and + * (via stage 3) the iOS port of app/g2/firmware-ota.ts. Mirrors g2flash.py: a 0x40-byte + * header (component count at +8), a 16-byte table-of-contents entry per component + * (offset at +4, CRC at +12), and per component a 128-byte subheader (payload size at +8, + * CRC at +12, NUL-terminated name at +48) followed by the payload. + * + * Validation takes the stricter of the two former implementations: the Android checks + * (component count, CRC in both TOC and subheader, main-app preamble/MRAM ceiling) plus the + * TypeScript ones (TOC/subheader/payload bounds, no overlapping components). + */ +object FirmwareImage { + const val HEADER_SIZE = 0x40 + const val TOC_ENTRY_SIZE = 16 + const val SUBHEADER_SIZE = 128 + const val NAME_OFFSET = 48 + const val NAME_MAX = 80 + + // Firmware 2.2.4 has 5 components; 2.2.6 has 6. + const val MIN_SEGMENTS = 5 + const val MAX_SEGMENTS = 6 + const val REQUIRED_SEGMENT = "ota/s200_firmware_ota.bin" + const val APP_LOAD_ADDR = 0x00438000L + const val APP_MAX_END = 0x007F0000L + const val APP_PREAMBLE = 0x20 + + class Segment( + /** Offset of the 128-byte subheader within the image. */ + @JvmField val off: Int, + /** Payload size in bytes (payload starts at off + SUBHEADER_SIZE). */ + @JvmField val ps: Int, + /** CRC-32C recorded in the table of contents. */ + @JvmField val crc: Long, + @JvmField val name: String, + ) { + val payloadStart: Int get() = off + SUBHEADER_SIZE + val end: Int get() = payloadStart + ps + } + + private val CRC32C_TABLE: IntArray = IntArray(256).also { table -> + for (b in 0 until 256) { + var c = b shl 24 + for (i in 0 until 8) { + c = if ((c and 0x80000000.toInt()) != 0) (c shl 1) xor 0x1edc6f41 else c shl 1 + } + table[b] = c + } + } + + /** CRC-32C, MSB-first, init 0, no final xor (matches g2flash.py crc32c_msb). */ + @JvmStatic + fun crc32cMsb(data: ByteArray, offset: Int = 0, length: Int = data.size - offset): Int { + require(offset >= 0 && length >= 0 && offset + length <= data.size) + var crc = 0 + for (i in offset until offset + length) { + crc = (crc shl 8) xor CRC32C_TABLE[((crc ushr 24) xor (data[i].toInt() and 0xff)) and 0xff] + } + return crc + } + + /** Unsigned CRC-32C as a Long, for comparison with recorded values. */ + @JvmStatic + fun crc32cUnsigned(data: ByteArray, offset: Int = 0, length: Int = data.size - offset): Long = + crc32cMsb(data, offset, length).toLong() and 0xffffffffL + + @JvmStatic + fun readU32(buf: ByteArray, offset: Int): Long { + if (offset < 0 || offset + 4 > buf.size) throw IllegalStateException("firmware header is truncated") + return (buf[offset].toLong() and 0xffL) or + ((buf[offset + 1].toLong() and 0xffL) shl 8) or + ((buf[offset + 2].toLong() and 0xffL) shl 16) or + ((buf[offset + 3].toLong() and 0xffL) shl 24) + } + + @JvmStatic + fun readCString(buf: ByteArray, offset: Int, maxLen: Int): String { + var end = offset + val limit = minOf(buf.size, offset + maxLen) + while (end < limit && buf[end].toInt() != 0) end++ + return buildString(end - offset) { for (i in offset until end) append((buf[i].toInt() and 0xff).toChar()) } + } + + /** Parses the table of contents without checking CRCs; throws on bounds violations. */ + @JvmStatic + fun parseSegments(img: ByteArray): List { + if (img.size < HEADER_SIZE) throw IllegalStateException("file is too small to be a firmware image") + val n = readU32(img, 8) + if (n <= 0 || n > 64) throw IllegalStateException("implausible component count $n (corrupt image?)") + val count = n.toInt() + val tocEnd = HEADER_SIZE + count * TOC_ENTRY_SIZE + if (tocEnd > img.size) throw IllegalStateException("table of contents runs past end of file") + val segs = ArrayList(count) + for (i in 0 until count) { + val base = HEADER_SIZE + i * TOC_ENTRY_SIZE + val crc = readU32(img, base + 12) + val offLong = readU32(img, base + 4) + if (offLong < tocEnd || offLong + SUBHEADER_SIZE > img.size) { + throw IllegalStateException("segment $i subheader is out of bounds") + } + val off = offLong.toInt() + val psLong = readU32(img, off + 8) + if (psLong <= 0 || off + SUBHEADER_SIZE + psLong > img.size) { + throw IllegalStateException("segment $i payload is truncated") + } + val name = readCString(img, off + NAME_OFFSET, NAME_MAX) + val seg = Segment(off, psLong.toInt(), crc, name) + for (other in segs) { + if (seg.off < other.end && other.off < seg.end) { + throw IllegalStateException("components ${other.name} and ${seg.name} overlap") + } + } + segs.add(seg) + } + return segs + } + + /** Full validation: layout, component count, CRCs, and the main-app preamble/MRAM check. */ + @JvmStatic + fun validate(img: ByteArray): List { + val segs = parseSegments(img) + if (segs.size < MIN_SEGMENTS || segs.size > MAX_SEGMENTS) { + throw IllegalStateException("expected $MIN_SEGMENTS-$MAX_SEGMENTS components, found ${segs.size}") + } + var main: Segment? = null + for (s in segs) { + val calc = crc32cUnsigned(img, s.payloadStart, s.ps) + val subCrc = readU32(img, s.off + 12) + if (calc != s.crc || calc != subCrc) { + throw IllegalStateException("component ${s.name} CRC32C is stale (image not checksum-fixed)") + } + if (REQUIRED_SEGMENT == s.name) { + if (main != null) throw IllegalStateException("required component $REQUIRED_SEGMENT is duplicated") + main = s + } + } + if (main == null) throw IllegalStateException("required component $REQUIRED_SEGMENT not found") + checkMainAppFitsMram(img, main) + return segs + } + + @JvmStatic + fun checkMainAppFitsMram(img: ByteArray, main: Segment) { + if (main.ps < APP_PREAMBLE) throw IllegalStateException("main-app payload is smaller than its preamble") + val loadAddr = readU32(img, main.payloadStart + 0x14) + val preLen = readU32(img, main.payloadStart) and 0xFFFFFFL + if (loadAddr != APP_LOAD_ADDR) { + throw IllegalStateException( + "main-app preamble load address is 0x" + loadAddr.toString(16) + + ", expected 0x" + APP_LOAD_ADDR.toString(16)) + } + if (preLen != main.ps.toLong()) { + throw IllegalStateException("main-app preamble length ($preLen) != staged payload size (${main.ps})") + } + val progEnd = APP_LOAD_ADDR + main.ps - APP_PREAMBLE + if (progEnd > APP_MAX_END) { + val over = progEnd - APP_MAX_END + throw IllegalStateException( + "main-app is too large: programmed region ends at 0x" + progEnd.toString(16) + + ", " + over + " bytes past the safe MRAM ceiling — refusing to flash (brick risk)") + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FlashPromptFlow.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FlashPromptFlow.kt new file mode 100644 index 00000000..d1b5a3f8 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FlashPromptFlow.kt @@ -0,0 +1,353 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile + +/** + * A minimal, stock-firmware-compatible flow used only to show the pre-flash confirmation + * prompt on the glasses and read back the user's Yes/No choice. It speaks only the stock subset + * — session prelude, a text container, a list container, and heartbeats. No images. + * + * Both arms are connected and security-authenticated up front, even though the prompt itself + * only needs the right arm (the lenses relay messages to each other, and acks/events only ever + * come from the right arm): on an unbonded phone the auth exchange is what raises the OS + * pairing prompt, and doing both here means both prompts appear at the start rather than one + * popping up half way through flashing the second lens. While connected, each arm's battery + * level is read (they are independent batteries) so the caller can refuse to flash on a low + * charge. + * + * With `skipPrompt` the on-glasses confirmation is not shown: the flow is just connect + auth + + * battery read + result(approved). Used to re-check the battery after the user has already + * confirmed once. [run] executes on the caller's worker thread; the heartbeat runs on its own + * thread while the prompt is up. + */ +class FlashPromptFlow( + link: StockLink, + rightAddress: String, + leftAddress: String, + warningText: String, + private val skipPrompt: Boolean, + private val listener: FaceclawFlashPromptListener, + private val timings: StockFlowTimings = StockFlowTimings(), + platform: ProtocolPlatform = protocolPlatform(), +) { + companion object { + const val TAG = "FaceclawFlashPrompt" + const val TEXT_NAME = "flashwarn" + const val LIST_NAME = "flashmenu" + const val TEXT_CONTAINER_ID = 1 + const val LIST_CONTAINER_ID = 2 + // Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid. + val ITEMS = arrayOf("No, cancel", "Yes, flash") + } + + private val rightAddress = rightAddress.trim() + private val leftAddress = leftAddress.trim() + private val warningText = warningText + private val platform = platform + private val lock = platform.createLock() + private val sleeper = InterruptibleSleep(platform) + private val selectionLatch = Latch(1, platform) + private val session = StockLinkSession(link, ::emitLog, timings, platform = platform) + + @Volatile + private var finished = false + + @Volatile + private var rightConnected = false + + @Volatile + private var leftConnected = false + + @Volatile + private var rightLost = false + + @Volatile + private var approved: Boolean? = null + + /** The running heartbeat's sleeper; interrupting it ends that thread. */ + @Volatile + private var heartbeat: InterruptibleSleep? = null + + val cancelled: Boolean + get() = session.cancelled + + init { + session.onEvent = { _, frame -> handleEvent(frame) } + session.onDisconnected = ::handleDisconnected + } + + /** Abort the prompt (e.g. the user backed out on the phone). */ + fun cancel() { + session.cancel() + selectionLatch.countDown() + sleeper.interrupt() + stopHeartbeat() + } + + fun run() { + try { + if (rightAddress.isEmpty()) { + listener.onState("error", "No right-arm address configured.") + return + } + + listener.onState("connecting", "") + connectArm(rightAddress, "right") + rightConnected = true + if (cancelled) { + teardown() + return + } + if (leftAddress.isNotEmpty()) { + connectArm(leftAddress, "left") + leftConnected = true + if (cancelled) { + teardown() + return + } + } + + listener.onState("connected", "") + // Auth both arms now (pairing prompts, if any, happen here) before anything else, + // so both bonds exist by the time flashing starts. + authenticateArm(rightAddress, "right") + if (leftConnected) { + authenticateArm(leftAddress, "left") + } + if (cancelled) { + teardown() + return + } + session.sendPrelude(rightAddress, ": $rightAddress") + + if (!skipPrompt) { + showPrompt(rightAddress) + startHeartbeat() + listener.onState("prompting", "") + + selectionLatch.await(timings.selectionTimeoutMs.toLong()) + stopHeartbeat() + + if (cancelled) { + listener.onState("cancelled", "") + teardown() + return + } + if (approved == null) { + if (rightLost) { + listener.onState("disconnected", "Lost connection to the glasses.") + } else { + listener.onState("timeout", "No response from the glasses.") + } + teardown() + return + } + try { + sendShutdown() + } catch (ignored: Exception) { + } + if (approved != true) { + listener.onResult(false) + listener.onState("result", "declined") + teardown() + return + } + } + + // Approved (or prompt skipped): read each arm's battery while the links are still + // up, then report the result. + listener.onState("battery", "") + readBatteries() + if (cancelled) { + listener.onState("cancelled", "") + teardown() + return + } + if (rightLost) { + listener.onState("disconnected", "Lost connection to the glasses.") + teardown() + return + } + finished = true + listener.onResult(true) + listener.onState("result", "approved") + teardown() + } catch (e: Exception) { + stopHeartbeat() + if (!cancelled) { + listener.onState("error", StockLinkSession.messageOf(e)) + } + teardown() + } + } + + private fun connectArm(address: String, arm: String) { + try { + session.bringUp(address) + } catch (e: IllegalStateException) { + throw IllegalStateException(StockLinkSession.messageOf(e) + ": $arm arm ($address)") + } + emitLog("connected $arm arm") + } + + /** + * Security-auth exchange on sid=0x80: firmware 2.2.9 will not run a session (and closes + * the link after ~30 s) without it, and on an unbonded phone this is what triggers SMP + * pairing, so it may sit waiting on an OS pairing prompt. + */ + private fun authenticateArm(address: String, arm: String) { + if (session.authenticate(address, arm) != StockLinkSession.AuthResult.SUCCESS) { + throw IllegalStateException( + "could not authenticate with the $arm arm ($address" + + ") — if the phone shows a Bluetooth pairing request, accept it and try again" + ) + } + emitLog("security auth complete: $arm arm") + } + + private fun showPrompt(address: String) { + // Create the prompt page (warning text + No/Yes list) on sid=0xe0 Cmd=0. Two attempts: + // on 2.2.9 the first request sent right after the prelude can be dropped while the lens + // emits its own sid-0x80 notifications (observed with the device-info settings read). + var pageAck: ByteArray? = null + var attempt = 0 + while (attempt < 2 && pageAck == null && !cancelled) { + val magic = session.allocMagic() + val page = BleProtocol.buildCreatePromptPage(magic, TEXT_NAME, TEXT_CONTAINER_ID, warningText, LIST_NAME, LIST_CONTAINER_ID, ITEMS) + pageAck = session.writeAndAwaitAck(address, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, magic, page, timings.createAckTimeoutMs) + if (pageAck == null) { + emitLog("prompt page attempt " + (attempt + 1) + " unacked: " + address) + } + attempt++ + } + if (pageAck == null) { + throw IllegalStateException("prompt page not acked: $address") + } + emitLog("prompt page shown on $address") + } + + /** + * Read each arm's battery via a sid-0x09 settings read on that arm's own link (the arms + * have independent batteries and each answers with its own). An arm that does not answer + * reports -1; the caller decides what to do with a partial reading. + */ + private fun readBatteries() { + val right = if (rightConnected) readBattery(rightAddress, "right") else -1 + val left = if (leftConnected) readBattery(leftAddress, "left") else -1 + emitLog("battery R=" + (if (right < 0) "?" else "$right%") + " L=" + (if (left < 0) "?" else "$left%")) + listener.onBattery(right, left) + } + + private fun readBattery(address: String, arm: String): Int { + var attempt = 0 + while (attempt < 2 && !cancelled) { + val ack = session.readSettings(address, timings.batteryAckTimeoutMs) + if (ack == null) { + emitLog("battery read attempt " + (attempt + 1) + " unacked: " + arm + " arm") + attempt++ + continue + } + val snapshot = BleProtocol.parseSettingsBattery(ack) + if (snapshot != null) { + return snapshot.battery + } + emitLog("battery read ack had no battery field: $arm arm") + attempt++ + } + return -1 + } + + private fun startHeartbeat() { + stopHeartbeat() + val ticker = InterruptibleSleep(platform) + heartbeat = ticker + startThread("faceclaw-flash-hb", true) { + while (heartbeat === ticker && ticker.sleep(timings.heartbeatIntervalMs.toLong())) { + if (heartbeat !== ticker) break + sendHeartbeat() + } + } + } + + private fun sendHeartbeat() { + if (finished || cancelled) { + return + } + try { + val heartbeat = BleProtocol.buildHeartbeat(session.allocMagic()) + if (rightConnected) { + session.writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat) + } + } catch (e: Exception) { + emitLog("heartbeat failed: " + e.message) + } + } + + private fun stopHeartbeat() { + val ticker = heartbeat ?: return + heartbeat = null + ticker.interrupt() + } + + private fun sendShutdown() { + val shutdown = BleProtocol.buildShutdown(session.allocMagic(), 0) + if (rightConnected) { + session.writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown) + } + } + + private fun teardown() { + finished = true + stopHeartbeat() + session.closeQuietly() + rightConnected = false + leftConnected = false + } + + private fun handleEvent(frame: BleProtocol.ParsedFrame) { + val selection = BleProtocol.parseListSelection(frame) ?: return + if (LIST_NAME != selection.containerName) { + return + } + // Only a confirmed click is a decision; scroll/highlight changes are ignored. + if (selection.eventType != BleProtocol.EVENT_CLICK) { + return + } + val itemName = selection.itemName + val yes = selection.itemIndex == 1 || (itemName != null && itemName.lowercase().startsWith("yes")) + lock.withLock { + if (finished) { + return + } + finished = true + approved = yes + } + emitLog("selection: " + (if (yes) "flash" else "cancel") + " (index " + selection.itemIndex + ")") + selectionLatch.countDown() + } + + private fun handleDisconnected(address: String) { + if (address.equals(leftAddress, ignoreCase = true)) { + // The prompt itself only needs the right arm; a dropped left link just means no + // left battery reading. + leftConnected = false + emitLog("left arm disconnected") + return + } + if (address.equals(rightAddress, ignoreCase = true)) { + rightConnected = false + lock.withLock { + if (!finished && !cancelled) { + rightLost = true + finished = true + selectionLatch.countDown() + } + } + } + } + + // Log lines reach the platform log through the adapter's onLog (Android: logcat under TAG). + private fun emitLog(line: String) { + listener.onLog(line) + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/OtaFlashFlow.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/OtaFlashFlow.kt new file mode 100644 index 00000000..e2f5ee58 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/OtaFlashFlow.kt @@ -0,0 +1,312 @@ +package com.faceclaw.app + +/** + * Ports g2flash.py's OTA flash procedure. Streams the EVENOTA firmware container to each lens + * over the firmware-data service using the aa21 envelope (BleProtocol.framePb) and the c0/c1 + * control/data protocol. + * + * Each lens connection completes the sid-0x80 security-auth exchange before OTA BEGIN — + * firmware 2.2.9 closes unauthenticated links ~30 s in, killing the transfer mid-component. No + * control-channel traffic is injected during the transfer itself: official OTA captures show + * none between BEGIN and the final END, heartbeats demonstrably do not satisfy the 2.2.9 + * deadline, and a concurrent control writer would interleave with the marker/data + * transactions. (See notes/ble-connections-2.2.9.md.) + * + * Lenses are flashed one at a time (left, then right). Finishing either lens reboots BOTH + * lenses, so the second lens is briefly unreachable — the reconnect for it uses a generous + * window rather than failing fast. [run] executes on the caller's worker thread. + */ +class OtaFlashFlow( + link: StockLink, + rightAddress: String, + leftAddress: String, + private val firmwarePath: String, + private val listener: FaceclawFirmwareFlasherListener, + private val timings: StockFlowTimings = StockFlowTimings(), + platform: ProtocolPlatform = protocolPlatform(), + /** Test seam: the firmware container bytes; defaults to reading [firmwarePath]. */ + private val readImage: (String) -> ByteArray = ::readFirmwareFile, +) { + companion object { + const val TAG = "FaceclawFlasher" + + // OTA message types (envelope sid byte) and control opcodes. + const val SID_CTRL = 0xc0 + const val SID_DATA = 0xc1 + const val FLAG_OTA = 0x00 + const val OP_BEGIN = 0x00 + const val OP_FILE_CHECK = 0x01 + const val OP_BLOCK = 0x02 + const val OP_END = 0x03 + + const val BLOCK_SIZE = 4096 + const val BLOCK_NAK_RETRIES = 3 + const val COMPONENT_RETRIES = 3 + + // END ack statuses that mean "component accepted": SUCCESS, UPDATING, SYS_RESTART. + private val END_OK = intArrayOf(0, 8, 9) + private val EMPTY = ByteArray(0) + + fun isEndOk(status: Int): Boolean = END_OK.contains(status) + + private fun readFirmwareFile(path: String): ByteArray = + try { + readFileData(path) + } catch (e: Exception) { + throw IllegalStateException("could not read firmware: " + e.message, e) + } + } + + private val rightAddress = rightAddress.trim() + private val leftAddress = leftAddress.trim() + private val sleeper = InterruptibleSleep(platform) + // The auth exchange uses its own magic range (0x60..0x7f) and the OTA envelope counter + // starts at 1, mirroring the stock sequence. + private val session = StockLinkSession(link, ::emitLog, timings, magicStart = 0x60, magicEnd = 0x7f, seqStart = 1, platform = platform) + + val cancelled: Boolean + get() = session.cancelled + + fun cancel() { + session.cancel() + sleeper.interrupt() + } + + fun run() { + try { + if (leftAddress.isEmpty() || rightAddress.isEmpty()) { + throw IllegalStateException("Both lens addresses are required to flash.") + } + + listener.onState("validating", "") + val img = readImage(firmwarePath) + val segs = FirmwareImage.validate(img) + emitLog("firmware validated: " + segs.size + " components, " + img.size + " bytes") + + flashLens("left", leftAddress, img, segs, timings.firstLensConnectWindowMs) + if (cancelled) { + listener.onState("error", "Cancelled.") + listener.onComplete(false, "Cancelled after the left lens.") + return + } + + listener.onState("rebooting", "Left lens done. Both lenses reboot briefly; reconnecting for the right lens.") + sleeper.sleep(timings.rebootSettleMs.toLong()) + flashLens("right", rightAddress, img, segs, timings.secondLensConnectWindowMs) + + listener.onState("done", "") + listener.onComplete(true, "Both lenses flashed. The glasses are rebooting into the custom firmware.") + } catch (e: Exception) { + val message = if (cancelled) "Cancelled." else StockLinkSession.messageOf(e) + listener.onState("error", message) + listener.onComplete(false, message) + } finally { + session.closeQuietly() + } + } + + private fun flashLens(lens: String, address: String, img: ByteArray, segs: List, connectWindowMs: Int) { + listener.onState("connecting", lens) + connectLensResilient(lens, address, connectWindowMs) + sleeper.sleep(timings.notifySettleMs.toLong()) + session.otaAcks.clear() + // Fresh envelope counter for the OTA stream (the auth exchange during bring-up used its + // own); mirrors the stock sequence. + session.resetSeq(1) + + listener.onState("flashing", lens) + val beginStatus = sendCtrlAndWait(address, OP_BEGIN, EMPTY, timings.ctrlAckTimeoutMs) + if (!isEndOk(beginStatus)) { + emitLog("warning: unexpected begin status $beginStatus; continuing") + } + // Progress is reported in bytes across the whole image: the segments are one large + // firmware blob plus several small ones, so a bar stepped per segment would sit still + // through the big one and then sprint through the rest. + var totalBytes = 0L + for (seg in segs) { + totalBytes += seg.ps + } + var bytesBefore = 0L + for (i in segs.indices) { + if (cancelled) { + throw IllegalStateException("Cancelled.") + } + flashComponentWithRetry(lens, address, i, segs.size, segs[i], img, bytesBefore, totalBytes) + bytesBefore += segs[i].ps + } + emitLog("$lens lens: all components verified") + session.disconnectQuietly(address) + } + + private fun flashComponentWithRetry( + lens: String, + address: String, + index: Int, + count: Int, + seg: FirmwareImage.Segment, + img: ByteArray, + bytesBefore: Long, + totalBytes: Long, + ) { + for (attempt in 0 until COMPONENT_RETRIES) { + if (attempt > 0) { + emitLog(seg.name + ": re-flash attempt " + (attempt + 1) + "/" + COMPONENT_RETRIES) + } + var endStatus: Int + try { + endStatus = flashComponent(lens, address, index, count, seg, img, bytesBefore, totalBytes) + } catch (e: StockTimeoutException) { + emitLog(seg.name + ": block phase failed: " + e.message) + endStatus = -1 + } catch (e: RuntimeException) { + emitLog(seg.name + ": block phase failed: " + e.message) + endStatus = -1 + } + if (isEndOk(endStatus)) { + emitLog(seg.name + ": END verify OK (status " + endStatus + ")") + return + } + if (endStatus >= 0) { + emitLog(seg.name + ": END verify FAILED (status " + endStatus + ")") + } + session.otaAcks.clear() + sleeper.sleep(timings.componentRetryDelayMs.toLong()) + } + throw IllegalStateException("component " + seg.name + " failed after " + COMPONENT_RETRIES + " attempts") + } + + private fun flashComponent( + lens: String, + address: String, + index: Int, + count: Int, + seg: FirmwareImage.Segment, + img: ByteArray, + bytesBefore: Long, + totalBytes: Long, + ): Int { + val sub = img.copyOfRange(seg.off, seg.off + FirmwareImage.SUBHEADER_SIZE) + val ps = seg.ps + val payloadStart = seg.off + FirmwareImage.SUBHEADER_SIZE + + val checkStatus = sendCtrlAndWait(address, OP_FILE_CHECK, sub, timings.ctrlAckTimeoutMs) + if (checkStatus != 0) { + throw IllegalStateException("FILE_CHECK rejected status=$checkStatus") + } + + val blockCount = (ps + BLOCK_SIZE - 1) / BLOCK_SIZE + for (b in 0 until blockCount) { + if (cancelled) { + throw IllegalStateException("Cancelled.") + } + val start = payloadStart + b * BLOCK_SIZE + val end = minOf(start + BLOCK_SIZE, payloadStart + ps) + val block = img.copyOfRange(start, end) + + var accepted = false + for (tries in 0 until BLOCK_NAK_RETRIES) { + val status = sendBlock(address, block) // throws StockTimeoutException -> component re-flash + if (status == 0) { + accepted = true + break + } + emitLog(seg.name + ": block " + b + "/" + blockCount + " NAK=" + status + " resend " + (tries + 1) + "/" + BLOCK_NAK_RETRIES) + } + if (!accepted) { + throw IllegalStateException("block " + b + " NAK'd " + BLOCK_NAK_RETRIES + " times") + } + if (b % 20 == 0 || b == blockCount - 1) { + val bytesSent = bytesBefore + minOf((b + 1).toLong() * BLOCK_SIZE, ps.toLong()) + listener.onProgress(lens, index + 1, count, b + 1, blockCount, bytesSent, totalBytes) + } + } + emitLog(seg.name + ": data phase done; sending END") + return sendCtrlAndWait(address, OP_END, EMPTY, timings.ctrlAckTimeoutMs) + } + + /** Send one 4 KB block as a marker + data pair sharing one envelope seq. */ + private fun sendBlock(address: String, block: ByteArray): Int { + val seq = session.nextSeq() + session.otaAcks.clear() + writeOta(address, SID_CTRL, byteArrayOf(OP_BLOCK.toByte()), seq) + writeOta(address, SID_DATA, block, seq) + return waitAck(OP_BLOCK, timings.blockAckTimeoutMs) + } + + private fun sendCtrlAndWait(address: String, op: Int, data: ByteArray, timeoutMs: Int): Int { + val seq = session.nextSeq() + session.otaAcks.clear() + val payload = ByteArray(1 + data.size) + payload[0] = op.toByte() + data.copyInto(payload, 1) + writeOta(address, SID_CTRL, payload, seq) + return waitAck(op, timeoutMs) + } + + private fun writeOta(address: String, sid: Int, payload: ByteArray, seq: Int): Boolean = + session.writeFrame(address, BleProtocol.OTA_DATA_WRITE_UUID, sid, FLAG_OTA, payload, seq) + + private fun waitAck(wantOp: Int, timeoutMs: Int): Int { + val deadline = session.now() + timeoutMs + while (true) { + val remaining = deadline - session.now() + if (remaining <= 0 || cancelled) { + break + } + val pb = session.otaAcks.poll(remaining) ?: break + if (pb.size >= 2 && (pb[0].toInt() and 0xff) == wantOp) { + return pb[1].toInt() and 0xff + } + // Different opcode (e.g. a late ack from a prior stage) — ignore, keep waiting. + } + throw StockTimeoutException("no ack op=0x" + wantOp.toString(16) + " within " + timeoutMs + "ms") + } + + // ---- connection ---------------------------------------------------------- + + private fun connectLensResilient(lens: String, address: String, windowMs: Int) { + val deadline = session.now() + windowMs + var lastError: String? = "unknown" + var attempt = 0 + while (session.now() < deadline && !cancelled) { + attempt++ + try { + if (bringUpLens(address)) { + emitLog("connected $lens lens (attempt $attempt)") + return + } + lastError = "connect/discover incomplete" + } catch (e: Exception) { + lastError = StockLinkSession.messageOf(e) + } + emitLog("$lens connect attempt $attempt failed ($lastError); retrying...") + session.disconnectQuietly(address) + sleeper.sleep(timings.otaRetryDelayMs.toLong()) + } + if (cancelled) { + throw IllegalStateException("Cancelled.") + } + throw IllegalStateException("could not reach $lens lens: $lastError") + } + + private fun bringUpLens(address: String): Boolean { + try { + // Control-channel notify carries the auth response; the OTA notify carries the acks. + session.bringUp(address, otaChannel = true) + } catch (e: IllegalStateException) { + return false + } + // Complete the sid-0x80 security-auth exchange on this connection. On an unbonded + // phone this triggers SMP pairing (possibly with an OS prompt), so the wait is + // generous. Must succeed before any OTA traffic. + if (session.authenticate(address, "ota") != StockLinkSession.AuthResult.SUCCESS) { + throw IllegalStateException("security auth not acknowledged — if the phone shows a Bluetooth pairing request, accept it") + } + return true + } + + // Log lines reach the platform log through the adapter's onLog (Android: logcat under TAG). + private fun emitLog(line: String) { + listener.onLog(line) + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ProtocolPlatform.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ProtocolPlatform.kt index ab7691f0..c9189e18 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ProtocolPlatform.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/ProtocolPlatform.kt @@ -8,6 +8,34 @@ interface ProtocolPlatform { fun createLock(): ProtocolLock fun createDeflater(): ProtocolDeflater + + /** A mutex plus condition variable for blocking waits (see [ProtocolCondition]). */ + fun createCondition(): ProtocolCondition +} + +/** + * Mutex + condition variable. NOT reentrant: iOS backs it with NSCondition, so a thread that + * already holds the lock must not lock it again (Android's implementation would tolerate it + * and hide the bug). Hold the lock while calling [awaitMs] and [signalAll]. + */ +interface ProtocolCondition { + fun lock() + + fun unlock() + + /** Waits up to [timeoutMs] (spurious wake-ups possible); the lock is held again on return. */ + fun awaitMs(timeoutMs: Long) + + fun signalAll() +} + +inline fun ProtocolCondition.withLock(action: () -> T): T { + lock() + try { + return action() + } finally { + unlock() + } } /** Must be reentrant: transport encoding can reset its history under the lock. */ diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLink.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLink.kt new file mode 100644 index 00000000..b7a200f2 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLink.kt @@ -0,0 +1,91 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmField + +/** Android bond state of a peripheral; iOS reports UNKNOWN (pairing is invisible to the app). */ +enum class BondState { + NONE, + BONDING, + BONDED, + UNKNOWN, +} + +/** Inbound side of a [StockLink]; called on whatever thread the platform stack delivers on. */ +interface StockLinkListener { + fun onNotification(address: String, characteristicUuid: String, data: ByteArray) + + fun onConnectionStateChange(address: String, connected: Boolean) +} + +/** + * The GATT boundary used by the stock-firmware flows (device-info probe, flash prompt, OTA + * flasher). Calls block on the caller's thread with explicit timeouts; addresses are opaque + * strings (Android MAC, iOS peripheral identifier). Android wraps FaceclawBleManager; an iOS + * implementation sits on CoreBluetooth. Methods other than [isConnected]/[bondState]/ + * [disconnect]/[close] may throw IllegalStateException when the link is not connected. + */ +interface StockLink { + fun setListener(listener: StockLinkListener?) + + fun connect(address: String, timeoutMs: Int): Boolean + + /** Best-effort link tuning after connect (connection priority, MTU). */ + fun prepareLink(address: String, desiredMtu: Int, timeoutMs: Int) + + fun discoverServices(address: String, timeoutMs: Int): Boolean + + fun enableNotifications(address: String, characteristicUuid: String, timeoutMs: Int): Boolean + + fun writeFrames( + address: String, + characteristicUuid: String, + frames: List, + mode: GattWriteMode, + timeoutMs: Int, + ): Boolean + + fun isConnected(address: String): Boolean + + fun bondState(address: String): BondState + + fun disconnect(address: String) + + fun close() +} + +/** A wait for a lens reply expired. */ +class StockTimeoutException(message: String) : Exception(message) + +/** + * Timeouts and pacing shared by the stock flows. Production uses the defaults; tests shrink + * them. Values are milliseconds unless named otherwise. + */ +class StockFlowTimings( + @JvmField val connectTimeoutMs: Int = ConnectionOptions.CONNECT_TIMEOUT_MS, + @JvmField val servicesTimeoutMs: Int = ConnectionOptions.SERVICES_TIMEOUT_MS, + @JvmField val descriptorTimeoutMs: Int = ConnectionOptions.DESCRIPTOR_TIMEOUT_MS, + @JvmField val writeTimeoutMs: Int = ConnectionOptions.WRITE_TIMEOUT_MS, + @JvmField val preludeTimeoutMs: Int = ConnectionOptions.PRELUDE_TIMEOUT_MS, + @JvmField val securityAuthTimeoutMs: Int = ConnectionOptions.SECURITY_AUTH_TIMEOUT_MS, + @JvmField val securityAuthSoftTimeoutMs: Int = ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS, + /** Upper bound on waiting while the OS reports pairing in progress (a dialog may be up). */ + @JvmField val pairingWaitCapMs: Int = 90_000, + /** After a fresh bond, how long the firmware gets to notify success before the auth request is re-sent. */ + @JvmField val postBondGraceMs: Int = 2_000, + @JvmField val pollMs: Int = 250, + /** Delay between connect/auth attempts on one arm and between auth re-sends. */ + @JvmField val armRetryDelayMs: Int = 1_000, + @JvmField val queryTimeoutMs: Int = 4_000, + @JvmField val heartbeatIntervalMs: Int = 4_000, + @JvmField val selectionTimeoutMs: Int = 120_000, + @JvmField val createAckTimeoutMs: Int = 3_000, + @JvmField val batteryAckTimeoutMs: Int = 3_000, + @JvmField val blockAckTimeoutMs: Int = 4_000, + @JvmField val ctrlAckTimeoutMs: Int = 8_000, + @JvmField val firstLensConnectWindowMs: Int = 30_000, + @JvmField val secondLensConnectWindowMs: Int = 120_000, + @JvmField val rebootSettleMs: Int = 5_000, + @JvmField val notifySettleMs: Int = 2_500, + @JvmField val otaRetryDelayMs: Int = 2_500, + @JvmField val componentRetryDelayMs: Int = 1_500, +) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLinkSession.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLinkSession.kt new file mode 100644 index 00000000..d83adeab --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/StockLinkSession.kt @@ -0,0 +1,443 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile + +/** + * The stock-firmware request/reply plumbing that the device-info probe, the flash prompt and + * the OTA flasher all need on top of a [StockLink]: connect + subscribe, envelope sequence and + * magic allocation, frame demux, ack matching keyed by (sid, magic), the bond-aware security + * auth exchange (only the firmware's SUCCESS satisfies it), the unsolicited settings capture, + * async-event and disconnect hooks, and the OTA ack queue. Blocking calls run on the owning + * flow's worker thread; notifications arrive on the platform's callback thread. + */ +class StockLinkSession( + private val link: StockLink, + private val log: (String) -> Unit, + private val timings: StockFlowTimings = StockFlowTimings(), + magicStart: Int = 100, + private val magicEnd: Int = 255, + seqStart: Int = 0x40, + /** Log every parsed control frame with a payload prefix (the probe's 2.2.9 diagnostics). */ + private val traceFrames: Boolean = false, + private val platform: ProtocolPlatform = protocolPlatform(), +) : StockLinkListener { + enum class AuthResult { + SUCCESS, + UNCONFIRMED, + LINK_DROPPED, + } + + private val lock = platform.createLock() + private val magicStart = magicStart + private var nextMagic = magicStart + private var nextSeq = seqStart + private val pendingAcks = HashMap() + private val ackPayloads = HashMap() + private val authMagics = HashSet() + private var authLatch: Latch? = null + + /** Latest sid-0x09 frame carrying firmware versions, whatever magic it came with. */ + @Volatile + var unsolicitedSettingsPb: ByteArray? = null + private set + + /** OTA acks (first two payload bytes: opcode, status) from the data-notify characteristic. */ + val otaAcks = BlockingQueue(platform) + + /** Async events (flag 0x01/0x06) on the control characteristic, e.g. list selections. */ + @Volatile + var onEvent: ((address: String, frame: BleProtocol.ParsedFrame) -> Unit)? = null + + @Volatile + var onDisconnected: ((address: String) -> Unit)? = null + + @Volatile + var cancelled = false + private set + + init { + link.setListener(this) + } + + val platformServices: ProtocolPlatform + get() = platform + + fun now(): Long = platform.elapsedRealtimeMs() + + /** Wake every pending wait; subsequent waits return immediately as timeouts. */ + fun cancel() { + cancelled = true + lock.withLock { + for (latch in pendingAcks.values) latch.countDown() + authLatch?.countDown() + } + } + + fun allocMagic(): Int = + lock.withLock { + val magic = nextMagic + nextMagic = if (nextMagic >= magicEnd) magicStart else nextMagic + 1 + magic + } + + fun nextSeq(): Int = + lock.withLock { + val seq = nextSeq and 0xff + nextSeq = (nextSeq + 1) and 0xff + seq + } + + fun resetSeq(value: Int) { + lock.withLock { nextSeq = value and 0xff } + } + + /** Connect, tune, discover and subscribe to the control notify (plus the OTA notify when asked). Throws on failure. */ + fun bringUp(address: String, otaChannel: Boolean = false) { + if (!link.connect(address, timings.connectTimeoutMs)) { + throw IllegalStateException("connect failed") + } + link.prepareLink(address, ConnectionOptions.DESIRED_MTU, timings.connectTimeoutMs) + if (!link.discoverServices(address, timings.servicesTimeoutMs)) { + throw IllegalStateException("service discovery failed") + } + if (!link.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, timings.descriptorTimeoutMs)) { + throw IllegalStateException("could not subscribe to notifications") + } + if (otaChannel && !link.enableNotifications(address, BleProtocol.OTA_DATA_NOTIFY_UUID, timings.descriptorTimeoutMs)) { + throw IllegalStateException("could not subscribe to OTA notifications") + } + } + + fun isConnected(address: String): Boolean = link.isConnected(address) + + fun disconnectQuietly(address: String) { + try { + link.disconnect(address) + } catch (ignored: Exception) { + } + } + + fun closeQuietly() { + try { + link.close() + } catch (ignored: Exception) { + } + } + + /** Frame and write one message on the control characteristic; false when the write failed. */ + fun writeFrame(address: String, sid: Int, flag: Int, payload: ByteArray): Boolean = + writeFrame(address, BleProtocol.WRITE_CHAR_UUID, sid, flag, payload, nextSeq()) + + /** @throws IllegalStateException when the link reports "not connected". */ + fun writeFrame(address: String, characteristicUuid: String, sid: Int, flag: Int, payload: ByteArray, seq: Int): Boolean { + val frames = BleProtocol.framePb(payload, sid, flag, seq) + return link.writeFrames(address, characteristicUuid, frames, ConnectionOptions.WRITE_MODE, timings.writeTimeoutMs) + } + + /** + * Write a request and wait for the ack carrying the same sid and magic. Returns the ack's + * protobuf (possibly empty), or null on write failure / timeout / cancel. + */ + fun writeAndAwaitAck(address: String, sid: Int, flag: Int, magic: Int, payload: ByteArray, timeoutMs: Int): ByteArray? { + val key = ackKey(sid, magic) + val latch = Latch(1, platform) + lock.withLock { + pendingAcks[key] = latch + ackPayloads.remove(key) + } + try { + val seq = nextSeq() + log( + "tx " + address + " sid=0x" + hex2(sid) + " flag=0x" + hex2(flag) + " magic=" + magic + + " seq=0x" + hex2(seq) + " len=" + payload.size + ) + val written = + try { + writeFrame(address, BleProtocol.WRITE_CHAR_UUID, sid, flag, payload, seq) + } catch (e: IllegalStateException) { + // "Not connected" — the link went away underneath us. + false + } + if (!written) { + log("tx write FAILED sid=0x" + sid.toString(16) + " (" + address + ")") + return null + } + if (!latch.await(timeoutMs.toLong()) || cancelled) { + return null + } + return lock.withLock { ackPayloads[key] ?: ByteArray(0) } + } finally { + lock.withLock { + if (pendingAcks[key] === latch) pendingAcks.remove(key) + ackPayloads.remove(key) + } + } + } + + /** Mandatory session prelude on sid=0x01; throws when it is not acked. */ + fun sendPrelude(address: String, failureDetail: String = "") { + if (writeAndAwaitAck( + address, + BleProtocol.PRELUDE_ACK_SID, + BleProtocol.FLAG_REQUEST, + BleProtocol.PRELUDE_ACK_MAGIC, + BleProtocol.PRELUDE_F5872_PAYLOAD, + timings.preludeTimeoutMs, + ) == null + ) { + throw IllegalStateException("session prelude not acked$failureDetail") + } + } + + /** One sid-0x09 settings read; the ack protobuf or null when unanswered. */ + fun readSettings(address: String, timeoutMs: Int): ByteArray? { + val magic = allocMagic() + return writeAndAwaitAck(address, BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_REQUEST, magic, BleProtocol.buildSettingsQuery(magic), timeoutMs) + } + + /** + * Send the sid-0x80 authentication request and wait for the firmware's SUCCESS notification, + * which only arrives once the link is encrypted. On an unbonded phone that means waiting + * through the OS pairing flow (BOND_BONDING, possibly with a dialog up), so the wait is + * extended while the OS reports pairing in progress and the request is re-sent once after a + * fresh bond in case the pre-pairing write was dropped. Bond state is polled; 250 ms + * granularity is plenty here. Platforms that cannot see bonding (UNKNOWN) get the plain + * timeout. The first reply with a non-success result is expected before encryption and does + * not satisfy the wait. + */ + fun authenticate(address: String, label: String): AuthResult { + val start = now() + var deadline = start + timings.securityAuthTimeoutMs + val hardDeadline = start + timings.pairingWaitCapMs + val latch = Latch(1, platform) + lock.withLock { + authMagics.clear() + authLatch = latch + } + val initialBond = link.bondState(address) + log("security auth: $label lens, bond state " + bondStateName(initialBond)) + try { + var sends = 0 + var lastSendFailed = false + var nextSendAt = start + var bondedAt = -1L + var resentAfterBond = false + var loggedBonding = false + while (!cancelled) { + val now = now() + val bond = link.bondState(address) + + if (bond == BondState.BONDING) { + // OS pairing in progress — the firmware will answer once the link is + // encrypted. Don't write, don't give up, don't move on to the other arm. + if (!loggedBonding) { + log("the OS is pairing with the $label lens; waiting for the user to accept") + loggedBonding = true + } + if (now >= hardDeadline) { + break + } + } else { + if (bond == BondState.BONDED && initialBond != BondState.BONDED && bondedAt < 0) { + bondedAt = now + log("bond established with the $label lens; waiting for the auth success") + deadline = maxOf(deadline, now + timings.securityAuthSoftTimeoutMs) + } + val wantSend = sends == 0 || + (lastSendFailed && sends < 3 && now >= nextSendAt) || + (bondedAt >= 0 && !resentAfterBond && now - bondedAt >= timings.postBondGraceMs) + if (wantSend) { + if (bondedAt >= 0) { + resentAfterBond = true + if (sends > 0) { + log("re-sending the auth request after pairing ($label lens)") + } + } + lastSendFailed = !sendAuthRequest(address) + sends++ + nextSendAt = now() + timings.armRetryDelayMs + if (lastSendFailed && !link.isConnected(address)) { + return AuthResult.LINK_DROPPED + } + } + if (now >= deadline) { + break + } + } + + if (latch.await(timings.pollMs.toLong()) && !cancelled) { + log("security auth complete: $label lens ($address)") + return AuthResult.SUCCESS + } + if (!link.isConnected(address)) { + log( + "security auth: $label lens disconnected while waiting" + + (if (bond == BondState.BONDING) " (the OS was still pairing)" else "") + ) + return AuthResult.LINK_DROPPED + } + } + if (cancelled) { + return AuthResult.UNCONFIRMED + } + log("security auth unconfirmed: $label lens ($address), bond state " + bondStateName(link.bondState(address))) + return AuthResult.UNCONFIRMED + } finally { + lock.withLock { + authLatch = null + authMagics.clear() + } + } + } + + private fun sendAuthRequest(address: String): Boolean { + val magic = allocMagic() + lock.withLock { authMagics.add(magic) } + val seq = nextSeq() + val payload = BleProtocol.buildAuthenticationRequest(magic) + log( + "tx " + address + " sid=0x" + hex2(BleProtocol.SID_SECURITY_AUTH) + " flag=0x" + hex2(BleProtocol.FLAG_SECURITY_AUTH) + + " magic=" + magic + " seq=0x" + hex2(seq) + " len=" + payload.size + ) + val written = + try { + writeFrame(address, BleProtocol.WRITE_CHAR_UUID, BleProtocol.SID_SECURITY_AUTH, BleProtocol.FLAG_SECURITY_AUTH, payload, seq) + } catch (e: IllegalStateException) { + false + } + if (!written) { + log("tx write FAILED sid=0x80 ($address)") + } + return written + } + + /** Block while the OS reports this arm as BONDING (pairing dialog up / SMP in flight). */ + fun waitForBondToSettle(address: String, label: String, sleeper: InterruptibleSleep) { + val cap = now() + timings.pairingWaitCapMs + var logged = false + while (!cancelled && link.bondState(address) == BondState.BONDING && now() < cap) { + if (!logged) { + log("waiting for the OS to finish pairing with the $label lens before reconnecting") + logged = true + } + sleeper.sleep(timings.pollMs.toLong()) + } + } + + // ---- inbound -------------------------------------------------------------- + + override fun onNotification(address: String, characteristicUuid: String, data: ByteArray) { + if (BleProtocol.OTA_DATA_NOTIFY_UUID.equals(characteristicUuid, ignoreCase = true)) { + val frame = BleProtocol.parseFrame(data) + if (frame.ok && frame.pb.size >= 2) { + otaAcks.put(frame.pb.copyOf(minOf(frame.pb.size, 2))) + } + return + } + if (!BleProtocol.NOTIFY_CHAR_UUID.equals(characteristicUuid, ignoreCase = true)) { + return + } + // One notification value can carry several envelope frames back to back; reading only + // the first would silently drop the rest. + val frames = BleProtocol.splitFrames(data) + if (traceFrames && frames.size > 1) { + log("rx " + address + " value carries " + frames.size + " frames (raw " + data.size + " bytes)") + } + for (buf in frames) { + handleFrame(address, buf, data.size) + } + } + + private fun handleFrame(address: String, buf: ByteArray, rawValueLength: Int) { + val frame = BleProtocol.parseFrame(buf) + if (!frame.ok) { + if (traceFrames) { + log( + "rx " + address + " unparseable frame len=" + buf.size + " (raw value " + rawValueLength + ")" + + " head=" + BinaryEncoding.bytesToHex(buf.copyOf(minOf(16, buf.size))) + ) + } + return + } + if (traceFrames) { + // Log every control frame while diagnosing 2.2.9: sid/flag/type/magic plus a + // payload prefix is enough to reconstruct what the lens said. + val declared = if (buf.size > 3) buf[3].toInt() and 0xff else 0 + val truncated = if (buf.size < 8 + declared) " TRUNCATED(declared=$declared)" else "" + log( + "rx " + address + " sid=0x" + hex2(frame.sid) + " flag=0x" + hex2(frame.flag) + " type=" + frame.msgType + + " magic=" + frame.msgSeq + " frag=" + (if (buf.size > 5) buf[5].toInt() and 0xff else 0) + "/" + + (if (buf.size > 4) buf[4].toInt() and 0xff else 0) + " len=" + frame.pb.size + truncated + + " pb=" + BinaryEncoding.bytesToHex(frame.pb.copyOf(minOf(48, frame.pb.size))) + ) + } + if (frame.sid == BleProtocol.SID_UI_SETTING && BleProtocol.parseSettingsFirmwareInfo(frame.pb) != null) { + // Any settings frame carrying firmware versions answers the probe's question, + // whether or not it matches the magic we asked with. + unsolicitedSettingsPb = frame.pb + } + if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { + // Async event, not an ack. This includes the lens's own periodic sid-0x80 notifies + // (device-chosen magic, non-empty result). + onEvent?.invoke(address, frame) + return + } + if (frame.sid == BleProtocol.SID_SECURITY_AUTH) { + var success = false + var ours = false + lock.withLock { + val currentLatch = authLatch + if (currentLatch != null) { + ours = authMagics.contains(frame.msgSeq) + for (magic in authMagics) { + if (BleProtocol.isAuthenticationSuccess(frame.pb, magic)) { + success = true + currentLatch.countDown() + break + } + } + } + } + if (ours && !success) { + // Expected before the link is encrypted: the firmware answers the request + // straight away with a non-success result and sends the real success once + // pairing/encryption completes. + log("auth reply for magic " + frame.msgSeq + " is not the success result; still waiting") + } + return + } + if (frame.msgSeq >= 0) { + val key = ackKey(frame.sid, frame.msgSeq) + lock.withLock { + val latch = pendingAcks[key] + if (latch != null) { + ackPayloads[key] = frame.pb + latch.countDown() + } + } + } + } + + override fun onConnectionStateChange(address: String, connected: Boolean) { + if (!connected) { + log("disconnected: $address") + onDisconnected?.invoke(address) + } + } + + companion object { + private fun ackKey(sid: Int, magic: Int): String = "$sid:$magic" + + internal fun hex2(value: Int): String = (value and 0xff).toString(16).padStart(2, '0') + + internal fun bondStateName(state: BondState): String = + when (state) { + BondState.NONE -> "none" + BondState.BONDING -> "bonding" + BondState.BONDED -> "bonded" + BondState.UNKNOWN -> "unknown" + } + + internal fun messageOf(e: Throwable): String = e.message ?: e.toString() + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionControls.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionControls.kt new file mode 100644 index 00000000..7694eb3a --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionControls.kt @@ -0,0 +1,695 @@ +package com.faceclaw.app + +import com.faceclaw.app.GlassesSessionCore.Companion.DASHBOARD_TILE +import com.faceclaw.app.GlassesSessionCore.Companion.FACECLAW_WAKE_CONTROL_WAIT_MS +import com.faceclaw.app.GlassesSessionCore.Companion.TAG + +/* + * GlassesSessionCore, part 3: CFW lease controls, EvenHub shutdown, the bandwidth + * benchmark stream, transport-failure handling and the listener emits (all + * marshalled through SessionHost.postToMain, or a subscriber's own dispatcher + * for compass events). + */ + +// --------------------------------------------------------------------------- +// Bandwidth benchmark + +/** Pending + in-flight benchmark no-op messages. */ +internal fun GlassesSessionCore.benchmarkOutstandingLocked(): Int { + var count = 0 + for (message in pendingMessages) { + if ("bandwidth" == message.kind) count++ + } + for (message in inFlightMessages) { + if ("bandwidth" == message.kind) count++ + } + return count +} + +/** + * Keep the benchmark stream fed: top the pending queue up so the send + * window never starves, stop enqueueing once the run expires (or a message + * times out), and finish the run when the last outstanding message drains. + */ +internal fun GlassesSessionCore.maintainBenchmarkLocked(now: Long) { + if (!sessionReady || !fixedLayoutCreated || shutdownRequested) { + finishBenchmarkLocked(true, "session no longer ready") + return + } + if (benchmarkLinkPending || now < benchmarkReadyAtMs) { + return + } + if (benchmarkAborted || now >= benchmarkDeadlineAtMs) { + // The run is over: drop queued-but-unsent no-ops (sending them + // would stretch the run past its deadline) and finish once the + // in-flight tail has acked or timed out. + val pendingIterator = pendingMessages.iterator() + while (pendingIterator.hasNext()) { + val queued = pendingIterator.next() + if ("bandwidth" == queued.kind) { + pendingIterator.remove() + magicPool.release(queued.sid, queued.magic, queued.label, "benchmark over") + } + } + if (benchmarkOutstandingLocked() == 0) { + finishBenchmarkLocked(false, "complete") + } + return + } + // One more than the window so a fresh message is always ready to write + // the moment an ack frees a slot. + var outstanding = benchmarkOutstandingLocked() + while (outstanding <= benchmarkWindowSize) { + enqueueBenchmarkMessageLocked() + outstanding++ + } +} + +internal fun GlassesSessionCore.finishBenchmarkLocked(aborted: Boolean, reason: String) { + if (!benchmarkActive) { + return + } + benchmarkActive = false + benchmarkAborted = benchmarkAborted or aborted + // Prefer the last ack as the end time so drain lag after the deadline + // doesn't dilute the throughput figure. + benchmarkEndAtMs = if (benchmarkLastAckAtMs != 0L) benchmarkLastAckAtMs else now() + logLine("bandwidth benchmark " + (if (benchmarkAborted) "aborted" else "finished") + " (" + reason + "): " + + benchmarkMessagesAcked + "/" + benchmarkMessagesSent + " acked, " + + benchmarkPayloadBytesAcked + "B payload, " + benchmarkTimeouts + " timeouts") +} + +internal fun GlassesSessionCore.enqueueBenchmarkMessageLocked() { + // Fresh bytes per message: the transport's persistent compression history + // would compress even a random payload if we reused it across the run. + val payload = ByteArray(benchmarkMessageSize) + kotlin.random.Random.nextBytes(payload) + payload[0] = CFW_MSG_DIAGNOSTICS.toByte() // CFW diagnostic-control mode... + payload[1] = 0x7f.toByte() // ...with an unused sub-op: acked, no effect + val message = messageBuilder.imagePayload( + "bandwidth", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + "bandwidth no-op " + payload.size + "B", + connectionOptions.sendImagesToLeft) + val payloadBytes = payload.size + // Logical custom-message bytes; excludes length tag and packet framing. + val wireBytes = message.message.size + message.onSent = MessageCallback { + benchmarkMessagesSent++ + if (benchmarkStartAtMs == 0L) { + benchmarkStartAtMs = now() + benchmarkDeadlineAtMs = benchmarkStartAtMs + benchmarkDurationMs + } + } + message.onAck = MessageCallback { + val ackedAtMs = now() + benchmarkMessagesAcked++ + benchmarkPayloadBytesAcked += payloadBytes + benchmarkWireBytesAcked += wireBytes + benchmarkLastAckAtMs = ackedAtMs + // No-op payloads ride the image path, so the firmware resets its + // heartbeat timer on them just like real image messages. + lastHeartbeatAckedAtMs = ackedAtMs + } + message.onTimeout = MessageCallback { + benchmarkTimeouts++ + benchmarkAborted = true + logLine("bandwidth benchmark ack timeout") + } + pendingMessages.addLast(message) +} + +// --------------------------------------------------------------------------- +// EvenHub shutdown and audio control waits + +internal fun GlassesSessionCore.sendShutdownInternal(exitMode: Int, reconnectOnTimeout: Boolean): Boolean { + val magic: Int + val startedAtMs = now() + monitor.withLock { + if (!running || !sessionReady) { + logLine("skip shutdown; session not ready") + return false + } + if (shutdownRequested) { + return true + } + shutdownRequested = true + // Magic values wrap, so an ACK from a much older suspend must not + // satisfy this request after enough sleep/wake cycles. + lastShutdownAckMagic = 0 + clearPendingMessagesLocked("shutdown requested") + val message = messageBuilder.shutdown(exitMode) + magic = message.magic + message.onAck = MessageCallback { + lastShutdownAckMagic = message.magic + fixedLayoutCreated = false + displayedFingerprint = "" + } + message.onTimeout = MessageCallback { + if (reconnectOnTimeout) { + handleTransportFailure("shutdown ack timeout") + } else { + logLine("EvenHub shutdown ack timeout; keeping BLE connected") + } + } + pendingMessages.addFirst(message) + logLine("queue shutdown") + // The stock compass keeps the magnetometer sampling independently of + // the plugin task, so ending the page does not stop it. Force a + // disable ahead of the shutdown command whenever it may be running: + // this also covers a disable that was wiped by the queue flush above + // or whose ack was lost, and the charging-mode/exit paths where the + // Compass window never got a chance to release it. + if (compassMaybeOn && fixedLayoutCreated) { + enqueueCompassControlLocked(true, false) + } + } + interruptibleSleep.interrupt() + + val ackDeadline = now() + ConnectionOptions.ACK_TIMEOUT_MS + 500 + monitor.withLock { + while (running + && sessionReady + && lastShutdownAckMagic != magic + && lastShutdownExitAtMs < startedAtMs + && hasPendingOrInflightMagicLocked(magic)) { + val remaining = ackDeadline - now() + if (remaining <= 0) { + break + } + monitor.awaitMs(minOf(remaining, 100L)) + } + val acked = lastShutdownAckMagic == magic + if (acked) { + val exitDeadline = now() + ConnectionOptions.ACK_TIMEOUT_MS + 500 + while (running && sessionReady && lastShutdownExitAtMs < startedAtMs) { + val remaining = exitDeadline - now() + if (remaining <= 0) { + break + } + monitor.awaitMs(minOf(remaining, 100L)) + } + } + return acked || lastShutdownExitAtMs >= startedAtMs + } +} + +internal fun GlassesSessionCore.waitForAudioControlAck(magic: Int, operation: String): Boolean { + val deadline = now() + ConnectionOptions.ACK_TIMEOUT_MS + ConnectionOptions.WRITE_TIMEOUT_MS + 500 + monitor.withLock { + while (running && sessionReady && lastAudioControlAckMagic != magic && hasPendingOrInflightMagicLocked(magic)) { + val remaining = deadline - now() + if (remaining <= 0) { + break + } + monitor.awaitMs(minOf(remaining, 100L)) + } + val acked = lastAudioControlAckMagic == magic + if (!acked) { + if ("enable" == operation) { + audioPacketListener = null + audioCaptureActive = false + } + logLine("G2 mic $operation ack timeout") + } + return acked + } +} + +// --------------------------------------------------------------------------- +// CFW wake and framebuffer leases + +/** + * Replace any stale lease control with one right-arm and one left-arm + * fire-and-forget write. With priority=true the right arm is sent first so + * CLAIM reaches the lens that originated the deferred wake immediately. + */ +internal fun GlassesSessionCore.enqueueFaceclawWakeControlLocked(operation: Int, nonce: Int, priority: Boolean): Int { + clearMessagesOfKindLocked("wake-lease-control") + val generation = ++faceclawWakeControlGeneration + faceclawWakeControlSentCount = 0 + if (operation == BleProtocol.FACECLAW_WAKE_OP_ACQUIRE) { + lastFaceclawWakeLeaseQueuedAtMs = now() + } + val onSent = MessageCallback { + if (faceclawWakeControlGeneration == generation) { + faceclawWakeControlSentCount += 1 + } + } + val right = messageBuilder.faceclawWakeControl(operation, nonce, false) + val left = messageBuilder.faceclawWakeControl(operation, nonce, true) + right.onSent = onSent + left.onSent = onSent + if (priority) { + pendingMessages.addFirst(left) + pendingMessages.addFirst(right) + } else { + pendingMessages.addLast(right) + pendingMessages.addLast(left) + } + logLine("queue " + right.label + " + L") + return generation +} + +internal fun GlassesSessionCore.waitForFaceclawWakeControlDelivery(generation: Int, timeoutMs: Long): Boolean { + val deadline = now() + maxOf(0L, timeoutMs) + monitor.withLock { + while (running + && sessionReady + && faceclawWakeControlGeneration == generation + && faceclawWakeControlSentCount < 2) { + val remaining = deadline - now() + if (remaining <= 0) { + break + } + monitor.awaitMs(minOf(remaining, 100L)) + } + return faceclawWakeControlGeneration == generation + && faceclawWakeControlSentCount >= 2 + } +} + +/** + * Acquire/renew or release CFW's independent direct-framebuffer repaint + * guard on both arms. It is separate from the optional idle-wake lease: + * every Faceclaw display session needs this guard while its EvenHub layout + * contains swipe-capturing stock widgets. + */ +internal fun GlassesSessionCore.enqueueFaceclawFramebufferControlLocked(operation: Int, priority: Boolean): Int { + clearMessagesOfKindLocked("framebuffer-lease-control") + val generation = ++faceclawFramebufferControlGeneration + faceclawFramebufferControlSentCount = 0 + if (operation == BleProtocol.FACECLAW_FB_OP_ACQUIRE) { + lastFaceclawFramebufferLeaseQueuedAtMs = now() + } + val onSent = MessageCallback { + if (faceclawFramebufferControlGeneration == generation) { + faceclawFramebufferControlSentCount += 1 + } + } + val right = messageBuilder.faceclawFramebufferControl(operation, false) + val left = messageBuilder.faceclawFramebufferControl(operation, true) + right.onSent = onSent + left.onSent = onSent + if (priority) { + pendingMessages.addFirst(left) + pendingMessages.addFirst(right) + } else { + pendingMessages.addLast(right) + pendingMessages.addLast(left) + } + logLine("queue " + right.label + " + L") + return generation +} + +internal fun GlassesSessionCore.waitForFaceclawFramebufferControlDelivery(generation: Int, timeoutMs: Long): Boolean { + val deadline = now() + maxOf(0L, timeoutMs) + monitor.withLock { + while (running + && sessionReady + && faceclawFramebufferControlGeneration == generation + && faceclawFramebufferControlSentCount < 2) { + val remaining = deadline - now() + if (remaining <= 0) { + break + } + monitor.awaitMs(minOf(remaining, 100L)) + } + return faceclawFramebufferControlGeneration == generation + && faceclawFramebufferControlSentCount >= 2 + } +} + +internal fun GlassesSessionCore.releaseFaceclawFramebufferLease(): Boolean { + val generation: Int + monitor.withLock { + if (!running || !sessionReady) { + return true + } + generation = enqueueFaceclawFramebufferControlLocked( + BleProtocol.FACECLAW_FB_OP_RELEASE, + true + ) + } + interruptibleSleep.interrupt() + return waitForFaceclawFramebufferControlDelivery( + generation, + FACECLAW_WAKE_CONTROL_WAIT_MS + ) +} + +// --------------------------------------------------------------------------- +// Failure handling + +/** The address of a configured arm the OS no longer holds a bond for, or null. */ +internal fun GlassesSessionCore.firstUnpairedArm(): String? { + if (!link.isBonded(rightAddress)) return rightAddress + if (!link.isBonded(leftAddress)) return leftAddress + return null +} + +/** + * A connect failure while an arm's bond is missing (the pairing was + * forgotten in the OS settings, or the address was typed in by hand and + * never paired) will repeat forever, so instead of scheduling a retry, + * park the worker loop and tell the user to re-pair. Only an explicit + * connect (which builds a fresh communicator) starts a new attempt. + */ +internal fun GlassesSessionCore.handleUnpairedFailure(address: String) { + logError("Connect failed and $address is not paired; suspending reconnect") + monitor.withLock { + reconnectHalted = true + sessionReady = false + fixedLayoutCreated = false + startupProbePending = false + shutdownRequested = false + chargingMode = false + imageRetryAfterMs = 0 + displayedFingerprint = "" + faceclawWakePendingNonce = -1 + lastFaceclawWakeLeaseQueuedAtMs = 0 + faceclawWakeControlSentCount = 0 + clearAllMessagesLocked("arm not paired: $address") + reconnectAfterMs = Long.MAX_VALUE + link.disconnect(rightAddress) + link.disconnect(leftAddress) + } + if (!userDisconnectRequested) { + setStateDisplay( + "unpaired", + "The glasses (" + address + ") are not paired with this phone." + + " Use \"Pair glasses\" to pair them again, then connect." + ) + } + interruptibleSleep.interrupt() +} + +internal fun GlassesSessionCore.handleTransportFailure(reason: String?) { + logError("Transport failure: $reason") + monitor.withLock { + maybeEmitEvenAppConflictLocked(reason) + finishBenchmarkLocked(true, "transport failure") + sessionReady = false + fixedLayoutCreated = false + startupProbePending = false + shutdownRequested = false + chargingMode = false + imageRetryAfterMs = 0 + displayedFingerprint = "" + faceclawWakePendingNonce = -1 + lastFaceclawWakeLeaseQueuedAtMs = 0 + faceclawWakeControlSentCount = 0 + clearAllMessagesLocked("transport failure: $reason") + reconnectAfterMs = now() + ConnectionOptions.RECONNECT_DELAY_MS + link.disconnect(rightAddress) + link.disconnect(leftAddress) + } + if (!userDisconnectRequested) { + setStateDisplay("retrying", if (reason == null || reason.isEmpty()) "Reconnecting..." else "Reconnecting after $reason") + } + interruptibleSleep.interrupt() +} + +internal fun GlassesSessionCore.resetSessionStateLocked() { + ringBattery = -1 + ringCharging = -1 + sessionReady = false + shutdownRequested = false + fixedLayoutCreated = false + chargingMode = false + rightConnected = false + leftConnected = false + ringConnected = false + ringNotificationsReady = false + reconnectAfterMs = 0 + reconnectHalted = false + ringReconnectAfterMs = 0 + lastAckAtMs = 0 + lastIncomingAtMs = 0 + lastHeartbeatSentAtMs = 0 + lastSessionReadyAtMs = 0 + consecutiveAckTimeouts = 0 + lastAudioControlAckMagic = 0 + audioCaptureActive = false + audioPacketListener = null + compassControlLastSent = -1 + // A dead transport orphans any glasses-side compass state; the fresh + // session re-asserts the desired state once its layout is ready. + compassMaybeOn = false + faceclawWakePendingNonce = -1 + lastFaceclawWakeLeaseQueuedAtMs = 0 + faceclawWakeControlSentCount = 0 + cfwCleanupDelivered = false + for (transport in cfwTransports) transport.reset() + lastCfwCleanupAckMagic = 0 + wearState = -1 + displayedFingerprint = "" + // Deliberately not clearing silentMode: it is a property of the glasses, + // not of our session, and silent mode blocks app launches, so it can be + // the very cause of the session teardown that got us here. +} + +// --------------------------------------------------------------------------- +// Listener emits (main thread via the host) + +internal fun GlassesSessionCore.emitAmbientLight(body: ByteArray) { + if (ambientLightListeners.isEmpty()) { + return + } + val copy = body.copyOf() + host.postToMain { + for (alsListener in ambientLightListeners) { + try { + alsListener.onAmbientLight(copy) + } catch (t: Throwable) { + logWarn("ambient light listener failed", t) + } + } + } +} + +internal fun GlassesSessionCore.emitMicStatus(body: ByteArray, address: String) { + if (micStatusListeners.isEmpty()) { + return + } + val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" + else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?" + val copy = body.copyOf() + host.postToMain { + for (micListener in micStatusListeners) { + try { + micListener.onMicStatus(copy, arm) + } catch (t: Throwable) { + logWarn("mic status listener failed", t) + } + } + } +} + +internal fun GlassesSessionCore.emitRingEvent(event: G2Event, frameId: Int) { + val current = listener + if (current == null) { + frameTimings.finishFrame(frameId, "discarded: no listener attached") + return + } + val containerNameSnapshot = event.containerName + host.postToMain { + frameTimings.log(frameId, "dispatching input event on main thread") + try { + current.onRingEvent(event.kind, containerNameSnapshot, event.eventType, event.eventSource, event.systemExitReasonCode, frameId, + event.ringTick, event.ringType, event.ringAux, event.ringSpeed) + } catch (t: Throwable) { + logWarn("listener onRingEvent failed", t) + frameTimings.finishFrame(frameId, "discarded: listener onRingEvent failed") + } + } +} + +/** Finish a frame owned by the communicator and tell the TS side, which may be awaiting it. */ +internal fun GlassesSessionCore.finishFrame(frameId: Int, outcome: String) { + if (frameId <= 0) { + return + } + frameTimings.finishFrame(frameId, outcome) + val current = listener ?: return + host.postToMain { + try { + current.onFrameFinished(frameId, outcome) + } catch (t: Throwable) { + logWarn("listener onFrameFinished failed", t) + } + } +} + +internal fun GlassesSessionCore.emitImuData(x: Double, y: Double, z: Double, eventSource: Int) { + if (imuListeners.isEmpty()) { + return + } + host.postToMain { + for (imuListener in imuListeners) { + try { + imuListener.onImuData(x, y, z, eventSource) + } catch (t: Throwable) { + logWarn("listener onImuData failed", t) + } + } + } +} + +internal fun GlassesSessionCore.emitCompassEvent(event: BleProtocol.CompassEvent) { + if (event.diagnosticFlags >= 0) { + val sources = arrayOf("unknown", "GRV", "GMRV", "RV") + host.log(SessionLogLevel.INFO, "FaceclawCompass", "heading=" + event.headingDegrees + + " magneticAccuracy=" + event.magneticAccuracy + + " magneticAnomalies=" + event.magneticAnomalies + + " orientationSource=" + sources[event.orientationSource] + + " flags=0x" + event.diagnosticFlags.toString(16) + + " sampleTimeMs=" + event.sampleTimeMs, null) + } + for (subscription in compassSubscriptions) { + subscription.dispatcher.post { + try { + subscription.listener.onCompassEvent(event.command, event.headingDegrees, + event.magneticAccuracy, event.magneticAnomalies, event.orientationSource, + event.diagnosticFlags, event.sampleTimeMs) + } catch (t: Throwable) { + logWarn("listener onCompassEvent failed", t) + } + } + } +} + +internal fun GlassesSessionCore.emitSilentMode(silent: Boolean) { + val current = listener ?: return + host.postToMain { + try { + current.onSilentMode(silent) + } catch (t: Throwable) { + logWarn("listener onSilentMode failed", t) + } + } +} + +internal fun GlassesSessionCore.emitWearState(wearing: Boolean) { + val current = listener ?: return + host.postToMain { + try { + current.onWearState(wearing) + } catch (t: Throwable) { + logWarn("listener onWearState failed", t) + } + } +} + +internal fun GlassesSessionCore.emitPhoneLockStateIfChanged(force: Boolean) { + val locked: Boolean + monitor.withLock { + val now = now() + if (!force && now - lastPhoneLockCheckAtMs < 1_000) return + lastPhoneLockCheckAtMs = now + locked = host.isPhoneLocked() + val value = if (locked) 1 else 0 + if (!force && value == phoneLockState) return + phoneLockState = value + } + val current = listener ?: return + host.postToMain { + try { + current.onPhoneLockState(locked) + } catch (t: Throwable) { + logWarn("listener onPhoneLockState failed", t) + } + } +} + +internal fun GlassesSessionCore.emitBatteryState(headsetBattery: Int, headsetCharging: Int) { + val reportedRingBattery = ringBattery + val reportedRingCharging = ringCharging + val current = listener ?: return + host.postToMain { + try { + current.onBatteryState(headsetBattery, headsetCharging, reportedRingBattery, reportedRingCharging) + } catch (t: Throwable) { + logWarn("listener onBatteryState failed", t) + } + } +} + +internal fun GlassesSessionCore.emitFirmwareInfo(info: BleProtocol.FirmwareInfo) { + val current = listener ?: return + host.postToMain { + try { + current.onFirmwareInfo(info.leftVersion, info.rightVersion, info.extension) + } catch (t: Throwable) { + logWarn("listener onFirmwareInfo failed", t) + } + } +} + +internal fun GlassesSessionCore.emitFrameMetrics(paintMs: Int, transmitMs: Int, tileCount: Int) { + val current = listener ?: return + host.postToMain { + try { + current.onFrameMetrics(paintMs, transmitMs, tileCount) + } catch (t: Throwable) { + logWarn("listener onFrameMetrics failed", t) + } + } +} + +internal fun GlassesSessionCore.maybeEmitEvenAppConflictLocked(reason: String?) { + if ("write failed" != reason) { + return + } + val now = now() + if (lastSessionReadyAtMs <= 0 || now - lastSessionReadyAtMs > ConnectionOptions.EVEN_APP_WRITE_FAILURE_WINDOW_MS) { + return + } + if (lastEvenAppConflictAtMs > 0 && now - lastEvenAppConflictAtMs < 60_000) { + return + } + if (!host.isEvenAppActive()) { + return + } + lastEvenAppConflictAtMs = now + emitEvenAppConflict("The Even Realities app still appears to be running. It can hold the glasses BLE link and cause Faceclaw write failures. Open its app settings and force stop it, then reconnect Faceclaw.") +} + +internal fun GlassesSessionCore.emitEvenAppConflict(message: String?) { + val current = listener ?: return + val messageSnapshot = message ?: "" + host.postToMain { + try { + current.onEvenAppConflict(messageSnapshot) + } catch (t: Throwable) { + logWarn("listener onEvenAppConflict failed", t) + } + } +} + +internal fun GlassesSessionCore.setStateDisplay(nextPhase: String, nextStatus: String) { + monitor.withLock { + phase = nextPhase + status = nextStatus + } + emitState() +} + +internal fun GlassesSessionCore.emitState() { + val current = listener ?: return + val phaseSnapshot: String + val statusSnapshot: String + monitor.withLock { + phaseSnapshot = phase + statusSnapshot = status + } + host.postToMain { + try { + current.onStateChange(phaseSnapshot, statusSnapshot) + } catch (t: Throwable) { + logWarn("listener onStateChange failed", t) + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt new file mode 100644 index 00000000..8175ccf9 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt @@ -0,0 +1,1917 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.jvm.JvmField + +/** + * The Faceclaw glasses session: connect/auth/prelude, the send scheduler and CFW + * message window, the image pipeline, and every EvenHub/CFW control the app + * drives. Platform-neutral; GATT goes through [SessionLink], side effects + * through [SessionHost], clocks/locks through [ProtocolPlatform]. The worker + * thread that runs [run] is started by the host from [start]. + * + * The class body holds the state and the public API; the scheduler, image + * pipeline and control helpers are extension functions in the sibling files + * (GlassesSessionSend.kt, GlassesSessionControls.kt), which is why the state is + * `internal` rather than private. + * + * Locking: [monitor] guards session state (reentrant); its wait sites are the + * public blocking waits and the connect settling sleep, each of which holds the + * lock exactly once. [desiredTilesLock] guards the desired-frame slot and is + * taken inside the monitor where both are needed. + */ +class GlassesSessionCore( + internal val link: SessionLink, + internal val host: SessionHost, + internal val frameTimings: FrameTimingsCore, + internal val platform: ProtocolPlatform, + rightAddress: String?, + leftAddress: String?, + ringAddress: String?, +) : FaceclawBleListener { + companion object { + const val TAG = "FaceclawComm" + + // Local metadata for custom-command bookkeeping, not an EvenHub container. + // Submitted frames supply pixel geometry; the stock layout only captures input. + internal val DASHBOARD_TILE: BleProtocol.ImageTileOptions = + BleProtocol.ImageTileOptions("img00", 10, 0, 0, 576, 288) + + internal const val FACECLAW_WAKE_LEASE_RENEW_MS = 45_000L + internal const val FACECLAW_WAKE_CONTROL_WAIT_MS = 1_500L + internal const val CFW_CLEANUP_WAIT_MS = 4_000L + internal const val COMPASS_REPORT_INTERVAL_MS = 100 + internal const val COMPASS_MIN_CHANGE_DEGREES = 0 + + // A timed-out benchmark message aborts the run, but its already-in-flight + // peers still time out one by one; keep the window comfortably below + // MAX_CONSECUTIVE_ACK_TIMEOUTS so a dead run can't escalate into a + // transport-failure reconnect all by itself. + internal const val BENCHMARK_MAX_WINDOW = 6 + + internal fun chargingStatusText(battery: Int): String { + return if (battery >= 0) + "Glasses charging. Battery $battery%." + else + "Glasses charging." + } + + internal fun timestamp(elapsedMs: Long): String { + val wallMs = currentTimeMillis() + return formatLocalTime(wallMs, "yyyy-MM-dd HH:mm:ss.SSS") + " elapsed=${elapsedMs}ms" + } + + private fun requireAddress(name: String, address: String?): String { + if (address == null || address.trim().isEmpty()) { + throw IllegalArgumentException("$name is required") + } + return address.trim() + } + + internal fun hex(data: ByteArray?): String { + if (data == null || data.isEmpty()) { + return "" + } + val out = CharArray(data.size * 2) + val digits = "0123456789abcdef".toCharArray() + for (i in data.indices) { + val value = data[i].toInt() and 0xff + out[i * 2] = digits[value ushr 4] + out[i * 2 + 1] = digits[value and 0x0f] + } + return out.concatToString() + } + + internal fun safeMessage(t: Throwable?): String { + if (t == null) { + return "unknown" + } + val trace = t.stackTraceToString() + if (trace.trim().isNotEmpty()) { + return trace + } + val message = t.message + return if (message == null || message.trim().isEmpty()) t.toString() else message + } + } + + internal val interruptibleSleep = InterruptibleSleep(platform) + internal val monitor = SessionMonitor(platform) + internal val rightAddress: String = requireAddress("rightAddress", rightAddress) + internal val leftAddress: String = requireAddress("leftAddress", leftAddress) + internal val ringAddress: String = ringAddress?.trim() ?: "" + + @Volatile internal var listener: FaceclawBleCommunicatorListener? = null + internal val imuListeners = CopyOnWriteList(platform) + /** A compass subscriber plus the dispatcher it registered from (see addCompassListener). */ + internal class CompassSubscription( + @JvmField val listener: FaceclawCompassListener, + @JvmField val dispatcher: SessionDispatcher, + ) + + internal val compassSubscriptions = CopyOnWriteList(platform) + internal val ambientLightListeners = CopyOnWriteList(platform) + internal val micStatusListeners = CopyOnWriteList(platform) + @Volatile internal var running = false + @Volatile internal var userDisconnectRequested = false + // Set when a connect attempt failed while an arm's OS bond is gone: + // retrying is pointless until the user re-pairs, so the worker loop parks + // instead of redialing. Cleared by start() (a fresh explicit connect). + @Volatile internal var reconnectHalted = false + + internal var phase = "disconnected" + internal var status = "Disconnected." + + internal var rightConnected = false + internal var leftConnected = false + internal var ringConnected = false + internal var ringNotificationsReady = false + internal var sessionReady = false + internal var fixedLayoutCreated = false + internal var shutdownRequested = false + // CFW firmware-debug-flags overlay (mode 7). Desired value pushed from TS; the + // sub-op last sent this session (-1 = not yet), reset on (re)connect so the + // overlay state is re-asserted on every reconnect and whenever the value changes. + @Volatile internal var firmwareDebugFlagsEnabled = false + internal var firmwareDebugFlagsLastSent = -1 + // Desired CFW mode-10 compass state. It survives reconnects; lastSent is + // reset with each session so an open Compass window is re-asserted. + /** + * Who currently wants the stock compass running (the Compass window, the + * Navigate worker, ...). The magnetometer is one shared resource, so it + * stays on while any owner holds it and is released when the last lets go; + * this keeps one app's release from silently switching off another's feed. + */ + internal val compassOwners: MutableSet = HashSet() + internal var compassControlLastSent = -1 + // Whether the glasses-side compass may still be running: set when an enable + // is enqueued, cleared only when a disable is acked. Drives the forced + // disable sent ahead of an EvenHub shutdown/suspend, since a pending + // disable can be wiped by the shutdown's queue flush and the retry loop + // does not run while shutdownRequested (magnetometer left on = battery drain). + internal var compassMaybeOn = false + internal var startupProbePending = false + // Desired ownership of CFW's fail-open stock-wake lease (dashboard launch + // and Even AI foreground takeover). This survives a transport reconnect; + // the lease itself is volatile firmware state and is re-acquired once both + // arms are ready. + internal var faceclawWakeLeaseEnabled = false + internal var lastFaceclawWakeLeaseQueuedAtMs = 0L + internal var faceclawWakeControlGeneration = 0 + internal var faceclawWakeControlSentCount = 0 + internal var lastFaceclawFramebufferLeaseQueuedAtMs = 0L + internal var faceclawFramebufferControlGeneration = 0 + internal var faceclawFramebufferControlSentCount = 0 + internal var faceclawWakePendingNonce = -1 + /** + * The last firmware-info read said the glasses run Faceclaw's custom + * firmware. Gates the private modes (cleanup, resource cache, ...) so stock + * or third-party firmware never sees them; the TS side checks the actual + * revision and disconnects on a mismatch, so no per-feature gating is + * needed here. + */ + internal var customFirmwareDetected = false + internal var cfwCleanupDelivered = false + internal var lastCfwCleanupAckMagic = 0 + + internal var reconnectAfterMs = 0L + internal var ringReconnectAfterMs = 0L + internal var lastAckAtMs = 0L + internal var lastIncomingAtMs = 0L + internal var lastHeartbeatSentAtMs = 0L + internal var lastHeartbeatAckedAtMs = 0L + internal var lastConnectionOrInputAtMs = 0L + internal var lastBatteryRefreshAtMs = 0L + internal var imageRetryAfterMs = 0L + internal var lastSessionReadyAtMs = 0L + internal var lastEvenAppConflictAtMs = 0L + internal var consecutiveAckTimeouts = 0 + internal var lastAudioControlAckMagic = 0 + + internal val connectionOptions = ConnectionOptions() + internal val magicPool = BleMagicPool(platform) + internal val messageBuilder = MessageBuilder(magicPool) + internal var nextTransportSeq = 0x40 + internal var nextMapSessionIdValue = 0 + internal var nextImageUpdateId = 1 + // Wire frame id for mode-3 deltas (CFW reorder/skip/dup diagnostic). uint16, + // advanced by 1 per emitted delta; kept in [1, 0xfffe] to avoid the CFW's + // 0xffff "empty" sentinel. + internal var nextImageFrameId = 1 + internal var lastShutdownAckMagic = 0 + internal var lastShutdownExitAtMs = 0L + internal var headsetBattery = -1 + internal var headsetCharging = -1 + internal var ringBattery = -1 + internal var ringCharging = -1 + // Silent mode: 1 = on, 0 = off, -1 = not yet known. See updateSilentModeLocked. + internal var silentMode = -1 + internal var wearState = -1 + internal var phoneLockState = -1 + internal var lastPhoneLockCheckAtMs = 0L + internal var audioCaptureActive = false + internal var firmwareInfoQueried = false + // Glasses are in the charging case: nobody is wearing them, so display + // communication pauses and only battery polls flow (see driveSession). + internal var chargingMode = false + @Volatile internal var audioPacketListener: FaceclawAudioPacketListener? = null + + // BLE bandwidth benchmark (Developer app). Streams no-op image payloads + // (CFW mode 7 with an unused sub-op: parsed, acked, and discarded — stock + // firmware likewise ignores unknown image modes) for a fixed duration with + // a selectable message size and pipeline window, then reports throughput. + // While active, desired-frame sends are held back and heartbeats are + // satisfied by the benchmark's own acks, so the stream is the only image + // traffic. All state below is guarded by `monitor`; results are read with + // getBandwidthBenchmarkStatus() and survive until the next run starts. + internal var benchmarkActive = false + internal var benchmarkAborted = false + internal var benchmarkMessageSize = 0 + internal var benchmarkWindowSize = 0 + internal var benchmarkDurationMs = 0 + internal var benchmarkLinkMode = 0 + internal var benchmarkLinkPending = false + internal var benchmarkReadyAtMs = 0L + internal var benchmarkStartAtMs = 0L // first benchmark write; 0 until then + internal var benchmarkDeadlineAtMs = 0L // start + duration; MAX_VALUE until first write + internal var benchmarkLastAckAtMs = 0L + internal var benchmarkEndAtMs = 0L // 0 while running; set when the run drains + internal var benchmarkMessagesSent = 0 + internal var benchmarkMessagesAcked = 0 + internal var benchmarkTimeouts = 0 + internal var benchmarkPayloadBytesAcked = 0L + internal var benchmarkWireBytesAcked = 0L + + internal var displayedFingerprint = "" + // The frame the firmware shadow will hold once the current image pipeline + // drains: the most recently ENQUEUED image (headerless packed 4bpp, see + // BmpUtil.pack4bppFromGray8), which is the correct base for the next delta + // when frames are pipelined. Set at enqueue; cleared whenever the image + // pipeline is cleared (clearAllMessagesLocked / clearMessagesOfKindLocked + // "image"), so it is only ever read while it holds a valid current-session base. + internal var lastEnqueuedPacked: ByteArray = ByteArray(0) + internal var lastEnqueuedWidth = 0 + internal var lastEnqueuedHeight = 0 + internal var lastEnqueuedFingerprint = "" + internal val imageUpdateStats: MutableMap = HashMap() + + internal val desiredTilesLock: ProtocolLock = platform.createLock() + internal var desiredFingerprint = "" + // Headerless packed 4bpp frame (see BmpUtil.pack4bppFromGray8) plus its + // pixel dimensions. + internal var desiredPacked: ByteArray? = ByteArray(0) + internal var desiredWidth = 0 + internal var desiredHeight = 0 + internal var desiredPaintMs = 0 + internal var desiredFrameId = 0 + // Screen-space deferred draws (glyphs + images) whose pixels are baked + // into desiredPacked; the resource-cache planner may replay them as + // on-glasses cached draws. + internal var desiredDraws: Array? = arrayOf() + // (frame, reason) of the last "waiting to send" line, so a frame that + // stalls for seconds records one line per state change (see + // noteImageStallLocked). Send-loop thread only. + internal var stallFrameId = 0 + internal var stallReason = "" + // Highest compositor sequence stored as the desired frame; composites that + // lost a store race to a newer one are discarded (their content is already + // included in the newer composite). + internal var lastStoredCompositeSeq = 0L + + // Wire submissions need screenGray + the shell scene, never preview pixels. + // Preview/screenshot/recording callers render those explicitly on demand. + internal val compositor = SurfaceCompositor(false) + + // Phone-side model of the CFW's 192 KiB resource cache. + // Reset whenever the image pipeline / EvenHub session is torn down: the + // firmware frees the cache with the fb lease, and after any resync the + // cheap safe assumption is an empty cache (glyphs re-upload lazily). + internal val resourceCache = ResourceCacheState() + internal val scenePlanner = ScenePlanner(resourceCache) + internal var desiredShellScene: ShellScene = ShellScene.EMPTY + + internal val pendingMessages = ArrayDeque() + internal val cfwTransports = arrayOf(CfwTransport(platform), CfwTransport(platform)) + internal val inFlightMessages = ArrayDeque() + internal var prewrittenMessage: OutboundMessage? = null + internal var prewrittenFrames: List = emptyList() + + internal fun now(): Long = platform.elapsedRealtimeMs() + + internal fun logLine(line: String) = host.log(SessionLogLevel.INFO, TAG, line, null) + + internal fun logDebug(line: String) = host.log(SessionLogLevel.DEBUG, TAG, line, null) + + internal fun logWarn(line: String, error: Throwable? = null) = host.log(SessionLogLevel.WARN, TAG, line, error) + + internal fun logError(line: String) = host.log(SessionLogLevel.ERROR, TAG, line, null) + + // --------------------------------------------------------------------- + // Lifecycle + + fun setListener(listener: FaceclawBleCommunicatorListener?) { + this.listener = listener + emitState() + emitPhoneLockStateIfChanged(true) + } + + /** Start the worker (through the host); false when it was already running. */ + fun start(): Boolean { + monitor.withLock { + if (running) { + return false + } + running = true + userDisconnectRequested = false + reconnectHalted = false + shutdownRequested = false + host.startWorker { run() } + return true + } + } + + fun disconnect() { + /* On the normal path DashboardController already sent mode 11 after + * quiescing its producers. Also cover direct/early close callers here; + * a successful cleanup must remain the final BLE message. Older CFWs + * fall back to the standalone framebuffer-lease release. */ + if (!cfwCleanupDelivered && !sendCfwCleanup()) { + releaseFaceclawFramebufferLease() + } + monitor.withLock { + userDisconnectRequested = true + running = false + audioCaptureActive = false + audioPacketListener = null + } + setStateDisplay("disconnecting", "Disconnecting...") + interruptibleSleep.interrupt() + host.joinWorker(5_000) + monitor.withLock { + resetSessionStateLocked() + clearAllMessagesLocked("disconnect") + // Unknown until the next connection's first push or settings poll. + silentMode = -1 + } + link.disconnect(rightAddress) + link.disconnect(leftAddress) + if (hasRingAddress()) { + link.disconnect(ringAddress) + } + link.close() + host.setScreenWakeLock(false) + setStateDisplay("disconnected", "Disconnected.") + } + + fun close() { + disconnect() + for (transport in cfwTransports) transport.close() + } + + /** The platform's screen-on/off/user-present signal: refresh the lock state and wake the worker. */ + fun onPhoneLockSignal() { + emitPhoneLockStateIfChanged(true) + interruptibleSleep.interrupt() + } + + fun setG2ScreenOn(screenOn: Boolean) { + host.postToMain { host.setScreenWakeLock(screenOn) } + } + + fun setFirmwareDebugFlags(enabled: Boolean) { + // Just record it; the drive loop emits the mode-7 control message when the + // display path is ready and idle, and re-emits when this value changes. + firmwareDebugFlagsEnabled = enabled + } + + fun startG2AudioCapture(listener: FaceclawAudioPacketListener?): Boolean { + if (listener == null) { + throw IllegalArgumentException("listener is required") + } + var magic = 0 + monitor.withLock { + if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { + logLine("skip G2 mic enable; EvenHub display path not ready") + return false + } + audioPacketListener = listener + val message = createAudioControlMessageLocked(true) + magic = message.magic + pendingMessages.addFirst(message) + logLine("queue G2 mic enable") + } + interruptibleSleep.interrupt() + return waitForAudioControlAck(magic, "enable") + } + + fun stopG2AudioCapture() { + var magic = 0 + monitor.withLock { + audioPacketListener = null + audioCaptureActive = false + clearMessagesOfKindLocked("audio-control") + if (running && sessionReady) { + val message = createAudioControlMessageLocked(false) + magic = message.magic + pendingMessages.addFirst(message) + logLine("queue G2 mic disable") + } + } + interruptibleSleep.interrupt() + if (magic != 0) { + waitForAudioControlAck(magic, "disable") + } + } + + fun isSessionReady(): Boolean { + monitor.withLock { + return running && sessionReady + } + } + + /** + * Whether the glasses mic is enabled right now. The enable lives in the + * current EvenHub session, so it dies with a transport drop, the charging + * case, or a suspend — silently, from the phone's point of view. Callers + * that track a capture across those events must check this rather than + * assume their earlier enable still holds. + */ + fun isAudioCaptureActive(): Boolean { + monitor.withLock { + return running && sessionReady && !shutdownRequested && audioCaptureActive + } + } + + /** + * Acquire/renew or release CFW's volatile wake-takeover lease on both + * arms. Delivery (not a protocol ACK) is awaited so a caller can ensure + * the fail-open firmware policy is installed before relying on wakeword + * interception or suspending EvenHub. + */ + fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean { + val generation: Int + monitor.withLock { + faceclawWakeLeaseEnabled = enabled + if (!running || !sessionReady) { + return !enabled + } + generation = enqueueFaceclawWakeControlLocked( + if (enabled) BleProtocol.FACECLAW_WAKE_OP_ACQUIRE else BleProtocol.FACECLAW_WAKE_OP_RELEASE, + 0, + true + ) + if (!enabled) { + faceclawWakePendingNonce = -1 + } + } + interruptibleSleep.interrupt() + return waitForFaceclawWakeControlDelivery(generation, FACECLAW_WAKE_CONTROL_WAIT_MS) + } + + /** + * Wait until the recreated layout and retained compositor frame have both + * landed. If this wake came from CFW's deferred double tap, READY + * is then sent to both arms to cancel their stock-dashboard fallback. + */ + fun awaitEvenHubSessionReady(timeoutMs: Int): Boolean { + val deadline = now() + maxOf(0, timeoutMs) + var readyGeneration = 0 + monitor.withLock { + while (running && sessionReady) { + var frameReady = false + desiredTilesLock.locked { + frameReady = desiredFingerprint.isNotEmpty() + && desiredFingerprint == displayedFingerprint + } + if (!shutdownRequested && fixedLayoutCreated && frameReady) { + if (faceclawWakePendingNonce >= 0) { + readyGeneration = enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_READY, + faceclawWakePendingNonce, + true + ) + faceclawWakePendingNonce = -1 + } + break + } + val remaining = deadline - now() + if (remaining <= 0) { + return false + } + monitor.awaitMs(minOf(remaining, 100L)) + } + if (!running || !sessionReady) { + return false + } + } + if (readyGeneration != 0) { + interruptibleSleep.interrupt() + if (!waitForFaceclawWakeControlDelivery(readyGeneration, FACECLAW_WAKE_CONTROL_WAIT_MS)) { + logLine("wake READY delivery not confirmed before fallback deadline") + } + } + return true + } + + /** + * Enable or disable the IMU (accelerometer) report stream. Fire-and-forget: + * the control message is queued ahead of other traffic; readings arrive via + * registered FaceclawImuListeners. reportFrq is the requested sample rate + * (ignored on disable). + */ + fun setImuReportEnabled(enable: Boolean, reportFrq: Int) { + monitor.withLock { + if (!running || !sessionReady) { + logLine("skip IMU " + (if (enable) "enable" else "disable") + "; session not ready") + return + } + clearMessagesOfKindLocked("imu-control") + val message = messageBuilder.enableOrDisableImu(enable, reportFrq) + message.onTimeout = MessageCallback { logLine("IMU control ack timeout") } + pendingMessages.addFirst(message) + logLine("queue IMU " + (if (enable) "enable freq=$reportFrq" else "disable")) + } + interruptibleSleep.interrupt() + } + + /** + * Enable/disable the stock compass through CFW image-handler mode 10. The + * desired state is retained across reconnects; headings arrive through + * stock sid-0x08 navigation notifications and FaceclawCompassListeners. + */ + fun setCompassEnabled(enable: Boolean) { + setCompassEnabled("compass", enable) + } + + /** + * As above, on behalf of a named owner. The compass runs while at least + * one owner has enabled it; an owner disabling it only takes effect once + * no other owner still wants it. + */ + fun setCompassEnabled(owner: String?, enable: Boolean) { + monitor.withLock { + val before = compassOwners.isNotEmpty() + if (enable) { + compassOwners.add(owner) + } else { + compassOwners.remove(owner) + } + val wanted = compassOwners.isNotEmpty() + if (wanted == before && compassControlLastSent == (if (wanted) 1 else 0)) { + logLine("compass " + (if (enable) "enable" else "disable") + " by " + owner + + "; state unchanged (owners=" + compassOwners + ")") + return + } + compassControlLastSent = -1 + clearMessagesOfKindLocked("compass-control") + if (running && sessionReady && !shutdownRequested && fixedLayoutCreated) { + enqueueCompassControlLocked(true, wanted) + } else { + logLine("defer compass " + (if (enable) "enable" else "disable") + "; display path not ready") + } + } + interruptibleSleep.interrupt() + } + + /** + * Set the lens brightness. Fire-and-forget, like the IMU control: the + * message is queued ahead of other traffic and any not-yet-sent brightness + * message is superseded. When autoAdjust is true the ambient-light sensor + * drives brightness and brightnessLevel is ignored; otherwise + * brightnessLevel (0-100) is applied directly. + */ + fun setBrightness(autoAdjust: Boolean, brightnessLevel: Int) { + monitor.withLock { + if (!running || !sessionReady) { + logLine("skip brightness set; session not ready") + return + } + clearMessagesOfKindLocked("brightness-control") + val message = messageBuilder.setBrightness(autoAdjust, brightnessLevel) + message.onTimeout = MessageCallback { logLine("brightness control ack timeout") } + pendingMessages.addFirst(message) + logLine("queue brightness " + (if (autoAdjust) "auto" else "level=$brightnessLevel")) + } + interruptibleSleep.interrupt() + } + + /** + * Enable the stock wear detector, then ask CFW to emit its current cached + * state. The queue order matters: the query must run after the setting is + * applied, including on a fresh install where wear detection was disabled. + */ + fun enableWearDetectionAndRequestState() { + monitor.withLock { + if (!running || !sessionReady) { + logLine("skip wear detector setup; session not ready") + return + } + clearMessagesOfKindLocked("wear-detection-control") + clearMessagesOfKindLocked("wear-query-control") + val queryLeft = messageBuilder.faceclawWearQuery(true) + val queryRight = messageBuilder.faceclawWearQuery(false) + val enable = messageBuilder.setWearDetection(true) + enable.onTimeout = MessageCallback { logLine("wear detection enable ack timeout") } + pendingMessages.addFirst(queryLeft) + pendingMessages.addFirst(queryRight) + pendingMessages.addFirst(enable) + logLine("queue wear detection enable + current-state query") + } + interruptibleSleep.interrupt() + } + + // --------------------------------------------------------------------- + // Bandwidth benchmark + + /** + * Start the BLE bandwidth benchmark: stream messageSize-byte no-op image + * payloads for durationMs, keeping up to windowSize messages awaiting ack + * at once, then leave the results for getBandwidthBenchmarkStatus(). + * Returns false when a run is already active or the image path is not + * ready. The duration clock starts at the first benchmark write, so + * traffic already queued ahead of the run doesn't count against it. + */ + fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean { + return startBandwidthBenchmarkWithLinkMode(messageSize, windowSize, durationMs, 0) + } + + // 0: current link; 1: re-request HIGH; 2: request 2M; 3: both. + fun startBandwidthBenchmarkWithLinkMode(messageSize: Int, windowSize: Int, + durationMs: Int, linkMode: Int): Boolean { + monitor.withLock { + if (benchmarkActive || !running || !sessionReady || !fixedLayoutCreated + || shutdownRequested || chargingMode) { + logLine("skip bandwidth benchmark; already running or image path not ready") + return false + } + benchmarkMessageSize = maxOf(2, minOf(messageSize, ConnectionOptions.IMAGE_FRAGMENT_SIZE)) + benchmarkWindowSize = maxOf(1, minOf(windowSize, BENCHMARK_MAX_WINDOW)) + benchmarkDurationMs = maxOf(1_000, durationMs) + benchmarkLinkMode = linkMode and 3 + benchmarkLinkPending = true + benchmarkReadyAtMs = Long.MAX_VALUE + benchmarkStartAtMs = 0 + benchmarkDeadlineAtMs = Long.MAX_VALUE + benchmarkLastAckAtMs = 0 + benchmarkEndAtMs = 0 + benchmarkMessagesSent = 0 + benchmarkMessagesAcked = 0 + benchmarkTimeouts = 0 + benchmarkPayloadBytesAcked = 0 + benchmarkWireBytesAcked = 0 + benchmarkAborted = false + benchmarkActive = true + logLine("bandwidth benchmark start: size=" + benchmarkMessageSize + + "B window=" + benchmarkWindowSize + " duration=" + benchmarkDurationMs + + "ms linkMode=" + benchmarkLinkMode) + } + interruptibleSleep.interrupt() + return true + } + + /** + * Cancel an in-progress benchmark (benchmark page closed). Queued no-op + * messages are dropped; in-flight ones drain through their normal acks. + */ + fun cancelBandwidthBenchmark() { + monitor.withLock { + if (!benchmarkActive) { + return + } + clearMessagesOfKindLocked("bandwidth") + finishBenchmarkLocked(true, "cancelled") + } + interruptibleSleep.interrupt() + } + + /** Status/results of the current or most recent benchmark run, as JSON. */ + fun getBandwidthBenchmarkStatus(): String { + monitor.withLock { + val state = if (benchmarkActive) + (if (benchmarkStartAtMs == 0L) "starting" else "running") + else + (if (benchmarkEndAtMs != 0L) "done" else "idle") + val end = if (benchmarkActive) now() else benchmarkEndAtMs + val elapsed = if (benchmarkStartAtMs == 0L) 0L else maxOf(0L, end - benchmarkStartAtMs) + try { + val status = linkedMapOf() + status["state"] = state + status["messageSize"] = benchmarkMessageSize + status["windowSize"] = benchmarkWindowSize + status["linkMode"] = benchmarkLinkMode + status["elapsedMs"] = elapsed + status["messagesSent"] = benchmarkMessagesSent + status["messagesAcked"] = benchmarkMessagesAcked + status["timeouts"] = benchmarkTimeouts + status["payloadBytesAcked"] = benchmarkPayloadBytesAcked + status["wireBytesAcked"] = benchmarkWireBytesAcked + status["aborted"] = benchmarkAborted + return Json.write(status) + } catch (e: Exception) { + return "{\"state\":\"idle\"}" + } + } + } + + // --------------------------------------------------------------------- + // Sensor and status listeners + + fun addImuListener(listener: FaceclawImuListener?) { + if (listener != null) { + imuListeners.add(listener) + } + } + + fun removeImuListener(listener: FaceclawImuListener?) { + if (listener != null) { + imuListeners.remove(listener) + } + } + + fun addAmbientLightListener(listener: FaceclawAmbientLightListener?) { + if (listener != null) { + ambientLightListeners.add(listener) + } + } + + fun removeAmbientLightListener(listener: FaceclawAmbientLightListener?) { + if (listener != null) { + ambientLightListeners.remove(listener) + } + } + + /** Request one CFW ambient-light report (image-handler mode 16 op 0). */ + fun queryAmbientLight() { + monitor.withLock { + enqueueAmbientLightControlLocked(byteArrayOf(CFW_MSG_AMBIENT_LIGHT.toByte(), 0.toByte()), "als query", false) + } + interruptibleSleep.interrupt() + } + + /** + * Start or stop CFW passive light-sensor polling (image-handler mode 16 + * ops 1/2). While polling, the firmware reads its OPT3001 every intervalMs + * (clamped 100..5000 by the firmware), never steps the panel brightness + * itself, and pushes a field-105 report when the reading moved by at least + * minDelta or heartbeatMs elapsed. bindToLease stops polling automatically + * when the Faceclaw framebuffer lease is released or lapses. Starting is + * idempotent and re-opens the sensor if the stock firmware closed it. + */ + fun setAmbientLightPolling(enable: Boolean, intervalMs: Int, minDelta: Int, + heartbeatMs: Int, bindToLease: Boolean) { + val payload = if (enable) + byteArrayOf( + CFW_MSG_AMBIENT_LIGHT.toByte(), + 1.toByte(), + (if (bindToLease) 1 else 0).toByte(), + (intervalMs and 0xff).toByte(), + ((intervalMs shr 8) and 0xff).toByte(), + (minDelta and 0xff).toByte(), + ((minDelta shr 8) and 0xff).toByte(), + (heartbeatMs and 0xff).toByte(), + ((heartbeatMs shr 8) and 0xff).toByte(), + ) + else + byteArrayOf(CFW_MSG_AMBIENT_LIGHT.toByte(), 2.toByte()) + monitor.withLock { + clearMessagesOfKindLocked("als-control") + enqueueAmbientLightControlLocked(payload, "als polling " + (if (enable) "start" else "stop"), true) + } + interruptibleSleep.interrupt() + } + + fun addMicStatusListener(listener: FaceclawMicStatusListener?) { + if (listener != null) { + micStatusListeners.add(listener) + } + } + + fun removeMicStatusListener(listener: FaceclawMicStatusListener?) { + if (listener != null) { + micStatusListeners.remove(listener) + } + } + + /** + * Queue a CFW mic_control record (['M','C',ver,op,...]) as a settings + * field-103 write to both temples, or to a single one. Fire-and-forget: + * the firmware answers with a field-104 status notify per temple, which + * arrives through addMicStatusListener. + */ + fun sendFaceclawMicControl(record: ByteArray?, label: String, rightTemple: Boolean, leftTemple: Boolean) { + if (record == null || record.size < 4) { + return + } + monitor.withLock { + if (!running || !sessionReady) { + logLine("skip mic control ($label); session not ready") + return + } + if (rightTemple) { + pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, false)) + } + if (leftTemple) { + pendingMessages.addLast(messageBuilder.faceclawMicControl(record, label, true)) + } + logLine("queue mic control $label") + } + interruptibleSleep.interrupt() + } + + /** + * Forward render-characteristic audio packets to the listener WITHOUT + * sending the stock EvenHub audio-control enable. Used for the CFW + * mic_control streaming path, where capture is armed through settings + * field 103 and the temples emit 'SM' frames on the same characteristic + * that stock mono LC3 uses. Returns false when no session is up. + */ + fun startG2AudioForwarding(listener: FaceclawAudioPacketListener?): Boolean { + if (listener == null) { + throw IllegalArgumentException("listener is required") + } + monitor.withLock { + if (!running || !sessionReady || shutdownRequested) { + logLine("skip G2 audio forwarding; session not ready") + return false + } + audioPacketListener = listener + audioCaptureActive = true + logLine("G2 audio forwarding enabled") + } + return true + } + + fun stopG2AudioForwarding() { + monitor.withLock { + audioPacketListener = null + audioCaptureActive = false + logLine("G2 audio forwarding disabled") + } + } + + /** + * Subscribe to compass events. Callbacks are delivered on the dispatcher of + * the thread that registered (falling back to the main thread), so app + * worker isolates can listen without a cross-thread hop into their JS. + */ + fun addCompassListener(listener: FaceclawCompassListener?) { + if (listener == null) { + return + } + compassSubscriptions.add(CompassSubscription(listener, host.currentThreadDispatcher())) + } + + fun removeCompassListener(listener: FaceclawCompassListener?) { + if (listener == null) { + return + } + for (subscription in compassSubscriptions) { + if (subscription.listener === listener) { + compassSubscriptions.remove(subscription) + } + } + } + + // --------------------------------------------------------------------- + // Compositor entry points (pixels arrive as ByteReaders; the platform + // adapter wraps its native buffers without copying) + + /** Set the compositor's output frame size. Call before configuring surfaces. */ + fun configureCompositorScreen(width: Int, height: Int) { + compositor.configureScreen(width, height) + } + + /** The current composite for previews/screenshots, or null before any surface exists. */ + fun previewComposite(): SurfaceCompositor.Composite? = compositor.previewComposite() + + /** + * Show or hide a compositor surface, immediately submitting the resulting + * frame. Recompositing here (rather than waiting for the next surface + * update) is what makes a just-foregrounded window's retained frame + * actually appear — otherwise a static window (e.g. the terminal hub) whose + * frame landed while briefly hidden would stay blank until its next repaint. + */ + fun setSurfaceVisible(id: String, visible: Boolean) { + // Its own frame: this recomposite is a real screen update with real + // latency, and without one it would show up in other frames' logs only + // as an anonymous "superseded by frame#0". + val frameId = frameTimings.startFrame( + "compositor:visible $id=$visible") + compositor.setSurfaceVisible(id, visible) + val composite = compositor.composite() + val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) + storeDesiredComposite(composite, packed, 0, frameId) + } + + /** + * Blank (screen off) or unblank the composited output, immediately + * submitting the resulting frame. Retained surface state is untouched, so + * unblanking restores the previous screen content without repaints. + */ + fun setScreenBlanked(blanked: Boolean) { + val frameId = frameTimings.startFrame( + "compositor:" + (if (blanked) "blank" else "unblank")) + compositor.setBlanked(blanked) + val composite = compositor.composite() + val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) + storeDesiredComposite(composite, packed, 0, frameId) + } + + /** + * Create or reconfigure a compositor surface. transparency is one of the + * SurfaceCompositor.TRANSPARENCY_* constants. Geometry changes take effect + * when the next frame is submitted. + */ + fun configureSurface(id: String?, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) { + compositor.configureSurface(id, x, y, width, height, zOrder, transparency) + } + + fun removeSurface(id: String) { + compositor.removeSurface(id) + } + + /** Stage an immutable shell snapshot alongside the retained app screen. */ + fun submitShellScene(bytes: ByteReader, paintMs: Int, frameId: Int) { + compositor.setShellScene(bytes) + val composite = compositor.composite() + storeDesiredComposite(composite, BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height), paintMs, frameId) + } + + /** Legacy compositor dimming for callers without a shell scene. */ + fun setUnderlayDim(belowZOrder: Int, factor256: Int) { + compositor.setUnderlayDim(belowZOrder, factor256) + } + + /** + * Apply an update to one compositor surface and submit the recomposited + * screen as the desired frame. The update covers the rect (rectX, rectY, + * rectWidth, rectHeight) in surface-local coordinates; contentFingerprint + * identifies the surface's full content after the update. glyphs carries + * the frame's glyph draws (see SurfaceCompositor's glyph overload for the + * buffer format), or null when the submitter has no glyph metadata; the + * pixels alone remain fully correct. + */ + fun submitSurfaceFrame( + pixels8bpp: ByteReader, + surfaceId: String, + rectX: Int, + rectY: Int, + rectWidth: Int, + rectHeight: Int, + contentFingerprint: String?, + paintMs: Int, + frameId: Int, + glyphs: ByteReader? + ) { + logLine("Received an updated frame for surface $surfaceId") + frameTimings.log(frameId, "surface " + surfaceId + " updated rect=" + + rectWidth + "x" + rectHeight + "+" + rectX + "+" + rectY + + (if (glyphs == null) " (no glyph draws)" else "")) + frameTimings.spanStart(frameId, "composite") + val composite = compositor.applyAndComposite( + surfaceId, pixels8bpp, rectX, rectY, rectWidth, rectHeight, contentFingerprint, glyphs) + frameTimings.spanEnd(frameId, "composite") + // Pack the composited 8bpp buffer down to the headerless 4bpp frame + // format the wire planners consume; BMP framing is added later only for + // the uncompressed fallback. + frameTimings.spanStart(frameId, "pack-4bpp") + val packed = BmpUtil.pack4bppFromGray8(composite.screenGray, composite.width, composite.height) + frameTimings.spanEnd(frameId, "pack-4bpp") + storeDesiredComposite(composite, packed, paintMs, frameId) + } + + /** Store a composite as the desired frame unless a newer one won the race. */ + internal fun storeDesiredComposite(composite: SurfaceCompositor.Composite, packed: ByteArray, paintMs: Int, frameId: Int) { + var supersededFrameId = 0 + var stale = false + desiredTilesLock.locked { + if (composite.seq <= lastStoredCompositeSeq) { + // A concurrent submission composited after us and stored first; + // its composite already includes this surface update. + stale = true + } else { + lastStoredCompositeSeq = composite.seq + supersededFrameId = desiredFrameId + desiredPacked = packed + desiredWidth = composite.width + desiredHeight = composite.height + desiredFingerprint = composite.fingerprint + desiredPaintMs = paintMs + desiredFrameId = frameId + desiredDraws = composite.draws + desiredShellScene = composite.shellScene + } + } + if (stale) { + finishFrame(frameId, "discarded: composite superseded before store") + return + } + if (supersededFrameId != 0 && supersededFrameId != frameId) { + finishFrame(supersededFrameId, "discarded: superseded by frame#$frameId before send") + } + frameTimings.log(frameId, "image submitted as desired frame") + interruptibleSleep.interrupt() + } + + /** + * Play a tone sequence via CFW load_image_z mode 5 kind 4. The payload is + * the complete wire buffer ([5][4][nSteps][freqLo,freqHi,duty,msLo,msHi]*n, + * up to 48 steps), built on the TS side; it rides the arbitrary-payload + * image path like the other mode-5 controls. + */ + fun playBuzzerSequence(bytes: ByteArray?) { + monitor.withLock { + if (!running || !sessionReady || !fixedLayoutCreated) { + logLine("skip buzzer sequence; session not ready") + return + } + if (bytes == null || bytes.size < 3) { + logLine("skip buzzer sequence; empty payload") + return + } + val message = messageBuilder.imagePayload( + DASHBOARD_TILE, + nextMapSessionId(), + bytes, + "buzzer sequence " + bytes.size + "B", + connectionOptions.sendImagesToLeft + ) + message.onTimeout = MessageCallback { + handleTransportFailure("buzzer sequence ack timeout") + } + pendingMessages.addLast(message) + logLine("queue " + message.label) + } + interruptibleSleep.interrupt() + } + + // --------------------------------------------------------------------- + // EvenHub page lifecycle + + fun sendShutdown(exitMode: Int): Boolean { + return sendShutdownInternal(exitMode, true) + } + + /** + * Send CFW image-handler mode 11 after quiescing normal traffic. A successful + * return means the cleanup was ACKed and no later Faceclaw message should be + * emitted before closing BLE. Unsupported/older CFWs return false so callers + * can use the legacy shutdown-and-lease-release path. + */ + fun sendCfwCleanup(): Boolean { + val magic: Int + monitor.withLock { + if (cfwCleanupDelivered) { + return true + } + if (!customFirmwareDetected || !running || !sessionReady + || shutdownRequested || !fixedLayoutCreated) { + logLine("skip CFW cleanup; mode 11 unavailable or image path not ready") + return false + } + + /* Stop auto-renewals, heartbeats, image generation, and control + * retries, then discard everything that has not reached BLE yet. */ + shutdownRequested = true + lastCfwCleanupAckMagic = 0 + clearPendingMessagesLocked("CFW cleanup requested") + logLine("quiescing transport for CFW cleanup") + } + interruptibleSleep.interrupt() + + /* WINDOW_SIZE can exceed one, so merely appending cleanup would allow it + * to overlap previously-written image fragments. Wait until all of those + * ACK or time out; shutdownRequested prevents the drive loop from adding + * any fresh automatic traffic meanwhile. */ + val drainDeadline = now() + CFW_CLEANUP_WAIT_MS + monitor.withLock { + while (running && sessionReady && !inFlightMessages.isEmpty()) { + val remaining = drainDeadline - now() + if (remaining <= 0) break + monitor.awaitMs(minOf(remaining, 100L)) + } + if (!running || !sessionReady || !inFlightMessages.isEmpty()) { + shutdownRequested = false + logLine("CFW cleanup could not drain prior traffic") + return false + } + + /* External producers are expected to be stopped by the caller, but + * clear once more at the barrier so cleanup is definitely last. */ + clearPendingMessagesLocked("CFW cleanup barrier") + val message = messageBuilder.cfwCleanup( + DASHBOARD_TILE, + nextMapSessionId(), + connectionOptions.sendImagesToLeft + ) + magic = message.magic + message.onAck = MessageCallback { + lastCfwCleanupAckMagic = message.magic + cfwCleanupDelivered = true + compassMaybeOn = false + faceclawWakeLeaseEnabled = false + logLine("CFW cleanup completed") + } + message.onTimeout = MessageCallback { logLine("CFW cleanup ack timeout") } + pendingMessages.addLast(message) + logLine("queue CFW cleanup") + } + interruptibleSleep.interrupt() + + val deadline = now() + CFW_CLEANUP_WAIT_MS + monitor.withLock { + while (running + && sessionReady + && lastCfwCleanupAckMagic != magic + && hasPendingOrInflightMagicLocked(magic)) { + val remaining = deadline - now() + if (remaining <= 0) break + monitor.awaitMs(minOf(remaining, 100L)) + } + val acked = lastCfwCleanupAckMagic == magic + if (!acked) shutdownRequested = false + return acked + } + } + + /** + * End the EvenHub page while retaining both arm GATT connections and all + * notification subscriptions. A missed ACK is intentionally non-fatal: + * reconnecting Bluetooth here would defeat the power-saving mode. + */ + fun suspendEvenHubSession(): Boolean { + // Ending the plugin task releases the fb lease, which frees the + // on-glasses resource cache; forget it phone-side either way (a lost + // ack may still have taken effect). + monitor.withLock { + resourceCache.reset() + } + if (sendShutdownInternal(0, false)) { + return true + } + monitor.withLock { + // A shutdown ACK can be lost even though the command took effect. + // If the transport remains intentionally quiesced, callers still + // need to remember to run the resume path on the next wake. + return running && sessionReady && shutdownRequested + } + } + + /** + * Start a fresh EvenHub plugin task on the existing BLE transport, then let + * the session driver create the layout, warm up the image path, and send + * the desired frame. + */ + fun resumeEvenHubSession(): Boolean { + var claimGeneration = 0 + monitor.withLock { + if (!running || !sessionReady || chargingMode) { + logLine("skip EvenHub resume; transport not ready") + return false + } + if (!shutdownRequested) { + return true + } + if (faceclawWakePendingNonce >= 0 + && hasPendingOrInflightKindLocked("wake-lease-control")) { + claimGeneration = faceclawWakeControlGeneration + } + logLine("replaying session prelude for EvenHub resume") + } + + // A custom double-tap wake has only a short unclaimed fail-open + // deadline. Let the worker put CLAIM on both arms before the direct + // prelude write begins. + if (claimGeneration != 0) { + waitForFaceclawWakeControlDelivery(claimGeneration, 500) + } + + try { + // Empty-name Cmd=9 tears down the whole plugin task, not just its + // image container. Re-run the launch prelude before Cmd=0 CREATE. + sendPrelude(true) + } catch (t: Throwable) { + logLine("EvenHub resume prelude failed: " + safeMessage(t)) + handleTransportFailure("EvenHub resume prelude failed") + return false + } + + monitor.withLock { + if (!running || !sessionReady || chargingMode) { + return false + } + shutdownRequested = false + fixedLayoutCreated = false + startupProbePending = false + audioCaptureActive = false + clearAllMessagesPreservingWakeLeaseLocked("EvenHub resume") + displayedFingerprint = "" + imageRetryAfterMs = 0 + lastHeartbeatSentAtMs = 0 + lastHeartbeatAckedAtMs = 0 + logLine("EvenHub session resume requested") + } + interruptibleSleep.interrupt() + return true + } + + // --------------------------------------------------------------------- + // Worker loop and inbound traffic + + /** The worker loop; runs on the thread the host started from [start]. */ + fun run() { + logLine("communicator start R=$rightAddress L=$leftAddress ring=$ringAddress") + while (true) { + try { + if (!running) { + logWarn("Exiting event looop") + break + } + emitPhoneLockStateIfChanged(false) + if (!sessionReady) { + if (reconnectHalted) { + interruptibleSleep.sleep(ConnectionOptions.IDLE_SLEEP_MS.toLong()) + continue + } + val now = now() + if (now < reconnectAfterMs) { + interruptibleSleep.sleep(minOf(ConnectionOptions.IDLE_SLEEP_MS.toLong(), reconnectAfterMs - now)) + continue + } + logWarn("Attempting to connect") + connectLoopOnce() + continue + } + + if (shouldAttemptRingConnect()) { + tryConnectRing("retry") + continue + } + + val sleepMs = driveSession() + if (sleepMs > 0) { + interruptibleSleep.sleep(sleepMs) + } + } catch (t: Throwable) { + if (!running) { + // The host interrupted the worker to stop it (JVM thread + // interrupt surfacing from a wait); nothing to recover. + logLine("communicator loop interrupted while stopping: " + (t.message ?: t.toString())) + break + } + logLine("communicator loop error: " + safeMessage(t)) + handleTransportFailure("loop error") + } + } + logLine("communicator stop") + } + + override fun onNotification(address: String?, characteristicUuid: String?, data: ByteArray?) { + if (address == null || characteristicUuid == null || data == null) { + return + } + val uuid = characteristicUuid.lowercase() + if (isDirectRingNotification(address, uuid)) { + handleDirectRingNotification(uuid, data) + return + } + if (BleProtocol.RENDER_NOTIFY_UUID == uuid) { + handleRenderNotification(address, data) + return + } + if (BleProtocol.NOTIFY_CHAR_UUID != uuid) { + return + } + if (data.size >= 7 && (data[6].toInt() and 255) == CfwTransport.SID) { + val acks = CfwTransport.parseAcks(data) ?: return + monitor.withLock { + lastIncomingAtMs = now() + for (ack in acks) { + for (message in inFlightMessages) { + val ingress = if (message.isLeftArmMessage) leftAddress else rightAddress + if (message.sid == CfwTransport.SID && address.equals(ingress, ignoreCase = true) && message.magic == ack.streamId) { + message.acceptCfwAck(ack) + logLine("CFW " + (if (ack.nack) "NACK" else "ACK") + " id=" + ack.streamId + + " ordinal=" + ack.messageId + " lens=" + ack.lens + " txseq=" + (data[2].toInt() and 255) + + " redundant=" + (ack !== acks[0]) + + " size=" + ack.size + " crc=" + ack.checksum + + " expected=" + message.message.size + "/" + message.cfwChecksum + + " ackedLenses=" + message.cfwAckLenses + + " ageMs=" + (lastIncomingAtMs - message.sentAtMs)) + message.ackPayload = data.copyOf() + break + } + } + } + drainCfwAcknowledgementsLocked() + } + interruptibleSleep.interrupt() + return + } + logDebug("onNotification: address=" + address + " characteristicUuid=" + characteristicUuid + " data.length=" + data.size) + val frame = BleProtocol.parseFrame(data) + val decodedWearState = BleProtocol.parseWearState(frame) + val compassEvent = if (address.equals(rightAddress, ignoreCase = true)) + BleProtocol.parseCompassEvent(frame) + else + null + var emitWearState = false + var event: G2Event? = null + monitor.withLock { + lastIncomingAtMs = now() + if (decodedWearState >= 0 && decodedWearState != wearState) { + wearState = decodedWearState + emitWearState = true + } + var faceclawWakeNotification = false + if (shutdownRequested + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING + && address.equals(rightAddress, ignoreCase = true)) { + val wakeNonce = BleProtocol.parseFaceclawWakeEvent(frame.pb) + if (wakeNonce >= 0) { + faceclawWakePendingNonce = wakeNonce + enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_CLAIM, + wakeNonce, + true + ) + faceclawWakeNotification = true + lastConnectionOrInputAtMs = lastIncomingAtMs + // The event type says which gesture woke the glasses: TS + // gives a head-up the Glanceboard and a double tap the + // regular UI. The claim handshake is the same for both. + val headUp = BleProtocol.parseFaceclawWakeEventCode(frame.pb) == + BleProtocol.FACECLAW_WAKE_EVENT_HEAD_UP + event = G2Event( + "display-wake", + "", + if (headUp) BleProtocol.EVENT_HEAD_UP else BleProtocol.EVENT_DOUBLE_CLICK, + 0, + 0 + ) + logLine("claimed deferred dashboard wake nonce=" + wakeNonce + + (if (headUp) " (head-up)" else "")) + } + } + if (!faceclawWakeNotification + && shutdownRequested + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING + && address.equals(rightAddress, ignoreCase = true)) { + // CFW idle-gesture forwarding (firmware revision 2+): with no + // EvenHub page the stock display thread drops taps, long + // presses and releases; the CFW reports them on the settings + // sid while our wake lease is held. Deliver them as the + // sys-events a live page would have produced, so TS treats a + // sleep-time tap or hold exactly like one during soft sleep + // (the Glanceboard). + val gesture = BleProtocol.parseFaceclawGestureEvent(frame.pb) + if (gesture != null) { + lastConnectionOrInputAtMs = lastIncomingAtMs + event = G2Event("sys-event", "", gesture.eventType, gesture.eventSource, 0) + logLine("idle gesture forwarded by CFW: type=" + gesture.eventType + + " source=" + gesture.eventSource) + } + } + if (!faceclawWakeNotification + && event == null + && shutdownRequested + && address.equals(rightAddress, ignoreCase = true) + && BleProtocol.isDisplayWakeStateChange(frame)) { + // With no EvenHub page, ring/arm double-taps are handled by the + // stock display lifecycle and surface only as this state ping. + // Translate it back into an input event so TS can wake the shell + // and recreate the page. + event = G2Event( + "display-wake", + "", + BleProtocol.EVENT_DOUBLE_CLICK, + 0, + 0 + ) + } + if (!faceclawWakeNotification + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING) { + // Mode-17 query notifications; settings READs are handled by + // createBatteryQueryMessageLocked so headset/ring update together. + if (address.equals(rightAddress, ignoreCase = true) + && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { + val ring = BleProtocol.parseRingBattery(frame.pb) + if (ring != null) { + ringBattery = ring.battery + ringCharging = ring.charging + emitBatteryState(headsetBattery, headsetCharging) + } + } + // CFW mic status (field 104) rides both standalone pushes and + // settings read acks, from each temple on its own link. + val micStatus = BleProtocol.parseFaceclawMicStatus(frame.pb) + if (micStatus != null) { + emitMicStatus(micStatus, address) + } + } + if (!faceclawWakeNotification + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING) { + // CFW ambient-light report (field 105) from the master temple. + val alsReport = BleProtocol.parseFaceclawAlsReport(frame.pb) + if (alsReport != null) { + emitAmbientLight(alsReport) + } + } + if (!faceclawWakeNotification + && decodedWearState < 0 + && frame.ok + && frame.sid == BleProtocol.SID_UI_SETTING) { + // Device-initiated settings push. It carries a magic the glasses + // chose, so it would otherwise fall through to resolveAckLocked, + // match nothing, and be logged as an unexpected ack. + val pushedSilentMode = BleProtocol.parseSilentModePush(frame.pb) + if (pushedSilentMode >= 0) { + updateSilentModeLocked(pushedSilentMode > 0) + return + } + } + if (!faceclawWakeNotification + && decodedWearState < 0 + && frame.ok + && frame.msgSeq >= 0 + && frame.flag != BleProtocol.FLAG_NOTIFY + && frame.flag != BleProtocol.FLAG_NOTIFY_ALT) { + lastAckAtMs = lastIncomingAtMs + resolveAckLocked(frame.sid, frame.msgSeq, frame.pb) + } + if (!faceclawWakeNotification + && event == null + && frame.ok + && address.equals(rightAddress, ignoreCase = true) + && (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) { + var decoded = G2Event.decode(frame) + if (decoded != null + && "sys-event" == decoded.kind + && decoded.eventType == BleProtocol.EVENT_HEAD_UP) { + // CFW forwards the IMU head-up while our page is on screen + // (soft sleep). Surface it as the same wake-only input the + // deferred head-up wake produces from a dark display. + decoded = G2Event("display-wake", "", BleProtocol.EVENT_HEAD_UP, decoded.eventSource, 0) + logLine("head-up forwarded by CFW while page on screen") + } + event = decoded + if (decoded != null) { + // Pure IMU samples arrive continuously; don't let them count + // as user input (which would starve battery polling). + val pureImuSample = "sys-event" == decoded.kind + && decoded.eventType == BleProtocol.EVENT_IMU_DATA_REPORT + if (!pureImuSample) { + lastConnectionOrInputAtMs = lastIncomingAtMs + } + if ("list-click" == decoded.kind || "text-click" == decoded.kind) { + // Container-routed touchpad input reached us, so the + // firmware is dispatching input: silent mode is off, + // whether or not its end-of-silent push arrived. + updateSilentModeLocked(false) + } + if ("sys-event" == decoded.kind) { + if (decoded.eventType == BleProtocol.EVENT_FOREGROUND_EXIT || decoded.eventType == BleProtocol.EVENT_ABNORMAL_EXIT || decoded.eventType == BleProtocol.EVENT_SYSTEM_EXIT) { + if (shutdownRequested) { + lastShutdownExitAtMs = now() + } + fixedLayoutCreated = false + displayedFingerprint = "" + clearAllMessagesLocked("firmware exit event") + } + } + } + } + } + interruptibleSleep.interrupt() + if (emitWearState) { + logLine(if (decodedWearState > 0) "wear state ON_HEAD" else "wear state OFF_HEAD") + emitWearState(decodedWearState > 0) + } + if (compassEvent != null) { + emitCompassEvent(compassEvent) + } + val finalEvent = event + if (finalEvent != null) { + if (finalEvent.hasImu) { + emitImuData(finalEvent.imuX, finalEvent.imuY, finalEvent.imuZ, finalEvent.eventSource) + } + // A standalone IMU_DATA_REPORT is a sensor sample, not a gesture: + // deliver it only to IMU listeners, skipping the input pipeline (and + // its per-frame latency bookkeeping) to avoid flooding it. + val pureImuSample = "sys-event" == finalEvent.kind + && finalEvent.eventType == BleProtocol.EVENT_IMU_DATA_REPORT + if (!pureImuSample) { + val frameId = frameTimings.startFrame( + "input:" + finalEvent.kind + " type=" + finalEvent.eventType + " src=" + finalEvent.eventSource) + frameTimings.log(frameId, "input event decoded from BLE notification") + emitRingEvent(finalEvent, frameId) + } + } + } + + internal fun handleDirectRingNotification(characteristicUuid: String, data: ByteArray) { + val decoded = FaceclawRingEventDecoder.decode(data) + if (decoded == null) { + logDebug("direct ring notify ignored: characteristicUuid=" + characteristicUuid + " raw=" + hex(data)) + return + } + + val event = decoded.event + val arrivalMs = now() + monitor.withLock { + lastIncomingAtMs = arrivalMs + lastConnectionOrInputAtMs = arrivalMs + } + logLine("direct ring " + decoded.label + " " + decoded.detail + " raw=" + hex(data)) + val frameId = frameTimings.startFrame("input:ring:" + decoded.label) + frameTimings.log(frameId, "input event decoded from direct ring notification") + emitRingEvent(event, frameId) + interruptibleSleep.interrupt() + } + + internal fun handleRenderNotification(address: String, data: ByteArray) { + val listenerToCall: FaceclawAudioPacketListener? + val arrivalMs = now() + monitor.withLock { + lastIncomingAtMs = arrivalMs + listenerToCall = if (audioCaptureActive) audioPacketListener else null + } + if (listenerToCall == null) { + return + } + val arm = if (address.equals(leftAddress, ignoreCase = true)) "L" else if (address.equals(rightAddress, ignoreCase = true)) "R" else "?" + try { + listenerToCall.onAudioPacket(data.copyOf(), arm, arrivalMs) + } catch (t: Throwable) { + logLine("G2 mic packet listener failed: " + safeMessage(t)) + } + } + + override fun onConnectionStateChange(address: String?, connected: Boolean) { + monitor.withLock { + if (address == null) { + return + } + if (isConfiguredRingAddress(address)) { + ringConnected = connected + ringNotificationsReady = false + if (!connected) { + ringReconnectAfterMs = now() + ConnectionOptions.RING_RECONNECT_DELAY_MS + } + logLine(if (connected) "direct ring BLE connected" else "direct ring BLE disconnected") + return + } + if (address.equals(rightAddress, ignoreCase = true)) { + rightConnected = connected + } else if (address.equals(leftAddress, ignoreCase = true)) { + leftConnected = connected + } else { + return + } + if (!connected) { + sessionReady = false + fixedLayoutCreated = false + startupProbePending = false + chargingMode = false + audioCaptureActive = false + audioPacketListener = null + clearAllMessagesLocked("connection lost") + displayedFingerprint = "" + if (!reconnectHalted) { + reconnectAfterMs = now() + ConnectionOptions.RECONNECT_DELAY_MS + } + } + } + interruptibleSleep.interrupt() + if (connected) { + setStateDisplay("connected", "Connected.") + } else if (!reconnectHalted) { + // While parked on a missing bond, keep the "unpaired" display: this + // callback is just the teardown of the arm that did connect. + setStateDisplay("connecting", "Connecting to the glasses...") + } + } + + // --------------------------------------------------------------------- + // Connect sequence (worker thread) + + internal fun connectLoopOnce() { + setStateDisplay("connecting", "Connecting to the glasses...") + try { + connectArm(rightAddress, true) + connectArm(leftAddress, true) + if (!sleepDuringConnectSettling(800)) { + return + } + authenticateArms() + sendPrelude() + + monitor.withLock { + sessionReady = true + // A fresh transport prelude always starts an active EvenHub + // lifecycle, even if the previous connection dropped while + // its page was intentionally suspended. + shutdownRequested = false + fixedLayoutCreated = false + clearAllMessagesLocked("session ready") + displayedFingerprint = "" + lastAckAtMs = now() + lastIncomingAtMs = lastAckAtMs + lastConnectionOrInputAtMs = lastAckAtMs + lastSessionReadyAtMs = lastAckAtMs + lastBatteryRefreshAtMs = 0 + imageRetryAfterMs = 0 + lastHeartbeatSentAtMs = 0 + lastHeartbeatAckedAtMs = 0 + consecutiveAckTimeouts = 0 + lastAudioControlAckMagic = 0 + audioCaptureActive = false + faceclawWakePendingNonce = -1 + cfwCleanupDelivered = false + for (transport in cfwTransports) transport.reset() + lastCfwCleanupAckMagic = 0 + lastFaceclawWakeLeaseQueuedAtMs = 0 + lastFaceclawFramebufferLeaseQueuedAtMs = 0 + enqueueFaceclawFramebufferControlLocked( + BleProtocol.FACECLAW_FB_OP_ACQUIRE, + true + ) + if (faceclawWakeLeaseEnabled) { + enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, + 0, + true + ) + } + } + setStateDisplay("connected", "Connected.") + logLine("session ready") + monitor.withLock { + // Query settings promptly on the first session so firmware + // version/extension (and battery) arrive without waiting for + // the input-quiet battery poll. The settings response doubles as + // the firmware-compatibility check surfaced during onboarding. + if (!firmwareInfoQueried) { + firmwareInfoQueried = true + lastBatteryRefreshAtMs = now() + pendingMessages.addLast(createBatteryQueryMessageLocked()) + logLine("queue settings query for firmware info") + } + } + tryConnectRing("initial") + } catch (t: Throwable) { + logLine("connect failed: " + safeMessage(t)) + val unpairedArm = firstUnpairedArm() + if (unpairedArm != null) { + handleUnpairedFailure(unpairedArm) + } else { + handleTransportFailure("connect failed") + } + } + } + + internal fun sleepDuringConnectSettling(delayMs: Long): Boolean { + val deadline = now() + delayMs + monitor.withLock { + while (running && !userDisconnectRequested) { + val remaining = deadline - now() + if (remaining <= 0) { + return true + } + monitor.awaitMs(minOf(remaining, 100L)) + } + return false + } + } + + internal fun connectArm(address: String, enableRenderNotify: Boolean) { + if (!link.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { + throw IllegalStateException("connect failed: $address") + } + // requestConnectionPriority has no callback in this Android compile target, so there is + // no reliable completion point to keep it in the global GATT operation pipeline. But it's + // important enough for performance that we call it anyways. + link.requestHighPriority(address) + + link.requestMtu(address, ConnectionOptions.DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) + + if (!link.discoverServices(address, ConnectionOptions.SERVICES_TIMEOUT_MS)) { + throw IllegalStateException("discoverServices failed: $address") + } + if (!link.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { + throw IllegalStateException("enableNotifications failed: " + address + " " + BleProtocol.NOTIFY_CHAR_UUID) + } + if (enableRenderNotify) { + link.enableNotifications(address, BleProtocol.RENDER_NOTIFY_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS) + } + monitor.withLock { + if (address.equals(rightAddress, ignoreCase = true)) { + rightConnected = true + } else if (address.equals(leftAddress, ignoreCase = true)) { + leftConnected = true + } + } + } + + internal fun shouldAttemptRingConnect(): Boolean { + if (!hasRingAddress()) { + return false + } + val now = now() + monitor.withLock { + return running + && sessionReady + && !ringNotificationsReady + && now >= ringReconnectAfterMs + && pendingMessages.isEmpty() + && inFlightMessages.isEmpty() + } + } + + internal fun tryConnectRing(reason: String) { + if (!hasRingAddress()) { + return + } + try { + connectRing() + } catch (t: Throwable) { + monitor.withLock { + ringConnected = false + ringNotificationsReady = false + ringReconnectAfterMs = now() + ConnectionOptions.RING_RECONNECT_DELAY_MS + } + logLine("direct ring connect failed (" + reason + "): " + safeMessage(t)) + } + } + + internal fun connectRing() { + logLine("connecting direct ring $ringAddress") + if (!link.connect(ringAddress, ConnectionOptions.CONNECT_TIMEOUT_MS)) { + throw IllegalStateException("connect failed: $ringAddress") + } + + link.requestHighPriority(ringAddress) + link.requestMtu(ringAddress, ConnectionOptions.RING_DESIRED_MTU, ConnectionOptions.CONNECT_TIMEOUT_MS) + + if (!link.discoverServices(ringAddress, ConnectionOptions.SERVICES_TIMEOUT_MS)) { + throw IllegalStateException("discoverServices failed: $ringAddress") + } + + val phoneNotify = enableRingNotification(BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID) + val dataNotify = enableRingNotification(BleProtocol.R1_NOTIFY_CHAR_UUID) + if (!phoneNotify && !dataNotify) { + throw IllegalStateException("no R1 notify characteristic subscribed") + } + + monitor.withLock { + ringConnected = true + ringNotificationsReady = true + ringReconnectAfterMs = 0 + } + logLine("direct ring ready phoneNotify=$phoneNotify dataNotify=$dataNotify") + } + + internal fun enableRingNotification(characteristicUuid: String): Boolean { + try { + return link.enableNotifications( + ringAddress, + characteristicUuid, + true, + ConnectionOptions.DESCRIPTOR_TIMEOUT_MS + ) + } catch (t: Throwable) { + logDebug("direct ring notify subscribe skipped: " + characteristicUuid + " " + safeMessage(t)) + return false + } + } + + /** + * Complete the sid-0x80 security-auth exchange on both freshly opened arm + * connections. Firmware 2.2.9 answers no queries until it completes over an + * encrypted link and closes unauthenticated links after ~30 s (see + * ../notes/ble-connections-2.2.9.md); on an unbonded phone the exchange is + * also what triggers SMP pairing. Deliberately soft: on timeout we log and + * continue rather than fail the connect — the custom firmware's response + * behavior is not yet hardware-verified, and on stock firmware an + * unanswered auth just means the prelude fails exactly as it did before. + * A pairing prompt accepted after our window still bonds at the OS level, + * so the next reconnect attempt authenticates promptly. + */ + internal fun authenticateArms() { + val right = messageBuilder.securityAuth(false) + val left = messageBuilder.securityAuth(true) + val now = now() + for (message in arrayOf(right, left)) { + message.onAck = MessageCallback { + } + message.onTimeout = MessageCallback { + } + message.sentAtMs = now + writeMessage(message) + } + val deadline = now() + ConnectionOptions.SECURITY_AUTH_SOFT_TIMEOUT_MS + while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { + val done = monitor.withLock { + !running || userDisconnectRequested || inFlightMessages.isEmpty() + } + if (done) { + break + } + val remaining = deadline - now() + if (remaining <= 0) { + break + } + interruptibleSleep.sleep(minOf(remaining, 100L)) + } + monitor.withLock { + if (!inFlightMessages.isEmpty()) { + clearInFlightMessagesLocked("security auth timeout") + logLine("security auth not acknowledged; continuing (2.2.9 stock requires it; older/custom firmware may not answer)") + return + } + } + val rightOk = BleProtocol.isAuthenticationSuccess(right.ackPayload, right.magic) + val leftOk = BleProtocol.isAuthenticationSuccess(left.ackPayload, left.magic) + logLine("security auth R=" + (if (rightOk) "ok" else "unconfirmed") + " L=" + (if (leftOk) "ok" else "unconfirmed")) + } + + internal fun sendPrelude() { + sendPrelude(false) + } + + internal fun sendPrelude(preserveWakeLeaseControls: Boolean) { + monitor.withLock { + if (preserveWakeLeaseControls) { + clearAllMessagesPreservingWakeLeaseLocked("prelude") + } else { + clearAllMessagesLocked("prelude") + } + } + val now = now() + val prelude = messageBuilder.prelude() + prelude.onAck = MessageCallback { + } + prelude.onTimeout = MessageCallback { + handleTransportFailure("ack timeout") + } + prelude.sentAtMs = now + writeMessage(prelude) + + val deadline = now() + ConnectionOptions.PRELUDE_TIMEOUT_MS + while (running && !userDisconnectRequested && !inFlightMessages.isEmpty()) { + val done = monitor.withLock { + !running || userDisconnectRequested || inFlightMessages.isEmpty() + } + if (done) { + break + } + val remaining = deadline - now() + if (remaining <= 0) { + break + } + interruptibleSleep.sleep(minOf(remaining, 100L)) + } + monitor.withLock { + if (!inFlightMessages.isEmpty()) { + clearInFlightMessagesLocked("prelude timeout") + throw IllegalStateException("prelude ack timeout") + } + } + } + + // --------------------------------------------------------------------- + // Small helpers shared by the extension files + + internal fun nextMapSessionId(): Int { + val id = nextMapSessionIdValue + val increment = if (connectionOptions.skipSessionIds) 2 else 1 + nextMapSessionIdValue = (nextMapSessionIdValue + increment) and 0xff + return id + } + + internal fun hasRingAddress(): Boolean { + return ringAddress.trim().isNotEmpty() + } + + internal fun isConfiguredRingAddress(address: String?): Boolean { + return hasRingAddress() && address != null && address.equals(ringAddress, ignoreCase = true) + } + + internal fun isDirectRingNotification(address: String?, characteristicUuid: String?): Boolean { + if (!isConfiguredRingAddress(address) || characteristicUuid == null) { + return false + } + return BleProtocol.R1_PHONE_NOTIFY_CHAR_UUID == characteristicUuid + || BleProtocol.R1_NOTIFY_CHAR_UUID == characteristicUuid + } + + internal fun desiredFingerprintSnapshot(): String { + desiredTilesLock.locked { + return desiredFingerprint + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt new file mode 100644 index 00000000..8411cb3b --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionSend.kt @@ -0,0 +1,1301 @@ +package com.faceclaw.app + +import com.faceclaw.app.GlassesSessionCore.Companion.DASHBOARD_TILE +import com.faceclaw.app.GlassesSessionCore.Companion.COMPASS_MIN_CHANGE_DEGREES +import com.faceclaw.app.GlassesSessionCore.Companion.COMPASS_REPORT_INTERVAL_MS +import com.faceclaw.app.GlassesSessionCore.Companion.FACECLAW_WAKE_LEASE_RENEW_MS +import com.faceclaw.app.GlassesSessionCore.Companion.safeMessage +import com.faceclaw.app.GlassesSessionCore.Companion.timestamp + +/* + * GlassesSessionCore, part 2: the send scheduler (driveSession), the CFW/EvenHub + * ack window, the desired-image pipeline and the message-queue bookkeeping. + * Everything here runs on the worker thread or under `monitor` (functions + * suffixed Locked require the caller to hold it). + */ + +internal fun GlassesSessionCore.driveSession(): Long { + while (true) { + // Run on the sender thread, outside `monitor`: Bluetooth API calls can + // wait on the global GATT lock, and callbacks need the session lock. + // Keep negotiation outside the timed stream. A fixed settling period + // is only an experiment boundary; HCI must confirm actual parameters. + var linkMode = -1 + var benchmarkAddresses: Array? = null + monitor.withLock { + if (benchmarkActive && benchmarkLinkPending) { + benchmarkLinkPending = false + linkMode = benchmarkLinkMode + benchmarkAddresses = arrayOf(leftAddress, rightAddress) + } + } + val addressesToPrepare = benchmarkAddresses + if (addressesToPrepare != null) { + for (address in addressesToPrepare) { + try { + link.prepareBenchmarkLink(address, linkMode) + } catch (error: RuntimeException) { + logLine("benchmark link request failed: " + safeMessage(error)) + } + } + monitor.withLock { + // Cancellation/new-run races leave the new run pending; its + // own preparation will replace this deadline before sending. + benchmarkReadyAtMs = now() + 1_000 + } + } + var messageToWrite: OutboundMessage? = null + var messageToPrewrite: OutboundMessage? = null + val now = now() + + maybeFinishNoChangeDesiredFrame() + + monitor.withLock { + drainCfwAcknowledgementsLocked() + if (cfwCleanupDelivered) { + /* Successful mode 11 must be the last Faceclaw write. Drop + * anything a late external producer attempted to enqueue + * while DashboardController was closing the transport. */ + clearPendingMessagesLocked("after CFW cleanup") + return 250 + } + if (sessionReady + && now - lastFaceclawFramebufferLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS + && !hasPendingOrInflightKindLocked("framebuffer-lease-control")) { + enqueueFaceclawFramebufferControlLocked( + BleProtocol.FACECLAW_FB_OP_ACQUIRE, + false + ) + } + if (faceclawWakeLeaseEnabled + && sessionReady + && now - lastFaceclawWakeLeaseQueuedAtMs >= FACECLAW_WAKE_LEASE_RENEW_MS + && !hasPendingOrInflightKindLocked("wake-lease-control")) { + enqueueFaceclawWakeControlLocked( + BleProtocol.FACECLAW_WAKE_OP_ACQUIRE, + 0, + false + ) + } + if (!inFlightMessages.isEmpty()) { + val oldest = inFlightMessages.firstOrNull() + val replay = CfwMessageWindow.replayWindow(inFlightMessages, now) + if (!replay.isEmpty()) { + logLine("CFW recovery: replay " + replay.size + + " unresolved message(s) from id=" + replay[0].magic) + for (candidate in replay) { + if (candidate.cfwRetries >= CfwMessageWindow.MAX_RETRIES) { + handleTransportFailure("CFW recovery retry limit") + return 0 + } + logLine("CFW replay id=" + candidate.magic + " label=" + candidate.label + + " cause=" + (if (candidate.cfwRetryPending) "NACK" + else if (candidate.cfwAckLenses == CfwTransport.BOTH) "ordered tail" else "missing ACK") + + " ackedLenses=" + candidate.cfwAckLenses + + " ageMs=" + (now - candidate.sentAtMs)) + inFlightMessages.remove(candidate) + magicPool.release(candidate.sid, candidate.magic, candidate.label, "CFW replay") + candidate.prepareCfwReplay(magicPool.allocate()) + } + for (i in replay.indices.reversed()) pendingMessages.addFirst(replay[i]) + return 0 + } + if (oldest != null && oldest.ackDeadlineAtMs <= now) { + logLine("message timed out: " + oldest.label) + inFlightMessages.removeFirst() + logLine("message timed out: " + oldest.label + " sid=" + oldest.sid + + " id=" + oldest.magic + " ackedLenses=" + oldest.cfwAckLenses + + " ageMs=" + (now - oldest.sentAtMs)) + magicPool.release(oldest.sid, oldest.magic, oldest.label, "timeout") + if (oldest.sid == CfwTransport.SID) + cfwTransports[if (oldest.isLeftArmMessage) 0 else 1].reset() + handleAckTimeoutLocked(oldest) + return 0 + } + if (connectionOptions.WINDOW_SIZE <= 1 + && sessionReady + && prewrittenMessage == null + && !pendingMessages.isEmpty() + && canPrewriteCandidate(pendingMessages.firstOrNull()) + && !shouldBlockPrewriteForHeartbeatLocked(now)) { + // Only the serial (window==1) path pre-sends the all-but-last + // packet; with a real window we just send the next message fully. + messageToPrewrite = pendingMessages.firstOrNull() + } + } + + if (chargingMode) { + // Glasses are in the case: no display traffic, only battery + // polls (which also detect the end of charging). + finishDesiredFrameLocked("discarded: glasses charging") + if (sessionReady && inFlightMessages.isEmpty() && !pendingMessages.isEmpty()) { + messageToWrite = pendingMessages.removeFirst() + logLine("sending pending message (charging): " + messageToWrite!!.label) + } else if (sessionReady && pendingMessages.isEmpty() && inFlightMessages.isEmpty() + && now - lastBatteryRefreshAtMs >= ConnectionOptions.CHARGING_BATTERY_POLL_MS) { + logLine("Writing charging-mode battery poll") + messageToWrite = createBatteryQueryMessageLocked() + lastBatteryRefreshAtMs = now + } else { + return 1_000 + } + } else { + if (messageToPrewrite == null + && !shutdownRequested + && !fixedLayoutCreated + && pendingMessages.isEmpty() + && inFlightMessages.isEmpty()) { + logLine("enqueueing create layout") + enqueueCreateLayoutLocked() + } else if (messageToPrewrite != null) { + // Prewrite outside the lock; the logical message remains pending until + // its final BLE frame is sent after the current protocol ACK. + } + if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated + && (if (firmwareDebugFlagsEnabled) 2 else 1) != firmwareDebugFlagsLastSent + && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { + logLine("enqueueing firmware debug flags " + (if (firmwareDebugFlagsEnabled) "show" else "hide")) + enqueueFirmwareDebugFlagsLocked() + } + + if (messageToPrewrite == null && !shutdownRequested && fixedLayoutCreated + && (if (compassOwners.isEmpty()) 0 else 1) != compassControlLastSent + && pendingMessages.isEmpty() && inFlightMessages.isEmpty()) { + val wanted = compassOwners.isNotEmpty() + logLine("enqueueing compass " + (if (wanted) "enable" else "disable")) + enqueueCompassControlLocked(false, wanted) + } + + if (benchmarkActive) { + maintainBenchmarkLocked(now) + } + + // Up to WINDOW_SIZE messages may be in flight at once (full + // pipelining); a slot frees when an ack arrives. An active + // bandwidth benchmark measures its own selected window instead. + val windowHasRoom = inFlightMessages.size < + maxOf(1, if (benchmarkActive) benchmarkWindowSize else connectionOptions.WINDOW_SIZE) + // A frame ready to send right now: don't inject a fresh + // heartbeat in front of it (the image's own ack resets the + // firmware heartbeat timer, so the heartbeat is redundant). + // "Ready" covers both a fresh composite still to be planned + // and a planned image already queued but not yet written -- + // enqueueing sets lastEnqueuedFingerprint, so testing only + // the desired fingerprint left the queued-but-unwritten + // window unprotected and a heartbeat that came due there + // cost the frame a full ack round trip (measured 124ms on + // frame#232 of the 2026-08-20 02:27 capture). + // A benchmark run counts as image traffic here for the same + // reason: its acks reset the firmware heartbeat timer, so a + // fresh heartbeat in front of it is redundant. + val imageWaiting = !shutdownRequested && fixedLayoutCreated + && !hasPendingOrInflightKindLocked("heartbeat") + && (benchmarkActive + || (now >= imageRetryAfterMs + && (hasPendingImageLocked() + || desiredFingerprintSnapshot() != lastEnqueuedFingerprint))) + noteImageStallLocked(now, windowHasRoom) + if (messageToPrewrite == null && handleHeartbeat(imageWaiting)) { + return ConnectionOptions.IDLE_SLEEP_MS.toLong() + } + + if (messageToPrewrite == null && sessionReady && windowHasRoom && !pendingMessages.isEmpty() + && CfwMessageWindow.canSend(inFlightMessages, pendingMessages.firstOrNull()!!)) { + messageToWrite = pendingMessages.removeFirst() + logLine("sending pending message: " + messageToWrite!!.label) + } else if (messageToPrewrite == null && !shutdownRequested && !benchmarkActive + && fixedLayoutCreated + && windowHasRoom && !hasPendingImageLocked() + && now >= imageRetryAfterMs + && desiredFingerprintSnapshot() != lastEnqueuedFingerprint) { + // Enqueue the next frame's delta against lastEnqueuedPacked + // (what the shadow will be), so it can pipeline behind an + // image still awaiting its ack. + logLine("Enqueued image update") + enqueueDesiredImageLocked() + return 0 + } else if (messageToPrewrite == null && shouldPollBatteryLocked(now)) { + logLine("Writing battery query") + messageToWrite = createBatteryQueryMessageLocked() + lastBatteryRefreshAtMs = now + } else if (messageToPrewrite == null && (!pendingMessages.isEmpty() || !inFlightMessages.isEmpty())) { + return ConnectionOptions.IDLE_SLEEP_MS.toLong() + } else if (messageToPrewrite == null) { + return 250 + } + } + } + + val prewrite = messageToPrewrite + if (prewrite != null) { + if (prewriteMessage(prewrite)) { + return 0 + } + return ConnectionOptions.IDLE_SLEEP_MS.toLong() + } + + val write = messageToWrite!! + if (!writeMessage(write)) { + monitor.withLock { + if (removePreparedMessageLocked(write) || write.magic == 0) { + handleTransportFailure("write failed") + } + } + return 0 + } + } +} + +/** + * If the desired image already matches what the glasses display, nothing will + * ever be enqueued for it, so finish its frame now (otherwise the TS side + * would block on it until its backpressure timeout). + */ +internal fun GlassesSessionCore.maybeFinishNoChangeDesiredFrame() { + var frameIdToFinish = 0 + monitor.withLock { + desiredTilesLock.locked { + if (desiredFrameId != 0 && lastEnqueuedFingerprint.isNotEmpty() && desiredFingerprint == lastEnqueuedFingerprint) { + frameIdToFinish = desiredFrameId + desiredFrameId = 0 + } + } + } + if (frameIdToFinish != 0) { + finishFrame(frameIdToFinish, "discarded: no change from displayed image") + } +} + +internal fun GlassesSessionCore.shouldBlockPrewriteForHeartbeatLocked(now: Long): Boolean { + if (shutdownRequested || !fixedLayoutCreated) { + return false + } + return hasPendingOrInflightKindLocked("heartbeat") + || now - lastHeartbeatAckedAtMs >= ConnectionOptions.HEARTBEAT_READY_MS +} + +internal fun GlassesSessionCore.canPrewriteCandidate(message: OutboundMessage?): Boolean { + if (message == null || message.sid == CfwTransport.SID || !message.isLeftArmMessage) { + return false + } + if ("image" != message.kind) { + return false + } + return message.message.size + 2 > 232 +} + +internal fun GlassesSessionCore.handleHeartbeat(imageWaiting: Boolean): Boolean { + val now = now() + val heartbeatEligible = !shutdownRequested && fixedLayoutCreated + val heartbeatPending = heartbeatEligible && hasPendingOrInflightKindLocked("heartbeat") + val heartbeatElapsedMs = now - lastHeartbeatAckedAtMs + val heartbeatReady = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS + val heartbeatUrgent = heartbeatEligible && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_URGENT_MS + + if (heartbeatReady && !heartbeatPending && inFlightMessages.isEmpty()) { + if (imageWaiting && !heartbeatUrgent) { + // Defer to the waiting frame: sending it now satisfies the + // firmware heartbeat deadline (its ack resets the timer), and + // the heartbeat still fires once we reach the URGENT threshold + // if rendering goes quiet again. Preserves the pending-heartbeat + // inter-lens-sync invariant below (that path is untouched). + return false + } + logLine("Writing heartbeat") + val heartbeatMessage = createHeartbeatMessage() + lastHeartbeatSentAtMs = now + writeMessage(heartbeatMessage) + return true + } else if (heartbeatUrgent) { + return true + } else if (heartbeatPending) { + // Don't send other message types while a heartbeat is pending because that + // can lead to inter-lens sync issues + return true + } + + return false +} + +internal fun GlassesSessionCore.createHeartbeatMessage(): OutboundMessage { + val message = messageBuilder.heartbeat() + message.onAck = MessageCallback { + monitor.withLock { + lastHeartbeatAckedAtMs = now() + } + } + message.onTimeout = MessageCallback { + // If a heartbeat fails to ack and we're over the heartbeat deadline, assume the connection is failed and reconnect. + // Otherwise ignore it, which will cause a retransmission attempt. + val isPastDeadline: Boolean + monitor.withLock { + isPastDeadline = now() - lastHeartbeatSentAtMs >= ConnectionOptions.HEARTBEAT_FAILURE_DEADLINE_MS + } + if (isPastDeadline) { + handleTransportFailure("heartbeat ack timeout") + } + } + return message +} + +internal fun GlassesSessionCore.writeMessage(message: OutboundMessage): Boolean { + val now = now() + message.writeStartedAtMs = now + message.sentAtMs = now + message.ackDeadlineAtMs = now + message.ackTimeoutMs + ConnectionOptions.WRITE_TIMEOUT_MS + if (message.magic != 0) { + monitor.withLock { + inFlightMessages.addLast(message) + } + } + if (message.imageUpdateId > 0 && message.imageMessageNumber == 1) { + monitor.withLock { + val stats = imageUpdateStats[message.imageUpdateId] + if (stats != null && stats.firstWriteStartedAtMs <= 0) { + stats.firstWriteStartedAtMs = now + } + } + } + + val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress + val frames: List + if (prewrittenMessage != null && prewrittenMessage !== message) { + if (!spoilPrewrittenMessage("before " + message.label)) { + return false + } + } + if (prewrittenMessage === message) { + frames = listOf(prewrittenFrames[prewrittenFrames.size - 1]) + prewrittenMessage = null + prewrittenFrames = emptyList() + } else if (message.sid == CfwTransport.SID) { + if (message.cfwRetries > 0) cfwTransports[if (message.isLeftArmMessage) 0 else 1].reset() + frames = cfwTransports[if (message.isLeftArmMessage) 0 else 1].encode( + message.message, message.magic, CfwTransport.BOTH, + link.negotiatedMtu(writeAddress)) + } else { + frames = BleProtocol.framePb( + message.message, + message.sid, + message.flag, + nextTransportSeq++ + ) + } + val result = link.writeFrames( + writeAddress, + BleProtocol.WRITE_CHAR_UUID, + frames, + ConnectionOptions.WRITE_MODE, + ConnectionOptions.WRITE_TIMEOUT_MS + ) + + monitor.withLock { + val sentAtMs = now() + message.sentAtMs = sentAtMs + message.ackDeadlineAtMs = sentAtMs + message.ackTimeoutMs + logImageUpdateSendLandmarkLocked(message) + val onSent = message.onSent + if (result && onSent != null) { + onSent.run() + monitor.signalAll() + } + } + + if (!result && message.sid == CfwTransport.SID) + cfwTransports[if (message.isLeftArmMessage) 0 else 1].reset() + return result +} + +internal fun GlassesSessionCore.prewriteMessage(message: OutboundMessage): Boolean { + if (prewrittenMessage === message) { + return true + } + if (prewrittenMessage != null && !spoilPrewrittenMessage("before prewrite " + message.label)) { + return false + } + if (!canPrewriteCandidate(message)) { + return false + } + + val frames: List = BleProtocol.framePb( + message.message, + message.sid, + message.flag, + nextTransportSeq++ + ) + if (frames.size <= 1) { + return false + } + + val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress + val prefixFrames = frames.subList(0, frames.size - 1) + val result = link.writeFrames( + writeAddress, + BleProtocol.WRITE_CHAR_UUID, + prefixFrames, + ConnectionOptions.WRITE_MODE, + ConnectionOptions.WRITE_TIMEOUT_MS + ) + if (!result) { + return false + } + + prewrittenMessage = message + prewrittenFrames = frames.toList() + logLine("prewrote " + message.label + " frames=" + prefixFrames.size + "/" + frames.size) + return true +} + +internal fun GlassesSessionCore.spoilPrewrittenMessage(reason: String): Boolean { + val message = prewrittenMessage + if (message == null || prewrittenFrames.isEmpty()) { + prewrittenMessage = null + prewrittenFrames = emptyList() + return true + } + val finalFrame = prewrittenFrames[prewrittenFrames.size - 1].copyOf() + if (finalFrame.size > 8) { + finalFrame[finalFrame.size - 1] = (finalFrame[finalFrame.size - 1].toInt() xor 0xff).toByte() + } + prewrittenMessage = null + prewrittenFrames = emptyList() + + val writeAddress = if (message.isLeftArmMessage) leftAddress else rightAddress + logLine("spoiling prewritten " + message.label + ": " + reason) + return link.writeFrames( + writeAddress, + BleProtocol.WRITE_CHAR_UUID, + listOf(finalFrame), + ConnectionOptions.WRITE_MODE, + ConnectionOptions.WRITE_TIMEOUT_MS + ) +} + +internal fun GlassesSessionCore.removePreparedMessageLocked(message: OutboundMessage?): Boolean { + if (message == null || message.magic == 0) { + return false + } + val iterator = inFlightMessages.iterator() + while (iterator.hasNext()) { + if (iterator.next() === message) { + iterator.remove() + magicPool.release(message.sid, message.magic, message.label, "write failed") + return true + } + } + return false +} + +/** Also drain on the worker: a clear/timeout may have removed a blocking + * head since the last notification. Fully ACKed controls must never reach + * the generic timeout path just because no further BLE reply arrived. */ +internal fun GlassesSessionCore.drainCfwAcknowledgementsLocked() { + while (true) { + val first = CfwMessageWindow.acknowledgedHead(inFlightMessages) ?: return + lastAckAtMs = now() + resolveAckLocked(first, first.ackPayload) + } +} + +internal fun GlassesSessionCore.resolveAckLocked(sid: Int, magic: Int, pb: ByteArray?) { + val iterator = inFlightMessages.iterator() + while (iterator.hasNext()) { + val message = iterator.next() + if (message.sid == sid && message.magic == magic) { + resolveAckLocked(message, pb) + return + } + } + recordUnexpectedAckLocked(sid, magic) +} + +internal fun GlassesSessionCore.resolveAckLocked(message: OutboundMessage, pb: ByteArray?) { + logLine("Got ACK for " + message.label + "(sid=" + message.sid + ", id=" + message.magic + ")") + inFlightMessages.remove(message) + message.ackPayload = pb?.copyOf() ?: ByteArray(0) + magicPool.release(message.sid, message.magic, message.label, "ack") + val onAck = message.onAck + if (onAck != null) { + onAck.run() + } + consecutiveAckTimeouts = 0 + // onAck may have just satisfied a waiter blocked on the monitor (e.g. + // awaitEvenHubSessionReady polling fixedLayoutCreated/displayedFingerprint + // after a create-layout or image ack). Without this, that waiter only + // notices on its own up-to-100ms poll tick, adding avoidable latency to + // every EvenHub wake. Always called with the monitor held (see call site). + monitor.signalAll() +} + +internal fun GlassesSessionCore.logImageUpdateSendLandmarkLocked(message: OutboundMessage) { + if (message.imageUpdateId <= 0) { + return + } + val stats = imageUpdateStats[message.imageUpdateId] + val frameId = if (stats == null) 0 else stats.frameId + if (message.imageMessageNumber == 1) { + if (stats != null && stats.firstWriteStartedAtMs <= 0) { + stats.firstWriteStartedAtMs = if (message.writeStartedAtMs > 0) message.writeStartedAtMs else message.sentAtMs + } + frameTimings.log(frameId, "first bluetooth packet sent") + logImageUpdateLandmarkLocked("first bluetooth message sent", message, message.sentAtMs) + } + if (message.imageMessageNumber == message.imageMessageCount) { + frameTimings.log(frameId, + "last bluetooth packet sent (message " + message.imageMessageNumber + "/" + message.imageMessageCount + ")") + logImageUpdateLandmarkLocked("last bluetooth message sent", message, message.sentAtMs) + } +} + +internal fun GlassesSessionCore.logImageUpdateAckLandmarkLocked(message: OutboundMessage) { + if (message.imageUpdateId <= 0 || message.imageMessageNumber != message.imageMessageCount) { + return + } + val ackedAtMs = now() + link.recordDisplayFrameSent() + val stats = imageUpdateStats.remove(message.imageUpdateId) + if (stats != null && stats.firstWriteStartedAtMs > 0) { + emitFrameMetrics(stats.paintMs, maxOf(0L, ackedAtMs - stats.firstWriteStartedAtMs).toInt(), stats.tileCount) + } + if (stats != null) { + finishFrame(stats.frameId, "sent") + } + logImageUpdateLandmarkLocked("last bluetooth message acked", message, ackedAtMs) +} + +/** Remove the stats entry for an image update that will not complete, finishing its frame. */ +internal fun GlassesSessionCore.discardImageUpdateStatsLocked(imageUpdateId: Int, reason: String) { + if (imageUpdateId <= 0) { + return + } + val stats = imageUpdateStats.remove(imageUpdateId) + if (stats != null) { + finishFrame(stats.frameId, "discarded: $reason") + } +} + +internal fun GlassesSessionCore.logImageUpdateLandmarkLocked(event: String, message: OutboundMessage, elapsedMs: Long) { + logLine("image update#" + message.imageUpdateId + " " + event + + " at " + timestamp(elapsedMs) + + " message=" + message.imageMessageNumber + "/" + message.imageMessageCount + + " label=" + message.label) +} + +internal fun GlassesSessionCore.enqueueCreateLayoutLocked() { + // New session: re-assert the firmware-debug-flags overlay once + // the layout is ready (the mode-7 send is gated on this having reset). + firmwareDebugFlagsLastSent = -1 + val message = messageBuilder.createLayout() + message.onAck = MessageCallback { + startupProbePending = false + clearMessagesOfKindLocked("startup-text-probe") + fixedLayoutCreated = true + displayedFingerprint = "" + } + message.onTimeout = MessageCallback { + if (startupProbePending) { + logLine("create layout timed out while startup text probe is pending") + if (hasPendingOrInflightKindLocked("startup-text-probe")) { + return@MessageCallback + } + startupProbePending = false + } + handleTransportFailure("ack timeout") + } + pendingMessages.addLast(message) + logLine("queue create layout") +} + +internal fun GlassesSessionCore.enqueueStartupProbeLocked() { + enqueueCreateLayoutLocked() + + val message = messageBuilder.startupTextProbe() + message.onAck = MessageCallback { + startupProbePending = false + clearMessagesOfKindLocked("create-layout") + fixedLayoutCreated = true + displayedFingerprint = "" + logLine("existing dashboard layout accepted text probe") + } + message.onTimeout = MessageCallback { + startupProbePending = false + if (hasPendingOrInflightKindLocked("create-layout")) { + return@MessageCallback + } + handleTransportFailure("ack timeout") + } + pendingMessages.addLast(message) + startupProbePending = true + logLine("queue startup text probe") +} + +/** + * Send the CFW mode-7 diagnostic-flag control op through the private stream: + * [7][2] to show the on-glasses debug-flag overlay, [7][1] to hide it. Uses the + * arbitrary-payload custom path (no bmp/dedup/frame-timing interaction). + */ +internal fun GlassesSessionCore.enqueueFirmwareDebugFlagsLocked() { + val show = firmwareDebugFlagsEnabled + val sub = if (show) 2 else 1 + val payload = byteArrayOf(CFW_MSG_DIAGNOSTICS.toByte(), sub.toByte()) + val message = messageBuilder.imagePayload( + DASHBOARD_TILE, nextMapSessionId(), payload, + "fw-debug-flags " + (if (show) "show" else "hide"), + connectionOptions.sendImagesToLeft) + pendingMessages.addLast(message) + firmwareDebugFlagsLastSent = sub + logLine("queue firmware debug flags " + (if (show) "show" else "hide")) +} + +/** + * Send CFW image-handler mode 10. Enable uses the configurable form + * [10][2][interval-ms LE16][minimum-change-degrees LE16]; disable remains [10][0]. + */ +internal fun GlassesSessionCore.enqueueCompassControlLocked(priority: Boolean, enable: Boolean) { + val sentState = if (enable) 1 else 0 + val payload = if (enable) + byteArrayOf( + CFW_MSG_COMPASS.toByte(), + 2.toByte(), + (COMPASS_REPORT_INTERVAL_MS and 0xff).toByte(), + ((COMPASS_REPORT_INTERVAL_MS shr 8) and 0xff).toByte(), + (COMPASS_MIN_CHANGE_DEGREES and 0xff).toByte(), + ((COMPASS_MIN_CHANGE_DEGREES shr 8) and 0xff).toByte(), + ) + else + byteArrayOf(CFW_MSG_COMPASS.toByte(), 0.toByte()) + val message = messageBuilder.imagePayload( + "compass-control", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + "compass " + (if (enable) "enable" else "disable"), + connectionOptions.sendImagesToLeft) + message.onTimeout = MessageCallback { + compassControlLastSent = -1 + logLine("compass control ack timeout") + } + if (enable) { + compassMaybeOn = true + } else { + message.onAck = MessageCallback { compassMaybeOn = false } + } + if (priority) pendingMessages.addFirst(message) + else pendingMessages.addLast(message) + compassControlLastSent = sentState + logLine("queue " + message.label) +} + +internal fun GlassesSessionCore.enqueueAmbientLightControlLocked(payload: ByteArray, label: String, priority: Boolean) { + if (!running || !sessionReady || shutdownRequested || !fixedLayoutCreated) { + logLine("skip $label; display path not ready") + return + } + val message = messageBuilder.imagePayload( + "als-control", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + label, + connectionOptions.sendImagesToLeft) + message.onTimeout = MessageCallback { logLine("$label ack timeout") } + if (priority) pendingMessages.addFirst(message) + else pendingMessages.addLast(message) + logLine("queue $label") +} + +internal fun GlassesSessionCore.enqueueDesiredImageLocked() { + val fingerprint = desiredFingerprintSnapshot() + val packedSnapshot: ByteArray? + val width: Int + val height: Int + val paintMs: Int + val frameId: Int + val draws: Array? + val scene: ShellScene + desiredTilesLock.locked { + packedSnapshot = desiredPacked + width = desiredWidth + height = desiredHeight + paintMs = desiredPaintMs + frameId = desiredFrameId + draws = desiredDraws + scene = desiredShellScene + desiredFrameId = 0 + } + val packedFrame: ByteArray = packedSnapshot ?: ByteArray(0) + if (customFirmwareDetected && packedFrame.size > 0) { + val rendered = scenePlanner.plan(packedFrame, width, height, draws, scene, nextImageFrameId, + connectionOptions.TEXTURE_CACHE_FRAMES, connectionOptions.INCREMENTAL_FRAMES, + connectionOptions.MULTI_RECT_FRAMES, ConnectionOptions.MULTI_RECT_MAX_RECTS) + nextImageFrameId = rendered.nextFid + val commands = rendered.commands + for (i in 0 until commands.size - 1) enqueueResourceCommandLocked(commands[i]) + val plan = BleImageOptimizer.TileImagePlan( + 0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId(), commands[commands.size - 1]) + finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId) + return + } + + frameTimings.spanStart(frameId, "compress-and-plan") + // Incremental (mode 3 bounding box) update against the last ENQUEUED frame + // (the base the firmware shadow will hold when this update is applied). + // lastEnqueuedPacked is cleared whenever the image pipeline is cleared, so + // a non-empty value means the display base is trusted. + var incrementalPayload: ByteArray? = null + var incrementalLog: String? = null + if (connectionOptions.INCREMENTAL_FRAMES && lastEnqueuedPacked.size > 0 + && lastEnqueuedWidth == width && lastEnqueuedHeight == height) { + val baseFid = nextImageFrameId + val single = + BleImageOptimizer.buildIncrementalImagePayload(lastEnqueuedPacked, packedFrame, width, height, baseFid) + if (single != null) { + incrementalPayload = single.payload + // advance only when a delta is actually emitted, so consecutive + // deltas carry consecutive ids (CFW skip/reorder detection) + nextImageFrameId = if (nextImageFrameId >= 0xfffe) 1 else nextImageFrameId + 1 + incrementalLog = "incremental update bbox=" + + ((single.payload[3].toInt() and 0xff) * 4) + "x" + ((single.payload[4].toInt() and 0xff) * 2) + + "+" + ((single.payload[1].toInt() and 0xff) * 4) + "+" + ((single.payload[2].toInt() and 0xff) * 2) + + " changed=" + single.changedBytes + "/" + single.boxBytes + "B" + + " clusters=" + single.clusterCount + + // When the bounding box spans multiple clusters or is sizeable, try + // splitting into tight rects (CFW mode-8). Only replace the single + // box if the multi-rect message is actually smaller on the wire. + if (connectionOptions.MULTI_RECT_FRAMES + && (single.clusterCount > 1 || single.payload.size > ConnectionOptions.MULTI_RECT_MIN_PAYLOAD)) { + val multi = BleImageOptimizer.buildMultiRectImagePayload( + lastEnqueuedPacked, packedFrame, width, height, baseFid, ConnectionOptions.MULTI_RECT_MAX_RECTS) + if (multi != null && multi.payload.size < single.payload.size) { + incrementalPayload = multi.payload + nextImageFrameId = multi.nextFid // rectCount fids consumed + incrementalLog = "multi-rect update n=" + multi.rectCount + + " covered=" + multi.coveredBytes + "B" + + " payload=" + multi.payload.size + "B (vs bbox " + single.payload.size + "B)" + } + } + } + } + val plan = if (incrementalPayload != null) + BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId(), incrementalPayload) + else + BleImageOptimizer.TileImagePlan(0, DASHBOARD_TILE, packedFrame, width, height, nextMapSessionId()) + frameTimings.spanEnd(frameId, "compress-and-plan") + if (incrementalLog != null) { + frameTimings.log(frameId, incrementalLog) + } + finishEnqueueDesiredImageLocked(plan, fingerprint, paintMs, frameId) +} + +/** Queue complete private commands, advance the delta base, and retain frame/ACK bookkeeping. */ +internal fun GlassesSessionCore.finishEnqueueDesiredImageLocked( + plan: BleImageOptimizer.TileImagePlan, fingerprint: String, paintMs: Int, frameId: Int) { + val updateId = nextImageUpdateId++ + val commands: MutableList = ArrayList() + if (plan.payload.size <= CfwTransport.MAX_MESSAGE) { + commands.add(plan.payload) + } else { + // A noisy full frame can exceed the stream record limit. Repaint it + // with independently decodable RLE bands below the decoded-message limit. + commands.addAll(BleImageOptimizer.encodeFullFrameBands( + plan.packed!!, plan.width, plan.height, nextImageFrameId)) + for (i in 0 until commands.size) { + nextImageFrameId = if (nextImageFrameId >= 0xfffe) 1 else nextImageFrameId + 1 + } + } + val messageCount = commands.size + imageUpdateStats[updateId] = BleImageOptimizer.ImageUpdateStats(paintMs, 1, frameId) + for (i in 0 until commands.size) { + enqueueCustomImageLocked(plan, commands[i], fingerprint, updateId, i + 1, messageCount) + } + // This frame is now the base for the next delta (it will be the firmware + // shadow once applied), even though it hasn't been acked yet — that is what + // lets the next frame pipeline behind it. plan.packed is the full frame; + // frames are immutable by convention, so referencing it is safe. + lastEnqueuedPacked = plan.packed!! + lastEnqueuedWidth = plan.width + lastEnqueuedHeight = plan.height + lastEnqueuedFingerprint = fingerprint + + frameTimings.log(frameId, "queued image update#" + updateId + + " messages=" + messageCount + " payload=" + plan.payload.size + "B") + logLine("queue image update#" + updateId + " fingerprint=" + fingerprint + + " messages=" + messageCount) +} + +/** + * Enqueue one resource eviction/upload command ahead of the image message that + * references its glyphs (the transport is FIFO, so no ack round trip is + * needed before use). A timeout means the on-glasses cache state is + * unknown; forget everything phone-side (glyphs re-upload lazily) and let + * the accompanying image update's own timeout drive the frame resync. + */ +internal fun GlassesSessionCore.enqueueResourceCommandLocked(payload: ByteArray) { + val message = messageBuilder.imagePayload( + "resources", + DASHBOARD_TILE, + nextMapSessionId(), + payload, + "resource command " + payload.size + "B", + connectionOptions.sendImagesToLeft) + message.onTimeout = MessageCallback { + resourceCache.reset() + logLine("resource command ack timeout; resource cache state reset") + } + pendingMessages.addLast(message) + logLine("queue " + message.label) +} + +internal fun GlassesSessionCore.enqueueCustomImageLocked( + plan: BleImageOptimizer.TileImagePlan, + payload: ByteArray, + fingerprint: String, + updateId: Int, + messageNumber: Int, + messageCount: Int +) { + val message = messageBuilder.customMessage("image", payload, + "image " + plan.tile.name + "#" + messageNumber, plan.tileIndex, connectionOptions.sendImagesToLeft) + message.setImageUpdatePosition(updateId, messageNumber, messageCount) + message.onAck = MessageCallback { + imageRetryAfterMs = 0 + // Firmware >= 2.2.4.34 resets its heartbeat timer when it receives + // image messages (not just heartbeats), so an acked image fragment + // satisfies the heartbeat deadline and heartbeats stop contending + // with active rendering. + lastHeartbeatAckedAtMs = now() + logImageUpdateAckLandmarkLocked(message) + var imageStillInFlight = false + for (inFlight in inFlightMessages) { + if ("image" == inFlight.kind) { + imageStillInFlight = true + break + } + } + if (!imageStillInFlight) { + var imageStillQueued = false + for (queued in pendingMessages) { + if ("image" == queued.kind) { + imageStillQueued = true + break + } + } + if (!imageStillQueued) { + displayedFingerprint = fingerprint + } + } + } + message.onTimeout = MessageCallback { + discardImageUpdateStatsLocked(message.imageUpdateId, "image ack timeout (will retry)") + clearMessagesOfKindLocked("image") + displayedFingerprint = "" + imageRetryAfterMs = now() + ConnectionOptions.IMAGE_RETRY_DELAY_MS + } + pendingMessages.addLast(message) +} + +internal fun GlassesSessionCore.createAudioControlMessageLocked(enable: Boolean): OutboundMessage { + val message = messageBuilder.enableOrDisableMic(enable) + message.onAck = MessageCallback { + lastAudioControlAckMagic = message.magic + audioCaptureActive = message.label?.contains("enable") == true + logLine(if (audioCaptureActive) "G2 mic enabled" else "G2 mic disabled") + } + message.onTimeout = MessageCallback { + handleTransportFailure("audio control ack timeout") + } + return message +} + +internal fun GlassesSessionCore.shouldPollBatteryLocked(now: Long): Boolean { + return !shutdownRequested + && sessionReady + && pendingMessages.isEmpty() + && inFlightMessages.isEmpty() + && now - lastConnectionOrInputAtMs >= ConnectionOptions.BATTERY_INPUT_QUIET_MS + && (lastBatteryRefreshAtMs == 0L || now - lastBatteryRefreshAtMs >= ConnectionOptions.BATTERY_REFRESH_INTERVAL_MS) +} + +internal fun GlassesSessionCore.createBatteryQueryMessageLocked(): OutboundMessage { + val message = messageBuilder.batteryQuery() + message.onAck = MessageCallback { + val ring = BleProtocol.parseRingBattery(message.ackPayload) + // Old firmware and missing/malformed extensions must clear any prior reading. + ringBattery = if (ring == null) -1 else ring.battery + ringCharging = if (ring == null) -1 else ring.charging + val snapshot = BleProtocol.parseSettingsBattery(message.ackPayload) + if (snapshot != null) { + headsetBattery = snapshot.battery + headsetCharging = snapshot.charging + emitBatteryState(headsetBattery, headsetCharging) + if (snapshot.silentMode >= 0) { + // Backstop for the push in onNotification: the firmware is + // confirmed to push silent-mode-on, but the off transition is + // not, so re-read the authoritative value on every poll. + updateSilentModeLocked(snapshot.silentMode > 0) + } + updateChargingModeLocked(snapshot.charging > 0, snapshot.battery) + } + val firmwareInfo = BleProtocol.parseSettingsFirmwareInfo(message.ackPayload) + if (firmwareInfo != null) { + customFirmwareDetected = firmwareInfo.isFaceclawFirmware() + emitFirmwareInfo(firmwareInfo) + } + } + message.onTimeout = MessageCallback { + logLine("Battery query timed out") + } + return message +} + +/** + * Track silent mode, which the wearer toggles by long-pressing both + * touchpads at once. While it is on the firmware refuses input events and + * app launches and powers the display down, so the glasses look dead even + * though the BLE session is healthy; the phone UI says so explicitly. + */ +internal fun GlassesSessionCore.updateSilentModeLocked(silent: Boolean) { + val next = if (silent) 1 else 0 + if (silentMode == next) { + return + } + silentMode = next + logLine(if (silent) "glasses entered silent mode" else "glasses left silent mode") + emitSilentMode(silent) +} + +/** + * Track whether the glasses are in the charging case. Charging means nobody + * is wearing them: display communication pauses (no heartbeats, so the + * firmware tears down its EvenHub context on its own) and only battery polls + * continue. When charging stops, tear the transport down and let the normal + * reconnect loop rebuild the session, layout, and first frame. + */ +internal fun GlassesSessionCore.updateChargingModeLocked(charging: Boolean, battery: Int) { + if (charging == chargingMode) { + if (chargingMode) { + setStateDisplay("charging", GlassesSessionCore.chargingStatusText(battery)) + } + return + } + if (charging) { + chargingMode = true + clearAllMessagesLocked("glasses charging") + fixedLayoutCreated = false + startupProbePending = false + displayedFingerprint = "" + finishDesiredFrameLocked("discarded: glasses charging") + logLine("glasses are charging; pausing display communication") + setStateDisplay("charging", GlassesSessionCore.chargingStatusText(battery)) + } else { + chargingMode = false + logLine("glasses removed from charger; reconnecting") + handleTransportFailure("charging ended") + } +} + +/** + * Record, into the frame that is waiting, why it did not go out on this + * pass of the send loop. Without this the export shows a bare multi-second + * jump between "image submitted as desired frame" and the first BLE + * packet, with no hint whether we were blocked on a heartbeat, the + * BLE window, or another message queued ahead. Deduped on (frame, reason), + * so a frame stalled for seconds gets one line per state change rather + * than one per loop pass. + */ +internal fun GlassesSessionCore.noteImageStallLocked(now: Long, windowHasRoom: Boolean) { + var frameId: Int + desiredTilesLock.locked { + frameId = desiredFrameId + } + val reason: String? + if (frameId != 0 && desiredFingerprintSnapshot() != lastEnqueuedFingerprint) { + reason = describeEnqueueBlockerLocked(now, windowHasRoom) + } else { + // Nothing waiting to be planned; an already-planned image may still + // be queued behind other traffic. + val queuedImage = firstPendingImageLocked() + frameId = if (queuedImage == null) 0 else imageUpdateFrameIdLocked(queuedImage.imageUpdateId) + reason = if (queuedImage == null) null else describeWriteBlockerLocked(now, windowHasRoom, queuedImage) + } + if (frameId == 0 || reason == null) { + stallFrameId = 0 + stallReason = "" + return + } + if (frameId == stallFrameId && reason == stallReason) { + return + } + stallFrameId = frameId + stallReason = reason + frameTimings.log(frameId, "waiting to send: $reason") +} + +/** Why the desired composite has not been turned into wire messages yet, or null. */ +internal fun GlassesSessionCore.describeEnqueueBlockerLocked(now: Long, windowHasRoom: Boolean): String? { + if (shutdownRequested) { + return "shutdown requested" + } + if (!sessionReady) { + return "BLE session not ready" + } + if (!fixedLayoutCreated) { + return "display layout not created yet" + } + if (now < imageRetryAfterMs) { + return "image retry backoff (" + (imageRetryAfterMs - now) + "ms left)" + } + if (hasPendingImageLocked()) { + return "an earlier image is still queued" + } + if (!windowHasRoom) { + return "BLE window full (" + inFlightMessages.size + " message(s) in flight)" + } + if (hasPendingOrInflightKindLocked("heartbeat")) { + return "heartbeat in flight" + } + if (!pendingMessages.isEmpty()) { + return pendingMessages.size.toString() + " message(s) queued ahead, next " + + pendingMessages.firstOrNull()?.label + } + return null +} + +/** Why a planned image message has not been written to BLE yet, or null. */ +internal fun GlassesSessionCore.describeWriteBlockerLocked(now: Long, windowHasRoom: Boolean, queuedImage: OutboundMessage): String? { + if (!sessionReady) { + return "BLE session not ready" + } + if (!windowHasRoom) { + return "BLE window full (" + inFlightMessages.size + " message(s) in flight)" + } + if (hasPendingOrInflightKindLocked("heartbeat")) { + return "heartbeat in flight" + } + // handleHeartbeat is a barrier: while one is due it holds back every + // other write, so a frame queued at the wrong moment waits a heartbeat + // round trip. Reported explicitly because it is otherwise invisible -- + // heartbeats belong to no frame. + val heartbeatElapsedMs = now - lastHeartbeatAckedAtMs + if (fixedLayoutCreated && !shutdownRequested + && heartbeatElapsedMs >= ConnectionOptions.HEARTBEAT_READY_MS) { + return "heartbeat due (" + heartbeatElapsedMs + "ms since the last one acked)" + } + val head = pendingMessages.firstOrNull() + if (head != null && head !== queuedImage) { + return "queued behind " + head.label + } + return null +} + +internal fun GlassesSessionCore.firstPendingImageLocked(): OutboundMessage? { + for (message in pendingMessages) { + if (message.imageUpdateId > 0) { + return message + } + } + return null +} + +internal fun GlassesSessionCore.imageUpdateFrameIdLocked(imageUpdateId: Int): Int { + val stats = imageUpdateStats[imageUpdateId] + return if (stats == null) 0 else stats.frameId +} + +internal fun GlassesSessionCore.finishDesiredFrameLocked(outcome: String) { + val frameIdToFinish: Int + desiredTilesLock.locked { + frameIdToFinish = desiredFrameId + desiredFrameId = 0 + } + finishFrame(frameIdToFinish, outcome) +} + +internal fun GlassesSessionCore.hasPendingOrInflightKindLocked(kind: String): Boolean { + for (queued in pendingMessages) { + if (kind == queued.kind) { + return true + } + } + for (inFlight in inFlightMessages) { + if (kind == inFlight.kind) { + return true + } + } + return false +} + +internal fun GlassesSessionCore.hasPendingOrInflightMagicLocked(magic: Int): Boolean { + for (queued in pendingMessages) { + if (queued.magic == magic) { + return true + } + } + for (inFlight in inFlightMessages) { + if (inFlight.magic == magic) { + return true + } + } + return false +} + +internal fun GlassesSessionCore.hasPendingMagicLocked(sid: Int, magic: Int): Boolean { + for (queued in pendingMessages) { + if (queued.sid == sid && queued.magic == magic) { + return true + } + } + return false +} + +internal fun GlassesSessionCore.handleAckTimeoutLocked(message: OutboundMessage) { + consecutiveAckTimeouts += 1 + + val onTimeout = message.onTimeout + if (onTimeout != null) { + onTimeout.run() + } + + if (consecutiveAckTimeouts > ConnectionOptions.MAX_CONSECUTIVE_ACK_TIMEOUTS) { + handleTransportFailure("too many ack timeouts") + } +} + +internal fun GlassesSessionCore.clearMessagesOfKindLocked(kind: String) { + val pendingIterator = pendingMessages.iterator() + while (pendingIterator.hasNext()) { + val message = pendingIterator.next() + if (kind == message.kind) { + pendingIterator.remove() + discardPrewriteIfMatchesLocked(message) + if ("image" == kind) { + discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared ($kind)") + } + magicPool.release(message.sid, message.magic, message.label, "cleared pending $kind") + } + } + val inFlightIterator = inFlightMessages.iterator() + while (inFlightIterator.hasNext()) { + val message = inFlightIterator.next() + if (kind == message.kind) { + inFlightIterator.remove() + if ("image" == kind) { + discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared ($kind)") + } + magicPool.release(message.sid, message.magic, message.label, "cleared inflight $kind") + } + } + if ("image" == kind) { + // The image pipeline was flushed (e.g. ack timeout -> keyframe resync): + // drop the pipelined delta base so the next image is a full keyframe. + lastEnqueuedPacked = ByteArray(0) + lastEnqueuedFingerprint = "" + } +} + +internal fun GlassesSessionCore.clearAllMessagesLocked(reason: String) { + clearPendingMessagesLocked(reason) + clearInFlightMessagesLocked(reason) + // The image pipeline is gone: drop the pipelined delta base so the next + // image is a full keyframe rather than a delta onto a stale base. + lastEnqueuedPacked = ByteArray(0) + lastEnqueuedFingerprint = "" + // Queued resource commands (if any) were dropped with the rest, and the + // session churn behind a full clear may have freed the on-glasses + // cache; forget it phone-side so glyphs re-upload lazily. + resourceCache.reset() +} + +/** + * A custom wake queues CLAIM before NativeScript asks for a resume. Keep + * that private control while flushing stale EvenHub traffic around the + * direct prelude write. + */ +internal fun GlassesSessionCore.clearAllMessagesPreservingWakeLeaseLocked(reason: String) { + val pendingIterator = pendingMessages.iterator() + while (pendingIterator.hasNext()) { + val message = pendingIterator.next() + if ("wake-lease-control" == message.kind) { + continue + } + pendingIterator.remove() + discardPrewriteIfMatchesLocked(message) + discardImageUpdateStatsLocked( + message.imageUpdateId, + "pending messages cleared: $reason" + ) + magicPool.release( + message.sid, + message.magic, + message.label, + "cleared pending: $reason" + ) + } + clearInFlightMessagesLocked(reason) + lastEnqueuedPacked = ByteArray(0) + lastEnqueuedFingerprint = "" + resourceCache.reset() +} + +/** Any image update whose fragments are still queued (not yet sent). */ +internal fun GlassesSessionCore.hasPendingImageLocked(): Boolean { + for (message in pendingMessages) { + if ("image" == message.kind) { + return true + } + } + return false +} + +internal fun GlassesSessionCore.clearPendingMessagesLocked(reason: String) { + while (!pendingMessages.isEmpty()) { + val message = pendingMessages.removeFirst() + discardPrewriteIfMatchesLocked(message) + discardImageUpdateStatsLocked(message.imageUpdateId, "pending messages cleared: $reason") + magicPool.release(message.sid, message.magic, message.label, "cleared pending: $reason") + } +} + +internal fun GlassesSessionCore.clearInFlightMessagesLocked(reason: String) { + while (!inFlightMessages.isEmpty()) { + val message = inFlightMessages.removeFirst() + discardImageUpdateStatsLocked(message.imageUpdateId, "inflight messages cleared: $reason") + magicPool.release(message.sid, message.magic, message.label, "cleared inflight: $reason") + } +} + +internal fun GlassesSessionCore.discardPrewriteIfMatchesLocked(message: OutboundMessage?) { + if (message != null && message === prewrittenMessage) { + prewrittenMessage = null + prewrittenFrames = emptyList() + } +} + +internal fun GlassesSessionCore.recordUnexpectedAckLocked(sid: Int, magic: Int) { + if (magic < BleMagicPool.MIN_MAGIC || magic > BleMagicPool.MAX_MAGIC) { + return + } + val previous = magicPool.getReleaseRecord(sid, magic) + if (previous == null) { + val pendingNote = if (hasPendingMagicLocked(sid, magic)) " while that magic is only pending locally" else "" + logLine("unexpected ACK sid=" + sid + " magic=" + magic + pendingNote + + "; possible Even app BLE contention") + return + } + if ("timeout" == previous.reason) { + logLine("late ACK after timeout sid=" + sid + " magic=" + magic + + " label=" + previous.label + + "; ACK timeout may be too short") + return + } + if ("ack" == previous.reason) { + logLine("duplicate ACK for already-acked message sid=" + sid + " magic=" + magic + + " label=" + previous.label + + "; possible Even app BLE contention") + return + } + logLine("late ACK for released message sid=" + sid + " magic=" + magic + + " label=" + previous.label + + " release=" + previous.reason) +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/SessionPorts.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/SessionPorts.kt new file mode 100644 index 00000000..1630beb4 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/SessionPorts.kt @@ -0,0 +1,165 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.InvocationKind +import kotlin.contracts.contract + +/** + * GATT transport used by [GlassesSessionCore]. Addresses are opaque strings (Android MAC + * addresses, CoreBluetooth identifiers on iOS); every call blocks the calling thread until the + * operation completes or [timeoutMs] elapses, exactly like Android's FaceclawBleManager. Inbound + * traffic reaches the core through its FaceclawBleListener methods, which the implementation + * must call from whatever thread the platform stack delivers on. + */ +interface SessionLink { + fun connect(address: String, timeoutMs: Int): Boolean + + /** Best effort; no completion point (see connectArm). */ + fun requestHighPriority(address: String) + + fun requestMtu(address: String, mtu: Int, timeoutMs: Int): Boolean + + fun negotiatedMtu(address: String): Int + + fun discoverServices(address: String, timeoutMs: Int): Boolean + + fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean + + fun writeFrames( + address: String, + characteristicUuid: String, + frames: List, + mode: GattWriteMode, + timeoutMs: Int, + ): Boolean + + fun disconnect(address: String) + + fun close() + + /** Whether the OS still holds a pairing bond for the address (iOS: always true). */ + fun isBonded(address: String): Boolean + + /** Bandwidth-benchmark link tuning; 0: current link, 1: HIGH priority, 2: 2M PHY, 3: both. */ + fun prepareBenchmarkLink(address: String, mode: Int) + + /** Traffic counter hook: one display frame fully acknowledged. */ + fun recordDisplayFrameSent() +} + +/** Delivers an action on a specific thread (a Looper, a dispatch queue, ...). */ +fun interface SessionDispatcher { + fun post(action: () -> Unit) +} + +enum class SessionLogLevel { + DEBUG, + INFO, + WARN, + ERROR, +} + +/** + * Platform side effects the session core needs. Listener callbacks are marshalled through + * [postToMain]; everything else is a synchronous query or command on the calling thread. + */ +interface SessionHost { + fun postToMain(action: () -> Unit) + + /** A dispatcher for the calling thread (its Looper/queue), falling back to the main thread. */ + fun currentThreadDispatcher(): SessionDispatcher + + fun isPhoneLocked(): Boolean + + /** Hold (true) or release (false) the "glasses screen on" wake lock; idempotent. */ + fun setScreenWakeLock(on: Boolean) + + /** Whether the stock Even app appears active (it can hold the BLE link). */ + fun isEvenAppActive(): Boolean + + /** Start the worker thread that runs [body] (the core's run loop) once. */ + fun startWorker(body: () -> Unit) + + /** Interrupt (where supported) and wait up to [timeoutMs] for the worker started by [startWorker]. */ + fun joinWorker(timeoutMs: Long) + + fun log(level: SessionLogLevel, tag: String, message: String, error: Throwable?) +} + +/** + * Java-monitor replacement: a reentrant state lock plus a separate condition used only at the + * blocking wait sites. Waiters must hold [lock] exactly once when calling [awaitMs]; notifiers + * may hold it (they normally do). Ordering is always lock -> signal, and the waiter never holds + * the signal while acquiring the lock, so the pair cannot deadlock and cannot lose a wake-up: + * the predicate is checked under [lock], the signal is taken before [lock] is released, and + * [ProtocolCondition.awaitMs] releases the signal atomically. + */ +internal class SessionMonitor(platform: ProtocolPlatform) { + val lock: ProtocolLock = platform.createLock() + private val signal: ProtocolCondition = platform.createCondition() + + fun signalAll() { + signal.lock() + try { + signal.signalAll() + } finally { + signal.unlock() + } + } + + /** Caller holds [lock] once; returns with it held again. Spurious wake-ups are possible. */ + fun awaitMs(timeoutMs: Long) { + signal.lock() + lock.unlock() + try { + signal.awaitMs(timeoutMs) + } finally { + signal.unlock() + } + lock.lock() + } +} + +/** Snapshot-iterated listener list (java.util.concurrent.CopyOnWriteArrayList stand-in). */ +internal class CopyOnWriteList(platform: ProtocolPlatform) : Iterable { + private val lock = platform.createLock() + + @Volatile private var items: List = emptyList() + + fun add(item: T) { + lock.withLock { items = items + item } + } + + fun remove(item: T) { + lock.withLock { items = items - item } + } + + fun isEmpty(): Boolean = items.isEmpty() + + override fun iterator(): Iterator = items.iterator() +} + +/** Runs [action] under the monitor's state lock; the contract lets `val`s be assigned inside, like `synchronized`. */ +@OptIn(ExperimentalContracts::class) +internal inline fun SessionMonitor.withLock(action: () -> T): T { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + lock.lock() + try { + return action() + } finally { + lock.unlock() + } +} + +/** [ProtocolLock.withLock] with a call-in-place contract. */ +@OptIn(ExperimentalContracts::class) +internal inline fun ProtocolLock.locked(action: () -> T): T { + contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } + lock() + try { + return action() + } finally { + unlock() + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphPacket.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphPacket.kt new file mode 100644 index 00000000..5d719a5a --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GlyphPacket.kt @@ -0,0 +1,168 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic +import kotlin.math.pow +import kotlin.math.roundToInt + +/** + * Wire packets produced by the platform text rasterizers (Android FontFileRenderer over + * minikin/HarfBuzz, iOS over CoreText) and consumed by the TypeScript side + * (app/native/font-files.ts, app/graphics/ttf-font.ts). Rasterization stays per platform; + * the packet layouts, gamma mapping and ink-box cropping live here so both platforms agree. + * + * Image packet (renderText / renderWrapped): [widthLo, widthHi, heightLo, heightHi, pixels...], + * one gamma-mapped coverage byte per pixel, row-major. + * + * Glyph-cell packet (renderGlyphCell), little-endian: + * [advance u16, 26.6 fixed point] + * [bearingX s16] ink left relative to the pen position + * [inkTop s16] ink top relative to the line top (ascent above baseline) + * [width u16][height u16] + * [width*height coverage bytes, gamma-mapped] + * An ink-free glyph (space) has width = height = 0 but a valid advance. + */ +object GlyphPacket { + const val IMAGE_HEADER_BYTES = 4 + const val GLYPH_CELL_HEADER_BYTES = 10 + + /** out = 255 * (coverage/255)^gamma; non-positive gamma means linear. */ + @JvmStatic + fun gammaLut(gammaIn: Double): ByteArray { + val gamma = if (gammaIn > 0 && gammaIn.isFinite()) gammaIn else 1.0 + val lut = ByteArray(256) + for (i in 0 until 256) { + lut[i] = (255.0 * (i / 255.0).pow(gamma)).roundToInt().coerceIn(0, 255).toByte() + } + return lut + } + + /** [first, last] painted (nonzero) column indexes, or null if blank. */ + @JvmStatic + fun paintedColumnRange(pixels: ByteArray, width: Int, height: Int): IntArray? { + var first = width + var last = -1 + for (y in 0 until height) { + val row = y * width + var x = 0 + while (x < first) { + if (pixels[row + x].toInt() != 0) { + first = x + break + } + x++ + } + x = width - 1 + while (x > last) { + if (pixels[row + x].toInt() != 0) { + last = x + break + } + x-- + } + } + return if (last >= first) intArrayOf(first, last) else null + } + + /** Tight [x0, y0, x1, y1] (inclusive) box of nonzero pixels, or null if blank. */ + @JvmStatic + fun inkBounds(pixels: ByteArray, width: Int, height: Int): IntArray? { + var x0 = width + var x1 = -1 + var y0 = height + var y1 = -1 + for (y in 0 until height) { + val row = y * width + for (x in 0 until width) { + if (pixels[row + x].toInt() != 0) { + if (x < x0) x0 = x + if (x > x1) x1 = x + if (y < y0) y0 = y + if (y > y1) y1 = y + } + } + } + return if (x1 >= x0) intArrayOf(x0, y0, x1, y1) else null + } + + /** Image packet of the whole width*height alpha raster. */ + @JvmStatic + fun packImage(alpha8: ByteArray, width: Int, height: Int, gamma: Double): ByteArray = + packImageRegion(alpha8, width, 0, 0, width, height, gamma) + + /** Image packet of the [x, y, width, height] region of a raster with row [stride]. */ + @JvmStatic + fun packImageRegion(alpha8: ByteArray, stride: Int, x: Int, y: Int, width: Int, height: Int, gamma: Double): ByteArray { + require(width >= 0 && height >= 0 && x >= 0 && y >= 0 && x + width <= stride) + val lut = gammaLut(gamma) + val out = ByteArray(IMAGE_HEADER_BYTES + width * height) + putU16(out, 0, width) + putU16(out, 2, height) + for (row in 0 until height) { + val src = (y + row) * stride + x + val dst = IMAGE_HEADER_BYTES + row * width + for (col in 0 until width) { + out[dst + col] = lut[alpha8[src + col].toInt() and 0xff] + } + } + return out + } + + /** 26.6 fixed-point advance clamped to u16. */ + @JvmStatic + fun advanceFixed(advancePx: Double): Int = (advancePx * 64.0).roundToInt().coerceIn(0, 0xffff) + + /** Glyph cell with no ink (space): valid advance, zero-size box. */ + @JvmStatic + fun emptyGlyphCell(advanceFixed: Int): ByteArray = glyphCellPacket(advanceFixed, 0, 0, 0, 0, null) + + /** Glyph cell from already gamma-mapped coverage. */ + @JvmStatic + fun glyphCellPacket(advanceFixed: Int, bearingX: Int, inkTop: Int, width: Int, height: Int, coverage: ByteArray?): ByteArray { + val out = ByteArray(GLYPH_CELL_HEADER_BYTES + (coverage?.size ?: 0)) + putU16(out, 0, advanceFixed) + putU16(out, 2, bearingX) + putU16(out, 4, inkTop) + putU16(out, 6, width) + putU16(out, 8, height) + coverage?.copyInto(out, GLYPH_CELL_HEADER_BYTES) + return out + } + + /** + * Glyph cell cropped to the tight ink box of a padded raster. [penX]/[baselineY] are the + * pen position inside the raster and [ascent] the font ascent above the baseline; the + * returned bearing/inkTop are relative to those, as the wire format requires. + */ + @JvmStatic + fun packGlyphCell( + advanceFixed: Int, + alpha8: ByteArray, + rasterWidth: Int, + rasterHeight: Int, + penX: Int, + baselineY: Int, + ascent: Int, + gamma: Double, + ): ByteArray { + val box = inkBounds(alpha8, rasterWidth, rasterHeight) ?: return emptyGlyphCell(advanceFixed) + val x0 = box[0] + val y0 = box[1] + val width = box[2] - x0 + 1 + val height = box[3] - y0 + 1 + val lut = gammaLut(gamma) + val coverage = ByteArray(width * height) + for (y in 0 until height) { + val src = (y0 + y) * rasterWidth + x0 + val dst = y * width + for (x in 0 until width) { + coverage[dst + x] = lut[alpha8[src + x].toInt() and 0xff] + } + } + return glyphCellPacket(advanceFixed, x0 - penX, ascent + (y0 - baselineY), width, height, coverage) + } + + private fun putU16(out: ByteArray, offset: Int, value: Int) { + out[offset] = (value and 0xff).toByte() + out[offset + 1] = ((value shr 8) and 0xff).toByte() + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GrayPacket.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GrayPacket.kt new file mode 100644 index 00000000..f11f1af9 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/GrayPacket.kt @@ -0,0 +1,117 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic +import kotlin.math.pow +import kotlin.math.roundToInt + +/** + * Converts ARGB pixels to the grayscale packet format used across the TS bridge: + * [widthLo, widthHi, heightLo, heightHi, pixels...] with one byte per pixel, row-major. + * Transparent pixels darken toward black (the on-glasses background). Platform code owns + * decoding and scaling (Bitmap / ImageIO); this object owns the pixel math so both platforms + * produce identical tone and dither. + */ +object GrayPacket { + const val HEADER_SIZE = 4 + + /** + * gamma > 1 darkens midtones (out = 255 * (in/255)^gamma). Source pixels are sRGB-encoded + * but the G2 drives its 16 levels roughly linearly, so mid-gray otherwise displays far + * brighter than intended; 2.2 undoes the sRGB encoding outright. + * + * dither error-diffuses against the 16 levels the frame is eventually packed to + * (BmpUtil.GRAY_TO_NIBBLE) instead of leaving each pixel to round on its own, which turns + * smooth gradients into visible bands. Dithered output is already quantized: every byte is + * a level times 16, which BmpUtil re-quantizes back to exactly that level. + */ + @JvmStatic + fun fromArgb(pixels: IntArray, width: Int, height: Int, gamma: Float, dither: Boolean): ByteArray { + require(width > 0 && height > 0 && pixels.size >= width * height) { "bad pixel plane" } + val out = ByteArray(HEADER_SIZE + width * height) + writeHeader(out, width, height) + val tone = toneCurve(gamma) + for (i in 0 until width * height) { + val p = pixels[i] + val a = (p ushr 24) and 0xff + val r = (p shr 16) and 0xff + val g = (p shr 8) and 0xff + val b = p and 0xff + out[HEADER_SIZE + i] = tone[((r * 299 + g * 587 + b * 114) / 1000) * a / 255].toByte() + } + if (dither) { + ditherToDisplayLevels(out, HEADER_SIZE, width, height) + } + return out + } + + @JvmStatic + fun writeHeader(out: ByteArray, width: Int, height: Int) { + out[0] = (width and 0xff).toByte() + out[1] = ((width shr 8) and 0xff).toByte() + out[2] = (height and 0xff).toByte() + out[3] = ((height shr 8) and 0xff).toByte() + } + + /** 256-entry map of source gray to displayed gray for out = in^gamma. */ + @JvmStatic + fun toneCurve(gamma: Float): IntArray { + val curve = IntArray(256) + for (v in 0 until 256) { + curve[v] = if (gamma == 1f) v else (255f * (v / 255f).pow(gamma)).roundToInt() + } + return curve + } + + /** + * Floyd-Steinberg error diffusion onto the display's 16 gray levels, in place over an 8bpp + * plane. Serpentine scanning keeps the diffusion from building up a directional texture + * across wide flat areas. + * + * Level n is written back as n * 16 rather than the n * 17 it stands for so that BmpUtil's + * (v + 8) >> 4 reproduces n exactly; level 0 is written as 1, not 0, because 0 is the shell's + * color-key for transparent. + */ + @JvmStatic + fun ditherToDisplayLevels(plane: ByteArray, offset: Int, width: Int, height: Int) { + var curr = FloatArray(width) + var next = FloatArray(width) + for (x in 0 until width) { + curr[x] = (plane[offset + x].toInt() and 0xff).toFloat() + } + for (y in 0 until height) { + val rowStart = offset + y * width + val nextStart = rowStart + width + val hasNext = y + 1 < height + for (x in 0 until width) { + next[x] = if (hasNext) (plane[nextStart + x].toInt() and 0xff).toFloat() else 0f + } + val leftToRight = (y and 1) == 0 + val start = if (leftToRight) 0 else width - 1 + val step = if (leftToRight) 1 else -1 + for (i in 0 until width) { + val x = start + i * step + val wanted = curr[x] + val level = (minOf(255f, maxOf(0f, wanted)) / 17f).roundToInt() + val error = wanted - level * 17f + plane[rowStart + x] = (if (level == 0) 1 else level * 16).toByte() + val ahead = x + step + if (ahead >= 0 && ahead < width) { + curr[ahead] += error * (7f / 16f) + } + if (hasNext) { + if (ahead >= 0 && ahead < width) { + next[ahead] += error * (1f / 16f) + } + next[x] += error * (5f / 16f) + val behind = x - step + if (behind >= 0 && behind < width) { + next[behind] += error * (3f / 16f) + } + } + } + val swap = curr + curr = next + next = swap + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/OpenTypeNames.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/OpenTypeNames.kt new file mode 100644 index 00000000..97a3b7c3 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/OpenTypeNames.kt @@ -0,0 +1,110 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic + +/** Random access over font bytes, so large files are not read whole just for a name. */ +interface RandomAccessBytes { + val length: Long + + /** Reads exactly [count] bytes at [offset] into [into]; throws when out of range. */ + fun read(offset: Long, into: ByteArray, count: Int) +} + +class ArrayRandomAccessBytes(private val bytes: ByteArray) : RandomAccessBytes { + override val length: Long + get() = bytes.size.toLong() + + override fun read(offset: Long, into: ByteArray, count: Int) { + require(offset >= 0 && count >= 0 && offset + count <= bytes.size) { "read out of range" } + bytes.copyInto(into, 0, offset.toInt(), offset.toInt() + count) + } +} + +/** + * Minimal OpenType 'name' table reader (TTF/OTF/TTC, first face) for font titles. + * Returns "Family\nStyle" ("Style" may be empty), preferring the typographic names + * (ids 16/17) over the legacy ones (1/2), or "" when the table cannot be parsed. + */ +object OpenTypeNames { + private const val TTCF = 0x74746366 + private const val NAME = 0x6e616d65 + + @JvmStatic + fun parseFile(path: String): String = parse(ArrayRandomAccessBytes(readFileData(path))) + + @JvmStatic + fun parse(bytes: ByteArray): String = parse(ArrayRandomAccessBytes(bytes)) + + @JvmStatic + fun parse(source: RandomAccessBytes): String { + val fileSize = source.length + if (fileSize < 12) return "" + var offset = 0L + if (readU32(source, 0) == TTCF) { // 'ttcf': use the first face + if (readU32(source, 8) < 1) return "" + offset = readU32(source, 12).toLong() and 0xffffffffL + } + val numTables = readU16(source, offset + 4) + var nameOffset = -1L + for (i in 0 until numTables) { + val rec = offset + 12 + i * 16L + if (rec + 16 > fileSize) return "" + if (readU32(source, rec) == NAME) { + nameOffset = readU32(source, rec + 8).toLong() and 0xffffffffL + break + } + } + if (nameOffset < 0 || nameOffset + 6 > fileSize) return "" + val count = readU16(source, nameOffset + 2) + val stringStorage = nameOffset + readU16(source, nameOffset + 4) + var family: String? = null + var style: String? = null + var preferredFamily: String? = null + var preferredStyle: String? = null + for (i in 0 until count) { + val rec = nameOffset + 6 + i * 12L + if (rec + 12 > fileSize) break + val platform = readU16(source, rec) + val nameId = readU16(source, rec + 6) + if (nameId != 1 && nameId != 2 && nameId != 16 && nameId != 17) continue + val length = readU16(source, rec + 8) + val strOffset = stringStorage + readU16(source, rec + 10) + if (strOffset + length > fileSize || length <= 0 || length > 512) continue + val data = ByteArray(length) + source.read(strOffset, data, length) + // Platform 0 (Unicode) and 3 (Windows) store UTF-16BE; + // platform 1 (Mac) is close enough to Latin-1 for names. + val value = (if (platform == 1) latin1(data) else utf16be(data)).trim() + if (value.isEmpty()) continue + if (nameId == 1 && family == null) family = value + if (nameId == 2 && style == null) style = value + if (nameId == 16 && preferredFamily == null) preferredFamily = value + if (nameId == 17 && preferredStyle == null) preferredStyle = value + } + val outFamily = preferredFamily ?: family ?: return "" + return outFamily + "\n" + (preferredStyle ?: style ?: "") + } + + private fun latin1(data: ByteArray): String = + CharArray(data.size) { (data[it].toInt() and 0xff).toChar() }.concatToString() + + private fun utf16be(data: ByteArray): String { + val chars = CharArray(data.size / 2) { + (((data[2 * it].toInt() and 0xff) shl 8) or (data[2 * it + 1].toInt() and 0xff)).toChar() + } + return chars.concatToString() + } + + private fun readU16(source: RandomAccessBytes, offset: Long): Int { + val b = ByteArray(2) + source.read(offset, b, 2) + return ((b[0].toInt() and 0xff) shl 8) or (b[1].toInt() and 0xff) + } + + private fun readU32(source: RandomAccessBytes, offset: Long): Int { + val b = ByteArray(4) + source.read(offset, b, 4) + return ((b[0].toInt() and 0xff) shl 24) or ((b[1].toInt() and 0xff) shl 16) or + ((b[2].toInt() and 0xff) shl 8) or (b[3].toInt() and 0xff) + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/PreviewPalette.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/PreviewPalette.kt new file mode 100644 index 00000000..134c750b --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/PreviewPalette.kt @@ -0,0 +1,52 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic +import kotlin.math.pow +import kotlin.math.roundToLong + +/** + * Palette for the phone-UI preview of an 8bpp grayscale frame: gray -> ARGB with a brightening + * gamma, either grayscale or green-on-black (matching the physical glasses). Both platforms + * should build their preview images from this table so they brighten identically. + */ +object PreviewPalette { + private var cachedLut: IntArray? = null + private var cachedGammaBits: Long = 0 + private var cachedGreen: Boolean = false + private val lock = protocolPlatform().createLock() + + /** ARGB value for [gray] under [brightenGamma]: 255 * (gray/255)^gamma per channel. */ + @JvmStatic + fun argb(gray: Int, brightenGamma: Double, green: Boolean): Int { + val v = (255 * (gray / 255.0).pow(brightenGamma)).roundToLong().coerceIn(0L, 255L).toInt() + return if (green) (0xff000000.toInt() or (v shl 8)) else (0xff000000.toInt() or (v shl 16) or (v shl 8) or v) + } + + /** Reuse the current preview palette; rebuild only when gamma or color changes. */ + @JvmStatic + fun lookupTable(brightenGamma: Double, green: Boolean): IntArray { + val gammaBits = brightenGamma.toBits() + lock.withLock { + val cached = cachedLut + if (cached != null && cachedGammaBits == gammaBits && cachedGreen == green) { + return cached + } + val lut = IntArray(256) { argb(it, brightenGamma, green) } + cachedGammaBits = gammaBits + cachedGreen = green + cachedLut = lut + return lut + } + } + + /** Expands [count] gray bytes starting at [offset] to ARGB pixels through the palette. */ + @JvmStatic + fun expand(gray: ByteArray, offset: Int, count: Int, brightenGamma: Double, green: Boolean): IntArray { + val lut = lookupTable(brightenGamma, green) + val colors = IntArray(count) + for (i in 0 until count) { + colors[i] = lut[gray[offset + i].toInt() and 0xff] + } + return colors + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/StatusIconArt.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/StatusIconArt.kt new file mode 100644 index 00000000..625d9326 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/StatusIconArt.kt @@ -0,0 +1,98 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic +import kotlin.math.abs + +/** + * Pure 24x24 8bpp icons for the system status strip (Wi-Fi level, cellular level, hotspot). + * Platform code reads the levels; this object only draws, so both platforms render the same + * artwork. + */ +object StatusIconArt { + const val ICON_SIZE = 24 + + @JvmStatic + fun wifi(level: Int): ByteArray { + val icon = ByteArray(ICON_SIZE * ICON_SIZE) + val cx = 12 + val cy = 18 + fillRect(icon, cx - 1, cy - 1, 3, 3, 230) + val radii = intArrayOf(5, 9, 13, 17) + for (index in radii.indices) { + if (level <= index) { + continue + } + drawWifiArc(icon, cx, cy, radii[index], 210) + } + return icon + } + + @JvmStatic + fun cell(level: Int): ByteArray { + val icon = ByteArray(ICON_SIZE * ICON_SIZE) + for (bar in 0 until 4) { + val x = 5 + bar * 4 + val height = 5 + bar * 4 + val value = if (level > bar) 220 else 55 + fillRect(icon, x, 20 - height, 3, height, value) + } + return icon + } + + @JvmStatic + fun hotspot(): ByteArray { + val icon = ByteArray(ICON_SIZE * ICON_SIZE) + fillRect(icon, 11, 17, 3, 3, 230) + drawWifiArc(icon, 12, 19, 7, 210) + drawWifiArc(icon, 12, 19, 12, 210) + fillRect(icon, 6, 5, 12, 2, 170) + return icon + } + + /** Nearest-neighbour resample of a 24x24 icon to size x size. */ + @JvmStatic + fun scale(source: ByteArray, size: Int): ByteArray { + if (size == ICON_SIZE) { + return source + } + val scaled = ByteArray(size * size) + for (y in 0 until size) { + val sy = minOf(ICON_SIZE - 1, (y * ICON_SIZE) / size) + for (x in 0 until size) { + val sx = minOf(ICON_SIZE - 1, (x * ICON_SIZE) / size) + scaled[y * size + x] = source[sy * ICON_SIZE + sx] + } + } + return scaled + } + + private fun drawWifiArc(icon: ByteArray, cx: Int, cy: Int, radius: Int, value: Int) { + val inner = (radius - 1) * (radius - 1) + val outer = (radius + 1) * (radius + 1) + for (y in 0 until ICON_SIZE) { + for (x in 0 until ICON_SIZE) { + val dx = x - cx + val dy = y - cy + val dist = dx * dx + dy * dy + if (dy <= 0 && dist >= inner && dist <= outer && abs(dx) <= radius) { + setPixel(icon, x, y, value) + } + } + } + } + + private fun fillRect(icon: ByteArray, x: Int, y: Int, width: Int, height: Int, value: Int) { + for (row in y until y + height) { + for (col in x until x + width) { + setPixel(icon, col, row, value) + } + } + } + + private fun setPixel(icon: ByteArray, x: Int, y: Int, value: Int) { + if (x < 0 || y < 0 || x >= ICON_SIZE || y >= ICON_SIZE) { + return + } + icon[y * ICON_SIZE + x] = value.coerceIn(0, 255).toByte() + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SvgIconSource.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SvgIconSource.kt new file mode 100644 index 00000000..676b4b31 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SvgIconSource.kt @@ -0,0 +1,150 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmField +import kotlin.jvm.JvmStatic +import kotlin.math.min + +/** One drawable element of a parsed icon; coordinates are in viewBox units. */ +sealed class SvgShape { + class PathData(@JvmField val d: String) : SvgShape() + + class Circle(@JvmField val cx: Float, @JvmField val cy: Float, @JvmField val r: Float) : SvgShape() + + class Ellipse(@JvmField val cx: Float, @JvmField val cy: Float, @JvmField val rx: Float, @JvmField val ry: Float) : SvgShape() + + /** rx/ry are both 0 for a sharp rectangle, otherwise both positive. */ + class Rect( + @JvmField val x: Float, + @JvmField val y: Float, + @JvmField val width: Float, + @JvmField val height: Float, + @JvmField val rx: Float, + @JvmField val ry: Float, + ) : SvgShape() + + class Line(@JvmField val x1: Float, @JvmField val y1: Float, @JvmField val x2: Float, @JvmField val y2: Float) : SvgShape() + + /** [points] is x0,y0,x1,y1,... with at least one pair; [closed] for polygon. */ + class Polyline(@JvmField val points: FloatArray, @JvmField val closed: Boolean) : SvgShape() +} + +class SvgIcon( + @JvmField val minX: Float, + @JvmField val minY: Float, + @JvmField val viewWidth: Float, + @JvmField val viewHeight: Float, + /** Lucide-style outline icons (fill="none") are stroked; everything else is filled. */ + @JvmField val stroked: Boolean, + @JvmField val shapes: List, +) { + /** + * Mapping from viewBox to a size*size raster: [translateX, translateY, scale]. Apply as + * translate(tx, ty), scale(s), translate(-minX, -minY), i.e. the viewBox centered in the box. + */ + fun placement(size: Int): FloatArray { + val scale = min(size / viewWidth, size / viewHeight) + return floatArrayOf((size - viewWidth * scale) / 2f, (size - viewHeight * scale) / 2f, scale) + } +} + +/** + * Parses the small subset of SVG used by Lucide / simple Noun Project icons (path, circle, + * ellipse, rect, line, polyline, polygon) into shapes the platform path builders draw. + * Also owns the 3-level coverage quantization applied after rasterization on both platforms. + */ +object SvgIconSource { + private val TAG_RE = Regex("<(path|circle|ellipse|rect|line|polyline|polygon)\\b([^>]*)>") + private val VIEWBOX_RE = Regex("viewBox\\s*=\\s*\"([^\"]*)\"") + private val SEPARATOR_RE = Regex("[\\s,]+") + + /** Null when nothing drawable was found. */ + @JvmStatic + fun parse(svg: String): SvgIcon? { + var minX = 0f + var minY = 0f + var viewW = 24f + var viewH = 24f + val vb = VIEWBOX_RE.find(svg) + if (vb != null) { + val parts = SEPARATOR_RE.split(vb.groupValues[1].trim()) + if (parts.size == 4) { + minX = parts[0].toFloat() + minY = parts[1].toFloat() + viewW = parts[2].toFloat() + viewH = parts[3].toFloat() + } + } + val stroked = svg.contains("fill=\"none\"") + val shapes = ArrayList() + for (m in TAG_RE.findAll(svg)) { + parseElement(m.groupValues[1], m.groupValues[2])?.let { shapes.add(it) } + } + if (shapes.isEmpty()) return null + return SvgIcon(minX, minY, viewW, viewH, stroked, shapes) + } + + /** + * Snap antialiased coverage toward hard edges so the 4bpp frames sent over BLE deflate + * better: mostly-transparent and mostly-opaque pixels become exactly 0/255 (long runs, and + * 0 stays color-key transparent for bitBlt), and only genuinely half-covered edge pixels + * keep one mid gray. At icon sizes this is visually near-identical. + */ + @JvmStatic + fun quantizeCoverage(alpha: Int): Int { + if (alpha < 64) return 0 + if (alpha >= 192) return 255 + return 128 + } + + /** Quantized coverage bytes from ARGB pixels (alpha channel = coverage). */ + @JvmStatic + fun quantizeArgb(pixels: IntArray): ByteArray { + val gray = ByteArray(pixels.size) + for (i in pixels.indices) gray[i] = quantizeCoverage((pixels[i] ushr 24) and 0xff).toByte() + return gray + } + + private fun parseElement(tag: String, attrs: String): SvgShape? = + when (tag) { + "path" -> attr(attrs, "d")?.let { SvgShape.PathData(it) } + "circle" -> { + val r = num(attrs, "r", 0f) + if (r > 0) SvgShape.Circle(num(attrs, "cx", 0f), num(attrs, "cy", 0f), r) else null + } + "ellipse" -> { + val rx = num(attrs, "rx", 0f) + val ry = num(attrs, "ry", 0f) + if (rx > 0 && ry > 0) SvgShape.Ellipse(num(attrs, "cx", 0f), num(attrs, "cy", 0f), rx, ry) else null + } + "rect" -> { + val w = num(attrs, "width", 0f) + val h = num(attrs, "height", 0f) + var rx = num(attrs, "rx", 0f) + var ry = num(attrs, "ry", if (rx > 0) rx else 0f) + if (rx <= 0) rx = ry + if (ry <= 0) ry = rx + if (w > 0 && h > 0) { + val rounded = rx > 0 || ry > 0 + SvgShape.Rect(num(attrs, "x", 0f), num(attrs, "y", 0f), w, h, if (rounded) rx else 0f, if (rounded) ry else 0f) + } else null + } + "line" -> SvgShape.Line(num(attrs, "x1", 0f), num(attrs, "y1", 0f), num(attrs, "x2", 0f), num(attrs, "y2", 0f)) + "polyline", "polygon" -> { + val points = attr(attrs, "points") ?: return null + val nums = SEPARATOR_RE.split(points.trim()) + val pairs = nums.size / 2 + if (pairs == 0) return null + val values = FloatArray(pairs * 2) { nums[it].toFloat() } + SvgShape.Polyline(values, tag == "polygon") + } + else -> null + } + + private fun attr(attrs: String, name: String): String? = + Regex("\\b" + name + "\\s*=\\s*\"([^\"]*)\"").find(attrs)?.groupValues?.get(1) + + private fun num(attrs: String, name: String, fallback: Float): Float { + val value = attr(attrs, name) ?: return fallback + return value.trim().toFloatOrNull() ?: fallback + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/HttpIdentity.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/HttpIdentity.kt new file mode 100644 index 00000000..f39b17f0 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/HttpIdentity.kt @@ -0,0 +1,26 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.jvm.JvmStatic + +/** + * Shared HTTP identity for the native networking helpers on both platforms. The version + * lives in app/version.ts, so the TypeScript side pushes the real string in at startup + * (see installNativeUserAgent in app/util/http.ts); the default is only a fallback for + * requests that somehow beat that call. + */ +object HttpIdentity { + const val DEFAULT_USER_AGENT = "Faceclaw" + + @Volatile + private var userAgent = DEFAULT_USER_AGENT + + @JvmStatic + fun setUserAgent(value: String?) { + val trimmed = value?.trim() + if (!trimmed.isNullOrEmpty()) userAgent = trimmed + } + + @JvmStatic + fun getUserAgent(): String = userAgent +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt new file mode 100644 index 00000000..40d9bbe0 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt @@ -0,0 +1,229 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmField +import kotlin.jvm.JvmStatic + +/** One accepted client connection of the local input port. */ +interface RemoteInputConnection { + /** Reads one byte, blocking at most [timeoutMs]; returns -1 on end of stream, timeout or error. */ + fun readByte(timeoutMs: Long): Int + + fun write(bytes: ByteArray) + + fun close() +} + +/** A bound, listening socket. */ +interface RemoteInputListener { + /** Blocks for the next client; returns null when the listener is closed or accept fails. */ + fun accept(): RemoteInputConnection? + + val isClosed: Boolean + + fun close() +} + +/** OS socket access for [RemoteInputSession]; a POSIX actual is the iOS counterpart. */ +interface LocalServerPort { + /** True when [address] is a unicast address assigned to a local interface (not any/multicast). */ + fun isLocalUnicastAddress(address: String): Boolean + + /** Binds and listens on [address]:[port]; throws when the port cannot be opened. */ + fun bind(address: String, port: Int): RemoteInputListener +} + +interface RandomSource { + fun nextBytes(count: Int): ByteArray +} + +/** One network address of a local interface, as enumerated by the platform. */ +data class InterfaceAddress( + val interfaceName: String, + val address: String, + val up: Boolean, + val pointToPoint: Boolean, + val loopback: Boolean, + val linkLocal: Boolean, + val anyLocal: Boolean, +) + +/** + * Explicit-address, bounded local input port shared by Android (java.net) and iOS (POSIX). + * Exactly one request is in flight: a client sends one newline-terminated UTF-8 frame of at most + * 64 KiB, the session publishes it as a pending JSON request, notifies the app through + * [dispatch] (which must run the callback on the app's UI thread, outside the lock), and blocks + * the serving thread until [complete] supplies the reply or the request deadline passes. + */ +class RemoteInputSession( + private val port: LocalServerPort, + private val random: RandomSource, + private val dispatch: (() -> Unit) -> Unit, + platform: ProtocolPlatform = protocolPlatform(), + private val wallClock: () -> Long = ::currentTimeMillis, + private val requestTimeoutMs: Long = REQUEST_TIMEOUT_MS, + private val readTimeoutMs: Long = READ_TIMEOUT_MS, +) { + private val condition = platform.createCondition() + private var server: RemoteInputListener? = null + private var client: RemoteInputConnection? = null + private var pending: String? = null + private var reply: String? = null + private var nextId = 0L + private var requestId = 0L + private var deadline = 0L + private var requestListener: (() -> Unit)? = null + + fun setRequestListener(listener: (() -> Unit)?) { + condition.withLock { requestListener = listener } + } + + /** Returns "" on success or a user-facing error. Never resolves hostnames or binds a wildcard. */ + fun start(port: Int, address: String): String { + condition.withLock { + if (server != null) return "" + if (!isNumericLocalAddress(address)) return "Invalid local address." + if (!this.port.isLocalUnicastAddress(address)) return "Address is not assigned to a local interface." + val listener = try { + this.port.bind(address, port) + } catch (e: Exception) { + return "Could not open local input port $port." + } + server = listener + startThread("FaceclawInput", true) { serve(listener) } + return "" + } + } + + fun stop() { + condition.withLock { + try { server?.close() } catch (ignored: Exception) {} + try { client?.close() } catch (ignored: Exception) {} + server = null + client = null + pending = null + requestId = 0 + reply = null + condition.signalAll() + } + } + + /** The pending request JSON (id, expiresAt, body), consumed once; null when none or expired. */ + fun nextRequest(): String? { + condition.withLock { + if (wallClock() >= deadline) { + pending = null + return null + } + val result = pending + pending = null + return result + } + } + + fun complete(id: Long, value: String?) { + condition.withLock { + if (id == requestId && wallClock() < deadline) { + reply = value + condition.signalAll() + } + } + } + + fun randomSecret(): String = BinaryEncoding.bytesToHex(random.nextBytes(32)) + + private fun notifyRequestReady(id: Long) { + // Called with the condition held; dispatching keeps JS off the socket thread and outside the lock. + dispatch { + val callback = condition.withLock { + if (requestId != id || pending == null || wallClock() >= deadline) null else requestListener + } + callback?.invoke() + } + } + + private fun serve(listener: RemoteInputListener) { + while (!listener.isClosed) { + val connection = listener.accept() ?: continue + try { + condition.withLock { + if (server !== listener) return + client = connection + } + val text = readFrame(connection) ?: continue + val response: String = condition.withLock { + if (server !== listener) return + requestId = ++nextId + deadline = wallClock() + requestTimeoutMs + reply = null + pending = Json.write(linkedMapOf("id" to requestId, "expiresAt" to deadline, "body" to text)) + notifyRequestReady(requestId) + while (reply == null && server === listener && wallClock() < deadline) { + condition.awaitMs(maxOf(1L, deadline - wallClock())) + } + val result = reply ?: TIMEOUT_RESPONSE + if (server === listener) { + pending = null + reply = null + requestId = 0 + } + result + } + connection.write((response + "\n").encodeToByteArray()) + } catch (ignored: Exception) { + // Never log request bodies: they contain credentials and possibly private text. + } finally { + try { connection.close() } catch (ignored: Exception) {} + condition.withLock { if (server === listener) client = null } + } + } + } + + /** One newline-terminated frame, or null when the client hung up, stalled or overflowed. */ + private fun readFrame(connection: RemoteInputConnection): String? { + val readDeadline = wallClock() + readTimeoutMs + val body = ByteSink() + while (true) { + val remaining = readDeadline - wallClock() + if (remaining <= 0) return null + val b = connection.readByte(remaining) + if (b == -1) return null + if (b == '\n'.code) break + if (body.size() >= MAX_FRAME_BYTES) return null + body.write(b) + } + return try { + body.toByteArray().decodeToString(throwOnInvalidSequence = true) + } catch (e: Exception) { + null + } + } + + companion object { + const val MAX_FRAME_BYTES = 65536 + const val REQUEST_TIMEOUT_MS = 5000L + const val READ_TIMEOUT_MS = 5000L + + @JvmField + val TIMEOUT_RESPONSE = "{\"ok\":false,\"error\":\"timeout\",\"message\":\"Faceclaw did not respond in time.\"}" + + private val numericAddress = Regex("[0-9.]+|[0-9a-fA-F]*:[0-9a-fA-F:.]*(%[a-zA-Z0-9_.-]+)?") + + /** Numeric IPv4/IPv6 literals only (optionally zone-scoped); hostnames are rejected. */ + @JvmStatic fun isNumericLocalAddress(address: String): Boolean = numericAddress.matches(address) + + /** Addresses a remote client could reach: up interfaces, minus loopback, link-local and wildcard. */ + @JvmStatic + fun reachableAddresses(all: List): List = + all.filter { it.up && !it.loopback && !it.linkLocal && !it.anyLocal } + + /** JSON array of {name, address, pointToPoint} consumed by app/remote/listeners.ts. */ + @JvmStatic + fun interfacesJson(all: List): String = + Json.write(reachableAddresses(all).map { + linkedMapOf("name" to it.interfaceName, "address" to it.address, "pointToPoint" to it.pointToPoint) + }) + + /** Lowercase hex SHA-256 of the UTF-8 token; the stored form of remote-input tokens. */ + @JvmStatic fun tokenHash(value: String): String = sha256Hex(value.encodeToByteArray()) + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/ResumableDownload.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/ResumableDownload.kt new file mode 100644 index 00000000..f1fce7f6 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/ResumableDownload.kt @@ -0,0 +1,178 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile + +/** One open HTTP response body; [read] returns bytes read or -1 at end. */ +interface DownloadResponse { + val code: Int + + /** Body length if known, else -1. */ + val contentLength: Long + + fun read(buffer: ByteArray): Int + + fun close() +} + +/** Blocking GET; `rangeFrom > 0` asks for `Range: bytes=-`. */ +interface DownloadTransport { + fun open(url: String, rangeFrom: Long): DownloadResponse +} + +interface FileSink { + fun write(bytes: ByteArray, offset: Int, length: Int) + + fun close() +} + +/** Storage port; paths are platform file paths. Multi-GB files must stream, hence no whole-file reads. */ +interface DownloadStorage { + /** Size in bytes, or -1 when missing. */ + fun length(path: String): Long + + fun prepareParent(path: String) + + fun openWrite(path: String, append: Boolean): FileSink + + /** Streams an existing file through [consumer] (bytes, count); stops early when it returns false. Returns bytes consumed. */ + fun readAll(path: String, consumer: (ByteArray, Int) -> Boolean): Long + + fun rename(from: String, to: String): Boolean + + fun delete(path: String): Boolean +} + +/** + * Large-file download to ".part" with HTTP Range resume across app restarts, a pinned + * sha256 hashed incrementally (including the resumed prefix), then a rename into place. + * [run] blocks on the calling thread; listener callbacks are invoked synchronously on it, so + * the platform adapter marshals them (Android posts to the constructing Looper). + */ +class ResumableDownload( + private val url: String, + private val destPath: String, + expectedSha256: String?, + private val expectedTotalBytes: Long, + private val transport: DownloadTransport, + private val storage: DownloadStorage, + private val listener: FaceclawModelDownloaderListener, + private val now: () -> Long = { currentTimeMillis() }, +) { + private val partPath = "$destPath.part" + private val expectedSha256 = expectedSha256?.lowercase() ?: "" + + @Volatile + private var cancelled = false + + @Volatile + private var response: DownloadResponse? = null + + /** Stops the download but keeps the .part file so a later run resumes. */ + fun cancel() { + cancelled = true + try { + response?.close() + } catch (ignored: Exception) { + } + } + + fun run() { + try { + if (storage.length(destPath) > 0) { + listener.onDone(destPath) + return + } + storage.prepareParent(destPath) + + var digest = Sha256Digest() + var offset = 0L + if (storage.length(partPath) >= 0) { + offset = hashExistingPrefix(digest) + if (cancelled) return + } + + val opened = transport.open(url, offset) + response = opened + var done: Long + try { + if (opened.code < 200 || opened.code >= 300) { + listener.onError("Model download failed: HTTP " + opened.code) + return + } + val resumed = opened.code == 206 + if (offset > 0 && !resumed) { + // Server ignored the Range header; start over. + offset = 0L + digest = Sha256Digest() + } + val total = + if (expectedTotalBytes > 0) expectedTotalBytes + else if (opened.contentLength > 0) offset + opened.contentLength + else -1L + + val out = storage.openWrite(partPath, resumed) + try { + val buffer = ByteArray(1 shl 16) + done = offset + var lastProgressAt = 0L + while (true) { + val read = opened.read(buffer) + if (read < 0) break + if (cancelled) return + out.write(buffer, 0, read) + digest.update(buffer, 0, read) + done += read + val time = now() + if (time - lastProgressAt >= PROGRESS_INTERVAL_MS) { + lastProgressAt = time + listener.onProgress(done, total) + } + } + } finally { + out.close() + } + } finally { + try { + opened.close() + } catch (ignored: Exception) { + } + } + + val partLength = storage.length(partPath) + if (expectedTotalBytes > 0 && partLength != expectedTotalBytes) { + listener.onError("Model download ended early (" + partLength + " of " + expectedTotalBytes + " bytes); try again to resume") + return + } + val actualSha = BinaryEncoding.bytesToHex(digest.digest()) + if (expectedSha256.isNotEmpty() && actualSha != expectedSha256) { + storage.delete(partPath) + listener.onError("Model download was corrupted (checksum mismatch); download it again") + return + } + if (!storage.rename(partPath, destPath)) { + listener.onError("Could not move the downloaded model into place") + return + } + listener.onDone(destPath) + } catch (e: Exception) { + if (cancelled) return + PlatformLog.w(TAG, "download failed: $e") + listener.onError("Model download failed: $e") + } + } + + /** Hash the already-downloaded prefix so the final digest covers the whole file. */ + private fun hashExistingPrefix(digest: Sha256Digest): Long = + storage.readAll(partPath) { bytes, count -> + if (cancelled) false + else { + digest.update(bytes, 0, count) + true + } + } + + companion object { + private const val TAG = "FaceclawModelDl" + const val PROGRESS_INTERVAL_MS = 500L + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/SseStream.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/SseStream.kt new file mode 100644 index 00000000..39b5ec13 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/SseStream.kt @@ -0,0 +1,209 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic + +/** Streaming POST transport; the platform (okhttp, NSURLSession) implements it. */ +interface StreamingHttp { + fun post(url: String, body: String, headers: List>, sink: ChunkSink): Cancellable +} + +interface Cancellable { + fun cancel() +} + +/** Raw response feed from a [StreamingHttp]; may be called from any thread, one call at a time. */ +interface ChunkSink { + fun onStatus(code: Int) + + fun onChunk(bytes: ByteArray, offset: Int, length: Int) + + fun onComplete() + + fun onFailure(message: String) +} + +sealed class SseEvent { + data class Line(val text: String) : SseEvent() + + data class HttpError(val code: Int, val body: String) : SseEvent() + + object Complete : SseEvent() + + data class Failure(val message: String) : SseEvent() +} + +/** + * Server-sent-events response policy shared by both platforms. Feeds raw bytes in through + * [ChunkSink] and queues [SseEvent]s for [takeEvents]. Behavior (matching the stricter iOS + * implementation): a UTF-8 BOM is stripped from the first line; lines split on LF, CR or CRLF; + * non-2xx responses buffer at most [ERROR_BODY_LIMIT] bytes of body and end in [SseEvent.HttpError]; + * a single line over [LINE_LIMIT] bytes, invalid UTF-8, or more than [QUEUE_BYTE_LIMIT] bytes / + * [QUEUE_EVENT_LIMIT] events waiting to be taken end the stream with a [SseEvent.Failure]. + * After the terminal event nothing further is queued; [cancel] drops everything. + */ +class SseStream : ChunkSink { + private val lock = protocolPlatform().createLock() + private val events = ArrayList() + private var queuedBytes = 0L + private var buffer = ByteArray(4096) + private var bufferLength = 0 + private var status = 0 + private var firstLine = true + private var finished = false + private var cancelled = false + + val isFinished: Boolean + get() = lock.withLock { finished } + + override fun onStatus(code: Int) { + lock.withLock { status = code } + } + + override fun onChunk(bytes: ByteArray, offset: Int, length: Int) { + lock.withLock { + if (finished || cancelled || length <= 0) return + if (status < 200 || status >= 300) { + val remaining = ERROR_BODY_LIMIT - bufferLength + append(bytes, offset, minOf(remaining, length)) + return + } + append(bytes, offset, length) + var start = 0 + var i = 0 + while (i < bufferLength) { + val c = buffer[i] + if (c != CR && c != LF) { + i++ + continue + } + if (c == CR && i + 1 == bufferLength) break + line(start, i - start) + if (finished) return + if (c == CR && buffer[i + 1] == LF) i++ + start = i + 1 + i++ + } + if (start > 0) { + buffer.copyInto(buffer, 0, start, bufferLength) + bufferLength -= start + } + if (bufferLength > LINE_LIMIT) finish(SseEvent.Failure("Streaming response line too large")) + } + } + + override fun onComplete() { + lock.withLock { + if (finished || cancelled) return + if (status < 200 || status >= 300) { + finish(SseEvent.HttpError(status, decode(0, bufferLength) ?: "")) + return + } + if (bufferLength > 0) { + if (buffer[bufferLength - 1] == CR) bufferLength-- + line(0, bufferLength) + if (finished) return + } + finish(SseEvent.Complete) + } + } + + override fun onFailure(message: String) { + lock.withLock { finish(SseEvent.Failure(message)) } + } + + /** Drains queued events in order. Empty once cancelled. */ + fun takeEvents(): List = + lock.withLock { + if (events.isEmpty()) return emptyList() + val taken = ArrayList(events) + events.clear() + queuedBytes = 0 + taken + } + + fun cancel() { + lock.withLock { + cancelled = true + events.clear() + queuedBytes = 0 + bufferLength = 0 + } + } + + private fun line(start: Int, length: Int) { + var text = decode(start, length) + if (text == null) { + finish(SseEvent.Failure("Invalid UTF-8 in streaming response")) + return + } + if (firstLine && text.startsWith('')) text = text.substring(1) + firstLine = false + queuedBytes += length + if (queuedBytes > QUEUE_BYTE_LIMIT || events.size >= QUEUE_EVENT_LIMIT) { + events.clear() + finish(SseEvent.Failure("Streaming response queue overflow")) + return + } + events.add(SseEvent.Line(text)) + } + + private fun decode(start: Int, length: Int): String? = + try { + buffer.decodeToString(start, start + length, throwOnInvalidSequence = true) + } catch (e: CharacterCodingException) { + null + } + + private fun finish(event: SseEvent) { + if (finished || cancelled) return + finished = true + events.add(event) + bufferLength = 0 + } + + private fun append(bytes: ByteArray, offset: Int, length: Int) { + if (length <= 0) return + if (bufferLength + length > buffer.size) buffer = buffer.copyOf(maxOf(bufferLength + length, buffer.size * 2)) + bytes.copyInto(buffer, bufferLength, offset, offset + length) + bufferLength += length + } + + companion object { + const val ERROR_BODY_LIMIT = 64 * 1024 + const val LINE_LIMIT = 2 * 1024 * 1024 + const val QUEUE_BYTE_LIMIT = 8L * 1024 * 1024 + const val QUEUE_EVENT_LIMIT = 16384 + private const val CR: Byte = '\r'.code.toByte() + private const val LF: Byte = '\n'.code.toByte() + + /** + * Unpacks the flat alternating [name, value, name, value, ...] header array the + * TypeScript side builds (okhttp Headers cannot cross the JS bridge). Entries with a + * null/empty name or a null value are skipped, as before. + */ + @JvmStatic + fun unpackHeaders(flat: Array?): List> { + if (flat == null) return emptyList() + val result = ArrayList>() + var i = 0 + while (i + 1 < flat.size) { + val name = flat[i] + val value = flat[i + 1] + if (!name.isNullOrEmpty() && value != null) result.add(name to value) + i += 2 + } + return result + } + + /** Delivers one event to a [FaceclawSseListener]. */ + @JvmStatic + fun deliver(event: SseEvent, listener: FaceclawSseListener) { + when (event) { + is SseEvent.Line -> listener.onLine(event.text) + is SseEvent.HttpError -> listener.onHttpError(event.code, event.body) + SseEvent.Complete -> listener.onComplete() + is SseEvent.Failure -> listener.onFailure(event.message) + } + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/settings/SettingsChangeHub.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/settings/SettingsChangeHub.kt new file mode 100644 index 00000000..f7c03152 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/settings/SettingsChangeHub.kt @@ -0,0 +1,71 @@ +package com.faceclaw.app + +/** Key/value backing store for app settings (SharedPreferences on Android, NSUserDefaults on iOS). */ +interface SettingsStorage { + fun getString(key: String?, defaultValue: String?): String? + + fun putString(key: String?, value: String?) + + fun getBoolean(key: String?, defaultValue: Boolean): Boolean + + fun putBoolean(key: String?, value: Boolean) +} + +/** Runs an action on the thread that registered a listener (a Looper Handler, a dispatch queue). */ +fun interface SettingsDispatcher { + fun post(action: () -> Unit) +} + +/** + * Settings reads/writes plus change fan-out. Each JS isolate registers one listener together + * with a dispatcher for its own thread; every write notifies every listener through its own + * dispatcher, so callbacks never run on a foreign thread. A listener registered without a + * dispatcher is accepted but never notified (it can still read fresh values on demand). + */ +class SettingsChangeHub( + private val storage: SettingsStorage, + private val warn: (String) -> Unit = { PlatformLog.w("FaceclawSettings", it) }, + platform: ProtocolPlatform = protocolPlatform(), +) { + private class Entry(val listener: FaceclawSettingsListener, val dispatcher: SettingsDispatcher?) + + private val lock = platform.createLock() + private var listeners: List = emptyList() + + fun getString(key: String?, defaultValue: String?): String? = storage.getString(key, defaultValue) + + fun setString(key: String?, value: String?) { + storage.putString(key, value) + notifyChanged(key) + } + + fun getBoolean(key: String?, defaultValue: Boolean): Boolean = storage.getBoolean(key, defaultValue) + + fun setBoolean(key: String?, value: Boolean) { + storage.putBoolean(key, value) + notifyChanged(key) + } + + fun register(listener: FaceclawSettingsListener, dispatcher: SettingsDispatcher?) { + if (dispatcher == null) warn("settings listener registered from a thread without a dispatcher; it will never be notified") + lock.withLock { listeners = listeners + Entry(listener, dispatcher) } + } + + fun unregister(listener: FaceclawSettingsListener?) { + lock.withLock { listeners = listeners.filter { it.listener !== listener } } + } + + fun notifyChanged(key: String?) { + val current = lock.withLock { listeners } + for (entry in current) { + val dispatcher = entry.dispatcher ?: continue + dispatcher.post { + try { + entry.listener.onSettingChanged(key) + } catch (error: Exception) { + warn("settings listener failed for key $key: ${error.message}") + } + } + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Concurrency.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Concurrency.kt new file mode 100644 index 00000000..02b82a99 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Concurrency.kt @@ -0,0 +1,105 @@ +package com.faceclaw.app + +/** + * Sleep that another thread can cut short. An interrupt delivered before the sleep begins is + * consumed by the next sleep (returns false immediately) rather than lost: interrupt() runs on + * other threads with no lock held by the sleeper between two work passes, so clearing the flag + * at entry would force a full sleep interval. Returns true when the full duration elapsed. + */ +class InterruptibleSleep(private val platform: ProtocolPlatform = protocolPlatform()) { + private val condition = platform.createCondition() + private var interrupted = false + + fun sleep(ms: Long): Boolean { + val deadline = platform.elapsedRealtimeMs() + maxOf(1L, ms) + condition.lock() + try { + if (interrupted) { + interrupted = false + return false + } + while (true) { + val remaining = deadline - platform.elapsedRealtimeMs() + if (remaining <= 0) return true + condition.awaitMs(remaining) + if (interrupted) { + interrupted = false + return false + } + } + } finally { + condition.unlock() + } + } + + fun interrupt() { + condition.withLock { + interrupted = true + condition.signalAll() + } + } +} + +/** One-shot countdown; await returns true once the count reaches zero, false on timeout. */ +class Latch(count: Int, private val platform: ProtocolPlatform = protocolPlatform()) { + private val condition = platform.createCondition() + private var remaining = count + + fun countDown() { + condition.withLock { + if (remaining > 0) remaining-- + if (remaining == 0) condition.signalAll() + } + } + + fun await(timeoutMs: Long): Boolean { + val deadline = platform.elapsedRealtimeMs() + timeoutMs + condition.withLock { + while (remaining > 0) { + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) return false + condition.awaitMs(left) + } + return true + } + } +} + +/** Unbounded FIFO handoff between threads with a timed poll. */ +class BlockingQueue(private val platform: ProtocolPlatform = protocolPlatform()) { + private val condition = platform.createCondition() + private val items = ArrayDeque() + + fun put(item: T) { + condition.withLock { + items.addLast(item) + condition.signalAll() + } + } + + fun poll(timeoutMs: Long): T? { + val deadline = platform.elapsedRealtimeMs() + timeoutMs + condition.withLock { + while (items.isEmpty()) { + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) return null + condition.awaitMs(left) + } + return items.removeFirst() + } + } + + fun clear() { + condition.withLock { items.clear() } + } + + val size: Int + get() = condition.withLock { items.size } +} + +/** Starts a platform thread running [body]; daemon threads never block process exit on the JVM. */ +expect fun startThread(name: String, daemon: Boolean, body: () -> Unit) + +expect fun sleepMs(ms: Long) + +fun currentThreadName(): String = com.faceclaw.shared.PlatformInfo.threadName() diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/FrameTimingsCore.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/FrameTimingsCore.kt new file mode 100644 index 00000000..74ee8e57 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/FrameTimingsCore.kt @@ -0,0 +1,451 @@ +package com.faceclaw.app + +import kotlin.math.abs +import kotlin.math.ceil +import kotlin.math.max +import kotlin.math.min + +/** + * Per-frame timing instrumentation, shared between the native BLE layer and the + * Typescript UI layer. A "frame" starts when we receive an input event (or a + * timer fires and we decide to redraw), and finishes when the resulting screen + * update has been fully transmitted to the glasses, is discarded unsent, or + * times out because nobody reported finishing it. + * + * Frames form a tree. One input event can fan out into several renders (the + * focused app's window plus the shell chrome, say), and each of those is its + * own frame linked back to the input frame that caused it via + * [startFrame]. The export nests descendants under their + * root and renders every line against the root's clock, so a single block + * shows the whole input-to-pixels story. Latency percentiles are measured over + * roots: root start to the first descendant that actually reached the glasses. + * + * All public methods are thread-safe and cheap enough to call from the BLE + * worker thread, the platform main thread, the JS thread, and app worker + * threads. Frame IDs are positive ints; 0 means "no frame" and is silently + * ignored everywhere, so callers do not need to null-check. + * + * This core owns the bookkeeping and the export text; the platform facade owns + * the export thread and file write (see the Android `FrameTimings`). The clock + * is [ProtocolPlatform.elapsedRealtimeMs] (monotonic, includes sleep); wall-clock, + * thread names and logging are injectable for tests. + */ +class FrameTimingsCore( + private val platform: ProtocolPlatform = protocolPlatform(), + private val wallClockMs: () -> Long = { currentTimeMillis() }, + private val threadName: () -> String = { currentThreadName() }, + private val formatWallClock: (Long) -> String = { formatLocalTime(it, "yyyy-MM-dd HH:mm:ss.SSS") }, + private val logInfo: (String) -> Unit = { PlatformLog.i(TAG, it) }, + private val logWarn: (String) -> Unit = { PlatformLog.w(TAG, it) }, +) { + companion object { + const val TAG = "FrameTimings" + + /** Frames still open after this long are finished as "timeout". */ + const val FRAME_TIMEOUT_MS = 30_000L + const val EXPORT_INTERVAL_MS = 15_000L + const val SWEEP_INTERVAL_MS = 5_000L + private const val RECENT_ROOTS_KEPT = 40 + private const val SLOWEST_ROOTS_KEPT = 20 + private const val SENT_DURATIONS_WINDOW = 512 + private const val MAX_LINES_PER_FRAME = 200 + /** + * Frames retained for ID lookup. Well above the number any export can + * reference, so a late log/span/finish call always finds its frame; frames + * older than this are unreachable and get collected. + */ + private const val FRAMES_RETAINED = 1024 + + private fun percentileOfSorted(sorted: List, percentile: Int): Long { + val index = ceil(percentile / 100.0 * sorted.size).toInt() - 1 + return sorted[max(0, min(sorted.size - 1, index))] + } + + /** java.lang.String.format("%+7d"): explicit sign, right-aligned in 7 columns. */ + private fun signedWidth7(value: Long): String { + val text = (if (value < 0) "-" else "+") + abs(value).toString() + return text.padStart(7) + } + } + + private class Line( + val atMs: Long, // elapsedRealtimeMs + val thread: String, + val message: String? + ) + + private class Frame( + val id: Int, + var reason: String, + val startedAtMs: Long, // elapsedRealtimeMs + val startedWallClockMs: Long, + val parent: Frame? + ) { + val children: MutableList = ArrayList(0) + val lines: MutableList = ArrayList() + val openSpans: MutableMap = LinkedHashMap() + var finishedAtMs: Long = 0 + var outcome: String? = null // null while open; "sent", "discarded: ...", "timeout: ..." + /** Set on the root once some frame in its subtree reached the glasses. */ + var subtreeSentRecorded = false + + fun root(): Frame { + var frame: Frame = this + while (frame.parent != null) { + frame = frame.parent!! + } + return frame + } + + fun isOpen(): Boolean = outcome == null + + fun durationMs(): Long = finishedAtMs - startedAtMs + + fun wasSent(): Boolean { + val outcome = this.outcome + return outcome != null && outcome.startsWith("sent") + } + + /** Last moment anything in this subtree happened, for whole-tree duration. */ + fun subtreeEndAtMs(nowMs: Long): Long { + var end = if (isOpen()) nowMs else finishedAtMs + for (child in children) { + end = max(end, child.subtreeEndAtMs(nowMs)) + } + return end + } + + fun subtreeHasOpenFrame(): Boolean { + if (isOpen()) return true + for (child in children) { + if (child.subtreeHasOpenFrame()) return true + } + return false + } + } + + private val lock = platform.createLock() + /** + * Every frame we still retain, keyed by ID, in insertion order: open frames + * plus enough history that late calls and the export can still resolve one. + */ + private val framesById: LinkedHashMap = LinkedHashMap() + private val recentRoots = ArrayDeque() + private val slowestRoots: MutableList = ArrayList() + private val inputLatencies = ArrayDeque() + private val renderLatencies = ArrayDeque() + private var nextFrameId = 1 + private var framesStarted: Long = 0 + private var framesSent: Long = 0 + private var framesDiscarded: Long = 0 + private var framesTimedOut: Long = 0 + private var exportDirty = false + + /** Begin a root frame; reason is a short label like "input:sys-event type=0". */ + fun startFrame(reason: String?): Int = startFrame(reason, 0) + + /** + * Begin a frame caused by an existing one (parentFrameId; 0 for a root). + * The child is nested under its root in the export and its latency counts + * against the root, so an input event that fans out into an app render and + * a shell-chrome render reads as one timeline instead of three. + */ + fun startFrame(reason: String?, parentFrameId: Int): Int { + val now = platform.elapsedRealtimeMs() + val frame = lock.withLock { + val parent = framesById[parentFrameId] + val frame = Frame(nextFrameId++, reason ?: "", now, wallClockMs(), parent) + framesById[frame.id] = frame + // Like LinkedHashMap.removeEldestEntry: drop at most the single eldest + // entry per insert, and only when it is already finished. + if (framesById.size > FRAMES_RETAINED) { + val eldest = framesById.entries.first() + if (!eldest.value.isOpen()) framesById.remove(eldest.key) + } + framesStarted++ + if (parent != null) { + parent.children.add(frame) + addLineLocked(parent, now, "spawned frame#" + frame.id + " (" + frame.reason + ")") + } + frame + } + return frame.id + } + + /** + * Append to a frame's label, for facts only known after it started (which + * app is in the foreground, which window a render is for). Shows up in the + * frame's header line, so the export is scannable without reading bodies. + */ + fun annotate(frameId: Int, text: String?) { + if (text == null || text.isEmpty()) return + lock.withLock { + val frame = framesById[frameId] ?: return + frame.reason = if (frame.reason.isEmpty()) text else frame.reason + " " + text + } + } + + fun log(frameId: Int, message: String?) { + val now = platform.elapsedRealtimeMs() + lock.withLock { + val frame = openFrameLocked(frameId) ?: return + addLineLocked(frame, now, message) + } + } + + fun spanStart(frameId: Int, name: String) { + val now = platform.elapsedRealtimeMs() + lock.withLock { + val frame = openFrameLocked(frameId) ?: return + frame.openSpans[name] = now + addLineLocked(frame, now, "span $name start") + } + } + + fun spanEnd(frameId: Int, name: String) { + val now = platform.elapsedRealtimeMs() + lock.withLock { + val frame = openFrameLocked(frameId) ?: return + val startedAt = frame.openSpans.remove(name) + if (startedAt == null) { + addLineLocked(frame, now, "span $name end (start not recorded)") + } else { + addLineLocked(frame, now, "span " + name + " end (" + (now - startedAt) + "ms)") + } + } + } + + /** + * Finish a frame. Outcomes: "sent" (counted in latency percentiles), anything + * starting with "discarded", or "timeout". First finish wins; later calls for + * the same frame are ignored, so racing completion paths are safe. + */ + fun finishFrame(frameId: Int, outcome: String?) { + val now = platform.elapsedRealtimeMs() + val finished = lock.withLock { + val frame = openFrameLocked(frameId) ?: return + finishFrameLocked(frame, now, outcome ?: "discarded: no outcome given") + frame + } + logInfo("frame#" + finished.id + " [" + finished.reason + "] -> " + finished.outcome + + " in " + finished.durationMs() + "ms") + } + + /** One-line stats summary, e.g. for showing in the phone UI. */ + fun statsSummary(): String { + lock.withLock { + val input = percentilesLocked(inputLatencies) + return "frames started=" + framesStarted + " sent=" + framesSent + + " discarded=" + framesDiscarded + " timeout=" + framesTimedOut + + (if (input == null) + "" + else " | input-to-display p50=" + input[0] + "ms p90=" + input[1] + + "ms p99=" + input[2] + "ms max=" + input[3] + "ms") + } + } + + /** Finish every frame open longer than [FRAME_TIMEOUT_MS] as a timeout; returns how many. */ + fun sweepTimedOut(): Int { + val now = platform.elapsedRealtimeMs() + val timedOut: MutableList = ArrayList() + lock.withLock { + for (frame in ArrayList(framesById.values)) { + if (frame.isOpen() && now - frame.startedAtMs >= FRAME_TIMEOUT_MS) { + finishFrameLocked(frame, now, "timeout: never reported finished") + timedOut.add(frame) + } + } + } + for (frame in timedOut) { + logWarn("frame#" + frame.id + " [" + frame.reason + "] timed out after " + + frame.durationMs() + "ms without being finished") + } + return timedOut.size + } + + /** True once a frame finished since the last [takeExport]/[buildExport] with clear. */ + val isExportDirty: Boolean + get() = lock.withLock { exportDirty } + + /** The full export text (does not clear the dirty flag). */ + fun buildExport(): String = lock.withLock { buildExportLocked() } + + /** The export text if anything changed since the last take, else null; clears the dirty flag. */ + fun takeExport(): String? = lock.withLock { + if (!exportDirty) return null + exportDirty = false + buildExportLocked() + } + + // --------------------------------------------------------------------- + + /** The frame with this ID if it exists and is still open, else null. */ + private fun openFrameLocked(frameId: Int): Frame? { + if (frameId <= 0) return null + val frame = framesById[frameId] + return if (frame != null && frame.isOpen()) frame else null + } + + private fun addLineLocked(frame: Frame, now: Long, message: String?) { + if (frame.lines.size >= MAX_LINES_PER_FRAME) { + if (frame.lines.size == MAX_LINES_PER_FRAME) { + frame.lines.add(Line(now, threadName(), "... line cap reached")) + } + return + } + frame.lines.add(Line(now, threadName(), message)) + } + + private fun finishFrameLocked(frame: Frame, now: Long, outcome: String) { + frame.finishedAtMs = now + frame.outcome = outcome + for (open in frame.openSpans.entries) { + frame.lines.add(Line(now, threadName(), + "span " + open.key + " never ended (started at +" + + (open.value - frame.startedAtMs) + "ms)")) + } + frame.openSpans.clear() + addLineLocked(frame, now, "finished: $outcome") + + val root = frame.root() + if (frame.wasSent()) { + framesSent++ + // The user-visible latency is input (or timer) to the first pixels + // that actually reached the glasses, wherever in the tree that was. + if (!root.subtreeSentRecorded) { + root.subtreeSentRecorded = true + recordLatencyLocked(root, now - root.startedAtMs) + insertSlowestLocked(root) + } + } else if (outcome.startsWith("timeout")) { + framesTimedOut++ + } else { + framesDiscarded++ + } + + if (root === frame) { + recentRoots.addLast(frame) + while (recentRoots.size > RECENT_ROOTS_KEPT) { + recentRoots.removeFirst() + } + } + exportDirty = true + } + + private fun recordLatencyLocked(root: Frame, latencyMs: Long) { + val bucket = if (root.reason.startsWith("input:")) inputLatencies else renderLatencies + bucket.addLast(latencyMs) + while (bucket.size > SENT_DURATIONS_WINDOW) { + bucket.removeFirst() + } + } + + private fun insertSlowestLocked(root: Frame) { + if (!slowestRoots.contains(root)) { + slowestRoots.add(root) + } + // Sorted and trimmed at export time, when every subtree duration is final. + } + + /** {p50, p90, p99, max} over a rolling latency window, or null if empty. */ + private fun percentilesLocked(window: ArrayDeque): LongArray? { + if (window.isEmpty()) return null + val sorted: MutableList = ArrayList(window) + sorted.sort() + return longArrayOf( + percentileOfSorted(sorted, 50), + percentileOfSorted(sorted, 90), + percentileOfSorted(sorted, 99), + sorted[sorted.size - 1], + ) + } + + private fun buildExportLocked(): String { + val now = platform.elapsedRealtimeMs() + val out = StringBuilder(64 * 1024) + out.append("FrameTimings export at ").append(formatWallClock(wallClockMs())).append('\n') + out.append(statsSummaryLocked()).append('\n') + out.append('\n') + out.append("Frames are trees: an input event's own frame is the root, and the renders it\n") + out.append("caused are indented under it with offsets measured from the root's start.\n") + out.append('\n') + + // Stable sort, descending by whole-tree duration (matches Collections.sort). + slowestRoots.sortWith(compareByDescending { it.subtreeEndAtMs(now) - it.startedAtMs }) + while (slowestRoots.size > SLOWEST_ROOTS_KEPT) { + slowestRoots.removeAt(slowestRoots.size - 1) + } + + out.append("=== slowest frames that reached the glasses ===\n") + for (frame in slowestRoots) { + appendTreeLocked(out, frame, frame, now) + } + + out.append("=== recent frames (oldest first) ===\n") + for (frame in recentRoots) { + appendTreeLocked(out, frame, frame, now) + } + return out.toString() + } + + private fun statsSummaryLocked(): String { + val input = percentilesLocked(inputLatencies) + val render = percentilesLocked(renderLatencies) + val out = StringBuilder() + out.append("frames started=").append(framesStarted).append(" sent=").append(framesSent) + .append(" discarded=").append(framesDiscarded).append(" timeout=").append(framesTimedOut) + .append(" open=").append(openFrameCountLocked()) + appendPercentilesLocked(out, "input-to-display latency", inputLatencies.size, input) + appendPercentilesLocked(out, "render-to-display latency", renderLatencies.size, render) + return out.toString() + } + + private fun appendPercentilesLocked(out: StringBuilder, label: String, count: Int, percentiles: LongArray?) { + if (percentiles == null) return + out.append('\n').append(label).append(" (last ").append(count).append("): p50=") + .append(percentiles[0]).append("ms p90=").append(percentiles[1]) + .append("ms p99=").append(percentiles[2]).append("ms max=").append(percentiles[3]).append("ms") + } + + private fun openFrameCountLocked(): Int { + var open = 0 + for (frame in framesById.values) { + if (frame.isOpen()) open++ + } + return open + } + + /** Print a frame and its descendants, all timed against root's start. */ + private fun appendTreeLocked(out: StringBuilder, frame: Frame, root: Frame, now: Long) { + var depth = 0 + var walk: Frame? = frame + while (walk !== root) { + depth++ + walk = walk!!.parent + } + val indent = " ".repeat(depth) + val startOffsetMs = frame.startedAtMs - root.startedAtMs + out.append(indent).append("frame#").append(frame.id) + .append(" [").append(frame.reason).append(']') + if (frame === root) { + out.append(" started ").append(formatWallClock(frame.startedWallClockMs)) + val totalMs = frame.subtreeEndAtMs(now) - frame.startedAtMs + out.append(" duration ").append(frame.durationMs()).append("ms") + if (frame.children.isNotEmpty()) { + out.append(" (tree ").append(totalMs).append("ms") + .append(if (frame.subtreeHasOpenFrame()) ", still open" else "").append(')') + } + } else { + out.append(" started +").append(startOffsetMs).append("ms") + .append(" duration ").append(if (frame.isOpen()) "open" else (frame.durationMs().toString() + "ms")) + } + out.append(" outcome ").append(frame.outcome ?: "(open)").append('\n') + for (line in frame.lines) { + out.append(indent).append(" ").append(signedWidth7(line.atMs - root.startedAtMs)) + .append("ms [").append(line.thread).append("] ").append(line.message).append('\n') + } + for (child in frame.children) { + appendTreeLocked(out, child, root, now) + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Json.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Json.kt new file mode 100644 index 00000000..147aa751 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/Json.kt @@ -0,0 +1,161 @@ +package com.faceclaw.app + +import kotlin.jvm.JvmStatic + +/** A JSON number kept as its source text so integers and decimals survive a round trip. */ +data class JsonNumber(val text: String) { + fun toLong(): Long = text.toLongOrNull() ?: text.toDouble().toLong() + + fun toInt(): Int = toLong().toInt() + + fun toDouble(): Double = text.toDouble() + + companion object { + @JvmStatic fun of(value: Long): JsonNumber = JsonNumber(value.toString()) + + @JvmStatic fun of(value: Int): JsonNumber = JsonNumber(value.toString()) + + @JvmStatic + fun of(value: Double): JsonNumber { + require(value.isFinite()) { "JSON numbers must be finite" } + val whole = value.toLong() + return JsonNumber(if (whole.toDouble() == value) whole.toString() else value.toString()) + } + } +} + +/** + * Minimal JSON codec shared by both platforms (org.json is JVM-only). Values are + * `Map` (insertion ordered), `List`, `String`, `Boolean`, `JsonNumber` + * and `null`. `parse` also accepts `//` and block comments plus trailing commas, which the + * settings documents rely on; `write` always emits strict JSON. + */ +object Json { + private val numberPattern = Regex("-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?") + + @JvmStatic fun parse(text: String): Any? = Parser(text).parse() + + @JvmStatic fun parseObject(text: String): Map = parse(text).asObject() ?: error("JSON object expected") + + @JvmStatic fun parseArray(text: String): List = parse(text).asArray() ?: error("JSON array expected") + + @JvmStatic + fun write(value: Any?, pretty: Boolean = false): String = write(value, pretty, 0) + + @JvmStatic + fun quote(text: String): String = buildString { + append('"') + for (c in text) when (c) { + '"' -> append("\\\"") + '\\' -> append("\\\\") + '\n' -> append("\\n") + '\r' -> append("\\r") + '\t' -> append("\\t") + else -> if (c < ' ') append("\\u" + c.code.toString(16).padStart(4, '0')) else append(c) + } + append('"') + } + + private fun write(value: Any?, pretty: Boolean, depth: Int): String { + fun collection(open: String, close: String, entries: List): String { + if (entries.isEmpty()) return open + close + return if (pretty) open + "\n" + entries.joinToString(",\n") { " ".repeat(depth + 1) + it } + "\n" + " ".repeat(depth) + close + else open + entries.joinToString(",") + close + } + return when (value) { + null -> "null" + is String -> quote(value) + is Boolean -> value.toString() + is JsonNumber -> value.text + is Int -> value.toString() + is Long -> value.toString() + is Float -> JsonNumber.of(value.toDouble()).text + is Double -> JsonNumber.of(value).text + is List<*> -> collection("[", "]", value.map { write(it, pretty, depth + 1) }) + is Array<*> -> collection("[", "]", value.map { write(it, pretty, depth + 1) }) + is Map<*, *> -> collection("{", "}", value.entries.map { quote(it.key as String) + (if (pretty) ": " else ":") + write(it.value, pretty, depth + 1) }) + else -> error("Unsupported JSON value: ${value::class.simpleName}") + } + } + + private class Parser(val text: String) { + var i = 0 + fun parse(): Any? { val result = value(0); space(); require(i == text.length) { "Trailing characters in JSON" }; return result } + fun space() { + while (i < text.length) { + if (text[i] in " \r\n\t") { i++; continue } + if (text.startsWith("//", i)) { while (i < text.length && text[i] != '\n' && text[i] != '\r') i++; continue } + if (text.startsWith("/*", i)) { val end = text.indexOf("*/", i + 2); require(end >= 0); i = end + 2; continue } + break + } + } + fun take(c: Char): Boolean { space(); return if (i < text.length && text[i] == c) { i++; true } else false } + fun value(depth: Int): Any? { + require(depth < 64); space(); require(i < text.length) { "Unexpected end of JSON" } + return when (text[i]) { + '"' -> string() + '{' -> { + i++; val result = linkedMapOf() + if (!take('}')) while (true) { + space(); val key = string(); require(!result.containsKey(key)) { "Duplicate key $key" }; require(take(':')) + result[key] = value(depth + 1) + if (take('}')) break + require(take(',')); if (take('}')) break + } + result + } + '[' -> { + i++; val result = mutableListOf() + if (!take(']')) while (true) { + result.add(value(depth + 1)); if (take(']')) break + require(take(',')); if (take(']')) break + } + result + } + 't' -> literal("true", true) + 'f' -> literal("false", false) + 'n' -> literal("null", null) + else -> { + val match = numberPattern.find(text, i) + require(match != null && match.range.first == i) { "Invalid JSON value at $i" } + require(match.value.toDouble().isFinite()); i += match.value.length; JsonNumber(match.value) + } + } + } + fun literal(word: String, result: Any?): Any? { require(text.startsWith(word, i)); i += word.length; return result } + fun string(): String { + require(i < text.length && text[i++] == '"') + return buildString { + while (true) { + require(i < text.length); val c = text[i++] + if (c == '"') break + require(c >= ' ') + if (c != '\\') { append(c); continue } + require(i < text.length) + append(when (val escaped = text[i++]) { + '"', '\\', '/' -> escaped + 'b' -> '\b'; 'f' -> '\u000c'; 'n' -> '\n'; 'r' -> '\r'; 't' -> '\t' + 'u' -> { require(i + 4 <= text.length); val hex = text.substring(i, i + 4); require(hex.all { it in "0123456789abcdefABCDEF" }); val code = hex.toInt(16); i += 4; code.toChar() } + else -> error("Invalid escape") + }) + } + } + } + } +} + +// Typed accessors for parsed values; each returns null when the value has another type. +@Suppress("UNCHECKED_CAST") +fun Any?.asObject(): Map? = this as? Map + +fun Any?.asArray(): List? = this as? List + +fun Any?.asString(): String? = this as? String + +fun Any?.asBoolean(): Boolean? = this as? Boolean + +fun Any?.asLong(): Long? = (this as? JsonNumber)?.toLong() ?: (this as? Long) ?: (this as? Int)?.toLong() + +fun Any?.asInt(): Int? = asLong()?.toInt() + +fun Any?.asDouble(): Double? = (this as? JsonNumber)?.toDouble() ?: (this as? Double) ?: (this as? Int)?.toDouble() ?: (this as? Long)?.toDouble() diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/PlatformUtil.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/PlatformUtil.kt new file mode 100644 index 00000000..a7813a56 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/PlatformUtil.kt @@ -0,0 +1,30 @@ +package com.faceclaw.app + +/** Incremental SHA-256; [digest] finishes the hash. */ +expect class Sha256Digest() { + fun update(bytes: ByteArray, offset: Int, length: Int) + + fun digest(): ByteArray +} + +fun Sha256Digest.update(bytes: ByteArray) = update(bytes, 0, bytes.size) + +fun sha256(bytes: ByteArray): ByteArray = Sha256Digest().also { it.update(bytes) }.digest() + +fun sha256Hex(bytes: ByteArray): String = BinaryEncoding.bytesToHex(sha256(bytes)) + +/** Wall-clock milliseconds since the Unix epoch (may jump; use ProtocolPlatform for intervals). */ +expect fun currentTimeMillis(): Long + +/** Formats [epochMs] in local time with a Unicode/SimpleDateFormat-style [pattern] (e.g. "yyyyMMdd-HHmmss-SSS"). */ +expect fun formatLocalTime(epochMs: Long, pattern: String): String + +expect object PlatformLog { + fun i(tag: String, message: String) + + fun w(tag: String, message: String) + + fun e(tag: String, message: String, error: Throwable?) +} + +fun PlatformLog.e(tag: String, message: String) = e(tag, message, null) diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt new file mode 100644 index 00000000..27f43702 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt @@ -0,0 +1,105 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import kotlinx.cinterop.addressOf +import kotlinx.cinterop.alloc +import kotlinx.cinterop.convert +import kotlinx.cinterop.free +import kotlinx.cinterop.memScoped +import kotlinx.cinterop.nativeHeap +import kotlinx.cinterop.ptr +import kotlinx.cinterop.reinterpret +import kotlinx.cinterop.usePinned +import platform.CoreCrypto.CC_SHA256_CTX +import platform.CoreCrypto.CC_SHA256_DIGEST_LENGTH +import platform.CoreCrypto.CC_SHA256_Final +import platform.CoreCrypto.CC_SHA256_Init +import platform.CoreCrypto.CC_SHA256_Update +import platform.Foundation.NSDate +import platform.Foundation.NSDateFormatter +import platform.Foundation.NSLocale +import platform.Foundation.NSLog +import platform.Foundation.NSThread +import platform.Foundation.dateWithTimeIntervalSince1970 +import platform.Foundation.timeIntervalSince1970 +import platform.posix.F_OK +import platform.posix.access +import platform.posix.fclose +import platform.posix.fopen +import platform.posix.fwrite +import platform.posix.rename +import platform.posix.stat +import platform.posix.unlink +import platform.posix.usleep + +actual class Sha256Digest actual constructor() { + private var context = nativeHeap.alloc().also { CC_SHA256_Init(it.ptr) } + private var finished = false + + actual fun update(bytes: ByteArray, offset: Int, length: Int) { + check(!finished) { "digest already finished" } + if (length == 0) return + bytes.usePinned { CC_SHA256_Update(context.ptr, it.addressOf(offset), length.convert()) } + } + + actual fun digest(): ByteArray { + check(!finished) { "digest already finished" } + val out = ByteArray(CC_SHA256_DIGEST_LENGTH) + out.usePinned { CC_SHA256_Final(it.addressOf(0).reinterpret(), context.ptr) } + nativeHeap.free(context.ptr) + finished = true + return out + } +} + +actual fun currentTimeMillis(): Long = (NSDate().timeIntervalSince1970 * 1000.0).toLong() + +actual fun formatLocalTime(epochMs: Long, pattern: String): String { + val formatter = NSDateFormatter() + formatter.locale = NSLocale("en_US_POSIX") + formatter.dateFormat = pattern + return formatter.stringFromDate(NSDate.dateWithTimeIntervalSince1970(epochMs / 1000.0)) +} + +actual object PlatformLog { + actual fun i(tag: String, message: String) = NSLog("%@", "$tag: $message") + + actual fun w(tag: String, message: String) = NSLog("%@", "$tag: [warn] $message") + + actual fun e(tag: String, message: String, error: Throwable?) = + NSLog("%@", "$tag: [error] $message" + (error?.let { " (${it.message})" } ?: "")) +} + +actual fun startThread(name: String, daemon: Boolean, body: () -> Unit) { + val thread = NSThread(block = body) + thread.name = name + thread.start() +} + +actual fun sleepMs(ms: Long) { + if (ms > 0) usleep((ms * 1000).convert()) +} + +actual fun writeFileData(path: String, bytes: ByteArray) { + val file = fopen(path, "wb") ?: error("Cannot write $path") + try { + if (bytes.isNotEmpty()) + bytes.usePinned { + check(fwrite(it.addressOf(0), 1u, bytes.size.convert(), file) == bytes.size.convert()) { "Short write to $path" } + } + } finally { + fclose(file) + } +} + +actual fun fileExists(path: String): Boolean = access(path, F_OK) == 0 + +actual fun fileLength(path: String): Long = memScoped { + val info = alloc() + if (stat(path, info.ptr) != 0) -1L else info.st_size +} + +actual fun deleteFile(path: String): Boolean = unlink(path) == 0 + +actual fun renameFile(from: String, to: String): Boolean = rename(from, to) == 0 diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/g2protocol/IosProtocolPlatform.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/g2protocol/IosProtocolPlatform.kt index 3b24fcca..4db40e9f 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/g2protocol/IosProtocolPlatform.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/g2protocol/IosProtocolPlatform.kt @@ -10,7 +10,10 @@ import kotlinx.cinterop.* import platform.CoreBluetooth.CBCharacteristicWriteType import platform.CoreBluetooth.CBCharacteristicWriteWithResponse import platform.CoreBluetooth.CBCharacteristicWriteWithoutResponse +import platform.Foundation.NSCondition +import platform.Foundation.NSDate import platform.Foundation.NSRecursiveLock +import platform.Foundation.dateWithTimeIntervalSinceNow import platform.posix.CLOCK_MONOTONIC_RAW import platform.posix.clock_gettime_nsec_np import platform.posix.memset @@ -32,6 +35,21 @@ object IosProtocolPlatform : ProtocolPlatform { override fun createDeflater(): ProtocolDeflater = IosDeflater() + override fun createCondition(): ProtocolCondition = + object : ProtocolCondition { + private val condition = NSCondition() + + override fun lock() = condition.lock() + + override fun unlock() = condition.unlock() + + override fun awaitMs(timeoutMs: Long) { + if (timeoutMs > 0) condition.waitUntilDate(NSDate.dateWithTimeIntervalSinceNow(timeoutMs / 1000.0)) + } + + override fun signalAll() = condition.broadcast() + } + fun writeType(mode: GattWriteMode): CBCharacteristicWriteType = when (mode) { GattWriteMode.WITH_RESPONSE -> CBCharacteristicWriteWithResponse diff --git a/tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/FrameTimingsFormatTest.kt b/tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/FrameTimingsFormatTest.kt new file mode 100644 index 00000000..312d43bf --- /dev/null +++ b/tests/kotlin/src/androidHostTest/kotlin/com/faceclaw/app/FrameTimingsFormatTest.kt @@ -0,0 +1,33 @@ +package com.faceclaw.app + +import java.util.Locale +import kotlin.test.Test +import kotlin.test.assertEquals + +/** The shared export must match what the Java-era String.format("%+7d") produced. */ +class FrameTimingsFormatTest { + private class FakeClock : ProtocolPlatform by AndroidProtocolPlatform { + var nowMs = 5_000L + override fun elapsedRealtimeMs(): Long = nowMs + } + + @Test + fun lineOffsetsMatchJavaFormat() { + val clock = FakeClock() + val core = FrameTimingsCore(clock, wallClockMs = { 0L }, threadName = { "worker" }, formatWallClock = { "w" }, logInfo = {}, logWarn = {}) + val offsets = listOf(-1_234_567L, -12L, -1L, 0L, 1L, 42L, 999L, 1_000L, 12_345L, 1_234_567L, 12_345_678L) + val root = core.startFrame("input:fmt") + for (offset in offsets) { + clock.nowMs = 5_000L + offset + core.log(root, "o=$offset") + } + clock.nowMs = 5_000L + core.finishFrame(root, "sent") + val export = core.buildExport() + for (offset in offsets) { + val javaLine = String.format(Locale.US, " %+7dms [%s] %s", offset, "worker", "o=$offset") + assert(export.contains("\n$javaLine\n")) { "missing <$javaLine> in\n$export" } + } + assertEquals(2, export.split("\n").count { it.contains("finished: sent") }) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmRingingPolicyTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmRingingPolicyTest.kt new file mode 100644 index 00000000..0dda856b --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmRingingPolicyTest.kt @@ -0,0 +1,123 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +private class FakeScheduler : AlarmScheduler { + val pending = LinkedHashMap Unit>>() + override fun postDelayed(token: Any, delayMs: Long, action: () -> Unit) { pending[token] = delayMs to action } + override fun cancel(token: Any) { pending.remove(token) } + override fun cancelAll() { pending.clear() } + fun fire(token: Any) { val entry = pending.remove(token) ?: error("no timer $token"); entry.second() } +} + +private class FakeSink : RingingSink { + val events = ArrayList() + var sounding = false + override fun showNotification(item: RingingItem) { events.add("notify ${item.id} " + (if (item.silenced) "silenced" else if (item.escalated) "ringing" else "glasses")) } + override fun itemRemoved(item: RingingItem) { events.add("removed ${item.id}") } + override fun ringingStarted() { events.add("wake") } + override fun startSound() { if (!sounding) { sounding = true; events.add("sound on") } } + override fun stopSound() { if (sounding) { sounding = false; events.add("sound off") } } + override fun reschedule(item: RingingItem, atMs: Long, minutes: Int) { events.add("reschedule ${item.id} $atMs $minutes") } + override fun cancelSchedule(id: Long) { events.add("cancel $id") } + override fun recordPhoneAction(id: Long, action: String, minutes: Int) { events.add("action $id $action $minutes") } + override fun log(line: String) { events.add("log $line") } +} + +class AlarmRingingPolicyTest { + private var now = 5_000_000L + private val gate = GlassesStatusGate { now } + private val scheduler = FakeScheduler() + private val sink = FakeSink() + private val policy = AlarmRingingPolicy(gate, { now }, testPlatform()).also { it.attach(scheduler, sink) } + + private fun item(id: Long, kind: String = AlarmSchedule.KIND_ALARM) = RingingItem(id, "Wake", "", kind, 9, now) + + @Test + fun glassesUnavailableEscalatesImmediately() { + policy.ring(item(1)) + assertEquals(listOf("log ring alarm 1 (no glasses status)", "wake", "notify 1 glasses", "log phone sound for 1: no glasses status", "notify 1 ringing", "sound on"), sink.events) + assertTrue(policy.isRinging(1)) + assertEquals(setOf("silence:1"), scheduler.pending.keys) + scheduler.fire("silence:1") + assertEquals(listOf("log auto-silenced 1", "notify 1 silenced", "sound off"), sink.events.drop(6)) + } + + @Test + fun deliveryAndAcknowledgementTimersEscalate() { + gate.set(connected = true, worn = true, charging = false) + policy.ring(item(2)) + assertEquals(listOf("log ring alarm 2 (glasses worn)", "wake", "notify 2 glasses"), sink.events) + assertEquals(setOf("delivery:2"), scheduler.pending.keys) + policy.markDelivered(2) + assertEquals("log delivered 2 to glasses", sink.events.last()) + assertEquals(setOf("delivery:2", "ack:2"), scheduler.pending.keys) + scheduler.fire("delivery:2") // delivered in time: no escalation + assertFalse(policy.snapshot().single().escalated) + scheduler.fire("ack:2") + assertTrue(policy.snapshot().single().escalated) + assertTrue(sink.sounding) + // Acknowledged on the glasses afterwards: quiet stop, sound off. + policy.stopQuietly(2, "acknowledged") + assertEquals(listOf("log acknowledged 2", "removed 2", "sound off"), sink.events.takeLast(3)) + assertFalse(policy.isAnythingRinging()) + } + + @Test + fun undeliveredRingEscalatesAfterDeliveryWait() { + gate.set(connected = true, worn = true, charging = false) + policy.ring(item(3)) + scheduler.fire("delivery:3") + assertEquals("log phone sound for 3: not delivered to the glasses", sink.events[3]) + assertTrue(sink.sounding) + } + + @Test + fun snoozeAndDismissRecordActionsAndRearm() { + policy.ring(item(4, AlarmSchedule.KIND_TIMER)) + policy.snooze(4) + assertEquals(listOf("action 4 snooze 9", "removed 4", "sound off", "reschedule 4 ${now + 9 * 60_000L} 9"), sink.events.takeLast(4)) + policy.ring(item(5)) + policy.dismiss(5) + assertEquals(listOf("action 5 dismiss 0", "removed 5", "sound off", "cancel 5"), sink.events.takeLast(4)) + policy.dismiss(99) // unknown: no-op + assertEquals("cancel 5", sink.events.last()) + } + + @Test + fun earlySignalsAreConsumedOrExpire() { + gate.set(connected = true, worn = true, charging = false) + assertFalse(policy.deliveredOrDefer(6)) + policy.ring(item(6)) + assertEquals("log delivered 6 to glasses", sink.events.last()) + assertEquals(setOf("ack:6"), scheduler.pending.keys) + + assertFalse(policy.stopOrDefer(7)) + policy.ring(item(7)) + assertEquals("log ring 7 already acknowledged", sink.events.last()) + assertFalse(policy.isRinging(7)) + + assertFalse(policy.stopOrDefer(8)) + now += AlarmRingingPolicy.EARLY_SIGNAL_MAX_AGE_MS + 1 + policy.ring(item(8)) + assertTrue(policy.isRinging(8)) + assertTrue(policy.stopOrDefer(8)) + assertTrue(policy.deliveredOrDefer(8)) + } + + @Test + fun duplicateRingOnlyRefreshesNotificationAndDetachDropsTimers() { + policy.ring(item(9)) + val before = sink.events.size + policy.ring(item(9)) + assertEquals(listOf("notify 9 ringing"), sink.events.drop(before)) + assertEquals(1, policy.snapshot().size) + policy.detach() + assertTrue(scheduler.pending.isEmpty()) + policy.ring(item(10)) // no host: ignored + assertFalse(policy.isRinging(10)) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmScheduleTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmScheduleTest.kt new file mode 100644 index 00000000..d8cd493b --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AlarmScheduleTest.kt @@ -0,0 +1,109 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +private class MemoryStore : AlarmStore { + val values = HashMap() + override fun read(key: String): String? = values[key] + override fun write(key: String, value: String?) { values[key] = value } +} + +class AlarmScheduleTest { + private val store = MemoryStore() + private var now = 1_700_000_000_000L + private val schedule = AlarmSchedule(store, { now }, testPlatform()) + + @Test + fun persistsEntriesAsJsonAndReplacesById() { + schedule.put(AlarmEntry(7, now + 60_000, "Tea", "steep", AlarmSchedule.KIND_TIMER, 5)) + schedule.put(AlarmEntry(8, now + 120_000, null, null, null, 10)) + assertEquals("""[{"id":7,"at":${now + 60_000},"title":"Tea","text":"steep","kind":"timer","snoozeMinutes":5},{"id":8,"at":${now + 120_000},"title":"","text":"","kind":"alarm","snoozeMinutes":10}]""", store.values[AlarmSchedule.KEY_SCHEDULED]) + schedule.put(AlarmEntry(7, now + 90_000, "Tea", "steep", AlarmSchedule.KIND_TIMER, 5)) + assertEquals(listOf(8L, 7L), schedule.entries().map { it.id }) + assertEquals(now + 90_000, schedule.find(7)?.at) + schedule.remove(8) + assertNull(schedule.find(8)) + // A corrupt file reads as empty rather than failing. + store.values[AlarmSchedule.KEY_SCHEDULED] = "{nope" + assertTrue(schedule.entries().isEmpty()) + } + + @Test + fun replayRingsRecentDropsMissedArmsFuture() { + schedule.put(AlarmEntry(1, now - 60_000, "recent", "", null, 10)) + schedule.put(AlarmEntry(2, now - AlarmSchedule.LATE_GRACE_MS - 1, "old", "", AlarmSchedule.KIND_TIMER, 10)) + schedule.put(AlarmEntry(3, now + 60_000, "future", "", null, 10)) + val rang = ArrayList() + val armed = ArrayList() + schedule.replay("boot", { rang.add(it.id) }, { armed.add(it.id) }) + assertEquals(listOf(1L), rang) + assertEquals(listOf(3L), armed) + assertEquals(listOf(1L, 3L), schedule.entries().map { it.id }) + val log = schedule.readLog() + assertTrue(log.contains("$now missed timer 2 (boot)"), log) + assertTrue(log.endsWith("$now rescheduled 1 (boot)"), log) + } + + @Test + fun stalenessComparesSoonestPendingWithSystemAlarm() { + assertFalse(schedule.looksStale(null)) + schedule.put(AlarmEntry(1, now - 1, "past", "", null, 10)) + assertNull(schedule.soonestPendingAt()) + schedule.put(AlarmEntry(2, now + 50_000, "", "", null, 10)) + schedule.put(AlarmEntry(3, now + 20_000, "", "", null, 10)) + assertEquals(now + 20_000, schedule.soonestPendingAt()) + assertTrue(schedule.looksStale(null)) + assertTrue(schedule.looksStale(now + 30_000)) + assertFalse(schedule.looksStale(now + 20_500)) + assertFalse(schedule.looksStale(now + 5_000)) + } + + @Test + fun journalAppendsAndDrains() { + schedule.appendJournal(5, "snooze", 10) + now += 1000 + schedule.appendJournal(6, "dismiss", 0) + assertEquals("""[{"id":5,"action":"snooze","minutes":10,"at":${now - 1000}},{"id":6,"action":"dismiss","minutes":0,"at":$now}]""", schedule.drainJournal()) + assertEquals("[]", schedule.drainJournal()) + val log = schedule.readLog().lines() + assertEquals("${now - 1000} phone snooze 5 (10 min)", log[0]) + assertEquals("$now phone dismiss 6", log[1]) + } + + @Test + fun logKeepsOnlyTheLastLines() { + for (index in 0 until AlarmSchedule.LOG_LINES + 5) schedule.log("line $index") + val lines = schedule.readLog().lines() + assertEquals(AlarmSchedule.LOG_LINES, lines.size) + assertEquals("$now line 5", lines.first()) + assertEquals("$now line ${AlarmSchedule.LOG_LINES + 4}", lines.last()) + } + + @Test + fun glassesGateRequiresFreshWornConnectedNotCharging() { + var clock = 10_000L + val gate = GlassesStatusGate { clock } + assertFalse(gate.canCarryAlarm()) + assertEquals("no glasses status", gate.description()) + gate.set(connected = true, worn = true, charging = false) + assertTrue(gate.canCarryAlarm()) + assertEquals("glasses worn", gate.description()) + gate.set(connected = true, worn = false, charging = false) + assertEquals("glasses not worn", gate.description()) + gate.set(connected = true, worn = true, charging = true) + assertEquals("glasses charging", gate.description()) + gate.set(connected = false, worn = true, charging = false) + assertEquals("glasses not connected", gate.description()) + gate.set(connected = true, worn = true, charging = false) + clock += GlassesStatusGate.MAX_AGE_MS + 1 + assertFalse(gate.canCarryAlarm()) + assertEquals("glasses status stale", gate.description()) + assertEquals(0x7fffffff and (0x1_0000_0002L xor 1L).toInt(), AlarmSchedule.requestCode(0x1_0000_0002L)) + assertNotNull(AlarmEntry.fromJson(Json.parse("""{"id":1,"at":2}"""))) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AudioHelpersTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AudioHelpersTest.kt new file mode 100644 index 00000000..8c4d7a0a --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/AudioHelpersTest.kt @@ -0,0 +1,130 @@ +package com.faceclaw.app + +import kotlin.math.abs +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class AudioHelpersTest { + @Test + fun cutPointLandsInQuietestWindowForFloatsAndShorts() { + // 1000 loud samples with a silent gap at 700..760; search the last 500 with a 40 window. + val floats = FloatArray(1000) { if (it in 700 until 760) 0f else 0.5f } + val cut = AudioSegmentation.quietestCutPoint(floats, floats.size, 500, 40) + assertTrue(cut in 700..760, "cut=$cut") + val shorts = ShortArray(1100) { if (it - 100 in 700 until 760) 0 else 16000 } + assertEquals(cut, AudioSegmentation.quietestCutPoint(shorts, 100, 1000, 500, 40)) + // Too short to search: returns the length unchanged. + assertEquals(30, AudioSegmentation.quietestCutPoint(FloatArray(30) { 0.1f }, 30, 500, 40)) + } + + @Test + fun normalizePeakScalesUpButNeverDown() { + val quiet = floatArrayOf(0.01f, -0.02f, 0.005f) + AudioSegmentation.normalizePeak(quiet, 0.9f, 30f) + assertTrue(abs(quiet[1] + 0.6f) < 1e-6f, "capped at maxGain 30: ${quiet[1]}") + val loud = floatArrayOf(0.95f, -0.5f) + AudioSegmentation.normalizePeak(loud, 0.9f, 30f) + assertEquals(0.95f, loud[0]) + val silent = FloatArray(4) + AudioSegmentation.normalizePeak(silent, 0.9f, 30f) + assertEquals(0f, AudioSegmentation.peakAmplitude(silent)) + } + + @Test + fun pcmConversionsRoundTrip() { + val samples = shortArrayOf(0, 1, -1, 32767, -32768, 256) + val le = AudioSegmentation.pcm16ToLittleEndian(samples, 0, samples.size) + assertEquals(listOf(0, 0, 1, 0, 0xff, 0xff, 0xff, 0x7f, 0, 0x80, 0, 1), le.map { it.toInt() and 0xff }) + val floats = AudioSegmentation.pcm16leToFloat(le) + assertEquals(AudioSegmentation.pcm16ToFloat(samples, 0, samples.size).toList(), floats.toList()) + assertEquals(32767 / 32768.0f, floats[3]) + assertEquals(-1f, floats[4]) + assertEquals(2.0, AudioSegmentation.rms(shortArrayOf(2, -2, 2, -2), 0, 4)) + } + + @Test + fun voicePrintMathAndBlobCodec() { + val v = floatArrayOf(3f, 4f) + VoicePrint.l2Normalize(v) + assertEquals(listOf(0.6f, 0.8f), v.toList()) + assertTrue(abs(VoicePrint.dot(v, v) - 1.0) < 1e-6) + assertNull(VoicePrint.l2Normalize(null)) + assertTrue(VoicePrint.isLongEnoughToEmbed(16000, 16000)) + assertTrue(!VoicePrint.isLongEnoughToEmbed(15999, 16000)) + + val blob = SpeakerEmbeddings.floatsToBlob(floatArrayOf(1.5f, -2f)) + assertEquals(listOf(0, 0, 0xc0, 0x3f, 0, 0, 0, 0xc0), blob.map { it.toInt() and 0xff }) + assertEquals(listOf(1.5f, -2f), SpeakerEmbeddings.blobToFloats(blob)!!.toList()) + assertNull(SpeakerEmbeddings.blobToFloats(byteArrayOf(1, 2, 3))) + assertNull(SpeakerEmbeddings.blobToFloats(null)) + } + + @Test + fun centroidUpdatesAndBlends() { + val first = SpeakerEmbeddings.runningMean(null, 0, floatArrayOf(1f, 0f), 5) + assertEquals(1, first.count) + assertEquals(listOf(1f, 0f), first.embedding.toList()) + val second = SpeakerEmbeddings.runningMean(first.embedding, first.count, floatArrayOf(0f, 1f), 5) + assertEquals(2, second.count) + assertTrue(abs(second.embedding[0] - second.embedding[1]) < 1e-6f) + assertTrue(abs(VoicePrint.dot(second.embedding, second.embedding) - 1.0) < 1e-6) + // The cap limits the existing weight: count 100 capped at 1 behaves like an equal blend. + val capped = SpeakerEmbeddings.runningMean(floatArrayOf(1f, 0f), 100, floatArrayOf(0f, 1f), 1) + assertTrue(abs(capped.embedding[0] - capped.embedding[1]) < 1e-6f) + assertEquals(101, capped.count) + // Mismatched sizes restart the centroid. + assertEquals(1, SpeakerEmbeddings.runningMean(floatArrayOf(1f), 4, floatArrayOf(0f, 1f), 5).count) + + val blended = SpeakerEmbeddings.blend(floatArrayOf(1f, 0f), 1, floatArrayOf(0f, 1f), 3) + assertNotNull(blended) + assertTrue(blended[1] > blended[0]) + assertEquals(listOf(0f, 1f), SpeakerEmbeddings.blend(null, 0, floatArrayOf(0f, 1f), 3)!!.toList()) + assertEquals(listOf(1f, 0f), SpeakerEmbeddings.blend(floatArrayOf(1f, 0f), 2, null, 0)!!.toList()) + assertNull(SpeakerEmbeddings.blend(null, 0, null, 0)) + assertTrue(SpeakerEmbeddings.shouldAdoptInsights(targetHasInsights = false, sourceHasInsights = true)) + assertTrue(!SpeakerEmbeddings.shouldAdoptInsights(targetHasInsights = true, sourceHasInsights = true)) + } + + private fun wav(dataSize: Int, extraChunk: Boolean = false, channels: Int = 1, bits: Int = 16, format: Int = 1): ByteArray { + val out = ByteSink() + fun u16(v: Int) { out.write(v); out.write(v ushr 8) } + fun u32(v: Int) { u16(v); u16(v ushr 16) } + out.write("RIFF".encodeToByteArray()); u32(0); out.write("WAVE".encodeToByteArray()) + if (extraChunk) { out.write("LIST".encodeToByteArray()); u32(4); u32(0) } + out.write("fmt ".encodeToByteArray()); u32(18) + u16(format); u16(channels); u32(16000); u32(16000 * channels * 2); u16(channels * 2); u16(bits); u16(0) + out.write("data".encodeToByteArray()); u32(dataSize) + return out.toByteArray() + } + + @Test + fun wavHeaderParsesChunksAndRecoversZeroSize() { + val header = wav(4000) + val info = WavPcmReader.parseHeader(header, header.size + 4000L) + assertEquals(16000, info.sampleRate) + assertEquals(1, info.channels) + assertEquals(16, info.bitsPerSample) + assertEquals(header.size.toLong(), info.dataOffset) + assertEquals(4000L, info.dataBytes) + + val withList = wav(100, extraChunk = true) + assertEquals(withList.size.toLong(), WavPcmReader.parseHeader(withList, withList.size + 100L).dataOffset) + + val unpatched = wav(0) + assertEquals(1234L, WavPcmReader.parseHeader(unpatched, unpatched.size + 1234L).dataBytes) + + assertFailsWith { WavPcmReader.parseHeader("RIFX".encodeToByteArray() + ByteArray(20), 24) } + assertFailsWith { WavPcmReader.parseHeader(wav(10, bits = 8), 100) } + assertFailsWith { WavPcmReader.parseHeader(wav(10, format = 3), 100) } + assertFailsWith { WavPcmReader.parseHeader(wav(10).copyOf(20), 100) } + // The shared header matches the shared writer. + val written = BinaryEncoding.wavHeader(640, 16000, 1) + val parsed = WavPcmReader.parseHeader(written, 44 + 640L) + assertEquals(44L, parsed.dataOffset) + assertEquals(640L, parsed.dataBytes) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/CaptionEngineCoreTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/CaptionEngineCoreTest.kt new file mode 100644 index 00000000..486d4130 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/CaptionEngineCoreTest.kt @@ -0,0 +1,127 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class CaptionEngineCoreTest { + private class Sink : CaptionSegmentSink { + val starts = mutableListOf() + val utterances = mutableListOf>() + override fun onSpeechStart(startMs: Long) { starts.add(startMs) } + override fun onUtterance(samples: ShortArray, length: Int, startMs: Long, endMs: Long, peakRms: Double) { + utterances.add(listOf(length, startMs, endMs, samples[0].toInt())) + } + } + + private fun chunk(amplitude: Int, samples: Int = 800): ShortArray = + ShortArray(samples) { if (it % 2 == 0) amplitude.toShort() else (-amplitude).toShort() } + + @Test + fun segmenterUsesPreRollOnsetReleaseAndSilence() { + val sink = Sink() + val segmenter = CaptionSegmenter(sink) + repeat(10) { segmenter.processChunk(chunk(100), 800) } // 500 ms idle, noise floor ~100 -> threshold 220 + repeat(10) { segmenter.processChunk(chunk(3000), 800) } // 500 ms speech + assertEquals(listOf(100L), sink.starts) // 500 ms - 400 ms pre-roll + repeat(15) { segmenter.processChunk(chunk(100), 800) } // 750 ms < 800 ms silence: still open + assertTrue(sink.utterances.isEmpty()) + segmenter.processChunk(chunk(100), 800) // 800 ms of silence closes it + assertEquals(1, sink.utterances.size) + val (length, startMs, endMs, first) = sink.utterances[0] + assertEquals(100L, startMs) + assertEquals(6400 + 10 * 800 + 16 * 800, length) // pre-roll + speech + trailing silence + assertEquals(startMs as Long + (length as Int) * 1000L / 16000, endMs) + assertEquals(100, first) // the pre-roll audio leads the utterance + assertTrue(segmenter.isInUtterance.not()) + } + + @Test + fun segmenterDropsTooShortUtterancesAndCapsLength() { + val sink = Sink() + val segmenter = CaptionSegmenter(sink) + segmenter.silenceMs = 100 // clamps to 200 + segmenter.processChunk(chunk(10), 800) // seeds the noise floor; becomes the 50 ms pre-roll + segmenter.processChunk(chunk(3000), 800) // onset + repeat(4) { segmenter.processChunk(chunk(0), 800) } // 200 ms silence + assertEquals(1, sink.starts.size) + assertTrue(sink.utterances.isEmpty()) // 300 ms < 350 ms minimum + repeat(400) { segmenter.processChunk(chunk(3000), 800) } // 20 s of speech: capped at 15 s + assertEquals(1, sink.utterances.size) + assertEquals(16000 * 15, sink.utterances[0][0]) + segmenter.flush() + assertEquals(2, sink.utterances.size) // the remainder is flushed on stop + } + + @Test + fun utteranceDecoderSplitsLongAudioAndEmbedsTenSeconds() { + val calls = mutableListOf() + val transcriber = object : OfflineTranscriber { + override fun recognize(samples: FloatArray, count: Int): String { calls.add(count); return if (calls.size == 2) ", b" else "a" } + override fun release() {} + } + var embedded = 0 + val embedder = object : SpeakerEmbedder { + override fun embed(pcm16le: ByteArray, sampleRate: Int): FloatArray? { embedded = pcm16le.size; return floatArrayOf(1f) } + override fun release() {} + } + val decoder = UtteranceDecoder(transcriber, embedder) + val utterance = ShortArray(16000 * 12) { if (it % 2 == 0) 2000 else -2000 } + assertEquals("a, b", decoder.recognize(utterance, utterance.size)) + assertEquals(2, calls.size) + assertTrue(calls[0] <= UtteranceDecoder.DECODE_SEGMENT_MAX_SAMPLES) + assertEquals(utterance.size, calls.sum()) + assertNotNull(decoder.embed(utterance, utterance.size)) + assertEquals(16000 * 10 * 2, embedded) + assertEquals("", UtteranceDecoder(null, null).recognize(utterance, utterance.size)) + assertNull(UtteranceDecoder(null, null).embed(utterance, utterance.size)) + } + + @Test + fun captionSessionRunsQueueThroughSegmenterAndDecoder() { + val startLatch = Latch(1, testPlatform()) + val utteranceLatch = Latch(1, testPlatform()) + val events = mutableListOf() + val listener = object : FaceclawCaptionEngineListener { + override fun onUtterance(text: String?, embedding: FloatArray?, startMs: Long, endMs: Long, peakRms: Double) { + events.add("utterance:$text:${embedding?.size}:$startMs"); utteranceLatch.countDown() + } + override fun onSpeechStart(startMs: Long) { events.add("start:$startMs"); startLatch.countDown() } + override fun onStatus(status: String?) { events.add("status:$status") } + } + val host = object : CaptionHost { + override val dispatcher = CallbackDispatcher { it() } + override fun loadTranscriber(modelDir: String): OfflineTranscriber? = if (modelDir == "models") object : OfflineTranscriber { + override fun recognize(samples: FloatArray, count: Int): String = "hi" + override fun release() {} + } else null + override fun loadEmbedder(modelPath: String): SpeakerEmbedder? = object : SpeakerEmbedder { + override fun embed(pcm16le: ByteArray, sampleRate: Int): FloatArray? = floatArrayOf(0.5f, 0.5f) + override fun release() {} + } + } + val session = CaptionSession(host, testPlatform(), "caption-test") { m, e -> error("$m: $e") } + session.setListener(listener) + session.setAsrModelDir("models") + session.setSpeakerModelPath("speaker") + session.setSilenceMs(300) + session.acceptPcm(ByteArray(1600)) // ignored before start + session.start() + val loud = AudioSegmentation.pcm16ToLittleEndian(chunk(3000), 0, 800) + val quiet = AudioSegmentation.pcm16ToLittleEndian(chunk(0), 0, 800) + val idle = AudioSegmentation.pcm16ToLittleEndian(chunk(10), 0, 800) + repeat(2) { session.acceptPcm(idle) } // seeds the noise floor and fills 100 ms of pre-roll + repeat(10) { session.acceptPcm(loud) } + assertTrue(startLatch.await(5000)) + repeat(8) { session.acceptPcm(quiet) } + assertTrue(utteranceLatch.await(5000)) + session.stop() + session.stop() // idempotent + assertEquals("status:Loading caption model...", events[0]) + assertEquals("status:Captions listening...", events[1]) + assertEquals("start:0", events[2]) + assertEquals("utterance:hi:2:0", events[3]) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/EvenHubAssetServerTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/EvenHubAssetServerTest.kt new file mode 100644 index 00000000..b064efb2 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/EvenHubAssetServerTest.kt @@ -0,0 +1,47 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class EvenHubAssetServerTest { + @Test + fun resolvesPathsWithIndexDefaultAndEscapeChecks() { + assertEquals("index.html", EvenHubAssetServer.resolve(null)!!.relativePath) + assertEquals("index.html", EvenHubAssetServer.resolve("")!!.relativePath) + assertEquals("index.html", EvenHubAssetServer.resolve("/")!!.relativePath) + assertEquals("assets/app.js", EvenHubAssetServer.resolve("/assets/app.js")!!.relativePath) + assertEquals("assets/app.js", EvenHubAssetServer.resolve("/assets/./x/../app.js")!!.relativePath) + assertNull(EvenHubAssetServer.resolve("/../secret")) + assertNull(EvenHubAssetServer.resolve("/a/../../secret")) + assertNull(EvenHubAssetServer.resolve("/..")) + assertTrue(EvenHubAssetServer.resolve("/index.html")!!.isHtml) + assertTrue(EvenHubAssetServer.isInsideRoot("/apps/x", "/apps/x/index.html")) + assertTrue(EvenHubAssetServer.isInsideRoot("/apps/x/", "/apps/x/a/b")) + assertEquals(false, EvenHubAssetServer.isInsideRoot("/apps/x", "/apps/xy/index.html")) + assertEquals(false, EvenHubAssetServer.isInsideRoot("/apps/x", "/apps/index.html")) + } + + @Test + fun mimeTableCoversBothPlatformsTables() { + assertEquals("text/html", EvenHubAssetServer.mimeTypeFor("Index.HTM")) + assertEquals("text/javascript", EvenHubAssetServer.mimeTypeFor("bundle.mjs")) + assertEquals("application/wasm", EvenHubAssetServer.mimeTypeFor("core.wasm")) + assertEquals("font/woff2", EvenHubAssetServer.mimeTypeFor("a.woff2")) + assertEquals("image/svg+xml", EvenHubAssetServer.mimeTypeFor("icon.svg")) + assertEquals("text/plain", EvenHubAssetServer.mimeTypeFor("bundle.js.map")) + assertEquals("application/octet-stream", EvenHubAssetServer.mimeTypeFor("blob")) + assertEquals("application/octet-stream", EvenHubAssetServer.mimeTypeFor("weird.xyz")) + } + + @Test + fun injectsShimAfterHeadOrAtStart() { + assertEquals( + "t", + EvenHubAssetServer.injectIntoHtml("t", "S"), + ) + assertEquals("x", EvenHubAssetServer.injectIntoHtml("x", "S")) + assertEquals(", tamper: (ByteArray) -> Unit = {}): ByteArray { + val count = components.size + val toc = FirmwareImage.HEADER_SIZE + count * FirmwareImage.TOC_ENTRY_SIZE + var offset = toc + val offsets = components.map { c -> offset.also { offset += FirmwareImage.SUBHEADER_SIZE + c.payload.size } } + val img = ByteArray(offset) + putU32(img, 8, count.toLong()) + components.forEachIndexed { i, c -> + val off = offsets[i] + putU32(img, FirmwareImage.HEADER_SIZE + i * 16 + 4, off.toLong()) + putU32(img, off + 8, c.payload.size.toLong()) + c.name.encodeToByteArray().copyInto(img, off + FirmwareImage.NAME_OFFSET) + c.payload.copyInto(img, off + FirmwareImage.SUBHEADER_SIZE) + } + tamper(img) + components.forEachIndexed { i, c -> + val off = offsets[i] + val crc = FirmwareImage.crc32cUnsigned(img, off + FirmwareImage.SUBHEADER_SIZE, c.payload.size) + putU32(img, FirmwareImage.HEADER_SIZE + i * 16 + 12, crc) + putU32(img, off + 12, crc) + } + return img + } + + private fun mainApp(size: Int): ByteArray { + val payload = ByteArray(size) { (it * 7).toByte() } + putU32(payload, 0, size.toLong()) + putU32(payload, 0x14, FirmwareImage.APP_LOAD_ADDR) + return payload + } + + private fun validComponents(): List = + listOf( + Component("ota/bootloader.bin", ByteArray(300) { it.toByte() }), + Component("ota/a.bin", ByteArray(64) { 1 }), + Component("ota/b.bin", ByteArray(128) { 2 }), + Component("ota/c.bin", ByteArray(32) { 3 }), + Component(FirmwareImage.REQUIRED_SEGMENT, mainApp(600)), + ) + + @Test + fun crc32cMatchesKnownVector() { + // Castagnoli polynomial, MSB-first, init 0, no reflection or final xor (g2flash.py + // crc32c_msb); vectors from an independent Python implementation of that definition. + assertEquals(0xc052a8c8L, FirmwareImage.crc32cUnsigned("123456789".encodeToByteArray())) + assertEquals(0xd7b91914L, FirmwareImage.crc32cUnsigned(ByteArray(256) { it.toByte() })) + assertEquals(0L, FirmwareImage.crc32cUnsigned(ByteArray(0))) + assertEquals(FirmwareImage.crc32cUnsigned("23456789".encodeToByteArray()), FirmwareImage.crc32cUnsigned("123456789".encodeToByteArray(), 1, 8)) + } + + @Test + fun validImageParsesAllComponents() { + val segs = FirmwareImage.validate(container(validComponents())) + assertEquals(5, segs.size) + assertEquals(listOf(300, 64, 128, 32, 600), segs.map { it.ps }) + assertEquals(FirmwareImage.REQUIRED_SEGMENT, segs[4].name) + assertTrue(segs.zipWithNext().all { (a, b) -> a.end <= b.off }) + } + + @Test + fun rejectsStaleCrc() { + val img = container(validComponents()) + img[img.size - 1] = (img[img.size - 1] + 1).toByte() + assertTrue(assertFailsWith { FirmwareImage.validate(img) }.message!!.contains("CRC32C")) + } + + @Test + fun rejectsOverlappingComponents() { + val img = container(validComponents()) { buf -> + // Point component 1's TOC entry at component 0, so both claim the same bytes. + val off0 = FirmwareImage.readU32(buf, FirmwareImage.HEADER_SIZE + 4) + putU32(buf, FirmwareImage.HEADER_SIZE + 16 + 4, off0) + } + assertTrue(assertFailsWith { FirmwareImage.parseSegments(img) }.message!!.contains("overlap")) + } + + @Test + fun rejectsTruncatedPayload() { + val img = container(validComponents()) + val truncated = img.copyOf(img.size - 10) + assertTrue(assertFailsWith { FirmwareImage.parseSegments(truncated) }.message!!.contains("truncated")) + assertFailsWith { FirmwareImage.parseSegments(ByteArray(0x10)) } + } + + @Test + fun rejectsWrongComponentCountAndMissingMain() { + val four = validComponents().dropLast(1) + assertTrue(assertFailsWith { FirmwareImage.validate(container(four)) }.message!!.contains("components")) + val noMain = validComponents().dropLast(1) + Component("ota/other.bin", ByteArray(40)) + assertTrue(assertFailsWith { FirmwareImage.validate(container(noMain)) }.message!!.contains("not found")) + } + + @Test + fun rejectsMainAppBeyondMramCeiling() { + val ceiling = (FirmwareImage.APP_MAX_END - FirmwareImage.APP_LOAD_ADDR + FirmwareImage.APP_PREAMBLE).toInt() + val fits = validComponents().dropLast(1) + Component(FirmwareImage.REQUIRED_SEGMENT, mainApp(ceiling)) + FirmwareImage.validate(container(fits)) + val tooBig = validComponents().dropLast(1) + Component(FirmwareImage.REQUIRED_SEGMENT, mainApp(ceiling + 1)) + assertTrue(assertFailsWith { FirmwareImage.validate(container(tooBig)) }.message!!.contains("MRAM")) + val badAddr = validComponents().dropLast(1) + Component(FirmwareImage.REQUIRED_SEGMENT, mainApp(600).also { putU32(it, 0x14, 0x1234L) }) + assertTrue(assertFailsWith { FirmwareImage.validate(container(badAddr)) }.message!!.contains("load address")) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FoundationTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FoundationTest.kt new file mode 100644 index 00000000..621153c0 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FoundationTest.kt @@ -0,0 +1,69 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class FoundationTest { + @Test + fun jsonRoundTripsObjectsArraysAndNumbers() { + val text = """{"a":1,"b":[true,null,"x\ny"],"c":{"d":2.5,"e":-3}}""" + val value = Json.parseObject(text) + assertEquals(1, value["a"].asInt()) + assertEquals(listOf(true, null, "x\ny"), value["b"].asArray()) + assertEquals(2.5, value["c"].asObject()!!["d"].asDouble()) + assertEquals(-3L, value["c"].asObject()!!["e"].asLong()) + assertEquals(text, Json.write(value)) + assertEquals("[1,2,\"q\\\"\"]", Json.write(listOf(1, 2L, "q\""))) + assertEquals("1", JsonNumber.of(1.0).text) + assertEquals("1.5", JsonNumber.of(1.5).text) + assertNull("x".asInt()) + } + + @Test + fun sha256MatchesKnownVector() { + assertEquals("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", sha256Hex("abc".encodeToByteArray())) + val incremental = Sha256Digest() + incremental.update("a".encodeToByteArray()) + incremental.update("bc".encodeToByteArray()) + assertEquals(sha256("abc".encodeToByteArray()).toList(), incremental.digest().toList()) + } + + @Test + fun latchAndQueueHandOffAcrossThreads() { + val platform = testPlatform() + val latch = Latch(1, platform) + val queue = BlockingQueue(platform) + assertFalse(latch.await(20)) + startThread("foundation-test", true) { + sleepMs(20) + queue.put("hello") + latch.countDown() + } + assertEquals("hello", queue.poll(2000)) + assertTrue(latch.await(2000)) + assertNull(queue.poll(10)) + } + + @Test + fun interruptibleSleepConsumesEarlyInterrupt() { + val platform = testPlatform() + val sleep = InterruptibleSleep(platform) + sleep.interrupt() + val start = platform.elapsedRealtimeMs() + assertFalse(sleep.sleep(500)) + assertTrue(platform.elapsedRealtimeMs() - start < 400) + assertTrue(sleep.sleep(5)) + startThread("foundation-wake", true) { sleepMs(30); sleep.interrupt() } + assertFalse(sleep.sleep(5000)) + } + + @Test + fun wallClockFormatsPattern() { + val text = formatLocalTime(0L, "yyyy") + assertTrue(text == "1970" || text == "1969", text) + assertTrue(currentTimeMillis() > 1_600_000_000_000L) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameTimingsCoreTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameTimingsCoreTest.kt new file mode 100644 index 00000000..ee9dc077 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameTimingsCoreTest.kt @@ -0,0 +1,139 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +class FrameTimingsCoreTest { + private class FakeClock : ProtocolPlatform by testPlatform() { + var nowMs = 1_000L + override fun elapsedRealtimeMs(): Long = nowMs + } + + private fun core(clock: FakeClock, logs: MutableList = ArrayList()) = FrameTimingsCore( + platform = clock, + wallClockMs = { 1_700_000_000_000L + clock.nowMs }, + threadName = { "t" }, + formatWallClock = { "wall@$it" }, + logInfo = { logs.add("I $it") }, + logWarn = { logs.add("W $it") }, + ) + + @Test + fun exportRendersTreeAgainstRootClockByteForByte() { + val clock = FakeClock() + val logs = ArrayList() + val core = core(clock, logs) + val root = core.startFrame("input:sys-event type=0") + clock.nowMs += 5 + core.annotate(root, "fg=terminal") + core.log(root, "input event received on JS side") + clock.nowMs += 1 + core.spanStart(root, "handle-input") + clock.nowMs += 10 + val child = core.startFrame("render:shell", root) + clock.nowMs += 4 + core.spanEnd(root, "handle-input") + core.spanEnd(root, "missing") + core.spanStart(child, "paint") + clock.nowMs += 30 + core.finishFrame(child, "discarded: superseded") + clock.nowMs += 50 + core.finishFrame(root, "sent") + core.finishFrame(root, "sent") // ignored: first finish wins + core.log(root, "late line is dropped") + clock.nowMs += 100 + + assertEquals(listOf( + "I frame#2 [render:shell] -> discarded: superseded in 34ms", + "I frame#1 [input:sys-event type=0 fg=terminal] -> sent in 100ms", + ), logs) + assertEquals("frames started=2 sent=1 discarded=1 timeout=0 | input-to-display p50=100ms p90=100ms p99=100ms max=100ms", core.statsSummary()) + + val expected = """ + |FrameTimings export at wall@1700000001200 + |frames started=2 sent=1 discarded=1 timeout=0 open=0 + |input-to-display latency (last 1): p50=100ms p90=100ms p99=100ms max=100ms + | + |Frames are trees: an input event's own frame is the root, and the renders it + |caused are indented under it with offsets measured from the root's start. + | + |=== slowest frames that reached the glasses === + |frame#1 [input:sys-event type=0 fg=terminal] started wall@1700000001000 duration 100ms (tree 100ms) outcome sent + | +5ms [t] input event received on JS side + | +6ms [t] span handle-input start + | +16ms [t] spawned frame#2 (render:shell) + | +20ms [t] span handle-input end (14ms) + | +20ms [t] span missing end (start not recorded) + | +100ms [t] finished: sent + | frame#2 [render:shell] started +16ms duration 34ms outcome discarded: superseded + | +20ms [t] span paint start + | +50ms [t] span paint never ended (started at +4ms) + | +50ms [t] finished: discarded: superseded + |=== recent frames (oldest first) === + |frame#1 [input:sys-event type=0 fg=terminal] started wall@1700000001000 duration 100ms (tree 100ms) outcome sent + | +5ms [t] input event received on JS side + | +6ms [t] span handle-input start + | +16ms [t] spawned frame#2 (render:shell) + | +20ms [t] span handle-input end (14ms) + | +20ms [t] span missing end (start not recorded) + | +100ms [t] finished: sent + | frame#2 [render:shell] started +16ms duration 34ms outcome discarded: superseded + | +20ms [t] span paint start + | +50ms [t] span paint never ended (started at +4ms) + | +50ms [t] finished: discarded: superseded + |""".trimMargin() + assertTrue(core.isExportDirty) + assertEquals(expected, core.takeExport()) + assertFalse(core.isExportDirty) + assertEquals(null, core.takeExport()) + assertEquals(expected, core.buildExport()) + } + + @Test + fun sweepFinishesStaleFramesAsTimeoutsAndIgnoresZeroAndUnknownIds() { + val clock = FakeClock() + val logs = ArrayList() + val core = core(clock, logs) + val stale = core.startFrame("render:app") + clock.nowMs += FrameTimingsCore.FRAME_TIMEOUT_MS - 1 + val fresh = core.startFrame("render:late") + assertEquals(0, core.sweepTimedOut()) + clock.nowMs += 1 + assertEquals(1, core.sweepTimedOut()) + assertEquals(listOf("W frame#$stale [render:app] timed out after 30000ms without being finished"), logs) + core.log(0, "ignored") + core.log(999, "ignored") + core.spanStart(0, "x") + core.finishFrame(0, "sent") + core.finishFrame(fresh, "sent") + assertEquals("frames started=2 sent=1 discarded=0 timeout=1", core.statsSummary()) + val export = core.buildExport() + assertTrue(export.contains("frame#$stale [render:app] started wall@")) + assertTrue(export.contains("outcome timeout: never reported finished\n")) + assertTrue(export.contains("render-to-display latency (last 1): p50=1ms p90=1ms p99=1ms max=1ms")) + assertTrue(export.contains("open=0")) + } + + @Test + fun lineCapAndNegativeOffsetsFormatLikeJava() { + val clock = FakeClock() + val core = core(clock) + val root = core.startFrame("input:x") + clock.nowMs -= 12 // a line stamped before the root's start still formats with a sign + core.log(root, "early") + clock.nowMs += 12 + repeat(250) { core.log(root, "line $it") } + core.finishFrame(root, "sent") + val export = core.buildExport() + assertTrue(export.contains("\n -12ms [t] early\n"), export) + // Printed once under "slowest" and once under "recent". + assertEquals(2, Regex("\\.\\.\\. line cap reached").findAll(export).count()) + assertTrue(export.contains("line 198")) + assertFalse(export.contains("line 199")) + // Like the Java original, lines past the cap (including the finish line) are dropped. + assertFalse(export.contains("finished: sent")) + assertTrue(export.contains("outcome sent\n")) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlassesSessionCoreTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlassesSessionCoreTest.kt new file mode 100644 index 00000000..63b1a0fd --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlassesSessionCoreTest.kt @@ -0,0 +1,421 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.test.Test +import kotlin.test.assertContentEquals +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +private const val RIGHT = "AA:00:00:00:00:01" +private const val LEFT = "AA:00:00:00:00:02" + +/** The test platform with a clock the tests can jump forward (the real waits keep real time). */ +private class ClockPlatform(private val base: ProtocolPlatform) : ProtocolPlatform by base { + @Volatile var offsetMs = 0L + + override fun elapsedRealtimeMs(): Long = base.elapsedRealtimeMs() + offsetMs +} + +private fun waitUntil(timeoutMs: Long, condition: () -> Boolean): Boolean { + val platform = testPlatform() + val deadline = platform.elapsedRealtimeMs() + timeoutMs + while (platform.elapsedRealtimeMs() < deadline) { + if (condition()) return true + sleepMs(10) + } + return condition() +} + +private fun ByteArray.containsSequence(needle: ByteArray): Boolean { + if (needle.isEmpty() || size < needle.size) return false + outer@ for (start in 0..size - needle.size) { + for (i in needle.indices) if (this[start + i] != needle[i]) continue@outer + return true + } + return false +} + +/** One logical write as the fake link saw it: the frames, the decoded pb, and the in-flight message (if any). */ +private class Write( + val address: String, + val sid: Int, + val frames: List, + val pb: ByteArray, + val kind: String?, + val label: String?, + val magic: Int, + val message: ByteArray?, +) + +/** + * A GATT link that records every write and, unless a kind is muted, answers it the way the + * firmware would: EvenHub/settings/auth requests get a matching ack frame, CFW stream + * messages get one ACK per lens. + */ +private class FakeLink(private val platform: ProtocolPlatform) : SessionLink { + lateinit var core: GlassesSessionCore + private val lock = platform.createLock() + private val writesList = ArrayList() + val muted = HashSet() + val connected = HashSet() + val disconnected = ArrayList() + @Volatile var closed = false + var seq = 0 + + val writes: List + get() = lock.withLock { writesList.toList() } + + /** Decoded CFW image messages (the drive loop's debug-flags control rides the same stream and is excluded). */ + fun cfwMessages(): List = writes.filter { it.sid == CfwTransport.SID && it.kind == "image" }.mapNotNull { it.message } + + override fun connect(address: String, timeoutMs: Int): Boolean { + connected.add(address) + return true + } + + override fun requestHighPriority(address: String) {} + + override fun requestMtu(address: String, mtu: Int, timeoutMs: Int): Boolean = true + + override fun negotiatedMtu(address: String): Int = 247 + + override fun discoverServices(address: String, timeoutMs: Int): Boolean = true + + override fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean = true + + override fun writeFrames(address: String, characteristicUuid: String, frames: List, mode: GattWriteMode, timeoutMs: Int): Boolean { + val sid = frames[0][6].toInt() and 255 + val magic = if (sid == CfwTransport.SID) frames[0][2].toInt() and 255 else BleProtocol.parseFrame(frames[0]).msgSeq + // The in-flight entry gives the label/kind and the decoded CFW message. + val inFlight = core.monitor.withLock { core.inFlightMessages.firstOrNull { it.sid == sid && it.magic == magic && magic != 0 } } + val pb = if (sid == CfwTransport.SID) ByteArray(0) else { + val joined = frames.flatMap { frame -> frame.slice(8 until 8 + (frame[3].toInt() and 255)) }.toByteArray() + joined.copyOf(maxOf(0, joined.size - 2)) + } + val write = Write(address, sid, frames, pb, inFlight?.kind, inFlight?.label, magic, inFlight?.message?.copyOf()) + lock.withLock { writesList.add(write) } + if (inFlight != null && inFlight.kind !in muted) { + if (sid == CfwTransport.SID) { + for (lens in 1..2) core.onNotification(address, BleProtocol.NOTIFY_CHAR_UUID, cfwAck(magic, lens, inFlight.message.size, inFlight.cfwChecksum)) + } else { + core.onNotification(address, BleProtocol.NOTIFY_CHAR_UUID, ackFrame(sid, magic, pb)) + } + } + return true + } + + private fun ackFrame(sid: Int, magic: Int, request: ByteArray): ByteArray { + val body = if (sid == BleProtocol.SID_SECURITY_AUTH) + BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + byteArrayOf(0x1a, 0x00) + else + BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic) + return BleProtocol.framePb(body, sid, 0x00, seq++)[0] + } + + override fun disconnect(address: String) { + disconnected.add(address) + connected.remove(address) + } + + override fun close() { + closed = true + } + + override fun isBonded(address: String): Boolean = true + + override fun prepareBenchmarkLink(address: String, mode: Int) {} + + override fun recordDisplayFrameSent() {} +} + +private fun cfwAck(streamId: Int, lens: Int, size: Int, checksum: Int): ByteArray { + val packet = ByteArray(19) + packet[0] = 0xaa.toByte() + packet[1] = 0x12 + packet[3] = 11 + packet[4] = 1 + packet[5] = 1 + packet[6] = CfwTransport.SID.toByte() + packet[8] = 1 + packet[9] = streamId.toByte() + packet[12] = lens.toByte() + packet[13] = size.toByte() + packet[14] = (size ushr 8).toByte() + packet[15] = checksum.toByte() + packet[16] = (checksum ushr 8).toByte() + val crc = CfwTransport.crc(packet.copyOfRange(8, 17)) + packet[17] = crc.toByte() + packet[18] = (crc ushr 8).toByte() + return packet +} + +private class FakeHost(private val platform: ProtocolPlatform) : SessionHost { + private val lock = platform.createLock() + private val lines = ArrayList() + private var done: Latch? = null + var wakeLock = false + + fun logs(): List = lock.withLock { lines.toList() } + + fun hasLog(fragment: String): Boolean = logs().any { it.contains(fragment) } + + override fun postToMain(action: () -> Unit) = action() + + override fun currentThreadDispatcher(): SessionDispatcher = SessionDispatcher { it() } + + override fun isPhoneLocked(): Boolean = false + + override fun setScreenWakeLock(on: Boolean) { + wakeLock = on + } + + override fun isEvenAppActive(): Boolean = false + + override fun startWorker(body: () -> Unit) { + val latch = Latch(1, platform) + done = latch + startThread("test-session", true) { + try { + body() + } finally { + latch.countDown() + } + } + } + + override fun joinWorker(timeoutMs: Long) { + done?.await(timeoutMs) + } + + override fun log(level: SessionLogLevel, tag: String, message: String, error: Throwable?) { + lock.withLock { lines.add("$level $tag: $message") } + } +} + +private class FakeListener : FaceclawBleCommunicatorListener { + val phases = ArrayList() + val events = ArrayList() + val finished = ArrayList() + val batteries = ArrayList() + + override fun onStateChange(phase: String?, status: String?) { + phases.add(phase ?: "") + } + + override fun onRingEvent(kind: String?, containerName: String?, eventType: Int, eventSource: Int, systemExitReasonCode: Int, frameId: Int, ringTick: Long, ringType: Int, ringAux: Int, ringSpeed: Int) { + events.add("$kind:$eventType") + } + + override fun onBatteryState(headsetBattery: Int, headsetCharging: Int, ringBattery: Int, ringCharging: Int) { + batteries.add("$headsetBattery/$headsetCharging/$ringBattery/$ringCharging") + } + + override fun onSilentMode(silent: Boolean) {} + + override fun onWearState(wearing: Boolean) {} + + override fun onPhoneLockState(locked: Boolean) {} + + override fun onEvenAppConflict(message: String?) {} + + override fun onFrameMetrics(paintMs: Int, transmitMs: Int, tileCount: Int) {} + + override fun onFrameFinished(frameId: Int, outcome: String?) { + finished.add("$frameId:$outcome") + } + + override fun onFirmwareInfo(leftVersion: String?, rightVersion: String?, extension: String?) {} +} + +private class Session { + val platform = ClockPlatform(testPlatform()) + val link = FakeLink(platform) + val host = FakeHost(platform) + val listener = FakeListener() + val frameTimings = FrameTimingsCore(platform) + val core = GlassesSessionCore(link, host, frameTimings, platform, RIGHT, LEFT, "") + + init { + link.core = core + core.setListener(listener) + } + + fun layoutCreated(): Boolean = core.monitor.withLock { core.fixedLayoutCreated } + + fun startAndAwaitLayout() { + assertTrue(core.start()) + assertTrue(waitUntil(5_000) { layoutCreated() }, "layout never created; logs=${host.logs().takeLast(20)}") + } + + /** A 64x32 surface frame with a marker byte at [marker]; returns the expected composite fingerprint. */ + fun submitFrame(marker: Int, value: Byte, frameId: Int): Unit { + val pixels = ByteArray(64 * 32) + pixels[marker] = value + core.submitSurfaceFrame(ArrayByteReader(pixels), "s", 0, 0, 64, 32, "content-$marker-$value", 0, frameId, null) + } + + fun displayedMatchesDesired(): Boolean = core.monitor.withLock { + core.desiredTilesLock.locked { core.desiredFingerprint.isNotEmpty() && core.desiredFingerprint == core.displayedFingerprint } + } +} + +class GlassesSessionCoreTest { + @Test + fun connectsAuthenticatesPreludesAndCreatesTheLayout() { + val s = Session() + s.startAndAwaitLayout() + val writes = s.link.writes + assertEquals(setOf(RIGHT, LEFT), writes.filter { it.sid == BleProtocol.SID_SECURITY_AUTH }.map { it.address }.toSet()) + assertTrue(s.host.hasLog("security auth R=ok L=ok"), s.host.logs().toString()) + assertEquals(1, writes.count { it.kind == "prelude" }) + // The framebuffer lease is acquired on both arms (fire-and-forget settings writes, magic 0). + val fbAcquire = byteArrayOf(70, 67, 1, BleProtocol.FACECLAW_FB_OP_ACQUIRE.toByte()) + assertEquals(setOf(RIGHT, LEFT), writes.filter { it.sid == BleProtocol.SID_UI_SETTING && it.pb.containsSequence(fbAcquire) }.map { it.address }.toSet()) + assertEquals(1, writes.count { it.kind == "battery" }, "settings query for firmware info") + assertEquals(1, writes.count { it.kind == "create-layout" }) + assertTrue(s.core.isSessionReady()) + assertEquals(listOf("disconnected", "connecting", "connected"), s.listener.phases.distinct()) + s.core.disconnect() + assertFalse(s.core.isSessionReady()) + assertEquals("disconnected", s.listener.phases.last()) + assertTrue(s.listener.phases.contains("disconnecting")) + assertTrue(s.link.closed) + assertEquals(listOf(RIGHT, LEFT), s.link.disconnected.takeLast(2)) + assertFalse(s.host.wakeLock) + assertTrue(s.host.hasLog("communicator stop")) + } + + @Test + fun imagePipelineSendsAKeyframeThenABoundingBoxDelta() { + val s = Session() + s.startAndAwaitLayout() + s.core.configureCompositorScreen(64, 32) + s.core.configureSurface("s", 0, 0, 64, 32, 0, SurfaceCompositor.TRANSPARENCY_OPAQUE) + s.submitFrame(100, 0x80.toByte(), 1) + assertTrue(waitUntil(5_000) { s.link.cfwMessages().size >= 1 && s.displayedMatchesDesired() }, s.host.logs().takeLast(20).toString()) + assertTrue(s.listener.finished.contains("1:sent"), s.listener.finished.toString()) + s.submitFrame(101, 0x80.toByte(), 2) + assertTrue(waitUntil(5_000) { s.link.cfwMessages().size >= 2 && s.displayedMatchesDesired() }, s.host.logs().takeLast(20).toString()) + val messages = s.link.cfwMessages() + assertEquals(CFW_MSG_FULL_FRAME, messages[0][0].toInt() and CFW_MSG_TYPE_MASK, "first frame is a keyframe") + assertEquals(CFW_MSG_BOUNDING_BOX, messages[1][0].toInt() and CFW_MSG_TYPE_MASK, "second frame is a delta") + assertTrue(s.listener.finished.contains("2:sent")) + // Identical content again: nothing is sent and the frame is finished as a no-change. + s.submitFrame(101, 0x80.toByte(), 3) + assertTrue(waitUntil(2_000) { s.listener.finished.any { it.startsWith("3:") } }) + assertTrue(s.listener.finished.any { it == "3:discarded: no change from displayed image" }, s.listener.finished.toString()) + assertEquals(2, s.link.cfwMessages().size) + s.core.disconnect() + } + + @Test + fun heartbeatAndLeaseRenewalFollowTheClock() { + val s = Session() + s.startAndAwaitLayout() + // The first heartbeat follows the layout at once (nothing has been acked yet); the + // next one waits for HEARTBEAT_READY_MS since that ack. + assertTrue(waitUntil(3_000) { s.link.writes.count { it.kind == "heartbeat" } == 1 }, s.host.logs().takeLast(10).toString()) + assertTrue(s.host.hasLog("Got ACK for heartbeat")) + sleepMs(300) + assertEquals(1, s.link.writes.count { it.kind == "heartbeat" }) + s.platform.offsetMs += ConnectionOptions.HEARTBEAT_READY_MS + 100L + s.core.interruptibleSleep.interrupt() + assertTrue(waitUntil(3_000) { s.link.writes.count { it.kind == "heartbeat" } == 2 }, s.host.logs().takeLast(10).toString()) + val leaseWritesBefore = s.link.writes.count { it.sid == BleProtocol.SID_UI_SETTING && it.pb.containsSequence(byteArrayOf(70, 67, 1, BleProtocol.FACECLAW_FB_OP_ACQUIRE.toByte())) } + s.platform.offsetMs += GlassesSessionCore.FACECLAW_WAKE_LEASE_RENEW_MS + 100L + s.core.interruptibleSleep.interrupt() + assertTrue(waitUntil(3_000) { + s.link.writes.count { it.sid == BleProtocol.SID_UI_SETTING && it.pb.containsSequence(byteArrayOf(70, 67, 1, BleProtocol.FACECLAW_FB_OP_ACQUIRE.toByte())) } == leaseWritesBefore + 2 + }, "framebuffer lease renewed on both arms") + s.core.disconnect() + } + + @Test + fun deferredWakeIsClaimedAndReadyIsSentAfterResume() { + val s = Session() + s.startAndAwaitLayout() + s.core.configureCompositorScreen(64, 32) + s.core.configureSurface("s", 0, 0, 64, 32, 0, SurfaceCompositor.TRANSPARENCY_OPAQUE) + s.submitFrame(7, 0x40, 1) + assertTrue(waitUntil(5_000) { s.displayedMatchesDesired() }) + + assertTrue(s.core.suspendEvenHubSession()) + assertTrue(s.core.monitor.withLock { s.core.shutdownRequested }) + assertEquals(1, s.link.writes.count { it.kind == "shutdown" }) + + // CFW deferred double-tap wake on the right arm: field 102 [F,C,ver,event=1,nonce LE16]. + val nonce = 0x1234 + val event = byteArrayOf(70, 67, 1, 1, (nonce and 0xff).toByte(), (nonce ushr 8).toByte()) + val pb = BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, 0) + BleProtocol.encodeBytesField(BleProtocol.FACECLAW_WAKE_EVENT_FIELD, event) + s.core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID, BleProtocol.framePb(pb, BleProtocol.SID_UI_SETTING, BleProtocol.FLAG_NOTIFY, 9)[0]) + assertTrue(s.listener.events.contains("display-wake:${BleProtocol.EVENT_DOUBLE_CLICK}"), s.listener.events.toString()) + val claim = byteArrayOf(70, 67, 1, BleProtocol.FACECLAW_WAKE_OP_CLAIM.toByte(), (nonce and 0xff).toByte(), (nonce ushr 8).toByte()) + assertTrue(waitUntil(3_000) { s.link.writes.count { it.pb.containsSequence(claim) } == 2 }, "CLAIM written to both arms") + assertEquals(RIGHT, s.link.writes.first { it.pb.containsSequence(claim) }.address, "right arm first") + + assertTrue(s.core.resumeEvenHubSession()) + assertEquals(2, s.link.writes.count { it.kind == "prelude" }) + assertTrue(waitUntil(5_000) { s.layoutCreated() && s.displayedMatchesDesired() }, s.host.logs().takeLast(20).toString()) + assertTrue(s.core.awaitEvenHubSessionReady(5_000)) + val ready = byteArrayOf(70, 67, 1, BleProtocol.FACECLAW_WAKE_OP_READY.toByte(), (nonce and 0xff).toByte(), (nonce ushr 8).toByte()) + assertEquals(2, s.link.writes.count { it.pb.containsSequence(ready) }, "READY written to both arms") + s.core.disconnect() + } + + @Test + fun unexpectedAndDuplicateAcksAreLoggedNotApplied() { + val s = Session() + s.startAndAwaitLayout() + val unknown = BleProtocol.framePb(BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, 150), BleProtocol.SID_EVENHUB, 0, 5)[0] + s.core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID, unknown) + assertTrue(s.host.hasLog("unexpected ACK sid=${BleProtocol.SID_EVENHUB} magic=150"), s.host.logs().takeLast(5).toString()) + val layout = s.link.writes.first { it.kind == "create-layout" } + val duplicate = BleProtocol.framePb(BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, layout.magic), layout.sid, 0, 6)[0] + s.core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID, duplicate) + assertTrue(s.host.hasLog("duplicate ACK for already-acked message sid=${layout.sid} magic=${layout.magic}"), s.host.logs().takeLast(5).toString()) + assertTrue(s.layoutCreated()) + s.core.disconnect() + } + + @Test + fun ackTimeoutOnTheLayoutReconnects() { + val s = Session() + s.link.muted.add("create-layout") + assertTrue(s.core.start()) + assertTrue(waitUntil(5_000) { s.link.writes.any { it.kind == "create-layout" } }) + assertFalse(s.layoutCreated()) + s.platform.offsetMs += ConnectionOptions.ACK_TIMEOUT_MS + ConnectionOptions.WRITE_TIMEOUT_MS + 1_000L + s.core.interruptibleSleep.interrupt() + assertTrue(waitUntil(3_000) { s.listener.phases.contains("retrying") }, s.host.logs().takeLast(10).toString()) + assertTrue(s.host.hasLog("message timed out: create-layout")) + assertTrue(s.host.hasLog("Transport failure: ack timeout")) + assertTrue(s.link.disconnected.containsAll(listOf(RIGHT, LEFT))) + s.core.disconnect() + assertEquals("disconnected", s.listener.phases.last()) + } + + @Test + fun cfwNackTriggersReplayWithAFreshStreamId() { + val s = Session() + s.link.muted.add("image") + s.startAndAwaitLayout() + s.core.configureCompositorScreen(64, 32) + s.core.configureSurface("s", 0, 0, 64, 32, 0, SurfaceCompositor.TRANSPARENCY_OPAQUE) + s.submitFrame(3, 0x20, 1) + assertTrue(waitUntil(5_000) { s.link.cfwMessages().size == 1 }) + val first = s.link.writes.first { it.sid == CfwTransport.SID && it.kind == "image" } + val message = assertNotNull(s.core.monitor.withLock { s.core.inFlightMessages.firstOrNull { it.magic == first.magic } }) + // A NACK from lens 1 marks the message for replay; the window re-sends it under a new id. + val nack = cfwAck(first.magic, 1, 0, 0).also { it[8] = 3; val crc = CfwTransport.crc(it.copyOfRange(8, 17)); it[17] = crc.toByte(); it[18] = (crc ushr 8).toByte() } + s.core.onNotification(LEFT, BleProtocol.NOTIFY_CHAR_UUID, nack) + assertTrue(waitUntil(3_000) { s.link.cfwMessages().size == 2 }, s.host.logs().takeLast(10).toString()) + assertTrue(s.host.hasLog("CFW replay id=${first.magic}")) + val second = s.link.writes.filter { it.sid == CfwTransport.SID && it.kind == "image" }[1] + assertTrue(second.magic != first.magic) + assertEquals(1, message.cfwRetries) + assertContentEquals(first.message, second.message) + s.core.disconnect() + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlyphAndIconSourceTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlyphAndIconSourceTest.kt new file mode 100644 index 00000000..46b27dd9 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GlyphAndIconSourceTest.kt @@ -0,0 +1,128 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertContentEquals +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class GlyphAndIconSourceTest { + private fun u16(bytes: ByteArray, at: Int) = (bytes[at].toInt() and 0xff) or ((bytes[at + 1].toInt() and 0xff) shl 8) + private fun s16(bytes: ByteArray, at: Int) = u16(bytes, at).toShort().toInt() + + // 6x4 raster: ink in columns 2..4, rows 1..2, one 128 edge pixel. + private val raster = byteArrayOf( + 0, 0, 0, 0, 0, 0, + 0, 0, -1, -1, 0, 0, + 0, 0, 0, -1, 0x7f, 0, + 0, 0, 0, 0, 0, 0, + ) + + @Test + fun gammaLutIsIdentityAtOneAndDarkensAboveOne() { + val linear = GlyphPacket.gammaLut(1.0) + for (i in 0 until 256) assertEquals(i, linear[i].toInt() and 0xff) + assertContentEquals(linear, GlyphPacket.gammaLut(0.0)) + val squared = GlyphPacket.gammaLut(2.0) + assertEquals(64, squared[128].toInt() and 0xff) + assertEquals(255, squared[255].toInt() and 0xff) + } + + @Test + fun inkScansFindPaintedBoxes() { + assertContentEquals(intArrayOf(2, 4), GlyphPacket.paintedColumnRange(raster, 6, 4)) + assertContentEquals(intArrayOf(2, 1, 4, 2), GlyphPacket.inkBounds(raster, 6, 4)) + assertNull(GlyphPacket.paintedColumnRange(ByteArray(12), 4, 3)) + assertNull(GlyphPacket.inkBounds(ByteArray(12), 4, 3)) + } + + @Test + fun imagePacketsCarryLittleEndianHeaderAndGammaMappedRegion() { + val whole = GlyphPacket.packImage(raster, 6, 4, 1.0) + assertEquals(4 + 24, whole.size) + assertEquals(6, u16(whole, 0)) + assertEquals(4, u16(whole, 2)) + assertContentEquals(raster, whole.copyOfRange(4, whole.size)) + val region = GlyphPacket.packImageRegion(raster, 6, 2, 1, 3, 2, 2.0) + assertEquals(3, u16(region, 0)) + assertEquals(2, u16(region, 2)) + assertContentEquals(byteArrayOf(-1, -1, 0, 0, -1, 63), region.copyOfRange(4, region.size)) + } + + @Test + fun glyphCellPacketsCropToInkAndEncodeSignedOffsets() { + val cell = GlyphPacket.packGlyphCell(GlyphPacket.advanceFixed(5.5), raster, 6, 4, penX = 3, baselineY = 3, ascent = 10, gamma = 1.0) + assertEquals(352, u16(cell, 0)) + assertEquals(-1, s16(cell, 2)) // ink starts one pixel left of the pen + assertEquals(8, s16(cell, 4)) // ascent 10, ink top two rows above the baseline + assertEquals(3, u16(cell, 6)) + assertEquals(2, u16(cell, 8)) + assertContentEquals(byteArrayOf(-1, -1, 0, 0, -1, 0x7f), cell.copyOfRange(10, cell.size)) + val empty = GlyphPacket.packGlyphCell(64, ByteArray(12), 4, 3, 0, 0, 10, 1.0) + assertContentEquals(byteArrayOf(64, 0, 0, 0, 0, 0, 0, 0, 0, 0), empty) + assertEquals(0xffff, GlyphPacket.advanceFixed(5000.0)) + } + + private fun nameTable(vararg records: Triple): ByteArray { + // records: (platformId, nameId, value); platform 1 stored Latin-1, others UTF-16BE + val strings = ArrayList() + for ((platform, _, value) in records) { + strings.add(if (platform == 1) ByteArray(value.length) { value[it].code.toByte() } + else ByteArray(value.length * 2) { if (it % 2 == 0) (value[it / 2].code shr 8).toByte() else value[it / 2].code.toByte() }) + } + val out = ByteSink() + fun u16(v: Int) { out.write(v ushr 8); out.write(v) } + fun u32(v: Int) { u16(v ushr 16); u16(v and 0xffff) } + val nameOffset = 12 + 16 + val nameLength = 6 + records.size * 12 + strings.sumOf { it.size } + u32(0x00010000); u16(1); u16(0); u16(0); u16(0) // offset table, 1 table + u32(0x6e616d65); u32(0); u32(nameOffset); u32(nameLength) // 'name' record + u16(0); u16(records.size); u16(6 + records.size * 12) + var offset = 0 + for ((i, record) in records.withIndex()) { + u16(record.first); u16(0); u16(0); u16(record.second); u16(strings[i].size); u16(offset) + offset += strings[i].size + } + for (s in strings) out.write(s) + return out.toByteArray() + } + + @Test + fun openTypeNamesPreferTypographicFamilyAndStyle() { + assertEquals("Roboto\nLight", OpenTypeNames.parse(nameTable(Triple(3, 1, "Roboto Light"), Triple(3, 2, "Regular"), Triple(3, 16, "Roboto"), Triple(1, 17, "Light")))) + assertEquals("Mono\n", OpenTypeNames.parse(nameTable(Triple(1, 1, " Mono ")))) + assertEquals("", OpenTypeNames.parse(nameTable(Triple(3, 2, "Bold")))) + assertEquals("", OpenTypeNames.parse(ByteArray(8))) + } + + @Test + fun svgIconsParseShapesStrokeRuleAndPlacement() { + val svg = """ + """ + val icon = SvgIconSource.parse(svg)!! + assertTrue(icon.stroked) + assertEquals(listOf("Rect", "Circle", "PathData", "Polyline", "Line"), icon.shapes.map { it::class.simpleName }) + val rect = icon.shapes[0] as SvgShape.Rect + assertEquals(2f, rect.rx); assertEquals(2f, rect.ry) + assertEquals(3f, (icon.shapes[1] as SvgShape.Circle).r) + assertEquals("M4 4h16", (icon.shapes[2] as SvgShape.PathData).d) + val polygon = icon.shapes[3] as SvgShape.Polyline + assertContentEquals(floatArrayOf(1f, 2f, 3f, 4f), polygon.points) + assertTrue(polygon.closed) + assertContentEquals(floatArrayOf(0f, 0f, 2f), icon.placement(48)) + val filled = SvgIconSource.parse("""""")!! + assertTrue(!filled.stroked) + assertContentEquals(floatArrayOf(0f, 5f, 0.5f), filled.placement(20)) + assertEquals(-2f, filled.minX) + assertNull(SvgIconSource.parse("""""")) + } + + @Test + fun coverageQuantizesToThreeLevels() { + assertEquals(0, SvgIconSource.quantizeCoverage(63)) + assertEquals(128, SvgIconSource.quantizeCoverage(64)) + assertEquals(128, SvgIconSource.quantizeCoverage(191)) + assertEquals(255, SvgIconSource.quantizeCoverage(192)) + assertContentEquals(byteArrayOf(0, -128, -1), SvgIconSource.quantizeArgb(intArrayOf(0x10ffffff, 0x80000000.toInt(), 0xff000000.toInt()))) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GraphicsCoresTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GraphicsCoresTest.kt new file mode 100644 index 00000000..1fc78bbd --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/GraphicsCoresTest.kt @@ -0,0 +1,99 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertContentEquals +import kotlin.test.assertEquals +import kotlin.test.assertSame +import kotlin.test.assertTrue + +class GraphicsCoresTest { + private fun checksum(bytes: ByteArray): Long { + var sum = 7L + for (b in bytes) sum = sum * 31 + (b.toInt() and 0xff) + return sum + } + + @Test + fun grayPacketHeaderAndFlatConversion() { + // 3x2: opaque white, opaque mid, transparent white, half-alpha red, opaque black, opaque green + val pixels = intArrayOf( + 0xffffffff.toInt(), 0xff808080.toInt(), 0x00ffffff, + 0x80ff0000.toInt(), 0xff000000.toInt(), 0xff00ff00.toInt(), + ) + val packet = GrayPacket.fromArgb(pixels, 3, 2, 1f, false) + assertEquals(4 + 6, packet.size) + assertContentEquals(byteArrayOf(3, 0, 2, 0), packet.copyOfRange(0, 4)) + assertEquals(255, packet[4].toInt() and 0xff) + assertEquals(128, packet[5].toInt() and 0xff) + assertEquals(0, packet[6].toInt() and 0xff) // alpha 0 darkens to black + assertEquals(76 * 128 / 255, packet[7].toInt() and 0xff) // luma 76 at half alpha + assertEquals(0, packet[8].toInt() and 0xff) + assertEquals(149, packet[9].toInt() and 0xff) + val wide = GrayPacket.fromArgb(IntArray(300 * 2), 300, 2, 1f, false) + assertContentEquals(byteArrayOf(0x2c, 1, 2, 0), wide.copyOfRange(0, 4)) + } + + @Test + fun toneCurveDarkensMidtones() { + val identity = GrayPacket.toneCurve(1f) + assertEquals((0..255).toList(), identity.toList()) + val curve = GrayPacket.toneCurve(2.2f) + assertEquals(0, curve[0]) + assertEquals(255, curve[255]) + assertEquals(56, curve[128]) + assertTrue(curve.toList() == curve.sorted()) + } + + @Test + fun ditherIsDeterministicAndQuantized() { + // A horizontal ramp over 16x4 so the diffusion has somewhere to go. + val pixels = IntArray(16 * 4) { i -> val v = (i % 16) * 17; 0xff000000.toInt() or (v shl 16) or (v shl 8) or v } + val a = GrayPacket.fromArgb(pixels, 16, 4, 1f, true) + val b = GrayPacket.fromArgb(pixels, 16, 4, 1f, true) + assertContentEquals(a, b) + for (i in 4 until a.size) { + val v = a[i].toInt() and 0xff + assertTrue(v == 1 || (v % 16 == 0 && v in 16..240), "byte $i = $v") + } + // Mid-gray flat area dithers to a mix of two adjacent levels, never a solid. + val flat = GrayPacket.fromArgb(IntArray(8 * 8) { 0xff7f7f7f.toInt() }, 8, 8, 1f, true) + val levels = flat.drop(4).map { it.toInt() and 0xff }.toSet() + assertEquals(setOf(112, 128), levels) + assertEquals(2001783152304756847L, checksum(a)) + } + + @Test + fun previewPaletteValues() { + assertEquals(0xff000000.toInt(), PreviewPalette.argb(0, 0.7, false)) + assertEquals(0xffffffff.toInt(), PreviewPalette.argb(255, 0.7, false)) + assertEquals(0xff00ff00.toInt(), PreviewPalette.argb(255, 0.7, true)) + val gray = PreviewPalette.argb(128, 0.7, false) + val v = gray and 0xff + assertEquals(157, v) + assertEquals(0xff000000.toInt() or (v shl 16) or (v shl 8) or v, gray) + assertEquals(0xff000000.toInt() or (v shl 8), PreviewPalette.argb(128, 0.7, true)) + assertEquals(0xff808080.toInt(), PreviewPalette.argb(128, 1.0, false)) + val lut = PreviewPalette.lookupTable(0.7, false) + assertSame(lut, PreviewPalette.lookupTable(0.7, false)) + assertEquals(256, lut.size) + val expanded = PreviewPalette.expand(byteArrayOf(0, 0x80.toByte(), 0xff.toByte()), 0, 3, 0.7, false) + assertContentEquals(intArrayOf(lut[0], lut[128], lut[255]), expanded) + } + + @Test + fun statusIconsAreStable() { + val wifi = StatusIconArt.wifi(4) + val cell = StatusIconArt.cell(2) + val hotspot = StatusIconArt.hotspot() + for (icon in listOf(wifi, cell, hotspot)) { + assertEquals(24 * 24, icon.size) + assertTrue(icon.any { it.toInt() != 0 }) + } + assertTrue(StatusIconArt.wifi(0).count { it.toInt() != 0 } < wifi.count { it.toInt() != 0 }) + assertEquals(StatusIconArt.wifi(2).toList(), StatusIconArt.wifi(2).toList()) + assertEquals(listOf(-7515428168691714401L, -7643893777543336767L, 7675840471157348143L), listOf(checksum(wifi), checksum(cell), checksum(hotspot))) + val scaled = StatusIconArt.scale(wifi, 12) + assertEquals(144, scaled.size) + assertSame(wifi, StatusIconArt.scale(wifi, 24)) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/Lc3PacketFramerTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/Lc3PacketFramerTest.kt new file mode 100644 index 00000000..274d54b4 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/Lc3PacketFramerTest.kt @@ -0,0 +1,67 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith + +class Lc3PacketFramerTest { + private class FakeCodec(var fail: Boolean = false) : Lc3Codec { + var calls = 0 + override fun decodeFrames(packet: ByteArray, offset: Int, length: Int, pcmOut: ShortArray): Int { + calls++ + assertEquals(0, offset) + assertEquals(Lc3PacketFramer.LC3_BYTES, length) + return if (fail) -1 else Lc3PacketFramer.SAMPLES_PER_PACKET + } + } + + private fun packet(counter: Int, ssr: Int = 0, angle: Int = 0): ByteArray { + val p = ByteArray(Lc3PacketFramer.PACKET_BYTES) + p[Lc3PacketFramer.COUNTER_OFFSET] = counter.toByte() + p[Lc3PacketFramer.SSR_OFFSET] = (ssr and 0xff).toByte() + p[Lc3PacketFramer.SSR_OFFSET + 1] = ((ssr shr 8) and 0xff).toByte() + p[Lc3PacketFramer.ANGLE_OFFSET] = (angle and 0xff).toByte() + p[Lc3PacketFramer.ANGLE_OFFSET + 1] = ((angle shr 8) and 0xff).toByte() + return p + } + + @Test + fun countsRealDuplicateLateAndMissingPackets() { + val codec = FakeCodec() + val framer = Lc3PacketFramer(codec) + val pcm = ShortArray(Lc3PacketFramer.SAMPLES_PER_PACKET) + assertEquals(800, framer.decodePacket(packet(250), pcm)) + assertEquals(800, framer.decodePacket(packet(251), pcm)) + assertEquals(0, framer.decodePacket(packet(251), pcm)) // relayed by the other arm + assertEquals(0, framer.decodePacket(packet(250), pcm)) // late copy (gap 255) + assertEquals(800, framer.decodePacket(packet(254), pcm)) // 252, 253 lost + assertEquals(800, framer.decodePacket(packet(1), pcm)) // wraps past 255 -> 0; 255, 0 lost + assertEquals(0, framer.decodePacket(packet(129), pcm)) // gap 128 is late, not 127 losses + assertEquals(4, framer.realPackets) + assertEquals(3, framer.duplicatePackets) + assertEquals(4, framer.missingPackets) + assertEquals(0, framer.decodeErrors) + assertEquals(4, codec.calls) + } + + @Test + fun parsesSignedTrailerAndRejectsBadInput() { + val codec = FakeCodec() + val framer = Lc3PacketFramer(codec) + val pcm = ShortArray(Lc3PacketFramer.SAMPLES_PER_PACKET) + framer.decodePacket(packet(7, ssr = -1234, angle = -45), pcm) + assertEquals(-1234, framer.lastSsr) + assertEquals(-45, framer.lastAngleDegrees) + assertEquals(0, framer.decodePacket(ByteArray(10), pcm)) + assertEquals(0, framer.decodePacket(null, pcm)) + assertEquals(2, framer.decodeErrors) + assertFailsWith { framer.decodePacket(packet(8), ShortArray(10)) } + codec.fail = true + assertEquals(0, framer.decodePacket(packet(8), pcm)) + assertEquals(3, framer.decodeErrors) + // A failed decode does not advance the counter, so 8 is still accepted afterwards. + codec.fail = false + assertEquals(800, framer.decodePacket(packet(8), pcm)) + assertEquals(2, framer.realPackets) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RemoteInputSessionTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RemoteInputSessionTest.kt new file mode 100644 index 00000000..a77c68ba --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/RemoteInputSessionTest.kt @@ -0,0 +1,178 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNull +import kotlin.test.assertTrue + +private class FakeConnection(input: String, private val bytesOverride: ByteArray? = null) : RemoteInputConnection { + private val bytes = bytesOverride ?: input.encodeToByteArray() + private var index = 0 + private val written = ByteSink() + var closed = false + val output: String get() = written.toByteArray().decodeToString() + + override fun readByte(timeoutMs: Long): Int = if (index < bytes.size) bytes[index++].toInt() and 255 else -1 + + override fun write(bytes: ByteArray) = written.write(bytes) + + override fun close() { closed = true } +} + +private class FakePort(platform: ProtocolPlatform) : LocalServerPort { + val connections = BlockingQueue(platform) + var localAddresses = setOf("127.0.0.1", "192.168.1.5") + var bindFails = false + var listener: FakeListener? = null + + inner class FakeListener : RemoteInputListener { + override var isClosed = false + override fun accept(): RemoteInputConnection? { + while (!isClosed) { + val next = connections.poll(20) + if (next != null) return next + } + return null + } + override fun close() { isClosed = true } + } + + override fun isLocalUnicastAddress(address: String): Boolean = address in localAddresses + + override fun bind(address: String, port: Int): RemoteInputListener { + if (bindFails) throw IllegalStateException("in use") + return FakeListener().also { listener = it } + } +} + +private fun waitFor(timeoutMs: Long = 3000, condition: () -> Boolean): Boolean { + val platform = testPlatform() + val deadline = platform.elapsedRealtimeMs() + timeoutMs + while (platform.elapsedRealtimeMs() < deadline) { + if (condition()) return true + sleepMs(5) + } + return condition() +} + +class RemoteInputSessionTest { + private val platform = testPlatform() + private val random = object : RandomSource { override fun nextBytes(count: Int) = ByteArray(count) { it.toByte() } } + private fun dispatchOnThread(action: () -> Unit) = startThread("remote-input-dispatch", true, action) + + private fun session(port: FakePort, requestTimeoutMs: Long = 5000, readTimeoutMs: Long = 5000) = + RemoteInputSession(port, random, ::dispatchOnThread, platform, requestTimeoutMs = requestTimeoutMs, readTimeoutMs = readTimeoutMs) + + @Test + fun startValidatesAddressesAndBindFailures() { + val port = FakePort(platform) + val session = session(port) + assertEquals("Invalid local address.", session.start(7000, "localhost")) + assertEquals("Address is not assigned to a local interface.", session.start(7000, "10.0.0.9")) + port.bindFails = true + assertEquals("Could not open local input port 7000.", session.start(7000, "127.0.0.1")) + port.bindFails = false + assertEquals("", session.start(7000, "127.0.0.1")) + assertEquals("", session.start(7000, "127.0.0.1"), "second start is a no-op") + session.stop() + assertTrue(waitFor { port.listener!!.isClosed }) + assertTrue(RemoteInputSession.isNumericLocalAddress("fe80::1%en0")) + assertFalse(RemoteInputSession.isNumericLocalAddress("example.com")) + } + + @Test + fun requestIsPublishedAnsweredAndWrittenBack() { + val port = FakePort(platform) + val session = session(port) + var notified = 0 + session.setRequestListener { notified++ } + assertEquals("", session.start(7000, "127.0.0.1")) + val connection = FakeConnection("{\"token\":\"t\",\"text\":\"hi\"}\n") + port.connections.put(connection) + assertTrue(waitFor { notified == 1 }) + val pending = Json.parseObject(session.nextRequest()!!) + assertEquals(1L, pending["id"].asLong()) + assertEquals("{\"token\":\"t\",\"text\":\"hi\"}", pending["body"].asString()) + assertTrue(pending["expiresAt"].asLong()!! > currentTimeMillis()) + assertNull(session.nextRequest(), "consumed once") + session.complete(99L, "{\"ok\":false}") + assertFalse(waitFor(100) { connection.output.isNotEmpty() }, "wrong id is ignored") + session.complete(1L, "{\"ok\":true}") + assertTrue(waitFor { connection.output == "{\"ok\":true}\n" }) + assertTrue(waitFor { connection.closed }) + session.stop() + } + + @Test + fun timeoutRepliesWithTheTimeoutResponse() { + val port = FakePort(platform) + val session = session(port, requestTimeoutMs = 150) + assertEquals("", session.start(7000, "127.0.0.1")) + val connection = FakeConnection("slow\n") + port.connections.put(connection) + assertTrue(waitFor { connection.output == RemoteInputSession.TIMEOUT_RESPONSE + "\n" }) + assertNull(session.nextRequest(), "expired request is dropped") + session.stop() + } + + @Test + fun oversizedAndIncompleteFramesGetNoReply() { + val port = FakePort(platform) + val session = session(port) + var notified = 0 + session.setRequestListener { notified++ } + assertEquals("", session.start(7000, "127.0.0.1")) + val huge = FakeConnection("", ByteArray(RemoteInputSession.MAX_FRAME_BYTES + 2) { 'a'.code.toByte() }.also { it[it.size - 1] = '\n'.code.toByte() }) + port.connections.put(huge) + assertTrue(waitFor { huge.closed }) + assertEquals("", huge.output) + val partial = FakeConnection("no newline") + port.connections.put(partial) + assertTrue(waitFor { partial.closed }) + assertEquals("", partial.output) + val invalidUtf8 = FakeConnection("", byteArrayOf(0xff.toByte(), 0xfe.toByte(), '\n'.code.toByte())) + port.connections.put(invalidUtf8) + assertTrue(waitFor { invalidUtf8.closed }) + assertEquals("", invalidUtf8.output) + assertEquals(0, notified) + assertNull(session.nextRequest()) + session.stop() + } + + @Test + fun stopWhilePendingReleasesTheServingThread() { + val port = FakePort(platform) + val session = session(port) + var notified = 0 + session.setRequestListener { notified++ } + assertEquals("", session.start(7000, "127.0.0.1")) + val connection = FakeConnection("pending\n") + port.connections.put(connection) + assertTrue(waitFor { notified == 1 }) + session.stop() + assertTrue(waitFor { connection.closed }) + assertNull(session.nextRequest()) + assertEquals("", session.start(7001, "127.0.0.1"), "restart after stop") + session.stop() + } + + @Test + fun helpersFilterInterfacesAndHashTokens() { + val all = listOf( + InterfaceAddress("lo0", "127.0.0.1", up = true, pointToPoint = false, loopback = true, linkLocal = false, anyLocal = false), + InterfaceAddress("wlan0", "192.168.1.5", up = true, pointToPoint = false, loopback = false, linkLocal = false, anyLocal = false), + InterfaceAddress("wlan0", "fe80::1%wlan0", up = true, pointToPoint = false, loopback = false, linkLocal = true, anyLocal = false), + InterfaceAddress("tun0", "100.64.0.2", up = true, pointToPoint = true, loopback = false, linkLocal = false, anyLocal = false), + InterfaceAddress("eth0", "10.0.0.2", up = false, pointToPoint = false, loopback = false, linkLocal = false, anyLocal = false), + InterfaceAddress("any", "0.0.0.0", up = true, pointToPoint = false, loopback = false, linkLocal = false, anyLocal = true), + ) + assertEquals( + "[{\"name\":\"wlan0\",\"address\":\"192.168.1.5\",\"pointToPoint\":false},{\"name\":\"tun0\",\"address\":\"100.64.0.2\",\"pointToPoint\":true}]", + RemoteInputSession.interfacesJson(all), + ) + assertEquals("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", RemoteInputSession.tokenHash("abc")) + val session = session(FakePort(platform)) + assertEquals("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", session.randomSecret()) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResumableDownloadTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResumableDownloadTest.kt new file mode 100644 index 00000000..be68ffa3 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/ResumableDownloadTest.kt @@ -0,0 +1,149 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class ResumableDownloadTest { + private class Storage : DownloadStorage { + val files = HashMap() + override fun length(path: String): Long = files[path]?.size?.toLong() ?: -1L + override fun prepareParent(path: String) {} + override fun openWrite(path: String, append: Boolean): FileSink { + if (!append) files[path] = ByteArray(0) + return object : FileSink { + override fun write(bytes: ByteArray, offset: Int, length: Int) { + files[path] = (files[path] ?: ByteArray(0)) + bytes.copyOfRange(offset, offset + length) + } + override fun close() {} + } + } + override fun readAll(path: String, consumer: (ByteArray, Int) -> Boolean): Long { + val data = files[path] ?: return 0 + var at = 0L + for (chunk in data.toList().chunked(7)) { + val bytes = chunk.toByteArray() + if (!consumer(bytes, bytes.size)) break + at += bytes.size + } + return at + } + override fun rename(from: String, to: String): Boolean { files[to] = files.remove(from) ?: return false; return true } + override fun delete(path: String): Boolean = files.remove(path) != null + } + + private class Transport(val content: ByteArray, val honorRange: Boolean = true, val truncateAt: Int = -1) : DownloadTransport { + var lastRange = -1L + override fun open(url: String, rangeFrom: Long): DownloadResponse { + lastRange = rangeFrom + val start = if (honorRange) rangeFrom.toInt() else 0 + val end = if (truncateAt >= 0) minOf(truncateAt, content.size) else content.size + val body = content.copyOfRange(start, end) + var at = 0 + return object : DownloadResponse { + override val code: Int = if (honorRange && rangeFrom > 0) 206 else 200 + override val contentLength: Long = body.size.toLong() + override fun read(buffer: ByteArray): Int { + if (at >= body.size) return -1 + val n = minOf(5, body.size - at) + body.copyInto(buffer, 0, at, at + n) + at += n + return n + } + override fun close() {} + } + } + } + + private class Events : FaceclawModelDownloaderListener { + val progress = ArrayList>() + var done: String? = null + var error: String? = null + override fun onProgress(bytesDownloaded: Long, totalBytes: Long) { progress.add(bytesDownloaded to totalBytes) } + override fun onDone(path: String?) { done = path } + override fun onError(message: String?) { error = message } + } + + private val content = ByteArray(40) { (it * 3).toByte() } + private val sha = sha256Hex(content) + + private fun run(storage: Storage, transport: Transport, expectedSha: String? = sha, total: Long = content.size.toLong()): Events { + val events = Events() + var clock = 0L + ResumableDownload("http://x/m", "/dest/model", expectedSha, total, transport, storage, events) { clock += 600; clock }.run() + return events + } + + @Test + fun freshDownloadVerifiesAndRenames() { + val storage = Storage() + val transport = Transport(content) + val events = run(storage, transport) + assertNull(events.error) + assertEquals("/dest/model", events.done) + assertEquals(content.toList(), storage.files["/dest/model"]!!.toList()) + assertEquals(0L, transport.lastRange) + assertTrue(events.progress.isNotEmpty() && events.progress.last().second == 40L) + val again = run(storage, transport) + assertEquals("/dest/model", again.done) + } + + @Test + fun resumesFromPartWhenServerHonorsRange() { + val storage = Storage() + storage.files["/dest/model.part"] = content.copyOfRange(0, 17) + val transport = Transport(content) + val events = run(storage, transport) + assertEquals(17L, transport.lastRange) + assertNull(events.error) + assertEquals(content.toList(), storage.files["/dest/model"]!!.toList()) + } + + @Test + fun restartsWhenServerIgnoresRange() { + val storage = Storage() + storage.files["/dest/model.part"] = ByteArray(17) { 1 } + val transport = Transport(content, honorRange = false) + val events = run(storage, transport) + assertEquals(17L, transport.lastRange) + assertNull(events.error) + assertEquals(content.toList(), storage.files["/dest/model"]!!.toList()) + } + + @Test + fun checksumMismatchDeletesPart() { + val storage = Storage() + val events = run(storage, Transport(content), expectedSha = "00".repeat(32)) + assertEquals("Model download was corrupted (checksum mismatch); download it again", events.error) + assertNull(storage.files["/dest/model.part"]) + assertNull(storage.files["/dest/model"]) + } + + @Test + fun shortBodyKeepsPartForResume() { + val storage = Storage() + val events = run(storage, Transport(content, truncateAt = 30)) + assertEquals("Model download ended early (30 of 40 bytes); try again to resume", events.error) + assertEquals(30, storage.files["/dest/model.part"]!!.size) + val resumed = run(storage, Transport(content)) + assertNull(resumed.error) + assertEquals(content.toList(), storage.files["/dest/model"]!!.toList()) + } + + @Test + fun httpErrorIsReported() { + val storage = Storage() + val transport = object : DownloadTransport { + override fun open(url: String, rangeFrom: Long): DownloadResponse = object : DownloadResponse { + override val code = 404 + override val contentLength = -1L + override fun read(buffer: ByteArray) = -1 + override fun close() {} + } + } + val events = Events() + ResumableDownload("u", "/dest/model", null, 0, transport, storage, events).run() + assertEquals("Model download failed: HTTP 404", events.error) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SettingsChangeHubTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SettingsChangeHubTest.kt new file mode 100644 index 00000000..42a019d3 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SettingsChangeHubTest.kt @@ -0,0 +1,46 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class SettingsChangeHubTest { + private class MemorySettings : SettingsStorage { + val values = HashMap() + override fun getString(key: String?, defaultValue: String?): String? = values[key] as? String ?: defaultValue + override fun putString(key: String?, value: String?) { values[key] = value } + override fun getBoolean(key: String?, defaultValue: Boolean): Boolean = values[key] as? Boolean ?: defaultValue + override fun putBoolean(key: String?, value: Boolean) { values[key] = value } + } + + @Test + fun writesNotifyEachListenerThroughItsOwnDispatcher() { + val warnings = ArrayList() + val hub = SettingsChangeHub(MemorySettings(), { warnings.add(it) }, testPlatform()) + val queued = ArrayList<() -> Unit>() + val seen = ArrayList() + val listener = object : FaceclawSettingsListener { override fun onSettingChanged(key: String?) { seen.add(key) } } + hub.register(listener) { queued.add(it) } + val silent = object : FaceclawSettingsListener { override fun onSettingChanged(key: String?) { seen.add("silent") } } + hub.register(silent, null) + assertEquals(1, warnings.size) + + hub.setString("font", "Inter") + hub.setBoolean("dark", true) + assertEquals("Inter", hub.getString("font", null)) + assertTrue(hub.getBoolean("dark", false)) + assertTrue(seen.isEmpty()) // delivered only when the dispatcher runs + queued.forEach { it() } + assertEquals(listOf("font", "dark"), seen) + + val failing = object : FaceclawSettingsListener { override fun onSettingChanged(key: String?) { throw IllegalStateException("boom") } } + hub.register(failing) { it() } + hub.setString("x", null) + assertTrue(warnings.last().contains("boom")) + hub.unregister(listener) + hub.unregister(failing) + queued.clear() + hub.setBoolean("dark", false) + assertTrue(queued.isEmpty()) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SseStreamTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SseStreamTest.kt new file mode 100644 index 00000000..901ba60d --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/SseStreamTest.kt @@ -0,0 +1,87 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class SseStreamTest { + private fun feed(stream: SseStream, vararg chunks: String) { + for (chunk in chunks) { + val bytes = chunk.encodeToByteArray() + stream.onChunk(bytes, 0, bytes.size) + } + } + + @Test + fun splitsLinesAcrossChunksWithBomAndCrlf() { + val stream = SseStream() + stream.onStatus(200) + feed(stream, "event: a\r", "\ndata: {\"x\":1}\n\nda", "ta: tail") + assertEquals(listOf(SseEvent.Line("event: a"), SseEvent.Line("data: {\"x\":1}"), SseEvent.Line("")), stream.takeEvents()) + stream.onComplete() + assertEquals(listOf(SseEvent.Line("data: tail"), SseEvent.Complete), stream.takeEvents()) + assertTrue(stream.isFinished) + feed(stream, "late\n") + assertEquals(emptyList(), stream.takeEvents()) + } + + @Test + fun errorBodyIsBufferedAndCapped() { + val stream = SseStream() + stream.onStatus(429) + feed(stream, "{\"error\":", "\"slow down\"}\n") + assertEquals(emptyList(), stream.takeEvents()) + stream.onComplete() + assertEquals(listOf(SseEvent.HttpError(429, "{\"error\":\"slow down\"}\n")), stream.takeEvents()) + + val capped = SseStream() + capped.onStatus(500) + val big = ByteArray(SseStream.ERROR_BODY_LIMIT + 100) { 'x'.code.toByte() } + capped.onChunk(big, 0, big.size) + capped.onComplete() + val event = capped.takeEvents().single() as SseEvent.HttpError + assertEquals(SseStream.ERROR_BODY_LIMIT, event.body.length) + } + + @Test + fun queueOverflowAndOversizedLinesFail() { + val stream = SseStream() + stream.onStatus(200) + val line = "x".repeat(1023) + "\n" + val block = line.repeat(64).encodeToByteArray() + var fed = 0L + while (fed <= SseStream.QUEUE_BYTE_LIMIT + block.size) { + stream.onChunk(block, 0, block.size) + fed += block.size + } + val events = stream.takeEvents() + assertEquals(SseEvent.Failure("Streaming response queue overflow"), events.single()) + + val long = SseStream() + long.onStatus(200) + val huge = ByteArray(SseStream.LINE_LIMIT + 1) { 'y'.code.toByte() } + long.onChunk(huge, 0, huge.size) + assertEquals(SseEvent.Failure("Streaming response line too large"), long.takeEvents().single()) + } + + @Test + fun failureAndCancelAreTerminal() { + val stream = SseStream() + stream.onStatus(200) + feed(stream, "a\n") + stream.onFailure("boom") + assertEquals(listOf(SseEvent.Line("a"), SseEvent.Failure("boom")), stream.takeEvents()) + val cancelled = SseStream() + cancelled.onStatus(200) + feed(cancelled, "a\n") + cancelled.cancel() + cancelled.onComplete() + assertEquals(emptyList(), cancelled.takeEvents()) + } + + @Test + fun unpacksFlatHeaderArrays() { + assertEquals(listOf("A" to "1", "C" to "3"), SseStream.unpackHeaders(arrayOf("A", "1", "", "2", "C", "3", "D"))) + assertEquals(emptyList(), SseStream.unpackHeaders(null)) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/StockFlowsTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/StockFlowsTest.kt new file mode 100644 index 00000000..9573d705 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/StockFlowsTest.kt @@ -0,0 +1,382 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertContains +import kotlin.test.assertContentEquals +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +/** A stock-firmware lens pair behind the StockLink port; replies are scripted per written message. */ +private class FakeStockLink : StockLink { + class Written(val address: String, val uuid: String, val sid: Int, val flag: Int, val seq: Int, val pb: ByteArray) { + /** Protobuf magic (field 2) of a control message; -1 for OTA payloads. */ + val magic: Int get() = if (sid == 0xc0 || sid == 0xc1) -1 else BleProtocol.readVarintFieldValue(BleProtocol.stripTrailingCrc(pb), 2, -1) + } + + var inbound: StockLinkListener? = null + val connected = HashSet() + val bond = HashMap() + val writes = ArrayList() + var connectResult: (String) -> Boolean = { true } + var responder: (Written) -> Unit = {} + var closed = false + + override fun setListener(listener: StockLinkListener?) { inbound = listener } + override fun connect(address: String, timeoutMs: Int): Boolean = connectResult(address).also { if (it) connected.add(address) } + override fun prepareLink(address: String, desiredMtu: Int, timeoutMs: Int) {} + override fun discoverServices(address: String, timeoutMs: Int): Boolean = address in connected + override fun enableNotifications(address: String, characteristicUuid: String, timeoutMs: Int): Boolean = address in connected + override fun writeFrames(address: String, characteristicUuid: String, frames: List, mode: GattWriteMode, timeoutMs: Int): Boolean { + if (address !in connected) throw IllegalStateException("Not connected: $address") + val head = frames.first() + val body = ByteArray(frames.sumOf { it.size - 8 }) + var at = 0 + for (f in frames) { f.copyInto(body, at, 8); at += f.size - 8 } + val written = Written(address, characteristicUuid, head[6].toInt() and 0xff, head[7].toInt() and 0xff, head[2].toInt() and 0xff, body) + writes.add(written) + responder(written) + return true + } + override fun isConnected(address: String): Boolean = address in connected + override fun bondState(address: String): BondState = bond[address] ?: BondState.BONDED + override fun disconnect(address: String) { connected.remove(address) } + override fun close() { closed = true; connected.clear() } + + /** Deliver a lens frame on the control notify characteristic. */ + fun notify(address: String, pb: ByteArray, sid: Int, flag: Int = 0) { + for (frame in BleProtocol.framePb(pb, sid, flag, 7)) inbound!!.onNotification(address, BleProtocol.NOTIFY_CHAR_UUID, frame) + } + fun otaAck(address: String, op: Int, status: Int) { + inbound!!.onNotification(address, BleProtocol.OTA_DATA_NOTIFY_UUID, BleProtocol.framePb(byteArrayOf(op.toByte(), status.toByte()), 0xc1, 0, 1).single()) + } + fun drop(address: String) { connected.remove(address); inbound!!.onConnectionStateChange(address, false) } +} + +private fun varint(value: Int): ByteArray { var v = value; val out = ArrayList(); do { var b = v and 0x7f; v = v ushr 7; if (v != 0) b = b or 0x80; out.add(b.toByte()) } while (v != 0); return out.toByteArray() } +private fun field(number: Int, bytes: ByteArray): ByteArray = varint((number shl 3) or 2) + varint(bytes.size) + bytes +private fun field(number: Int, text: String): ByteArray = field(number, text.encodeToByteArray()) +private fun authSuccess(magic: Int) = BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + field(3, ByteArray(0)) +private fun authPending(magic: Int) = BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + field(3, BleProtocol.encodeVarintField(1, 1)) +private fun ack(magic: Int) = BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic) +private fun settingsAck(magic: Int, battery: Int = -1, left: String = "", right: String = "", extension: String = ""): ByteArray { + var request = ByteArray(0) + if (left.isNotEmpty()) request += field(5, left) + if (right.isNotEmpty()) request += field(6, right) + if (battery >= 0) request += BleProtocol.encodeVarintField(12, battery) + var pb = BleProtocol.encodeVarintField(1, 2) + BleProtocol.encodeVarintField(2, magic) + field(4, request) + if (extension.isNotEmpty()) pb += field(100, extension) + return pb +} +private fun listSelection(container: String, item: String, index: Int, eventType: Int): ByteArray = + field(13, field(1, field(2, container) + field(3, item) + BleProtocol.encodeVarintField(4, index) + BleProtocol.encodeVarintField(5, eventType))) + +private val fast = StockFlowTimings( + securityAuthTimeoutMs = 300, securityAuthSoftTimeoutMs = 100, pairingWaitCapMs = 2_000, postBondGraceMs = 20, pollMs = 5, + armRetryDelayMs = 5, queryTimeoutMs = 40, preludeTimeoutMs = 40, heartbeatIntervalMs = 15, selectionTimeoutMs = 80, createAckTimeoutMs = 40, + batteryAckTimeoutMs = 40, blockAckTimeoutMs = 60, ctrlAckTimeoutMs = 60, firstLensConnectWindowMs = 200, secondLensConnectWindowMs = 200, + rebootSettleMs = 5, notifySettleMs = 5, otaRetryDelayMs = 5, componentRetryDelayMs = 5, +) + +private const val R = "AA:00:00:00:00:01" +private const val L = "AA:00:00:00:00:02" + +private class ProbeEvents : FaceclawDeviceInfoProbeListener { + val logs = ArrayList(); val states = ArrayList(); var result: List? = null; var error: String? = null + override fun onLog(line: String?) { logs.add(line ?: "") } + override fun onState(state: String?, detail: String?) { states.add("$state:$detail") } + override fun onResult(leftVersion: String?, rightVersion: String?, extension: String?) { result = listOf(leftVersion ?: "", rightVersion ?: "", extension ?: "") } + override fun onError(message: String?) { error = message } +} + +/** Standard lens behaviour: auth succeeds, prelude and settings are acked with the given versions/battery. */ +private fun stockResponder(link: FakeStockLink, left: String = "2.2.9", right: String = "2.2.9", extension: String = "", battery: Int = 85): (FakeStockLink.Written) -> Unit = { w -> + when (w.sid) { + BleProtocol.SID_SECURITY_AUTH -> link.notify(w.address, authSuccess(w.magic), w.sid) + BleProtocol.PRELUDE_ACK_SID -> link.notify(w.address, ack(BleProtocol.PRELUDE_ACK_MAGIC), w.sid) + BleProtocol.SID_UI_SETTING -> link.notify(w.address, settingsAck(w.magic, battery, left, right, extension), w.sid) + BleProtocol.SID_EVENHUB -> link.notify(w.address, ack(w.magic), w.sid) + } +} + +class StockFlowsTest { + @Test + fun probeAuthenticatesBothArmsThenReadsVersions() { + val link = FakeStockLink() + link.responder = stockResponder(link, "L1", "R1", "Faceclaw/3") + val events = ProbeEvents() + DeviceInfoProbeFlow(link, R, L, events, fast, testPlatform()).run() + assertEquals(listOf("L1", "R1", "Faceclaw/3"), events.result) + assertEquals(null, events.error) + assertEquals(listOf("connecting:right", "authenticating:right", "connecting:left", "authenticating:left", "querying:right"), events.states) + // Right arm then left arm auth, then prelude + one settings read on the right arm only. + assertEquals(listOf(R, L), link.writes.filter { it.sid == BleProtocol.SID_SECURITY_AUTH }.map { it.address }) + assertEquals(listOf(R), link.writes.filter { it.sid == BleProtocol.SID_UI_SETTING }.map { it.address }) + assertTrue(link.closed) + } + + @Test + fun probeUsesUnsolicitedSettingsPushAndFallsBackToLeftLens() { + // Right lens: auth ok, but the settings read is never acked; instead a push on a + // device-chosen magic carries the versions. + val pushed = FakeStockLink() + pushed.responder = { w -> + when (w.sid) { + BleProtocol.SID_SECURITY_AUTH -> pushed.notify(w.address, authSuccess(w.magic), w.sid) + BleProtocol.PRELUDE_ACK_SID -> pushed.notify(w.address, ack(BleProtocol.PRELUDE_ACK_MAGIC), w.sid) + BleProtocol.SID_UI_SETTING -> pushed.notify(w.address, settingsAck(250, -1, "P1", "P2", ""), w.sid) + } + } + var events = ProbeEvents() + DeviceInfoProbeFlow(pushed, R, "", events, fast, testPlatform()).run() + assertEquals(listOf("P1", "P2", ""), events.result) + assertTrue(events.logs.any { it.contains("unsolicited settings push") }) + + // Right lens silent on settings (both attempts); the left lens answers. + val silentRight = FakeStockLink() + silentRight.responder = { w -> + when (w.sid) { + BleProtocol.SID_SECURITY_AUTH -> silentRight.notify(w.address, authSuccess(w.magic), w.sid) + BleProtocol.PRELUDE_ACK_SID -> silentRight.notify(w.address, ack(BleProtocol.PRELUDE_ACK_MAGIC), w.sid) + BleProtocol.SID_UI_SETTING -> if (w.address == L) silentRight.notify(w.address, settingsAck(w.magic, -1, "LL", "RR", ""), w.sid) + } + } + events = ProbeEvents() + DeviceInfoProbeFlow(silentRight, R, L, events, fast, testPlatform()).run() + assertEquals(listOf("LL", "RR", ""), events.result) + assertTrue(events.logs.any { it.contains("probing the left lens") }) + assertEquals(2, silentRight.writes.count { it.sid == BleProtocol.SID_UI_SETTING && it.address == R }) + assertContains(events.states, "querying:left") + } + + @Test + fun probeWaitsThroughPairingAndResendsAfterBond() { + // Unbonded phone: the first auth request is answered with the pre-encryption + // non-success result, the OS then pairs (no writes while BONDING), and once bonded the + // request is re-sent after the grace period and finally succeeds. + val link = FakeStockLink() + link.bond[R] = BondState.NONE + val authReplies = ArrayList() + link.responder = { w -> + when (w.sid) { + BleProtocol.SID_SECURITY_AUTH -> { authReplies.add(w.magic); link.notify(w.address, if (authReplies.size == 1) authPending(w.magic) else authSuccess(w.magic), w.sid) } + BleProtocol.PRELUDE_ACK_SID -> link.notify(w.address, ack(BleProtocol.PRELUDE_ACK_MAGIC), w.sid) + BleProtocol.SID_UI_SETTING -> link.notify(w.address, settingsAck(w.magic, -1, "a", "b", ""), w.sid) + } + } + startThread("bond-flip", true) { sleepMs(20); link.bond[R] = BondState.BONDING; sleepMs(40); link.bond[R] = BondState.BONDED } + val events = ProbeEvents() + DeviceInfoProbeFlow(link, R, "", events, fast, testPlatform()).run() + assertEquals(listOf("a", "b", ""), events.result, events.logs.joinToString("\n")) + assertTrue(events.logs.any { it.contains("is not the success result") }) + assertTrue(events.logs.any { it.contains("is pairing with the right lens") }) + assertTrue(events.logs.any { it.contains("bond established") }) + assertTrue(events.logs.any { it.contains("re-sending the auth request after pairing") }) + assertEquals(2, authReplies.size) + assertTrue(events.logs.any { it.contains("security auth complete: right lens") }) + } + + @Test + fun probeReportsUnreachableArmAndCancel() { + val link = FakeStockLink() + link.connectResult = { false } + val events = ProbeEvents() + DeviceInfoProbeFlow(link, R, L, events, fast, testPlatform()).run() + assertNotNull(events.error).let { assertTrue(it.contains("could not connect to the right lens"), it) } + assertEquals(3, events.states.count { it == "connecting:right" }) + + val cancelled = FakeStockLink() + cancelled.responder = { w -> if (w.sid == BleProtocol.SID_SECURITY_AUTH) cancelled.notify(w.address, authPending(w.magic), w.sid) } + val slow = StockFlowTimings(securityAuthTimeoutMs = 5_000, pollMs = 5) + val flow = DeviceInfoProbeFlow(cancelled, R, "", ProbeEvents().also { events.logs.clear() }, slow, testPlatform()) + startThread("cancel", true) { sleepMs(30); flow.cancel() } + val start = testPlatform().elapsedRealtimeMs() + flow.run() + assertTrue(testPlatform().elapsedRealtimeMs() - start < 2_000) + assertTrue(flow.cancelled) + } + + private class PromptEvents : FaceclawFlashPromptListener { + val logs = ArrayList(); val states = ArrayList(); var battery: Pair? = null; var result: Boolean? = null + override fun onLog(line: String?) { logs.add(line ?: "") } + override fun onState(state: String?, detail: String?) { states.add("$state:$detail") } + override fun onBattery(rightPercent: Int, leftPercent: Int) { battery = rightPercent to leftPercent } + override fun onResult(approved: Boolean) { result = approved } + } + + private fun promptResponder(link: FakeStockLink, selection: Int?, batteries: Map): (FakeStockLink.Written) -> Unit = { w -> + when (w.sid) { + BleProtocol.SID_SECURITY_AUTH -> link.notify(w.address, authSuccess(w.magic), w.sid) + BleProtocol.PRELUDE_ACK_SID -> link.notify(w.address, ack(BleProtocol.PRELUDE_ACK_MAGIC), w.sid) + BleProtocol.SID_UI_SETTING -> link.notify(w.address, settingsAck(w.magic, batteries[w.address] ?: -1), w.sid) + BleProtocol.SID_EVENHUB -> { + val cmd = BleProtocol.readVarintFieldValue(BleProtocol.stripTrailingCrc(w.pb), 1, -1) + link.notify(w.address, ack(w.magic), w.sid) + // Cmd 0 = create page: the user taps a row right away (a scroll first, which must be ignored). + if (cmd == 0 && selection != null) { + link.notify(w.address, listSelection(FlashPromptFlow.LIST_NAME, "other", 0, BleProtocol.EVENT_SCROLL_TOP), BleProtocol.SID_EVENHUB, BleProtocol.FLAG_NOTIFY) + link.notify(w.address, listSelection(FlashPromptFlow.LIST_NAME, FlashPromptFlow.ITEMS[selection], selection, BleProtocol.EVENT_CLICK), BleProtocol.SID_EVENHUB, BleProtocol.FLAG_NOTIFY) + } + } + } + } + + @Test + fun promptApprovalReadsBothBatteriesAndShutsDown() { + val link = FakeStockLink() + link.responder = promptResponder(link, 1, mapOf(R to 85, L to 70)) + val events = PromptEvents() + FlashPromptFlow(link, R, L, "warning", false, events, fast, testPlatform()).run() + assertEquals(true, events.result, events.logs.joinToString("\n")) + assertEquals(85 to 70, events.battery) + assertEquals(listOf("connecting:", "connected:", "prompting:", "battery:", "result:approved"), events.states) + val hub = link.writes.filter { it.sid == BleProtocol.SID_EVENHUB }.map { BleProtocol.readVarintFieldValue(BleProtocol.stripTrailingCrc(it.pb), 1, -1) } + assertEquals(0, hub.first()) // create page + assertEquals(9, hub.last()) // shutdown + assertTrue(link.writes.all { it.sid != BleProtocol.SID_EVENHUB || it.address == R }) + assertTrue(link.closed) + } + + @Test + fun promptDeclineTimeoutAndSkip() { + val declined = FakeStockLink() + declined.responder = promptResponder(declined, 0, mapOf()) + var events = PromptEvents() + FlashPromptFlow(declined, R, "", "w", false, events, fast, testPlatform()).run() + assertEquals(false, events.result) + assertEquals("result:declined", events.states.last()) + assertEquals(null, events.battery) + + val silent = FakeStockLink() + silent.responder = promptResponder(silent, null, mapOf()) + events = PromptEvents() + FlashPromptFlow(silent, R, "", "w", false, events, fast, testPlatform()).run() + assertEquals(null, events.result) + assertEquals("timeout:No response from the glasses.", events.states.last()) + // Heartbeats (EvenHub cmd 12) kept the page alive while waiting (interval 15 ms, wait 80 ms). + assertTrue(silent.writes.count { it.sid == BleProtocol.SID_EVENHUB && BleProtocol.readVarintFieldValue(BleProtocol.stripTrailingCrc(it.pb), 1, -1) == 12 } >= 2) + + val skipped = FakeStockLink() + skipped.responder = promptResponder(skipped, null, mapOf(R to 50)) + events = PromptEvents() + FlashPromptFlow(skipped, R, L, "w", true, events, fast, testPlatform()).run() + assertEquals(true, events.result) + assertEquals(50 to -1, events.battery) + assertFalse(skipped.writes.any { it.sid == BleProtocol.SID_EVENHUB }) + + val lost = FakeStockLink() + lost.responder = { w -> + promptResponder(lost, null, mapOf())(w) + if (w.sid == BleProtocol.SID_EVENHUB) lost.drop(R) + } + events = PromptEvents() + FlashPromptFlow(lost, R, "", "w", false, events, fast, testPlatform()).run() + assertEquals("disconnected:Lost connection to the glasses.", events.states.last()) + } + + // ---- OTA --------------------------------------------------------------- + + private fun putU32(buf: ByteArray, offset: Int, value: Long) { for (i in 0 until 4) buf[offset + i] = ((value ushr (8 * i)) and 0xff).toByte() } + + private fun container(): ByteArray { + val mainApp = ByteArray(6000) { (it * 7).toByte() }.also { putU32(it, 0, 6000L); putU32(it, 0x14, FirmwareImage.APP_LOAD_ADDR) } + val components = listOf("ota/bootloader.bin" to ByteArray(300) { it.toByte() }, "ota/a.bin" to ByteArray(64) { 1 }, "ota/b.bin" to ByteArray(128) { 2 }, "ota/c.bin" to ByteArray(32) { 3 }, FirmwareImage.REQUIRED_SEGMENT to mainApp) + val toc = FirmwareImage.HEADER_SIZE + components.size * FirmwareImage.TOC_ENTRY_SIZE + var offset = toc + val offsets = components.map { c -> offset.also { offset += FirmwareImage.SUBHEADER_SIZE + c.second.size } } + val img = ByteArray(offset) + putU32(img, 8, components.size.toLong()) + components.forEachIndexed { i, c -> + val off = offsets[i] + putU32(img, FirmwareImage.HEADER_SIZE + i * 16 + 4, off.toLong()) + putU32(img, off + 8, c.second.size.toLong()) + c.first.encodeToByteArray().copyInto(img, off + FirmwareImage.NAME_OFFSET) + c.second.copyInto(img, off + FirmwareImage.SUBHEADER_SIZE) + val crc = FirmwareImage.crc32cUnsigned(c.second) + putU32(img, FirmwareImage.HEADER_SIZE + i * 16 + 12, crc) + putU32(img, off + 12, crc) + } + return img + } + + private class FlashEvents : FaceclawFirmwareFlasherListener { + val logs = ArrayList(); val states = ArrayList(); val progress = ArrayList(); var complete: Pair? = null + override fun onLog(line: String?) { logs.add(line ?: "") } + override fun onProgress(lens: String?, componentIndex: Int, componentCount: Int, blockIndex: Int, blockCount: Int, bytesSent: Long, bytesTotal: Long) { progress.add("$lens $componentIndex/$componentCount $blockIndex/$blockCount $bytesSent/$bytesTotal") } + override fun onState(state: String?, detail: String?) { states.add("$state:$detail") } + override fun onComplete(success: Boolean, detail: String?) { complete = success to (detail ?: "") } + } + + /** OTA lens: NAKs one block once and fails one END once, exercising both retry paths. */ + private class OtaLens(val link: FakeStockLink) { + val received = HashMap() + var nakOnce = true + var failEndOnce = true + var component = ByteArray(0) + fun respond(w: FakeStockLink.Written) { + when (w.sid) { + BleProtocol.SID_SECURITY_AUTH -> link.notify(w.address, authSuccess(w.magic), w.sid) + OtaFlashFlow.SID_CTRL -> { + val pb = BleProtocol.stripTrailingCrc(w.pb) + when (pb[0].toInt()) { + OtaFlashFlow.OP_BEGIN -> link.otaAck(w.address, OtaFlashFlow.OP_BEGIN, 0) + OtaFlashFlow.OP_FILE_CHECK -> { component = ByteArray(0); link.otaAck(w.address, OtaFlashFlow.OP_FILE_CHECK, 0) } + OtaFlashFlow.OP_END -> { + val status = if (failEndOnce) { failEndOnce = false; 5 } else { received[w.address] = (received[w.address] ?: ByteArray(0)) + component; 9 } + link.otaAck(w.address, OtaFlashFlow.OP_END, status) + } + OtaFlashFlow.OP_BLOCK -> {} + } + } + OtaFlashFlow.SID_DATA -> { + val block = BleProtocol.stripTrailingCrc(w.pb) + if (nakOnce) { nakOnce = false; link.otaAck(w.address, OtaFlashFlow.OP_BLOCK, 1) } else { component += block; link.otaAck(w.address, OtaFlashFlow.OP_BLOCK, 0) } + } + } + } + } + + @Test + fun otaFlashesBothLensesWithBlockNakAndEndRetry() { + val img = container() + val segs = FirmwareImage.validate(img) + val link = FakeStockLink() + val lens = OtaLens(link) + link.responder = lens::respond + val events = FlashEvents() + OtaFlashFlow(link, R, L, "fw.bin", events, fast, testPlatform()) { img }.run() + assertEquals(true to "Both lenses flashed. The glasses are rebooting into the custom firmware.", events.complete, events.logs.joinToString("\n")) + assertEquals(listOf("validating:", "connecting:left", "flashing:left", "rebooting:Left lens done. Both lenses reboot briefly; reconnecting for the right lens.", "connecting:right", "flashing:right", "done:"), events.states) + // Every component payload arrived intact on both lenses, in order. + val expected = segs.fold(ByteArray(0)) { acc, s -> acc + img.copyOfRange(s.payloadStart, s.payloadStart + s.ps) } + assertContentEquals(expected, lens.received[L]!!) + assertContentEquals(expected, lens.received[R]!!) + assertTrue(events.logs.any { it.contains("NAK=1 resend 1/3") }) + assertTrue(events.logs.any { it.contains("END verify FAILED (status 5)") }) + assertTrue(events.logs.any { it.contains("re-flash attempt 2/3") }) + assertEquals("left 5/5 2/2 6524/6524", events.progress.first { it.startsWith("left 5/5 2") }) + // Marker + data share one envelope seq; the OTA stream restarts at 1 per lens. + val leftOta = link.writes.filter { it.address == L && it.uuid == BleProtocol.OTA_DATA_WRITE_UUID } + assertEquals(1, leftOta.first().seq) + val firstBlock = leftOta.indexOfFirst { it.sid == OtaFlashFlow.SID_DATA } + assertEquals(leftOta[firstBlock - 1].seq, leftOta[firstBlock].seq) + assertEquals(setOf(BleProtocol.WRITE_CHAR_UUID), link.writes.filter { it.sid == BleProtocol.SID_SECURITY_AUTH }.map { it.uuid }.toSet()) + } + + @Test + fun otaGivesUpWhenLensConnectWindowExpires() { + val link = FakeStockLink() + link.connectResult = { false } + val events = FlashEvents() + OtaFlashFlow(link, R, L, "fw.bin", events, fast, testPlatform()) { container() }.run() + assertEquals(false to "could not reach left lens: connect/discover incomplete", events.complete) + assertEquals("error:could not reach left lens: connect/discover incomplete", events.states.last()) + assertTrue(events.logs.count { it.contains("left connect attempt") } >= 2) + assertTrue(link.closed) + + val unreadable = FlashEvents() + OtaFlashFlow(FakeStockLink(), R, L, "/nonexistent/fw.bin", unreadable, fast, testPlatform()).run() + assertTrue(unreadable.complete!!.second.startsWith("could not read firmware"), unreadable.complete!!.second) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/VoiceCaptureSessionTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/VoiceCaptureSessionTest.kt new file mode 100644 index 00000000..17711f98 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/VoiceCaptureSessionTest.kt @@ -0,0 +1,273 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class VoiceCaptureSessionTest { + /** Real clock plus an offset the test can advance to force decode cadences. */ + private class ShiftedPlatform(private val base: ProtocolPlatform) : ProtocolPlatform by base { + var offsetMs = 0L + override fun elapsedRealtimeMs(): Long = base.elapsedRealtimeMs() + offsetMs + } + + private class Events : FaceclawVoiceControllerListener { + val statuses = mutableListOf() + val transcripts = mutableListOf>() + val pcmChunks = mutableListOf() + val frameMeta = mutableListOf>() + var speechEnds = 0 + var verified: Pair? = null + val stopped = mutableListOf() + val stoppedLatch = Latch(1, testPlatform()) + override fun onStatus(status: String?) { statuses.add(status) } + override fun onTranscript(text: String?, isFinal: Boolean) { transcripts.add(text to isFinal) } + override fun onStopped(captureId: Int) { stopped.add(captureId); stoppedLatch.countDown() } + override fun onPcm(pcm16le: ByteArray?) { pcmChunks.add(pcm16le!!) } + override fun onFrameMeta(angleDegrees: Int, ssr: Int) { frameMeta.add(angleDegrees to ssr) } + override fun onSpeechEnd() { speechEnds++ } + override fun onSpeakerVerified(isWearer: Boolean, similarity: Float) { verified = isWearer to similarity } + } + + /** Scripted phone mic: each entry is a chunk amplitude; after the script the read fails (-1). */ + private class ScriptedMic(private val amplitudes: List, private val onRead: () -> Unit = {}) : PcmAudioSource { + var index = 0 + var closed = false + override fun read(pcm: ShortArray): Int { + onRead() + if (index >= amplitudes.size) return -1 + val amplitude = amplitudes[index++] + for (i in pcm.indices) pcm[i] = (if (i % 2 == 0) amplitude else -amplitude).toShort() + return pcm.size + } + override fun close() { closed = true } + } + + private class FakeTranscriber(private val text: (Int) -> String) : OfflineTranscriber { + val calls = mutableListOf() + var released = false + override fun recognize(samples: FloatArray, count: Int): String { calls.add(count); return text(count) } + override fun release() { released = true } + } + + private class FakeHost( + val platform: ProtocolPlatform, + var mic: PcmAudioSource? = null, + var transcriber: OfflineTranscriber? = null, + var hasModel: Boolean = true, + var embedding: FloatArray? = null, + var g2Ready: Boolean = false, + ) : VoiceCaptureHost { + override val dispatcher = CallbackDispatcher { it() } + var packetListener: FaceclawAudioPacketListener? = null + var g2Stops = 0 + val recordings = mutableListOf() + override fun onSessionStarting() {} + override fun isG2SessionReady(): Boolean = g2Ready + override fun isG2AudioCaptureActive(): Boolean = packetListener != null + override fun g2AudioSource(): PacketAudioSource? = if (!g2Ready) null else object : PacketAudioSource { + override fun start(listener: FaceclawAudioPacketListener): Boolean { packetListener = listener; return true } + override fun stop() { g2Stops++ } + override fun isActive(): Boolean = packetListener != null + } + override fun createPacketDecoder(): AudioPacketDecoder = object : AudioPacketDecoder { + override fun decodePacket(packet: ByteArray?, pcmOut: ShortArray?): Int { + if (packet == null || packet.size != Lc3PacketFramer.PACKET_BYTES) return 0 + pcmOut!!.fill(packet[0].toShort()) + lastAngleDegrees = Lc3PacketFramer.readTrailerS16(packet, Lc3PacketFramer.ANGLE_OFFSET) + lastSsr = Lc3PacketFramer.readTrailerS16(packet, Lc3PacketFramer.SSR_OFFSET) + realPackets++ + return Lc3PacketFramer.SAMPLES_PER_PACKET + } + override var lastAngleDegrees = 0 + override var lastSsr = 0 + override var realPackets = 0L + override val duplicatePackets = 0L + override val missingPackets = 0L + override val decodeErrors = 0L + override fun close() {} + } + override fun openPhoneMic(): PcmAudioSource? = mic + override fun hasTranscriberModel(kind: VoiceModelKind): Boolean = hasModel + override fun loadTranscriber(kind: VoiceModelKind): OfflineTranscriber = transcriber ?: error("no transcriber") + override fun speakerEmbedder(modelPath: String): SpeakerEmbedder = object : SpeakerEmbedder { + override fun embed(pcm16le: ByteArray, sampleRate: Int): FloatArray? = embedding + override fun release() {} + } + override fun recordingSink(): RecordingSink = RecordingSink { bytes, _ -> recordings.add(bytes) } + } + + private val logs = mutableListOf() + + private fun session(host: VoiceCaptureHost, platform: ProtocolPlatform, name: String) = + VoiceCaptureSession(host, platform, name, { logs.add("I $it") }, { logs.add("W $it") }, { m, e -> logs.add("E $m ${e.message}") }) + + private fun packet(value: Int, angle: Int, ssr: Int): ByteArray { + val bytes = ByteArray(Lc3PacketFramer.PACKET_BYTES) + bytes[0] = value.toByte() + bytes[Lc3PacketFramer.SSR_OFFSET] = (ssr and 0xff).toByte() + bytes[Lc3PacketFramer.SSR_OFFSET + 1] = (ssr shr 8).toByte() + bytes[Lc3PacketFramer.ANGLE_OFFSET] = (angle and 0xff).toByte() + bytes[Lc3PacketFramer.ANGLE_OFFSET + 1] = (angle shr 8).toByte() + return bytes + } + + @Test + fun beamGateWrapsAroundAndClampsHalfWidth() { + val session = session(FakeHost(testPlatform()), testPlatform(), "voice-test-beam") + session.setBeamFilter(true, 170, 30) + assertTrue(session.withinBeam(170)) + assertTrue(session.withinBeam(-170)) // 20 degrees away across the wrap + assertFalse(session.withinBeam(120)) + session.setBeamFilter(true, 0, 1) // clamps to 5 + assertTrue(session.withinBeam(5)) + assertFalse(session.withinBeam(6)) + } + + @Test + fun droppingQueueKeepsNewestAndCountsDrops() { + val queue = DroppingPacketQueue(3, testPlatform()) + for (i in 1..5) queue.put(i) + assertEquals(2L, queue.droppedCount) + assertEquals(3, queue.take(10) { true }) + assertEquals(4, queue.take(10) { true }) + assertEquals(5, queue.take(10) { true }) + assertNull(queue.take(10, { true })) + assertNull(queue.take(10, { false })) + } + + @Test + fun g2PacketsAreCountedGatedAndForwarded() { + val platform = ShiftedPlatform(testPlatform()) + val host = FakeHost(platform, g2Ready = true) + val events = Events() + val session = session(host, platform, "voice-test-g2") + session.setListener(events) + session.setBeamFilter(true, 0, 30) + session.start("cloud", 7) + val deadline = platform.elapsedRealtimeMs() + 3000 + while (host.packetListener == null && platform.elapsedRealtimeMs() < deadline) sleepMs(5) + val listener = host.packetListener!! + listener.onAudioPacket(packet(1, 10, 5), "L", 1000) + listener.onAudioPacket(packet(2, 90, 5), "L", 1050) // outside the beam: meta only + listener.onAudioPacket(packet(3, 0, 0), "R", 1200) // wrong arm, late (150 ms gap), ssr 0 passes the gate + listener.onAudioPacket(ByteArray(3), "L", 1230) // bad length: dropped by the decoder + val waitUntil = platform.elapsedRealtimeMs() + 3000 + while (events.pcmChunks.size < 2 && platform.elapsedRealtimeMs() < waitUntil) sleepMs(5) + session.stop() + assertTrue(events.stoppedLatch.await(3000)) + val stats = session.audioStats() + assertEquals(4L, stats.queuedPackets) + assertEquals(1L, stats.wrongArmPackets) + assertEquals(1L, stats.latePackets) + assertEquals(150L, stats.maxInterPacketMs) + assertEquals(2, events.pcmChunks.size) + assertEquals(Lc3PacketFramer.SAMPLES_PER_PACKET * 2, events.pcmChunks[0].size) + assertEquals(listOf(10 to 5, 90 to 5, 0 to 0), events.frameMeta) + assertEquals(listOf(7), events.stopped) + assertTrue(host.g2Stops >= 1) + assertTrue(events.statuses.contains("Listening (cloud)...")) + assertTrue(events.transcripts.isEmpty()) + assertTrue(logs.any { it.startsWith("I G2 mic packets=4 decoded=3") && it.contains("wrongArm=1") }, logs.toString()) + } + + @Test + fun startRefusesWithoutGlassesAndWhenAlreadyRunning() { + val host = FakeHost(testPlatform(), g2Ready = false) + val events = Events() + val session = session(host, testPlatform(), "voice-test-refuse") + session.setListener(events) + session.start("onboard", 3) + assertEquals>(listOf("Voice control needs an active G2 connection."), events.statuses) + assertEquals(listOf(3), events.stopped) + assertFalse(session.isCapturing()) + } + + @Test + fun onboardTranscriptCommitsSegmentsAndFinalizesWithReplaceSemantics() { + val platform = ShiftedPlatform(testPlatform()) + // 170 chunks of 800 samples = 8.5 s: one 8 s segment commit plus a tail. + val mic = ScriptedMic(List(170) { 3000 }) { platform.offsetMs += 1000 } + val transcriber = FakeTranscriber { "x" } + val host = FakeHost(platform, mic = mic, transcriber = transcriber) + val events = Events() + val session = session(host, platform, "voice-test-onboard") + session.setListener(events) + session.setUsePhoneMic(true) + session.setSaveRecordings(true) + session.start("onboard", 1) + assertTrue(events.stoppedLatch.await(10000)) + assertTrue(mic.closed) + assertTrue(transcriber.released) + assertEquals("Loading transcription model...", events.statuses[0]) + assertEquals("Listening...", events.statuses[1]) + val finals = events.transcripts.filter { it.second } + assertEquals(1, finals.size) + assertEquals("x x", finals.single().first) + assertEquals("x" to false, events.transcripts.first()) + assertTrue(events.transcripts.any { it == ("x x" to false) }) + // Every segment handed to the model is at most 8 s and was peak-normalized. + assertTrue(transcriber.calls.all { it in 1..VoiceCaptureSession.TRANSCRIPT_SEGMENT_MAX_SAMPLES }) + assertTrue(logs.any { it.startsWith("I Moonshine decode final=true") }, logs.toString()) + assertEquals(1, host.recordings.size) + assertEquals(170 * 800 * 2, host.recordings[0].size) + assertEquals(170, events.pcmChunks.size) + assertEquals("x x", VoiceCaptureSession.joinTranscript("x", "x")) + assertEquals("x, y", VoiceCaptureSession.joinTranscript("x", ", y")) + } + + @Test + fun endpointingFiresOnceAfterSpeechThenSilence() { + val platform = ShiftedPlatform(testPlatform()) + val script = List(8) { 0 } + List(10) { 3000 } + List(24) { 0 } + val host = FakeHost(platform, mic = ScriptedMic(script)) + val events = Events() + val session = session(host, platform, "voice-test-endpoint") + session.setListener(events) + session.setUsePhoneMic(true) + session.setEndpointing(true) + session.start("cloud", 2) + assertTrue(events.stoppedLatch.await(10000)) + assertEquals(1, events.speechEnds) + assertNull(events.verified) + } + + @Test + fun speakerVerificationFailsOpenAndComparesEmbeddings() { + fun run(embedding: FloatArray?, chunks: Int): Pair? { + val platform = ShiftedPlatform(testPlatform()) + val host = FakeHost(platform, mic = ScriptedMic(List(chunks) { 1000 }), embedding = embedding) + val events = Events() + val session = session(host, platform, "voice-test-verify") + session.setListener(events) + session.setUsePhoneMic(true) + session.setSpeakerVerification("model", floatArrayOf(1f, 0f), 0.8f) + session.start("cloud", 4) + assertTrue(events.stoppedLatch.await(10000)) + return events.verified + } + assertEquals?>(true to 0f, run(floatArrayOf(1f, 0f), 10)) // under 1 s: too short, fails open + assertEquals?>(true to 0f, run(null, 30)) // no embedding: fails open + assertEquals?>(true to 0f, run(floatArrayOf(1f), 30)) // dimension mismatch: fails open + assertEquals?>(true to 1f, run(floatArrayOf(1f, 0f), 30)) + assertEquals?>(false to 0f, run(floatArrayOf(0f, 1f), 30)) + } + + @Test + fun missingModelReportsAndStops() { + val host = FakeHost(testPlatform(), mic = ScriptedMic(emptyList()), hasModel = false) + val events = Events() + val session = session(host, testPlatform(), "voice-test-nomodel") + session.setListener(events) + session.setUsePhoneMic(true) + session.start("onboard", 9) + assertTrue(events.stoppedLatch.await(5000)) + assertEquals>(listOf("Voice model not downloaded (see Settings > Voice)."), events.statuses) + assertEquals(listOf(9), events.stopped) + assertEquals("1.50", formatFixed(1.5, 2)) + assertEquals("-0.333", formatFixed(-1.0 / 3, 3)) + assertEquals("0", formatFixed(0.4, 0)) + } +} From c3a0ba9f56ca7b3b398ec1144bc6a47e362d26e5 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 19:55:08 -0700 Subject: [PATCH 12/27] Refactor Kotlin for iOS commonality --- App_Resources/iOS/src/FaceclawBluetooth.h | 14 - App_Resources/iOS/src/FaceclawBluetooth.m | 197 ----- App_Resources/iOS/src/FaceclawRemoteInput.h | 13 - App_Resources/iOS/src/FaceclawRemoteInput.m | 166 ---- App_Resources/iOS/src/FaceclawSseRequest.h | 8 - App_Resources/iOS/src/FaceclawSseRequest.m | 153 ---- app/g2/firmware-ota.ts | 91 --- app/g2/flash-prompt-protocol.ts | 18 - app/g2/stock-connection.ts | 152 ---- .../faceclaw/app/g2protocol/FirmwareImage.kt | 4 +- .../g2protocol/session/GlassesSessionCore.kt | 46 ++ .../faceclaw/app/net/RemoteInputSession.kt | 13 +- .../com/faceclaw/app/IosFrameTimings.kt | 90 +++ .../com/faceclaw/app/PlatformUtil.ios.kt | 10 +- .../com/faceclaw/app/ble/IosBleCentral.kt | 718 ++++++++++++++++++ .../com/faceclaw/app/ble/IosGlassesSession.kt | 245 ++++++ .../com/faceclaw/app/ble/IosSessionHost.kt | 92 +++ .../com/faceclaw/app/ble/IosStockFlows.kt | 173 +++++ .../faceclaw/app/net/IosModelDownloader.kt | 257 +++++++ .../com/faceclaw/app/net/IosPosixSockets.kt | 265 +++++++ .../com/faceclaw/app/net/IosRemoteInput.kt | 54 ++ .../com/faceclaw/app/net/IosSseRequest.kt | 119 +++ .../com/faceclaw/app/net/IosStreamingHttp.kt | 117 +++ package.json | 3 +- scripts/before_build.sh | 2 + .../hooks/faceclaw-kotlin.before-prepare.js | 8 + scripts/install-hooks.cjs | 31 + scripts/ios.sh | 1 + tests/ios-onboarding-ota.test.cjs | 142 ---- .../com/faceclaw/app/IosNetworkingTest.kt | 314 ++++++++ .../com/faceclaw/app/IosSessionFacadeTest.kt | 228 ++++++ 31 files changed, 2780 insertions(+), 964 deletions(-) delete mode 100644 App_Resources/iOS/src/FaceclawBluetooth.h delete mode 100644 App_Resources/iOS/src/FaceclawBluetooth.m delete mode 100644 App_Resources/iOS/src/FaceclawRemoteInput.h delete mode 100644 App_Resources/iOS/src/FaceclawRemoteInput.m delete mode 100644 App_Resources/iOS/src/FaceclawSseRequest.h delete mode 100644 App_Resources/iOS/src/FaceclawSseRequest.m delete mode 100644 app/g2/firmware-ota.ts delete mode 100644 app/g2/flash-prompt-protocol.ts delete mode 100644 app/g2/stock-connection.ts create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosFrameTimings.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosSessionHost.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosStockFlows.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosModelDownloader.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosPosixSockets.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosRemoteInput.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosSseRequest.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosStreamingHttp.kt create mode 100644 scripts/hooks/faceclaw-kotlin.before-prepare.js create mode 100644 scripts/install-hooks.cjs delete mode 100644 tests/ios-onboarding-ota.test.cjs create mode 100644 tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosNetworkingTest.kt create mode 100644 tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosSessionFacadeTest.kt diff --git a/App_Resources/iOS/src/FaceclawBluetooth.h b/App_Resources/iOS/src/FaceclawBluetooth.h deleted file mode 100644 index e59bf88c..00000000 --- a/App_Resources/iOS/src/FaceclawBluetooth.h +++ /dev/null @@ -1,14 +0,0 @@ -#import -#import - -/** Main-queue CoreBluetooth adapter. Protocol and MAC matching live in TS. */ -@interface FaceclawBluetooth : NSObject -@property (nonatomic, copy) void (^eventHandler)(NSString *json); -- (void)initializeBluetooth; -- (void)scan:(BOOL)enabled; -- (void)connect:(NSString *)identifier requestId:(NSInteger)requestId; -- (void)connect:(NSString *)identifier requiresANCS:(BOOL)requiresANCS requestId:(NSInteger)requestId; -- (void)subscribe:(NSString *)identifier characteristic:(NSString *)uuid requestId:(NSInteger)requestId; -- (void)write:(NSString *)identifier characteristic:(NSString *)uuid data:(NSData *)data requestId:(NSInteger)requestId; -- (void)disconnect:(NSString *)identifier; -@end diff --git a/App_Resources/iOS/src/FaceclawBluetooth.m b/App_Resources/iOS/src/FaceclawBluetooth.m deleted file mode 100644 index 6ba03e75..00000000 --- a/App_Resources/iOS/src/FaceclawBluetooth.m +++ /dev/null @@ -1,197 +0,0 @@ -#import "FaceclawBluetooth.h" - -@interface FCBPeripheral : NSObject -@property (nonatomic, strong) CBPeripheral *peripheral; -@property (nonatomic, strong) NSMutableDictionary *characteristics; -@property (nonatomic, strong) NSMutableDictionary *subscriptions; -@property (nonatomic, strong) NSMutableArray *writes; -@property (nonatomic, strong) NSNumber *connectRequest; -@property (nonatomic) NSInteger pendingServices; -@property (nonatomic) BOOL awaitingWriteResponse; -@end -@implementation FCBPeripheral -- (instancetype)init { - if ((self = [super init])) { - _characteristics = [NSMutableDictionary new]; _subscriptions = [NSMutableDictionary new]; - _writes = [NSMutableArray new]; - } - return self; -} -@end - -@interface FaceclawBluetooth () -@property (nonatomic, strong) CBCentralManager *central; -@property (nonatomic, strong) NSMutableDictionary *peers; -@property (nonatomic) BOOL scanRequested; -@end - -@implementation FaceclawBluetooth -- (instancetype)init { if ((self = [super init])) _peers = [NSMutableDictionary new]; return self; } -- (void)emit:(NSDictionary *)event { - if (!self.eventHandler) return; - NSData *data = [NSJSONSerialization dataWithJSONObject:event options:0 error:nil]; - if (data) self.eventHandler([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); -} -- (void)complete:(NSNumber *)request error:(NSString *)error details:(NSDictionary *)details { - if (!request) return; - NSMutableDictionary *event = [@{ @"kind": @"completion", @"id": request } mutableCopy]; - if (error) event[@"error"] = error; - if (details) event[@"details"] = details; - [self emit:event]; -} -- (void)initializeBluetooth { - if (!self.central) self.central = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()]; - else [self centralManagerDidUpdateState:self.central]; -} -- (void)scan:(BOOL)enabled { - self.scanRequested = enabled; - if (!enabled) { [self.central stopScan]; return; } - [self initializeBluetooth]; - if (self.central.state == CBManagerStatePoweredOn) - [self.central scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey: @YES}]; -} -- (void)centralManagerDidUpdateState:(CBCentralManager *)central { - [self emit:@{@"kind": @"state", @"state": @(central.state), @"authorization": @(CBManager.authorization)}]; - if (central.state != CBManagerStatePoweredOn) { - for (FCBPeripheral *peer in self.peers.allValues) [self failPeer:peer reason:@"Bluetooth is unavailable"]; - } else if (self.scanRequested) { - [central scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey: @YES}]; - } -} -- (FCBPeripheral *)remember:(CBPeripheral *)peripheral { - NSString *identifier = peripheral.identifier.UUIDString; - FCBPeripheral *peer = self.peers[identifier]; - if (!peer) { peer = [FCBPeripheral new]; peer.peripheral = peripheral; self.peers[identifier] = peer; } - peripheral.delegate = self; - return peer; -} -- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisement RSSI:(NSNumber *)RSSI { - [self remember:peripheral]; - NSData *data = advertisement[CBAdvertisementDataManufacturerDataKey]; - NSMutableString *hex = [NSMutableString new]; - const uint8_t *bytes = data.bytes; - for (NSUInteger i = 0; i < data.length; i++) [hex appendFormat:@"%02x", bytes[i]]; - [self emit:@{@"kind": @"advertisement", @"identifier": peripheral.identifier.UUIDString, - @"name": advertisement[CBAdvertisementDataLocalNameKey] ?: peripheral.name ?: @"", - @"manufacturerData": hex, @"rssi": RSSI, - @"connectable": advertisement[CBAdvertisementDataIsConnectable] ?: @YES}]; -} -- (void)connect:(NSString *)identifier requestId:(NSInteger)requestId { - [self connect:identifier requiresANCS:NO requestId:requestId]; -} -- (void)connect:(NSString *)identifier requiresANCS:(BOOL)requiresANCS requestId:(NSInteger)requestId { - if (self.central.state != CBManagerStatePoweredOn) { [self complete:@(requestId) error:@"Bluetooth is not ready" details:nil]; return; } - FCBPeripheral *peer = self.peers[identifier.uppercaseString]; - if (!peer) { - NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:identifier]; - CBPeripheral *peripheral = uuid ? [self.central retrievePeripheralsWithIdentifiers:@[uuid]].firstObject : nil; - if (peripheral) peer = [self remember:peripheral]; - } - if (!peer) { [self complete:@(requestId) error:@"Peripheral is unknown; scan for the device first" details:nil]; return; } - if (peer.connectRequest || peer.peripheral.state != CBPeripheralStateDisconnected) { - [self complete:@(requestId) error:@"Peripheral is already connecting or connected" details:nil]; return; - } - [peer.characteristics removeAllObjects]; peer.connectRequest = @(requestId); - [self.central connectPeripheral:peer.peripheral options:requiresANCS ? @{CBConnectPeripheralOptionRequiresANCS: @YES} : nil]; -} -- (void)centralManager:(CBCentralManager *)central didUpdateANCSAuthorizationForPeripheral:(CBPeripheral *)peripheral { - [self emit:@{@"kind": @"ancs-authorization", @"identifier": peripheral.identifier.UUIDString, - @"authorized": @(peripheral.ancsAuthorized)}]; -} -- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { - [peripheral discoverServices:nil]; -} -- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { - [self failPeer:[self remember:peripheral] reason:error.localizedDescription ?: @"Connection failed"]; -} -- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { - [self failPeer:[self remember:peripheral] reason:error.localizedDescription ?: @"Disconnected"]; -} -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error { - FCBPeripheral *peer = [self remember:peripheral]; - if (error || !peripheral.services.count) { [self failPeer:peer reason:error.localizedDescription ?: @"No services found"]; return; } - peer.pendingServices = peripheral.services.count; - for (CBService *service in peripheral.services) [peripheral discoverCharacteristics:nil forService:service]; -} -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { - FCBPeripheral *peer = [self remember:peripheral]; - if (!peer.connectRequest) return; - if (error) { [self failPeer:peer reason:error.localizedDescription]; return; } - for (CBCharacteristic *characteristic in service.characteristics) peer.characteristics[characteristic.UUID.UUIDString.lowercaseString] = characteristic; - if (--peer.pendingServices == 0) { - NSNumber *request = peer.connectRequest; peer.connectRequest = nil; - [self complete:request error:nil details:@{@"characteristics": peer.characteristics.allKeys, - @"maxWrite": @([peripheral maximumWriteValueLengthForType:CBCharacteristicWriteWithoutResponse])}]; - } -} -- (void)subscribe:(NSString *)identifier characteristic:(NSString *)uuid requestId:(NSInteger)requestId { - FCBPeripheral *peer = self.peers[identifier.uppercaseString]; - CBCharacteristic *characteristic = peer.characteristics[uuid.lowercaseString]; - if (!characteristic || !(characteristic.properties & (CBCharacteristicPropertyNotify | CBCharacteristicPropertyIndicate))) { - [self complete:@(requestId) error:@"Notification characteristic is unavailable" details:nil]; return; - } - if (characteristic.isNotifying) { [self complete:@(requestId) error:nil details:nil]; return; } - if (peer.subscriptions[uuid.lowercaseString]) { [self complete:@(requestId) error:@"Subscription already pending" details:nil]; return; } - peer.subscriptions[uuid.lowercaseString] = @(requestId); - [peer.peripheral setNotifyValue:YES forCharacteristic:characteristic]; -} -- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { - FCBPeripheral *peer = [self remember:peripheral]; NSString *key = characteristic.UUID.UUIDString.lowercaseString; - NSNumber *request = peer.subscriptions[key]; [peer.subscriptions removeObjectForKey:key]; - [self complete:request error:error.localizedDescription ?: (characteristic.isNotifying ? nil : @"Notifications not enabled") details:nil]; -} -- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { - if (error) { [self emit:@{@"kind": @"error", @"message": error.localizedDescription}]; return; } - NSMutableString *hex = [NSMutableString new]; NSData *data = characteristic.value; const uint8_t *bytes = data.bytes; - for (NSUInteger i = 0; i < data.length; i++) [hex appendFormat:@"%02x", bytes[i]]; - [self emit:@{@"kind": @"notification", @"identifier": peripheral.identifier.UUIDString, - @"characteristic": characteristic.UUID.UUIDString.lowercaseString, @"data": hex}]; -} -- (void)write:(NSString *)identifier characteristic:(NSString *)uuid data:(NSData *)data requestId:(NSInteger)requestId { - FCBPeripheral *peer = self.peers[identifier.uppercaseString]; - CBCharacteristic *characteristic = peer.characteristics[uuid.lowercaseString]; - if (!characteristic || peer.peripheral.state != CBPeripheralStateConnected) { - [self complete:@(requestId) error:@"Write characteristic is disconnected or unavailable" details:nil]; return; - } - CBCharacteristicWriteType type = (characteristic.properties & CBCharacteristicPropertyWriteWithoutResponse) - ? CBCharacteristicWriteWithoutResponse : CBCharacteristicWriteWithResponse; - if (!(characteristic.properties & (CBCharacteristicPropertyWriteWithoutResponse | CBCharacteristicPropertyWrite)) || - data.length > [peer.peripheral maximumWriteValueLengthForType:type]) { - [self complete:@(requestId) error:@"Write exceeds the negotiated BLE payload size or is unsupported" details:nil]; return; - } - if (peer.writes.count >= 256) { [self complete:@(requestId) error:@"Bluetooth write queue is full" details:nil]; return; } - [peer.writes addObject:@{@"id": @(requestId), @"characteristic": characteristic, @"data": [data copy], @"type": @(type)}]; - [self drain:peer]; -} -- (void)drain:(FCBPeripheral *)peer { - while (peer.writes.count && !peer.awaitingWriteResponse && peer.peripheral.state == CBPeripheralStateConnected) { - NSDictionary *write = peer.writes.firstObject; - CBCharacteristicWriteType type = [write[@"type"] integerValue]; - if (type == CBCharacteristicWriteWithoutResponse && !peer.peripheral.canSendWriteWithoutResponse) return; - if (type == CBCharacteristicWriteWithResponse) peer.awaitingWriteResponse = YES; - [peer.peripheral writeValue:write[@"data"] forCharacteristic:write[@"characteristic"] type:type]; - if (peer.awaitingWriteResponse) return; - [peer.writes removeObjectAtIndex:0]; [self complete:write[@"id"] error:nil details:nil]; - } -} -- (void)peripheralIsReadyToSendWriteWithoutResponse:(CBPeripheral *)peripheral { [self drain:[self remember:peripheral]]; } -- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { - FCBPeripheral *peer = [self remember:peripheral]; - if (!peer.awaitingWriteResponse || !peer.writes.count) return; - NSDictionary *write = peer.writes.firstObject; [peer.writes removeObjectAtIndex:0]; peer.awaitingWriteResponse = NO; - [self complete:write[@"id"] error:error.localizedDescription details:nil]; [self drain:peer]; -} -- (void)failPeer:(FCBPeripheral *)peer reason:(NSString *)reason { - if (!peer) return; - NSNumber *connect = peer.connectRequest; peer.connectRequest = nil; - [self complete:connect error:reason details:nil]; - NSArray *subscriptions = peer.subscriptions.allValues; [peer.subscriptions removeAllObjects]; - NSArray *writes = [peer.writes copy]; [peer.writes removeAllObjects]; peer.awaitingWriteResponse = NO; - for (NSNumber *request in subscriptions) [self complete:request error:reason details:nil]; - for (NSDictionary *write in writes) [self complete:write[@"id"] error:reason details:nil]; - [peer.characteristics removeAllObjects]; - if (peer.peripheral.state != CBPeripheralStateDisconnected) [self.central cancelPeripheralConnection:peer.peripheral]; - [self emit:@{@"kind": @"disconnected", @"identifier": peer.peripheral.identifier.UUIDString, @"message": reason}]; -} -- (void)disconnect:(NSString *)identifier { [self failPeer:self.peers[identifier.uppercaseString] reason:@"Disconnected"]; } -@end diff --git a/App_Resources/iOS/src/FaceclawRemoteInput.h b/App_Resources/iOS/src/FaceclawRemoteInput.h deleted file mode 100644 index 4a5708f4..00000000 --- a/App_Resources/iOS/src/FaceclawRemoteInput.h +++ /dev/null @@ -1,13 +0,0 @@ -#import -@interface FaceclawRemoteInput : NSObject -+ (instancetype)shared; -+ (NSString *)interfaces; -- (NSString *)start:(int)port; -- (NSString *)start:(int)port address:(NSString *)address; -- (void)stop; -- (void)setRequestListener:(void (^)(void))listener; -- (NSString *)nextRequest; -- (void)complete:(long long)identifier response:(NSString *)response; -- (NSString *)randomSecret; -- (NSString *)tokenDigest:(NSString *)value; -@end diff --git a/App_Resources/iOS/src/FaceclawRemoteInput.m b/App_Resources/iOS/src/FaceclawRemoteInput.m deleted file mode 100644 index b7e73446..00000000 --- a/App_Resources/iOS/src/FaceclawRemoteInput.m +++ /dev/null @@ -1,166 +0,0 @@ -#import "FaceclawRemoteInput.h" -#import "FaceclawCrypto.h" -#import -#import -#import -#import -#import -#import -#import -#import -#import - -@implementation FaceclawRemoteInput { - NSCondition *_condition; - int _server, _client; - NSUInteger _generation; - long long _nextId, _requestId; - NSTimeInterval _deadline; - NSString *_pending, *_reply; - void (^_requestListener)(void); -} -+ (instancetype)shared { - static FaceclawRemoteInput *instance; static dispatch_once_t once; - dispatch_once(&once, ^{ instance = [self new]; }); return instance; -} -- (instancetype)init { - if ((self = [super init])) { _condition = [NSCondition new]; _server = _client = -1; } - return self; -} -- (NSString *)start:(int)port { return [self start:port address:@"127.0.0.1"]; } -- (NSString *)start:(int)port address:(NSString *)address { - [_condition lock]; - if (_server >= 0) { [_condition unlock]; return @""; } - struct addrinfo hints = {0}, *resolved = NULL; - hints.ai_flags = AI_NUMERICHOST; hints.ai_socktype = SOCK_STREAM; - NSString *service = [NSString stringWithFormat:@"%d", port]; - if (getaddrinfo(address.UTF8String, service.UTF8String, &hints, &resolved) != 0) { - [_condition unlock]; return @"Invalid local address."; - } - BOOL wildcard = resolved->ai_family == AF_INET ? - ((struct sockaddr_in *)resolved->ai_addr)->sin_addr.s_addr == INADDR_ANY : - IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)resolved->ai_addr)->sin6_addr); - if (wildcard) { freeaddrinfo(resolved); [_condition unlock]; return @"Wildcard addresses are not allowed."; } - int fd = socket(resolved->ai_family, SOCK_STREAM, 0), yes = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); - int result = fd < 0 ? -1 : bind(fd, resolved->ai_addr, (socklen_t)resolved->ai_addrlen); - freeaddrinfo(resolved); - if (result || listen(fd, 8)) { - if (fd >= 0) close(fd); [_condition unlock]; return @"Could not open input port on this address."; - } - _server = fd; NSUInteger generation = ++_generation; - [_condition unlock]; - dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{ [self serve:fd generation:generation]; }); - return @""; -} -- (void)stop { - [_condition lock]; ++_generation; - // The serving thread owns close(); shutdown interrupts its blocking I/O. - if (_server >= 0) shutdown(_server, SHUT_RDWR); - if (_client >= 0) shutdown(_client, SHUT_RDWR); - _server = _client = -1; _requestId = 0; _pending = _reply = nil; - [_condition broadcast]; [_condition unlock]; -} -- (NSString *)nextRequest { - [_condition lock]; - NSString *result = NSDate.date.timeIntervalSince1970 < _deadline ? _pending : nil; - _pending = nil; [_condition unlock]; return result; -} -- (void)setRequestListener:(void (^)(void))listener { - [_condition lock]; _requestListener = [listener copy]; [_condition unlock]; -} -- (void)notifyRequestReady:(long long)identifier { - // Dispatch from under the condition lock; invoke JS only on the main thread, - // outside the lock, and discard notifications invalidated by stop/timeout. - dispatch_async(dispatch_get_main_queue(), ^{ - [self->_condition lock]; - void (^callback)(void) = self->_requestId == identifier && self->_pending && - NSDate.date.timeIntervalSince1970 < self->_deadline ? self->_requestListener : nil; - [self->_condition unlock]; - if (callback) callback(); - }); -} -- (void)complete:(long long)identifier response:(NSString *)response { - [_condition lock]; - if (_requestId == identifier && NSDate.date.timeIntervalSince1970 < _deadline) { _reply = response; [_condition signal]; } - [_condition unlock]; -} -- (void)serve:(int)listener generation:(NSUInteger)generation { - for (;;) { - [_condition lock]; BOOL current = generation == _generation; [_condition unlock]; - if (!current) break; - // Poll also guarantees stop is observed on platforms where shutdown does not wake accept. - struct pollfd p = { .fd = listener, .events = POLLIN }; - if (poll(&p, 1, 250) <= 0) continue; - int client = accept(listener, NULL, NULL); - if (client < 0) break; - @autoreleasepool { - [_condition lock]; current = generation == _generation; - if (current) _client = client; - [_condition unlock]; - if (!current) { close(client); break; } - struct timeval timeout = {5, 0}; int yes = 1; - setsockopt(client, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); - setsockopt(client, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); - setsockopt(client, SOL_SOCKET, SO_NOSIGPIPE, &yes, sizeof(yes)); - NSTimeInterval readDeadline = NSDate.date.timeIntervalSince1970 + 5; - NSMutableData *body = [NSMutableData new]; unsigned char byte; BOOL complete = NO; - while (body.length <= 65536) { - NSTimeInterval remaining = readDeadline - NSDate.date.timeIntervalSince1970; - struct pollfd input = { .fd = client, .events = POLLIN }; - if (remaining <= 0 || poll(&input, 1, (int)(remaining * 1000)) <= 0 || recv(client, &byte, 1, 0) != 1) break; - if (byte == '\n') { complete = YES; break; } - [body appendBytes:&byte length:1]; - } - NSString *text = complete ? [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding] : nil; - if (text) { - [_condition lock]; - if (generation == _generation) { - _requestId = ++_nextId; _deadline = NSDate.date.timeIntervalSince1970 + 5; _reply = nil; - NSData *json = [NSJSONSerialization dataWithJSONObject:@{@"id":@(_requestId), @"expiresAt":@(_deadline * 1000), @"body":text} options:0 error:nil]; - _pending = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding]; - [self notifyRequestReady:_requestId]; - while (!_reply && generation == _generation && NSDate.date.timeIntervalSince1970 < _deadline) - [_condition waitUntilDate:[NSDate dateWithTimeIntervalSince1970:_deadline]]; - NSString *reply = _reply ?: @"{\"ok\":false,\"error\":\"timeout\",\"message\":\"Faceclaw did not respond in time.\"}"; - if (generation == _generation) { _pending = _reply = nil; _requestId = 0; } - [_condition unlock]; - NSData *data = [[reply stringByAppendingString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding]; - NSUInteger offset = 0; - while (offset < data.length) { - ssize_t n = send(client, (const char *)data.bytes + offset, data.length - offset, 0); - if (n <= 0) break; offset += n; - } - } else [_condition unlock]; - } - [_condition lock]; if (generation == _generation) _client = -1; [_condition unlock]; - close(client); - } - } - close(listener); - [_condition lock]; if (generation == _generation) _server = -1; [_condition unlock]; -} -+ (NSString *)interfaces { - NSMutableArray *result = [NSMutableArray new]; struct ifaddrs *interfaces = NULL; - if (getifaddrs(&interfaces) == 0) { - for (struct ifaddrs *item = interfaces; item; item = item->ifa_next) { - if (!item->ifa_addr || !(item->ifa_flags & IFF_UP) || (item->ifa_flags & IFF_LOOPBACK)) continue; - int family = item->ifa_addr->sa_family; - if (family != AF_INET && family != AF_INET6) continue; - char address[NI_MAXHOST]; - if (getnameinfo(item->ifa_addr, item->ifa_addr->sa_len, address, sizeof(address), NULL, 0, NI_NUMERICHOST)) continue; - [result addObject:@{@"name":@(item->ifa_name), @"address":@(address), @"pointToPoint":@((item->ifa_flags & IFF_POINTOPOINT) != 0)}]; - } - freeifaddrs(interfaces); - } - return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:result options:0 error:nil] encoding:NSUTF8StringEncoding]; -} -- (NSString *)randomSecret { - unsigned char bytes[32]; - if (SecRandomCopyBytes(kSecRandomDefault, sizeof(bytes), bytes) != errSecSuccess) return @""; - NSMutableString *hex = [NSMutableString new]; - for (NSUInteger i = 0; i < sizeof(bytes); i++) [hex appendFormat:@"%02x", bytes[i]]; - return hex; -} -- (NSString *)tokenDigest:(NSString *)value { return [FaceclawCrypto sha256:[value dataUsingEncoding:NSUTF8StringEncoding]]; } -@end diff --git a/App_Resources/iOS/src/FaceclawSseRequest.h b/App_Resources/iOS/src/FaceclawSseRequest.h deleted file mode 100644 index 3177e20b..00000000 --- a/App_Resources/iOS/src/FaceclawSseRequest.h +++ /dev/null @@ -1,8 +0,0 @@ -#import - -/** Streaming POST. Events are polled by the owning JS isolate, including workers. */ -@interface FaceclawSseRequest : NSObject -- (instancetype)initWithURL:(NSString *)url body:(NSString *)body headers:(NSString *)headersJson; -- (NSString *)takeEvents; -- (void)cancel; -@end diff --git a/App_Resources/iOS/src/FaceclawSseRequest.m b/App_Resources/iOS/src/FaceclawSseRequest.m deleted file mode 100644 index 7e793257..00000000 --- a/App_Resources/iOS/src/FaceclawSseRequest.m +++ /dev/null @@ -1,153 +0,0 @@ -#import "FaceclawSseRequest.h" -#import -#if TARGET_OS_IOS -#import -#endif - -@interface FaceclawSseRequest () -@property(nonatomic, strong) NSURLSession *session; -@property(nonatomic, strong) NSURLSessionDataTask *task; -@property(nonatomic, strong) NSMutableData *buffer; -@property(nonatomic, strong) NSMutableArray *events; -@property(nonatomic) NSUInteger queuedBytes; -@property(nonatomic) NSInteger status; -@property(nonatomic) BOOL finished; -@property(nonatomic) BOOL cancelled; -@property(nonatomic) BOOL firstLine; -#if TARGET_OS_IOS -@property(nonatomic) UIBackgroundTaskIdentifier backgroundTask; -#endif -@end - -@implementation FaceclawSseRequest -- (instancetype)initWithURL:(NSString *)url body:(NSString *)body headers:(NSString *)headersJson { - if ((self = [super init])) { - _buffer = [NSMutableData new]; _events = [NSMutableArray new]; _firstLine = YES; -#if TARGET_OS_IOS - _backgroundTask = UIBackgroundTaskInvalid; - dispatch_async(dispatch_get_main_queue(), ^{ - @synchronized(self) { - if (self.cancelled || self.finished) return; - self.backgroundTask = [UIApplication.sharedApplication beginBackgroundTaskWithName:@"Assistant response" expirationHandler:^{ - [self finish:@{@"kind": @"failure", @"text": @"iOS background time expired. Open Faceclaw and retry."}]; - [self endBackgroundTask]; - }]; - } - }); -#endif - NSURL *target = [NSURL URLWithString:url]; - if (!target || ![@[@"https", @"http"] containsObject:target.scheme.lowercaseString]) { - [self finish:@{@"kind": @"failure", @"text": @"Invalid streaming URL"}]; return self; - } - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:target]; - request.HTTPMethod = @"POST"; - request.HTTPBody = [body dataUsingEncoding:NSUTF8StringEncoding]; - [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; - [request setValue:@"text/event-stream" forHTTPHeaderField:@"Accept"]; - NSDictionary *headers = [NSJSONSerialization JSONObjectWithData:[headersJson dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil]; - if ([headers isKindOfClass:NSDictionary.class]) for (NSString *name in headers) { - if ([headers[name] isKindOfClass:NSString.class]) [request setValue:headers[name] forHTTPHeaderField:name]; - } - NSURLSessionConfiguration *config = NSURLSessionConfiguration.ephemeralSessionConfiguration; - config.timeoutIntervalForRequest = 180; - config.timeoutIntervalForResource = 180; - _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; - _task = [_session dataTaskWithRequest:request]; - [_task resume]; - } - return self; -} -- (void)endBackgroundTask { -#if TARGET_OS_IOS - dispatch_async(dispatch_get_main_queue(), ^{ - @synchronized(self) { - if (self.backgroundTask == UIBackgroundTaskInvalid) return; - [UIApplication.sharedApplication endBackgroundTask:self.backgroundTask]; - self.backgroundTask = UIBackgroundTaskInvalid; - } - }); -#endif -} -- (void)finish:(NSDictionary *)event { - @synchronized(self) { - if (_finished || _cancelled) return; - _finished = YES; [_events addObject:event]; - [_session invalidateAndCancel]; _session = nil; _task = nil; - [_buffer setLength:0]; - } -} -- (NSString *)takeEvents { - @synchronized(self) { - NSData *data = [NSJSONSerialization dataWithJSONObject:_events options:0 error:nil]; - [_events removeAllObjects]; _queuedBytes = 0; - if (_finished) [self endBackgroundTask]; - return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ?: @"[]"; - } -} -- (void)cancel { - @synchronized(self) { - _cancelled = YES; - [_events removeAllObjects]; [_buffer setLength:0]; _queuedBytes = 0; - [_session invalidateAndCancel]; _session = nil; _task = nil; - [self endBackgroundTask]; - } -} -- (void)line:(NSData *)data { - NSString *line = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - if (!line) { [self finish:@{@"kind": @"failure", @"text": @"Invalid UTF-8 in streaming response"}]; return; } - if (_firstLine && [line hasPrefix:@"\uFEFF"]) line = [line substringFromIndex:1]; - _firstLine = NO; - _queuedBytes += data.length; - if (_queuedBytes > 8 * 1024 * 1024 || _events.count >= 16384) { - [_events removeAllObjects]; - [self finish:@{@"kind": @"failure", @"text": @"Streaming response queue overflow"}]; return; - } - [_events addObject:@{@"kind": @"line", @"text": line}]; -} -- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler { - @synchronized(self) { _status = [(NSHTTPURLResponse *)response statusCode]; } - completionHandler(NSURLSessionResponseAllow); -} -- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest *))completionHandler { - // Never forward provider credentials to a redirected endpoint. - completionHandler(nil); -} -- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)task didReceiveData:(NSData *)data { - @synchronized(self) { - if (_finished || _cancelled) return; - if (_status < 200 || _status >= 300) { - NSUInteger remaining = 65536 - _buffer.length; - [_buffer appendData:[data subdataWithRange:NSMakeRange(0, MIN(remaining, data.length))]]; - return; - } - [_buffer appendData:data]; - NSUInteger start = 0; - const uint8_t *bytes = _buffer.bytes; - for (NSUInteger i = 0; i < _buffer.length; i++) { - if (bytes[i] != '\r' && bytes[i] != '\n') continue; - if (bytes[i] == '\r' && i + 1 == _buffer.length) break; - [self line:[_buffer subdataWithRange:NSMakeRange(start, i - start)]]; - if (_finished) return; - if (bytes[i] == '\r' && bytes[i + 1] == '\n') i++; - start = i + 1; - } - if (start) [_buffer replaceBytesInRange:NSMakeRange(0, start) withBytes:NULL length:0]; - if (_buffer.length > 2 * 1024 * 1024) [self finish:@{@"kind": @"failure", @"text": @"Streaming response line too large"}]; - } -} -- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { - @synchronized(self) { - if (_finished || _cancelled) return; - if (error) { [self finish:@{@"kind": @"failure", @"text": error.localizedDescription}]; return; } - if (_status < 200 || _status >= 300) { - NSString *body = [[NSString alloc] initWithData:_buffer encoding:NSUTF8StringEncoding] ?: @""; - [self finish:@{@"kind": @"http-error", @"code": @(_status), @"text": body}]; return; - } - if (_buffer.length) { - if (((const uint8_t *)_buffer.bytes)[_buffer.length - 1] == '\r') [_buffer setLength:_buffer.length - 1]; - [self line:_buffer]; - } - [self finish:@{@"kind": @"complete"}]; - } -} -@end diff --git a/app/g2/firmware-ota.ts b/app/g2/firmware-ota.ts deleted file mode 100644 index 78cc4701..00000000 --- a/app/g2/firmware-ota.ts +++ /dev/null @@ -1,91 +0,0 @@ -/** Stock EVENOTA validation and transfer, matching Android's flasher/g2flash.py. */ -import { StockConnection, OTA_WRITE, OTA_NOTIFY } from './stock-connection' -import { concat } from './ble-protocol' -import type { FlashProgress } from './firmware-types' - -export type FirmwareSegment = { offset: number; size: number; name: string } -const CRC_TABLE = Array.from({ length: 256 }, (_, b) => { - let c = b << 24 - for (let i = 0; i < 8; i++) c = c & 0x80000000 ? (c << 1) ^ 0x1edc6f41 : c << 1 - return c >>> 0 -}) -export function firmwareCrc(data: Uint8Array): number { - let crc = 0 - for (const byte of data) crc = (crc << 8) ^ CRC_TABLE[((crc >>> 24) ^ byte) & 255] - return crc >>> 0 -} -export function validateFirmware(image: Uint8Array): FirmwareSegment[] { - const u32 = (offset: number) => { - if (offset < 0 || offset + 4 > image.length) throw new Error('Firmware header is truncated.') - return new DataView(image.buffer, image.byteOffset, image.byteLength).getUint32(offset, true) - } - if (image.length < 0x40) throw new Error('File is too small to be a firmware image.') - const count = u32(8) - if (count < 5 || count > 6 || 0x40 + count * 16 > image.length) throw new Error('Expected 5–6 firmware components.') - const segments: FirmwareSegment[] = [] - for (let i = 0; i < count; i++) { - const toc = 0x40 + i * 16, offset = u32(toc + 4) - if (offset < 0x40 + count * 16 || offset + 128 > image.length) throw new Error('Firmware component header is out of bounds.') - const size = u32(offset + 8), end = offset + 128 + size - if (!size || end > image.length) throw new Error('Firmware component payload is truncated.') - if (segments.some(s => offset < s.offset + 128 + s.size && s.offset < end)) throw new Error('Firmware components overlap.') - const nameBytes = image.subarray(offset + 48, offset + 128) - const name = String.fromCharCode(...nameBytes.subarray(0, nameBytes.indexOf(0) < 0 ? 80 : nameBytes.indexOf(0))) - const crc = firmwareCrc(image.subarray(offset + 128, end)) - if (crc !== u32(toc + 12) || crc !== u32(offset + 12)) throw new Error(`Component ${name} CRC32C is stale (image not checksum-fixed).`) - segments.push({ offset, size, name }) - } - const mains = segments.filter(s => s.name === 'ota/s200_firmware_ota.bin') - if (mains.length !== 1) throw new Error('Required main firmware component is missing or duplicated.') - const main = mains[0], payload = main.offset + 128 - if (main.size < 32 || u32(payload + 0x14) !== 0x00438000 || (u32(payload) & 0xffffff) !== main.size) - throw new Error('Main-app preamble load address or length is invalid.') - if (0x00438000 + main.size - 32 > 0x007f0000) throw new Error('Main-app exceeds the safe MRAM ceiling — refusing to flash.') - return segments -} - -export async function flashLensImage(link: StockConnection, role: string, image: Uint8Array, segments: FirmwareSegment[], - progress: (value: FlashProgress) => void, log: (line: string) => void, - delay: (ms: number) => Promise): Promise { - let sequence = 0 - const ctrl = async (op: number, payload = new Uint8Array(), data?: Uint8Array): Promise => { - sequence = (sequence + 1) & 255 - const message = await link.exchange(role, 0xc0, concat(new Uint8Array([op]), payload), - message => message.command === op, data ? 4000 : 8000, OTA_WRITE, OTA_NOTIFY, 0, sequence, data) - return message.payload[1] - } - const accepted = (status: number) => [0, 8, 9].includes(status) - const begin = await ctrl(0) - if (!accepted(begin)) throw new Error(`OTA BEGIN rejected (status ${begin}).`) - const total = segments.reduce((sum, segment) => sum + segment.size, 0) - let before = 0 - for (const [index, segment] of segments.entries()) { - let verified = false, failure: unknown - for (let attempt = 0; attempt < 3; attempt++) { - link.check() - if (attempt) { log(`${segment.name}: re-flash attempt ${attempt + 1}/3`); await delay(1500) } - try { - const status = await ctrl(1, image.slice(segment.offset, segment.offset + 128)) - if (status !== 0) throw new Error(`FILE_CHECK rejected (status ${status}).`) - const blocks = Math.ceil(segment.size / 4096) - for (let block = 0; block < blocks; block++) { - const start = segment.offset + 128 + block * 4096 - const data = image.slice(start, Math.min(start + 4096, segment.offset + 128 + segment.size)) - let ok = false - for (let retry = 0; retry < 3; retry++) { - if (await ctrl(2, new Uint8Array(), data) === 0) { ok = true; break } - } - if (!ok) throw new Error(`Block ${block + 1} rejected three times.`) - if (block % 20 === 0 || block === blocks - 1) - progress({ lens: role, componentIndex: index + 1, componentCount: segments.length, blockIndex: block + 1, - blockCount: blocks, bytesSent: before + Math.min((block + 1) * 4096, segment.size), bytesTotal: total }) - } - const end = await ctrl(3) - if (!accepted(end)) throw new Error(`END verification failed (status ${end}).`) - log(`${role} ${segment.name}: END verify OK (status ${end})`); verified = true; break - } catch (error) { link.check(); failure = error } - } - if (!verified) throw new Error(`Component ${segment.name} failed after 3 attempts: ${failure}`) - before += segment.size - } -} diff --git a/app/g2/flash-prompt-protocol.ts b/app/g2/flash-prompt-protocol.ts deleted file mode 100644 index d4e166e4..00000000 --- a/app/g2/flash-prompt-protocol.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { bytes, concat, integer, readBytes, readInteger, readString, type ProtocolMessage } from './ble-protocol' -const text = (field: number, value: string) => bytes(field, new Uint8Array(Array.from(value, ch => ch.charCodeAt(0)))) -export function createFlashPrompt(magic: number, warning: string): Uint8Array { - const geometry = (y: number, height: number, id: number, name: string) => concat( - integer(1, 0), integer(2, y), integer(3, 280), integer(4, height), integer(9, id), text(10, name)) - const list = concat(geometry(150, 120, 2, 'flashmenu'), bytes(11, concat(integer(1, 2), integer(3, 1), text(4, 'No, cancel'), text(4, 'Yes, flash'))), integer(12, 1)) - const label = concat(geometry(0, 130, 1, 'flashwarn'), text(12, warning)) - return concat(integer(1, 0), integer(2, magic), bytes(3, concat(integer(1, 2), bytes(2, list), bytes(3, label), integer(5, 10000)))) -} -export function flashPromptSelection(message: ProtocolMessage): boolean | null { - if (message.sid !== 0xe0 || ![1, 6].includes(message.flag)) return null - const event = readBytes(message.payload, 13), list = event && readBytes(event, 1) - if (!list || readString(list, 2) !== 'flashmenu' || readInteger(list, 5, 0) !== 0) return null - const index = readInteger(list, 4, -1), name = readString(list, 3).toLowerCase() - if (index === 1 || name.startsWith('yes')) return true - if (index === 0 || name.startsWith('no')) return false - return null -} diff --git a/app/g2/stock-connection.ts b/app/g2/stock-connection.ts deleted file mode 100644 index edce1b4f..00000000 --- a/app/g2/stock-connection.ts +++ /dev/null @@ -1,152 +0,0 @@ -import * as p from './ble-protocol' -import type { SessionTransport, SessionAddresses, TransportEvent } from './glasses-session' -import { hexToBytes } from '../util/hex-util' - -declare function setTimeout(callback: () => void, ms: number): number -declare function clearTimeout(id: number): void - -export const OTA_WRITE = '00002760-08c2-11e1-9073-0e8ac72e0001' -export const OTA_NOTIFY = '00002760-08c2-11e1-9073-0e8ac72e0002' -export class StockTimeout extends Error {} -type Waiter = { role: string; characteristic: string; match: (message: p.ProtocolMessage) => boolean; - resolve: (message: p.ProtocolMessage) => void; reject: (error: Error) => void; timer: ReturnType | null } - -/** Exclusive, short-lived stock-protocol connection for onboarding/OTA. No display pump. */ -export class StockConnection { - ids: Record = {} - private limits: Record = {} - private receiver = new p.MessageReceiver() - private waiters = new Set() - private listeners = new Set<(role: string, message: p.ProtocolMessage) => void>() - private lost = new Set() - private writes = new Map>() - private closed = false - private magic = 0x60 - private sequence = 0 - private off: () => void - constructor(private transport: SessionTransport, private log: (line: string) => void = () => {}) { - this.off = transport.onEvent(event => this.receive(event)) - } - check(): void { if (this.closed) throw new Error('Cancelled.') } - isConnected(role: string): boolean { return !this.closed && !!this.limits[role] && !this.lost.has(role) } - async resolve(addresses: SessionAddresses): Promise { - this.ids = await this.transport.resolveDevices(addresses); this.check() - } - async connect(role: string, ota = false): Promise { - this.check(); this.lost.delete(role) - const id = this.ids[role] - if (!id) throw new Error(`No ${role} lens configured.`) - const details = await this.transport.connect(id) - if (this.closed) { this.transport.disconnect(id); this.check() } - this.limits[role] = details.maxWrite - for (const characteristic of [p.G2_WRITE, p.G2_NOTIFY, ...(ota ? [OTA_WRITE, OTA_NOTIFY] : [])]) - if (!details.characteristics.includes(characteristic)) throw new Error(`${role} lens is missing ${ota ? 'firmware update' : 'G2'} characteristics.`) - await this.transport.subscribe(id, p.G2_NOTIFY); this.check() - if (ota) { await this.transport.subscribe(id, OTA_NOTIFY); this.check() } - } - nextMagic(): number { this.magic = this.magic >= 0x7f ? 0x60 : this.magic + 1; return this.magic } - async authenticate(role: string): Promise { - for (let attempt = 0; attempt < 2; attempt++) { - const magic = this.nextMagic() - try { - await this.exchange(role, p.SID.auth, p.authentication(magic), - message => p.authenticationSucceeded(message, magic), 30_000, p.G2_WRITE, p.G2_NOTIFY, 0) - this.log(`Security authentication complete: ${role} lens`); return - } catch (error) { this.check(); if (!(error instanceof StockTimeout) || attempt === 1) throw error } - } - } - request(role: string, sid: number, build: (magic: number) => Uint8Array, timeout = 3500, fixedMagic?: number): Promise { - const magic = fixedMagic ?? this.nextMagic() - return this.exchange(role, sid, build(magic), message => message.sid === sid && message.magic === magic && ![1, 6].includes(message.flag), timeout) - } - write(role: string, sid: number, payload: Uint8Array, characteristic = p.G2_WRITE, flag = 0x20, sequence = ++this.sequence): Promise { - // Keep a fragmented control message together when the prompt heartbeat - // overlaps a settings request or shutdown. - const pending = (this.writes.get(role) ?? Promise.resolve()).catch(() => {}).then(async () => { - this.check() - for (const frame of p.frameMessage(payload, sid, flag, sequence, this.limits[role])) { - this.check() - if (this.lost.has(role)) throw new Error(`Lost connection to the ${role} lens.`) - await this.transport.write(this.ids[role], characteristic, frame) - } - this.check() - if (this.lost.has(role)) throw new Error(`Lost connection to the ${role} lens.`) - }) - this.writes.set(role, pending) - return pending - } - exchange(role: string, sid: number, payload: Uint8Array, match: Waiter['match'], timeout: number, - write = p.G2_WRITE, notify = p.G2_NOTIFY, flag = 0x20, sequence?: number, data?: Uint8Array): Promise { - this.check() - return new Promise((resolve, reject) => { - let written = false, reply: p.ProtocolMessage | null = null - const waiter: Waiter = { role, characteristic: notify, match, - resolve: message => { reply = message; if (written) resolve(message) }, reject, - timer: null } - this.waiters.add(waiter) - void (async () => { - await this.write(role, sid, payload, write, flag, sequence) - if (data) await this.write(role, 0xc1, data, write, flag, sequence) - this.check() - if (!reply && !this.waiters.has(waiter)) return - written = true - if (reply) resolve(reply) - else waiter.timer = setTimeout(() => { - this.waiters.delete(waiter) - reject(new StockTimeout(`No response from the ${role} lens (0x${sid.toString(16)}).`)) - }, timeout) - })().catch(error => { this.waiters.delete(waiter); if (waiter.timer !== null) clearTimeout(waiter.timer); reject(error) }) - }) - } - - onMessage(listener: (role: string, message: p.ProtocolMessage) => void): () => void { - this.listeners.add(listener); return () => this.listeners.delete(listener) - } - private receive(event: TransportEvent): void { - if (this.closed) return - const role = Object.keys(this.ids).find(role => this.ids[role] === event.identifier) - if (!role) return - if (event.kind === 'disconnected') { - this.lost.add(role) - for (const waiter of [...this.waiters]) if (waiter.role === role) { - this.waiters.delete(waiter); if (waiter.timer !== null) clearTimeout(waiter.timer); waiter.reject(new Error(`Lost connection to the ${role} lens.`)) - } - return - } - if (event.kind !== 'notification' || !event.data || ![p.G2_NOTIFY, OTA_NOTIFY].includes(event.characteristic!)) return - try { - const data = hexToBytes(event.data) - const messages = event.characteristic === OTA_NOTIFY ? decodeOtaAcks(data) : this.receiver.receive(event.identifier!, data) - for (const message of messages) { - for (const waiter of [...this.waiters]) if (waiter.role === role && waiter.characteristic === event.characteristic && waiter.match(message)) { - this.waiters.delete(waiter); if (waiter.timer !== null) clearTimeout(waiter.timer); waiter.resolve(message) - } - if (event.characteristic === p.G2_NOTIFY) for (const listener of this.listeners) listener(role, message) - } - } catch (error) { this.log(`Ignored malformed onboarding notification: ${error}`) } - } - disconnect(role: string): void { this.lost.add(role); if (this.ids[role]) this.transport.disconnect(this.ids[role]); this.receiver.clear() } - close(): void { - if (this.closed) return - this.closed = true; this.off(); this.transport.stopScan() - for (const waiter of this.waiters) { if (waiter.timer !== null) clearTimeout(waiter.timer); waiter.reject(new Error('Cancelled.')) } - this.waiters.clear(); this.listeners.clear() - for (const role of Object.keys(this.ids)) this.disconnect(role) - } -} - -/** OTA ACKs are raw opcode/status bytes, not protobuf; validate the aa21 CRC envelope. */ -export function decodeOtaAcks(data: Uint8Array): p.ProtocolMessage[] { - const messages: p.ProtocolMessage[] = [] - for (let offset = 0; offset + 8 <= data.length;) { - const n = data[offset + 3], end = offset + 8 + n - if (end > data.length) break - if (data[offset] === 0xaa && [0x12, 0x21].includes(data[offset + 1]) && data[offset + 4] === 1 && data[offset + 5] === 1 && n >= 4) { - const payload = data.slice(offset + 8, end - 2) - if (p.crc16(payload) === (data[end - 2] | data[end - 1] << 8)) - messages.push({ sid: data[offset + 6], flag: data[offset + 7], payload, command: payload[0], magic: -1 }) - } - offset = end - } - return messages -} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt index a1c62bce..c8c7a4d5 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/FirmwareImage.kt @@ -19,7 +19,7 @@ object FirmwareImage { const val TOC_ENTRY_SIZE = 16 const val SUBHEADER_SIZE = 128 const val NAME_OFFSET = 48 - const val NAME_MAX = 80 + const val NAME_LENGTH = 80 // Firmware 2.2.4 has 5 components; 2.2.6 has 6. const val MIN_SEGMENTS = 5 @@ -107,7 +107,7 @@ object FirmwareImage { if (psLong <= 0 || off + SUBHEADER_SIZE + psLong > img.size) { throw IllegalStateException("segment $i payload is truncated") } - val name = readCString(img, off + NAME_OFFSET, NAME_MAX) + val name = readCString(img, off + NAME_OFFSET, NAME_LENGTH) val seg = Segment(off, psLong.toInt(), crc, name) for (other in segs) { if (seg.off < other.end && other.off < seg.end) { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt index 8175ccf9..fb85df35 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt @@ -32,6 +32,10 @@ class GlassesSessionCore( companion object { const val TAG = "FaceclawComm" + /** Relay-frame signature ('A','N') checked by [rawFrameTap]. */ + internal const val RELAY_TAG_A: Byte = 0x41 + internal const val RELAY_TAG_N: Byte = 0x4e + // Local metadata for custom-command bookkeeping, not an EvenHub container. // Submitted frames supply pixel geometry; the stock layout only captures input. internal val DASHBOARD_TILE: BleProtocol.ImageTileOptions = @@ -102,6 +106,14 @@ class GlassesSessionCore( internal val ringAddress: String = ringAddress?.trim() ?: "" @Volatile internal var listener: FaceclawBleCommunicatorListener? = null + + /** + * Optional tap for relay frames the session does not interpret: notifications on the + * right arm's data characteristic whose first two bytes are 'A','N' (the iOS ANCS + * notification relay, consumed by the phone-side ANCS client). Unset (Android) they + * fall through to the normal frame parser exactly as before. Called on the BLE thread. + */ + @Volatile internal var rawFrameTap: ((ByteArray) -> Unit)? = null internal val imuListeners = CopyOnWriteList(platform) /** A compass subscriber plus the dispatcher it registered from (see addCompassListener). */ internal class CompassSubscription( @@ -309,6 +321,33 @@ class GlassesSessionCore( // --------------------------------------------------------------------- // Lifecycle + /** See [rawFrameTap]; null restores the default (frames parsed by the session). */ + fun setRawFrameTap(tap: ((ByteArray) -> Unit)?) { + rawFrameTap = tap + } + + /** + * Write one already-framed packet to an arm outside the message scheduler (the ANCS + * relay client builds its own packets). Blocks like any link write; false when the + * arm is unknown, the link rejects the write, or the session is not running. + */ + fun writeRawPacket(arm: String, packet: ByteArray): Boolean { + val address = when (arm.uppercase()) { + "R", "RIGHT" -> rightAddress + "L", "LEFT" -> leftAddress + else -> return false + } + val active = monitor.withLock { running } + if (!active) return false + return try { + link.writeFrames(address, BleProtocol.WRITE_CHAR_UUID, listOf(packet), ConnectionOptions.WRITE_MODE, + ConnectionOptions.WRITE_TIMEOUT_MS) + } catch (t: Throwable) { + logLine("raw packet write failed: " + safeMessage(t)) + false + } + } + fun setListener(listener: FaceclawBleCommunicatorListener?) { this.listener = listener emitState() @@ -1308,6 +1347,13 @@ class GlassesSessionCore( interruptibleSleep.interrupt() return } + val tap = rawFrameTap + if (tap != null && data.size >= 2 && data[0] == RELAY_TAG_A && data[1] == RELAY_TAG_N + && address.equals(rightAddress, ignoreCase = true)) { + monitor.withLock { lastIncomingAtMs = now() } + tap(data.copyOf()) + return + } logDebug("onNotification: address=" + address + " characteristicUuid=" + characteristicUuid + " data.length=" + data.size) val frame = BleProtocol.parseFrame(data) val decodedWearState = BleProtocol.parseWearState(frame) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt index 40d9bbe0..cc27aa64 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/net/RemoteInputSession.kt @@ -132,7 +132,8 @@ class RemoteInputSession( fun randomSecret(): String = BinaryEncoding.bytesToHex(random.nextBytes(32)) private fun notifyRequestReady(id: Long) { - // Called with the condition held; dispatching keeps JS off the socket thread and outside the lock. + // Called WITHOUT the condition held (ProtocolCondition is not reentrant on iOS, and a + // dispatcher may run the closure inline); the closure re-checks the request under the lock. dispatch { val callback = condition.withLock { if (requestId != id || pending == null || wallClock() >= deadline) null else requestListener @@ -150,14 +151,18 @@ class RemoteInputSession( client = connection } val text = readFrame(connection) ?: continue - val response: String = condition.withLock { + val id = condition.withLock { if (server !== listener) return requestId = ++nextId deadline = wallClock() + requestTimeoutMs reply = null pending = Json.write(linkedMapOf("id" to requestId, "expiresAt" to deadline, "body" to text)) - notifyRequestReady(requestId) - while (reply == null && server === listener && wallClock() < deadline) { + requestId + } + notifyRequestReady(id) + val response: String = condition.withLock { + if (server !== listener) return + while (reply == null && requestId == id && server === listener && wallClock() < deadline) { condition.awaitMs(maxOf(1L, deadline - wallClock())) } val result = reply ?: TIMEOUT_RESPONSE diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosFrameTimings.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosFrameTimings.kt new file mode 100644 index 00000000..1fb23767 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosFrameTimings.kt @@ -0,0 +1,90 @@ +package com.faceclaw.app + +import platform.Foundation.NSDocumentDirectory +import platform.Foundation.NSSearchPathForDirectoriesInDomains +import platform.Foundation.NSUserDomainMask + +/** + * iOS facade over the shared [FrameTimingsCore] with the Android FrameTimings method set. + * [startExport] enables the export thread that sweeps timed-out frames every 5 s and writes + * /frame-timings.txt every 15 s while dirty (the app's Documents folder is + * visible in Finder/Files when UIFileSharingEnabled is on). + */ +class IosFrameTimings internal constructor(platform: ProtocolPlatform) { + constructor() : this(IosProtocolPlatform) + + val core = FrameTimingsCore(platform) + private val lock = platform.createLock() + private var exportDir: String? = null + private var exporting = false + + /** Idempotent; enables filesystem export into [directory] (default: Documents). */ + fun startExport(directory: String?) { + lock.withLock { + exportDir = directory ?: documentsDirectory() + if (exporting) return + exporting = true + } + startThread("FrameTimingsExport", true) { exportLoop() } + } + + fun startFrame(reason: String?): Int = core.startFrame(reason) + + fun startFrame(reason: String?, parentFrameId: Int): Int = core.startFrame(reason, parentFrameId) + + fun annotate(frameId: Int, text: String?) = core.annotate(frameId, text) + + fun log(frameId: Int, message: String?) = core.log(frameId, message) + + fun spanStart(frameId: Int, name: String) = core.spanStart(frameId, name) + + fun spanEnd(frameId: Int, name: String) = core.spanEnd(frameId, name) + + fun finishFrame(frameId: Int, outcome: String?) = core.finishFrame(frameId, outcome) + + fun statsSummary(): String = core.statsSummary() + + /** Writes the export now (if anything changed); returns the file path or null. */ + fun exportNow(): String? { + val dir = lock.withLock { exportDir } ?: return null + val content = core.takeExport() ?: return null + val target = "$dir/$EXPORT_FILE_NAME" + val temp = "$target.tmp" + return try { + writeFileData(temp, content.encodeToByteArray()) + if (renameFile(temp, target)) target else { + PlatformLog.w(TAG, "failed to rename $temp to $target") + null + } + } catch (t: Throwable) { + PlatformLog.w(TAG, "failed to export frame timings: ${t.message}") + null + } + } + + private fun exportLoop() { + var lastExportAtMs = 0L + while (true) { + sleepMs(FrameTimingsCore.SWEEP_INTERVAL_MS) + try { + core.sweepTimedOut() + val now = IosProtocolPlatform.elapsedRealtimeMs() + if (core.isExportDirty && now - lastExportAtMs >= FrameTimingsCore.EXPORT_INTERVAL_MS) { + lastExportAtMs = now + exportNow() + } + } catch (t: Throwable) { + PlatformLog.w(TAG, "export loop error: ${t.message}") + } + } + } + + companion object { + private const val TAG = FrameTimingsCore.TAG + const val EXPORT_FILE_NAME = "frame-timings.txt" + val shared: IosFrameTimings by lazy { IosFrameTimings() } + + fun documentsDirectory(): String = + NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstOrNull() as? String ?: "." + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt index 27f43702..185bdfcb 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/PlatformUtil.ios.kt @@ -63,12 +63,16 @@ actual fun formatLocalTime(epochMs: Long, pattern: String): String { } actual object PlatformLog { - actual fun i(tag: String, message: String) = NSLog("%@", "$tag: $message") + // NSLog's vararg bridge cannot take a Kotlin String (it segfaults), so the message becomes + // the format string itself with '%' escaped. + private fun emit(text: String) = NSLog(text.replace("%", "%%")) - actual fun w(tag: String, message: String) = NSLog("%@", "$tag: [warn] $message") + actual fun i(tag: String, message: String) = emit("$tag: $message") + + actual fun w(tag: String, message: String) = emit("$tag: [warn] $message") actual fun e(tag: String, message: String, error: Throwable?) = - NSLog("%@", "$tag: [error] $message" + (error?.let { " (${it.message})" } ?: "")) + emit("$tag: [error] $message" + (error?.let { " (${it.message})" } ?: "")) } actual fun startThread(name: String, daemon: Boolean, body: () -> Unit) { diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt new file mode 100644 index 00000000..aec8d2e0 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt @@ -0,0 +1,718 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlinx.cinterop.BetaInteropApi::class) + +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlinx.cinterop.ObjCSignatureOverride +import platform.CoreBluetooth.CBAdvertisementDataIsConnectable +import platform.CoreBluetooth.CBAdvertisementDataLocalNameKey +import platform.CoreBluetooth.CBAdvertisementDataManufacturerDataKey +import platform.CoreBluetooth.CBCentralManager +import platform.CoreBluetooth.CBCentralManagerDelegateProtocol +import platform.CoreBluetooth.CBCentralManagerScanOptionAllowDuplicatesKey +import platform.CoreBluetooth.CBCharacteristic +import platform.CoreBluetooth.CBCharacteristicPropertyIndicate +import platform.CoreBluetooth.CBCharacteristicPropertyNotify +import platform.CoreBluetooth.CBCharacteristicPropertyWrite +import platform.CoreBluetooth.CBCharacteristicPropertyWriteWithoutResponse +import platform.CoreBluetooth.CBCharacteristicWriteType +import platform.CoreBluetooth.CBCharacteristicWriteWithResponse +import platform.CoreBluetooth.CBCharacteristicWriteWithoutResponse +import platform.CoreBluetooth.CBConnectPeripheralOptionRequiresANCS +import platform.CoreBluetooth.CBManager +import platform.CoreBluetooth.CBManagerStatePoweredOff +import platform.CoreBluetooth.CBManagerStatePoweredOn +import platform.CoreBluetooth.CBManagerStateUnauthorized +import platform.CoreBluetooth.CBManagerStateUnsupported +import platform.CoreBluetooth.CBPeripheral +import platform.CoreBluetooth.CBPeripheralDelegateProtocol +import platform.CoreBluetooth.CBPeripheralStateConnected +import platform.CoreBluetooth.CBPeripheralStateDisconnected +import platform.CoreBluetooth.CBService +import platform.Foundation.NSData +import platform.Foundation.NSError +import platform.Foundation.NSNumber +import platform.Foundation.NSUUID +import platform.darwin.NSObject +import platform.darwin.dispatch_async +import platform.darwin.dispatch_get_main_queue +import platform.darwin.dispatch_queue_create +import platform.darwin.dispatch_sync + +/** Scan/state events for the phone-side device picker; delivered on the main queue. */ +interface IosBleScanListener { + /** CBManagerState raw value and CBManagerAuthorization raw value. */ + fun onBluetoothState(state: Int, authorization: Int) + + fun onAdvertisement(identifier: String, name: String, manufacturerDataHex: String, rssi: Int, connectable: Boolean) +} + +/** ANCS authorization changes for a connected peripheral; delivered on the BLE queue. */ +fun interface IosAncsAuthorizationListener { + fun onAncsAuthorization(identifier: String, authorized: Boolean) +} + +/** + * CoreBluetooth central used by the shared session and stock-firmware flows on iOS. It is + * the iOS counterpart of Android's FaceclawBleManager: every [SessionLink]/[StockLink] call + * blocks the calling (worker) thread until the delegate reports completion or the timeout + * elapses. CoreBluetooth runs on a private serial queue; the calling thread hands it work + * with dispatch_sync and waits on a condition the delegate signals. Addresses are peripheral + * identifier UUID strings (case-insensitive). Inbound notifications and connection-state + * changes go to the registered listeners on the BLE queue; scan events go to the main queue. + * + * Locking: [cond] (non-reentrant) guards all peer state. It is never held across a + * dispatch_sync or a listener callback. + */ +class IosBleCentral(private val platform: ProtocolPlatform = IosProtocolPlatform) : SessionLink, StockLink { + companion object { + const val TAG = "FaceclawBle" + const val ADVERTISEMENT_CACHE = 512 + private const val READY_TIMEOUT_MS = 30_000 + private const val DEFAULT_ATT_MTU = 23 + private const val MAX_ATT_MTU = 517 + } + + private class Peer(val peripheral: CBPeripheral) { + val identifier: String = peripheral.identifier.UUIDString.uppercase() + val characteristics = HashMap() + var connectPending = false + var connected = false + var failure: String? = null + var discoverPending = false + var pendingServices = 0 + var notifyPending: String? = null + var notifyResult: Boolean? = null + var writePending = false + var writeError: String? = null + var readyForWriteWithoutResponse = false + var requiresAncs = false + var reportedConnected = false + } + + private class Advertisement(var name: String, var manufacturerDataHex: String) + + private val queue = dispatch_queue_create("com.faceclaw.ble", null) + private val cond: ProtocolCondition = platform.createCondition() + private val peers = HashMap() + private val advertisements = LinkedHashMap() + private val delegate = Delegate(this) + private var central: CBCentralManager? = null + + @Volatile private var bluetoothState: Long = 0 + @Volatile private var scanRequested = false + @Volatile private var scanListener: IosBleScanListener? = null + @Volatile private var ancsListener: IosAncsAuthorizationListener? = null + @Volatile private var sessionListener: FaceclawBleListener? = null + @Volatile private var stockListener: StockLinkListener? = null + @Volatile private var closed = false + + // ----- listeners ------------------------------------------------------------------ + + /** The session core (a FaceclawBleListener); called on the BLE queue. */ + fun setSessionListener(listener: FaceclawBleListener?) { + sessionListener = listener + } + + override fun setListener(listener: StockLinkListener?) { + stockListener = listener + } + + fun setAncsAuthorizationListener(listener: IosAncsAuthorizationListener?) { + ancsListener = listener + } + + /** Connect [identifier] with CBConnectPeripheralOptionRequiresANCS (the right arm relays iPhone notifications). */ + fun setRequiresAncs(identifier: String, required: Boolean) { + val key = identifier.uppercase() + cond.withLock { peers[key]?.requiresAncs = required } + pendingAncs[key] = required + } + + private val pendingAncs = HashMap() + + /** Whether the OS granted ANCS for the peripheral (false when unknown or disconnected). */ + fun isAncsAuthorized(identifier: String): Boolean = + cond.withLock { peers[identifier.uppercase()]?.peripheral?.ancsAuthorized ?: false } + + // ----- readiness and scanning ----------------------------------------------------------- + + /** Current CBManagerState raw value (0 until the central reports). */ + fun bluetoothState(): Int = bluetoothState.toInt() + + fun authorization(): Int = CBManager.authorization.toInt() + + /** + * Creates the central (which triggers the permission prompt on first use) and waits for + * it to power on. Returns null when ready or a user-facing message (the same texts the + * TypeScript transport used). + */ + fun waitForPoweredOn(timeoutMs: Int = READY_TIMEOUT_MS): String? { + ensureCentral() + val deadline = platform.elapsedRealtimeMs() + timeoutMs + cond.lock() + try { + while (true) { + when (bluetoothState) { + CBManagerStatePoweredOn -> return null + CBManagerStateUnsupported -> return "Bluetooth is unavailable on this device. Use the physical iPhone." + CBManagerStateUnauthorized -> return "Allow Faceclaw to use Bluetooth in iPhone Settings." + CBManagerStatePoweredOff -> return "Turn on Bluetooth, then try again." + } + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) return "Waiting for Bluetooth permission timed out. Try again after allowing Bluetooth." + cond.awaitMs(left) + } + } finally { + cond.unlock() + } + } + + private fun ensureCentral() { + if (central != null) { + // Re-report the current state so a fresh listener learns it. + val listener = scanListener + if (listener != null) { + val state = bluetoothState.toInt() + val authorization = authorization() + dispatch_async(dispatch_get_main_queue()) { listener.onBluetoothState(state, authorization) } + } + return + } + central = CBCentralManager(delegate = delegate, queue = queue) + } + + fun setScanListener(listener: IosBleScanListener?) { + scanListener = listener + } + + /** Starts (or keeps) scanning for all peripherals with duplicates; events reach the scan listener on main. */ + fun startScan() { + scanRequested = true + ensureCentral() + dispatch_sync(queue) { + val manager = central ?: return@dispatch_sync + if (manager.state == CBManagerStatePoweredOn) beginScan(manager) + } + } + + fun stopScan() { + scanRequested = false + dispatch_sync(queue) { central?.stopScan() } + } + + private fun beginScan(manager: CBCentralManager) { + manager.scanForPeripheralsWithServices(null, mapOf(CBCentralManagerScanOptionAllowDuplicatesKey to true)) + } + + /** Known peripheral identifiers from this process's scans/retrievals (uppercase). */ + fun knownIdentifiers(): List = cond.withLock { peers.keys.toList() } + + // ----- SessionLink / StockLink ---------------------------------------------------------- + + override fun connect(address: String, timeoutMs: Int): Boolean { + val identifier = address.uppercase() + val deadline = platform.elapsedRealtimeMs() + timeoutMs + val ready = waitForPoweredOn(minOf(timeoutMs, READY_TIMEOUT_MS)) + if (ready != null) { + log("connect $identifier: $ready") + return false + } + val peer = findOrDiscover(identifier, deadline) ?: run { + log("connect $identifier: peripheral not found") + return false + } + val requiresAncs = cond.withLock { + if (peer.connected || peer.connectPending) { + log("connect $identifier: already connecting or connected") + return peer.connected + } + peer.characteristics.clear() + peer.failure = null + peer.connectPending = true + peer.reportedConnected = false + peer.requiresAncs || (pendingAncs[identifier] ?: false) + } + dispatch_sync(queue) { + val manager = central ?: return@dispatch_sync + manager.connectPeripheral( + peer.peripheral, + if (requiresAncs) mapOf(CBConnectPeripheralOptionRequiresANCS to true) else null, + ) + } + val connected = cond.withLock { + while (peer.connectPending) { + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) break + cond.awaitMs(left) + } + val ok = peer.connected + if (!ok) peer.connectPending = false + ok + } + if (!connected) { + log("connect $identifier failed: " + (cond.withLock { peer.failure } ?: "timeout")) + dispatch_sync(queue) { central?.cancelPeripheralConnection(peer.peripheral) } + } + return connected + } + + private fun findOrDiscover(identifier: String, deadline: Long): Peer? { + cond.withLock { peers[identifier] }?.let { return it } + var retrieved: CBPeripheral? = null + dispatch_sync(queue) { + val manager = central ?: return@dispatch_sync + val uuid = NSUUID(uUIDString = identifier) ?: return@dispatch_sync + retrieved = manager.retrievePeripheralsWithIdentifiers(listOf(uuid)).firstOrNull() as? CBPeripheral + } + retrieved?.let { return remember(it) } + // Not known to the system: scan until the identifier shows up. + val wasScanning = scanRequested + startScan() + try { + cond.lock() + try { + while (true) { + peers[identifier]?.let { return it } + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) return null + cond.awaitMs(left) + } + } finally { + cond.unlock() + } + } finally { + if (!wasScanning) stopScan() + } + } + + override fun requestHighPriority(address: String) {} + + override fun requestMtu(address: String, mtu: Int, timeoutMs: Int): Boolean = true + + override fun prepareLink(address: String, desiredMtu: Int, timeoutMs: Int) {} + + override fun negotiatedMtu(address: String): Int { + val peer = cond.withLock { peers[address.uppercase()] } ?: return DEFAULT_ATT_MTU + // CoreBluetooth reports the ATT payload; Android reports the ATT MTU (payload + 3). + val payload = peer.peripheral.maximumWriteValueLengthForType(CBCharacteristicWriteWithoutResponse).toInt() + return (payload + 3).coerceIn(DEFAULT_ATT_MTU, MAX_ATT_MTU) + } + + override fun discoverServices(address: String, timeoutMs: Int): Boolean { + val peer = connectedPeer(address) ?: return false + val deadline = platform.elapsedRealtimeMs() + timeoutMs + cond.withLock { + peer.discoverPending = true + peer.pendingServices = 0 + peer.characteristics.clear() + } + dispatch_sync(queue) { peer.peripheral.discoverServices(null) } + return cond.withLock { + while (peer.discoverPending && peer.connected) { + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) break + cond.awaitMs(left) + } + !peer.discoverPending && peer.connected && peer.characteristics.isNotEmpty() + } + } + + override fun enableNotifications(address: String, characteristicUuid: String, timeoutMs: Int): Boolean = + enableNotifications(address, characteristicUuid, true, timeoutMs) + + override fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean { + val peer = connectedPeer(address) ?: return false + val key = characteristicUuid.lowercase() + val characteristic = cond.withLock { peer.characteristics[key] } ?: run { + log("notifications $key: characteristic unavailable") + return false + } + val notifiable = (characteristic.properties and (CBCharacteristicPropertyNotify or CBCharacteristicPropertyIndicate)) != 0uL + if (!notifiable) { + log("notifications $key: not notifiable") + return false + } + if (characteristic.isNotifying == enable) return true + val deadline = platform.elapsedRealtimeMs() + timeoutMs + cond.withLock { + peer.notifyPending = key + peer.notifyResult = null + } + dispatch_sync(queue) { peer.peripheral.setNotifyValue(enable, characteristic) } + return cond.withLock { + while (peer.notifyPending == key && peer.connected) { + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) break + cond.awaitMs(left) + } + val result = peer.notifyResult == true && peer.connected + if (peer.notifyPending == key) peer.notifyPending = null + result || (!enable && peer.connected) + } + } + + override fun writeFrames( + address: String, + characteristicUuid: String, + frames: List, + mode: GattWriteMode, + timeoutMs: Int, + ): Boolean { + val peer = connectedPeer(address) ?: return false + val key = characteristicUuid.lowercase() + val characteristic = cond.withLock { peer.characteristics[key] } ?: run { + log("write $key: characteristic unavailable") + return false + } + val writable = (characteristic.properties and (CBCharacteristicPropertyWrite or CBCharacteristicPropertyWriteWithoutResponse)) != 0uL + if (!writable) return false + val withoutResponseSupported = (characteristic.properties and CBCharacteristicPropertyWriteWithoutResponse) != 0uL + val type: CBCharacteristicWriteType = + if (mode == GattWriteMode.WITHOUT_RESPONSE && withoutResponseSupported) CBCharacteristicWriteWithoutResponse + else CBCharacteristicWriteWithResponse + val limit = peer.peripheral.maximumWriteValueLengthForType(type).toInt() + val deadline = platform.elapsedRealtimeMs() + timeoutMs + for (frame in frames) { + if (frame.size > limit) { + log("write $key: ${frame.size} bytes exceeds the ${limit}-byte limit") + return false + } + val data = frame.data() + if (type == CBCharacteristicWriteWithResponse) { + cond.withLock { + peer.writePending = true + peer.writeError = null + } + dispatch_sync(queue) { peer.peripheral.writeValue(data, characteristic, type) } + val ok = cond.withLock { + while (peer.writePending && peer.connected) { + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) break + cond.awaitMs(left) + } + val done = !peer.writePending && peer.writeError == null && peer.connected + peer.writePending = false + done + } + if (!ok) { + log("write $key failed: " + (cond.withLock { peer.writeError } ?: "timeout")) + return false + } + IosBleTraffic.recordWrite(frame.size) + } else { + while (true) { + var sent = false + var connected = true + dispatch_sync(queue) { + if (peer.peripheral.state != CBPeripheralStateConnected) { + connected = false + } else if (peer.peripheral.canSendWriteWithoutResponse) { + peer.peripheral.writeValue(data, characteristic, type) + sent = true + } + } + if (!connected) return false + if (sent) { + IosBleTraffic.recordWrite(frame.size) + break + } + // Pace on the controller's buffer: wait for peripheralIsReadyToSendWriteWithoutResponse. + val ready = cond.withLock { + peer.readyForWriteWithoutResponse = false + while (!peer.readyForWriteWithoutResponse && peer.connected) { + val left = deadline - platform.elapsedRealtimeMs() + if (left <= 0) break + cond.awaitMs(minOf(left, 50)) + // canSendWriteWithoutResponse may flip without a callback; re-check. + if (peer.peripheral.canSendWriteWithoutResponse) break + } + peer.connected && (peer.readyForWriteWithoutResponse || peer.peripheral.canSendWriteWithoutResponse) + } + if (!ready) { + if (platform.elapsedRealtimeMs() >= deadline) { + log("write $key: timed out waiting for the write buffer") + return false + } + if (!cond.withLock { peer.connected }) return false + } + } + } + } + return true + } + + override fun isConnected(address: String): Boolean = + cond.withLock { peers[address.uppercase()]?.connected ?: false } + + override fun bondState(address: String): BondState = BondState.UNKNOWN + + override fun isBonded(address: String): Boolean = true + + override fun prepareBenchmarkLink(address: String, mode: Int) {} + + override fun recordDisplayFrameSent() { + IosBleTraffic.recordDisplayFrame() + } + + override fun disconnect(address: String) { + val peer = cond.withLock { peers[address.uppercase()] } ?: return + dispatch_sync(queue) { + if (peer.peripheral.state != CBPeripheralStateDisconnected) central?.cancelPeripheralConnection(peer.peripheral) + } + failPeer(peer, "Disconnected", notifyListeners = false) + } + + override fun close() { + closed = true + scanRequested = false + val all = cond.withLock { peers.values.toList() } + dispatch_sync(queue) { + central?.stopScan() + for (peer in all) if (peer.peripheral.state != CBPeripheralStateDisconnected) central?.cancelPeripheralConnection(peer.peripheral) + } + for (peer in all) failPeer(peer, "Closed", notifyListeners = false) + } + + // ----- internals ------------------------------------------------------------------ + + private fun connectedPeer(address: String): Peer? { + val peer = cond.withLock { peers[address.uppercase()]?.takeIf { it.connected } } + if (peer == null) log("$address is not connected") + return peer + } + + private fun remember(peripheral: CBPeripheral): Peer { + val identifier = peripheral.identifier.UUIDString.uppercase() + return cond.withLock { + peers.getOrPut(identifier) { + peripheral.delegate = delegate + Peer(peripheral).also { it.requiresAncs = pendingAncs[identifier] ?: false } + } + } + } + + /** Marks the peer disconnected, wakes every waiter and (optionally) tells the listeners. */ + private fun failPeer(peer: Peer, reason: String, notifyListeners: Boolean) { + val wasReported = cond.withLock { + val reported = peer.reportedConnected + peer.failure = reason + peer.connectPending = false + peer.connected = false + peer.reportedConnected = false + peer.discoverPending = false + peer.notifyPending = null + peer.writePending = false + peer.readyForWriteWithoutResponse = false + peer.characteristics.clear() + cond.signalAll() + reported + } + if (notifyListeners && wasReported) emitConnectionState(peer.identifier, false) + } + + private fun emitConnectionState(identifier: String, connected: Boolean) { + sessionListener?.onConnectionStateChange(identifier, connected) + stockListener?.onConnectionStateChange(identifier, connected) + } + + private fun log(message: String) = PlatformLog.i(TAG, message) + + // ----- delegate callbacks (BLE queue) ---------------------------------------------------- + + private fun onStateUpdated(manager: CBCentralManager) { + val state = manager.state + bluetoothState = state + cond.withLock { cond.signalAll() } + val listener = scanListener + if (listener != null) { + val authorization = authorization() + dispatch_async(dispatch_get_main_queue()) { listener.onBluetoothState(state.toInt(), authorization) } + } + if (state != CBManagerStatePoweredOn) { + val all = cond.withLock { peers.values.toList() } + for (peer in all) failPeer(peer, "Bluetooth is unavailable", notifyListeners = true) + } else if (scanRequested) { + beginScan(manager) + } + } + + private fun onDiscovered(peripheral: CBPeripheral, advertisementData: Map, rssi: NSNumber) { + val peer = remember(peripheral) + cond.withLock { cond.signalAll() } // findOrDiscover may be waiting for this identifier + val listener = scanListener ?: return + val manufacturer = (advertisementData[CBAdvertisementDataManufacturerDataKey] as? NSData)?.byteArray() + val advertisedName = advertisementData[CBAdvertisementDataLocalNameKey] as? String + val connectable = (advertisementData[CBAdvertisementDataIsConnectable] as? NSNumber)?.boolValue ?: true + val merged = cond.withLock { + val previous = advertisements.remove(peer.identifier) + val name = advertisedName ?: peripheral.name ?: previous?.name ?: "" + val hex = if (manufacturer != null) BinaryEncoding.bytesToHex(manufacturer) else previous?.manufacturerDataHex ?: "" + if (advertisements.size >= ADVERTISEMENT_CACHE) advertisements.remove(advertisements.keys.first()) + Advertisement(name, hex).also { advertisements[peer.identifier] = it } + } + val identifier = peer.identifier + val level = rssi.intValue + dispatch_async(dispatch_get_main_queue()) { + listener.onAdvertisement(identifier, merged.name, merged.manufacturerDataHex, level, connectable) + } + } + + private fun onConnected(peripheral: CBPeripheral) { + val peer = remember(peripheral) + cond.withLock { + peer.connected = true + peer.connectPending = false + peer.failure = null + peer.reportedConnected = true + cond.signalAll() + } + emitConnectionState(peer.identifier, true) + } + + private fun onDisconnected(peripheral: CBPeripheral, error: NSError?) { + val peer = remember(peripheral) + failPeer(peer, error?.localizedDescription ?: "Disconnected", notifyListeners = true) + } + + private fun onServicesDiscovered(peripheral: CBPeripheral, error: NSError?) { + val peer = remember(peripheral) + val services = peripheral.services?.mapNotNull { it as? CBService } ?: emptyList() + if (error != null || services.isEmpty()) { + cond.withLock { + peer.discoverPending = false + cond.signalAll() + } + return + } + cond.withLock { peer.pendingServices = services.size } + for (service in services) peripheral.discoverCharacteristics(null, service) + } + + private fun onCharacteristicsDiscovered(peripheral: CBPeripheral, service: CBService, error: NSError?) { + val peer = remember(peripheral) + cond.withLock { + if (error == null) { + for (item in service.characteristics ?: emptyList()) { + val characteristic = item as? CBCharacteristic ?: continue + peer.characteristics[characteristic.UUID.UUIDString.lowercase()] = characteristic + } + } + peer.pendingServices-- + if (peer.pendingServices <= 0) peer.discoverPending = false + cond.signalAll() + } + } + + private fun onNotificationState(peripheral: CBPeripheral, characteristic: CBCharacteristic, error: NSError?) { + val peer = remember(peripheral) + val key = characteristic.UUID.UUIDString.lowercase() + cond.withLock { + if (peer.notifyPending == key) { + peer.notifyResult = error == null && characteristic.isNotifying + peer.notifyPending = null + } + cond.signalAll() + } + } + + private fun onValue(peripheral: CBPeripheral, characteristic: CBCharacteristic, error: NSError?) { + if (error != null) { + log("notification error: " + error.localizedDescription) + return + } + val data = characteristic.value?.byteArray() ?: return + val identifier = peripheral.identifier.UUIDString.uppercase() + val uuid = characteristic.UUID.UUIDString.lowercase() + IosBleTraffic.recordRead(data.size) + sessionListener?.onNotification(identifier, uuid, data) + stockListener?.onNotification(identifier, uuid, data) + } + + private fun onWrote(peripheral: CBPeripheral, error: NSError?) { + val peer = remember(peripheral) + cond.withLock { + peer.writeError = error?.localizedDescription + peer.writePending = false + cond.signalAll() + } + } + + private fun onReadyForWriteWithoutResponse(peripheral: CBPeripheral) { + val peer = remember(peripheral) + cond.withLock { + peer.readyForWriteWithoutResponse = true + cond.signalAll() + } + } + + private fun onAncsAuthorization(peripheral: CBPeripheral) { + val identifier = peripheral.identifier.UUIDString.uppercase() + ancsListener?.onAncsAuthorization(identifier, peripheral.ancsAuthorized) + } + + private class Delegate(private val owner: IosBleCentral) : NSObject(), CBCentralManagerDelegateProtocol, CBPeripheralDelegateProtocol { + override fun centralManagerDidUpdateState(central: CBCentralManager) = owner.onStateUpdated(central) + + override fun centralManager(central: CBCentralManager, didDiscoverPeripheral: CBPeripheral, advertisementData: Map, RSSI: NSNumber) = + owner.onDiscovered(didDiscoverPeripheral, advertisementData, RSSI) + + @ObjCSignatureOverride + override fun centralManager(central: CBCentralManager, didConnectPeripheral: CBPeripheral) = owner.onConnected(didConnectPeripheral) + + @ObjCSignatureOverride + override fun centralManager(central: CBCentralManager, didFailToConnectPeripheral: CBPeripheral, error: NSError?) = + owner.onDisconnected(didFailToConnectPeripheral, error) + + @ObjCSignatureOverride + override fun centralManager(central: CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: NSError?) = + owner.onDisconnected(didDisconnectPeripheral, error) + + @ObjCSignatureOverride + override fun centralManager(central: CBCentralManager, didUpdateANCSAuthorizationForPeripheral: CBPeripheral) = + owner.onAncsAuthorization(didUpdateANCSAuthorizationForPeripheral) + + override fun peripheral(peripheral: CBPeripheral, didDiscoverServices: NSError?) = owner.onServicesDiscovered(peripheral, didDiscoverServices) + + @ObjCSignatureOverride + override fun peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService: CBService, error: NSError?) = + owner.onCharacteristicsDiscovered(peripheral, didDiscoverCharacteristicsForService, error) + + @ObjCSignatureOverride + override fun peripheral(peripheral: CBPeripheral, didUpdateNotificationStateForCharacteristic: CBCharacteristic, error: NSError?) = + owner.onNotificationState(peripheral, didUpdateNotificationStateForCharacteristic, error) + + @ObjCSignatureOverride + override fun peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic: CBCharacteristic, error: NSError?) = + owner.onValue(peripheral, didUpdateValueForCharacteristic, error) + + @ObjCSignatureOverride + override fun peripheral(peripheral: CBPeripheral, didWriteValueForCharacteristic: CBCharacteristic, error: NSError?) = + owner.onWrote(peripheral, error) + + override fun peripheralIsReadyToSendWriteWithoutResponse(peripheral: CBPeripheral) = owner.onReadyForWriteWithoutResponse(peripheral) + } +} + +/** Process-wide BLE traffic counters (the TypeScript ios-ble-traffic counters' successor). */ +object IosBleTraffic { + private val lock = IosProtocolPlatform.createLock() + private var bytesWritten = 0L + private var bytesRead = 0L + private var displayFrames = 0L + + fun recordWrite(bytes: Int) = lock.withLock { bytesWritten += bytes } + + fun recordRead(bytes: Int) = lock.withLock { bytesRead += bytes } + + fun recordDisplayFrame() = lock.withLock { displayFrames++ } + + /** [bytesWritten, bytesRead, displayFrames] and resets the counters. */ + fun sample(): LongArray = lock.withLock { + val out = longArrayOf(bytesWritten, bytesRead, displayFrames) + bytesWritten = 0 + bytesRead = 0 + displayFrames = 0 + out + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt new file mode 100644 index 00000000..37900640 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt @@ -0,0 +1,245 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import platform.Foundation.NSData +import platform.darwin.dispatch_async +import platform.darwin.dispatch_get_main_queue +import platform.darwin.dispatch_queue_create + +/** iPhone-notification relay hooks; both callbacks are delivered on the main queue. */ +interface IosAncsListener { + fun onAncsAuthorization(authorized: Boolean) + + /** A relay frame ('A','N',...) received on the right arm's data characteristic. */ + fun onRelayFrame(data: NSData) +} + +/** + * ObjC-facing facade over the shared [GlassesSessionCore] for the NativeScript app: the iOS + * counterpart of Android's FaceclawBleCommunicator with the same method names. GATT goes + * through [IosBleCentral], side effects through [IosSessionHost]; every listener the + * TypeScript side installs is invoked on the main queue. Binary crossings use NSData. + */ +class IosGlassesSession internal constructor( + link: SessionLink, + private val central: IosBleCentral?, + private val host: SessionHost, + rightAddress: String, + leftAddress: String, + ringAddress: String, + platform: ProtocolPlatform, +) { + /** Production constructor: CoreBluetooth link + main-queue host. Addresses are peripheral identifiers. */ + constructor(rightAddress: String, leftAddress: String, ringAddress: String) : this( + IosBleCentral(), + rightAddress, + leftAddress, + ringAddress, + ) + + private constructor(central: IosBleCentral, rightAddress: String, leftAddress: String, ringAddress: String) : this( + central, + central, + IosSessionHost(), + rightAddress, + leftAddress, + ringAddress, + IosProtocolPlatform, + ) + + companion object { + const val TAG = GlassesSessionCore.TAG + } + + private val frameTimings = IosFrameTimings.shared.core + private val core = GlassesSessionCore(link, host, frameTimings, platform, rightAddress, leftAddress, ringAddress) + private val rawQueue = dispatch_queue_create("com.faceclaw.session.raw", null) + private val rightIdentifier = rightAddress.uppercase() + + init { + central?.setSessionListener(core) + } + + // ----- lifecycle ------------------------------------------------------------------ + + fun setListener(listener: FaceclawBleCommunicatorListener?) = core.setListener(listener) + + fun start(): Boolean = core.start() + + fun disconnect() = core.disconnect() + + fun close() = core.close() + + fun onPhoneLockSignal() = core.onPhoneLockSignal() + + fun isSessionReady(): Boolean = core.isSessionReady() + + // ----- iPhone notification relay (ANCS) ------------------------------------------------- + + /** Ask CoreBluetooth for ANCS on the right arm's next connection (call before start()). */ + fun setRequiresAncs(required: Boolean) { + central?.setRequiresAncs(rightIdentifier, required) + } + + fun isAncsAuthorized(): Boolean = central?.isAncsAuthorized(rightIdentifier) ?: false + + fun setAncsListener(listener: IosAncsListener?) { + if (listener == null) { + core.setRawFrameTap(null) + central?.setAncsAuthorizationListener(null) + return + } + core.setRawFrameTap { bytes -> + val data = bytes.data() + dispatch_async(dispatch_get_main_queue()) { listener.onRelayFrame(data) } + } + central?.setAncsAuthorizationListener { _, authorized -> + dispatch_async(dispatch_get_main_queue()) { listener.onAncsAuthorization(authorized) } + } + } + + /** Queue one relay packet for the right arm; never blocks the caller (writes run on a serial queue). */ + fun writeRawToRight(packet: NSData) { + val bytes = packet.byteArray() + dispatch_async(rawQueue) { + if (!core.writeRawPacket("R", bytes)) PlatformLog.w(TAG, "relay packet dropped (${bytes.size} bytes)") + } + } + + // ----- controls ------------------------------------------------------------------- + + fun setG2ScreenOn(screenOn: Boolean) = core.setG2ScreenOn(screenOn) + + fun setFirmwareDebugFlags(enabled: Boolean) = core.setFirmwareDebugFlags(enabled) + + /** The packet listener is invoked on the main queue (the core delivers on the BLE queue). */ + fun startG2AudioCapture(listener: FaceclawAudioPacketListener?): Boolean = + core.startG2AudioCapture(listener?.let { MainQueueAudioListener(it) }) + + fun stopG2AudioCapture() = core.stopG2AudioCapture() + + fun isAudioCaptureActive(): Boolean = core.isAudioCaptureActive() + + fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean = core.setFaceclawWakeLeaseEnabled(enabled) + + fun awaitEvenHubSessionReady(timeoutMs: Int): Boolean = core.awaitEvenHubSessionReady(timeoutMs) + + fun setImuReportEnabled(enable: Boolean, reportFrq: Int) = core.setImuReportEnabled(enable, reportFrq) + + fun setCompassEnabled(enable: Boolean) = core.setCompassEnabled(enable) + + fun setCompassEnabledForOwner(owner: String?, enable: Boolean) = core.setCompassEnabled(owner, enable) + + fun setBrightness(autoAdjust: Boolean, brightnessLevel: Int) = core.setBrightness(autoAdjust, brightnessLevel) + + fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState() + + fun startBandwidthBenchmark(messageSize: Int, windowSize: Int, durationMs: Int): Boolean = + core.startBandwidthBenchmark(messageSize, windowSize, durationMs) + + fun startBandwidthBenchmarkWithLinkMode(messageSize: Int, windowSize: Int, durationMs: Int, linkMode: Int): Boolean = + core.startBandwidthBenchmarkWithLinkMode(messageSize, windowSize, durationMs, linkMode) + + fun cancelBandwidthBenchmark() = core.cancelBandwidthBenchmark() + + fun getBandwidthBenchmarkStatus(): String = core.getBandwidthBenchmarkStatus() + + fun addImuListener(listener: FaceclawImuListener?) = core.addImuListener(listener) + + fun removeImuListener(listener: FaceclawImuListener?) = core.removeImuListener(listener) + + fun addAmbientLightListener(listener: FaceclawAmbientLightListener?) = core.addAmbientLightListener(listener) + + fun removeAmbientLightListener(listener: FaceclawAmbientLightListener?) = core.removeAmbientLightListener(listener) + + fun queryAmbientLight() = core.queryAmbientLight() + + fun setAmbientLightPolling(enable: Boolean, intervalMs: Int, minDelta: Int, heartbeatMs: Int, bindToLease: Boolean) = + core.setAmbientLightPolling(enable, intervalMs, minDelta, heartbeatMs, bindToLease) + + fun addMicStatusListener(listener: FaceclawMicStatusListener?) = core.addMicStatusListener(listener) + + fun removeMicStatusListener(listener: FaceclawMicStatusListener?) = core.removeMicStatusListener(listener) + + fun sendFaceclawMicControl(record: NSData?, label: String, rightTemple: Boolean, leftTemple: Boolean) = + core.sendFaceclawMicControl(record?.byteArray(), label, rightTemple, leftTemple) + + fun startG2AudioForwarding(listener: FaceclawAudioPacketListener?): Boolean = + core.startG2AudioForwarding(listener?.let { MainQueueAudioListener(it) }) + + fun stopG2AudioForwarding() = core.stopG2AudioForwarding() + + /** Compass events are delivered on the queue of the thread that adds the listener (main for TypeScript). */ + fun addCompassListener(listener: FaceclawCompassListener?) = core.addCompassListener(listener) + + fun removeCompassListener(listener: FaceclawCompassListener?) = core.removeCompassListener(listener) + + fun sendShutdown(exitMode: Int): Boolean = core.sendShutdown(exitMode) + + fun sendCfwCleanup(): Boolean = core.sendCfwCleanup() + + fun suspendEvenHubSession(): Boolean = core.suspendEvenHubSession() + + fun resumeEvenHubSession(): Boolean = core.resumeEvenHubSession() + + fun playBuzzerSequence(payload: NSData?) = core.playBuzzerSequence(payload?.byteArray()) + + // ----- surfaces ------------------------------------------------------------------- + + /** Set the compositor's output frame size. Call before configuring surfaces. */ + fun configureCompositorScreen(width: Int, height: Int) = core.configureCompositorScreen(width, height) + + fun setSurfaceVisible(id: String, visible: Boolean) = core.setSurfaceVisible(id, visible) + + fun setScreenBlanked(blanked: Boolean) = core.setScreenBlanked(blanked) + + fun configureSurface(id: String, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) = + core.configureSurface(id, x, y, width, height, zOrder, transparency) + + fun removeSurface(id: String) = core.removeSurface(id) + + fun submitShellScene(bytes: NSData, paintMs: Int, frameId: Int) = core.submitShellScene(IosByteReader(bytes), paintMs, frameId) + + fun setUnderlayDim(belowZOrder: Int, factor256: Int) = core.setUnderlayDim(belowZOrder, factor256) + + fun submitSurfaceFrame( + pixels8bpp: NSData, + surfaceId: String, + rectX: Int, + rectY: Int, + rectWidth: Int, + rectHeight: Int, + contentFingerprint: String?, + paintMs: Int, + frameId: Int, + glyphs: NSData?, + ) = core.submitSurfaceFrame( + IosByteReader(pixels8bpp), surfaceId, rectX, rectY, rectWidth, rectHeight, contentFingerprint, paintMs, frameId, + glyphs?.let { IosByteReader(it) }, + ) + + /** The current composited screen (gray, 8bpp) or null before any surface was configured. */ + fun previewComposite(): IosTextureFrame? = core.previewComposite()?.let { IosTextureFrame(it) } + + fun compositeWidth(): Int = core.previewComposite()?.width ?: 0 + + fun compositeHeight(): Int = core.previewComposite()?.height ?: 0 + + /** The current composite as a 4-bit grayscale PNG, or null. */ + fun screenshotPng(): NSData? { + val composite = core.previewComposite() ?: return null + return SharedScreenshots.encode4BitGrayPng(composite.gray, composite.width, composite.height).data() + } + + /** Frame-timings export text (see FrameTimingsCore), for the phone-side debug page. */ + fun frameTimingsExport(): String = frameTimings.buildExport() + + internal fun coreForTests(): GlassesSessionCore = core + + private class MainQueueAudioListener(private val delegate: FaceclawAudioPacketListener) : FaceclawAudioPacketListener { + override fun onAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { + dispatch_async(dispatch_get_main_queue()) { delegate.onAudioPacket(data, arm, arrivalMs) } + } + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosSessionHost.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosSessionHost.kt new file mode 100644 index 00000000..1e03e786 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosSessionHost.kt @@ -0,0 +1,92 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import platform.Foundation.NSBundle +import platform.Foundation.NSNotificationCenter +import platform.Foundation.NSOperationQueue +import platform.Foundation.NSThread +import platform.UIKit.UIApplication +import platform.UIKit.UIApplicationProtectedDataDidBecomeAvailable +import platform.UIKit.UIApplicationProtectedDataWillBecomeUnavailable +import platform.darwin.dispatch_async +import platform.darwin.dispatch_get_main_queue +import platform.darwin.dispatch_queue_create + +/** + * iOS [SessionHost]: listener callbacks go to the main queue (NativeScript's JavaScript + * thread), the session worker is an NSThread, the "glasses screen on" wake lock maps to the + * idle timer, and "phone locked" tracks protected-data availability (data protection kicks + * in shortly after the passcode lock engages), observed on the main queue so the worker + * never has to block on the main thread. There is no Even-app conflict on iOS. + */ +class IosSessionHost(private val platform: ProtocolPlatform = IosProtocolPlatform, private val threadName: String = "FaceclawBleCommunicator") : SessionHost { + private val mainDispatcher = SessionDispatcher { action -> dispatch_async(dispatch_get_main_queue()) { action() } } + + @Volatile private var phoneLocked = false + + @Volatile private var workerDone: Latch? = null + + /** UIApplication exists only inside a UIKit app; the Kotlin test executable has no bundle type. */ + private val uiApplicationAvailable: Boolean = + NSBundle.mainBundle.infoDictionary?.get("CFBundlePackageType") == "APPL" + + init { + if (uiApplicationAvailable) { + val center = NSNotificationCenter.defaultCenter + center.addObserverForName(UIApplicationProtectedDataWillBecomeUnavailable, null, NSOperationQueue.mainQueue) { phoneLocked = true } + center.addObserverForName(UIApplicationProtectedDataDidBecomeAvailable, null, NSOperationQueue.mainQueue) { phoneLocked = false } + dispatch_async(dispatch_get_main_queue()) { + phoneLocked = !UIApplication.sharedApplication.protectedDataAvailable + } + } + } + + override fun postToMain(action: () -> Unit) { + dispatch_async(dispatch_get_main_queue()) { action() } + } + + override fun currentThreadDispatcher(): SessionDispatcher { + if (NSThread.isMainThread) return mainDispatcher + val queue = dispatch_queue_create("com.faceclaw.session.subscriber", null) + return SessionDispatcher { action -> dispatch_async(queue) { action() } } + } + + override fun isPhoneLocked(): Boolean = phoneLocked + + override fun setScreenWakeLock(on: Boolean) { + if (!uiApplicationAvailable) return + dispatch_async(dispatch_get_main_queue()) { UIApplication.sharedApplication.idleTimerDisabled = on } + } + + override fun isEvenAppActive(): Boolean = false + + override fun startWorker(body: () -> Unit) { + val latch = Latch(1, platform) + workerDone = latch + val thread = NSThread { + try { + body() + } finally { + latch.countDown() + } + } + thread.name = threadName + thread.start() + } + + override fun joinWorker(timeoutMs: Long) { + // Kotlin/Native threads cannot be interrupted; the core wakes its own sleeper before joining. + workerDone?.await(timeoutMs) + workerDone = null + } + + override fun log(level: SessionLogLevel, tag: String, message: String, error: Throwable?) { + when (level) { + SessionLogLevel.DEBUG, SessionLogLevel.INFO -> PlatformLog.i(tag, message) + SessionLogLevel.WARN -> PlatformLog.w(tag, if (error != null) "$message (${error.message})" else message) + SessionLogLevel.ERROR -> PlatformLog.e(tag, message, error) + } + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosStockFlows.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosStockFlows.kt new file mode 100644 index 00000000..a8146eba --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosStockFlows.kt @@ -0,0 +1,173 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import platform.Foundation.NSThread +import platform.darwin.dispatch_async +import platform.darwin.dispatch_get_main_queue + +private fun main(action: () -> Unit) { + dispatch_async(dispatch_get_main_queue()) { action() } +} + +private fun runOnThread(name: String, body: () -> Unit) { + val thread = NSThread { body() } + thread.name = name + thread.start() +} + +/** + * iOS host for the shared [DeviceInfoProbeFlow]: owns a CoreBluetooth link, runs the flow on + * its own NSThread and delivers listener callbacks on the main queue. Same surface as + * Android's FaceclawDeviceInfoProbe. Addresses are peripheral identifiers. + */ +class IosDeviceInfoProbe(rightAddress: String, leftAddress: String) { + private val link = IosBleCentral() + private val lock = IosProtocolPlatform.createLock() + private var started = false + private var listener: FaceclawDeviceInfoProbeListener? = null + + private val flow = DeviceInfoProbeFlow( + link, + rightAddress, + leftAddress, + object : FaceclawDeviceInfoProbeListener { + override fun onLog(line: String?) { + PlatformLog.i(DeviceInfoProbeFlow.TAG, line ?: "") + post { it.onLog(line) } + } + + override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") } + + override fun onResult(leftVersion: String?, rightVersion: String?, extension: String?) = + post { it.onResult(leftVersion, rightVersion, extension) } + + override fun onError(message: String?) = post { it.onError(message ?: "") } + }, + ) + + fun setListener(listener: FaceclawDeviceInfoProbeListener?) { + lock.withLock { this.listener = listener } + } + + fun start() { + lock.withLock { + if (started) return + started = true + } + runOnThread("faceclaw-device-info") { flow.run() } + } + + fun cancel() = flow.cancel() + + fun close() { + cancel() + runCatching { link.close() } + } + + private fun post(action: (FaceclawDeviceInfoProbeListener) -> Unit) = main { + lock.withLock { listener }?.let(action) + } +} + +/** iOS host for the shared [FlashPromptFlow] (the on-glasses Yes/No confirmation before flashing). */ +class IosFlashPrompt(rightAddress: String, leftAddress: String, warningText: String, skipPrompt: Boolean) { + private val link = IosBleCentral() + private val lock = IosProtocolPlatform.createLock() + private var started = false + private var listener: FaceclawFlashPromptListener? = null + + private val flow = FlashPromptFlow( + link, + rightAddress, + leftAddress, + warningText, + skipPrompt, + object : FaceclawFlashPromptListener { + override fun onLog(line: String?) { + PlatformLog.i(FlashPromptFlow.TAG, line ?: "") + post { it.onLog(line) } + } + + override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") } + + override fun onBattery(rightPercent: Int, leftPercent: Int) = post { it.onBattery(rightPercent, leftPercent) } + + override fun onResult(approved: Boolean) = post { it.onResult(approved) } + }, + ) + + fun setListener(listener: FaceclawFlashPromptListener?) { + lock.withLock { this.listener = listener } + } + + fun start() { + lock.withLock { + if (started) return + started = true + } + runOnThread("faceclaw-flash-prompt") { flow.run() } + } + + fun cancel() = flow.cancel() + + fun close() { + cancel() + runCatching { link.close() } + } + + private fun post(action: (FaceclawFlashPromptListener) -> Unit) = main { + lock.withLock { listener }?.let(action) + } +} + +/** iOS host for the shared [OtaFlashFlow] (custom-firmware OTA over the stock protocol). */ +class IosFirmwareFlasher(rightAddress: String, leftAddress: String, firmwarePath: String) { + private val link = IosBleCentral() + private val lock = IosProtocolPlatform.createLock() + private var started = false + private var listener: FaceclawFirmwareFlasherListener? = null + + private val flow = OtaFlashFlow( + link, + rightAddress, + leftAddress, + firmwarePath, + object : FaceclawFirmwareFlasherListener { + override fun onLog(line: String?) { + PlatformLog.i(OtaFlashFlow.TAG, line ?: "") + post { it.onLog(line) } + } + + override fun onProgress(lens: String?, componentIndex: Int, componentCount: Int, blockIndex: Int, blockCount: Int, bytesSent: Long, bytesTotal: Long) = + post { it.onProgress(lens, componentIndex, componentCount, blockIndex, blockCount, bytesSent, bytesTotal) } + + override fun onState(state: String?, detail: String?) = post { it.onState(state, detail ?: "") } + + override fun onComplete(success: Boolean, detail: String?) = post { it.onComplete(success, detail ?: "") } + }, + ) + + fun setListener(listener: FaceclawFirmwareFlasherListener?) { + lock.withLock { this.listener = listener } + } + + fun start() { + lock.withLock { + if (started) return + started = true + } + runOnThread("faceclaw-flasher") { flow.run() } + } + + fun cancel() = flow.cancel() + + fun close() { + cancel() + runCatching { link.close() } + } + + private fun post(action: (FaceclawFirmwareFlasherListener) -> Unit) = main { + lock.withLock { listener }?.let(action) + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosModelDownloader.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosModelDownloader.kt new file mode 100644 index 00000000..20919c7c --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosModelDownloader.kt @@ -0,0 +1,257 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import kotlin.concurrent.Volatile + +import kotlinx.cinterop.addressOf +import kotlinx.cinterop.convert +import kotlinx.cinterop.usePinned +import platform.Foundation.NSData +import platform.Foundation.NSError +import platform.Foundation.NSFileManager +import platform.Foundation.NSHTTPURLResponse +import platform.Foundation.NSURLResponse +import platform.Foundation.NSURLSession +import platform.Foundation.NSURLSessionConfiguration +import platform.Foundation.NSURLSessionDataDelegateProtocol +import platform.Foundation.NSURLSessionDataTask +import platform.Foundation.NSURLSessionResponseAllow +import platform.Foundation.NSURLSessionResponseDisposition +import platform.Foundation.NSURLSessionTask +import platform.darwin.NSObject +import platform.posix.fclose +import platform.posix.fopen +import platform.posix.fread +import platform.posix.fwrite + +/** + * iOS twin of the Android FaceclawModelDownloader: NSURLSession transport and POSIX + * storage under the shared [ResumableDownload], run on its own thread with listener + * callbacks on the main queue. Same constructor/start/cancel shape as Android. + */ +class IosModelDownloader internal constructor( + url: String, + destPath: String, + expectedSha256: String?, + expectedTotalBytes: Long, + listener: FaceclawModelDownloaderListener, + dispatch: (() -> Unit) -> Unit, +) { + constructor(url: String, destPath: String, expectedSha256: String?, expectedTotalBytes: Long, listener: FaceclawModelDownloaderListener) : + this(url, destPath, expectedSha256, expectedTotalBytes, listener, ::dispatchToMain) + + private val transport = IosDownloadTransport() + private val download: ResumableDownload + + init { + val posted = object : FaceclawModelDownloaderListener { + override fun onProgress(bytesDownloaded: Long, totalBytes: Long) = dispatch { listener.onProgress(bytesDownloaded, totalBytes) } + + override fun onDone(path: String?) = dispatch { listener.onDone(path) } + + override fun onError(message: String?) = dispatch { listener.onError(message) } + } + download = ResumableDownload(url, destPath, expectedSha256, expectedTotalBytes, transport, IosDownloadStorage, posted) + } + + fun start() = startThread("FaceclawModelDl", true) { download.run() } + + /** Stops the download but keeps the .part file so a later start() resumes. */ + fun cancel() { + download.cancel() + transport.cancel() + } +} + +/** + * Blocking-read view of an NSURLSession data task: the delegate queues body chunks and the + * reader drains them, suspending the task while too much is buffered. + */ +internal class IosDownloadTransport : DownloadTransport { + @Volatile + private var current: Session? = null + + fun cancel() { + current?.close() + } + + override fun open(url: String, rangeFrom: Long): DownloadResponse { + val target = parseUrl(url) ?: error("Invalid download URL") + val headers = if (rangeFrom > 0) listOf("Range" to "bytes=$rangeFrom-") else emptyList() + val request = buildRequest(target, "GET", null, headers) + val configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration + configuration.timeoutIntervalForRequest = 60.0 + configuration.timeoutIntervalForResource = 7 * 24 * 3600.0 + val session = Session() + current = session + session.start(configuration, request) + if (!session.responded.await(30_000)) { + session.close() + error("download timed out waiting for the server") + } + session.failure?.let { session.close(); error(it) } + return session + } + + /** Body reader; NSURLSession callbacks arrive through [Delegate] on the session's queue. */ + private class Session : DownloadResponse { + private val platform = IosProtocolPlatform + val responded = Latch(1, platform) + private val chunks = BlockingQueue(platform) + private val lock = platform.createLock() + private var queuedBytes = 0L + private var suspended = false + private var pending: ByteArray? = null + private var pendingOffset = 0 + private var ended = false + + @Volatile + var failure: String? = null + private var session: NSURLSession? = null + private var task: NSURLSessionDataTask? = null + + override var code: Int = 0 + private set + + override var contentLength: Long = -1 + private set + + fun start(configuration: NSURLSessionConfiguration, request: platform.Foundation.NSURLRequest) { + val created = NSURLSession.sessionWithConfiguration(configuration, Delegate(this), delegateQueue = null) + session = created + task = created.dataTaskWithRequest(request).also { it.resume() } + } + + fun onResponse(response: NSURLResponse) { + code = (response as? NSHTTPURLResponse)?.statusCode?.toInt() ?: 0 + contentLength = response.expectedContentLength + responded.countDown() + } + + fun onData(data: NSData, dataTask: NSURLSessionDataTask) { + val bytes = data.byteArray() + if (bytes.isEmpty()) return + chunks.put(bytes) + lock.withLock { + queuedBytes += bytes.size + if (queuedBytes > HIGH_WATER && !suspended) { + suspended = true + dataTask.suspend() + } + } + } + + fun onFinished(error: NSError?) { + if (error != null) failure = error.localizedDescription + responded.countDown() + chunks.put(END) + } + + override fun read(buffer: ByteArray): Int { + var source = pending + if (source == null) { + if (ended) return -1 + val next = chunks.poll(60_000) ?: error("download stalled") + if (next === END) { + ended = true + failure?.let { error(it) } + return -1 + } + source = next + pendingOffset = 0 + } + val count = minOf(buffer.size, source.size - pendingOffset) + source.copyInto(buffer, 0, pendingOffset, pendingOffset + count) + pendingOffset += count + if (pendingOffset >= source.size) { + pending = null + lock.withLock { + queuedBytes -= source.size + if (suspended && queuedBytes < LOW_WATER) { + suspended = false + task?.resume() + } + } + } else pending = source + return count + } + + override fun close() { + session?.invalidateAndCancel() + session = null + chunks.put(END) + } + } + + private class Delegate(private val owner: Session) : NSObject(), NSURLSessionDataDelegateProtocol { + override fun URLSession( + session: NSURLSession, + dataTask: NSURLSessionDataTask, + didReceiveResponse: NSURLResponse, + completionHandler: (NSURLSessionResponseDisposition) -> Unit, + ) { + owner.onResponse(didReceiveResponse) + completionHandler(NSURLSessionResponseAllow) + } + + override fun URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData: NSData) = + owner.onData(didReceiveData, dataTask) + + override fun URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError: NSError?) { + owner.onFinished(didCompleteWithError) + session.finishTasksAndInvalidate() + } + } +} + +private val END = ByteArray(0) +private const val HIGH_WATER = 4L * 1024 * 1024 +private const val LOW_WATER = 1L * 1024 * 1024 + +/** POSIX file storage for downloads; multi-GB files stream through fixed buffers. */ +internal object IosDownloadStorage : DownloadStorage { + override fun length(path: String): Long = fileLength(path) + + override fun prepareParent(path: String) { + val parent = path.substringBeforeLast('/', "") + if (parent.isNotEmpty()) NSFileManager.defaultManager.createDirectoryAtPath(parent, true, null, null) + } + + override fun openWrite(path: String, append: Boolean): FileSink { + val file = fopen(path, if (append) "ab" else "wb") ?: error("Cannot write $path") + return object : FileSink { + override fun write(bytes: ByteArray, offset: Int, length: Int) { + if (length <= 0) return + bytes.usePinned { + check(fwrite(it.addressOf(offset), 1u, length.convert(), file) == length.convert()) { "Short write to $path" } + } + } + + override fun close() { + fclose(file) + } + } + } + + override fun readAll(path: String, consumer: (ByteArray, Int) -> Boolean): Long { + val file = fopen(path, "rb") ?: return 0 + var consumed = 0L + try { + val buffer = ByteArray(1 shl 16) + while (true) { + val read = buffer.usePinned { fread(it.addressOf(0), 1u, buffer.size.convert(), file) }.toInt() + if (read <= 0) break + if (!consumer(buffer, read)) break + consumed += read + } + } finally { + fclose(file) + } + return consumed + } + + override fun rename(from: String, to: String): Boolean = renameFile(from, to) + + override fun delete(path: String): Boolean = deleteFile(path) +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosPosixSockets.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosPosixSockets.kt new file mode 100644 index 00000000..0091d193 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosPosixSockets.kt @@ -0,0 +1,265 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import kotlin.concurrent.Volatile + +import kotlinx.cinterop.ByteVar +import kotlinx.cinterop.CPointer +import kotlinx.cinterop.IntVar +import kotlinx.cinterop.addressOf +import kotlinx.cinterop.alloc +import kotlinx.cinterop.allocArray +import kotlinx.cinterop.allocPointerTo +import kotlinx.cinterop.CFunction +import kotlinx.cinterop.COpaquePointer +import kotlinx.cinterop.COpaquePointerVar +import kotlinx.cinterop.UIntVar +import kotlinx.cinterop.invoke +import kotlinx.cinterop.plus +import kotlinx.cinterop.convert +import kotlinx.cinterop.memScoped +import kotlinx.cinterop.pointed +import kotlinx.cinterop.ptr +import kotlinx.cinterop.reinterpret +import kotlinx.cinterop.sizeOf +import kotlinx.cinterop.toKString +import kotlinx.cinterop.usePinned +import kotlinx.cinterop.value +import platform.Security.SecRandomCopyBytes +import platform.Security.kSecRandomDefault +import platform.posix.AF_INET +import platform.posix.AF_INET6 +import platform.posix.AI_NUMERICHOST +import platform.posix.AI_NUMERICSERV +import platform.posix.IFF_LOOPBACK +import platform.posix.IFF_POINTOPOINT +import platform.posix.IFF_UP +import platform.posix.IPPROTO_TCP +import platform.posix.NI_MAXHOST +import platform.posix.NI_NUMERICHOST +import platform.posix.POLLIN +import platform.posix.SHUT_RDWR +import platform.posix.SOCK_STREAM +import platform.posix.SOL_SOCKET +import platform.posix.SO_NOSIGPIPE +import platform.posix.SO_REUSEADDR +import platform.posix.TCP_NODELAY +import platform.posix.accept +import platform.posix.addrinfo +import platform.posix.bind +import platform.posix.close +import platform.posix.dlopen +import platform.posix.dlsym +import platform.posix.RTLD_NOW +import platform.posix.freeaddrinfo +import platform.posix.getaddrinfo +import platform.posix.getnameinfo +import platform.posix.listen +import platform.posix.poll +import platform.posix.pollfd +import platform.posix.recv +import platform.posix.send +import platform.posix.setsockopt +import platform.posix.shutdown +import platform.posix.sockaddr +import platform.posix.socket + +/** Numeric host text of a socket address, or null when it is not IPv4/IPv6. */ +private fun numericHost(address: CPointer?): String? { + if (address == null) return null + val family = address.pointed.sa_family.toInt() + if (family != AF_INET && family != AF_INET6) return null + return memScoped { + val host = allocArray(NI_MAXHOST) + val status = getnameinfo(address, address.pointed.sa_len.convert(), host, NI_MAXHOST.convert(), null, 0u, NI_NUMERICHOST) + if (status != 0) null else host.toKString() + } +} + +// Kotlin/Native's POSIX library for iOS does not bind , so the two functions are +// resolved from libSystem at runtime and `struct ifaddrs` is read by its fixed 64-bit layout: +// ifa_next @0, ifa_name @8, ifa_flags @16, ifa_addr @24 (netmask @32, dstaddr @40, data @48). +private typealias GetIfAddrs = CFunction<(CPointer) -> Int> +private typealias FreeIfAddrs = CFunction<(COpaquePointer?) -> Unit> + +private val libSystem: COpaquePointer? by lazy { dlopen(null, RTLD_NOW) } + +private fun CPointer<*>.pointerField(offset: Int): COpaquePointer? = + (this.reinterpret() + offset)!!.reinterpret().pointed.value + +private fun CPointer<*>.uintField(offset: Int): UInt = + (this.reinterpret() + offset)!!.reinterpret().pointed.value + +/** Every address assigned to a local interface, as the shared session's [InterfaceAddress]. */ +fun iosInterfaceAddresses(): List { + val result = ArrayList() + val getifaddrs = dlsym(libSystem, "getifaddrs")?.reinterpret() ?: return result + val freeifaddrs = dlsym(libSystem, "freeifaddrs")?.reinterpret() ?: return result + memScoped { + val list = alloc() + if (getifaddrs(list.ptr) != 0) return result + try { + var item: COpaquePointer? = list.value + while (item != null) { + val host = numericHost(item.pointerField(24)?.reinterpret()) + if (host != null) { + val flags = item.uintField(16).toInt() + val bare = host.substringBefore('%') + val loopbackFlag = flags and IFF_LOOPBACK != 0 + result.add(InterfaceAddress( + interfaceName = item.pointerField(8)?.reinterpret()?.toKString() ?: "", + address = host, + up = flags and IFF_UP != 0, + pointToPoint = flags and IFF_POINTOPOINT != 0, + loopback = loopbackFlag || bare.startsWith("127.") || bare == "::1", + linkLocal = bare.startsWith("169.254.") || bare.lowercase().startsWith("fe80:"), + anyLocal = bare == "0.0.0.0" || bare == "::", + )) + } + item = item.pointerField(0) + } + } finally { + freeifaddrs(list.value) + } + } + return result +} + +private fun setIntOption(fd: Int, level: Int, option: Int, value: Int) { + memScoped { + val holder = alloc() + holder.value = value + setsockopt(fd, level, option, holder.ptr, sizeOf().convert()) + } +} + +/** Canonical numeric text of a literal address, or null when it is not a literal. */ +private fun canonicalAddress(address: String): String? = + memScoped { + val hints = alloc() + hints.ai_flags = AI_NUMERICHOST + hints.ai_socktype = SOCK_STREAM + val resolved = allocPointerTo() + if (getaddrinfo(address, null, hints.ptr, resolved.ptr) != 0) return null + try { + numericHost(resolved.value?.pointed?.ai_addr) + } finally { + freeaddrinfo(resolved.value) + } + } + +/** POSIX sockets for the shared [RemoteInputSession]. */ +object IosLocalServerPort : LocalServerPort { + override fun isLocalUnicastAddress(address: String): Boolean { + val canonical = canonicalAddress(address) ?: return false + // Wildcard and multicast addresses are never assigned to an interface. + return iosInterfaceAddresses().any { it.address == canonical || it.address.substringBefore('%') == canonical } + } + + override fun bind(address: String, port: Int): RemoteInputListener { + val fd = memScoped { + val hints = alloc() + hints.ai_flags = AI_NUMERICHOST or AI_NUMERICSERV + hints.ai_socktype = SOCK_STREAM + val resolved = allocPointerTo() + if (getaddrinfo(address, port.toString(), hints.ptr, resolved.ptr) != 0) error("Invalid address") + try { + val info = resolved.value!!.pointed + val socketFd = socket(info.ai_family, SOCK_STREAM, 0) + if (socketFd < 0) error("socket failed") + setIntOption(socketFd, SOL_SOCKET, SO_REUSEADDR, 1) + if (bind(socketFd, info.ai_addr, info.ai_addrlen) != 0 || listen(socketFd, 8) != 0) { + close(socketFd) + error("bind failed") + } + socketFd + } finally { + freeaddrinfo(resolved.value) + } + } + return PosixListener(fd) + } +} + +private class PosixListener(private val fd: Int) : RemoteInputListener { + @Volatile + private var closed = false + + override val isClosed: Boolean + get() = closed + + override fun accept(): RemoteInputConnection? { + while (!closed) { + // Polling also guarantees close() is observed where shutdown does not wake accept. + val ready = memScoped { + val request = alloc() + request.fd = fd + request.events = POLLIN.toShort() + poll(request.ptr, 1u, 250) + } + if (closed) return null + if (ready <= 0) continue + val client = accept(fd, null, null) + if (client < 0) return null + setIntOption(client, SOL_SOCKET, SO_NOSIGPIPE, 1) + setIntOption(client, IPPROTO_TCP, TCP_NODELAY, 1) + return PosixConnection(client) + } + return null + } + + override fun close() { + if (closed) return + closed = true + shutdown(fd, SHUT_RDWR) + close(fd) + } +} + +private class PosixConnection(private val fd: Int) : RemoteInputConnection { + @Volatile + private var closed = false + + override fun readByte(timeoutMs: Long): Int { + if (closed) return -1 + return memScoped { + val request = alloc() + request.fd = fd + request.events = POLLIN.toShort() + if (poll(request.ptr, 1u, timeoutMs.coerceIn(0L, Int.MAX_VALUE.toLong()).toInt()) <= 0) return -1 + val byte = alloc() + if (recv(fd, byte.ptr, 1u, 0) != 1L) -1 else byte.value.toInt() and 0xff + } + } + + override fun write(bytes: ByteArray) { + if (bytes.isEmpty() || closed) return + bytes.usePinned { pinned -> + var offset = 0 + while (offset < bytes.size) { + val sent = send(fd, pinned.addressOf(offset), (bytes.size - offset).convert(), 0) + if (sent <= 0L) error("send failed") + offset += sent.toInt() + } + } + } + + override fun close() { + if (closed) return + closed = true + shutdown(fd, SHUT_RDWR) + close(fd) + } +} + +/** Cryptographically secure bytes from the Security framework. */ +object IosSecureRandom : RandomSource { + override fun nextBytes(count: Int): ByteArray { + val bytes = ByteArray(count) + if (count == 0) return bytes + val status = bytes.usePinned { SecRandomCopyBytes(kSecRandomDefault, count.convert(), it.addressOf(0)) } + check(status == 0) { "SecRandomCopyBytes failed: $status" } + return bytes + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosRemoteInput.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosRemoteInput.kt new file mode 100644 index 00000000..1fc1034b --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosRemoteInput.kt @@ -0,0 +1,54 @@ +package com.faceclaw.app + +import platform.darwin.dispatch_async +import platform.darwin.dispatch_get_main_queue + +/** Runs [action] on the main queue, where NativeScript's JavaScript lives. */ +internal fun dispatchToMain(action: () -> Unit) { + dispatch_async(dispatch_get_main_queue()) { action() } +} + +/** + * iOS facade over the shared [RemoteInputSession] for the TypeScript side + * (app/native/remote-input.ios.ts): POSIX sockets, Security-framework randomness and + * main-queue request notifications. Mirrors the Android FaceclawRemoteInput API. + */ +class IosRemoteInput internal constructor( + dispatch: (() -> Unit) -> Unit, + requestTimeoutMs: Long, +) { + constructor() : this(::dispatchToMain, RemoteInputSession.REQUEST_TIMEOUT_MS) + + private val session = RemoteInputSession( + port = IosLocalServerPort, + random = IosSecureRandom, + dispatch = dispatch, + platform = IosProtocolPlatform, + requestTimeoutMs = requestTimeoutMs, + ) + + /** Called (on the main queue) whenever a request is waiting in [nextRequest]. */ + fun setRequestListener(listener: (() -> Unit)?) = session.setRequestListener(listener) + + fun start(port: Int): String = startAddress(port, "127.0.0.1") + + /** Returns "" on success or a user-facing error. */ + fun startAddress(port: Int, address: String): String = session.start(port, address) + + fun stop() = session.stop() + + fun nextRequest(): String? = session.nextRequest() + + fun complete(id: Long, value: String?) = session.complete(id, value) + + fun randomSecret(): String = session.randomSecret() + + fun tokenDigest(value: String): String = RemoteInputSession.tokenHash(value) + + /** JSON array of {name, address, pointToPoint} for the reachable local interfaces. */ + fun interfaces(): String = RemoteInputSession.interfacesJson(iosInterfaceAddresses()) + + companion object { + val shared: IosRemoteInput by lazy { IosRemoteInput() } + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosSseRequest.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosSseRequest.kt new file mode 100644 index 00000000..b64f303b --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosSseRequest.kt @@ -0,0 +1,119 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile + +import platform.Foundation.NSRecursiveLock +import platform.UIKit.UIApplication +import platform.UIKit.UIBackgroundTaskIdentifier +import platform.UIKit.UIBackgroundTaskInvalid + +/** + * iOS twin of the Android FaceclawSseRequest for app/native/sse.ios.ts: starts a streaming + * POST immediately and pushes the shared [SseStream] events to [listener] on the main queue, + * in order. A UIKit background task keeps the stream alive while the app is backgrounded. + * headersJson is a JSON object of header name to value. + */ +class IosSseRequest internal constructor( + url: String, + body: String, + headersJson: String?, + private val listener: FaceclawSseListener, + private val dispatch: (() -> Unit) -> Unit, + keepAliveInBackground: Boolean, +) { + constructor(url: String, body: String, headersJson: String?, listener: FaceclawSseListener) : + this(url, body, headersJson, listener, ::dispatchToMain, true) + + private val stream = SseStream() + private val lock = NSRecursiveLock() + private var backgroundTask: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid + private var keepAlive = keepAliveInBackground + + @Volatile + private var cancelled = false + private val transfer: Cancellable + + init { + val headers = ArrayList>() + if (!headersJson.isNullOrBlank()) { + runCatching { Json.parse(headersJson).asObject() }.getOrNull()?.forEach { (name, value) -> + val text = value.asString() + if (name.isNotEmpty() && text != null) headers.add(name to text) + } + } + if (keepAlive) dispatchToMain { beginBackgroundTask() } + val sink = object : ChunkSink { + override fun onStatus(code: Int) = stream.onStatus(code) + + override fun onChunk(bytes: ByteArray, offset: Int, length: Int) { + stream.onChunk(bytes, offset, length) + drain() + } + + override fun onComplete() { + stream.onComplete() + drain() + } + + override fun onFailure(message: String) { + stream.onFailure(message) + drain() + } + } + transfer = IosStreamingHttp.post(url.trim(), body, headers, sink) + } + + fun cancel() { + cancelled = true + stream.cancel() + transfer.cancel() + if (keepAlive) dispatchToMain { endBackgroundTask() } + } + + /** Hands every queued event to the listener on the main queue, in order. */ + private fun drain() { + val events = stream.takeEvents() + if (events.isEmpty()) return + dispatch { + for (event in events) { + if (cancelled) return@dispatch + try { + SseStream.deliver(event, listener) + } catch (t: Throwable) { + PlatformLog.w(TAG, "listener callback failed: ${t.message}") + } + } + if (stream.isFinished && keepAlive) endBackgroundTask() + } + } + + // Main queue only. + private fun beginBackgroundTask() { + lock.lock() + try { + if (cancelled || stream.isFinished || backgroundTask != UIBackgroundTaskInvalid) return + backgroundTask = UIApplication.sharedApplication.beginBackgroundTaskWithName("Assistant response") { + stream.onFailure("iOS background time expired. Open Faceclaw and retry.") + drain() + endBackgroundTask() + } + } finally { + lock.unlock() + } + } + + private fun endBackgroundTask() { + lock.lock() + try { + if (backgroundTask == UIBackgroundTaskInvalid) return + UIApplication.sharedApplication.endBackgroundTask(backgroundTask) + backgroundTask = UIBackgroundTaskInvalid + } finally { + lock.unlock() + } + } + + private companion object { + const val TAG = "FaceclawSseRequest" + } +} diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosStreamingHttp.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosStreamingHttp.kt new file mode 100644 index 00000000..91a32f72 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/net/IosStreamingHttp.kt @@ -0,0 +1,117 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import kotlin.concurrent.Volatile + +import platform.Foundation.NSData +import platform.Foundation.NSError +import platform.Foundation.NSHTTPURLResponse +import platform.Foundation.NSMutableURLRequest +import platform.Foundation.NSString +import platform.Foundation.NSURL +import platform.Foundation.NSURLRequest +import platform.Foundation.NSURLResponse +import platform.Foundation.NSURLSession +import platform.Foundation.NSURLSessionConfiguration +import platform.Foundation.NSURLSessionDataDelegateProtocol +import platform.Foundation.NSURLSessionDataTask +import platform.Foundation.NSURLSessionResponseAllow +import platform.Foundation.NSURLSessionResponseDisposition +import platform.Foundation.NSURLSessionTask +import platform.Foundation.NSUTF8StringEncoding +import platform.Foundation.create +import platform.Foundation.dataUsingEncoding +import platform.Foundation.setHTTPBody +import platform.Foundation.setHTTPMethod +import platform.Foundation.setValue +import platform.darwin.NSObject + +/** Builds an NSURLRequest with the shared User-Agent unless the caller supplied one. */ +internal fun buildRequest(url: NSURL, method: String, body: String?, headers: List>): NSMutableURLRequest { + val request = NSMutableURLRequest.requestWithURL(url) + request.setHTTPMethod(method) + if (body != null) request.setHTTPBody((body as NSString).dataUsingEncoding(NSUTF8StringEncoding)) + var hasUserAgent = false + for ((name, value) in headers) { + if (name.equals("User-Agent", ignoreCase = true)) hasUserAgent = true + request.setValue(value, forHTTPHeaderField = name) + } + if (!hasUserAgent) request.setValue(HttpIdentity.getUserAgent(), forHTTPHeaderField = "User-Agent") + return request +} + +internal fun parseUrl(url: String): NSURL? { + val target = NSURL.URLWithString(url) ?: return null + val scheme = target.scheme?.lowercase() ?: return null + return if (scheme == "https" || scheme == "http") target else null +} + +/** + * Streaming POST over NSURLSession for the shared [SseStream]. Redirects are refused so + * provider credentials in the headers are never forwarded; a 3xx reaches the sink as a + * status with an (empty) body. Delegate callbacks arrive on NSURLSession's own queue. + */ +internal object IosStreamingHttp : StreamingHttp { + override fun post(url: String, body: String, headers: List>, sink: ChunkSink): Cancellable { + val target = parseUrl(url) + if (target == null) { + sink.onFailure("Invalid streaming URL") + return object : Cancellable { override fun cancel() {} } + } + val request = buildRequest(target, "POST", body, listOf("Content-Type" to "application/json; charset=utf-8", "Accept" to "text/event-stream") + headers) + val configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration + configuration.timeoutIntervalForRequest = 180.0 + configuration.timeoutIntervalForResource = 180.0 + val delegate = StreamingDelegate(sink) + val session = NSURLSession.sessionWithConfiguration(configuration, delegate, delegateQueue = null) + val task = session.dataTaskWithRequest(request) + task.resume() + return object : Cancellable { + override fun cancel() { + delegate.cancelled = true + session.invalidateAndCancel() + } + } + } + + private class StreamingDelegate(private val sink: ChunkSink) : NSObject(), NSURLSessionDataDelegateProtocol { + @Volatile + var cancelled = false + + override fun URLSession( + session: NSURLSession, + dataTask: NSURLSessionDataTask, + didReceiveResponse: NSURLResponse, + completionHandler: (NSURLSessionResponseDisposition) -> Unit, + ) { + val code = (didReceiveResponse as? NSHTTPURLResponse)?.statusCode?.toInt() ?: 0 + if (!cancelled) sink.onStatus(code) + completionHandler(NSURLSessionResponseAllow) + } + + override fun URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData: NSData) { + if (cancelled) return + val bytes = didReceiveData.byteArray() + sink.onChunk(bytes, 0, bytes.size) + } + + override fun URLSession( + session: NSURLSession, + task: NSURLSessionTask, + willPerformHTTPRedirection: NSHTTPURLResponse, + newRequest: NSURLRequest, + completionHandler: (NSURLRequest?) -> Unit, + ) { + // Never forward provider credentials to a redirected endpoint. + completionHandler(null) + } + + override fun URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError: NSError?) { + if (cancelled) return + if (didCompleteWithError != null) sink.onFailure(didCompleteWithError.localizedDescription) + else sink.onComplete() + session.finishTasksAndInvalidate() + } + } +} diff --git a/package.json b/package.json index 12869539..96173ab8 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "release": "scripts/release.sh", "clean": "rm -rf platforms", "test": "tsc -p tests/tsconfig.json && node --test tests/*.test.cjs", - "test:kotlin:ios": "bash scripts/test-kotlin.sh iosSimulatorArm64Test compileKotlinIosArm64" + "test:kotlin:ios": "bash scripts/test-kotlin.sh iosSimulatorArm64Test compileKotlinIosArm64", + "postinstall": "node scripts/install-hooks.cjs" }, "dependencies": { "@evenrealities/pretext": "^0.1.4", diff --git a/scripts/before_build.sh b/scripts/before_build.sh index 9a1c34f0..9692ea5f 100644 --- a/scripts/before_build.sh +++ b/scripts/before_build.sh @@ -5,3 +5,5 @@ else cp build_paths.sh.template build_paths.sh fi +# Restore the Kotlin prepare hook if a package install removed it. +node "$(dirname "${BASH_SOURCE[0]}")/install-hooks.cjs" diff --git a/scripts/hooks/faceclaw-kotlin.before-prepare.js b/scripts/hooks/faceclaw-kotlin.before-prepare.js new file mode 100644 index 00000000..435b315f --- /dev/null +++ b/scripts/hooks/faceclaw-kotlin.before-prepare.js @@ -0,0 +1,8 @@ +const { buildKotlin, checkAndroidRuntime } = require('../../scripts/kotlin-build.cjs'); + +module.exports = function (hookArgs) { + // NativeScript parses hooks with an older JavaScript parser; avoid optional chaining. + const { platform, release } = hookArgs.prepareData; + if (platform === 'android') checkAndroidRuntime(); + return buildKotlin(platform, release ? 'release' : 'debug'); +}; diff --git a/scripts/install-hooks.cjs b/scripts/install-hooks.cjs new file mode 100644 index 00000000..a0aebec6 --- /dev/null +++ b/scripts/install-hooks.cjs @@ -0,0 +1,31 @@ +// NativeScript runs hooks//*.js, but that directory is also managed by +// @nativescript/hook on package (re)installs and has been observed to lose our +// custom hook. The tracked copy under scripts/hooks/ is the source of truth; +// this restores it on `npm install` and before every build. +const fs = require('node:fs'); +const path = require('node:path'); + +const root = path.resolve(__dirname, '..'); +const hooks = [ + { source: 'scripts/hooks/faceclaw-kotlin.before-prepare.js', target: 'hooks/before-prepare/faceclaw-kotlin.js' }, +]; + +function installHooks() { + const restored = []; + for (const { source, target } of hooks) { + const from = path.join(root, source); + const to = path.join(root, target); + const content = fs.readFileSync(from); + if (fs.existsSync(to) && fs.readFileSync(to).equals(content)) continue; + fs.mkdirSync(path.dirname(to), { recursive: true }); + fs.writeFileSync(to, content); + restored.push(target); + } + return restored; +} + +module.exports = { installHooks }; +if (require.main === module) { + const restored = installHooks(); + if (restored.length) console.log(`[hooks] restored ${restored.join(', ')}`); +} diff --git a/scripts/ios.sh b/scripts/ios.sh index e86bc302..e5e9f0d5 100755 --- a/scripts/ios.sh +++ b/scripts/ios.sh @@ -19,4 +19,5 @@ if command -v ruby >/dev/null 2>&1; then export PATH="$gem_bin:$PATH" fi +node scripts/install-hooks.cjs exec ns "$@" diff --git a/tests/ios-onboarding-ota.test.cjs b/tests/ios-onboarding-ota.test.cjs deleted file mode 100644 index 029b386d..00000000 --- a/tests/ios-onboarding-ota.test.cjs +++ /dev/null @@ -1,142 +0,0 @@ -const test = require('node:test'); -const assert = require('node:assert/strict'); -const p = require('../.test-build/app/g2/ble-protocol.js'); -const { StockConnection, OTA_WRITE, OTA_NOTIFY, decodeOtaAcks } = require('../.test-build/app/g2/stock-connection.js'); -const { firmwareCrc, validateFirmware, flashLensImage } = require('../.test-build/app/g2/firmware-ota.js'); -const { createFlashPrompt, flashPromptSelection } = require('../.test-build/app/g2/flash-prompt-protocol.js'); -const hex = bytes => Buffer.from(bytes).toString('hex'); -function fixture() { - const sizes = [9000, 20, 20, 20, 20], image = new Uint8Array(0x40 + 5 * 16 + sizes.reduce((n, size) => n + size + 128, 0)); - const view = new DataView(image.buffer), u32 = (off, value) => view.setUint32(off, value, true); - u32(8, 5); let offset = 0x40 + 5 * 16; - sizes.forEach((size, index) => { - u32(0x40 + index * 16 + 4, offset); u32(offset + 8, size); - image.set(Buffer.from(index ? `ota/part${index}.bin` : 'ota/s200_firmware_ota.bin'), offset + 48); - image.fill(index + 1, offset + 128, offset + 128 + size); - if (!index) { u32(offset + 128, size); u32(offset + 128 + 0x14, 0x00438000); } - const crc = firmwareCrc(image.subarray(offset + 128, offset + 128 + size)); - u32(offset + 12, crc); u32(0x40 + index * 16 + 12, crc); offset += size + 128; - }); - return image; -} -class Transport { - listeners = new Set(); writes = []; messages = []; chunks = []; seq = 0; held = false; respond = null; closed = []; - onEvent(fn) { this.listeners.add(fn); return () => this.listeners.delete(fn); } - emit(event) { for (const fn of this.listeners) fn(event); } - async resolveDevices() { return { left: 'L', right: 'R' }; } - async connect() { return { characteristics: [p.G2_WRITE, p.G2_NOTIFY, OTA_WRITE, OTA_NOTIFY], maxWrite: 60 }; } - async subscribe() {} - stopScan() {} - disconnect(id) { this.closed.push(id); this.emit({ kind: 'disconnected', identifier: id }); } - notify(id, sid, payload, characteristic = p.G2_NOTIFY, flag = 0) { - this.emit({ kind: 'notification', identifier: id, characteristic, data: hex(p.concat(...p.frameMessage(payload, sid, flag, 10))) }); - } - async write(id, characteristic, bytes) { - this.writes.push({ id, characteristic, bytes }); - if (bytes[5] === 1) this.chunks = []; - this.chunks.push(bytes.subarray(8)); - if (bytes[5] !== bytes[4]) return; - const all = p.concat(...this.chunks), payload = all.slice(0, -2); - assert.equal(p.crc16(payload), all.at(-2) | all.at(-1) << 8); - const message = { id, characteristic, sid: bytes[6], seq: bytes[2], payload }; - this.messages.push(message); - if (this.respond) return this.respond(message); - if (this.held) return; - if (characteristic === OTA_WRITE) { - if (message.sid === 0xc0 && payload[0] === 2) { this.seq = message.seq; return; } - if (message.sid === 0xc1) assert.equal(message.seq, this.seq, 'marker/data sequence must match'); - this.notify(id, 0xc0, new Uint8Array([message.sid === 0xc1 ? 2 : payload[0], 0]), OTA_NOTIFY); - } else { - this.notify(id, message.sid, p.concat(p.integer(1, p.readInteger(payload, 1)), p.integer(2, p.readInteger(payload, 2)), p.bytes(3, new Uint8Array()))); - } - } -} -async function connection(t, transport = new Transport()) { - const link = new StockConnection(transport); t.after(() => link.close()); - await link.resolve({ left: 'a', right: 'b', ring: '' }); await link.connect('left', true); - return { link, transport }; -} - -test('OTA validator checks CRCs, bounds, overlap and the main-app preamble before transfer', () => { - const image = fixture(), segments = validateFirmware(image); - assert.equal(segments.length, 5); - const corrupt = image.slice(); corrupt[segments[0].offset + 200] ^= 1; - assert.throws(() => validateFirmware(corrupt), /CRC32C/); - assert.throws(() => validateFirmware(image.slice(0, -1)), /truncated/); - const bad = image.slice(), view = new DataView(bad.buffer); - view.setUint32(0x44, 0xfffffff0, true); assert.throws(() => validateFirmware(bad), /bounds/); - const overlap = image.slice(); new DataView(overlap.buffer).setUint32(0x54, segments[0].offset, true); - assert.throws(() => validateFirmware(overlap), /overlap/); - const wrongLoad = image.slice(), w = new DataView(wrongLoad.buffer), main = segments[0]; - w.setUint32(main.offset + 128 + 0x14, 0, true); - const crc = firmwareCrc(wrongLoad.subarray(main.offset + 128, main.offset + 128 + main.size)); - w.setUint32(main.offset + 12, crc, true); w.setUint32(0x4c, crc, true); - assert.throws(() => validateFirmware(wrongLoad), /preamble/); -}); - -test('OTA framing streams every verified byte in 4KB blocks with shared marker/data sequences', async t => { - const { link, transport } = await connection(t); await link.authenticate('left'); - const image = fixture(), segments = validateFirmware(image), progress = []; - await flashLensImage(link, 'left', image, segments, value => progress.push(value), () => {}, async () => {}); - const controls = transport.messages.filter(m => m.sid === 0xc0); - assert.equal(controls[0].payload[0], 0); - assert.equal(controls.filter(m => m.payload[0] === 1).length, 5); - assert.equal(controls.filter(m => m.payload[0] === 3).length, 5); - const streamed = p.concat(...transport.messages.filter(m => m.sid === 0xc1).map(m => m.payload)); - assert.deepEqual(streamed, p.concat(...segments.map(s => image.slice(s.offset + 128, s.offset + 128 + s.size)))); - assert.equal(progress.at(-1).bytesSent, progress.at(-1).bytesTotal); - assert.ok(transport.writes.every(w => w.bytes.length <= 60)); -}); - -test('OTA retries NAKed blocks and failed END verification, but never accepts a rejected FILE_CHECK', async () => { - const image = fixture(), segments = validateFirmware(image); let blockAttempts = 0, endAttempts = 0, checks = 0; - const fake = { check() {}, async exchange(_role, _sid, payload, _match, _timeout, _write, _notify, _flag, _seq, data) { - const op = payload[0]; let status = 0; - if (op === 1) checks++; - if (op === 2 && ++blockAttempts === 1) status = 1; - if (op === 3 && ++endAttempts === 1) status = 2; - return { payload: new Uint8Array([op, status]) }; - } }; - await flashLensImage(fake, 'left', image, segments, () => {}, () => {}, async () => {}); - assert.equal(checks, 6); assert.equal(blockAttempts, 11); - let dataWrites = 0; - fake.exchange = async (_role, _sid, payload, ...args) => { if (args.at(-1)) dataWrites++; return { payload: new Uint8Array([payload[0], payload[0] === 1 ? 4 : 0]) }; }; - await assert.rejects(flashLensImage(fake, 'left', image, segments, () => {}, () => {}, async () => {}), /failed after 3 attempts/); - assert.equal(dataWrites, 0); -}); - -test('onboarding requests ignore wrong peers, magic and pre-encryption authentication failures', async t => { - const { link, transport } = await connection(t); let resolved = false; - transport.respond = message => { - const magic = p.readInteger(message.payload, 2); - const good = p.concat(p.integer(1, 4), p.integer(2, magic), p.bytes(3, new Uint8Array())); - transport.notify('stranger', p.SID.auth, good); - transport.notify('R', p.SID.auth, good); - transport.notify('L', p.SID.auth, p.concat(p.integer(1, 4), p.integer(2, magic), p.bytes(3, p.integer(1, 1)))); - transport.notify('L', p.SID.auth, p.concat(p.integer(1, 4), p.integer(2, magic + 1), p.bytes(3, new Uint8Array()))); - setImmediate(() => { assert.equal(resolved, false); transport.notify('L', p.SID.auth, good); }); - }; - await link.authenticate('left'); resolved = true; -}); - -test('OTA ACK parsing rejects bad CRC and truncation; cancellation rejects an outstanding transaction', async t => { - const { link, transport } = await connection(t); transport.held = true; - const payload = new Uint8Array([2, 0]), packet = p.frameMessage(payload, 0xc0, 0, 1)[0]; - assert.equal(decodeOtaAcks(packet)[0].payload[1], 0); - assert.deepEqual(decodeOtaAcks(packet.slice(0, -1)), []); - packet[8] ^= 1; assert.deepEqual(decodeOtaAcks(packet), []); - const pending = link.exchange('left', 0xc0, new Uint8Array([0]), m => m.command === 0, 8000, OTA_WRITE, OTA_NOTIFY, 0); - link.close(); await assert.rejects(pending, /Cancelled/); - assert.equal(transport.listeners.size, 0); -}); - -test('stock confirmation keeps No first and accepts only a confirmed flashmenu selection', () => { - const page = createFlashPrompt(42, 'Warning'); const body = p.readBytes(page, 3); - const list = p.readBytes(body, 2), label = p.readBytes(body, 3); - assert.equal(p.readInteger(list, 3), 280); assert.equal(p.readInteger(label, 4), 130); - assert.equal(p.readString(list, 10), 'flashmenu'); assert.equal(p.readString(label, 12), 'Warning'); - const event = (index, type = 0, name = 'flashmenu') => ({ sid: 0xe0, flag: 1, - payload: p.bytes(13, p.bytes(1, p.concat(p.bytes(2, new Uint8Array(Buffer.from(name))), p.integer(4, index), p.integer(5, type)))) }); - assert.equal(flashPromptSelection(event(0)), false); assert.equal(flashPromptSelection(event(1)), true); - assert.equal(flashPromptSelection(event(1, 1)), null); assert.equal(flashPromptSelection(event(1, 0, 'other')), null); -}); diff --git a/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosNetworkingTest.kt b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosNetworkingTest.kt new file mode 100644 index 00000000..fea48103 --- /dev/null +++ b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosNetworkingTest.kt @@ -0,0 +1,314 @@ +@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class) + +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertContentEquals +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue +import kotlinx.cinterop.ByteVar +import kotlinx.cinterop.addressOf +import kotlinx.cinterop.alloc +import kotlinx.cinterop.allocPointerTo +import kotlinx.cinterop.memScoped +import kotlinx.cinterop.pointed +import kotlinx.cinterop.ptr +import kotlinx.cinterop.usePinned +import kotlinx.cinterop.value +import platform.Foundation.NSTemporaryDirectory +import platform.posix.AI_NUMERICHOST +import platform.posix.AI_NUMERICSERV +import platform.posix.SOCK_STREAM +import platform.posix.addrinfo +import platform.posix.close +import platform.posix.connect +import platform.posix.freeaddrinfo +import platform.posix.getaddrinfo +import platform.posix.recv +import platform.posix.send +import platform.posix.socket + +private var nextPort = 43000 + (currentTimeMillis() % 9000).toInt() + +/** Binds the next free loopback port; returns the listener and its port. */ +private fun bindFreePort(): Pair { + repeat(50) { + val port = nextPort++ + val listener = runCatching { IosLocalServerPort.bind("127.0.0.1", port) }.getOrNull() ?: return@repeat + return listener to port + } + error("no free loopback port") +} + +/** Blocking POSIX client: connects to loopback, sends [request], reads until the peer closes. */ +private fun loopbackExchange(port: Int, request: ByteArray, readTimeoutMs: Int = 8000): ByteArray = memScoped { + val hints = alloc() + hints.ai_flags = AI_NUMERICHOST or AI_NUMERICSERV + hints.ai_socktype = SOCK_STREAM + val resolved = allocPointerTo() + check(getaddrinfo("127.0.0.1", port.toString(), hints.ptr, resolved.ptr) == 0) + val info = resolved.value!!.pointed + val fd = socket(info.ai_family, SOCK_STREAM, 0) + check(fd >= 0) + try { + check(connect(fd, info.ai_addr, info.ai_addrlen) == 0) { "connect failed" } + request.usePinned { check(send(fd, it.addressOf(0), request.size.toULong(), 0) == request.size.toLong()) } + val out = ByteSink() + val buffer = ByteArray(4096) + val deadline = IosProtocolPlatform.elapsedRealtimeMs() + readTimeoutMs + while (IosProtocolPlatform.elapsedRealtimeMs() < deadline) { + val n = buffer.usePinned { recv(fd, it.addressOf(0), buffer.size.toULong(), 0) } + if (n <= 0L) break + out.write(buffer, 0, n.toInt()) + if (out.toByteArray().last() == '\n'.code.toByte()) break + } + out.toByteArray() + } finally { + freeaddrinfo(resolved.value) + close(fd) + } +} + +/** Minimal loopback HTTP/1.1 server for the NSURLSession facades; one request per connection. */ +private class LoopbackHttpServer(private val handler: (path: String, headers: Map) -> Reply) { + class Reply(val status: Int, val headers: List>, val pieces: List, val pieceDelayMs: Long = 0) + + private val listener: RemoteInputListener + val port: Int + val requests = ArrayList>() + private val lock = IosProtocolPlatform.createLock() + + init { + val bound = bindFreePort() + listener = bound.first + port = bound.second + startThread("loopback-http", true) { + while (!listener.isClosed) { + val connection = listener.accept() ?: continue + startThread("loopback-http-conn", true) { serve(connection) } + } + } + } + + fun url(path: String) = "http://127.0.0.1:$port$path" + + fun close() = listener.close() + + fun requestsFor(path: String): List> = lock.withLock { requests.filter { it["path"] == path } } + + private fun serve(connection: RemoteInputConnection) { + try { + val head = ByteSink() + while (true) { + val b = connection.readByte(5000) + if (b < 0) return + head.write(b) + val bytes = head.toByteArray() + val n = bytes.size + if (n >= 4 && bytes[n - 4] == '\r'.code.toByte() && bytes[n - 3] == '\n'.code.toByte() && + bytes[n - 2] == '\r'.code.toByte() && bytes[n - 1] == '\n'.code.toByte()) break + } + val lines = head.toByteArray().decodeToString().split("\r\n").filter { it.isNotEmpty() } + val path = lines.first().split(' ')[1] + val headers = lines.drop(1).associate { it.substringBefore(':').trim().lowercase() to it.substringAfter(':').trim() } + val bodyLength = headers["content-length"]?.toIntOrNull() ?: 0 + repeat(bodyLength) { connection.readByte(5000) } + lock.withLock { requests.add(headers + ("path" to path)) } + val reply = handler(path, headers) + val total = reply.pieces.sumOf { it.size } + val response = buildString { + append("HTTP/1.1 ${reply.status} X\r\n") + for ((name, value) in reply.headers) append("$name: $value\r\n") + append("Content-Length: $total\r\nConnection: close\r\n\r\n") + } + connection.write(response.encodeToByteArray()) + for (piece in reply.pieces) { + connection.write(piece) + if (reply.pieceDelayMs > 0) sleepMs(reply.pieceDelayMs) + } + } catch (ignored: Exception) { + } finally { + connection.close() + } + } +} + +private fun waitUntil(timeoutMs: Long, condition: () -> Boolean): Boolean { + val deadline = IosProtocolPlatform.elapsedRealtimeMs() + timeoutMs + while (IosProtocolPlatform.elapsedRealtimeMs() < deadline) { + if (condition()) return true + sleepMs(20) + } + return condition() +} + +private class RecordingSseListener : FaceclawSseListener { + private val lock = IosProtocolPlatform.createLock() + val lines = ArrayList() + var httpError: Pair? = null + var failure: String? = null + var completed = false + val finished: Boolean get() = lock.withLock { completed || httpError != null || failure != null } + + override fun onLine(line: String?) { lock.withLock { lines.add(line ?: "") } } + override fun onHttpError(code: Int, body: String?) { lock.withLock { httpError = code to (body ?: "") } } + override fun onComplete() { lock.withLock { completed = true } } + override fun onFailure(message: String?) { lock.withLock { failure = message ?: "" } } +} + +private class RecordingDownloadListener : FaceclawModelDownloaderListener { + private val lock = IosProtocolPlatform.createLock() + var progress = 0 + var done: String? = null + var error: String? = null + val finished: Boolean get() = lock.withLock { done != null || error != null } + + override fun onProgress(bytesDownloaded: Long, totalBytes: Long) { lock.withLock { progress++ } } + override fun onDone(path: String?) { lock.withLock { done = path } } + override fun onError(message: String?) { lock.withLock { error = message } } +} + +class IosNetworkingTest { + private val immediate: (() -> Unit) -> Unit = { it() } + + /** Like the main queue: never runs on the caller's thread, so the session's lock is not re-entered. */ + private val hop: (() -> Unit) -> Unit = { action -> startThread("test-dispatch", true, action) } + + @Test + fun remoteInputRoundTripsOverLoopbackAndTimesOut() { + val (probe, port) = bindFreePort() + probe.close() + val remote = IosRemoteInput(hop, requestTimeoutMs = 1200) + val ready = BlockingQueue(IosProtocolPlatform) + remote.setRequestListener { ready.put("ready") } + assertEquals("Invalid local address.", remote.startAddress(port, "example.com")) + assertEquals("Address is not assigned to a local interface.", remote.startAddress(port, "0.0.0.0")) + assertEquals("", remote.startAddress(port, "127.0.0.1")) + try { + val replies = BlockingQueue(IosProtocolPlatform) + startThread("remote-client", true) { replies.put(loopbackExchange(port, "hello world\n".encodeToByteArray())) } + assertEquals("ready", ready.poll(5000)) + val request = Json.parseObject(assertNotNull(remote.nextRequest())) + assertEquals("hello world", request["body"].asString()) + assertNull(remote.nextRequest()) + remote.complete(request["id"].asLong()!!, "{\"ok\":true}") + assertEquals("{\"ok\":true}\n", assertNotNull(replies.poll(5000)).decodeToString()) + + startThread("remote-client-2", true) { replies.put(loopbackExchange(port, "later\n".encodeToByteArray())) } + assertEquals("ready", ready.poll(5000)) + assertNotNull(remote.nextRequest()) + assertEquals(RemoteInputSession.TIMEOUT_RESPONSE + "\n", assertNotNull(replies.poll(8000)).decodeToString()) + + assertEquals(64, remote.randomSecret().length) + assertEquals(RemoteInputSession.tokenHash("abc"), remote.tokenDigest("abc")) + val all = iosInterfaceAddresses() + assertTrue(all.any { it.loopback && it.address == "127.0.0.1" }, all.toString()) + assertTrue(Json.parseArray(remote.interfaces()).none { it.asObject()!!["address"].asString() == "127.0.0.1" }) + assertTrue(IosLocalServerPort.isLocalUnicastAddress("::1")) + assertFalse(IosLocalServerPort.isLocalUnicastAddress("224.0.0.1")) + } finally { + remote.stop() + } + } + + @Test + fun sseStreamsLinesRefusesRedirectsAndReportsErrors() { + val body = "event: a\r\ndata: one\n\ndata: two\r\n".encodeToByteArray() + val server = LoopbackHttpServer { path, _ -> + when (path) { + "/sse" -> LoopbackHttpServer.Reply(200, listOf("Content-Type" to "text/event-stream"), + listOf(body.copyOfRange(0, 13), body.copyOfRange(13, body.size)), pieceDelayMs = 50) + "/limited" -> LoopbackHttpServer.Reply(429, listOf("Content-Type" to "text/plain"), listOf("slow down".encodeToByteArray())) + else -> LoopbackHttpServer.Reply(302, listOf("Location" to "http://127.0.0.1:1/never"), listOf(ByteArray(0))) + } + } + try { + val ok = RecordingSseListener() + IosSseRequest(server.url("/sse"), "{\"q\":1}", "{\"X-Test\":\"yes\"}", ok, immediate, false) + assertTrue(waitUntil(10_000) { ok.finished }, "sse did not finish: ${ok.failure}") + assertEquals(listOf("event: a", "data: one", "", "data: two"), ok.lines) + assertTrue(ok.completed) + val request = server.requestsFor("/sse").single() + assertEquals("yes", request["x-test"]) + assertEquals("text/event-stream", request["accept"]) + assertTrue(request["user-agent"]!!.isNotEmpty()) + + val limited = RecordingSseListener() + IosSseRequest(server.url("/limited"), "{}", null, limited, immediate, false) + assertTrue(waitUntil(10_000) { limited.finished }) + assertEquals(429 to "slow down", limited.httpError) + + val redirected = RecordingSseListener() + IosSseRequest(server.url("/moved"), "{}", "{}", redirected, immediate, false) + assertTrue(waitUntil(10_000) { redirected.finished }) + assertEquals(302, redirected.httpError?.first) + assertTrue(server.requestsFor("/never").isEmpty()) + } finally { + server.close() + } + } + + @Test + fun downloaderFetchesAndResumesWithRange() { + val payload = ByteArray(200_000) { (it * 31 + it / 977).toByte() } + val sha = sha256Hex(payload) + val server = LoopbackHttpServer { _, headers -> + val range = headers["range"] + if (range != null && range.startsWith("bytes=")) { + val from = range.removePrefix("bytes=").removeSuffix("-").toInt() + LoopbackHttpServer.Reply(206, listOf("Content-Range" to "bytes $from-${payload.size - 1}/${payload.size}"), + listOf(payload.copyOfRange(from, payload.size))) + } else LoopbackHttpServer.Reply(200, emptyList(), listOf(payload.copyOfRange(0, 70_000), payload.copyOfRange(70_000, payload.size)), pieceDelayMs = 30) + } + val dir = NSTemporaryDirectory().trimEnd('/') + "/faceclaw-dl-" + currentTimeMillis() + val dest = "$dir/model.bin" + try { + val first = RecordingDownloadListener() + IosModelDownloader(server.url("/model.bin"), dest, sha, payload.size.toLong(), first, immediate).start() + assertTrue(waitUntil(20_000) { first.finished }, "download did not finish: ${first.error}") + assertEquals(dest, first.done, first.error) + assertContentEquals(payload, readFileData(dest)) + assertTrue(first.progress >= 1) + assertNull(server.requestsFor("/model.bin").single()["range"]) + + deleteFile(dest) + writeFileData("$dest.part", payload.copyOfRange(0, 50_000)) + val second = RecordingDownloadListener() + IosModelDownloader(server.url("/model.bin"), dest, sha, payload.size.toLong(), second, immediate).start() + assertTrue(waitUntil(20_000) { second.finished }, "resume did not finish: ${second.error}") + assertEquals(dest, second.done, second.error) + assertContentEquals(payload, readFileData(dest)) + assertEquals("bytes=50000-", server.requestsFor("/model.bin").last()["range"]) + assertEquals(-1L, fileLength("$dest.part")) + } finally { + server.close() + deleteFile(dest) + deleteFile("$dest.part") + } + } + + @Test + fun frameTimingsExportsToAFile() { + val dir = NSTemporaryDirectory().trimEnd('/') + "/faceclaw-ft-" + currentTimeMillis() + platform.Foundation.NSFileManager.defaultManager.createDirectoryAtPath(dir, true, null, null) + val timings = IosFrameTimings(IosProtocolPlatform) + assertNull(timings.exportNow()) + timings.startExport(dir) + val frame = timings.startFrame("test:frame") + timings.spanStart(frame, "work") + timings.log(frame, "hello") + timings.spanEnd(frame, "work") + timings.finishFrame(frame, "sent") + val path = assertNotNull(timings.exportNow()) + assertEquals("$dir/${IosFrameTimings.EXPORT_FILE_NAME}", path) + val text = readFileData(path).decodeToString() + assertTrue(text.contains("test:frame"), text) + assertTrue(text.contains("hello"), text) + assertNull(timings.exportNow()) + assertTrue(timings.statsSummary().isNotEmpty()) + deleteFile(path) + } +} diff --git a/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosSessionFacadeTest.kt b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosSessionFacadeTest.kt new file mode 100644 index 00000000..6067bfc8 --- /dev/null +++ b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosSessionFacadeTest.kt @@ -0,0 +1,228 @@ +package com.faceclaw.app + +import kotlin.concurrent.Volatile +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNotNull +import kotlin.test.assertTrue +import platform.Foundation.NSDate +import platform.Foundation.NSDefaultRunLoopMode +import platform.Foundation.NSRunLoop +import platform.Foundation.NSThread +import platform.Foundation.dateWithTimeIntervalSinceNow +import platform.Foundation.runMode + +private const val RIGHT = "11111111-2222-3333-4444-555555555501" +private const val LEFT = "11111111-2222-3333-4444-555555555502" + +/** Pump the main run loop (which drains the main dispatch queue) until [condition] or timeout. */ +private fun pumpMainUntil(timeoutMs: Long, condition: () -> Boolean): Boolean { + val deadline = IosProtocolPlatform.elapsedRealtimeMs() + timeoutMs + while (IosProtocolPlatform.elapsedRealtimeMs() < deadline) { + if (condition()) return true + NSRunLoop.mainRunLoop.runMode(NSDefaultRunLoopMode, NSDate.dateWithTimeIntervalSinceNow(0.02)) + } + return condition() +} + +/** A GATT link that acks EvenHub/settings/auth requests and CFW stream messages like the firmware. */ +private class FakeIosLink : SessionLink { + lateinit var core: GlassesSessionCore + private val lock = IosProtocolPlatform.createLock() + val connected = HashSet() + val disconnected = ArrayList() + @Volatile var closed = false + @Volatile var writes = 0 + private var seq = 0 + + override fun connect(address: String, timeoutMs: Int): Boolean { + connected.add(address) + return true + } + + override fun requestHighPriority(address: String) {} + + override fun requestMtu(address: String, mtu: Int, timeoutMs: Int): Boolean = true + + override fun negotiatedMtu(address: String): Int = 247 + + override fun discoverServices(address: String, timeoutMs: Int): Boolean = true + + override fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean = true + + override fun writeFrames(address: String, characteristicUuid: String, frames: List, mode: GattWriteMode, timeoutMs: Int): Boolean { + writes++ + val sid = frames[0][6].toInt() and 255 + val magic = if (sid == CfwTransport.SID) frames[0][2].toInt() and 255 else BleProtocol.parseFrame(frames[0]).msgSeq + val inFlight = core.monitor.withLock { core.inFlightMessages.firstOrNull { it.sid == sid && it.magic == magic && magic != 0 } } + if (inFlight != null) { + if (sid == CfwTransport.SID) { + for (lens in 1..2) core.onNotification(address, BleProtocol.NOTIFY_CHAR_UUID, cfwAck(magic, lens, inFlight.message.size, inFlight.cfwChecksum)) + } else { + val joined = frames.flatMap { frame -> frame.slice(8 until 8 + (frame[3].toInt() and 255)) }.toByteArray() + val pb = joined.copyOf(maxOf(0, joined.size - 2)) + core.onNotification(address, BleProtocol.NOTIFY_CHAR_UUID, ackFrame(sid, magic, pb)) + } + } + return true + } + + private fun ackFrame(sid: Int, magic: Int, request: ByteArray): ByteArray { + val body = if (sid == BleProtocol.SID_SECURITY_AUTH) + BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + byteArrayOf(0x1a, 0x00) + else + BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic) + return lock.withLock { BleProtocol.framePb(body, sid, 0x00, seq++)[0] } + } + + private fun cfwAck(streamId: Int, lens: Int, size: Int, checksum: Int): ByteArray { + val packet = ByteArray(19) + packet[0] = 0xaa.toByte() + packet[1] = 0x12 + packet[3] = 11 + packet[4] = 1 + packet[5] = 1 + packet[6] = CfwTransport.SID.toByte() + packet[8] = 1 + packet[9] = streamId.toByte() + packet[12] = lens.toByte() + packet[13] = size.toByte() + packet[14] = (size ushr 8).toByte() + packet[15] = checksum.toByte() + packet[16] = (checksum ushr 8).toByte() + val crc = CfwTransport.crc(packet.copyOfRange(8, 17)) + packet[17] = crc.toByte() + packet[18] = (crc ushr 8).toByte() + return packet + } + + override fun disconnect(address: String) { + disconnected.add(address) + connected.remove(address) + } + + override fun close() { + closed = true + } + + override fun isBonded(address: String): Boolean = true + + override fun prepareBenchmarkLink(address: String, mode: Int) {} + + override fun recordDisplayFrameSent() {} +} + +private class MainThreadListener : FaceclawBleCommunicatorListener { + val phases = ArrayList() + var offMainCallbacks = 0 + + private fun record(phase: String) { + if (!NSThread.isMainThread) offMainCallbacks++ + phases.add(phase) + } + + override fun onStateChange(phase: String?, status: String?) = record(phase ?: "") + + override fun onRingEvent(kind: String?, containerName: String?, eventType: Int, eventSource: Int, systemExitReasonCode: Int, frameId: Int, ringTick: Long, ringType: Int, ringAux: Int, ringSpeed: Int) {} + + override fun onBatteryState(headsetBattery: Int, headsetCharging: Int, ringBattery: Int, ringCharging: Int) { + if (!NSThread.isMainThread) offMainCallbacks++ + } + + override fun onSilentMode(silent: Boolean) {} + + override fun onWearState(wearing: Boolean) {} + + override fun onPhoneLockState(locked: Boolean) {} + + override fun onEvenAppConflict(message: String?) {} + + override fun onFrameMetrics(paintMs: Int, transmitMs: Int, tileCount: Int) {} + + override fun onFrameFinished(frameId: Int, outcome: String?) {} + + override fun onFirmwareInfo(leftVersion: String?, rightVersion: String?, extension: String?) {} +} + +class IosSessionFacadeTest { + @Test + fun facadeSessionConnectsOverAnInjectedLinkAndReportsOnTheMainQueue() { + assertTrue(NSThread.isMainThread, "tests drive the main run loop") + val link = FakeIosLink() + val host = IosSessionHost(threadName = "test-session") + val session = IosGlassesSession(link, null, host, RIGHT, LEFT, "", IosProtocolPlatform) + link.core = session.coreForTests() + val listener = MainThreadListener() + session.setListener(listener) + assertTrue(session.start()) + assertFalse(session.start(), "already running") + assertTrue(pumpMainUntil(5_000) { listener.phases.contains("connected") }, "phases=${listener.phases}") + assertTrue(session.isSessionReady()) + assertEquals(0, listener.offMainCallbacks, "listener callbacks must arrive on the main queue") + assertTrue(pumpMainUntil(5_000) { link.writes > 3 }, "auth, prelude, settings and layout writes (saw ${link.writes})") + session.disconnect() + assertTrue(pumpMainUntil(2_000) { listener.phases.lastOrNull() == "disconnected" }, "phases=${listener.phases}") + assertFalse(session.isSessionReady()) + assertTrue(link.closed) + assertEquals(listOf(RIGHT, LEFT), link.disconnected.takeLast(2)) + assertEquals(0, listener.offMainCallbacks) + } + + @Test + fun relayFramesReachTheAncsListenerOnMainAndOtherFramesDoNot() { + val link = FakeIosLink() + val host = IosSessionHost(threadName = "test-session-ancs") + val session = IosGlassesSession(link, null, host, RIGHT, LEFT, "", IosProtocolPlatform) + val core = session.coreForTests() + link.core = core + val relayed = ArrayList() + var offMain = 0 + session.setAncsListener(object : IosAncsListener { + override fun onAncsAuthorization(authorized: Boolean) {} + + override fun onRelayFrame(data: platform.Foundation.NSData) { + if (!NSThread.isMainThread) offMain++ + relayed.add(data.byteArray()) + } + }) + val relay = byteArrayOf(65, 78, 1, 0, 9, 9, 9, 9, 0, 0, 0) + core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID, relay) + core.onNotification(LEFT, BleProtocol.NOTIFY_CHAR_UUID, relay) // wrong arm: ignored by the tap + assertTrue(pumpMainUntil(2_000) { relayed.size == 1 }) + assertEquals(relay.toList(), relayed[0].toList()) + assertEquals(0, offMain) + session.setAncsListener(null) + core.onNotification(RIGHT, BleProtocol.NOTIFY_CHAR_UUID, relay) + assertFalse(pumpMainUntil(200) { relayed.size > 1 }) + } + + @Test + fun hostDispatchesToTheCallingQueueAndRunsTheWorker() { + val host = IosSessionHost(threadName = "test-host") + var onMain = false + host.currentThreadDispatcher().post { onMain = NSThread.isMainThread } + assertTrue(pumpMainUntil(1_000) { onMain }) + var workerThread = "" + host.startWorker { workerThread = NSThread.currentThread.name ?: "" } + host.joinWorker(2_000) + assertEquals("test-host", workerThread) + var posted = false + host.postToMain { posted = NSThread.isMainThread } + assertTrue(pumpMainUntil(1_000) { posted }) + assertFalse(host.isEvenAppActive()) + } + + @Test + fun stockFlowFacadesConstructWithoutBluetooth() { + // No CoreBluetooth on the simulator; construction and cancel/close must still be safe. + val probe = IosDeviceInfoProbe(RIGHT, LEFT) + probe.setListener(null) + probe.close() + val prompt = IosFlashPrompt(RIGHT, LEFT, "warn", true) + prompt.close() + val flasher = IosFirmwareFlasher(RIGHT, LEFT, "/nonexistent.bin") + flasher.close() + assertNotNull(IosFrameTimings.shared.core.buildExport()) + } +} From 4a194e37bb34b61c1872436321f4321a205d2a7b Mon Sep 17 00:00:00 2001 From: James Babcock Date: Tue, 22 Sep 2026 21:26:51 -0700 Subject: [PATCH 13/27] Refactor iOS version to use a bunch more shared code --- App_Resources/iOS/build.xcconfig | 4 + App_Resources/iOS/src/module.modulemap | 3 - app/g2/ble-image-optimizer.ios.ts | 15 - app/g2/ble-image-optimizer.ts | 50 -- app/g2/ble-protocol.ts | 203 ----- app/g2/ble-traffic-counters.ts | 17 - app/g2/brightness-protocol.ts | 8 - app/g2/cfw-transport.ios.ts | 21 - app/g2/cfw-transport.ts | 57 -- app/g2/draw-protocol.ts | 15 - app/g2/glasses-session.ts | 645 --------------- app/g2/ios-preview-controller.ts | 513 +++++++++--- app/g2/texture-planner.ts | 8 - app/g2/wear-protocol.ts | 15 - app/graphics/surface-compositor.ios.ts | 5 - app/graphics/surface-compositor.ts | 2 - app/native/ble-traffic.ios.ts | 16 +- app/native/device-info-probe.ios.ts | 137 ++-- app/native/faceclaw-communicator.ios.ts | 677 ++++++++++++++++ app/native/firmware-flasher.ios.ts | 153 ++-- app/native/flash-prompt-communicator.ios.ts | 164 ++-- app/native/ios-bluetooth.ts | 129 ++- app/native/kotlin-listener.ios.ts | 10 + app/native/kotlin-protocol-smoke.ios.ts | 30 +- app/native/preview-display.ios.ts | 141 ++++ app/native/remote-input.ios.ts | 18 +- app/native/sse.ios.ts | 33 +- app/native/texture-planner.ios.ts | 13 - native/kotlin/README.md | 13 +- .../com/faceclaw/app/ble/IosBleCentral.kt | 6 + .../com/faceclaw/app/ble/IosGlassesSession.kt | 23 + tests/ble-image-optimizer.test.cjs | 66 -- tests/cfw-transport.test.cjs | 53 -- tests/ios-app-host.test.cjs | 105 ++- tests/ios-assistant.test.cjs | 32 +- tests/ios-ble.test.cjs | 751 ------------------ tests/ios-glanceboard.test.cjs | 116 ++- tests/ios-onboarding.test.cjs | 171 ++-- tests/ring-input-protocol.test.cjs | 32 - tests/tsconfig.json | 9 +- 40 files changed, 1874 insertions(+), 2605 deletions(-) delete mode 100644 app/g2/ble-image-optimizer.ios.ts delete mode 100644 app/g2/ble-image-optimizer.ts delete mode 100644 app/g2/ble-protocol.ts delete mode 100644 app/g2/ble-traffic-counters.ts delete mode 100644 app/g2/brightness-protocol.ts delete mode 100644 app/g2/cfw-transport.ios.ts delete mode 100644 app/g2/cfw-transport.ts delete mode 100644 app/g2/draw-protocol.ts delete mode 100644 app/g2/glasses-session.ts delete mode 100644 app/g2/texture-planner.ts delete mode 100644 app/g2/wear-protocol.ts create mode 100644 app/native/faceclaw-communicator.ios.ts create mode 100644 app/native/kotlin-listener.ios.ts create mode 100644 app/native/preview-display.ios.ts delete mode 100644 app/native/texture-planner.ios.ts delete mode 100644 tests/ble-image-optimizer.test.cjs delete mode 100644 tests/cfw-transport.test.cjs delete mode 100644 tests/ios-ble.test.cjs delete mode 100644 tests/ring-input-protocol.test.cjs diff --git a/App_Resources/iOS/build.xcconfig b/App_Resources/iOS/build.xcconfig index abc28fff..f657ddce 100644 --- a/App_Resources/iOS/build.xcconfig +++ b/App_Resources/iOS/build.xcconfig @@ -8,6 +8,10 @@ OTHER_LDFLAGS = $(inherited) -framework CoreBluetooth -framework CoreLocation -f ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; HEADER_SEARCH_PATHS = $(inherited) "$(SRCROOT)/../../App_Resources/iOS/src/lc3" +// NativeScript's xcconfig merge keeps only the CocoaPods HEADER_SEARCH_PATHS when the +// generated project is rebuilt, so the vendored liblc3 include dir is also passed as a flag +// (OTHER_CFLAGS merges like OTHER_LDFLAGS). +OTHER_CFLAGS = $(inherited) -I"$(SRCROOT)/../../App_Resources/iOS/src/lc3" // FaceclawKit ships arm64 device and Apple-silicon simulator slices. EXCLUDED_ARCHS[sdk=iphonesimulator*] = x86_64; diff --git a/App_Resources/iOS/src/module.modulemap b/App_Resources/iOS/src/module.modulemap index 73b6e464..14291369 100644 --- a/App_Resources/iOS/src/module.modulemap +++ b/App_Resources/iOS/src/module.modulemap @@ -1,17 +1,14 @@ module FaceclawGraphics { header "FaceclawGraphics.h" header "FaceclawFontRenderer.h" - header "FaceclawBluetooth.h" header "FaceclawSocket.h" header "FaceclawLc3Decoder.h" header "FaceclawSpeech.h" - header "FaceclawSseRequest.h" header "FaceclawLocation.h" header "FaceclawCalendar.h" header "FaceclawConfigPort.h" header "FaceclawEvenHubWebView.h" header "FaceclawCrypto.h" - header "FaceclawRemoteInput.h" header "FaceclawQrScanner.h" export * } diff --git a/app/g2/ble-image-optimizer.ios.ts b/app/g2/ble-image-optimizer.ios.ts deleted file mode 100644 index 989ca1c2..00000000 --- a/app/g2/ble-image-optimizer.ios.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { fromData, toData, nativeArray } from '../native/kotlin-data' -declare const FaceclawKitIosProtocol: any -const protocol = FaceclawKitIosProtocol.new() -export function buildBoundingBoxPayload(previous: Uint8Array | null, next: Uint8Array, width: number, height: number, frameId: number): Uint8Array | null { - if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0 || - width % 4 || height % 2 || width / 4 > 255 || height / 2 > 255 || - !previous || previous.length !== width * height / 2 || next.length !== previous.length) return null - const result = protocol.boundingBoxPreviousNextWidthHeightFrameId(toData(previous), toData(next), width, height, frameId) - return result ? fromData(result) : null -} -export function buildFullFrameBands(packed: Uint8Array, width: number, height: number, firstId: number): Uint8Array[] { - if (width <= 0 || width > 640 || width % 4 || height <= 0 || height > 480 || height % 2 || packed.length !== width * height / 2) - throw new Error('Invalid framebuffer dimensions') - return nativeArray(protocol.fullFrameBandsDataWidthHeightFirstId(toData(packed), width, height, firstId), fromData) -} diff --git a/app/g2/ble-image-optimizer.ts b/app/g2/ble-image-optimizer.ts deleted file mode 100644 index 8ae18607..00000000 --- a/app/g2/ble-image-optimizer.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { CFW_MSG_BOUNDING_BOX } from "./cfw-message-type"; -import { concat, rle4 } from './ble-protocol' - -/** Android BleImageOptimizer's mode-3 changed rectangle. Coordinates are in - * units of 4 columns / 2 rows; pixels are top-down packed 4bpp, high nibble first. - * null means identical, incomparable, or a full-screen box: use dedup/mode 6. Compression belongs to the CFW transport. - */ -export function buildBoundingBoxPayload(previous: Uint8Array | null, next: Uint8Array, - width: number, height: number, frameId: number): Uint8Array | null { - if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0 || - width % 4 || height % 2 || width / 4 > 255 || height / 2 > 255 || - !previous || previous.length !== width * height / 2 || next.length !== previous.length) return null - const stride = width / 2 - let minX = stride, maxX = -1, minY = height, maxY = -1 - for (let y = 0; y < height; y++) { - const row = y * stride - for (let x = 0; x < stride; x++) { - if (previous[row + x] === next[row + x]) continue - minX = Math.min(minX, x); maxX = Math.max(maxX, x) - minY = Math.min(minY, y); maxY = y - } - } - if (maxY < 0) return null - const left = (minX * 2) & ~3, right = Math.min(width, ((maxX + 1) * 2 + 3) & ~3) - const top = minY & ~1, bottom = Math.min(height, (maxY + 2) & ~1) - const boxWidth = right - left, boxHeight = bottom - top - if (boxWidth === width && boxHeight === height) return null - const regionStride = boxWidth / 2, region = new Uint8Array(regionStride * boxHeight) - for (let y = 0; y < boxHeight; y++) { - const start = (top + y) * stride + left / 2 - region.set(next.subarray(start, start + regionStride), y * regionStride) - } - return concat(new Uint8Array([CFW_MSG_BOUNDING_BOX, left / 4, top / 2, boxWidth / 4, boxHeight / 2, - frameId & 255, (frameId >>> 8) & 255]), rle4(region)) -} - -/** Full repaint as independent 64-row mode-3 bands when RLE exceeds uint16. */ -export function buildFullFrameBands(packed: Uint8Array, width: number, height: number, firstId: number): Uint8Array[] { - if (width <= 0 || width > 640 || width % 4 || height <= 0 || height > 480 || height % 2 || packed.length !== width * height / 2) - throw new Error('Invalid framebuffer dimensions') - const bands: Uint8Array[] = [] - let id = firstId - for (let top = 0; top < height; top += 64) { - const rows = Math.min(64, height - top) - bands.push(concat(new Uint8Array([CFW_MSG_BOUNDING_BOX, 0, top / 2, width / 4, rows / 2, id & 255, id >>> 8]), - rle4(packed.subarray(top * width / 2, (top + rows) * width / 2)))) - id = id >= 0xfffe ? 1 : id + 1 - } - return bands -} diff --git a/app/g2/ble-protocol.ts b/app/g2/ble-protocol.ts deleted file mode 100644 index 42c80796..00000000 --- a/app/g2/ble-protocol.ts +++ /dev/null @@ -1,203 +0,0 @@ -import { type RingInput, decodeRingMetadata } from "./ring-input"; -import { type CompassEvent } from '../native/compass-types' -/** G2 wire protocol, ported from g2protocol/BleProtocol.java. No platform APIs. */ -import { OsEventTypeList } from './events' -export const G2_WRITE = '00002760-08c2-11e1-9073-0e8ac72e5401' -export const G2_NOTIFY = '00002760-08c2-11e1-9073-0e8ac72e5402' -export const G2_RENDER_NOTIFY = '00002760-08c2-11e1-9073-0e8ac72e6402' -export const RING_NOTIFY = ['bae80011-4f05-4503-8e65-3af1f7329d1f', 'bae80013-4f05-4503-8e65-3af1f7329d1f'] -export const SID = { auth: 0x80, launch: 1, hub: 0xe0, settings: 9, cfw: 0xf0 } as const -export function concat(...parts: Uint8Array[]): Uint8Array { - const output = new Uint8Array(parts.reduce((n, p) => n + p.length, 0)) - let offset = 0; for (const part of parts) { output.set(part, offset); offset += part.length }; return output -} -function varint(value: number): Uint8Array { - const bytes: number[] = [] - do { const next = value & 127; value >>>= 7; bytes.push(next | (value ? 128 : 0)) } while (value) - return new Uint8Array(bytes) -} -export const integer = (field: number, value: number): Uint8Array => concat(varint(field * 8), varint(value)) -export const bytes = (field: number, value: Uint8Array): Uint8Array => concat(varint(field * 8 + 2), varint(value.length), value) -// Outbound names/text here are fixed ASCII protocol identifiers. -const string = (field: number, value: string): Uint8Array => bytes(field, new Uint8Array(Array.from(value, c => c.charCodeAt(0)))) -const wrap = (command: number, magic: number, field: number, body: Uint8Array) => concat(integer(1, command), integer(2, magic), bytes(field, body)) -export const authentication = (magic: number) => wrap(4, magic, 3, concat(integer(1, 1), integer(2, 4))) -export const prelude = () => wrap(2, 156, 4, bytes(3, bytes(2, bytes(2, concat(integer(1, 0), integer(2, 0)))))) -export const heartbeat = (magic: number) => wrap(12, magic, 14, integer(1, 0)) -export const audioControl = (magic: number, enabled: boolean) => wrap(15, magic, 18, integer(1, enabled ? 1 : 0)) -export const settingsQuery = (magic: number) => wrap(2, magic, 4, integer(1, 1)) -export const shutdown = (magic: number) => wrap(9, magic, 11, integer(1, 1)) -export const framebufferLease = (acquire: boolean) => concat(integer(1, 1), integer(2, 0), bytes(101, new Uint8Array([70, 67, 1, acquire ? 5 : 6, 0, 0]))) -export function createLayout(magic: number): Uint8Array { - const geometry = concat(integer(1, 0), integer(2, 0), integer(3, 576), integer(4, 288)) - const text = concat(geometry, integer(9, 1), string(10, 'dashboard'), integer(11, 1), string(12, ' ')) - return wrap(0, magic, 3, concat(integer(1, 1), bytes(3, text), integer(5, 10000))) -} -export function crc16(data: Uint8Array): number { - let crc = 0xffff - for (const byte of data) { - crc ^= byte << 8 - for (let i = 0; i < 8; i++) crc = ((crc << 1) ^ ((crc & 0x8000) ? 0x1021 : 0)) & 0xffff - } - return crc -} -export function frameMessage(payload: Uint8Array, sid: number, flag: number, sequence: number, maxWrite = 240): Uint8Array[] { - const chunkSize = Math.min(232, Math.floor(maxWrite) - 8) - if (chunkSize < 12) throw new Error('Negotiated BLE write size is too small') - const crc = crc16(payload), withCrc = concat(payload, new Uint8Array([crc & 255, crc >>> 8])) - const count = Math.ceil(withCrc.length / chunkSize) - if (count > 255) throw new Error('Protocol message exceeds the fragment limit') - return Array.from({ length: count }, (_, i) => { - const chunk = withCrc.subarray(i * chunkSize, (i + 1) * chunkSize) - return concat(new Uint8Array([0xaa, 0x21, sequence & 255, chunk.length, count, i + 1, sid, flag]), chunk) - }) -} -export type ProtocolMessage = { sid: number; flag: number; payload: Uint8Array; command: number; magic: number; packet?: Uint8Array } -/** Handles split/coalesced envelopes and reassembles each link/sequence separately. */ -export class MessageReceiver { - private streams = new Map() - private messages = new Map() - clear(): void { this.streams.clear(); this.messages.clear() } - receive(link: string, data: Uint8Array, now = Date.now()): ProtocolMessage[] { - for (const [key, message] of this.messages) if (now - message.seen > 5000) this.messages.delete(key) - let stream = concat(this.streams.get(link) ?? new Uint8Array(), data) - const output: ProtocolMessage[] = [] - while (stream.length >= 8) { - if (stream[0] !== 0xaa || ![0x21, 0x12].includes(stream[1])) { stream = stream.subarray(1); continue } - const length = stream[3], count = stream[4], index = stream[5] - if (stream.length < length + 8) break - const sid = stream[6], flag = stream[7], key = `${link}:${stream[2]}:${sid}:${flag}` - const packet = stream.slice(0, length + 8) - const chunk = stream.slice(8, 8 + length); stream = stream.subarray(length + 8) - if (sid === SID.cfw) { - output.push({ sid, flag, payload: chunk, command: -1, magic: -1, packet }) - continue - } - if (!count || !index || index > count) { this.messages.delete(key); continue } - if (index === 1) this.messages.set(key, { chunks: [], total: count, seen: now, size: 0 }) - const message = this.messages.get(key) - if (!message || message.total !== count || message.chunks.length + 1 !== index) { this.messages.delete(key); continue } - message.chunks.push(chunk); message.size += chunk.length; message.seen = now - if (message.size > 65536) { this.messages.delete(key); continue } - if (index !== count) continue - this.messages.delete(key) - const complete = concat(...message.chunks) - if (complete.length < 2) continue - const payload = complete.subarray(0, -2), crc = complete[complete.length - 2] | (complete[complete.length - 1] << 8) - if (crc16(payload) !== crc) continue - try { output.push({ sid, flag, payload, command: readInteger(payload, 1, -1), magic: readInteger(payload, 2, -1) }) } - catch { /* Malformed notifications cannot satisfy an acknowledgement. */ } - } - this.streams.set(link, stream.slice()) - return output - } -} -function readVarint(data: Uint8Array, offset: number): [number, number] { - let value = 0 - for (let i = 0; i < 5 && offset < data.length; i++) { - const byte = data[offset++]; value += (byte & 127) * 2 ** (i * 7) - if (!(byte & 128)) return [value, offset] - } - throw new Error('Truncated or oversized protobuf varint') -} -function field(data: Uint8Array, number: number): number | Uint8Array | undefined { - let offset = 0 - while (offset < data.length) { - let key: number; [key, offset] = readVarint(data, offset) - const tag = key >>> 3, wire = key & 7 - if (!tag) throw new Error('Invalid protobuf field') - if (wire === 0) { - let value: number; [value, offset] = readVarint(data, offset) - if (tag === number) return value - } else { - let length: number - if (wire === 2) [length, offset] = readVarint(data, offset) - else if (wire === 1) length = 8 - else if (wire === 5) length = 4 - else throw new Error('Unsupported protobuf wire type') - if (offset + length > data.length) throw new Error('Truncated protobuf field') - if (tag === number && wire === 2) return data.subarray(offset, offset + length) - offset += length - } - } - return undefined -} -export function readInteger(data: Uint8Array, number: number, fallback = 0): number { const value = field(data, number); return typeof value === 'number' ? value : fallback } -export function readBytes(data: Uint8Array, number: number): Uint8Array | undefined { const value = field(data, number); return value instanceof Uint8Array ? value : undefined } -export function readString(data: Uint8Array, number: number): string { return Array.from(readBytes(data, number) ?? [], value => String.fromCharCode(value)).join('') } -export function authenticationSucceeded(message: ProtocolMessage, magic: number): boolean { - return message.sid === SID.auth && message.command === 4 && message.magic === magic && readBytes(message.payload, 3)?.length === 0 -} -export type GlassesInput = { ringInput?: RingInput; kind: 'sys-event' | 'list-click' | 'text-click' | 'display-wake' | 'even-ai'; eventType: number; eventSource: number; systemExitReasonCode: number; containerName: string; frameId: number } -export function decodeGlassesInput(message: ProtocolMessage): GlassesInput | null { - if (message.sid !== SID.hub || ![1, 6].includes(message.flag)) return null - const events = readBytes(message.payload, 13); if (!events) return null - for (const [field, kind, typeField] of [[1, 'list-click', 5], [2, 'text-click', 3], [3, 'sys-event', 1]] as const) { - const event = readBytes(events, field) - if (event) return { kind: kind === 'sys-event' && readInteger(event, typeField) === OsEventTypeList.HEAD_UP_EVENT ? 'display-wake' : kind, - eventType: readInteger(event, typeField), eventSource: field === 3 ? readInteger(event, 2) : 0, - ringInput: field === 3 && readInteger(event, 2) === 2 ? decodeRingMetadata(readBytes(event, 100)) : undefined, - systemExitReasonCode: field === 3 ? readInteger(event, 4) : 0, containerName: field === 3 ? '' : readString(event, 2), frameId: 0 } - } - return null -} -export function decodeRingInput(data: Uint8Array): GlassesInput | null { - let eventType: number | undefined - if (data.length === 11 && data[0] === 0 && data[1] === 9 && data[2] === 0x61 && data[3] === 0) - eventType = ({ 0: 9, 1: 0, 2: 3, 4: 1, 5: 2, 8: 10 } as Record)[data[4]] - if (data.length === 3 && data[0] === 255) { - if (data[1] === 3 && data[2] === 32) eventType = 9 - if (data[1] === 4 && data[2] === 1) eventType = 0 - if (data[1] === 4 && data[2] === 2) eventType = 3 - if (data[1] === 5) eventType = data[2] <= 1 ? 2 : 1 - } - return eventType === undefined ? null : { kind: 'sys-event', eventType, eventSource: 2, systemExitReasonCode: 0, containerName: '', frameId: 0 } -} -export function packGray4(gray: Uint8Array, width: number, height: number): Uint8Array { - if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1 || gray.length !== width * height) throw new Error('Invalid display frame') - const stride = Math.ceil(width / 2), packed = new Uint8Array(stride * height) - for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) { - const nibble = Math.min(15, (gray[y * width + x] + 8) >> 4) - packed[y * stride + (x >> 1)] |= nibble << (x % 2 ? 0 : 4) - } - return packed -} -export function rle4(packed: Uint8Array): Uint8Array { - const output = new Uint8Array(packed.length * 2) - const nibble = (i: number) => (packed[i >> 1] >> (i % 2 ? 0 : 4)) & 15 - let used = 0, i = 0 - while (i < packed.length * 2) { - const color = nibble(i); let end = i + 1 - while (end < packed.length * 2 && nibble(end) === color) end++ - let remaining = end - i - while (remaining) { - const count = Math.min(65535, remaining) - if (count <= 15) output[used++] = (count << 4) | color - else { output[used++] = color; if (count <= 255) output[used++] = count - else { output[used++] = 0; output[used++] = count & 255; output[used++] = count >>> 8 } } - remaining -= count - } - i = end - } - return output.slice(0, used) -} - -/** Reference decoder for host tests; iOS uses the shared Kotlin implementation. */ -export function decodeCompassInput(message: ProtocolMessage): CompassEvent | null { - if (message.sid !== 8 || ![1, 6].includes(message.flag)) return null - const command = readInteger(message.payload, 1, -1) - if (command === 16 || command === 17) return { command, headingDegrees: -1 } - if (command !== 15) return null - const compass = readBytes(message.payload, 10) - const headingDegrees = compass ? readInteger(compass, 1, -1) : -1 - if (headingDegrees < 0 || headingDegrees >= 360) return null - const event: CompassEvent = { command, headingDegrees } - let d: Uint8Array | undefined - try { d = readBytes(message.payload, 100) } catch { return event } - if (d?.length === 12 && d[0] === 67 && d[1] === 77 && d[2] === 1 && d[7] === 0 && - (d[3] <= 3 || d[3] === 255) && (d[4] <= 2 || d[4] === 255) && d[5] <= 3) { - event.diagnostics = { magneticAccuracy: d[3] === 255 ? -1 : d[3], magneticAnomalies: d[4] === 255 ? -1 : d[4], - orientationSource: d[5], flags: d[6], sampleTimeMs: new DataView(d.buffer, d.byteOffset + 8, 4).getUint32(0, true) } - } - return event -} diff --git a/app/g2/ble-traffic-counters.ts b/app/g2/ble-traffic-counters.ts deleted file mode 100644 index d37023aa..00000000 --- a/app/g2/ble-traffic-counters.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** Same units as Android FaceclawBleManager: protocol messages, framed write - * bytes accepted by the transport, and fully acknowledged display updates. - * Totals survive reconnects and the setting being switched off. - */ -export class BleTrafficCounters { - private messages = 0 - private bytes = 0 - private frames = 0 - recordWrite(bytes: number): void { this.bytes += bytes } - recordMessage(): void { this.messages++ } - recordDisplayFrame(): void { this.frames++ } - sample(): { messages: number; bytes: number; frames: number } { - return { messages: this.messages, bytes: this.bytes, frames: this.frames } - } -} -// The iOS BLE session and phone UI both run in the main isolate. -export const iosBleTraffic = new BleTrafficCounters() diff --git a/app/g2/brightness-protocol.ts b/app/g2/brightness-protocol.ts deleted file mode 100644 index 79b64d57..00000000 --- a/app/g2/brightness-protocol.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { bytes, concat, integer } from './ble-protocol' - -/** Same G2SettingPackage as Kotlin BleProtocol.buildSetBrightness. */ -export function setBrightness(magic: number, level: number | null): Uint8Array { - const fields = level === null ? integer(1, 1) - : concat(integer(1, 0), integer(2, Math.max(0, Math.min(100, Math.round(level))))) - return concat(integer(1, 1), integer(2, magic), bytes(3, bytes(1, fields))) -} diff --git a/app/g2/cfw-transport.ios.ts b/app/g2/cfw-transport.ios.ts deleted file mode 100644 index 135f31d1..00000000 --- a/app/g2/cfw-transport.ios.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { fromData, toData, nativeArray } from '../native/kotlin-data' -declare const FaceclawKitIosCfwTransport: any, FaceclawKitIosProtocol: any -export const CFW_MAX_MESSAGE = 65535 -export type CfwAck = { nack: boolean; streamId: number; messageId: number; lens: number; size: number; checksum: number } -/** maxWrite is the ATT value limit; Kotlin owns the persistent zlib stream. */ -export class CfwTransport { - private native = FaceclawKitIosCfwTransport.new() - reset(): void { this.native.reset() } - encode(message: Uint8Array, streamId: number, lenses: number, maxWrite: number): Uint8Array[] { - if (message.length > CFW_MAX_MESSAGE || !Number.isInteger(streamId) || streamId < 0 || streamId > 255 || - ![1, 2, 3].includes(lenses) || !Number.isInteger(maxWrite) || maxWrite < 20 || maxWrite > 514) - throw new Error('Invalid CFW stream parameters') - return nativeArray(this.native.encodeDataStreamIdLensesMaxWrite(toData(message), streamId, lenses, maxWrite), fromData) - } -} -const protocol = FaceclawKitIosProtocol.new() -export function parseCfwAcks(packet: Uint8Array): CfwAck[] | null { - const acks = protocol.acksData(toData(packet)) - return acks ? nativeArray(acks, (ack: any) => ({ nack: ack.nack, streamId: ack.streamId, messageId: ack.messageId, - lens: ack.lens, size: ack.size, checksum: ack.checksum })) : null -} diff --git a/app/g2/cfw-transport.ts b/app/g2/cfw-transport.ts deleted file mode 100644 index 8f6dd234..00000000 --- a/app/g2/cfw-transport.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { concat, crc16, SID } from './ble-protocol' - -declare const require: (name: string) => any -/** Mirrors CFW_MESSAGE_MAX in g2flash/patches/message_transport.h. */ -export const CFW_MAX_MESSAGE = 65535 -export type CfwAck = { nack: boolean; streamId: number; messageId: number; lens: number; size: number; checksum: number } -const u16 = (data: Uint8Array, offset: number) => data[offset] | (data[offset + 1] << 8) - -/** Matches Android CfwTransport. maxWrite is the ATT value limit (MTU - 3). */ -export class CfwTransport { - private compressor: any - private resetPending = true - private lenses = 0 - reset(): void { this.compressor = null; this.resetPending = true; this.lenses = 0 } - encode(message: Uint8Array, streamId: number, lenses: number, maxWrite: number): Uint8Array[] { - if (message.length > CFW_MAX_MESSAGE || !Number.isInteger(streamId) || streamId < 0 || streamId > 255 || - ![1, 2, 3].includes(lenses) || !Number.isInteger(maxWrite) || maxWrite < 20 || maxWrite > 514) - throw new Error('Invalid CFW stream parameters') - if (this.lenses !== lenses) this.reset() - if (!this.compressor) this.compressor = new (require('pako').Deflate)() - const chunks: Uint8Array[] = [] - // SYNC_FLUSH emits this record while retaining history for the next one. - this.compressor.onData = (chunk: Uint8Array) => chunks.push(chunk.slice()) - if (!this.compressor.push(message, 2)) throw new Error(this.compressor.msg || 'CFW compression failed') - let body = concat(...chunks), flags = lenses | 4 | (this.resetPending ? 8 : 0) - if (!body.length) flags &= ~4 - if (body.length > CFW_MAX_MESSAGE) { - this.reset(); body = message; flags = lenses | 8 - } else { this.resetPending = false; this.lenses = lenses } - const checksum = crc16(message) - const record = concat(new Uint8Array([flags, body.length & 255, body.length >>> 8, checksum & 255, checksum >>> 8]), body) - const capacity = Math.min(252, maxWrite - 11), packets: Uint8Array[] = [] - for (let offset = 0, index = 0; offset < record.length; offset += capacity, index++) { - const body = concat(new Uint8Array([lenses | (offset === 0 ? 0x80 : 0) | - (offset + capacity >= record.length ? 0x40 : 0)]), record.subarray(offset, offset + capacity)) - const crc = crc16(body) - packets.push(concat(new Uint8Array([0xaa, 0x21, (streamId + index) & 255, body.length + 2, 1, 1, SID.cfw, 0]), - body, new Uint8Array([crc & 255, crc >>> 8]))) - } - return packets - } -} - -/** Validate the entire primary + redundant-ACK packet before applying any ACK. */ -export function parseCfwAcks(packet: Uint8Array): CfwAck[] | null { - const n = packet.length - if (n < 19 || n > 40 || (n - 19) % 7 || packet[0] !== 0xaa || packet[1] !== 0x12 || - packet[3] !== n - 8 || packet[4] !== 1 || packet[5] !== 1 || packet[6] !== SID.cfw || packet[7] !== 0 || - ![1, 3].includes(packet[8]) || ![1, 2].includes(packet[12]) || (packet[8] === 3 && n !== 19) || - crc16(packet.subarray(8, -2)) !== u16(packet, n - 2)) return null - const acks = [{ nack: packet[8] === 3, streamId: packet[9], messageId: u16(packet, 10), - lens: packet[12], size: u16(packet, 13), checksum: u16(packet, 15) }] - for (let offset = 17; offset < n - 2; offset += 7) - acks.push({ nack: false, streamId: packet[offset], messageId: u16(packet, offset + 1), lens: packet[12], - size: u16(packet, offset + 3), checksum: u16(packet, offset + 5) }) - return acks -} diff --git a/app/g2/draw-protocol.ts b/app/g2/draw-protocol.ts deleted file mode 100644 index 4f5c3de1..00000000 --- a/app/g2/draw-protocol.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { CFW_MSG_BOUNDING_BOX, CFW_MSG_DRAW_CALLS, CFW_MSG_FULL_FRAME, CFW_MSG_MULTI_SEGMENT, CFW_MSG_TYPE_MASK } from "./cfw-message-type"; -/** Adapter for raster-only senders; optimized legacy layouts remain internal to the phone. */ -export function drawMessages(payload: Uint8Array, width = 640, height = 480): Uint8Array[] { - const word = (v: number) => [v & 255, (v >>> 8) & 255] - const mode = payload[0] & CFW_MSG_TYPE_MASK - let calls: Uint8Array[] - if (mode === CFW_MSG_MULTI_SEGMENT) { - const output: Uint8Array[] = []; let p=2 - for(let i=0;i new Uint8Array([CFW_MSG_DRAW_CALLS,1,0,...word(call.length),...call])) -} diff --git a/app/g2/glasses-session.ts b/app/g2/glasses-session.ts deleted file mode 100644 index fce88f76..00000000 --- a/app/g2/glasses-session.ts +++ /dev/null @@ -1,645 +0,0 @@ -import { CFW_MSG_CLEANUP, CFW_MSG_COMPASS, CFW_MSG_EVICT_RESOURCE, CFW_MSG_FULL_FRAME, CFW_MSG_PRESENT } from "./cfw-message-type"; -import { drawMessages } from './draw-protocol' -import { setBrightness } from './brightness-protocol' -import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client' -import { type CompassEvent } from '../native/compass-types' -import * as protocol from './ble-protocol' -import { iosBleTraffic } from './ble-traffic-counters' -import { buildBoundingBoxPayload, buildFullFrameBands } from './ble-image-optimizer' -import { CfwTransport, CFW_MAX_MESSAGE, parseCfwAcks } from './cfw-transport' -import { hasCompatibleFirmware, firmwareIncompatibilityMessage, REQUIRED_FACECLAW_FIRMWARE_VERSION } from './firmware-compat' -import { hexToBytes } from '../util/hex-util' -import { deviceAddressError } from './ios-peripheral-identity' -import { decodeWearState, enableWearDetection, queryWearState } from './wear-protocol' -import type { SessionTexturePlanner, TextureFrame } from './texture-planner' - -declare function setTimeout(callback: () => void, ms: number): number -declare function clearTimeout(id: number): void -export type SessionAddresses = { left: string; right: string; ring: string } -export type TransportEvent = { kind: string; identifier?: string; characteristic?: string; data?: string; message?: string; state?: number; authorized?: boolean } -export interface SessionTransport { - onEvent(listener: (event: TransportEvent) => void): () => void - resolveDevices(addresses: SessionAddresses): Promise> - connect(identifier: string, requiresANCS?: boolean): Promise<{ characteristics: string[]; maxWrite: number }> - subscribe(identifier: string, characteristic: string): Promise - write(identifier: string, characteristic: string, bytes: Uint8Array): Promise - disconnect(identifier: string): void - stopScan(): void -} -export type SessionState = { phase: 'disconnected' | 'connecting' | 'connected' | 'retrying' | 'disconnecting' | 'error'; - status: string; battery: number | null; charging: boolean | null; ring: boolean; frames: number; capabilities: string; leftVersion: string; rightVersion: string } -type PendingAck = { resolve: (message: protocol.ProtocolMessage) => void; reject: (error: Error) => void; - timer: number | null; command: number; label: string } -class AckTimeout extends Error {} -// Match Android ConnectionOptions.WINDOW_SIZE. This bounds complete image -// messages queued for writing or awaiting ACK, not individual BLE packets. -const DISPLAY_WINDOW_SIZE = 3 -type CfwPending = { payload: Uint8Array; checksum: number; role: string; magic: number; ackLenses: number; retries: number; - retryPending: boolean; deadline: number; resolve: () => void; reject: (error: Error) => void } -type DisplayFrame = { packed: Uint8Array; commands: Uint8Array[]; offset: number; pending: number } - -/** G2 session independent of the phone OS. Images go to L, control to R, as on Android. */ -export class GlassesSession { - state: SessionState = { phase: 'disconnected', status: 'Preview only', battery: null, charging: null, ring: false, - frames: 0, capabilities: '', leftVersion: '', rightVersion: '' } - readonly notifications: AncsClient - private generation = 0 - private ids: Record = {} - private limits: Record = {} - private cfwPending: CfwPending[] = [] - private cfwTransports = new Map() - private cfwTimer: number | null = null - private pending = new Map() - private receiver = new protocol.MessageReceiver() - private writes = new Map>() - private magic = 100 - private sequence = 0x40 - private timer: number | null = null - private retryTimer: number | null = null - private ringRetryTimer: number | null = null - private ringRetryCount = 0 - private ringConnecting = false - private retryCount = 0 - private wanted = false - private addresses: SessionAddresses | null = null - private latest: Uint8Array | null = null - private latestTextures: TextureFrame | null = null - private displayed: Uint8Array | null = null - private lastEnqueued: Uint8Array | null = null - // Match Android: advance only for emitted deltas, skipping 0 / 0xffff. - private nextImageFrameId = 1 - private displayFrames: DisplayFrame[] = [] - private displaySending: DisplayFrame | null = null - private displayInFlight = 0 - private pumping = false - private lastHeartbeat = 0 - private lastLease = 0 - private lastSettings = 0 - private charging = false - private layoutCreated = false - private off: () => void - private stopping: Promise | null = null - private audioListener: ((packet: Uint8Array) => void) | null = null - private microphoneToken = 0 - private microphoneWork: Promise = Promise.resolve() - private microphoneEnabled = false - private compassWanted = false - private compassSent: boolean | null = null - private compassStopping = false - private compassWork: Promise = Promise.resolve() - constructor(private readonly transport: SessionTransport, - private readonly onState: (state: SessionState) => void, - private readonly onInput: (input: protocol.GlassesInput) => void, - private readonly log: (message: string) => void = () => {}, - private readonly onActivity: () => void = () => {}, - private readonly onCompass: (event: CompassEvent) => void = () => {}, - private readonly onWearState: (wearing: boolean) => void = () => {}, - onNotificationsChanged: (key?: string, popup?: boolean) => void = () => {}, - private readonly textures?: SessionTexturePlanner) { - this.notifications = new AncsClient(packet => this.writePackets('right', () => [packet]), onNotificationsChanged, message => this.log('ANCS: ' + message)) - this.off = transport.onEvent(event => this.receive(event)) - } - private update(phase: SessionState['phase'], status: string): void { - this.state = { ...this.state, phase, status }; this.log(status); this.onState({ ...this.state }) - } - async start(addresses: SessionAddresses, retry = false): Promise { - if (['connecting', 'connected', 'disconnecting'].includes(this.state.phase)) return - const invalid = deviceAddressError(addresses) - if (invalid) { this.update('error', invalid); return } - this.addresses = { ...addresses }; this.wanted = true; this.compassStopping = false - if (!retry) this.retryCount = 0 - const generation = ++this.generation - this.state = { ...this.state, capabilities: '', leftVersion: '', rightVersion: '', battery: null, charging: null, ring: false } - this.charging = false - this.update('connecting', 'Finding configured devices…') - try { - const ids = await this.transport.resolveDevices(addresses); this.check(generation) - this.ids = ids - for (const role of ['right', 'left']) { - this.update('connecting', `Connecting ${role} arm…`) - const details = await this.transport.connect(ids[role], role === 'right'); this.check(generation) - this.limits[role] = details.maxWrite - if (!details.characteristics.includes(protocol.G2_WRITE) || !details.characteristics.includes(protocol.G2_NOTIFY)) throw new Error(`${role} arm is missing G2 communication characteristics.`) - await this.transport.subscribe(ids[role], protocol.G2_NOTIFY); this.check(generation) - } - this.update('connecting', 'Authenticating… Accept pairing if iOS asks.') - await Promise.all(['right', 'left'].map(async role => { - try { - const answer = await this.request(role, protocol.SID.auth, protocol.authentication, 'Security authentication', 30_000, 0) - if (!protocol.authenticationSucceeded(answer, answer.magic)) throw new Error(`${role} arm rejected authentication.`) - } catch (error) { - if (!(error instanceof AckTimeout)) throw error - // Older CFW may not implement the reply. A settings response below - // still has to prove we have a working, compatible session. - this.log(`${role} authentication unconfirmed; checking firmware response`) - } - })) - this.check(generation) - this.update('connecting', 'Checking glasses firmware…') - const settings = await this.request('right', protocol.SID.settings, protocol.settingsQuery, 'Settings query') - this.applySettings(settings) - const firmware = { leftVersion: this.state.leftVersion, rightVersion: this.state.rightVersion, extension: this.state.capabilities } - if (!hasCompatibleFirmware(firmware)) - throw new Error((firmwareIncompatibilityMessage(firmware) || `The glasses must report Faceclaw firmware revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION} or newer.`) + ' Use Devices → Check firmware to install it.') - this.update('connecting', 'Starting glasses display…') - await this.request('right', protocol.SID.launch, () => protocol.prelude(), 'App launch', 3500, 0x20, 156) - await this.lease(true) - await this.request('right', protocol.SID.hub, protocol.createLayout, 'Create display layout') - this.check(generation); this.layoutCreated = true - await this.enableWearDetectionAndRequestState(); this.check(generation) - this.lastHeartbeat = this.lastLease = this.lastSettings = Date.now() - this.displayed = null; this.retryCount = 0 - this.update('connected', 'Glasses connected') - if (/^Faceclaw\/(\d+)/.test(this.state.capabilities) && Number(this.state.capabilities.split('/')[1]) >= ANCS_FIRMWARE_VERSION) - this.notifications.start((Date.now() ^ Math.floor(Math.random()*0xffffffff)) >>> 0, this.limits.right) - else this.notifications.stop(`Update glasses to Faceclaw firmware ${ANCS_FIRMWARE_VERSION} or newer for iPhone notifications.`) - await this.syncCompass(); this.check(generation) - this.schedule() - if (addresses.ring && ids.ring) await this.connectRing(generation) - else if (addresses.ring) this.update('connected', 'Glasses connected; configured ring was not found') - } catch (error) { - if (generation !== this.generation) return - this.fail(error, retry || error instanceof AckTimeout) - } - } - private async connectRing(generation: number): Promise { - if (this.ringConnecting || generation !== this.generation || this.state.phase !== 'connected' || !this.ids.ring) return - this.ringConnecting = true - const identifier = this.ids.ring - try { - const ring = await this.transport.connect(identifier); this.check(generation) - this.log(`R1 services discovered: ${ring.characteristics.join(', ')}`) - const notifications = protocol.RING_NOTIFY.filter(uuid => ring.characteristics.includes(uuid)) - if (!notifications.length) throw new Error('No R1 gesture notifications found') - let subscribed = 0 - for (const uuid of notifications) { - this.log(`Subscribing R1 ${uuid}`) - try { await this.transport.subscribe(identifier, uuid); this.check(generation); subscribed++; this.log(`R1 subscribed ${uuid}`) } - catch (error) { this.check(generation); this.log(`R1 channel unavailable ${uuid}: ${this.message(error)}`) } - } - if (!subscribed) throw new Error('Neither R1 notification channel could be subscribed') - this.check(generation); this.state.ring = true; this.ringRetryCount = 0 - this.update('connected', 'Glasses and ring connected') - } catch (error) { - if (generation !== this.generation) return - this.state.ring = false - this.transport.disconnect(identifier) - this.update('connected', `Glasses connected; ring unavailable: ${this.message(error)}`) - } finally { - if (generation === this.generation) { - this.ringConnecting = false - if (!this.state.ring) this.scheduleRingRetry() - } - } - } - private scheduleRingRetry(): void { - if (!this.wanted || this.state.phase !== 'connected' || !this.ids.ring || this.ringConnecting || this.ringRetryTimer !== null || this.ringRetryCount >= 5) return - const generation = this.generation, delay = Math.min(30_000, 2000 * 2 ** this.ringRetryCount++) - this.log(`Retrying ring in ${delay / 1000}s`) - this.ringRetryTimer = setTimeout(() => { - this.ringRetryTimer = null - if (generation === this.generation) void this.connectRing(generation) - }, delay) - } - private check(generation: number): void { if (generation !== this.generation) throw new Error('Connection cancelled') } - private nextMagic(): number { - for (let i = 0; i < 156; i++) { - const magic = this.magic; this.magic = this.magic === 255 ? 100 : this.magic + 1 - if (magic !== 156 && !this.cfwPending.some(item => item.magic === magic) && ![...this.pending.keys()].some(key => key.endsWith(`:${magic}`))) return magic - } - throw new Error('All message identifiers are in use') - } - private request(role: string, sid: number, build: (magic: number) => Uint8Array, label: string, - timeout = 3500, flag = 0x20, fixedMagic?: number): Promise { - const magic = fixedMagic ?? this.nextMagic(), payload = build(magic), key = `${sid}:${magic}` - this.log(`TX ${label} ${role} sid=${sid.toString(16)} magic=${magic}`) - const generation = this.generation - return new Promise((resolve, reject) => { - const pending: PendingAck = { resolve, reject, timer: null, command: protocol.readInteger(payload, 1, -1), label } - this.pending.set(key, pending) - this.send(role, sid, flag, payload).then(() => { - if (this.pending.get(key) !== pending || generation !== this.generation) return - pending.timer = setTimeout(() => { - this.pending.delete(key); reject(new AckTimeout(`${label} was not acknowledged by the glasses.`)) - }, timeout) - }).catch(error => { - if (this.pending.get(key) !== pending) return - this.pending.delete(key); if (pending.timer) clearTimeout(pending.timer); reject(error) - }) - }) - } - private send(role: string, sid: number, flag: number, payload: Uint8Array): Promise { - return this.writePackets(role, () => protocol.frameMessage(payload, sid, flag, this.sequence++, this.limits[role])) - } - private writePackets(role: string, build: () => Uint8Array[], current = () => true): Promise { - const identifier = this.ids[role], generation = this.generation - if (!identifier) return Promise.reject(new Error(`No ${role} device connected`)) - const previous = this.writes.get(identifier) ?? Promise.resolve() - // A failed write poisons this link's queue until reset: do not transmit - // later fragments after a hole in the image stream. - const work = previous.then(async () => { - this.check(generation) - if (!current()) return - for (const frame of build()) { - this.check(generation) - if (!current()) return - await this.transport.write(identifier, protocol.G2_WRITE, frame) - iosBleTraffic.recordWrite(frame.length) - } - iosBleTraffic.recordMessage() - }) - // A whole message owns the write queue; heartbeat packets cannot split an image message. - this.writes.set(identifier, work) - return work - } - private lease(acquire: boolean): Promise { - return Promise.all(['right', 'left'].map(role => this.send(role, protocol.SID.settings, 0x20, protocol.framebufferLease(acquire)))) - } - private requestCfw(role: string, payload: Uint8Array): Promise { - if (payload.length > CFW_MAX_MESSAGE - 16) return Promise.reject(new Error('CFW message too large')) - return new Promise((resolve, reject) => { - const item: CfwPending = { role, payload, checksum: protocol.crc16(payload), magic: this.nextMagic(), ackLenses: 0, retries: 0, - retryPending: false, deadline: 0, resolve, reject } - this.cfwPending.push(item) - this.sendCfw(item) - }) - } - private sendCfw(item: CfwPending): void { - const generation = this.generation, magic = item.magic - const current = () => generation === this.generation && item.magic === magic && this.cfwPending.includes(item) - void this.writePackets(item.role, () => { - let transport = this.cfwTransports.get(item.role) - if (!transport) { transport = new CfwTransport(); this.cfwTransports.set(item.role, transport) } - if (item.retries) transport.reset() - return transport.encode(item.payload, magic, 3, this.limits[item.role]) - }, current).then(() => { - if (!current()) return - item.deadline = Date.now() + 500 - this.scheduleCfwRecovery() - }).catch(error => { if (current()) this.fail(error, true) }) - } - private receiveCfw(identifier: string, packet: Uint8Array): void { - const acks = parseCfwAcks(packet) - if (!acks) return - for (const ack of acks) { - // The ingress temple relays the other lens's result on the SAME link. - const item = this.cfwPending.find(p => this.ids[p.role] === identifier && p.magic === ack.streamId) - if (!item || ack.messageId !== 0) continue - if (ack.nack) item.retryPending = true - else if (ack.size === item.payload.length && ack.checksum === item.checksum) item.ackLenses |= ack.lens - this.log(`CFW ${ack.nack ? 'NACK' : 'ACK'} stream=${ack.streamId} lens=${ack.lens} size=${ack.size} crc=${ack.checksum} confirmed=${item.ackLenses}`) - } - while (this.cfwPending.length) { - const head = this.cfwPending[0] - if (head.retryPending || head.ackLenses !== 3) break - this.cfwPending.shift(); head.resolve() - } - this.scheduleCfwRecovery() - } - private scheduleCfwRecovery(): void { - if (this.cfwTimer !== null) clearTimeout(this.cfwTimer) - this.cfwTimer = null - let deadline = Infinity - for (const item of this.cfwPending) { - if (item.retryPending) deadline = 0 - else if (item.ackLenses !== 3 && item.deadline) deadline = Math.min(deadline, item.deadline) - } - if (deadline === Infinity) return - this.cfwTimer = setTimeout(() => { - this.cfwTimer = null - this.recoverCfw() - }, Math.max(0, deadline - Date.now())) - } - private recoverCfw(): void { - if (!this.cfwPending.some(p => p.retryPending || (p.ackLenses !== 3 && p.deadline > 0 && p.deadline <= Date.now()))) { - this.scheduleCfwRecovery(); return - } - if (this.cfwPending.some(p => p.retries >= 3)) { this.fail(new Error('CFW recovery retry limit'), true); return } - this.log(`CFW recovery: replay ${this.cfwPending.length} unresolved messages`) - // Go back to the oldest unresolved command, including any ACKed tail. - // Fresh stream IDs reject stale ACKs; each replay resets compression history. - for (const item of this.cfwPending) { - item.magic = this.nextMagic(); item.retries++; item.ackLenses = 0 - item.deadline = 0; item.retryPending = false - } - for (const item of this.cfwPending) this.sendCfw(item) - } - private receive(event: TransportEvent): void { - if (!Object.values(this.ids).includes(event.identifier ?? '')) return - if (event.kind === 'ancs-authorization' && event.identifier === this.ids.right) { - if (event.authorized === false) { - const active = this.notifications.state !== 'disconnected' - const command = this.notifications.stopCommand() - this.notifications.stop('Enable Share System Notifications in iPhone Settings → Bluetooth → right lens.') - if (active && this.state.phase === 'connected') void this.writePackets('right', () => [command]).catch(() => {}) - } else if (this.state.phase === 'connected' && /^Faceclaw\/(\d+)/.test(this.state.capabilities) && Number(this.state.capabilities.split('/')[1]) >= ANCS_FIRMWARE_VERSION) { - this.notifications.start((Date.now() ^ Math.floor(Math.random()*0xffffffff)) >>> 0, this.limits.right) - } - return - } - if (event.kind === 'disconnected') { - if (event.identifier === this.ids.ring) { - this.state.ring = false - if (this.state.phase === 'connected') { - this.update('connected', `Glasses connected; ring disconnected${event.message ? ': ' + event.message : ''}`) - this.scheduleRingRetry() - } - } else if (['connected', 'connecting'].includes(this.state.phase)) this.fail(new Error(event.message || 'Glasses disconnected'), true) - return - } - if (event.kind !== 'notification' || !event.data) return - if (event.characteristic === protocol.G2_RENDER_NOTIFY && event.identifier !== this.ids.ring) { - if (this.audioListener && this.state.phase === 'connected') { - this.audioListener(hexToBytes(event.data)) - this.onActivity(); this.wake() - } - return - } - const ring = event.identifier === this.ids.ring - if (ring ? !protocol.RING_NOTIFY.includes(event.characteristic ?? '') : event.characteristic !== protocol.G2_NOTIFY) return - try { - const data = hexToBytes(event.data) - if (ring) { - const input = protocol.decodeRingInput(data) - if (input) { this.log(`Direct R1 gesture ${input.eventType}`); this.onInput(input) } - return - } - if (event.identifier === this.ids.right && this.notifications.receive(data)) return - for (const message of this.receiver.receive(event.identifier!, data)) { - this.log(`RX ${event.identifier === this.ids.left ? 'L' : 'R'} sid=${message.sid.toString(16)} flag=${message.flag.toString(16)} cmd=${message.command} magic=${message.magic}`) - if (message.sid === protocol.SID.cfw) { - this.receiveCfw(event.identifier!, message.packet!) - continue - } - if (![1, 6].includes(message.flag)) { - // A master arm can relay the other arm's ACK; magic is allocated - // across BOTH links, matching Android's communicator. - const key = `${message.sid}:${message.magic}`, pending = this.pending.get(key) - if (pending) { - this.pending.delete(key); if (pending.timer) clearTimeout(pending.timer) - pending.resolve(message) - } - } - if (message.sid === protocol.SID.settings) this.applySettings(message) - const wearing = decodeWearState(message) - if (wearing !== null) this.onWearState(wearing) - if (event.identifier === this.ids.right) { - if (this.state.phase === 'connected') { - const compass = protocol.decodeCompassInput(message) - if (compass) this.onCompass(compass) - } - const input = protocol.decodeGlassesInput(message) - if (input) { - if (input.kind === 'sys-event' && [5, 6, 7].includes(input.eventType) && this.state.phase === 'connected') { - // Respect an explicit glasses-side exit; the user can reconnect. - void this.stop(); continue - } - this.onInput(input) - } - } - } - } catch (error) { this.log(`Ignored malformed BLE notification: ${this.message(error)}`) } - finally { - // CoreBluetooth can wake a suspended iOS process for a notification. - // Service wall-clock deadlines now, without waiting for a suspended timer. - if (this.state.phase === 'connected') { this.onActivity(); this.wake() } - } - } - private applySettings(message: protocol.ProtocolMessage): void { - const values = protocol.readBytes(message.payload, 4) - const capabilities = protocol.readString(message.payload, 100) - if (capabilities) this.state.capabilities = capabilities - if (values) { - const left = protocol.readString(values, 5), right = protocol.readString(values, 6) - if (left) this.state.leftVersion = left - if (right) this.state.rightVersion = right - const battery = protocol.readInteger(values, 12, -1), charging = protocol.readInteger(values, 13, -1) - if (battery >= 0 && battery <= 100) this.state.battery = battery - if (charging >= 0) this.state.charging = this.charging = charging > 0 - } - this.onState({ ...this.state }) - } - async enableWearDetectionAndRequestState(): Promise { - const generation = this.generation - // Like Android, a missing enable ACK must not suppress the current-state query. - try { await this.request('right', protocol.SID.settings, enableWearDetection, 'Enable wear detection') } - catch (error) { if (!(error instanceof AckTimeout)) throw error; this.log(this.message(error)) } - this.check(generation) - await this.send('right', protocol.SID.settings, 0x20, queryWearState()) - this.check(generation) - await this.send('left', protocol.SID.settings, 0x20, queryWearState()) - } - async setBrightness(level: number | null): Promise { - if (this.state.phase !== 'connected') return - await this.request('right', protocol.SID.settings, magic => setBrightness(magic, level), 'Brightness') - } - setFrame(gray: Uint8Array, textures?: TextureFrame): void { - if (this.state.phase !== 'connected') return - this.latest = protocol.packGray4(gray, 640, 480) - this.latestTextures = textures ?? null - this.schedule(0) - } - /** Same mode-5 kind-4 sequencer payload and acknowledged image path as Android. */ - async playBuzzerSequence(payload: Uint8Array): Promise { - if (this.state.phase !== 'connected' || !this.layoutCreated || payload.length < 3) return - const generation = this.generation - try { await this.requestCfw('left', new Uint8Array(payload)) } - catch (error) { if (generation === this.generation) this.fail(error, true) } - } - /** Serialize mic enable/disable, including a release while enable awaits ACK. */ - setMicrophone(enabled: boolean, listener?: (packet: Uint8Array) => void): Promise { - const token = ++this.microphoneToken, generation = this.generation - this.audioListener = enabled ? listener ?? null : null - const current = () => generation === this.generation && token === this.microphoneToken - const work = this.microphoneWork.catch(() => {}).then(async () => { - if (!current()) return - if (this.state.phase !== 'connected') { - if (enabled) throw new Error('Connect the glasses before starting voice input.') - return - } - if (enabled) { - await Promise.all(['left', 'right'].map(role => this.transport.subscribe(this.ids[role], protocol.G2_RENDER_NOTIFY))) - if (!current()) return - } - await this.request('right', protocol.SID.hub, magic => protocol.audioControl(magic, enabled), enabled ? 'Microphone enable' : 'Microphone disable') - if (current()) { this.microphoneEnabled = enabled; this.log(`Glasses microphone ${enabled ? 'enabled' : 'disabled'}`) } - }).catch(error => { - if (current()) { this.audioListener = null; this.microphoneEnabled = false } - throw error - }) - this.microphoneWork = work - return work - } - setCompassEnabled(enabled: boolean): void { - this.compassWanted = enabled - void this.syncCompass() - } - /** Serialize changes so a release cannot overtake an unacknowledged enable. */ - private syncCompass(): Promise { - const generation = this.generation - const work = this.compassWork.then(async () => { - if (generation !== this.generation || this.state.phase !== 'connected') return - const enabled = !this.compassStopping && this.compassWanted - if (this.compassSent === enabled) return - // Same CFW mode 10, 100 ms report interval and zero minimum change as Android. - await this.requestCfw('left', new Uint8Array(enabled ? [CFW_MSG_COMPASS, 2, 100, 0, 0, 0] : [CFW_MSG_COMPASS, 0])) - if (generation === this.generation) this.compassSent = enabled - }).catch(error => { if (generation === this.generation) this.fail(error, true) }) - this.compassWork = work - return work - } - wake(): void { - if (this.timer !== null) { clearTimeout(this.timer); this.timer = null } - void this.pump() - } - private schedule(delay = 1000): void { - if (delay === 0 && this.timer !== null) { clearTimeout(this.timer); this.timer = null } - if (this.timer !== null || this.pumping || this.state.phase !== 'connected') return - this.timer = setTimeout(() => { this.timer = null; void this.pump() }, delay) - } - private canSendDisplay(): boolean { - if (this.displaySending?.commands[this.displaySending.offset][0] === CFW_MSG_EVICT_RESOURCE && this.cfwPending.length) return false - // Also bound completed frames retained behind a missing/out-of-order ACK. - return this.displayInFlight < DISPLAY_WINDOW_SIZE && !!(this.displaySending || - (this.latest && !this.charging && this.displayFrames.length < DISPLAY_WINDOW_SIZE)) - } - private fillDisplayWindow(generation: number): void { - while (this.canSendDisplay()) { - if (!this.displaySending) { - const packed = this.latest!; this.latest = null - const textureFrame = this.latestTextures; this.latestTextures = null - // Compare with the last enqueued image, not the last ACKed one. In an - // A -> B -> A sequence, B may still be in flight when A is requested. - if (!textureFrame && this.lastEnqueued && packed.every((value, i) => value === this.lastEnqueued![i])) continue - const texturePlan = textureFrame ? this.textures?.plan(this.lastEnqueued, packed, textureFrame, this.nextImageFrameId) : null - let commands: Uint8Array[] - if (texturePlan) { - // Resource commands participate in the same ordered, acknowledged command window as - // the image. Coalescing only happens before planning mutates residency. - commands = [...texturePlan.resourceCommands, texturePlan.payload] - this.nextImageFrameId = texturePlan.nextFid - this.log(`Display textures (${texturePlan.resourceCommands.length} resource commands, cache=${texturePlan.usedBytes}B)`) - } else { - const delta = buildBoundingBoxPayload(this.lastEnqueued, packed, 640, 480, this.nextImageFrameId) - const payload = delta ?? protocol.concat(new Uint8Array([CFW_MSG_FULL_FRAME]), protocol.rle4(packed)) - if (delta) this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 - commands = payload.length <= CFW_MAX_MESSAGE - 16 ? [payload] : buildFullFrameBands(packed, 640, 480, this.nextImageFrameId) - if (payload.length > CFW_MAX_MESSAGE - 16) for (const _ of commands) - this.nextImageFrameId = this.nextImageFrameId >= 0xfffe ? 1 : this.nextImageFrameId + 1 - commands = [...commands.flatMap(command => drawMessages(command)), new Uint8Array([CFW_MSG_PRESENT])] - this.log(`Display ${delta ? 'bbox' : 'full'} (${commands.length} CFW commands)`) - } - this.displaySending = { packed, commands, offset: 0, pending: 0 } - this.displayFrames.push(this.displaySending); this.lastEnqueued = packed - } - const frame = this.displaySending - // Drain earlier commands before evicting: recovery may replay any unresolved draw/upload. - if (frame.commands[frame.offset][0] === CFW_MSG_EVICT_RESOURCE && this.cfwPending.length) return - const payload = frame.commands[frame.offset++] - frame.pending++; this.displayInFlight++ - if (frame.offset >= frame.commands.length) this.displaySending = null - // Writes serialize on L while up to three complete commands await their - // two-lens ACKs. Retire commands in submission order. - void this.requestCfw('left', payload).then(() => { - if (generation !== this.generation) return - frame.pending--; this.displayInFlight--; this.lastHeartbeat = Date.now() - // Retire in submission order even if relayed ACKs arrive out of order. - // A frame counts only after every command has been acknowledged. - while (this.displayFrames.length) { - const completed = this.displayFrames[0] - if (completed.offset < completed.commands.length || completed.pending) break - this.displayFrames.shift(); this.displayed = completed.packed - this.state.frames++; iosBleTraffic.recordDisplayFrame(); this.onState({ ...this.state }) - this.log(`Display frame ${this.state.frames} acknowledged (${completed.commands.length} commands)`) - } - this.wake() - }).catch(error => { if (generation === this.generation) this.fail(error, true) }) - } - } - private async pump(): Promise { - if (this.pumping || this.state.phase !== 'connected') return - this.pumping = true; const generation = this.generation - try { - const now = Date.now() - // Firmware frees resources when its 90-second framebuffer lease expires. - // After a long iOS suspension, reconnect rather than replaying pending - // draws against unknown memory. Leave a margin for the two arm writes. - if (now - this.lastLease >= 80_000) throw new Error('Display lease lapsed; restarting session') - if (now - this.lastHeartbeat >= 4000) { - const gap = now - this.lastHeartbeat - await this.request('right', protocol.SID.hub, protocol.heartbeat, 'Heartbeat', 1500); this.lastHeartbeat = Date.now() - this.log(`Heartbeat acknowledged (gap ${gap}ms)`) - } - if (now - this.lastLease >= 45_000) { await this.lease(true); this.lastLease = Date.now() } - if (now - this.lastSettings >= (this.charging ? 30_000 : 300_000)) { - const settings = await this.request('right', protocol.SID.settings, protocol.settingsQuery, 'Battery query') - this.applySettings(settings); this.lastSettings = Date.now() - } - this.check(generation) - this.fillDisplayWindow(generation) - } catch (error) { if (generation === this.generation) this.fail(error, true) } - finally { if (generation === this.generation) { this.pumping = false; this.schedule(this.canSendDisplay() ? 0 : 1000) } } - } - private reset(): void { - this.notifications.stop() - ++this.generation - this.compassSent = null; this.compassWork = Promise.resolve() - ++this.microphoneToken; this.audioListener = null; this.microphoneEnabled = false - if (this.timer !== null) clearTimeout(this.timer) - if (this.retryTimer !== null) clearTimeout(this.retryTimer) - if (this.ringRetryTimer !== null) clearTimeout(this.ringRetryTimer) - this.ringRetryTimer = null; this.ringConnecting = false; this.ringRetryCount = 0 - this.timer = this.retryTimer = null; this.pumping = false - const pending = [...this.pending.values()]; this.pending.clear() - for (const request of pending) { if (request.timer) clearTimeout(request.timer); request.reject(new Error('Connection ended')) } - if (this.cfwTimer !== null) clearTimeout(this.cfwTimer) - this.cfwTimer = null - const custom = this.cfwPending; this.cfwPending = [] - for (const item of custom) item.reject(new Error('Connection ended')) - this.cfwTransports.clear() - this.receiver.clear(); this.writes.clear(); this.latest = this.displayed = null - this.latestTextures = null; this.textures?.reset() - this.lastEnqueued = null; this.displayFrames = []; this.displaySending = null; this.displayInFlight = 0 - } - private closeLinks(): void { - const ids = this.ids; this.ids = {}; this.limits = {} - for (const identifier of Object.values(ids)) this.transport.disconnect(identifier) - this.transport.stopScan(); this.layoutCreated = false; this.state.ring = false - } - private fail(error: unknown, retry: boolean): void { - const message = this.message(error); this.reset(); this.closeLinks() - if (retry && this.wanted && this.addresses && this.retryCount < 5) { - const delay = Math.min(30_000, 2000 * 2 ** this.retryCount++) - this.update('retrying', `${message} Retrying in ${delay / 1000}s…`) - this.retryTimer = setTimeout(() => { this.retryTimer = null; if (this.wanted && this.addresses) void this.start(this.addresses, true) }, delay) - } else { this.wanted = false; this.update('error', message) } - } - stop(): Promise { - if (this.stopping) return this.stopping - this.stopping = this.stopInternal().finally(() => { this.stopping = null }) - return this.stopping - } - private async stopInternal(): Promise { - this.wanted = false - this.compassStopping = true - await this.syncCompass() - // Stop mic capture before ending the display session. Late enable ACKs - // cannot leave a microphone streaming after an explicit Disconnect. - if (this.audioListener || this.microphoneEnabled) { - try { await this.setMicrophone(false) } catch (error) { this.log(`Microphone cleanup: ${this.message(error)}`) } - } - if (this.notifications.state !== 'disconnected') { - try { await this.writePackets('right', () => [this.notifications.stopCommand()]) } catch {} - } - const cleanup = this.layoutCreated && this.state.phase === 'connected' - this.update('disconnecting', 'Disconnecting…'); this.reset() - try { - if (cleanup) { - await this.requestCfw('left', new Uint8Array([CFW_MSG_CLEANUP])) - } - } catch (error) { this.log(`Disconnect cleanup: ${this.message(error)}`) } - finally { this.reset(); this.closeLinks(); this.update('disconnected', 'Preview only') } - } - dispose(): void { void this.stop().finally(() => this.off()) } - private message(error: unknown): string { return error instanceof Error ? error.message : String(error) } -} diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts index 644723a8..cd5b4b82 100644 --- a/app/g2/ios-preview-controller.ts +++ b/app/g2/ios-preview-controller.ts @@ -17,10 +17,11 @@ import { IosNavigationSensors } from '../native/ios-navigation-sensors' import { Utils } from '@nativescript/core' import { bindCompassSession, receiveCompassEvent } from '../native/compass.ios' import { Dialogs, File, knownFolders, path, type ImageSource } from '@nativescript/core' -import { iosBluetooth } from '../native/ios-bluetooth' import { iosVoiceInput } from '../native/ios-voice-input' import { nightscoutBridge } from '../native/nightscout-bridge' -import { GlassesSession, type SessionState } from './glasses-session' +import { FaceclawCommunicatorBridge, resolveIosPeripherals, type CommunicatorState, type RawInputEvent } from '../native/faceclaw-communicator.ios' +import { PreviewDisplayTarget, type DisplayTarget } from '../native/preview-display.ios' +import { AncsClient, ANCS_FIRMWARE_VERSION } from './ancs-client' import { GlanceHost, type GlanceDisplay } from './glance-host' import { createLockScreenImage, LOCK_SCREEN_SURFACE_ID } from './lock-screen' import { OsEventTypeList } from './events' @@ -34,12 +35,9 @@ import { createInProcessWindow, YieldAtRootLayer, type InProcessAppOptions, type import { getStringSettingById, nightscoutSiteUrlSetting, nightscoutApiTokenSetting } from '../ui/dashboard-settings' import { readPhoneBatteryState } from '../native/phone-battery' import { iosAppUnavailableReason } from '../apps/ios-availability' -import { SurfaceCompositor } from '../graphics/surface-compositor' -import { flattenPlanesWithDraws, type Plane } from '../graphics/plane' +import { flattenPlanesWithDraws, planesFingerprint, type Plane } from '../graphics/plane' import { prepareFrameDraws } from '../graphics/glyph-wire' -import { IosTexturePlanner } from '../native/texture-planner.ios' import { G2_LENS_WIDTH, G2_LENS_HEIGHT } from '../graphics/image' -import { previewPixels } from '../native/ios-graphics' import { makeInputEvent, type InputEvent, type InputEventPayload } from '../ui/gestures' import { noopLayerActions, type LayerActions } from '../ui/layers' import { TextViewerLayer } from '../apps/files/text-viewer' @@ -51,47 +49,75 @@ import type { PhoneGesture } from '../phone-ui/phone-gestures' import { isWelcomeSoundPending, setWelcomeSoundPending } from '../phone-ui/onboarding-state' import { findSoundEffect, playSoundEffect } from '../ui/sound-effects' -/** iOS host for the shared app registry, shell, compositor and BLE session. */ +const SHELL_SURFACE_ID = 'shell' +const SHELL_SURFACE_Z_ORDER = 1 +const LOCK_SURFACE_Z_ORDER = 1000 +/** The shell render loop waits this long for the glasses to take a frame before moving on. */ +const FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS = 2000 + +export type SessionPhase = 'disconnected' | 'connecting' | 'connected' | 'retrying' | 'disconnecting' | 'error' +export type SessionState = { phase: SessionPhase; status: string; battery: number | null; charging: boolean | null; + ring: boolean; frames: number; capabilities: string; leftVersion: string; rightVersion: string } + +function ancsCapable(capabilities: string): boolean { + return /^Faceclaw\/(\d+)/.test(capabilities) && Number(capabilities.split('/')[1]) >= ANCS_FIRMWARE_VERSION +} + +/** + * iOS host for the shared app registry, shell and BLE session. The session, + * compositor and transport live in shared Kotlin (FaceclawCommunicatorBridge + * over FaceclawKitIosGlassesSession); with no glasses connected the same + * compositor runs headless (PreviewDisplayTarget) so the phone mirror works. + */ export class IosPreviewController { - private readonly compositor = new SurfaceCompositor(G2_LENS_WIDTH, G2_LENS_HEIGHT) + private previewTarget: PreviewDisplayTarget | null = null + private communicator: FaceclawCommunicatorBridge | null = null + private readonly startedCommunicators = new WeakSet() + state: SessionState = { phase: 'disconnected', status: 'Preview only', battery: null, charging: null, ring: false, + frames: 0, capabilities: '', leftVersion: '', rightVersion: '' } + private notifications: AncsClient | null = null + private readonly sessionOffs: (() => void)[] = [] + private stopping: Promise | null = null + /** Resolves once the current display target has every surface configured. */ + private displayReady: Promise = Promise.resolve() + private connecting = false + private sessionCreated = false + private wearDetectionRequested = false private readonly glanceDisplay: GlanceDisplay = { - configureSurface: async (id, options) => { - this.compositor.configureSurface(id, options) - }, - setSurfaceVisible: async (id, visible) => { - this.compositor.setSurfaceVisible(id, visible); this.scheduleFrame() - }, - setScreenBlanked: async blanked => { - this.compositor.setScreenBlanked(blanked); this.scheduleFrame() - }, - submitSurfaceFrame: async (id, pixels, rect, _fingerprint, _paintMs, _frameId, draws) => { - this.compositor.submitSurfaceFrame(id, pixels, rect, draws); this.scheduleFrame() + configureSurface: async (id, options) => { await this.display?.configureSurface(id, options) }, + setSurfaceVisible: async (id, visible) => { await this.display?.setSurfaceVisible(id, visible); this.schedulePreviewUpdate() }, + setScreenBlanked: async blanked => { await this.display?.setScreenBlanked(blanked); this.schedulePreviewUpdate() }, + submitSurfaceFrame: async (id, pixels, rect, fingerprint, paintMs, frameId, draws) => { + await this.display?.submitSurfaceFrame(id, pixels, rect, fingerprint, paintMs, frameId, draws); this.schedulePreviewUpdate() }, } private readonly glance = new GlanceHost({ - getDisplay: () => this.glanceDisplay, + getDisplay: () => this.display ? this.glanceDisplay : null, getProvider: () => ALL_APPS.find(app => app.glanceboard)?.glanceboard ?? null, canShow: () => this.runtimeNeeded && !this.glassesLocked, // iOS retains the EvenHub session while the shell sleeps. The board's // opaque first frame is ready before we unblank the compositor. ensureSessionActive: async () => { - this.compositor.setScreenBlanked(false); this.scheduleFrame(); return true + await this.display?.setScreenBlanked(false); this.schedulePreviewUpdate(); return true }, onHiddenWhileAsleep: () => { - if (!shell.isScreenOn()) this.compositor.setScreenBlanked(true) - this.scheduleFrame() + if (!shell.isScreenOn()) void this.display?.setScreenBlanked(true).then(() => this.schedulePreviewUpdate()) + else this.schedulePreviewUpdate() }, - onVisibilityChanged: () => this.scheduleFrame(), + onVisibilityChanged: () => this.schedulePreviewUpdate(), appendLog: message => this.logBluetooth(message), }) - private renderTimer: ReturnType | null = null + private previewTimer: ReturnType | null = null private clockTimer: ReturnType | null = null private offSettings: (() => void) | null = null private lastBrightness: string | null = null private active = false private runtimeRunning = false private clockMinute = -1 - private shellDirty = true + private shellRenderInProgress = false + private shellRenderQueued = false + private nextFrameId = 1 + private nextWorkerFrame = 0 private inputQueue: Promise = Promise.resolve() private lastLayout = '' private readonly appHosts = new Map() @@ -102,13 +128,12 @@ export class IosPreviewController { private glassesWorn: boolean | null = null private glassesLocked = false private lockEnabled = lockScreenEnabledSetting.get() - private session: GlassesSession | null = null private acknowledgedFrames = 0 private logLines: string[] = [] private logTimer: ReturnType | null = null private readonly actions: LayerActions = { ...noopLayerActions, - playBuzzerSequence: payload => this.session?.playBuzzerSequence(payload), + playBuzzerSequence: payload => this.communicator?.playBuzzerSequence(payload), requestRender: () => this.requestShellRender(), disconnect: () => this.disconnect(), startVoiceCapture: endpointing => this.startVoiceCapture(endpointing), @@ -130,11 +155,7 @@ export class IosPreviewController { private readonly onError: (message: string) => void, private readonly onConnectionState: (state: SessionState) => void = () => {}, private readonly onKeyboardInputChanged: (session: KeyboardInputSession | null) => void = () => {}) { - this.compositor.configureSurface('shell', { x: 0, y: 0, width: 640, height: 480, zOrder: 1, transparency: 'color-key' }) - this.compositor.configureSurface(LOCK_SCREEN_SURFACE_ID, { - x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT, zOrder: 1000, transparency: 'opaque', - }) - this.compositor.setSurfaceVisible(LOCK_SCREEN_SURFACE_ID, false) + this.ensurePreviewDisplay() shell.configure({ actions: this.actions, voiceInputEnabled: true, @@ -151,7 +172,8 @@ export class IosPreviewController { onWindowsChanged: () => this.requestShellRender(), onScreenStateChanged: on => { if (on) this.glance.dismiss() - this.compositor.setScreenBlanked(!on); this.requestShellRender() + void this.display?.setScreenBlanked(!on).catch(error => this.fail(error)) + this.requestShellRender() }, }) const launcher = createLauncherWindow({ @@ -160,9 +182,9 @@ export class IosPreviewController { launchApp: id => this.launchApp(id), uninstallApp: id => this.uninstallApp(id), submitFrame: planes => this.submit(LAUNCHER_SURFACE_ID, planes), - setSurfaceVisible: visible => { this.compositor.setSurfaceVisible(LAUNCHER_SURFACE_ID, visible); this.scheduleFrame() }, + setSurfaceVisible: visible => this.setWindowSurfaceVisible(LAUNCHER_SURFACE_ID, visible), }) - this.configureWindow(launcher) + void this.configureWindow(launcher) shell.registerWindow(launcher) shell.wake('window') shell.focusWindow(launcher.windowId) @@ -198,14 +220,54 @@ export class IosPreviewController { for (const app of ALL_APPS) if (app.appId !== 'launcher' && !iosAppUnavailableReason(app.appId)) app.boot?.(this.buildAppContext(app)) } + /** The compositor frames go to: the live session, else the headless preview. */ + private get display(): DisplayTarget | null { return this.communicator ?? this.previewTarget } + + private ensurePreviewDisplay(): void { + if (this.communicator || this.previewTarget) return + const target = new PreviewDisplayTarget() + this.previewTarget = target + target.activate(() => this.schedulePreviewUpdate()) + this.displayReady = this.registerSurfaces(target).catch(error => this.fail(error)) + } + + private teardownPreviewDisplay(): void { + const target = this.previewTarget + if (!target) return + this.previewTarget = null + this.glance.reset() + target.release() + } + + /** (Re)create every compositor surface on a fresh display target. */ + private async registerSurfaces(target: DisplayTarget): Promise { + await target.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT) + await target.configureSurface(SHELL_SURFACE_ID, { x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT, + zOrder: SHELL_SURFACE_Z_ORDER, transparency: 'color-key' }) + await target.setUnderlayDim(SHELL_SURFACE_Z_ORDER, 1) + await target.configureSurface(LOCK_SCREEN_SURFACE_ID, { + x: 0, y: 0, width: G2_LENS_WIDTH, height: G2_LENS_HEIGHT, zOrder: LOCK_SURFACE_Z_ORDER, transparency: 'opaque', + }) + if (this.glassesLocked) await this.submitLockImage(target) + await target.setSurfaceVisible(LOCK_SCREEN_SURFACE_ID, this.glassesLocked) + await target.setScreenBlanked(!shell.isScreenOn()) + this.lastLayout = '' + for (const window of shell.getWindows()) await this.configureWindow(window, target) + } + + private async submitLockImage(target: DisplayTarget): Promise { + const image = createLockScreenImage() + await target.submitSurfaceFrame(LOCK_SCREEN_SURFACE_ID, image.to8bppBuffer(), + { x: 0, y: 0, width: image.width, height: image.height }, 'lock-screen', 0, 0) + } + resume(): void { if (this.active) return this.active = true this.syncRuntime() this.handlePhoneLockState(!UIApplication.sharedApplication.protectedDataAvailable) this.logBluetooth('Phone foreground') - if (this.session) this.onConnectionState({ ...this.session.state }) - this.session?.wake() + if (this.communicator) this.onConnectionState({ ...this.state }) this.relayout() shell.foregroundWindow()?.requestRender() this.requestShellRender() @@ -216,12 +278,11 @@ export class IosPreviewController { iosVoiceInput.stopPhoneCapture() // The phone preview is hidden; the glasses still own their screen and input. this.syncRuntime() - this.logBluetooth(`Phone background; glasses ${this.session?.state.phase ?? 'disconnected'}`) + this.logBluetooth(`Phone background; glasses ${this.state.phase}`) this.flushBluetoothLog() - this.session?.wake() } private get runtimeNeeded(): boolean { - return this.active || !!this.session && ['connected', 'connecting', 'retrying', 'disconnecting'].includes(this.session.state.phase) + return this.active || ['connected', 'connecting', 'retrying', 'disconnecting'].includes(this.state.phase) } private syncRuntime(): void { const running = this.runtimeNeeded @@ -231,14 +292,14 @@ export class IosPreviewController { if (!running) { void nightscoutBridge.stop().catch(error => this.fail(error)) this.glance.dismiss() - this.compositor.setScreenBlanked(!shell.isScreenOn()) + void this.display?.setScreenBlanked(!shell.isScreenOn()).catch(error => this.fail(error)) this.offSettings?.(); this.offSettings = null for (const observer of this.batteryObservers.splice(0)) NSNotificationCenter.defaultCenter.removeObserver(observer) for (const observer of this.lockObservers.splice(0)) NSNotificationCenter.defaultCenter.removeObserver(observer) UIDevice.currentDevice.batteryMonitoringEnabled = false if (this.clockTimer !== null) clearInterval(this.clockTimer) - if (this.renderTimer !== null) clearTimeout(this.renderTimer) - this.clockTimer = this.renderTimer = null + if (this.previewTimer !== null) clearTimeout(this.previewTimer) + this.clockTimer = this.previewTimer = null return } UIDevice.currentDevice.batteryMonitoringEnabled = true @@ -268,12 +329,13 @@ export class IosPreviewController { this.clockTimer = setInterval(() => this.refreshClock(), 60_000) } private pushBrightness(): void { - const session = this.session - if (session?.state.phase !== 'connected') { this.lastBrightness = null; return } + const communicator = this.communicator + if (!communicator || this.state.phase !== 'connected') { this.lastBrightness = null; return } const value = brightnessSetting.get() if (value === this.lastBrightness) return this.lastBrightness = value - void session.setBrightness(brightnessSettingToLevel(value)).catch(error => { + const level = brightnessSettingToLevel(value) + void communicator.setBrightness(level === null, level ?? 0).catch(error => { this.lastBrightness = null this.logBluetooth(`Brightness: ${String(error)}`) }) @@ -285,12 +347,13 @@ export class IosPreviewController { if (!enabled) this.setGlassesLocked(false) else { if (this.phoneLocked && this.glassesWorn === false) this.setGlassesLocked(true) - if (this.session?.state.phase === 'connected') - void this.session.enableWearDetectionAndRequestState().catch(error => this.fail(error)) + if (this.communicator && this.state.phase === 'connected') + void this.communicator.enableWearDetectionAndRequestState().catch(error => this.fail(error)) } } private handlePhoneLockState(locked: boolean): void { this.phoneLocked = locked + this.communicator?.onPhoneLockSignal() if (!locked) this.setGlassesLocked(false) else if (this.lockEnabled && this.glassesWorn === false) this.setGlassesLocked(true) } @@ -304,17 +367,21 @@ export class IosPreviewController { } private setGlassesLocked(locked: boolean): void { if (locked === this.glassesLocked) return - if (locked) { - const image = createLockScreenImage() - this.compositor.submitSurfaceFrame(LOCK_SCREEN_SURFACE_ID, image.to8bppBuffer(), - { x: 0, y: 0, width: image.width, height: image.height }) - } this.glassesLocked = locked if (locked) { this.glance.dismiss() iosVoiceInput.handleSessionEnded('Glasses locked. Unlock your phone to start voice input again.') } - this.compositor.setSurfaceVisible(LOCK_SCREEN_SURFACE_ID, locked) + void (async () => { + await this.displayReady + const display = this.display + if (!display) return + { + if (locked) await this.submitLockImage(display) + await display.setSurfaceVisible(LOCK_SCREEN_SURFACE_ID, locked) + this.schedulePreviewUpdate() + } + })().catch(error => this.fail(error)) this.logBluetooth(`Glasses ${locked ? 'locked' : 'unlocked'}`) this.requestShellRender() } @@ -322,45 +389,90 @@ export class IosPreviewController { const minute = Math.floor(Date.now() / 60_000) if (minute !== this.clockMinute) { this.clockMinute = minute; this.requestShellRender() } } - private configureWindow(window: ShellWindow): void { - this.compositor.configureSurface(window.surfaceId, { + private async configureWindow(window: ShellWindow, target: DisplayTarget | null = this.display): Promise { + if (!target) return + await target.configureSurface(window.surfaceId, { ...appViewportRect(window.heightMode, window.appId), zOrder: 0, transparency: 'opaque', }) - this.compositor.setSurfaceVisible(window.surfaceId, shell.foregroundWindow()?.windowId === window.windowId) + await target.setSurfaceVisible(window.surfaceId, shell.foregroundWindow()?.windowId === window.windowId) } private relayout(): void { const layout = shell.getWindows().map(window => JSON.stringify(appViewportRect(window.heightMode, window.appId))).join(";") if (layout === this.lastLayout) return this.lastLayout = layout for (const window of shell.getWindows()) { - this.configureWindow(window) + void this.configureWindow(window).catch(error => this.fail(error)) window.relayout?.() } } + /** Submit a painted frame for an in-process window (e.g. the launcher). */ private async submit(id: string, planes: Plane[]): Promise { + await this.displayReady + const display = this.display + if (!display) return + const fingerprint = planesFingerprint(planes) const { image, draws } = flattenPlanesWithDraws(planes) - this.compositor.submitSurfaceFrame(id, image.pixels, { x: 0, y: 0, width: image.width, height: image.height }, prepareFrameDraws(draws)) - this.scheduleFrame() + await display.submitSurfaceFrame(id, image.pixels, { x: 0, y: 0, width: image.width, height: image.height }, + fingerprint, -1, 0, prepareFrameDraws(draws)) + this.schedulePreviewUpdate() } - private requestShellRender(): void { this.shellDirty = true; this.scheduleFrame() } - private scheduleFrame(): void { - if (!this.runtimeNeeded || this.renderTimer !== null) return - // Coalesce window/chrome updates into one glasses frame, capped at 30 fps. - this.renderTimer = setTimeout(() => { - this.renderTimer = null - if (!this.runtimeNeeded) return + /** Worker windows ship baked pixels; every submit is new content to the compositor. */ + private async submitWorkerPixels(id: string, pixels: Uint8Array, width: number, height: number, draws: ArrayBuffer | null): Promise { + await this.displayReady + const display = this.display + if (!display) return + await display.submitSurfaceFrame(id, pixels, { x: 0, y: 0, width, height }, `${id}#${++this.nextWorkerFrame}`, -1, 0, draws) + this.schedulePreviewUpdate() + } + private setWindowSurfaceVisible(id: string, visible: boolean): void { + void this.display?.setSurfaceVisible(id, visible).then(() => this.schedulePreviewUpdate()).catch(error => this.fail(error)) + } + private removeWindowSurface(id: string): void { + void this.display?.removeSurface(id).then(() => this.schedulePreviewUpdate()).catch(error => this.fail(error)) + } + /** Re-render and resubmit the shell surface; one render in flight, at most one queued. */ + private requestShellRender(): void { + if (this.shellRenderInProgress) { this.shellRenderQueued = true; return } + this.shellRenderInProgress = true + void (async () => { try { - if (this.shellDirty) { - this.shellDirty = false - this.compositor.setShellScene(shell.paintScene()) - } - const { pixels, textures } = this.compositor.compositeFrame() - this.session?.setFrame(pixels, textures) - if (this.active) { - const image = previewPixels(pixels, 640, 480, previewColorSetting.get() === 'green') - this.onFrame(image, this.glassesLocked ? 'Glasses locked' : this.glance.isVisible() ? 'Glanceboard' - : `${shell.foregroundWindow()?.title ?? 'Apps'} · ${shell.getFocus() === 'sidebar' ? 'App switcher' : 'App'}`) - } + do { + this.shellRenderQueued = false + await this.renderShell() + } while (this.shellRenderQueued) + } catch (error) { this.fail(error) } + finally { this.shellRenderInProgress = false } + })() + } + private async renderShell(): Promise { + await this.displayReady + const display = this.display + if (!display) return + const startedAt = Date.now() + const bytes = shell.paintScene() + const frameId = this.allocateFrameId() + await display.submitShellScene(bytes, Date.now() - startedAt, frameId) + // Backpressure: the next shell render waits for this one to reach the + // glasses (the preview target resolves immediately; nothing transmits). + await display.waitForFrameFinished(frameId, FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS) + this.schedulePreviewUpdate() + } + private allocateFrameId(): number { + const id = this.nextFrameId + this.nextFrameId = this.nextFrameId >= 0x7fffffff ? 1 : this.nextFrameId + 1 + return id + } + /** Refresh the phone mirror from the composited screen, coalesced at 30 fps. */ + private schedulePreviewUpdate(): void { + if (!this.active || this.previewTimer !== null) return + this.previewTimer = setTimeout(() => { + this.previewTimer = null + if (!this.active) return + try { + const image = this.display?.getCompositePreview(previewColorSetting.get() === 'green') + if (!image) return + this.onFrame(image, this.glassesLocked ? 'Glasses locked' : this.glance.isVisible() ? 'Glanceboard' + : `${shell.foregroundWindow()?.title ?? 'Apps'} · ${shell.getFocus() === 'sidebar' ? 'App switcher' : 'App'}`) } catch (error) { this.fail(error) } }, 33) } @@ -469,7 +581,7 @@ export class IosPreviewController { launchInProcessApp: (id, surface, create) => this.launchInProcessApp(id, surface, create), ensureWorkerHost: create => this.ensureWorkerHost(app.appId, create), submitWindowFrame: (id, planes) => this.submit(id, planes), - setWindowSurfaceVisible: (id, visible) => { this.compositor.setSurfaceVisible(id, visible); this.scheduleFrame() }, + setWindowSurfaceVisible: (id, visible) => this.setWindowSurfaceVisible(id, visible), requestShellRender: () => this.requestShellRender(), appendLog: message => console.log(`[ios-app] ${message}`), setTextEditorHost: () => {}, } @@ -484,13 +596,17 @@ export class IosPreviewController { let surfaceReady = false const app = create({ actions: this.actions, submitFrame: planes => surfaceReady ? this.submit(surfaceId, planes) : Promise.resolve(), - setSurfaceVisible: visible => { this.compositor.setSurfaceVisible(surfaceId, visible); this.scheduleFrame() }, - removeSurface: () => { surfaceReady = false; this.compositor.removeSurface(surfaceId); this.scheduleFrame() }, - reconfigureSurface: () => { const window = shell.getWindows().find(w => w.windowId === windowId); if (window) this.configureWindow(window); this.requestShellRender() }, + setSurfaceVisible: visible => this.setWindowSurfaceVisible(surfaceId, visible), + removeSurface: () => { surfaceReady = false; this.removeWindowSurface(surfaceId) }, + reconfigureSurface: () => { + const window = shell.getWindows().find(w => w.windowId === windowId) + if (window) void this.configureWindow(window).catch(error => this.fail(error)) + this.requestShellRender() + }, onClosed: () => { this.inProcessApps.delete(windowId) }, }) this.inProcessApps.set(windowId, app) - this.configureWindow(app.window) + await this.configureWindow(app.window) surfaceReady = true shell.registerWindow(app.window); shell.focusWindow(windowId) app.requestRender(); this.requestShellRender() @@ -507,13 +623,15 @@ export class IosPreviewController { playBuzzerSequence: payload => this.actions.playBuzzerSequence(payload), openUrl: url => { void Utils.openUrl(url) }, configureSurface: async (id, visible, heightMode) => { - this.compositor.configureSurface(id, { ...appViewportRect(heightMode, appId), zOrder: 0, transparency: 'opaque' }) - this.compositor.setSurfaceVisible(id, visible) + const display = this.display + if (!display) return + await display.configureSurface(id, { ...appViewportRect(heightMode, appId), zOrder: 0, transparency: 'opaque' }) + await display.setSurfaceVisible(id, visible) }, - setSurfaceVisible: (id, visible) => { this.compositor.setSurfaceVisible(id, visible); this.scheduleFrame() }, - removeSurface: id => { this.compositor.removeSurface(id); this.scheduleFrame() }, + setSurfaceVisible: (id, visible) => this.setWindowSurfaceVisible(id, visible), + removeSurface: id => this.removeWindowSurface(id), submitPixels: (id, pixels, width, height, draws) => { - this.compositor.submitSurfaceFrame(id, pixels, { x: 0, y: 0, width, height }, draws); this.scheduleFrame() + void this.submitWorkerPixels(id, pixels, width, height, draws).catch(error => this.fail(error)) }, requestShellRender: () => this.requestShellRender(), openSettings: section => { void this.launchApp('settings', { section }) }, @@ -529,45 +647,193 @@ export class IosPreviewController { displayModeSetting.set(values[(values.indexOf(displayModeSetting.get()) + 1) % values.length]) } get displayModeLabel(): string { return displayModeLabel(displayModeSetting.get()) } - get connectionState(): SessionState | null { return this.session?.state ?? null } + get connectionState(): SessionState | null { return this.sessionCreated ? this.state : null } get connectionDetails(): string { const state = this.connectionState return state ? `${state.status}\nL: ${state.leftVersion || 'unknown'}\nR: ${state.rightVersion || 'unknown'}\nBattery: ${state.battery ?? '?'}%\nRing: ${state.ring ? 'connected' : 'disconnected'}\nFrames acknowledged: ${state.frames}\n${state.capabilities}\n\n${this.logLines.slice(-12).join('\n')}` : 'Preview only. Configure devices, then connect.' } + private update(phase: SessionPhase, status: string): void { + this.state = { ...this.state, phase, status } + this.logBluetooth(status) + this.emitState() + } + private emitState(): void { + if (this.state.phase !== 'connected') resetRingInputFilter() + this.pushBrightness() + this.maybePlayWelcomeSound(this.state) + if (this.state.phase !== 'connected' && this.state.phase !== 'connecting') this.glassesWorn = null + if (this.state.phase !== 'connected') iosVoiceInput.handleSessionEnded() + shell.setBatteryLevels({ headset: this.state.battery, headsetCharging: this.state.charging }) + this.syncRuntime() + if (this.active) this.onConnectionState({ ...this.state }) + this.requestShellRender() + } async connect(): Promise { - if (!this.active) return + if (!this.active || this.connecting || this.stopping) return + if (this.communicator && ['connecting', 'connected', 'retrying', 'disconnecting'].includes(this.state.phase)) return const addresses = loadDeviceAddresses(), error = deviceAddressError(addresses) if (error) { this.onError(error); return } - if (!this.session) { - this.session = new GlassesSession(iosBluetooth(), state => { - if (state.phase !== "connected") resetRingInputFilter() - this.pushBrightness() - this.maybePlayWelcomeSound(state) - if (state.phase !== 'connected' && state.phase !== 'connecting') this.glassesWorn = null - if (state.phase !== 'connected') iosVoiceInput.handleSessionEnded() - shell.setBatteryLevels({ headset: state.battery, headsetCharging: state.charging }) - this.syncRuntime() - if (this.active) this.onConnectionState(state) - this.requestShellRender() - }, input => { - this.inputQueue = this.inputQueue.then(async () => { - if (this.session?.state.phase !== 'connected') return - await this.receiveInput(rawInputEventToInputEvent(input), - input.kind === 'display-wake' && input.eventType === OsEventTypeList.HEAD_UP_EVENT) - this.logBluetooth(`Input ${input.eventType} source ${input.eventSource}`) - }).catch(error => this.fail(error)) - }, message => this.logBluetooth(message), () => { - if (!UIApplication.sharedApplication.protectedDataAvailable) this.handlePhoneLockState(true) - this.refreshClock() - }, receiveCompassEvent, wearing => this.handleWearState(wearing), (key, popup) => { - iosNotificationsChanged(key, popup); this.requestShellRender() - }, new IosTexturePlanner()) - bindIosNotifications(this.session.notifications) - bindCompassSession(this.session) + this.connecting = true + this.sessionCreated = true + try { + this.state = { ...this.state, capabilities: '', leftVersion: '', rightVersion: '', battery: null, charging: null, ring: false } + this.update('connecting', 'Finding configured devices…') + let identifiers + try { identifiers = await resolveIosPeripherals(addresses) } + catch (failure) { + this.update('error', failure instanceof Error ? failure.message : String(failure)) + return + } + if (this.communicator) await this.closeCommunicator() + const communicator = new FaceclawCommunicatorBridge(identifiers) + this.teardownPreviewDisplay() + this.communicator = communicator + this.wearDetectionRequested = false + this.bindCommunicator(communicator) + this.displayReady = this.registerSurfaces(communicator) + await this.displayReady + this.update('connecting', 'Connecting to the glasses…') + this.startedCommunicators.add(communicator) + await communicator.start() + for (const window of shell.getWindows()) window.requestRender() + this.requestShellRender() + } catch (failure) { + this.fail(failure) + await this.closeCommunicator().catch(() => {}) + this.ensurePreviewDisplay() + this.update('error', failure instanceof Error ? failure.message : String(failure)) + } finally { + this.connecting = false } - await this.session.start(addresses) } - async disconnect(): Promise { await this.session?.stop() } + private bindCommunicator(communicator: FaceclawCommunicatorBridge): void { + const notifications = new AncsClient(packet => communicator.writeRawToRight(packet), (key, popup) => { + iosNotificationsChanged(key, popup); this.requestShellRender() + }, message => this.logBluetooth('ANCS: ' + message)) + this.notifications = notifications + bindIosNotifications(notifications) + bindCompassSession(communicator) + communicator.setRequiresAncs(true) + this.sessionOffs.push( + communicator.onStateChange(state => this.handleSessionState(communicator, state)), + communicator.onRingEvent(input => this.handleRingEvent(input)), + communicator.onBatteryState(state => { + if (this.communicator !== communicator) return + this.state = { ...this.state, battery: state.battery >= 0 && state.battery <= 100 ? state.battery : this.state.battery, + charging: state.chargingStatus >= 0 ? state.chargingStatus > 0 : this.state.charging, + ring: (state.ringBattery ?? -1) >= 0 || this.state.ring } + shell.setBatteryLevels({ headset: this.state.battery, headsetCharging: this.state.charging }) + if (this.active) this.onConnectionState({ ...this.state }) + this.requestShellRender() + }), + communicator.onFirmwareInfo(info => { + if (this.communicator !== communicator) return + this.state = { ...this.state, leftVersion: info.leftVersion || this.state.leftVersion, + rightVersion: info.rightVersion || this.state.rightVersion, capabilities: info.extension || this.state.capabilities } + if (this.active) this.onConnectionState({ ...this.state }) + this.syncNotifications(communicator) + }), + communicator.onFrameMetrics(() => { + if (this.communicator !== communicator) return + this.state = { ...this.state, frames: this.state.frames + 1 } + this.onActivity() + this.maybePlayWelcomeSound(this.state) + if (this.active) this.onConnectionState({ ...this.state }) + this.schedulePreviewUpdate() + }), + communicator.onWearState(wearing => { if (this.communicator === communicator) this.handleWearState(wearing) }), + communicator.addCompassListener(receiveCompassEvent), + communicator.onAncsRelayFrame(frame => { if (this.communicator === communicator) notifications.receive(frame) }), + communicator.onAncsAuthorization(authorized => { + if (this.communicator !== communicator) return + if (authorized) { this.syncNotifications(communicator); return } + const active = notifications.state !== 'disconnected' + const command = notifications.stopCommand() + notifications.stop('Enable Share System Notifications in iPhone Settings → Bluetooth → right lens.') + if (active && this.state.phase === 'connected') void communicator.writeRawToRight(command).catch(() => {}) + }), + ) + } + private handleSessionState(communicator: FaceclawCommunicatorBridge, state: CommunicatorState): void { + if (this.communicator !== communicator) return + // Registering the listener makes the Kotlin session report its current state, which is + // "disconnected" before start(); that must not be mistaken for the session ending. + if (!this.startedCommunicators.has(communicator)) return + const phase: SessionPhase = state.phase === 'charging' ? 'connected' : state.phase === 'unpaired' ? 'error' : state.phase + if (phase === 'connected' && this.state.phase !== 'connected') { + this.state = { ...this.state, frames: this.state.frames } + if (!this.wearDetectionRequested) { + this.wearDetectionRequested = true + void communicator.enableWearDetectionAndRequestState().catch(error => this.logBluetooth(`Wear detection: ${String(error)}`)) + } + } + this.update(phase, state.status) + if (phase === 'connected') this.syncNotifications(communicator) + else if ((phase === 'disconnected' || phase === 'error') && !this.stopping) { + // The session ended on its own (retries exhausted, an arm unpaired): release it and go headless. + void this.disconnect(state.status) + } + } + private handleRingEvent(input: RawInputEvent): void { + this.inputQueue = this.inputQueue.then(async () => { + if (this.state.phase !== 'connected') return + this.onActivity() + if (input.ringInput) this.state = { ...this.state, ring: true } + await this.receiveInput(rawInputEventToInputEvent(input), + input.kind === 'display-wake' && input.eventType === OsEventTypeList.HEAD_UP_EVENT) + this.logBluetooth(`Input ${input.eventType} source ${input.eventSource}`) + }).catch(error => this.fail(error)) + } + /** Any glasses traffic: CoreBluetooth can wake a suspended process, so refresh what timers would have. */ + private onActivity(): void { + if (!UIApplication.sharedApplication.protectedDataAvailable) this.handlePhoneLockState(true) + this.refreshClock() + } + /** Start iPhone notification relay once the firmware is known to support it and ANCS is authorized. */ + private syncNotifications(communicator: FaceclawCommunicatorBridge): void { + const notifications = this.notifications + if (!notifications || this.state.phase !== 'connected') return + if (!ancsCapable(this.state.capabilities)) { + if (this.state.capabilities) notifications.stop(`Update glasses to Faceclaw firmware ${ANCS_FIRMWARE_VERSION} or newer for iPhone notifications.`) + return + } + if (notifications.state !== 'disconnected') return + notifications.start((Date.now() ^ Math.floor(Math.random() * 0xffffffff)) >>> 0, communicator.rightWriteLimit()) + } + async disconnect(reason?: string): Promise { + if (this.stopping) return this.stopping + const communicator = this.communicator + if (!communicator) return + // Marked before any bridge call: the session may report "disconnected" from inside disconnect(). + let finished!: () => void + this.stopping = new Promise(resolve => { finished = resolve }) + try { + const notifications = this.notifications + if (notifications && notifications.state !== 'disconnected') { + const command = notifications.stopCommand() + notifications.stop() + if (this.state.phase === 'connected') { try { await communicator.writeRawToRight(command) } catch {} } + } + if (this.state.phase === 'connected' || this.state.phase === 'connecting' || this.state.phase === 'retrying') + this.update('disconnecting', 'Disconnecting…') + await communicator.disconnect().catch(error => this.logBluetooth(`Disconnect: ${String(error)}`)) + } finally { + await this.closeCommunicator() + this.ensurePreviewDisplay() + this.update(reason ? 'error' : 'disconnected', reason ?? 'Preview only') + this.stopping = null + finished() + } + } + private async closeCommunicator(): Promise { + const communicator = this.communicator + if (!communicator) return + for (const off of this.sessionOffs.splice(0)) off() + this.notifications = null + this.communicator = null + this.glance.reset() + await communicator.close().catch(error => this.logBluetooth(`Close: ${String(error)}`)) + } private maybePlayWelcomeSound(state: SessionState): void { const firstNewFrame = state.frames > this.acknowledgedFrames this.acknowledgedFrames = state.frames @@ -582,17 +848,18 @@ export class IosPreviewController { startVoiceInput(): void { if (!this.glassesLocked) shell.startVoiceInput() } private async prepareVoiceCapture(): Promise { if (this.glassesLocked) return false - const usePhoneMic = this.session?.state.phase !== 'connected' + const usePhoneMic = this.state.phase !== 'connected' if (usePhoneMic && !this.active) return false const ready = await iosVoiceInput.prepare(this.active, usePhoneMic) if (!ready && this.active) this.onError(iosVoiceInput.statusText) - return ready && !this.glassesLocked && (this.session?.state.phase === 'connected' || this.active) + return ready && !this.glassesLocked && (this.state.phase === 'connected' || this.active) } private async startVoiceCapture(endpointing = false): Promise { if (this.glassesLocked) return const log = (message: string) => this.logBluetooth(message) - if (this.session?.state.phase === 'connected') { - await iosVoiceInput.startGlassesCapture(this.session, log, endpointing) + const communicator = this.communicator + if (communicator && this.state.phase === 'connected') { + await iosVoiceInput.startGlassesCapture(communicator, log, endpointing) } else if (this.active) { // Recheck microphone permission if the glasses disconnected after prepare. if (!await iosVoiceInput.prepare(this.active, true) || !this.active || this.glassesLocked) return diff --git a/app/g2/texture-planner.ts b/app/g2/texture-planner.ts deleted file mode 100644 index f8274896..00000000 --- a/app/g2/texture-planner.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** Platform-owned snapshot of the same composite as the submitted pixels. */ -export type TextureFrame = { readonly native: object } -export type TexturePlan = { resourceCommands: Uint8Array[]; payload: Uint8Array; nextFid: number; usedBytes: number } -/** Sessions own residency; frame snapshots may be coalesced without changing it. */ -export interface SessionTexturePlanner { - plan(previous: Uint8Array | null, next: Uint8Array, frame: TextureFrame, firstId: number): TexturePlan | null - reset(): void -} diff --git a/app/g2/wear-protocol.ts b/app/g2/wear-protocol.ts deleted file mode 100644 index 4e06c1ef..00000000 --- a/app/g2/wear-protocol.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { bytes, concat, integer, readBytes, readInteger, type ProtocolMessage } from './ble-protocol' - -// Matches BleProtocol.buildSetWearDetection/buildFaceclawWakeControl on Android. -export const enableWearDetection = (magic: number): Uint8Array => concat( - integer(1, 1), integer(2, magic), bytes(3, bytes(5, integer(1, 1)))) -export const queryWearState = (): Uint8Array => concat( - integer(1, 1), integer(2, 0), bytes(101, new Uint8Array([70, 67, 1, 7, 0, 0]))) - -export function decodeWearState(message: ProtocolMessage): boolean | null { - if (message.sid !== 0x10 || message.command !== 3) return null - const event = readBytes(message.payload, 5) - if (!event || readInteger(event, 1, -1) !== 1) return null - const state = readInteger(event, 2, -1) - return state === 0 ? false : state === 1 ? true : null -} diff --git a/app/graphics/surface-compositor.ios.ts b/app/graphics/surface-compositor.ios.ts index c99e559e..42b8c402 100644 --- a/app/graphics/surface-compositor.ios.ts +++ b/app/graphics/surface-compositor.ios.ts @@ -1,5 +1,4 @@ import { fromData, toData } from '../native/kotlin-data' -import type { TextureFrame } from '../g2/texture-planner' import type { SurfaceConfiguration, SurfaceRect } from './surface-compositor' export type { SurfaceConfiguration, SurfaceRect } from './surface-compositor' declare const FaceclawKitIosSurfaceCompositor: any @@ -35,8 +34,4 @@ export class SurfaceCompositor { } setShellScene(bytes: Uint8Array): void { this.native.shellData(toData(bytes)) } composite(): Uint8Array { return fromData(this.native.composite()) } - compositeFrame(): { pixels: Uint8Array; textures: TextureFrame } { - const native = this.native.compositeFrame() - return { pixels: fromData(native.pixels), textures: { native } } - } } diff --git a/app/graphics/surface-compositor.ts b/app/graphics/surface-compositor.ts index 769deb36..8f212b47 100644 --- a/app/graphics/surface-compositor.ts +++ b/app/graphics/surface-compositor.ts @@ -1,6 +1,5 @@ import { presentationRecords, readPresentation, paintPresentation, type Selection } from "./presentation-wire" /** Platform-independent 8bpp surface composition for the local display. */ -import type { TextureFrame } from '../g2/texture-planner' export type SurfaceRect = { x: number; y: number; width: number; height: number } export type SurfaceConfiguration = SurfaceRect & { zOrder: number @@ -55,7 +54,6 @@ export class SurfaceCompositor { surface.pixels.set(pixels.subarray(source, source + right - left), y * surface.width + left) } } - compositeFrame(): { pixels: Uint8Array; textures?: TextureFrame } { return { pixels: this.composite() } } composite(): Uint8Array { const output = new Uint8Array(this.width * this.height) if (this.blanked) return output diff --git a/app/native/ble-traffic.ios.ts b/app/native/ble-traffic.ios.ts index ef3f9a25..f41aafd4 100644 --- a/app/native/ble-traffic.ios.ts +++ b/app/native/ble-traffic.ios.ts @@ -1,3 +1,15 @@ -import { iosBleTraffic } from '../g2/ble-traffic-counters' export type { BleTrafficSample } from './ble-traffic' -export function sampleBleTraffic(): { messages: number; bytes: number; frames: number } { return iosBleTraffic.sample() } +declare const FaceclawKitIosBleTraffic: any + +// The Kotlin counters reset on every sample; accumulate here so callers see +// running totals like FaceclawBleManager.sampleOutboundTraffic on Android. +// CoreBluetooth has no per-message boundary; messages counts write calls. +const totals = { messages: 0, bytes: 0, frames: 0 } +export function sampleBleTraffic(): { messages: number; bytes: number; frames: number } { + const sample = FaceclawKitIosBleTraffic.shared.sample() + const written = Number(sample.getIndex(0)), frames = Number(sample.getIndex(2)) + totals.bytes += written + totals.frames += frames + if (written > 0) totals.messages++ + return { ...totals } +} diff --git a/app/native/device-info-probe.ios.ts b/app/native/device-info-probe.ios.ts index ac82157c..913c5e12 100644 --- a/app/native/device-info-probe.ios.ts +++ b/app/native/device-info-probe.ios.ts @@ -1,68 +1,89 @@ -import { StockConnection, StockTimeout } from '../g2/stock-connection' -import * as p from '../g2/ble-protocol' import { iosBluetooth } from './ios-bluetooth' +import { kotlinListener } from './kotlin-listener.ios' import type { DeviceInfo, DeviceInfoState } from './device-info-probe' export type { DeviceInfo, DeviceInfoState } from './device-info-probe' +declare const FaceclawKitIosDeviceInfoProbe: any, FaceclawKitFaceclawDeviceInfoProbeListener: any + +/** + * iOS twin of the Android DeviceInfoProbe wrapper: the shared Kotlin DeviceInfoProbeFlow + * runs over a CoreBluetooth central (FaceclawKitIosDeviceInfoProbe); TypeScript only maps + * the stored MAC addresses to peripheral identifiers first. Callbacks arrive on the main + * queue and are fanned out asynchronously like the Android wrapper does. + */ export class DeviceInfoProbe { - private logs = new Set<(line: string) => void>() - private states = new Set<(state: DeviceInfoState, detail: string) => void>() - private link = new StockConnection(iosBluetooth(), line => { for (const fn of this.logs) fn(line) }) - constructor(private right: string, private left = '') {} - onLog(fn: (line: string) => void): () => void { this.logs.add(fn); return () => this.logs.delete(fn) } - onStateChange(fn: (state: DeviceInfoState, detail: string) => void): () => void { this.states.add(fn); return () => this.states.delete(fn) } - async run(): Promise { - const snapshots = new Map() - const parse = (message: p.ProtocolMessage): DeviceInfo => { - const values = p.readBytes(message.payload, 4) - return { leftVersion: values ? p.readString(values, 5) : '', rightVersion: values ? p.readString(values, 6) : '', extension: p.readString(message.payload, 100) } - } - const hasVersion = (info: DeviceInfo) => !!(info.leftVersion || info.rightVersion || info.extension) - // Some stock builds push settings using their own magic instead of the - // query's magic. Keep a valid snapshot as the Android probe does. - this.link.onMessage((role, message) => { - if (message.sid === p.SID.settings) { const info = parse(message); if (hasVersion(info)) snapshots.set(role, info) } + private probe: any = null + private listenerProxy: object | null = null + private readonly logListeners = new Set<(line: string) => void>() + private readonly stateListeners = new Set<(state: DeviceInfoState, detail: string) => void>() + private settled = false + private cancelled = false + private resolveFn: ((info: DeviceInfo) => void) | null = null + private rejectFn: ((error: Error) => void) | null = null + + constructor(private readonly rightAddress: string, private readonly leftAddress = '') {} + + onLog(listener: (line: string) => void): () => void { + this.logListeners.add(listener) + return () => this.logListeners.delete(listener) + } + + onStateChange(listener: (state: DeviceInfoState, detail: string) => void): () => void { + this.stateListeners.add(listener) + return () => this.stateListeners.delete(listener) + } + + run(): Promise { + return new Promise((resolve, reject) => { + this.resolveFn = resolve + this.rejectFn = reject + void this.start() }) + } + + private async start(): Promise { + let identifiers: Record try { - await this.link.resolve({ right: this.right, left: this.left, ring: '' }) - for (const role of ['right', ...(this.left ? ['left'] : [])]) { - await this.bringUp(role) - } - let lastError: unknown - for (const role of ['right', ...(this.left ? ['left'] : [])]) { - for (const fn of this.states) fn('querying', role) - try { - if (!this.link.isConnected(role)) await this.bringUp(role) - await this.link.request(role, p.SID.launch, p.prelude, 3500, 156) - for (let attempt = 0; attempt < 2; attempt++) { - try { - const message = await this.link.request(role, p.SID.settings, p.settingsQuery) - const info = parse(message) - if (hasVersion(info)) return info - } catch (error) { this.link.check(); lastError = error } - if (snapshots.has(role)) return snapshots.get(role)! - } - } catch (error) { this.link.check(); lastError = error } - } - throw lastError ?? new Error("Connected, but couldn't read a firmware version.") - } finally { this.close() } - } - private async bringUp(role: string): Promise { - for (let attempt = 0; ; attempt++) { - try { - for (const fn of this.states) fn('connecting', role) - await this.link.connect(role) - for (const fn of this.states) fn('authenticating', role) - // Version reads remain available on older stock builds without an auth ACK. - try { await this.link.authenticate(role) } catch (error) { if (!(error instanceof StockTimeout)) throw error } - return - } catch (error) { - this.link.check(); this.link.disconnect(role) - if (attempt === 2) throw error - await new Promise(resolve => setTimeout(resolve, 1500)); this.link.check() - } + this.emit(this.stateListeners, 'connecting', 'right') + identifiers = await iosBluetooth().resolveDevices({ right: this.rightAddress, left: this.leftAddress, ring: '' }) + } catch (error) { + this.settle(error instanceof Error ? error : new Error(String(error)), null) + return } + if (this.cancelled) { this.settle(new Error('Cancelled.'), null); return } + this.probe = FaceclawKitIosDeviceInfoProbe.alloc().initWithRightAddressLeftAddress(identifiers.right ?? '', identifiers.left ?? '') + this.listenerProxy = kotlinListener(FaceclawKitFaceclawDeviceInfoProbeListener, { + onLogLine: (line: string) => this.emit(this.logListeners, String(line ?? '')), + onStateStateDetail: (state: string, detail: string) => + this.emit(this.stateListeners, String(state) as DeviceInfoState, String(detail ?? '')), + onResultLeftVersionRightVersionExtension: (leftVersion: string, rightVersion: string, extension: string) => + this.settle(null, { leftVersion: String(leftVersion ?? ''), rightVersion: String(rightVersion ?? ''), extension: String(extension ?? '') }), + onErrorMessage: (message: string) => this.settle(new Error(String(message ?? '')), null), + }) + this.probe.setListenerListener(this.listenerProxy) + this.probe.start() + } + + cancel(): void { + this.cancelled = true + try { this.probe?.cancel() } catch { /* ignore */ } + } + + close(): void { + this.cancelled = true + try { this.probe?.close() } catch { /* ignore */ } + } + + private settle(error: Error | null, info: DeviceInfo | null): void { + if (this.settled) return + this.settled = true + this.close() + if (error) this.rejectFn?.(error) + else if (info) this.resolveFn?.(info) + } + + private emit(listeners: Set<(...args: A) => void>, ...args: A): void { + const snapshot = Array.from(listeners) + setTimeout(() => { for (const listener of snapshot) listener(...args) }, 0) } - cancel(): void { this.link.close() } - close(): void { this.link.close() } } diff --git a/app/native/faceclaw-communicator.ios.ts b/app/native/faceclaw-communicator.ios.ts new file mode 100644 index 00000000..aad20272 --- /dev/null +++ b/app/native/faceclaw-communicator.ios.ts @@ -0,0 +1,677 @@ +import type { RingInput } from "../g2/ring-input"; +import { File, knownFolders, path, type ImageSource } from "@nativescript/core"; +import { type FirmwareInfo } from "../g2/firmware-compat"; +import { type CompassEvent } from "./compass-types"; +import { fromData, toData } from "./kotlin-data"; +import { previewPixels } from "./ios-graphics"; +import { iosBluetooth } from "./ios-bluetooth"; + +export type { FirmwareInfo }; + +// Kotlin/Native facades exported by FaceclawKit (see native/kotlin/shared/src/iosMain/.../ble). +declare const FaceclawKitIosGlassesSession: any; +declare const FaceclawKitIosProtocolPlatform: any; +declare const FaceclawKitFaceclawBleCommunicatorListener: any; +declare const FaceclawKitIosAncsListener: any; +declare const FaceclawKitIosAudioPacketListener: any; +declare const FaceclawKitFaceclawCompassListener: any; + + +export type CommunicatorPhase = + | "disconnected" + | "connecting" + | "connected" + | "charging" + | "retrying" + | "unpaired" + | "disconnecting"; + +export type CommunicatorState = { + phase: CommunicatorPhase; + status: string; +}; + +export type HeadsetBatteryState = { + battery: number; + chargingStatus: number; + ringBattery?: number; + ringChargingStatus?: number; +}; + +export type FrameMetrics = { + paintMs: number; + transmitMs: number; + tileCount: number; +}; + +/** See the Android twin: compositor surface configuration in screen pixels. */ +export type SurfaceOptions = { + x: number; + y: number; + width: number; + height: number; + zOrder: number; + transparency: "opaque" | "color-key"; +}; + +export type RawInputEvent = { ringInput?: RingInput } & ( + | { kind: "list-click"; containerName: string; eventType: number; eventSource: number; systemExitReasonCode: number; frameId: number } + | { kind: "text-click"; containerName: string; eventType: number; eventSource: number; systemExitReasonCode: number; frameId: number } + | { kind: "sys-event"; containerName: string; eventType: number; eventSource: number; systemExitReasonCode: number; frameId: number } + | { kind: "even-ai"; containerName: string; eventType: number; eventSource: number; systemExitReasonCode: number; frameId: number } + | { kind: "watch-gesture"; containerName: string; eventType: number; eventSource: number; systemExitReasonCode: number; frameId: number } + | { kind: "display-wake"; containerName: string; eventType: number; eventSource: number; systemExitReasonCode: number; frameId: number } +); + +function nonNegativeNumber(value: number): number { + const numeric = Number(value); + return Number.isFinite(numeric) ? Math.max(0, numeric) : 0; +} + +/** A 0..1 brightness factor as the compositor's 0..256 fixed-point form. */ +export function dimFactor256(factor: number): number { + return Math.round(Math.max(0, Math.min(1, factor)) * 256); +} + +function timestamp(): string { + const now = new Date(); + const pad = (value: number, width = 2) => String(value).padStart(width, "0"); + return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}-${pad(now.getMilliseconds(), 3)}`; +} + +export type PeripheralIdentifiers = { right: string; left: string; ring: string }; + +/** + * Map the configured MAC addresses to CoreBluetooth identifiers through the scan + * layer (app/native/ios-bluetooth.ts): the mapping a previous scan persisted, else a + * fresh scan that classifies Even advertisements. The scan layer also owns Bluetooth + * readiness (creating the central triggers the permission prompt on first use). + */ +export async function resolveIosPeripherals(addresses: { right: string; left: string; ring?: string }): Promise { + const resolved = await iosBluetooth().resolveDevices({ right: addresses.right, left: addresses.left, ring: addresses.ring ?? "" }); + return { + right: String(resolved.right ?? "").toUpperCase(), + left: String(resolved.left ?? "").toUpperCase(), + ring: String(resolved.ring ?? "").toUpperCase(), + }; +} + +/** Bluetooth powered on and authorized (prompts for permission the first time); rejects with the user-facing reason. */ +export function ensureIosBluetoothReady(): Promise { + return iosBluetooth().ensureReady(); +} + +@NativeClass() +class SessionListener extends NSObject { + static ObjCProtocols = [FaceclawKitFaceclawBleCommunicatorListener]; + bridge!: FaceclawCommunicatorBridge; + onStateChangePhaseStatus(phase: string, status: string): void { this.bridge.handleStateChange(String(phase ?? ""), String(status ?? "")); } + onRingEventKindContainerNameEventTypeEventSourceSystemExitReasonCodeFrameIdRingTickRingTypeRingAuxRingSpeed( + kind: string, containerName: string, eventType: number, eventSource: number, systemExitReasonCode: number, + frameId: number, ringTick: number, ringType: number, ringAux: number, ringSpeed: number, + ): void { + this.bridge.handleRingEvent(String(kind ?? ""), String(containerName ?? ""), Number(eventType), Number(eventSource), + Number(systemExitReasonCode), Number(frameId), Number(ringTick), Number(ringType), Number(ringAux), Number(ringSpeed)); + } + onBatteryStateHeadsetBatteryHeadsetChargingRingBatteryRingCharging(headsetBattery: number, headsetCharging: number, ringBattery: number, ringCharging: number): void { + this.bridge.handleBatteryState(Number(headsetBattery), Number(headsetCharging), Number(ringBattery), Number(ringCharging)); + } + onSilentModeSilent(silent: boolean): void { this.bridge.handleSilentMode(Boolean(silent)); } + onWearStateWearing(wearing: boolean): void { this.bridge.handleWearState(Boolean(wearing)); } + onPhoneLockStateLocked(locked: boolean): void { this.bridge.handlePhoneLockState(Boolean(locked)); } + onEvenAppConflictMessage(message: string): void { this.bridge.handleEvenAppConflict(String(message ?? "")); } + onFrameMetricsPaintMsTransmitMsTileCount(paintMs: number, transmitMs: number, tileCount: number): void { + this.bridge.handleFrameMetrics(Number(paintMs), Number(transmitMs), Number(tileCount)); + } + onFrameFinishedFrameIdOutcome(frameId: number, outcome: string): void { this.bridge.handleFrameFinished(Number(frameId), String(outcome ?? "")); } + onFirmwareInfoLeftVersionRightVersionExtension(leftVersion: string, rightVersion: string, extension: string): void { + this.bridge.handleFirmwareInfo(String(leftVersion ?? ""), String(rightVersion ?? ""), String(extension ?? "")); + } +} + +@NativeClass() +class AncsListener extends NSObject { + static ObjCProtocols = [FaceclawKitIosAncsListener]; + bridge!: FaceclawCommunicatorBridge; + onAncsAuthorizationAuthorized(authorized: boolean): void { this.bridge.handleAncsAuthorization(Boolean(authorized)); } + onRelayFrameData(data: NSData): void { this.bridge.handleAncsRelayFrame(fromData(data)); } +} + +@NativeClass() +class AudioPacketListener extends NSObject { + static ObjCProtocols = [FaceclawKitIosAudioPacketListener]; + handler!: (packet: Uint8Array, arm: string, arrivalMs: number) => void; + onAudioPacketDataArmArrivalMs(data: NSData, arm: string, arrivalMs: number): void { + this.handler(fromData(data), String(arm ?? ""), Number(arrivalMs)); + } +} + +@NativeClass() +class CompassListener extends NSObject { + static ObjCProtocols = [FaceclawKitFaceclawCompassListener]; + handler!: (event: CompassEvent) => void; + onCompassEventCommandHeadingDegreesMagneticAccuracyMagneticAnomaliesOrientationSourceDiagnosticFlagsSampleTimeMs( + command: number, headingDegrees: number, magneticAccuracy: number, magneticAnomalies: number, + orientationSource: number, diagnosticFlags: number, sampleTimeMs: number, + ): void { + this.handler({ + command: Number(command), headingDegrees: Number(headingDegrees), + diagnostics: diagnosticFlags >= 0 ? { + magneticAccuracy: Number(magneticAccuracy), magneticAnomalies: Number(magneticAnomalies), + orientationSource: Number(orientationSource), flags: Number(diagnosticFlags), sampleTimeMs: Number(sampleTimeMs), + } : undefined, + }); + } +} + +/** + * The iOS twin of the Android communicator bridge: the same public API over + * the shared Kotlin session (FaceclawKitIosGlassesSession, CoreBluetooth + * underneath). Addresses are CoreBluetooth identifiers (resolveIosPeripherals + * maps the configured MACs). Every Kotlin callback already arrives on the + * main queue; listener fan-out is still deferred with setTimeout like on + * Android so callers never re-enter the bridge from a Kotlin frame. + */ +export class FaceclawCommunicatorBridge { + private readonly communicator: any; + private readonly listenerProxy: SessionListener; + private ancsProxy: AncsListener | null = null; + private nativeCallQueue: Promise = Promise.resolve(); + private queuedNativeCalls = 0; + private readonly frameMetricWaiters = new Set<(metrics: FrameMetrics) => void>(); + private readonly finishedFrameOutcomes = new Map(); + private readonly frameFinishedWaiters = new Map void>>(); + private readonly stateListeners = new Set<(state: CommunicatorState) => void>(); + private readonly ringListeners = new Set<(event: RawInputEvent) => void>(); + private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>(); + private readonly silentModeListeners = new Set<(silent: boolean) => void>(); + private readonly wearStateListeners = new Set<(wearing: boolean) => void>(); + private readonly phoneLockStateListeners = new Set<(locked: boolean) => void>(); + private latestWearState: boolean | null = null; + private latestPhoneLockState: boolean | null = null; + private readonly evenAppConflictListeners = new Set<(message: string) => void>(); + private readonly frameMetricsListeners = new Set<(metrics: FrameMetrics) => void>(); + private readonly firmwareInfoListeners = new Set<(info: FirmwareInfo) => void>(); + private readonly ancsAuthorizationListeners = new Set<(authorized: boolean) => void>(); + private readonly ancsRelayListeners = new Set<(frame: Uint8Array) => void>(); + private audioListener: AudioPacketListener | null = null; + private microphoneWork: Promise = Promise.resolve(); + private microphoneToken = 0; + + constructor(addresses: { right: string; left: string; ring?: string }) { + this.communicator = FaceclawKitIosGlassesSession.alloc().initWithRightAddressLeftAddressRingAddress( + String(addresses.right ?? "").toUpperCase(), + String(addresses.left ?? "").toUpperCase(), + String(addresses.ring ?? "").toUpperCase(), + ); + this.listenerProxy = SessionListener.new() as SessionListener; + this.listenerProxy.bridge = this; + this.communicator.setListenerListener(this.listenerProxy); + } + + // ----- Kotlin listener entry points (main queue) ----------------------------------- + + /** @internal */ + handleStateChange(phase: string, status: string): void { + this.emitAsync(this.stateListeners, { phase: phase as CommunicatorPhase, status }); + } + + /** @internal */ + handleRingEvent(kind: string, containerName: string, eventType: number, eventSource: number, systemExitReasonCode: number, + frameId: number, ringTick: number, ringType: number, ringAux: number, ringSpeed: number): void { + const event = { + kind: kind as RawInputEvent["kind"], containerName, eventType, eventSource, systemExitReasonCode, frameId, + ringInput: ringTick >= 0 ? { tick: ringTick, type: ringType, aux: ringAux, speed: ringSpeed } : undefined, + } as RawInputEvent; + this.emitAsync(this.ringListeners, event); + } + + /** @internal */ + handleBatteryState(battery: number, chargingStatus: number, ringBattery: number, ringChargingStatus: number): void { + this.emitAsync(this.batteryListeners, { battery, chargingStatus, ringBattery, ringChargingStatus }); + } + + /** @internal */ + handleSilentMode(silent: boolean): void { this.emitAsync(this.silentModeListeners, silent); } + + /** @internal */ + handleWearState(wearing: boolean): void { + this.latestWearState = wearing; + this.emitAsync(this.wearStateListeners, wearing); + } + + /** @internal */ + handlePhoneLockState(locked: boolean): void { + this.latestPhoneLockState = locked; + this.emitAsync(this.phoneLockStateListeners, locked); + } + + /** @internal */ + handleEvenAppConflict(message: string): void { this.emitAsync(this.evenAppConflictListeners, message); } + + /** @internal */ + handleFrameMetrics(paintMs: number, transmitMs: number, tileCount: number): void { + const metrics = { paintMs: nonNegativeNumber(paintMs), transmitMs: nonNegativeNumber(transmitMs), tileCount: nonNegativeNumber(tileCount) }; + const waiters = Array.from(this.frameMetricWaiters); + this.frameMetricWaiters.clear(); + for (const waiter of waiters) setTimeout(() => waiter(metrics), 0); + this.emitAsync(this.frameMetricsListeners, metrics); + } + + /** @internal */ + handleFrameFinished(frameId: number, outcome: string): void { this.recordFrameFinished(frameId, outcome); } + + /** @internal */ + handleFirmwareInfo(leftVersion: string, rightVersion: string, extension: string): void { + this.emitAsync(this.firmwareInfoListeners, { leftVersion, rightVersion, extension }); + } + + /** @internal */ + handleAncsAuthorization(authorized: boolean): void { this.emitAsync(this.ancsAuthorizationListeners, authorized); } + + /** @internal */ + handleAncsRelayFrame(frame: Uint8Array): void { this.emitAsync(this.ancsRelayListeners, frame); } + + private emitAsync(listeners: Set<(value: T) => void>, value: T): void { + const snapshot = Array.from(listeners); + setTimeout(() => { + for (const listener of snapshot) listener(value); + }, 0); + } + + /** Same FIFO as the Android bridge: native calls stay ordered; the fast path skips a task hop when idle. */ + private enqueueNativeCall(operation: () => T, inlineWhenIdle = false): Promise { + if (inlineWhenIdle && this.queuedNativeCalls === 0) { + try { + return Promise.resolve(operation()); + } catch (error) { + return Promise.reject(error); + } + } + this.queuedNativeCalls++; + const run = () => + new Promise((resolve, reject) => { + setTimeout(() => { + this.queuedNativeCalls--; + try { + resolve(operation()); + } catch (error) { + reject(error); + } + }, 0); + }); + const result = this.nativeCallQueue.then(run, run); + this.nativeCallQueue = result.then(() => undefined, () => undefined); + return result; + } + + // ----- listeners ------------------------------------------------------------------- + + onStateChange(listener: (state: CommunicatorState) => void): () => void { + this.stateListeners.add(listener); + return () => this.stateListeners.delete(listener); + } + + onRingEvent(listener: (event: RawInputEvent) => void): () => void { + this.ringListeners.add(listener); + return () => this.ringListeners.delete(listener); + } + + onBatteryState(listener: (state: HeadsetBatteryState) => void): () => void { + this.batteryListeners.add(listener); + return () => this.batteryListeners.delete(listener); + } + + onSilentMode(listener: (silent: boolean) => void): () => void { + this.silentModeListeners.add(listener); + return () => this.silentModeListeners.delete(listener); + } + + onWearState(listener: (wearing: boolean) => void): () => void { + this.wearStateListeners.add(listener); + if (this.latestWearState !== null) { + const wearing = this.latestWearState; + setTimeout(() => { if (this.wearStateListeners.has(listener)) listener(wearing); }, 0); + } + return () => this.wearStateListeners.delete(listener); + } + + onPhoneLockState(listener: (locked: boolean) => void): () => void { + this.phoneLockStateListeners.add(listener); + if (this.latestPhoneLockState !== null) { + const locked = this.latestPhoneLockState; + setTimeout(() => { if (this.phoneLockStateListeners.has(listener)) listener(locked); }, 0); + } + return () => this.phoneLockStateListeners.delete(listener); + } + + onEvenAppConflict(listener: (message: string) => void): () => void { + this.evenAppConflictListeners.add(listener); + return () => this.evenAppConflictListeners.delete(listener); + } + + onFrameMetrics(listener: (metrics: FrameMetrics) => void): () => void { + this.frameMetricsListeners.add(listener); + return () => this.frameMetricsListeners.delete(listener); + } + + onFirmwareInfo(listener: (info: FirmwareInfo) => void): () => void { + this.firmwareInfoListeners.add(listener); + return () => this.firmwareInfoListeners.delete(listener); + } + + getNativeCommunicator(): any { + return this.communicator; + } + + private recordFrameFinished(frameId: number, outcome: string): void { + if (!Number.isFinite(frameId) || frameId <= 0) return; + this.finishedFrameOutcomes.set(frameId, outcome); + while (this.finishedFrameOutcomes.size > 128) { + const oldest = this.finishedFrameOutcomes.keys().next().value; + if (oldest === undefined) break; + this.finishedFrameOutcomes.delete(oldest); + } + const waiters = this.frameFinishedWaiters.get(frameId); + if (waiters) { + this.frameFinishedWaiters.delete(frameId); + for (const waiter of waiters) setTimeout(() => waiter(outcome), 0); + } + } + + waitForFrameFinished(frameId: number, timeoutMs: number): Promise { + const known = this.finishedFrameOutcomes.get(frameId); + if (known !== undefined) return Promise.resolve(known); + if (frameId <= 0) return Promise.resolve(null); + const delayMs = Math.max(1, Math.round(nonNegativeNumber(timeoutMs))); + return new Promise((resolve) => { + let settled = false; + const onFinished = (outcome: string) => { + if (settled) return; + settled = true; + clearTimeout(timeoutHandle); + resolve(outcome); + }; + let waiters = this.frameFinishedWaiters.get(frameId); + if (!waiters) { + waiters = new Set(); + this.frameFinishedWaiters.set(frameId, waiters); + } + waiters.add(onFinished); + const timeoutHandle = setTimeout(() => { + if (settled) return; + settled = true; + const pending = this.frameFinishedWaiters.get(frameId); + if (pending) { + pending.delete(onFinished); + if (pending.size === 0) this.frameFinishedWaiters.delete(frameId); + } + resolve(null); + }, delayMs); + }); + } + + waitForNextFrameMetrics(timeoutMs: number): Promise { + const delayMs = Math.max(1, Math.round(nonNegativeNumber(timeoutMs))); + return new Promise((resolve) => { + let settled = false; + let timeoutHandle: ReturnType | null = null; + const complete = (metrics: FrameMetrics | null) => { + if (settled) return; + settled = true; + if (timeoutHandle !== null) clearTimeout(timeoutHandle); + this.frameMetricWaiters.delete(onMetrics); + resolve(metrics); + }; + const onMetrics = (metrics: FrameMetrics) => complete(metrics); + this.frameMetricWaiters.add(onMetrics); + timeoutHandle = setTimeout(() => complete(null), delayMs); + }); + } + + // ----- session --------------------------------------------------------------------- + + async start(): Promise { + await this.enqueueNativeCall(() => { this.communicator.start(); }); + } + + async setG2ScreenOn(screenOn: boolean): Promise { + await this.enqueueNativeCall(() => this.communicator.setG2ScreenOnScreenOn(Boolean(screenOn))); + } + + async setFirmwareDebugFlags(enabled: boolean): Promise { + await this.enqueueNativeCall(() => this.communicator.setFirmwareDebugFlagsEnabled(Boolean(enabled))); + } + + /** Set lens brightness: auto (ambient sensor) or an explicit 0-100 level. */ + async setBrightness(autoAdjust: boolean, level: number): Promise { + await this.enqueueNativeCall(() => this.communicator.setBrightnessAutoAdjustBrightnessLevel(Boolean(autoAdjust), Math.round(level))); + } + + async enableWearDetectionAndRequestState(): Promise { + await this.enqueueNativeCall(() => this.communicator.enableWearDetectionAndRequestState()); + } + + isSessionReady(): boolean { + return Boolean(this.communicator.isSessionReady()); + } + + /** The platform's lock/screen signal (the iOS host also observes protected data itself). */ + onPhoneLockSignal(): void { + this.communicator.onPhoneLockSignal(); + } + + // ----- compositor ------------------------------------------------------------------ + + async configureCompositorScreen(width: number, height: number): Promise { + await this.enqueueNativeCall(() => { + this.communicator.configureCompositorScreenWidthHeight(Math.round(width), Math.round(height)); + }); + } + + /** Phone-UI preview of the current composited screen, or null if none yet. */ + getCompositePreview(green = false): ImageSource | null { + const frame = this.communicator.previewComposite(); + if (!frame) return null; + const width = Number(this.communicator.compositeWidth()), height = Number(this.communicator.compositeHeight()); + if (width <= 0 || height <= 0) return null; + return previewPixels(fromData(frame.pixels), width, height, green); + } + + /** Save the current composite as a 4-bit grayscale PNG under Documents; returns the path (empty if none). Cropping is not supported on iOS. */ + saveScreenshot(crop?: { x: number; y: number; width: number; height: number }): string { + if (crop) return ""; + const png = this.communicator.screenshotPng(); + if (!png) return ""; + const target = path.join(knownFolders.documents().path, `screen-${timestamp()}.png`); + File.fromPath(target).writeSync(png); + return target; + } + + /** Screen recording is not available on iOS yet. */ + startScreenRecording(): void {} + + recordScreenFrame(): void {} + + stopScreenRecording(): string { return ""; } + + async configureSurface(id: string, options: SurfaceOptions): Promise { + const transparency = options.transparency === "color-key" ? 1 : 0; + await this.enqueueNativeCall(() => { + this.communicator.configureSurfaceIdXYWidthHeightZOrderTransparency( + id, Math.round(options.x), Math.round(options.y), Math.round(options.width), Math.round(options.height), + Math.round(options.zOrder), transparency, + ); + }); + } + + async removeSurface(id: string): Promise { + await this.enqueueNativeCall(() => { this.communicator.removeSurfaceId(id); }); + } + + async submitShellScene(bytes: Uint8Array, paintMs = 0, frameId = 0): Promise { + const snapshot = new Uint8Array(bytes); + await this.enqueueNativeCall(() => this.communicator.submitShellSceneBytesPaintMsFrameId(toData(snapshot), Math.round(nonNegativeNumber(paintMs)), Math.round(nonNegativeNumber(frameId))), true); + } + + async setUnderlayDim(belowZOrder: number, factor: number): Promise { + await this.enqueueNativeCall(() => { + this.communicator.setUnderlayDimBelowZOrderFactor256(Math.round(belowZOrder), dimFactor256(factor)); + }); + } + + async setSurfaceVisible(id: string, visible: boolean): Promise { + await this.enqueueNativeCall(() => { this.communicator.setSurfaceVisibleIdVisible(id, Boolean(visible)); }); + } + + async setScreenBlanked(blanked: boolean): Promise { + await this.enqueueNativeCall(() => { this.communicator.setScreenBlankedBlanked(Boolean(blanked)); }); + } + + async submitSurfaceFrame( + surfaceId: string, + pixels8bpp: Uint8Array, + rect: { x: number; y: number; width: number; height: number }, + fingerprint: string, + paintMs = -1, + frameId = 0, + glyphs: ArrayBuffer | null = null, + ): Promise { + const snapshot = new Uint8Array(pixels8bpp); + const draws = glyphs ? toData(new Uint8Array(glyphs)) : null; + await this.enqueueNativeCall(() => { + this.communicator.submitSurfaceFramePixels8bppSurfaceIdRectXRectYRectWidthRectHeightContentFingerprintPaintMsFrameIdGlyphs( + toData(snapshot), surfaceId, Math.round(rect.x), Math.round(rect.y), Math.round(rect.width), Math.round(rect.height), + fingerprint, Math.round(nonNegativeNumber(paintMs)), Math.round(nonNegativeNumber(frameId)), draws, + ); + }, true); + } + + // ----- controls -------------------------------------------------------------------- + + async disconnect(): Promise { + await this.enqueueNativeCall(() => this.communicator.disconnect()); + } + + async sendShutdown(exitMode = 0): Promise { + return this.enqueueNativeCall(() => Boolean(this.communicator.sendShutdownExitMode(exitMode))); + } + + async sendCfwCleanup(): Promise { + return this.enqueueNativeCall(() => Boolean(this.communicator.sendCfwCleanup())); + } + + async suspendEvenHubSession(): Promise { + return this.enqueueNativeCall(() => Boolean(this.communicator.suspendEvenHubSession())); + } + + async resumeEvenHubSession(): Promise { + return this.enqueueNativeCall(() => Boolean(this.communicator.resumeEvenHubSession())); + } + + async setFaceclawWakeLeaseEnabled(enabled: boolean): Promise { + return this.enqueueNativeCall(() => Boolean(this.communicator.setFaceclawWakeLeaseEnabledEnabled(Boolean(enabled)))); + } + + async awaitEvenHubSessionReady(timeoutMs: number): Promise { + return this.enqueueNativeCall(() => Boolean(this.communicator.awaitEvenHubSessionReadyTimeoutMs(Math.round(nonNegativeNumber(timeoutMs))))); + } + + /** Play a CFW mode-5 kind-4 tone sequence (complete wire payload). */ + async playBuzzerSequence(payload: Uint8Array): Promise { + const snapshot = new Uint8Array(payload); + await this.enqueueNativeCall(() => { this.communicator.playBuzzerSequencePayload(toData(snapshot)); }); + } + + async close(): Promise { + this.setAncsListeners(false); + await this.enqueueNativeCall(() => this.communicator.close()); + } + + // ----- iOS extras: compass, microphone, iPhone notifications (ANCS) ---------------------- + + /** CFW mode-10 compass on behalf of `owner`; the magnetometer runs while any owner wants it. */ + setCompassEnabled(enabled: boolean, owner = "compass"): void { + this.communicator.setCompassEnabledForOwnerOwnerEnable(owner, Boolean(enabled)); + } + + /** Compass heading/calibration events, delivered on the main queue. */ + addCompassListener(listener: (event: CompassEvent) => void): () => void { + const proxy = CompassListener.new() as CompassListener; + proxy.handler = listener; + this.communicator.addCompassListenerListener(proxy); + return () => { this.communicator.removeCompassListenerListener(proxy); }; + } + + /** + * Serialized glasses microphone enable/disable (the voice bridge's + * IosMicrophoneSession contract). A release while an enable awaits its ACK + * still wins: the token check drops the stale packets. + */ + setMicrophone(enabled: boolean, listener?: (packet: Uint8Array) => void): Promise { + const token = ++this.microphoneToken; + const work = this.microphoneWork.catch(() => {}).then(async () => { + if (token !== this.microphoneToken) return; + if (!enabled) { + this.audioListener = null; + await this.enqueueNativeCall(() => this.communicator.stopG2AudioCapture()); + return; + } + if (!this.isSessionReady()) throw new Error("Connect the glasses before starting voice input."); + const proxy = AudioPacketListener.new() as AudioPacketListener; + proxy.handler = (packet) => { if (token === this.microphoneToken && listener) listener(packet); }; + this.audioListener = proxy; + const started = await this.enqueueNativeCall(() => Boolean(this.communicator.startG2AudioCaptureNsDataListener(proxy))); + if (!started) { + this.audioListener = null; + throw new Error("The glasses did not enable their microphone. Reconnect and try again."); + } + }); + this.microphoneWork = work; + return work; + } + + /** Ask CoreBluetooth for ANCS on the right arm's next connection (call before start()). */ + setRequiresAncs(required: boolean): void { + this.communicator.setRequiresAncsRequired(Boolean(required)); + this.setAncsListeners(required); + } + + isAncsAuthorized(): boolean { + return Boolean(this.communicator.isAncsAuthorized()); + } + + onAncsAuthorization(listener: (authorized: boolean) => void): () => void { + this.ancsAuthorizationListeners.add(listener); + return () => this.ancsAuthorizationListeners.delete(listener); + } + + /** Relay frames ('A','N',...) received on the right arm, for the ANCS client. */ + onAncsRelayFrame(listener: (frame: Uint8Array) => void): () => void { + this.ancsRelayListeners.add(listener); + return () => this.ancsRelayListeners.delete(listener); + } + + /** Queue one relay packet for the right arm; the Kotlin side writes it off the JS thread. */ + async writeRawToRight(packet: Uint8Array): Promise { + if (!this.isSessionReady()) throw new Error("Glasses are not connected."); + const snapshot = new Uint8Array(packet); + this.communicator.writeRawToRightPacket(toData(snapshot)); + } + + /** The right arm's usable write payload for relay packets (20 until connected). */ + rightWriteLimit(): number { + return Number(this.communicator.rightWriteLimit()) || 20; + } + + private setAncsListeners(install: boolean): void { + if (install && !this.ancsProxy) { + this.ancsProxy = AncsListener.new() as AncsListener; + this.ancsProxy.bridge = this; + this.communicator.setAncsListenerListener(this.ancsProxy); + } else if (!install && this.ancsProxy) { + this.communicator.setAncsListenerListener(null); + this.ancsProxy = null; + } + } +} diff --git a/app/native/firmware-flasher.ios.ts b/app/native/firmware-flasher.ios.ts index bcbf8613..c52e3b80 100644 --- a/app/native/firmware-flasher.ios.ts +++ b/app/native/firmware-flasher.ios.ts @@ -1,83 +1,124 @@ import { Application } from '@nativescript/core' -import { StockConnection } from '../g2/stock-connection' -import { flashLensImage, validateFirmware } from '../g2/firmware-ota' import { CFW_PATCH_SET } from '../g2/firmware/cfw-patches' import { firmwareSha256, readFirmwareFile } from './firmware-files.ios' import { iosBluetooth } from './ios-bluetooth' -import type { FlashState, FlashProgress } from './firmware-flasher' -export type { FlashState, FlashProgress } from './firmware-flasher' +import { kotlinListener } from './kotlin-listener.ios' +import type { FlashState, FlashProgress } from '../g2/firmware-types' +export type { FlashState, FlashProgress } from '../g2/firmware-types' +declare const FaceclawKitIosFirmwareFlasher: any, FaceclawKitFaceclawFirmwareFlasherListener: any + +/** + * iOS twin of the Android FirmwareFlasher wrapper. The OTA transfer itself is the shared + * Kotlin OtaFlashFlow over a CoreBluetooth central (FaceclawKitIosFirmwareFlasher); this + * wrapper keeps the iOS-only policy around it: the image must still hash to the prepared + * custom (or pinned stock) firmware, the phone must stay in the foreground with the screen + * awake, and MAC addresses are mapped to peripheral identifiers first. + */ export class FirmwareFlasher { - private logs = new Set<(line: string) => void>() - private states = new Set<(state: FlashState, detail: string) => void>() - private progresses = new Set<(value: FlashProgress) => void>() - private completes = new Set<(success: boolean, detail: string) => void>() - private link = new StockConnection(iosBluetooth(), line => this.log(line)) + private flasher: any = null + private listenerProxy: object | null = null + private readonly logListeners = new Set<(line: string) => void>() + private readonly progressListeners = new Set<(progress: FlashProgress) => void>() + private readonly stateListeners = new Set<(state: FlashState, detail: string) => void>() + private readonly completeListeners = new Set<(success: boolean, detail: string) => void>() private started = false + private finished = false private cancelled = false - private sleeps = new Set<() => void>() private foregroundError = '' - constructor(private addresses: { right: string; left: string }, private path: string) {} - onLog(fn: (line: string) => void): () => void { this.logs.add(fn); return () => this.logs.delete(fn) } - onStateChange(fn: (state: FlashState, detail: string) => void): () => void { this.states.add(fn); return () => this.states.delete(fn) } - onProgress(fn: (value: FlashProgress) => void): () => void { this.progresses.add(fn); return () => this.progresses.delete(fn) } - onComplete(fn: (success: boolean, detail: string) => void): () => void { this.completes.add(fn); return () => this.completes.delete(fn) } - private log(line: string): void { for (const fn of this.logs) fn(line) } - private state(state: FlashState, detail = ''): void { for (const fn of this.states) fn(state, detail) } - start(): void { if (!this.started) { this.started = true; void this.run() } } + private previousIdle = false + + constructor(private readonly addresses: { right: string; left: string }, private readonly path: string) {} + + onLog(listener: (line: string) => void): () => void { + this.logListeners.add(listener) + return () => this.logListeners.delete(listener) + } + + onProgress(listener: (progress: FlashProgress) => void): () => void { + this.progressListeners.add(listener) + return () => this.progressListeners.delete(listener) + } + + onStateChange(listener: (state: FlashState, detail: string) => void): () => void { + this.stateListeners.add(listener) + return () => this.stateListeners.delete(listener) + } + + onComplete(listener: (success: boolean, detail: string) => void): () => void { + this.completeListeners.add(listener) + return () => this.completeListeners.delete(listener) + } + + start(): void { + if (this.started) return + this.started = true + void this.run() + } + private readonly backgrounded = () => { this.foregroundError = 'Flashing was interrupted because Faceclaw left the foreground. Keep both lenses charged, return to Faceclaw, and retry both lenses.' this.cancel() } + private async run(): Promise { - const previousIdle = UIApplication.sharedApplication.idleTimerDisabled + this.previousIdle = UIApplication.sharedApplication.idleTimerDisabled UIApplication.sharedApplication.idleTimerDisabled = true Application.on(Application.suspendEvent, this.backgrounded) - let success = false, detail = '' try { - this.link.check() if (UIApplication.sharedApplication.applicationState !== UIApplicationState.Active) throw new Error('Keep Faceclaw open on the iPhone while flashing.') - this.state('validating') + this.emit(this.stateListeners, 'validating', '') const image = readFirmwareFile(this.path) const hash = firmwareSha256(image.buffer) if (![CFW_PATCH_SET.outputSha256, CFW_PATCH_SET.baseSha256].includes(hash)) throw new Error('Prepared firmware failed SHA-256 verification. Prepare the firmware again before flashing.') - const segments = validateFirmware(image) - await this.link.resolve({ ...this.addresses, ring: '' }) - for (const role of ['left', 'right']) { - if (role === 'right') { - this.state('rebooting', 'Left lens done. Both lenses reboot briefly; reconnecting for the right lens.') - await this.delay(5000) - } - this.state('connecting', role) - const deadline = Date.now() + (role === 'left' ? 30_000 : 120_000) - for (;;) { - try { await this.link.connect(role, true); await this.link.authenticate(role); break } - catch (error) { this.link.check(); this.link.disconnect(role); if (Date.now() >= deadline) throw error; await this.delay(2500) } - } - await this.delay(2500) - this.state('flashing', role) - await flashLensImage(this.link, role, image, segments, value => { for (const fn of this.progresses) fn(value) }, line => this.log(line), ms => this.delay(ms)) - this.link.disconnect(role) - } - success = true; detail = 'Both lenses flashed. Your glasses are rebooting.' + const identifiers = await iosBluetooth().resolveDevices({ ...this.addresses, ring: '' }) + if (this.cancelled) throw new Error('Cancelled.') + this.flasher = FaceclawKitIosFirmwareFlasher.alloc().initWithRightAddressLeftAddressFirmwarePath(identifiers.right ?? '', identifiers.left ?? '', this.path) + this.listenerProxy = kotlinListener(FaceclawKitFaceclawFirmwareFlasherListener, { + onLogLine: (line: string) => this.emit(this.logListeners, String(line ?? '')), + onProgressLensComponentIndexComponentCountBlockIndexBlockCountBytesSentBytesTotal: ( + lens: string, componentIndex: number, componentCount: number, blockIndex: number, blockCount: number, bytesSent: number, bytesTotal: number, + ) => this.emit(this.progressListeners, { + lens: String(lens ?? ''), componentIndex: Number(componentIndex), componentCount: Number(componentCount), + blockIndex: Number(blockIndex), blockCount: Number(blockCount), bytesSent: Number(bytesSent), bytesTotal: Number(bytesTotal), + }), + onStateStateDetail: (state: string, detail: string) => { + // The terminal state is reported by finish() so a foreground/cancel reason can replace the detail. + const name = String(state) as FlashState + if (name !== 'done' && name !== 'error') this.emit(this.stateListeners, name, String(detail ?? '')) + }, + onCompleteSuccessDetail: (success: boolean, detail: string) => this.finish(Boolean(success), String(detail ?? '')), + }) + this.flasher.setListenerListener(this.listenerProxy) + this.flasher.start() } catch (error) { - detail = this.foregroundError || (this.cancelled ? 'Cancelled. Retry with both lenses powered on to complete installation.' : String((error as Error).message ?? error)) - } finally { - Application.off(Application.suspendEvent, this.backgrounded) - UIApplication.sharedApplication.idleTimerDisabled = previousIdle - this.link.close() + this.finish(false, String((error as Error).message ?? error)) } - this.state(success ? 'done' : 'error', detail) - for (const fn of this.completes) fn(success, detail) } - private delay(ms: number): Promise { - this.link.check() - return new Promise((resolve, reject) => { - const cancel = () => { clearTimeout(timer); this.sleeps.delete(cancel); reject(new Error('Cancelled.')) } - const timer = setTimeout(() => { this.sleeps.delete(cancel); resolve() }, ms) - this.sleeps.add(cancel) - }) + + private finish(success: boolean, detail: string): void { + if (this.finished) return + this.finished = true + Application.off(Application.suspendEvent, this.backgrounded) + UIApplication.sharedApplication.idleTimerDisabled = this.previousIdle + try { this.flasher?.close() } catch { /* ignore */ } + const message = success ? detail + : this.foregroundError || (this.cancelled ? 'Cancelled. Retry with both lenses powered on to complete installation.' : detail) + this.emit(this.stateListeners, success ? 'done' : 'error', message) + this.emit(this.completeListeners, success, message) } - cancel(): void { this.cancelled = true; this.link.close(); for (const cancel of [...this.sleeps]) cancel() } + + cancel(): void { + this.cancelled = true + try { this.flasher?.cancel() } catch { /* ignore */ } + // Before the Kotlin flow exists (validation, address resolution) nothing will report completion. + if (!this.flasher) this.finish(false, 'Cancelled.') + } + close(): void { this.cancel() } + + private emit(listeners: Set<(...args: A) => void>, ...args: A): void { + const snapshot = Array.from(listeners) + setTimeout(() => { for (const listener of snapshot) listener(...args) }, 0) + } } diff --git a/app/native/flash-prompt-communicator.ios.ts b/app/native/flash-prompt-communicator.ios.ts index bea0933f..62e918b3 100644 --- a/app/native/flash-prompt-communicator.ios.ts +++ b/app/native/flash-prompt-communicator.ios.ts @@ -1,88 +1,98 @@ -import { StockConnection } from '../g2/stock-connection' -import { createFlashPrompt, flashPromptSelection } from '../g2/flash-prompt-protocol' -import * as p from '../g2/ble-protocol' import { iosBluetooth } from './ios-bluetooth' +import { kotlinListener } from './kotlin-listener.ios' import type { FlashPromptBattery, FlashPromptState } from './flash-prompt-communicator' export type { FlashPromptBattery, FlashPromptState } from './flash-prompt-communicator' +declare const FaceclawKitIosFlashPrompt: any, FaceclawKitFaceclawFlashPromptListener: any + +function normalizePercent(value: number): number | null { + const n = Number(value) + return Number.isFinite(n) && n >= 0 ? n : null +} + +/** + * iOS twin of the Android FlashPromptCommunicator wrapper over the shared Kotlin + * FlashPromptFlow (FaceclawKitIosFlashPrompt): connects and authenticates both arms, shows + * the pre-flash Yes/No page on the glasses (unless skipPrompt) and reads each arm's battery. + */ export class FlashPromptCommunicator { - private logs = new Set<(line: string) => void>() - private states = new Set<(state: FlashPromptState, detail: string) => void>() - private results = new Set<(approved: boolean) => void>() - private batteries = new Set<(battery: FlashPromptBattery) => void>() - private link = new StockConnection(iosBluetooth(), line => { for (const fn of this.logs) fn(line) }) + private communicator: any = null + private listenerProxy: object | null = null + private readonly logListeners = new Set<(line: string) => void>() + private readonly stateListeners = new Set<(state: FlashPromptState, detail: string) => void>() + private readonly resultListeners = new Set<(approved: boolean) => void>() + private readonly batteryListeners = new Set<(battery: FlashPromptBattery) => void>() + private started = false private closed = false - private started = false - private heartbeat: ReturnType | null = null - private stopSelection: (() => void) | null = null - constructor(private addresses: { right: string; left: string }, private warning: string, private options?: { skipPrompt?: boolean }) {} - onLog(fn: (line: string) => void): () => void { this.logs.add(fn); return () => this.logs.delete(fn) } - onStateChange(fn: (state: FlashPromptState, detail: string) => void): () => void { this.states.add(fn); return () => this.states.delete(fn) } - onResult(fn: (approved: boolean) => void): () => void { this.results.add(fn); return () => this.results.delete(fn) } - onBattery(fn: (battery: FlashPromptBattery) => void): () => void { this.batteries.add(fn); return () => this.batteries.delete(fn) } - private state(state: FlashPromptState, detail = ''): void { for (const fn of this.states) fn(state, detail) } - start(): void { if (!this.started) { this.started = true; void this.run() } } + + constructor( + private readonly addresses: { right: string; left: string }, + private readonly warningText: string, + private readonly options?: { skipPrompt?: boolean }, + ) {} + + onLog(listener: (line: string) => void): () => void { + this.logListeners.add(listener) + return () => this.logListeners.delete(listener) + } + + onStateChange(listener: (state: FlashPromptState, detail: string) => void): () => void { + this.stateListeners.add(listener) + return () => this.stateListeners.delete(listener) + } + + onBattery(listener: (battery: FlashPromptBattery) => void): () => void { + this.batteryListeners.add(listener) + return () => this.batteryListeners.delete(listener) + } + + onResult(listener: (approved: boolean) => void): () => void { + this.resultListeners.add(listener) + return () => this.resultListeners.delete(listener) + } + + start(): void { + if (this.started) return + this.started = true + void this.run() + } + private async run(): Promise { + let identifiers: Record try { - this.state('connecting') - await this.link.resolve({ ...this.addresses, ring: '' }) - // Complete pairing for one peripheral before starting the other. - for (const role of ['right', 'left']) { - await this.link.connect(role) - if (role === 'right') this.state('connected') - await this.link.authenticate(role) - } - await this.link.request('right', p.SID.launch, p.prelude, 3500, 156) - if (!this.options?.skipPrompt) { - // Listen before creating the page: an immediate tap may precede its ACK. - const selection = this.selection() - // Attach a rejection handler immediately, even while create-page is pending. - void selection.catch(() => {}) - for (let attempt = 0; ; attempt++) { - try { await this.link.request('right', p.SID.hub, magic => createFlashPrompt(magic, this.warning)); break } - catch (error) { this.link.check(); if (attempt) throw error } - } - this.state('prompting') - this.heartbeat = setInterval(() => { - void this.link.write('right', p.SID.hub, p.heartbeat(this.link.nextMagic())).catch(error => { - if (!this.closed) this.state('error', String(error.message ?? error)) - this.close() - }) - }, 4000) - const approved = await selection - this.stopHeartbeat() - // Stock shutdown returns the glasses to their normal UI before OTA. - await this.link.write('right', p.SID.hub, p.concat(p.integer(1, 9), p.integer(2, this.link.nextMagic()), p.bytes(11, p.integer(1, 0)))) - if (!approved) { for (const fn of this.results) fn(false); return } - } - this.state('battery') - const battery: FlashPromptBattery = { right: null, left: null } - for (const role of ['right', 'left'] as const) { - for (let attempt = 0; attempt < 2; attempt++) { - try { - const message = await this.link.request(role, p.SID.settings, p.settingsQuery) - const values = p.readBytes(message.payload, 4), value = values ? p.readInteger(values, 12, -1) : -1 - if (value >= 0 && value <= 100) { battery[role] = value; break } - } catch (error) { this.link.check() } - } - } - for (const fn of this.batteries) fn(battery) - for (const fn of this.results) fn(true) - } catch (error) { if (!this.closed) this.state('error', String((error as Error).message ?? error)) } - finally { this.close() } + this.emit(this.stateListeners, 'connecting', '') + identifiers = await iosBluetooth().resolveDevices({ ...this.addresses, ring: '' }) + } catch (error) { + if (!this.closed) this.emit(this.stateListeners, 'error', String((error as Error).message ?? error)) + return + } + if (this.closed) return + this.communicator = FaceclawKitIosFlashPrompt.alloc().initWithRightAddressLeftAddressWarningTextSkipPrompt( + identifiers.right ?? '', identifiers.left ?? '', this.warningText, Boolean(this.options?.skipPrompt)) + this.listenerProxy = kotlinListener(FaceclawKitFaceclawFlashPromptListener, { + onLogLine: (line: string) => this.emit(this.logListeners, String(line ?? '')), + onStateStateDetail: (state: string, detail: string) => + this.emit(this.stateListeners, String(state) as FlashPromptState, String(detail ?? '')), + onBatteryRightPercentLeftPercent: (rightPercent: number, leftPercent: number) => + this.emit(this.batteryListeners, { right: normalizePercent(rightPercent), left: normalizePercent(leftPercent) }), + onResultApproved: (approved: boolean) => this.emit(this.resultListeners, Boolean(approved)), + }) + this.communicator.setListenerListener(this.listenerProxy) + this.communicator.start() + } + + cancel(): void { + this.closed = true + try { this.communicator?.cancel() } catch { /* ignore */ } } - private selection(): Promise { - return new Promise((resolve, reject) => { - const cleanup = () => { clearTimeout(timer); off(); this.stopSelection = null } - const off = this.link.onMessage((role, message) => { - const result = role === 'right' ? flashPromptSelection(message) : null - if (result !== null) { cleanup(); resolve(result) } - }) - const timer = setTimeout(() => { cleanup(); reject(new Error('No response from the glasses.')) }, 120_000) - this.stopSelection = () => { cleanup(); reject(new Error('Cancelled.')) } - }) + + close(): void { + this.closed = true + try { this.communicator?.close() } catch { /* ignore */ } + } + + private emit(listeners: Set<(...args: A) => void>, ...args: A): void { + const snapshot = Array.from(listeners) + setTimeout(() => { for (const listener of snapshot) listener(...args) }, 0) } - private stopHeartbeat(): void { if (this.heartbeat) clearInterval(this.heartbeat); this.heartbeat = null } - cancel(): void { this.close() } - close(): void { this.closed = true; this.stopHeartbeat(); this.stopSelection?.(); this.link.close() } } diff --git a/app/native/ios-bluetooth.ts b/app/native/ios-bluetooth.ts index 20bc5025..b1016b29 100644 --- a/app/native/ios-bluetooth.ts +++ b/app/native/ios-bluetooth.ts @@ -1,75 +1,80 @@ import { ApplicationSettings } from '@nativescript/core' import { identifyIosPeripheral, type IosAdvertisement, type IosDevice } from '../g2/ios-peripheral-identity' import { hexToBytes } from '../util/hex-util' +import { kotlinListener } from './kotlin-listener.ios' -declare const FaceclawBluetooth: any -type NativeEvent = { kind: string; id?: number; error?: string; details?: ConnectionDetails; state?: number; - identifier?: string; characteristic?: string; data?: string; message?: string } & Partial -export type ConnectionDetails = { characteristics: string[]; maxWrite: number } -export type BluetoothEvent = NativeEvent | { kind: 'device'; device: IosDevice } -type Pending = { resolve: (details: ConnectionDetails) => void; reject: (error: Error) => void; timer: ReturnType } +declare const FaceclawKitIosBleCentral: any, FaceclawKitIosProtocolPlatform: any, FaceclawKitIosBleScanListener: any -/** One central manager per app, with asynchronous main-queue GATT operations. */ +/** CBManagerState raw values reported by the Kotlin central. */ +export const BLE_STATE_UNSUPPORTED = 2, BLE_STATE_UNAUTHORIZED = 3, BLE_STATE_POWERED_OFF = 4, BLE_STATE_POWERED_ON = 5 + +export type BluetoothEvent = + | { kind: 'state'; state: number; authorization: number } + | { kind: 'advertisement'; identifier: string; name: string; manufacturerData: string; rssi: number; connectable: boolean } + | { kind: 'device'; device: IosDevice } + | { kind: 'scan-started' } + | { kind: 'scan-stopped' } + +/** + * Scanning and MAC-address-to-identifier resolution over the shared Kotlin CoreBluetooth + * central (FaceclawKitIosBleCentral). GATT sessions no longer pass through here: the + * session and stock-firmware flows own their own Kotlin centrals. What stays in TypeScript + * is the Even classification of advertisements and the persisted identifier map, which the + * Android address model (MACs) needs on iOS. + */ export class IosBluetooth { - private readonly native = FaceclawBluetooth.new() + private readonly native = FaceclawKitIosBleCentral.alloc().initWithPlatform(FaceclawKitIosProtocolPlatform.shared) private readonly listeners = new Set<(event: BluetoothEvent) => void>() - private readonly pending = new Map() - private readonly advertisements = new Map() readonly devices = new Map() - private requestId = 0 private scanTimer: ReturnType | null = null private scanGeneration = 0 + private readonly scanListener: object state = 0 + authorization = 0 scanning = false constructor() { - this.native.eventHandler = (json: string) => { - try { this.receive(JSON.parse(json)) } catch (error) { console.error(`[ios-ble] ${error}`) } - } + this.scanListener = kotlinListener(FaceclawKitIosBleScanListener, { + onBluetoothStateStateAuthorization: (state: number, authorization: number) => { + this.state = Number(state); this.authorization = Number(authorization) + this.emit({ kind: 'state', state: this.state, authorization: this.authorization }) + }, + onAdvertisementIdentifierNameManufacturerDataHexRssiConnectable: (identifier: string, name: string, manufacturerData: string, rssi: number, connectable: boolean) => { + // The Kotlin central already merges split advertisements and bounds its cache. + const raw: IosAdvertisement = { identifier: String(identifier), name: String(name ?? ''), manufacturerData: String(manufacturerData ?? ''), rssi: Number(rssi), connectable: connectable !== false } + this.emit({ kind: 'advertisement', ...raw }) + const device = identifyIosPeripheral(raw) + if (device) { + this.devices.set(device.address, device) + ApplicationSettings.setString(`ios.ble.peripheral.${device.address}`, JSON.stringify({ identifier: device.identifier, role: device.role })) + this.emit({ kind: 'device', device }) + } + }, + }) + this.native.setScanListenerListener(this.scanListener) } onEvent(listener: (event: BluetoothEvent) => void): () => void { this.listeners.add(listener); return () => { this.listeners.delete(listener) } } private emit(event: BluetoothEvent): void { for (const listener of [...this.listeners]) listener(event) } - private receive(event: NativeEvent): void { - if (event.kind === 'completion') { - const pending = this.pending.get(event.id!) - if (pending) { - this.pending.delete(event.id!); clearTimeout(pending.timer) - if (event.error) pending.reject(new Error(event.error)); else pending.resolve(event.details!) - } - return - } - if (event.kind === 'state') this.state = event.state! - if (event.kind === 'advertisement') { - const previous = this.advertisements.get(event.identifier!) - const raw: IosAdvertisement = { identifier: event.identifier!, name: event.name || previous?.name || '', - manufacturerData: event.manufacturerData || previous?.manufacturerData || '', rssi: event.rssi!, connectable: event.connectable !== false } - // Bound the cache even in a crowded radio environment. - if (this.advertisements.size >= 512 && !this.advertisements.has(raw.identifier)) this.advertisements.delete(this.advertisements.keys().next().value!) - this.advertisements.set(raw.identifier, raw) - const device = identifyIosPeripheral(raw) - if (device) { - this.devices.set(device.address, device) - ApplicationSettings.setString(`ios.ble.peripheral.${device.address}`, JSON.stringify({ identifier: device.identifier, role: device.role })) - this.emit({ kind: 'device', device }) - } - return - } - this.emit(event) + /** Creates the central (first use shows the Bluetooth permission prompt) without blocking the JS thread. */ + private ensureCentral(): void { + // A zero timeout returns immediately after creating the central; the state arrives + // through the scan listener on the main queue. + this.native.waitForPoweredOnTimeoutMs(0) } ensureReady(): Promise { + if (this.state === BLE_STATE_POWERED_ON) return Promise.resolve() return new Promise((resolve, reject) => { const finish = (error?: Error) => { clearTimeout(timer); off(); error ? reject(error) : resolve() } const off = this.onEvent(event => { if (event.kind !== 'state') return - const state = (event as NativeEvent).state - if (state === 5) finish() - else if (state === 2) finish(new Error('Bluetooth is unavailable on this device. Use the physical iPhone.')) - else if (state === 3) finish(new Error('Allow Faceclaw to use Bluetooth in iPhone Settings.')) - else if (state === 4) finish(new Error('Turn on Bluetooth, then try again.')) + if (event.state === BLE_STATE_POWERED_ON) finish() + else if (event.state === BLE_STATE_UNSUPPORTED) finish(new Error('Bluetooth is unavailable on this device. Use the physical iPhone.')) + else if (event.state === BLE_STATE_UNAUTHORIZED) finish(new Error('Allow Faceclaw to use Bluetooth in iPhone Settings.')) + else if (event.state === BLE_STATE_POWERED_OFF) finish(new Error('Turn on Bluetooth, then try again.')) }) const timer = setTimeout(() => finish(new Error('Waiting for Bluetooth permission timed out. Try again after allowing Bluetooth.')), 30_000) - this.native.initializeBluetooth() + this.ensureCentral() }) } async startScan(durationMs = 12_000): Promise { @@ -77,17 +82,18 @@ export class IosBluetooth { const generation = this.scanGeneration await this.ensureReady() if (generation !== this.scanGeneration) throw new Error('Bluetooth scan cancelled') - this.scanning = true; this.native.scan(true) + this.scanning = true; this.native.startScan() this.scanTimer = setTimeout(() => this.stopScan(), durationMs) this.emit({ kind: 'scan-started' }) } stopScan(): void { ++this.scanGeneration if (this.scanTimer) clearTimeout(this.scanTimer) - this.scanTimer = null; this.native.scan(false) + this.scanTimer = null const wasScanning = this.scanning; this.scanning = false - if (wasScanning) this.emit({ kind: 'scan-stopped' }) + if (wasScanning) { this.native.stopScan(); this.emit({ kind: 'scan-stopped' }) } } + /** Peripheral identifiers for the stored MAC addresses, scanning for any that are not remembered. */ async resolveDevices(addresses: { left: string; right: string; ring: string }): Promise> { const generation = this.scanGeneration await this.ensureReady() @@ -109,7 +115,7 @@ export class IosBluetooth { await new Promise((resolve, reject) => { const off = this.onEvent(event => { if (event.kind === 'device') { - const device = (event as { device: IosDevice }).device + const device = event.device for (const role of ['left', 'right', 'ring'] as const) { if (addresses[role] === device.address && device.role === role) result[role] = device.identifier } @@ -123,29 +129,6 @@ export class IosBluetooth { }) return result } - private operation(identifier: string, call: (id: number) => void, timeoutMs = 10_000, disconnectOnTimeout = true): Promise { - const id = ++this.requestId - return new Promise((resolve, reject) => { - const timer = setTimeout(() => { - this.pending.delete(id); if (disconnectOnTimeout) this.native.disconnect(identifier) - reject(new Error('Bluetooth operation timed out. Wake the device and try connecting again.')) - }, timeoutMs) - this.pending.set(id, { resolve, reject, timer }) - try { call(id) } catch (error) { clearTimeout(timer); this.pending.delete(id); reject(error) } - }) - } - connect(identifier: string, requiresANCS = false): Promise { return this.operation(identifier, id => this.native.connectRequiresANCSRequestId(identifier, requiresANCS, id), 20_000) } - async subscribe(identifier: string, characteristic: string): Promise { - // R1 exposes two notification channels; one may never complete its CCCD - // request. Keep the link alive so the other channel can still be tried. - await this.operation(identifier, id => this.native.subscribeCharacteristicRequestId(identifier, characteristic, id), 30_000, false) - } - async write(identifier: string, characteristic: string, bytes: Uint8Array): Promise { - const copy = new Uint8Array(bytes) - const data = NSData.dataWithBytesLength(interop.handleof(copy.buffer), copy.byteLength) - await this.operation(identifier, id => this.native.writeCharacteristicDataRequestId(identifier, characteristic, data, id)) - } - disconnect(identifier: string): void { this.native.disconnect(identifier) } forget(address: string): void { ApplicationSettings.remove(`ios.ble.peripheral.${address}`); this.devices.delete(address) } } let instance: IosBluetooth | null = null diff --git a/app/native/kotlin-listener.ios.ts b/app/native/kotlin-listener.ios.ts new file mode 100644 index 00000000..8bbab1bb --- /dev/null +++ b/app/native/kotlin-listener.ios.ts @@ -0,0 +1,10 @@ +/** + * Implements a FaceclawKit (Kotlin) listener protocol with plain JavaScript methods. + * NativeScript maps the method names to the protocol's selectors by camel-casing the + * selector parts (`onLog:` -> `onLogLine`, `onState:detail:` -> `onStateStateDetail`, ...). + * Keep a reference to the returned object for as long as the Kotlin side may call it. + */ +export function kotlinListener(protocol: unknown, methods: T): T { + const NativeListener = (NSObject as any).extend(methods, { protocols: [protocol] }) + return NativeListener.new() as T +} diff --git a/app/native/kotlin-protocol-smoke.ios.ts b/app/native/kotlin-protocol-smoke.ios.ts index f2221d5b..ecd2629e 100644 --- a/app/native/kotlin-protocol-smoke.ios.ts +++ b/app/native/kotlin-protocol-smoke.ios.ts @@ -1,14 +1,9 @@ -import { CFW_MSG_BOUNDING_BOX, CFW_MSG_CREATE_SURFACE, CFW_MSG_PRESENT, CFW_MSG_UPLOAD_RESOURCE } from "../g2/cfw-message-type"; import { GrayImage } from "../graphics/image" import { encodeShellScene } from "../graphics/shell-scene" import { decodeImageBytes } from './image-bytes.ios' import * as protocol from '../g2/ble-protocol.ios' -import { CfwTransport, parseCfwAcks } from '../g2/cfw-transport.ios' import { SurfaceCompositor } from '../graphics/surface-compositor.ios' -import { buildBoundingBoxPayload } from '../g2/ble-image-optimizer.ios' import { lvglMetrics } from './lvgl-font.ios' -import { textureImageId } from './texture-atlas.ios' -import { IosTexturePlanner } from './texture-planner.ios' /** Development-only checks of real NativeScript selectors and bulk data crossings. */ export function runKotlinProtocolSmokeTest(): void { @@ -24,11 +19,6 @@ export function runKotlinProtocolSmokeTest(): void { const payload = protocol.bytes(13, protocol.bytes(3, protocol.concat(protocol.integer(1, 12), protocol.integer(2, 2)))) const event = protocol.decodeGlassesInput({ sid: 224, flag: 1, payload, command: 0, magic: 0 }) assert(event?.kind === 'display-wake' && event.eventSource === 2, 'event') - const transport = new CfwTransport() - const packets = transport.encode(new Uint8Array(128).fill(9), 255, 3, 185) - assert(packets.length > 0 && packets.every(p => p.length <= 185), 'compression') - transport.reset() - assert(parseCfwAcks(new Uint8Array()) === null, 'invalid ACK') const c = new SurfaceCompositor(3, 2) c.configureSurface('test', { x: 0, y: 0, width: 3, height: 2, zOrder: 0, transparency: 'opaque' }) c.submitSurfaceFrame('test', new Uint8Array([0, 16, 255, 32, 48, 64]), { x: 0, y: 0, width: 3, height: 2 }) @@ -37,28 +27,12 @@ export function runKotlinProtocolSmokeTest(): void { c.setShellScene(new Uint8Array([1,0,1,0,0,0,0,0,1,0,1,0,128,0,0,0,0,0,255])) assert(hex(c.composite()) === 'f00070101020', 'shell scene bridge and 4bpp composition') c.setScreenBlanked(true); assert(c.composite().every(p => p === 0), 'blanking') - const textures = new IosTexturePlanner(), textured = new SurfaceCompositor(4, 2) - textured.configureSurface('icon', { x: 0, y: 0, width: 2, height: 2, zOrder: 0, transparency: 'opaque' }) - const white = new Uint8Array(4).fill(255) - const icon = textureImageId('protocol-smoke-white', 2, 2, white) - const draw = new DataView(new ArrayBuffer(9)); draw.setUint8(0, 1); draw.setUint32(1, icon, true) - textured.submitSurfaceFrame('icon', white, { x: 0, y: 0, width: 2, height: 2 }, draw.buffer) - const snapshot = textured.compositeFrame(), packed = protocol.packGray4(snapshot.pixels, 4, 2) - const cold = textures.plan(null, packed, snapshot.textures, 1) - assert(!!cold && cold.resourceCommands.some(command => command[0] === CFW_MSG_UPLOAD_RESOURCE) && cold.payload[0] === CFW_MSG_PRESENT, 'texture upload and draw') - assert(textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length === 0, 'texture reuse') - textures.reset() - assert((textures.plan(null, packed, snapshot.textures, 1)?.resourceCommands.length ?? 0) > 0, 'texture reset') const selectedSurface = new GrayImage(8, 4, 1) selectedSurface.drawMenuSelection(new GrayImage(4, 2, 255), 1, 1, 16, 48, 0, 2) const selectedPreview = new SurfaceCompositor(8, 4) selectedPreview.setShellScene(encodeShellScene([{ image: selectedSurface, x: 0, y: 0, shellKey: 100 }])) - const selectedSnapshot = selectedPreview.compositeFrame() - assert(selectedSnapshot.pixels[10] === 240 && selectedSnapshot.pixels[9] === 0, 'menu selection depth and bridge') - const selectedPlan = new IosTexturePlanner().plan(null, protocol.packGray4(selectedSnapshot.pixels, 8, 4), selectedSnapshot.textures, 1) - assert(!!selectedPlan && selectedPlan.payload[0] === CFW_MSG_PRESENT && selectedPlan.resourceCommands.some(c => c[0] === CFW_MSG_CREATE_SURFACE), 'menu resource planning') - const changed = new Uint8Array(16); changed[0] = 255 - assert(buildBoundingBoxPayload(new Uint8Array(16), changed, 8, 4, 1)?.[0] === CFW_MSG_BOUNDING_BOX, 'image update') + const selectedPixels = selectedPreview.composite() + assert(selectedPixels[10] === 240 && selectedPixels[9] === 0, 'menu selection depth and bridge') assert(lvglMetrics('/nonexistent/faceclaw-font').length === 0, 'font bridge') const compass = protocol.decodeCompassInput({ sid: 8, flag: 1, command: 15, magic: 0, payload: new Uint8Array([8, 15, 16, 0, 82, 3, 8, 231, 2, 162, 6, 12, 67, 77, 1, 3, 2, 3, 140, 0, 152, 186, 220, 254]) }) diff --git a/app/native/preview-display.ios.ts b/app/native/preview-display.ios.ts new file mode 100644 index 00000000..250b6f07 --- /dev/null +++ b/app/native/preview-display.ios.ts @@ -0,0 +1,141 @@ +import { File, knownFolders, path, type ImageSource } from "@nativescript/core"; +import { SurfaceCompositor } from "../graphics/surface-compositor"; +import { G2_LENS_WIDTH, G2_LENS_HEIGHT } from "../graphics/image"; +import { previewPixels } from "./ios-graphics"; +import { toData } from "./kotlin-data"; +import type { FaceclawCommunicatorBridge, SurfaceOptions } from "./faceclaw-communicator.ios"; + +declare const FaceclawKitIosProtocol: any; + +/** The display subset of the communicator bridge; see the Android twin. */ +export type DisplayTarget = Pick< + FaceclawCommunicatorBridge, + | "configureCompositorScreen" + | "configureSurface" + | "removeSurface" + | "setSurfaceVisible" + | "setUnderlayDim" + | "setScreenBlanked" + | "submitSurfaceFrame" + | "submitShellScene" + | "waitForFrameFinished" + | "getCompositePreview" + | "saveScreenshot" + | "startScreenRecording" + | "recordScreenFrame" + | "stopScreenRecording" +>; + +function timestamp(): string { + const now = new Date(); + const pad = (value: number, width = 2) => String(value).padStart(width, "0"); + return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}-${pad(now.getMilliseconds(), 3)}`; +} + +/** + * Headless display target for iOS while no glasses session exists: the same + * shared Kotlin SurfaceCompositor a live session composes with, so the phone + * mirror, apps and shell render identically before connecting. Frames end + * at the compositor; there is no transmit backpressure to wait on. + */ +export class PreviewDisplayTarget implements DisplayTarget { + private compositor = new SurfaceCompositor(G2_LENS_WIDTH, G2_LENS_HEIGHT); + private onFrameComposited: (() => void) | null = null; + private released = false; + + /** Receive a callback per applied frame, the stand-in for the connected path's frame-finished callback. */ + activate(onFrameComposited: () => void): void { + this.onFrameComposited = onFrameComposited; + } + + release(): void { + this.released = true; + this.onFrameComposited = null; + } + + private composited(): void { + if (!this.released) this.onFrameComposited?.(); + } + + async configureCompositorScreen(width: number, height: number): Promise { + if (Math.round(width) !== this.compositor.width || Math.round(height) !== this.compositor.height) { + this.compositor = new SurfaceCompositor(Math.round(width), Math.round(height)); + } + } + + async configureSurface(id: string, options: SurfaceOptions): Promise { + this.compositor.configureSurface(id, { + x: Math.round(options.x), y: Math.round(options.y), width: Math.round(options.width), height: Math.round(options.height), + zOrder: Math.round(options.zOrder), transparency: options.transparency, + }); + } + + async removeSurface(id: string): Promise { + this.compositor.removeSurface(id); + this.composited(); + } + + async setSurfaceVisible(id: string, visible: boolean): Promise { + this.compositor.setSurfaceVisible(id, Boolean(visible)); + this.composited(); + } + + async setUnderlayDim(belowZOrder: number, factor: number): Promise { + this.compositor.setUnderlayDim(Math.round(belowZOrder), Math.max(0, Math.min(1, factor))); + this.composited(); + } + + async setScreenBlanked(blanked: boolean): Promise { + this.compositor.setScreenBlanked(Boolean(blanked)); + this.composited(); + } + + async submitSurfaceFrame( + surfaceId: string, + pixels8bpp: Uint8Array, + rect: { x: number; y: number; width: number; height: number }, + _fingerprint: string, + _paintMs = -1, + _frameId = 0, + glyphs: ArrayBuffer | null = null, + ): Promise { + this.compositor.submitSurfaceFrame(surfaceId, pixels8bpp, + { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) }, glyphs); + this.composited(); + } + + async submitShellScene(bytes: Uint8Array, _paintMs = 0, _frameId = 0): Promise { + this.compositor.setShellScene(bytes); + this.composited(); + } + + /** Nothing transmits: every frame is finished as soon as it is composited. */ + waitForFrameFinished(frameId: number, _timeoutMs: number): Promise { + return Promise.resolve(frameId > 0 ? "composited" : null); + } + + /** The current composite as gray pixels (row-major, compositor size). */ + composite(): Uint8Array { + return this.compositor.composite(); + } + + getCompositePreview(green = false): ImageSource | null { + return previewPixels(this.compositor.composite(), this.compositor.width, this.compositor.height, green); + } + + /** Save the current composite as a 4-bit grayscale PNG under Documents; cropping is not supported on iOS. */ + saveScreenshot(crop?: { x: number; y: number; width: number; height: number }): string { + if (crop) return ""; + const png = FaceclawKitIosProtocol.new().pngDataWidthHeight(toData(this.compositor.composite()), this.compositor.width, this.compositor.height); + if (!png) return ""; + const target = path.join(knownFolders.documents().path, `screen-${timestamp()}.png`); + File.fromPath(target).writeSync(png); + return target; + } + + startScreenRecording(): void {} + + recordScreenFrame(): void {} + + stopScreenRecording(): string { return ""; } +} diff --git a/app/native/remote-input.ios.ts b/app/native/remote-input.ios.ts index 511cd41c..3e6c9b07 100644 --- a/app/native/remote-input.ios.ts +++ b/app/native/remote-input.ios.ts @@ -1,14 +1,16 @@ import { createListenerPool, type InterfaceAddress } from '../remote/listeners'; -declare const FaceclawRemoteInput: any; +declare const FaceclawKitIosRemoteInput: any; +/** The shared Kotlin RemoteInputSession over POSIX sockets; request notifications arrive on the main queue. */ export function remoteNative(onRequestReady: () => void) { return createListenerPool(() => { - const native = FaceclawRemoteInput.alloc().init(); - native.setRequestListener(onRequestReady); - return { start: (port, address) => String(native.startAddress(port, address)), stop: () => { native.setRequestListener(null); native.stop(); }, - nextRequest: () => native.nextRequest(), complete: (id, response) => native.completeResponse(id, response) }; + const native = FaceclawKitIosRemoteInput.new(); + native.setRequestListenerListener(onRequestReady); + return { start: (port, address) => String(native.startAddressPortAddress(port, address)), stop: () => { native.setRequestListenerListener(null); native.stop(); }, + nextRequest: () => native.nextRequest(), complete: (id, response) => native.completeIdValue(id, response) }; }); } -export function remoteInterfaces(): InterfaceAddress[] { return JSON.parse(String(FaceclawRemoteInput.interfaces())); } -export function randomTokenSecret(): string { return String(FaceclawRemoteInput.shared().randomSecret()); } -export function tokenHash(value: string): string { return String(FaceclawRemoteInput.shared().tokenDigest(value)); } +function shared(): any { return FaceclawKitIosRemoteInput.companion.shared; } +export function remoteInterfaces(): InterfaceAddress[] { return JSON.parse(String(shared().interfaces())); } +export function randomTokenSecret(): string { return String(shared().randomSecret()); } +export function tokenHash(value: string): string { return String(shared().tokenDigestValue(value)); } export function copyRemoteToken(value: string): void { UIPasteboard.generalPasteboard.string = value; } diff --git a/app/native/sse.ios.ts b/app/native/sse.ios.ts index bd3e7284..2c5c1609 100644 --- a/app/native/sse.ios.ts +++ b/app/native/sse.ios.ts @@ -1,28 +1,19 @@ import { type SseListener } from './sse-types'; import { withUserAgent } from '../util/http'; +import { kotlinListener } from './kotlin-listener.ios'; export { type SseListener } from './sse-types'; -declare const FaceclawSseRequest: any; +declare const FaceclawKitIosSseRequest: any, FaceclawKitFaceclawSseListener: any; -/** Drain native events on the requesting JS isolate, never on a URLSession thread. */ +/** The shared Kotlin SseStream over NSURLSession; the Kotlin side delivers every callback on the main queue, in order. */ export function openSseRequest(url: string, body: string, headers: Record, listener: SseListener): { cancel(): void } { - const native = FaceclawSseRequest.alloc().initWithURLBodyHeaders(url, body, JSON.stringify(withUserAgent(headers))); let ended = false; - const cancel = () => { if (ended) return; ended = true; clearInterval(timer); native.cancel(); }; - const timer = setInterval(() => { - try { - for (const event of JSON.parse(native.takeEvents())) { - if (ended) break; - if (event.kind === 'line') listener.onLine(event.text); - else { - cancel(); - if (event.kind === 'complete') listener.onComplete(); - else if (event.kind === 'http-error') listener.onHttpError(event.code, event.text); - else listener.onFailure(event.text); - } - } - } catch (error) { - cancel(); listener.onFailure(String((error as Error)?.message ?? error)); - } - }, 25); - return { cancel }; + const once = (deliver: () => void) => { if (ended) return; ended = true; deliver(); }; + const nativeListener = kotlinListener(FaceclawKitFaceclawSseListener, { + onLineLine: (line: string) => { if (!ended) listener.onLine(String(line ?? '')); }, + onHttpErrorCodeBody: (code: number, errorBody: string) => once(() => listener.onHttpError(Number(code), String(errorBody ?? ''))), + onComplete: () => once(() => listener.onComplete()), + onFailureMessage_: (message: string) => once(() => listener.onFailure(String(message ?? ''))), + }); + const native = FaceclawKitIosSseRequest.alloc().initWithUrlBodyHeadersJsonListener(url, body, JSON.stringify(withUserAgent(headers)), nativeListener); + return { cancel: () => { if (ended) return; ended = true; native.cancel(); } }; } diff --git a/app/native/texture-planner.ios.ts b/app/native/texture-planner.ios.ts deleted file mode 100644 index 7de63cbd..00000000 --- a/app/native/texture-planner.ios.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { fromData, toData, nativeArray } from './kotlin-data' -import type { SessionTexturePlanner, TextureFrame, TexturePlan } from '../g2/texture-planner' -declare const FaceclawKitIosTexturePlanner: any - -export class IosTexturePlanner implements SessionTexturePlanner { - private readonly native = FaceclawKitIosTexturePlanner.new() - reset(): void { this.native.reset() } - plan(previous: Uint8Array | null, next: Uint8Array, frame: TextureFrame, firstId: number): TexturePlan | null { - const result = this.native.planPreviousNextFrameFirstId(previous ? toData(previous) : null, toData(next), frame.native, firstId) - return result ? { payload: fromData(result.payload), resourceCommands: nativeArray(result.resourceCommands, fromData), - nextFid: result.nextFid, usedBytes: result.usedBytes } : null - } -} diff --git a/native/kotlin/README.md b/native/kotlin/README.md index 40190770..be2f5147 100644 --- a/native/kotlin/README.md +++ b/native/kotlin/README.md @@ -62,11 +62,14 @@ that remains: the sherpa-onnx classes, which are the vendored Android JNI ABI. PNG/GIF adapters retain only Android storage responsibilities; their codecs are shared. -On `ios-port`, platform adapters route the existing TypeScript session and UI -logic through shared Kotlin for protocol builders, CRC/framing/reassembly, -event decoding, CFW compression/ACKs, changed-image regions, surface composition, -and LVGL glyphs. The original pure TypeScript implementations remain as Node -test references; NativeScript selects the `.ios.ts` native adapters. +On iOS (since 2026-09-22) `iosMain` also hosts the platform actuals for the shared +cores: `ble/IosBleCentral` (CoreBluetooth, implements `SessionLink` and `StockLink` +plus scanning and ANCS authorization), `ble/IosSessionHost`, `ble/IosGlassesSession` +(the facade `app/native/faceclaw-communicator.ios.ts` wraps), `ble/IosStockFlows` +(device-info probe, flash prompt, OTA flasher), `net/IosRemoteInput`, +`net/IosSseRequest`, `net/IosModelDownloader` and `IosFrameTimings`. Callbacks into +TypeScript are always dispatched to the main queue. The former pure-TypeScript +session/protocol duplicates were deleted; their coverage lives in `tests/kotlin`. Texture rendering uses the same `GlyphAtlas`, `ImageAtlas`, `TextureCacheState` and `TexturePlanner` on both platforms. iOS's `IosTextureAtlas` and diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt index aec8d2e0..38af3ba8 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosBleCentral.kt @@ -182,8 +182,14 @@ class IosBleCentral(private val platform: ProtocolPlatform = IosProtocolPlatform central = CBCentralManager(delegate = delegate, queue = queue) } + /** + * Registers the scan/state listener and creates the central if needed, so a listener that + * only waits for readiness (no scan) still receives the state report; an existing central's + * current state is re-reported to the new listener on the main queue. + */ fun setScanListener(listener: IosBleScanListener?) { scanListener = listener + if (listener != null && !closed) ensureCentral() } /** Starts (or keeps) scanning for all peripherals with duplicates; events reach the scan listener on main. */ diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt index 37900640..f4fe2b3d 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt @@ -15,6 +15,11 @@ interface IosAncsListener { fun onRelayFrame(data: NSData) } +/** Audio packets for the NativeScript side as NSData (a Kotlin ByteArray crosses per byte). Main queue. */ +interface IosAudioPacketListener { + fun onAudioPacket(data: NSData, arm: String, arrivalMs: Long) +} + /** * ObjC-facing facade over the shared [GlassesSessionCore] for the NativeScript app: the iOS * counterpart of Android's FaceclawBleCommunicator with the same method names. GATT goes @@ -119,6 +124,16 @@ class IosGlassesSession internal constructor( fun stopG2AudioCapture() = core.stopG2AudioCapture() + /** As [startG2AudioCapture], with packets delivered as NSData on the main queue. */ + fun startG2AudioCaptureNsData(listener: IosAudioPacketListener): Boolean = + core.startG2AudioCapture(NsDataAudioListener(listener)) + + /** The right arm's usable write payload (ATT MTU minus the 3-byte header), or 20 when unknown. */ + fun rightWriteLimit(): Int { + val mtu = try { central?.negotiatedMtu(rightIdentifier) ?: 0 } catch (t: Throwable) { 0 } + return if (mtu > 3) mtu - 3 else 20 + } + fun isAudioCaptureActive(): Boolean = core.isAudioCaptureActive() fun setFaceclawWakeLeaseEnabled(enabled: Boolean): Boolean = core.setFaceclawWakeLeaseEnabled(enabled) @@ -237,6 +252,14 @@ class IosGlassesSession internal constructor( internal fun coreForTests(): GlassesSessionCore = core + private class NsDataAudioListener(private val delegate: IosAudioPacketListener) : FaceclawAudioPacketListener { + override fun onAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { + val packet = (data ?: ByteArray(0)).data() + val label = arm ?: "" + dispatch_async(dispatch_get_main_queue()) { delegate.onAudioPacket(packet, label, arrivalMs) } + } + } + private class MainQueueAudioListener(private val delegate: FaceclawAudioPacketListener) : FaceclawAudioPacketListener { override fun onAudioPacket(data: ByteArray?, arm: String?, arrivalMs: Long) { dispatch_async(dispatch_get_main_queue()) { delegate.onAudioPacket(data, arm, arrivalMs) } diff --git a/tests/ble-image-optimizer.test.cjs b/tests/ble-image-optimizer.test.cjs deleted file mode 100644 index a222728a..00000000 --- a/tests/ble-image-optimizer.test.cjs +++ /dev/null @@ -1,66 +0,0 @@ -const test = require('node:test'); -const assert = require('node:assert/strict'); -const { deflate } = require('pako'); -const { buildBoundingBoxPayload: bbox } = require('../.test-build/app/g2/ble-image-optimizer.js'); -const { applyDisplayPayload } = require('./helpers/display-payload.cjs'); -const { rle4 } = require('../.test-build/app/g2/ble-protocol.js'); - -test('mode-3 payload matches the production Android encoder byte for byte', () => { - // Generated with javac from g2protocol/BleImageOptimizer.java, 2026-09-08. - const vectors = [ - [0, 0, 0xab, '030000010134121a1b60'], - [319, 479, 0x12, '039fef01013412601112'], - [3, 5, 0xa5, '03010201013412601a15'], - ]; - for (const [x, y, value, expected] of vectors) { - const base = new Uint8Array(320 * 480), next = base.slice(); next[y * 320 + x] = value; - const payload = bbox(base, next, 640, 480, 0x1234); - assert.equal(Buffer.from(payload).toString('hex'), expected); - assert.deepEqual(applyDisplayPayload(base, payload), next); - } -}); - -test('bounding boxes include both nibbles, preserve neighboring pixels and cover all four screen edges', () => { - const base = Uint8Array.from({ length: 320 * 480 }, (_, i) => i & 255); - for (const x of [0, 1, 2, 3, 4, 637, 638, 639]) for (const y of [0, 1, 2, 477, 478, 479]) { - const next = base.slice(); next[y * 320 + (x >> 1)] ^= x % 2 ? 15 : 240; - const payload = bbox(base, next, 640, 480, 1); - assert.deepEqual([...payload.slice(1, 5)], [Math.floor(x / 4), Math.floor(y / 2), 1, 1]); - assert.deepEqual(applyDisplayPayload(base, payload), next); - } -}); - -test('unchanged, incompatible and full-screen boxes fall back without compressing a region', () => { - const base = new Uint8Array(320 * 480), next = base.slice(); next[0] = next[next.length - 1] = 255; - const compress = () => assert.fail('A fallback must not compress a bounding box'); - assert.equal(bbox(base, base, 640, 480, 1, compress), null); - assert.equal(bbox(base, next, 640, 480, 1, compress), null); - assert.equal(bbox(null, next, 640, 480, 1, compress), null); - assert.equal(bbox(base.subarray(1), next, 640, 480, 1, compress), null); - assert.equal(bbox(base, next.subarray(1), 640, 480, 1, compress), null); - for (const [w, h] of [[0, 480], [639, 480], [640, 479], [1024, 480], [640, 512]]) - assert.equal(bbox(base, next, w, h, 1, compress), null); -}); - -test('seeded sparse edits reconstruct exactly across successive bounding-box updates', () => { - let seed = 42; - const random = limit => { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; return seed % limit; }; - let base = Uint8Array.from({ length: 320 * 480 }, () => random(256)); - for (let fid = 1; fid <= 60; fid++) { - const next = base.slice(), bx = random(280), by = random(440); - for (let n = 0; n < 20; n++) next[(by + random(40)) * 320 + bx + random(40)] ^= 0xff; - const payload = bbox(base, next, 640, 480, fid); - assert.ok(payload); assert.equal(payload[5] | (payload[6] << 8), fid); - assert.deepEqual(applyDisplayPayload(base, payload), next); - base = next; - } -}); - -test('a small edit encodes only its region on a busy screen', () => { - const base = Uint8Array.from({ length: 320 * 480 }, (_, i) => i & 255), next = base.slice(); - next[100 * 320 + 100] ^= 255; - const payload = bbox(base, next, 640, 480, 1); - assert.ok(payload.length <= 15); - assert.ok(payload.length < (1 + rle4(next).length) / 10); - assert.deepEqual(applyDisplayPayload(base, payload), next); -}); diff --git a/tests/cfw-transport.test.cjs b/tests/cfw-transport.test.cjs deleted file mode 100644 index 8811c45d..00000000 --- a/tests/cfw-transport.test.cjs +++ /dev/null @@ -1,53 +0,0 @@ -const test = require('node:test'); -const assert = require('node:assert/strict'); -const fs = require('node:fs'); -const os = require('node:os'); -const path = require('node:path'); -const { execFileSync } = require('node:child_process'); -const { CfwTransport, parseCfwAcks } = require('../.test-build/app/g2/cfw-transport.js'); -const { crc16, concat, MessageReceiver } = require('../.test-build/app/g2/ble-protocol.js'); -const hex = value => Buffer.from(value).toString('hex'); - -test('iOS transport matches Android packets including persistent compression, reset, raw fallback and ATT limits', () => { - const random = new Uint8Array(65535); let seed = 42; - for (let i = 0; i < random.length; i++) { seed ^= seed << 13; seed ^= seed >>> 17; seed ^= seed << 5; random[i] = seed & 255; } - const cases = [[100, 3, 185, new Uint8Array([6, 0, 0, 255, 255])], - [101, 3, 185, new Uint8Array([6, 0, 0, 255, 255])], [102, 1, 20, new Uint8Array(500).fill(42)], - 'reset', [255, 3, 514, random], [103, 3, 240, new Uint8Array([11])]]; - // Captured from the original Java encoder before migration; production now uses Kotlin. - const expected = require('./fixtures/cfw-java-golden.json'); - const hash = value => require('node:crypto').createHash('sha256').update(value).digest('hex'); - const transport = new CfwTransport(); let index = 0; - for (const c of cases) { - if (c === 'reset') { transport.reset(); continue; } - const [id, lenses, maxWrite, payload] = c, packets = transport.encode(payload, id, lenses, maxWrite); - assert.ok(packets.every(p => p.length <= maxWrite)); - assert.equal(hash(packets.map(hex).join(' ')), expected[index++]); - } - -}); - -function ackPacket(records, lens = 1, nack = false) { - const words = (id, ordinal, size, crc) => new Uint8Array([id, ordinal & 255, ordinal >>> 8, size & 255, size >>> 8, crc & 255, crc >>> 8]); - const first = words(...records[0]); - const body = concat(new Uint8Array([nack ? 3 : 1]), first.subarray(0, 3), new Uint8Array([lens]), - first.subarray(3), ...records.slice(1).map(r => words(...r))); - const crc = crc16(body); - return concat(new Uint8Array([0xaa, 0x12, 50, body.length + 2, 1, 1, 0xf0, 0]), body, new Uint8Array([crc & 255, crc >>> 8])); -} -test('redundant ACKs are validated atomically and survive split/coalesced notifications', () => { - const packet = ackPacket([[104, 0, 50, 123], [103, 0, 40, 321], [102, 0, 30, 222], [101, 0, 20, 111]], 2); - assert.deepEqual(parseCfwAcks(packet).map(a => [a.streamId, a.lens, a.size]), [[104, 2, 50], [103, 2, 40], [102, 2, 30], [101, 2, 20]]); - const receiver = new MessageReceiver(); - assert.deepEqual(receiver.receive('L', packet.subarray(0, 6)), []); - const messages = receiver.receive('L', concat(packet.subarray(6), packet)); - assert.equal(messages.length, 2); assert.deepEqual(parseCfwAcks(messages[0].packet), parseCfwAcks(packet)); - for (let offset = 0; offset < packet.length; offset++) { - const corrupt = packet.slice(); corrupt[offset] ^= 1; - // Transport sequence byte is not covered by the ACK's CRC or identity. - if (offset !== 2) assert.equal(parseCfwAcks(corrupt), null, `offset ${offset}`); - } - assert.equal(parseCfwAcks(ackPacket([[104, 0, 50, 123]], 3)), null); - assert.equal(parseCfwAcks(ackPacket([[104, 0, 50, 123], [103, 0, 40, 321]], 1, true)), null); - assert.equal(parseCfwAcks(ackPacket([[104, 0, 0, 0]], 1, true))[0].nack, true); -}); diff --git a/tests/ios-app-host.test.cjs b/tests/ios-app-host.test.cjs index 1a3b69cd..6672d6b2 100644 --- a/tests/ios-app-host.test.cjs +++ b/tests/ios-app-host.test.cjs @@ -82,7 +82,7 @@ test('iOS host forwards hands-free capture mode to the voice bridge', async () = const { IosPreviewController } = load('app/g2/ios-preview-controller.ts', { require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: { startGlassesCapture: (_session, _log, endpointing) => captures.push(endpointing) } } : {} }); const host = Object.create(IosPreviewController.prototype); - host.session = { state: { phase: 'connected' } }; + host.communicator = {}; host.state = { phase: 'connected' }; await host.startVoiceCapture(true); await host.startVoiceCapture(); assert.deepEqual(captures, [true, false]); @@ -207,22 +207,43 @@ test('settings-driven repaint runs after font cache invalidation, regardless of test('background glasses input still composites frames; phone resume preserves the session; explicit stop stays stopped', async () => { const tasks = new Map(), screenStates = [], inputs = [], frames = [], previews = [], states = [], sounds = []; - let nextTask = 0, starts = 0, stops = 0, pollStarts = 0, pollStops = 0, session; + let nextTask = 0, starts = 0, stops = 0, pollStarts = 0, pollStops = 0, bridge; const window = { windowId: 'launcher', surfaceId: 'launcher', appId: 'launcher', title: 'Apps', setScreenOn: on => screenStates.push(on), requestRender() {} }; const shell = { configure() {}, registerWindow() {}, wake() {}, focusWindow() {}, getWindows: () => [window], foregroundWindow: () => window, isScreenOn: () => true, setBatteryLevels() {}, paintScene() { return new Uint8Array([0,0]); }, paintSurface() {}, underlayDim: () => 0, getFocus: () => 'app', receiveInput: async input => { inputs.push(input); } }; - class Session { - state = { phase: 'disconnected' }; - constructor(_transport, onState, onInput) { session = this; this.onState = onState; this.onInput = onInput; } - async start() { starts++; this.state = { phase: 'connected' }; this.onState(this.state); } - async stop() { stops++; this.state = { phase: 'disconnected' }; this.onState(this.state); } - async setBrightness() {} - setFrame(pixels) { if (this.state.phase === 'connected') frames.push(pixels); } - playBuzzerSequence(payload) { sounds.push([...payload]); } - wake() {} + // The shared Kotlin session, as seen through the iOS bridge: frames reach it + // only while connected, callbacks come back on the JS thread. + const noop = () => () => {}; + class FaceclawCommunicatorBridge { + phase = 'disconnected'; + constructor() { bridge = this; } + onStateChange(fn) { this.stateListener = fn; return noop(); } + onRingEvent(fn) { this.ringListener = fn; return noop(); } + onBatteryState() { return noop(); } onFirmwareInfo() { return noop(); } onFrameMetrics() { return noop(); } + onWearState() { return noop(); } addCompassListener() { return noop(); } onAncsRelayFrame() { return noop(); } + onAncsAuthorization() { return noop(); } setRequiresAncs() {} rightWriteLimit() { return 20; } onPhoneLockSignal() {} + async writeRawToRight() {} + async start() { starts++; this.phase = 'connected'; this.stateListener({ phase: 'connected', status: 'Connected.' }); } + async disconnect() { stops++; this.phase = 'disconnected'; this.stateListener({ phase: 'disconnected', status: 'Disconnected.' }); } + async close() {} + async setBrightness() {} async enableWearDetectionAndRequestState() {} + async configureCompositorScreen() {} async configureSurface() {} async setUnderlayDim() {} async setSurfaceVisible() {} + async setScreenBlanked() {} async removeSurface() {} + async submitSurfaceFrame(_id, pixels) { if (this.phase === 'connected') frames.push(pixels); } + async submitShellScene(bytes) { if (this.phase === 'connected') frames.push(bytes); } + waitForFrameFinished() { return Promise.resolve('sent'); } + getCompositePreview() { return new Uint8Array([1, 2]); } + async playBuzzerSequence(payload) { sounds.push([...payload]); } + } + class PreviewDisplayTarget { + activate() {} release() {} + async configureCompositorScreen() {} async configureSurface() {} async setUnderlayDim() {} async setSurfaceVisible() {} + async setScreenBlanked() {} async removeSurface() {} async submitSurfaceFrame() {} async submitShellScene() {} + waitForFrameFinished() { return Promise.resolve('composited'); } + getCompositePreview() { return new Uint8Array([1, 2]); } } const settings = { brightnessSetting: { get: () => 'auto' }, brightnessSettingToLevel: () => null, lockScreenEnabledSetting: { get: () => true }, onAnySettingChanged: () => () => {}, previewColorSetting: { get: () => 'white' } }; const modules = { @@ -238,22 +259,20 @@ test('background glasses input still composites frames; phone resume preserves t '../native/compass.ios': { bindCompassSession() {}, receiveCompassEvent() {} }, '@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) }, knownFolders: { documents: () => ({ path: '/tmp' }) }, path }, '../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {} } }, - '../native/ios-bluetooth': { iosBluetooth: () => ({}) }, './glasses-session': { GlassesSession: Session }, + '../native/faceclaw-communicator.ios': { FaceclawCommunicatorBridge, resolveIosPeripherals: async addresses => addresses }, + '../native/preview-display.ios': { PreviewDisplayTarget }, + './ancs-client': { ANCS_FIRMWARE_VERSION: 16, AncsClient: class { state = 'disconnected'; start() {} stop() {} stopCommand() { return new Uint8Array(); } receive() { return false; } } }, '../native/nightscout-bridge': { nightscoutBridge: { async start() { pollStarts++; }, async stop() { pollStops++; } } }, - './glance-host': { GlanceHost: class { dismiss() {} isVisible() { return false; } } }, - './device-addresses': { loadDeviceAddresses: () => ({}) }, './ios-peripheral-identity': { deviceAddressError: () => null }, + './glance-host': { GlanceHost: class { dismiss() {} reset() {} isVisible() { return false; } } }, + './device-addresses': { loadDeviceAddresses: () => ({ right: 'AA', left: 'BB', ring: '' }) }, './ios-peripheral-identity': { deviceAddressError: () => null }, '../apps/launcher/launcher-app': { createLauncherWindow: () => window, LAUNCHER_SURFACE_ID: 'launcher' }, '../apps/launcher': { launcherEntries: () => [] }, '../apps/all-apps': { ALL_APPS: [] }, '../ui/dashboard-settings': settings, '../native/phone-battery': { readPhoneBatteryState: () => ({ battery: 80, charging: false }) }, - '../graphics/surface-compositor': { SurfaceCompositor: class { - setShellScene() {} configureSurface() {} setSurfaceVisible() {} submitSurfaceFrame() {} setUnderlayDim() {} setScreenBlanked() {} - compositeFrame() { return { pixels: new Uint8Array([1, 2]) }; } - } }, - '../graphics/plane': { flattenPlanesWithDraws: () => ({ image: { pixels: new Uint8Array([1, 2]), width: 2, height: 1 }, draws: [] }) }, + '../graphics/plane': { flattenPlanesWithDraws: () => ({ image: { pixels: new Uint8Array([1, 2]), width: 2, height: 1 }, draws: [] }), planesFingerprint: () => 'fp' }, '../graphics/glyph-wire': { prepareFrameDraws: () => null }, - '../native/texture-planner.ios': { IosTexturePlanner: class {} }, - '../native/ios-graphics': { previewPixels: pixels => pixels }, + '../graphics/image': { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480 }, + './lock-screen': { LOCK_SCREEN_SURFACE_ID: 'lock-screen', createLockScreenImage: () => ({ width: 1, height: 1, to8bppBuffer: () => new Uint8Array(1) }) }, '../ui/shell/shell': { shell, rawInputEventToInputEvent: input => input }, '../ui/shell/geometry': { appViewportRect: () => ({ x: 0, y: 0, width: 640, height: 480 }) }, pako: { deflate: x => x }, @@ -269,29 +288,32 @@ test('background glasses input still composites frames; phone resume preserves t NSOperationQueue: { mainQueue: {} }, }); const flush = () => { for (const [id, fn] of [...tasks]) { if (tasks.delete(id)) fn(); } }; + const settle = async () => { for (let i = 0; i < 4; i++) { flush(); await new Promise(resolve => setImmediate(resolve)); } }; const controller = new api.IosPreviewController(image => previews.push(image), assert.fail, state => states.push(state)); await controller.actions.playBuzzerSequence(new Uint8Array([5, 4, 0])); assert.equal(sounds.length, 0); - controller.resume(); await controller.connect(); flush(); + controller.resume(); await controller.connect(); await settle(); await controller.actions.playBuzzerSequence(new Uint8Array([5, 4, 0])); assert.deepEqual(sounds, [[5, 4, 0]]); const previewCount = previews.length, stateCount = states.length; controller.pause(); controller.pause(); // NativeScript also unloads its root page on background entry. assert.equal(stops, 0); assert.ok(screenStates.every(Boolean)); assert.equal(pollStarts, 1); assert.equal(pollStops, 0, 'connected glasses keep Nightscout polling in background'); - session.onInput({ eventType: 3, eventSource: 1 }); - await controller.inputQueue; flush(); - assert.equal(inputs.length, 1); assert.ok(frames.length >= 2); + const frameCount = frames.length; + bridge.ringListener({ kind: 'sys-event', containerName: '', eventType: 3, eventSource: 1, systemExitReasonCode: 0, frameId: 0 }); + await controller.inputQueue; await settle(); + assert.equal(inputs.length, 1); assert.ok(frames.length > frameCount, 'background input still composites frames'); assert.equal(previews.length, previewCount); assert.equal(states.length, stateCount); - controller.resume(); flush(); + controller.resume(); await settle(); assert.equal(starts, 1); assert.ok(previews.length > previewCount); - controller.pause(); await controller.disconnect(); flush(); + controller.pause(); await controller.disconnect(); await settle(); assert.equal(stops, 1); assert.equal(screenStates.at(-1), false); assert.equal(pollStops, 1); - const frameCount = frames.length; - session.onInput({ eventType: 3, eventSource: 1 }); await controller.inputQueue; flush(); - assert.equal(inputs.length, 1); assert.equal(frames.length, frameCount); - controller.resume(); flush(); + const stoppedFrames = frames.length; + bridge.ringListener({ kind: 'sys-event', containerName: '', eventType: 3, eventSource: 1, systemExitReasonCode: 0, frameId: 0 }); + await controller.inputQueue; await settle(); + assert.equal(inputs.length, 1); assert.equal(frames.length, stoppedFrames); + controller.resume(); await settle(); assert.equal(starts, 1); assert.equal(controller.connectionState.phase, 'disconnected'); assert.equal(pollStarts, 2, 'resuming the phone restarts Nightscout polling'); }); @@ -368,21 +390,22 @@ test('iOS configures an in-process surface before submitting constructor-trigger require: name => ({ '../ui/shell/shell': { shell }, '../ui/shell/geometry': { appViewportRect: () => ({ x: 0, y: 0, width: 2, height: 1 }) }, - '../graphics/plane': { flattenPlanesWithDraws: planes => ({ image: planes[0], draws: [] }) }, + '../graphics/plane': { flattenPlanesWithDraws: planes => ({ image: planes[0], draws: [] }), planesFingerprint: () => 'fp' }, '../graphics/glyph-wire': { prepareFrameDraws: () => null }, })[name] ?? {}, console, }); - // Exercise the real launch method with a strict compositor boundary. App + // Exercise the real launch method with a strict display boundary. App // construction paints synchronously, as Nightscout's tray subscription does. const controller = Object.create(api.IosPreviewController.prototype); controller.inProcessApps = new Map(); controller.requestShellRender = () => {}; - controller.scheduleFrame = () => {}; - controller.compositor = { - configureSurface(id) { surfaces.add(id); }, setSurfaceVisible() {}, - removeSurface(id) { surfaces.delete(id); }, - submitSurfaceFrame(id, pixels) { assert.ok(surfaces.has(id), `unconfigured ${id}`); submitted.push([...pixels]); }, + controller.schedulePreviewUpdate = () => {}; + controller.communicator = null; + controller.previewTarget = { + async configureSurface(id) { surfaces.add(id); }, async setSurfaceVisible() {}, + async removeSurface(id) { surfaces.delete(id); }, + async submitSurfaceFrame(id, pixels) { assert.ok(surfaces.has(id), `unconfigured ${id}`); submitted.push([...pixels]); }, }; let plumbing, early; const fresh = [{ pixels: new Uint8Array([30, 40]), width: 2, height: 1 }]; @@ -453,14 +476,14 @@ test('iOS preview voice uses the phone microphone, while connected capture stays require: id => id === '../native/ios-voice-input' ? { iosVoiceInput: bridge } : {}, }); const host = Object.create(IosPreviewController.prototype); - host.active = true; host.glassesLocked = false; + host.active = true; host.glassesLocked = false; host.communicator = null; host.state = { phase: 'disconnected' }; assert.equal(await host.prepareVoiceCapture(), true); await host.startVoiceCapture(true); assert.deepEqual(calls, [['prepare', true, true], ['prepare', true, true], ['phone', true]]); - calls.length = 0; host.session = { state: { phase: 'connected' } }; + calls.length = 0; host.communicator = {}; host.state = { phase: 'connected' }; assert.equal(await host.prepareVoiceCapture(), true); await host.startVoiceCapture(false); assert.deepEqual(calls, [['prepare', true, false], ['glasses', false]]); - calls.length = 0; host.active = false; host.session = null; + calls.length = 0; host.active = false; host.communicator = null; host.state = { phase: 'disconnected' }; assert.equal(await host.prepareVoiceCapture(), false); await host.startVoiceCapture(); assert.deepEqual(calls, []); }); diff --git a/tests/ios-assistant.test.cjs b/tests/ios-assistant.test.cjs index 310aafa6..e4a965bb 100644 --- a/tests/ios-assistant.test.cjs +++ b/tests/ios-assistant.test.cjs @@ -77,23 +77,27 @@ for (const provider of ['openai', 'anthropic']) { }); } -test('iOS SSE adapter invokes listeners on its polling thread and stops polling at cancellation/EOF', () => { - const timers = new Set(), instances = [], seen = []; +test('iOS SSE adapter forwards the Kotlin stream events once and stops after cancellation/EOF', () => { + const instances = [], seen = []; + const nsObject = { extend: methods => ({ new: () => ({ ...methods }) }) }; + const listenerModule = loader({ NSObject: nsObject }, {})('app/native/kotlin-listener.ios.ts'); const api = loader({ - setInterval: fn => { timers.add(fn); return fn; }, clearInterval: fn => timers.delete(fn), - FaceclawSseRequest: { alloc: () => ({ initWithURLBodyHeaders(url, body, headers) { - const instance = { events: [], cancelled: false, takeEvents() { const events = this.events; this.events = []; return JSON.stringify(events); }, cancel() { this.cancelled = true; } }; - instances.push(instance); assert.equal(JSON.parse(headers)['User-Agent'], 'fixture'); return instance; - } }) }, - }, { '../util/http': { withUserAgent: headers => ({ ...headers, 'User-Agent': 'fixture' }) } })('app/native/sse.ios.ts'); - const listener = { onLine: line => seen.push(line), onComplete: () => seen.push('complete'), onHttpError() {}, onFailure: error => assert.fail(error) }; + FaceclawKitIosSseRequest: { alloc: () => ({ initWithUrlBodyHeadersJsonListener(url, body, headers, listener) { + const instance = { listener, cancelled: false, cancel() { this.cancelled = true; } }; + instances.push(instance); assert.equal(JSON.parse(headers)['User-Agent'], 'fixture'); assert.equal(url, 'https://fixture'); return instance; + } }) }, FaceclawKitFaceclawSseListener: {}, + }, { '../util/http': { withUserAgent: headers => ({ ...headers, 'User-Agent': 'fixture' }) }, './kotlin-listener.ios': listenerModule })('app/native/sse.ios.ts'); + const listener = { onLine: line => seen.push(line), onComplete: () => seen.push('complete'), onHttpError: (code, body) => seen.push(`http:${code}:${body}`), onFailure: error => seen.push(`fail:${error}`) }; const handle = api.openSseRequest('https://fixture', '{}', {}, listener); - instances[0].events.push({ kind: 'line', text: 'first' }); assert.deepEqual(seen, []); - for (const tick of timers) tick(); assert.deepEqual(seen, ['first']); - handle.cancel(); assert.equal(timers.size, 0); assert.equal(instances[0].cancelled, true); + instances[0].listener.onLineLine('first'); assert.deepEqual(seen, ['first']); + handle.cancel(); handle.cancel(); assert.equal(instances[0].cancelled, true); + instances[0].listener.onLineLine('after cancel'); instances[0].listener.onComplete(); assert.deepEqual(seen, ['first']); api.openSseRequest('https://fixture', '{}', {}, listener); - instances[1].events.push({ kind: 'line', text: 'last' }, { kind: 'complete' }); - for (const tick of [...timers]) tick(); assert.deepEqual(seen, ['first', 'last', 'complete']); assert.equal(timers.size, 0); + instances[1].listener.onLineLine('last'); instances[1].listener.onComplete(); instances[1].listener.onFailureMessage_('late'); + assert.deepEqual(seen, ['first', 'last', 'complete']); + api.openSseRequest('https://fixture', '{}', {}, listener); + instances[2].listener.onHttpErrorCodeBody(429, 'slow down'); instances[2].listener.onComplete(); + assert.deepEqual(seen.at(-1), 'http:429:slow down'); }); test('iOS only offers cloud assistant models and preserves old local-model conversations as Auto', () => { diff --git a/tests/ios-ble.test.cjs b/tests/ios-ble.test.cjs deleted file mode 100644 index 3003c085..00000000 --- a/tests/ios-ble.test.cjs +++ /dev/null @@ -1,751 +0,0 @@ -const test = require('node:test'); -const assert = require('node:assert/strict'); -const p = require('../.test-build/app/g2/ble-protocol.js'); -const { identifyIosPeripheral, deviceAddressError } = require('../.test-build/app/g2/ios-peripheral-identity.js'); -const { GlassesSession } = require('../.test-build/app/g2/glasses-session.js'); -const { deflate, inflate } = require('pako'); -const { inflateSync, constants } = require('node:zlib'); -const { REQUIRED_FACECLAW_FIRMWARE_VERSION } = require('../.test-build/app/g2/firmware-compat.js'); -const hex = bytes => Buffer.from(bytes).toString('hex'); -const string = (field, text) => p.bytes(field, new Uint8Array(Buffer.from(text))); - -// Generated by compiling the existing Android BleProtocol.java/BmpUtil.java, -// plus BleImageOptimizer's unchanged RLE method, with javac 25.0.2. -test('iOS/shared protocol matches Android-generated wire vectors byte for byte', () => { - const vectors = [ - [p.authentication(101), '080410651a0408011004'], - [p.prelude(), '0802109c01220a1a081206120408001000'], - [p.createLayout(102), '080010661a2308011a1c0800100018c00420a0024801520964617368626f617264580162012028904e'], - [p.heartbeat(103), '080c106772020800'], - [p.settingsQuery(104), '0802106822020801'], - [p.shutdown(105), '080910695a020801'], - [p.framebufferLease(true), '08011000aa0606464301050000'], - [p.framebufferLease(false), '08011000aa0606464301060000'], - [p.frameMessage(p.authentication(101), 128, 0, 64)[0], 'aa21400c01018000080410651a04080110041024'], - ]; - for (const [actual, expected] of vectors) assert.equal(hex(actual), expected); - const packed = p.packGray4(new Uint8Array([0, 1, 7, 8, 15, 16, 23, 24, 127, 128, 247, 255]), 3, 4); - assert.equal(hex(packed), '0000111012808ff0'); - assert.equal(hex(p.rle4(packed)), '40311011121810182f10'); -}); - -test('negotiated-MTU framing reassembles split and coalesced notifications and rejects bad CRC', () => { - const payload = p.concat(p.integer(1, 3), p.integer(2, 110), p.bytes(8, new Uint8Array(3900).fill(55))); - const frames = p.frameMessage(payload, 0xe0, 0x20, 17, 185); - assert.ok(frames.every(f => f.length <= 185)); - const receiver = new p.MessageReceiver(), stream = p.concat(...frames); - assert.deepEqual(receiver.receive('L', stream.slice(0, 7)), []); - const messages = receiver.receive('L', stream.slice(7)); - assert.equal(messages.length, 1); assert.deepEqual(messages[0].payload, payload); - stream[stream.length - 1] ^= 1; - assert.deepEqual(receiver.receive('L', stream), []); - assert.throws(() => p.frameMessage(payload, 1, 0, 1, 10), /too small/); - assert.throws(() => p.readBytes(new Uint8Array([0x1a, 0x7f]), 3), /Truncated/); -}); - -test('interleaved links and missing/expired fragments cannot produce false ACKs', () => { - const payload = p.concat(p.integer(1, 3), p.integer(2, 110), p.bytes(8, new Uint8Array(300))); - const frames = p.frameMessage(payload, 224, 0, 17), receiver = new p.MessageReceiver(); - assert.deepEqual(receiver.receive('L', frames[0], 0), []); - assert.deepEqual(receiver.receive('R', frames[1], 1), []); - assert.deepEqual(receiver.receive('L', frames[1], 6000), []); - assert.equal(receiver.receive('L', p.concat(...frames), 6001).length, 1); -}); - -test('full-frame RLE splits 65535-pixel runs and preserves opaque near-black', () => { - const packed = p.packGray4(new Uint8Array(640 * 480).fill(1), 640, 480); - assert.ok(packed.every(v => v === 0)); - const encoded = p.rle4(packed); - let count = 0, offset = 0; - while (offset < encoded.length) { - const token = encoded[offset++]; let run = token >>> 4; - if (!run) { run = encoded[offset++]; if (!run) { run = encoded[offset] | (encoded[offset + 1] << 8); offset += 2; } } - assert.equal(token & 15, 0); count += run; - } - assert.equal(count, 640 * 480); - assert.deepEqual(inflate(deflate(encoded)), encoded); -}); - -test('iOS mapping requires the full advertised MAC, never just a name suffix', () => { - const raw = { identifier: '8A2DD845-B208-F292-EB77-F4645C5AC42F', name: 'Even G2_32_L_B6ECE0', - manufacturerData: '4552' + Buffer.from('S211GBBC180304').toString('hex') + 'e0ecb61412e001', rssi: -45, connectable: true }; - const device = identifyIosPeripheral(raw); - assert.equal(device.address, 'E0:12:14:B6:EC:E0'); assert.equal(device.role, 'left'); - assert.equal(device.identifier, raw.identifier); assert.equal(device.serial, 'S211GBBC180304'); - assert.equal(identifyIosPeripheral({ ...raw, manufacturerData: '' }), null); - assert.equal(identifyIosPeripheral({ ...raw, identifier: 'not-a-uuid' }), null); - assert.match(deviceAddressError({ left: device.address, right: device.address, ring: '' }), /different/); - assert.equal(deviceAddressError({ left: device.address, right: 'AA:BB:CC:DD:EE:FF', ring: '' }), null); -}); - -test('ring and arm input decoders preserve gesture and source', () => { - assert.equal(p.decodeRingInput(new Uint8Array([255, 4, 2])).eventType, 3); - assert.equal(p.decodeRingInput(new Uint8Array([255, 5, 0])).eventType, 2); - assert.equal(p.decodeRingInput(new Uint8Array([255, 5, 2])).eventType, 1); - assert.equal(p.decodeRingInput(new Uint8Array([0, 9, 97, 0, 8, 0, 0, 0, 0, 0, 0])).eventType, 10); - assert.equal(p.decodeRingInput(new Uint8Array([255, 4, 99])), null); - const payload = p.bytes(13, p.bytes(3, p.concat(p.integer(1, 9), p.integer(2, 3)))); - assert.equal(p.decodeGlassesInput({ sid: 224, flag: 1, payload }).eventSource, 3); - assert.equal(p.decodeGlassesInput({ sid: 224, flag: 32, payload }), null); - const headUp = p.bytes(13, p.bytes(3, p.concat(p.integer(1, 12), p.integer(2, 1)))); - const wake = p.decodeGlassesInput({ sid: 224, flag: 1, payload: headUp }); - assert.equal(wake.kind, 'display-wake'); - assert.equal(wake.eventType, 12); - assert.equal(wake.eventSource, 1); - // The stock G2 sender omits source for dedicated Faceclaw event 14. - const press = p.decodeGlassesInput({ sid: 224, flag: 1, - payload: p.bytes(13, p.bytes(3, p.integer(1, 14))) }); - assert.equal(press.kind, 'sys-event'); - assert.equal(press.eventType, 14); - assert.equal(press.eventSource, 0); -}); - -class FakeTransport { - events = new Set(); receiver = new p.MessageReceiver(); sent = []; subscriptions = []; closed = []; - hold = false; held = []; stock = false; cfw = new Map(); - onEvent(fn) { this.events.add(fn); return () => this.events.delete(fn); } - emit(event) { for (const fn of [...this.events]) fn(event); } - async resolveDevices() { return { left: 'L', right: 'R', ring: 'ring' }; } - async connect(id) { return { characteristics: id === 'ring' ? p.RING_NOTIFY : [p.G2_WRITE, p.G2_NOTIFY], maxWrite: 185 }; } - async subscribe(id, characteristic) { this.subscriptions.push([id, characteristic]); } - disconnect(id) { this.closed.push(id); this.emit({ kind: 'disconnected', identifier: id }); } - stopScan() {} - ack(id, message, overrides = {}) { - if (message.sid === p.SID.cfw) { - for (const lens of overrides.lenses ?? [1, 2]) { - const size = overrides.size ?? message.payload.length, crc = overrides.checksum ?? p.crc16(message.payload); - const body = new Uint8Array([overrides.nack ? 3 : 1, overrides.magic ?? message.magic, overrides.ordinal ?? 0, 0, lens, size & 255, size >>> 8, crc & 255, crc >>> 8]); - const checksum = p.crc16(body); - const packet = p.concat(new Uint8Array([0xaa, 0x12, 0, 11, 1, 1, overrides.sid ?? p.SID.cfw, 0]), body, new Uint8Array([checksum & 255, checksum >>> 8])); - this.emit({ kind: 'notification', identifier: overrides.identifier ?? id, characteristic: p.G2_NOTIFY, data: hex(packet) }); - } - return; - } - let body = new Uint8Array(); - if (message.sid === p.SID.auth) body = p.bytes(3, new Uint8Array()); - if (message.sid === p.SID.settings) body = p.concat(p.bytes(4, p.concat(string(5, '2.2.9.22'), string(6, '2.2.9.22'), p.integer(12, 90), p.integer(13, 0))), string(100, this.stock ? '' : `Faceclaw/${this.firmware ?? REQUIRED_FACECLAW_FIRMWARE_VERSION}`)); - const responseCommand = message.sid === p.SID.launch ? 1 : message.sid === p.SID.hub && message.command === 0 ? 1 : message.sid === p.SID.hub && message.command === 3 ? 4 : message.command; - const payload = p.concat(p.integer(1, responseCommand), p.integer(2, overrides.magic ?? message.magic), body); - const data = hex(p.concat(...p.frameMessage(payload, overrides.sid ?? message.sid, 0, 12))); - // The right/master link also carries ACKs for image writes to L. - this.emit({ kind: 'notification', identifier: overrides.identifier ?? 'R', characteristic: p.G2_NOTIFY, data }); - } - async write(id, characteristic, frame) { - assert.equal(characteristic, p.G2_WRITE); assert.ok(frame.length <= 185); - if (frame[0] === 65 && frame[1] === 78) { (this.ancs ??= []).push({ id, frame: new Uint8Array(frame) }); return; } - let messages; - if (frame[6] === p.SID.cfw) { - assert.equal(p.crc16(frame.subarray(8, -2)), frame[frame.length - 2] | frame[frame.length - 1] << 8); - let state = this.cfw.get(id) ?? { history: Buffer.alloc(0), decoded: 0 }; - if (frame[8] & 0x80) { state.record = []; state.magic = frame[2]; } - state.record.push(frame.subarray(9, -2)); this.cfw.set(id, state); - if (!(frame[8] & 0x40)) return; - const record = p.concat(...state.record), flags = record[0]; - assert.equal(record.length - 5, record[1] | record[2] << 8); - if (flags & 8) { state.history = Buffer.alloc(0); state.decoded = 0; } - let payload = record.subarray(5); - if (flags & 4) { - state.history = Buffer.concat([state.history, payload]); - const all = inflateSync(state.history, { finishFlush: constants.Z_SYNC_FLUSH }); - payload = new Uint8Array(all.subarray(state.decoded)); state.decoded = all.length; - } - assert.equal(p.crc16(payload), record[3] | record[4] << 8); - messages = [{ sid: p.SID.cfw, magic: state.magic, payload, flags, command: -1 }]; - } else messages = this.receiver.receive(id, frame); - for (const message of messages) { - this.sent.push({ id, message }); - if (!message.magic) continue; - if (this.hold) this.held.push({ id, message }); - else queueMicrotask(() => this.ack(id, message)); - } - } -} -const addresses = { right: 'AA:BB:CC:DD:EE:01', left: 'AA:BB:CC:DD:EE:02', ring: '' }; -async function until(predicate) { - for (let i = 0; i < 100; i++) { if (predicate()) return; await new Promise(resolve => setTimeout(resolve, 5)); } - assert.fail('Timed out waiting for test state'); -} -function harness(t, transport = new FakeTransport(), textures) { - const states = [], input = [], compass = [], wear = []; - const session = new GlassesSession(transport, state => states.push(state), event => input.push(event), undefined, undefined, event => compass.push(event), wearing => wear.push(wearing), undefined, textures); - t.after(async () => { transport.hold = false; await session.stop(); }); - return { transport, session, states, input, compass, wear }; -} -test('session authenticates both arms, checks firmware and sends acknowledged display data to L', async t => { - const h = harness(t); await h.session.start({ ...addresses, ring: 'AA:BB:CC:DD:EE:03' }); - assert.equal(h.session.state.phase, 'connected'); assert.equal(h.session.state.ring, true); - assert.equal(h.session.state.battery, 90); - assert.equal(h.session.state.charging, false); - assert.deepEqual(h.transport.sent.filter(s => s.message.sid === 128).map(s => s.id).sort(), ['L', 'R']); - h.session.setFrame(new Uint8Array(640 * 480)); await until(() => h.session.state.frames === 1); - const image = h.transport.sent.find(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 26); - assert.equal(image.id, 'L'); - assert.equal(image.message.payload[0], 26); - const layout = h.transport.sent.find(s => s.message.sid === p.SID.hub && s.message.command === 0); - assert.equal(p.readBytes(p.readBytes(layout.message.payload, 3), 4), undefined); - await h.session.stop(); - assert.equal(h.session.state.phase, 'disconnected'); - assert.ok(h.transport.sent.some(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 11)); -}); -test('stock firmware is rejected before framebuffer/layout/image commands', async t => { - const transport = new FakeTransport(); transport.stock = true; - const h = harness(t, transport); await h.session.start(addresses); - assert.equal(h.session.state.phase, 'error'); assert.match(h.session.state.status, /firmware/); - assert.ok(!transport.sent.some(s => s.message.sid === p.SID.hub)); -}); -test('one unavailable R1 notification channel does not discard the usable channel', async t => { - const transport = new FakeTransport(); - const subscribe = transport.subscribe.bind(transport); - transport.subscribe = async (id, uuid) => { - if (uuid === p.RING_NOTIFY[0]) throw new Error('CCCD timed out'); - return subscribe(id, uuid); - }; - const h = harness(t, transport); await h.session.start({ ...addresses, ring: 'AA:BB:CC:DD:EE:03' }); - assert.equal(h.session.state.ring, true); - assert.ok(transport.subscriptions.some(([id, uuid]) => id === 'ring' && uuid === p.RING_NOTIFY[1])); - assert.ok(!transport.closed.includes('ring')); -}); -test('disconnect cancels in-flight authentication and ignores late acknowledgements', async t => { - const h = harness(t); h.transport.hold = true; - const start = h.session.start(addresses); await until(() => h.transport.held.length === 2); - await h.session.stop(); - for (const held of h.transport.held) h.transport.ack(held.id, held.message); - await start; - assert.equal(h.session.state.phase, 'disconnected'); - assert.ok(!h.states.some(s => s.phase === 'connected')); - assert.equal(h.transport.sent.length, 2); -}); -test('wrong peer, service or magic cannot satisfy a pending request; timeout rejects it', async t => { - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - const request = h.session.request('right', p.SID.hub, p.heartbeat, 'test heartbeat', 30); - const rejected = assert.rejects(request, /not acknowledged/); - await until(() => h.transport.held.length > 0); - const held = h.transport.held[0]; - h.transport.ack(held.id, held.message, { identifier: 'stranger' }); - h.transport.ack(held.id, held.message, { sid: 9 }); - h.transport.ack(held.id, held.message, { magic: held.message.magic + 1 }); - await rejected; -}); - -test('ring disconnect retries independently and stop cancels further retries', async t => { - const h = harness(t); await h.session.start({ ...addresses, ring: 'AA:BB:CC:DD:EE:03' }); - const armMessages = h.transport.sent.length; - h.transport.emit({ kind: 'disconnected', identifier: 'ring', message: 'Link lost' }); - assert.equal(h.session.state.phase, 'connected'); assert.equal(h.session.state.ring, false); - assert.notEqual(h.session.ringRetryTimer, null); - await new Promise(resolve => setTimeout(resolve, 2100)); - assert.equal(h.session.state.ring, true); - assert.equal(h.transport.sent.length, armMessages); - assert.equal(h.transport.subscriptions.filter(([id]) => id === 'ring').length, 4); - h.transport.emit({ kind: 'disconnected', identifier: 'ring' }); - await h.session.stop(); - assert.equal(h.session.ringRetryTimer, null); -}); - -test('a BLE wake services overdue heartbeat and lease without waiting for a suspended poll timer', async t => { - const h = harness(t); await h.session.start(addresses); - clearTimeout(h.session.timer); h.session.timer = null; - h.session.lastHeartbeat = Date.now() - 12_000; - h.session.lastLease = Date.now() - 60_000; - const before = h.transport.sent.length; - const data = hex(p.concat(...p.frameMessage(p.integer(1, 6), p.SID.auth, 1, 22))); - h.transport.emit({ kind: 'notification', identifier: 'L', characteristic: p.G2_NOTIFY, data }); - // pump starts in the notification callback, before any timers can fire. - assert.equal(h.session.pumping, true); - await until(() => !h.session.pumping); - const sent = h.transport.sent.slice(before); - assert.equal(sent.filter(s => s.message.sid === p.SID.hub && s.message.command === 12).length, 1); - assert.deepEqual(sent.filter(s => s.message.sid === p.SID.settings).map(s => s.id).sort(), ['L', 'R']); - assert.equal(h.session.state.phase, 'connected'); - assert.deepEqual(h.transport.closed, []); - await h.session.stop(); - const count = h.transport.sent.length; - h.session.wake(); - h.transport.emit({ kind: 'notification', identifier: 'L', characteristic: p.G2_NOTIFY, data }); - assert.equal(h.transport.sent.length, count); - assert.equal(h.session.state.phase, 'disconnected'); -}); - -test('glasses mic uses Android wire control and only routes bound-arm audio during capture', async t => { - assert.equal(hex(p.audioControl(101, true)), '080f10659201020801'); - assert.equal(hex(p.audioControl(101, false)), '080f10659201020800'); - const h = harness(t), audio = []; - await h.session.start(addresses); - const send = id => h.transport.emit({ kind: 'notification', identifier: id, characteristic: p.G2_RENDER_NOTIFY, data: '010203' }); - send('R'); assert.equal(audio.length, 0); - await h.session.setMicrophone(true, bytes => audio.push(hex(bytes))); - assert.ok(h.transport.subscriptions.some(([id, c]) => id === 'R' && c === p.G2_RENDER_NOTIFY)); - assert.ok(h.transport.subscriptions.some(([id, c]) => id === 'L' && c === p.G2_RENDER_NOTIFY)); - send('stranger'); send('ring'); send('L'); send('R'); - assert.deepEqual(audio, ['010203', '010203']); - const disabling = h.session.setMicrophone(false); - send('R'); assert.equal(audio.length, 2); // Immediate, before the disable ACK. - await disabling; - assert.deepEqual(h.transport.sent.filter(s => s.message.command === 15).map(s => - [s.id, p.readInteger(p.readBytes(s.message.payload, 18), 1)]), [['R', 1], ['R', 0]]); -}); -test('release while microphone enable awaits ACK sends disable last and rejects further audio', async t => { - const h = harness(t); await h.session.start(addresses); - h.transport.hold = true; - let packets = 0; - const enabling = h.session.setMicrophone(true, () => packets++); - await until(() => h.transport.held.some(s => s.message.command === 15)); - const disabling = h.session.setMicrophone(false); - h.transport.emit({ kind: 'notification', identifier: 'R', characteristic: p.G2_RENDER_NOTIFY, data: '01' }); - assert.equal(packets, 0); - h.transport.hold = false; - for (const s of h.transport.held) h.transport.ack(s.id, s.message); - await Promise.all([enabling, disabling]); - const mic = h.transport.sent.filter(s => s.message.command === 15); - assert.equal(p.readInteger(p.readBytes(mic.at(-1).message.payload, 18), 1), 0); -}); - -const imageMessages = transport => transport.sent.filter(s => s.message.sid === p.SID.cfw && ![10, 11].includes(s.message.payload[0])); -const imageBody = sent => sent.message.payload; -const ack = (transport, sent, overrides) => transport.ack(sent.id, sent.message, overrides); -const tick = () => new Promise(resolve => setImmediate(resolve)); -const noisy = () => Uint8Array.from({ length: 640 * 480 }, (_, i) => (i % 2) * 255); - -test('resource evictions and uploads precede their frame, share ACK accounting, and coalesce pixels with draw identities', async t => { - const plans = []; - let resets = 0; - const textures = { - reset() { resets++; }, - plan(previous, next, frame, firstId) { - plans.push({ previous, next, frame, firstId }); - return { resourceCommands: plans.length === 1 ? [new Uint8Array([22, 1]), new Uint8Array([21, 2])] : [], - payload: new Uint8Array([8, plans.length]), nextFid: firstId + 2, usedBytes: 100 }; - }, - }; - const h = harness(t, new FakeTransport(), textures); - await h.session.start(addresses); h.transport.hold = true; - const a = { native: { id: 'a' } }, b = { native: { id: 'b' } }, c = { native: { id: 'c' } }; - h.session.setFrame(new Uint8Array(640 * 480), a); - await until(() => imageMessages(h.transport).length === 3); - const sent = imageMessages(h.transport); - assert.deepEqual(sent.map(s => s.message.payload[0]), [22, 21, 8]); - h.session.setFrame(new Uint8Array(640 * 480).fill(80), b); - h.session.setFrame(new Uint8Array(640 * 480).fill(160), c); - assert.equal(plans.length, 1, 'coalesced frames must not allocate textures'); - ack(h.transport, sent[2]); ack(h.transport, sent[1]); await tick(); - assert.equal(h.session.state.frames, 0, 'a draw ACK cannot retire an unacknowledged upload'); - ack(h.transport, sent[0]); await until(() => imageMessages(h.transport).length === 4); - assert.equal(h.session.state.frames, 1); - assert.equal(plans.length, 2); assert.equal(plans[1].frame, c); - assert.deepEqual(plans[1].previous, plans[0].next); - assert.equal(plans[1].firstId, plans[0].firstId + 2); - assert.ok(plans[1].next.every(value => value === 0xaa)); - ack(h.transport, imageMessages(h.transport)[3]); await until(() => h.session.state.frames === 2); - h.transport.hold = false; await h.session.stop(); - assert.ok(resets > 0); -}); - -test('evictions drain earlier replayable draws before resource IDs can be reused', async t => { - let plans = 0; - const textures = { - reset() {}, - plan() { return { resourceCommands: ++plans === 1 ? [] : [new Uint8Array([22]), new Uint8Array([21])], - payload: new Uint8Array([8]), nextFid: 1, usedBytes: 100 }; }, - }; - const h = harness(t, new FakeTransport(), textures); await h.session.start(addresses); - h.transport.hold = true; - h.session.setFrame(new Uint8Array(640 * 480), { native: {} }); - await until(() => imageMessages(h.transport).length === 1); - h.session.setFrame(new Uint8Array(640 * 480).fill(80), { native: {} }); - await until(() => plans === 2); await tick(); - assert.equal(imageMessages(h.transport).length, 1, 'eviction cannot enter an unresolved window'); - h.session.recoverCfw(); await tick(); - assert.equal(imageMessages(h.transport).length, 1); - ack(h.transport, imageMessages(h.transport)[0]); - await until(() => imageMessages(h.transport).length === 4); - assert.deepEqual(imageMessages(h.transport).map(s => s.message.payload[0]), [8, 22, 21, 8]); - h.transport.hold = false; - for (const sent of imageMessages(h.transport).slice(1)) ack(h.transport, sent); - await until(() => h.session.state.frames === 2); -}); - -test('a failed resource upload invalidates residency and the pipelined frame base', async t => { - let resets = 0; - const textures = { - reset() { resets++; }, - plan() { return { resourceCommands: [new Uint8Array([21])], payload: new Uint8Array([8]), nextFid: 1, usedBytes: 4 }; }, - }; - const h = harness(t, new FakeTransport(), textures); await h.session.start(addresses); - const original = h.session.requestCfw.bind(h.session); - h.session.requestCfw = (role, payload) => payload[0] === 21 ? Promise.reject(new Error('texture upload failed')) : original(role, payload); - h.session.setFrame(new Uint8Array(640 * 480), { native: {} }); - await until(() => h.session.state.phase === 'retrying'); - assert.equal(resets, 1); assert.equal(h.session.lastEnqueued, null); - assert.equal(h.session.latestTextures, null); assert.equal(h.session.state.frames, 0); -}); - -test('resuming near framebuffer lease expiry discards cached draws before transmission', async t => { - let resets = 0, plans = 0; - const textures = { reset() { resets++; }, plan() { plans++; return null; } }; - const h = harness(t, new FakeTransport(), textures); await h.session.start(addresses); - h.session.lastLease = Date.now() - 85_000; - h.session.setFrame(new Uint8Array(640 * 480), { native: {} }); - await h.session.pump(); - assert.equal(h.session.state.phase, 'retrying'); - assert.equal(resets, 1); assert.equal(plans, 0); - assert.equal(imageMessages(h.transport).length, 0); -}); - -// Both eyes must finish; wrong ingress, size, CRC, ordinal and legacy replies do not count. -test('CFW ACK identity and both-lens completion gate display metrics', async t => { - const { iosBleTraffic } = require('../.test-build/app/g2/ble-traffic-counters.js'); - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - const before = iosBleTraffic.sample(); let written = 0; - const write = h.transport.write.bind(h.transport); - h.transport.write = async (...args) => { written += args[2].length; await write(...args); }; - h.session.setFrame(new Uint8Array(640 * 480)); - await until(() => imageMessages(h.transport).length === 2); - const [draw, sent] = imageMessages(h.transport); - ack(h.transport,draw); - for (const wrong of [{ identifier: 'R' }, { size: 99 }, { checksum: 0 }, { ordinal: 1 }, { magic: sent.message.magic + 1 }]) ack(h.transport, sent, wrong); - ack(h.transport, sent, { lenses: [1] }); await tick(); - assert.equal(h.session.state.frames, 0); - ack(h.transport, sent, { lenses: [2] }); await until(() => h.session.state.frames === 1); - assert.equal(iosBleTraffic.sample().bytes - before.bytes, written); - assert.equal(iosBleTraffic.sample().messages - before.messages, 2); - assert.equal(iosBleTraffic.sample().frames - before.frames, 1); - ack(h.transport, sent); await tick(); assert.equal(h.session.state.frames, 1); -}); - -test('large frames use bounded RLE bands and ordered three-message pipelining', async t => { - const { applyDisplayPayload } = require('./helpers/display-payload.cjs'); - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - const gray = noisy(); h.session.setFrame(gray); - await until(() => imageMessages(h.transport).length === 3); - const first = imageMessages(h.transport); - ack(h.transport, first[2]); ack(h.transport, first[1]); await tick(); - assert.equal(imageMessages(h.transport).length, 3); assert.equal(h.session.state.frames, 0); - ack(h.transport, first[0]); await until(() => imageMessages(h.transport).length === 6); - for (const sent of imageMessages(h.transport).slice(3)) ack(h.transport, sent); - await until(() => imageMessages(h.transport).length === 9); - assert.equal(h.session.state.frames, 0); - for (const sent of imageMessages(h.transport).slice(6)) ack(h.transport, sent); - await until(() => h.session.state.frames === 1); - let shadow = new Uint8Array(320 * 480); - for (const sent of imageMessages(h.transport)) { - assert.ok(sent.message.payload.length <= 65535); - shadow = applyDisplayPayload(shadow, sent.message.payload); - } - assert.deepEqual(shadow, p.packGray4(gray, 640, 480)); -}); - -test('draw/present pairs pipeline and coalesce waiting frames', async t => { - const h=harness(t);await h.session.start(addresses);h.transport.hold=true; - const submit=async v=>{h.session.setFrame(new Uint8Array(640*480).fill(v));await h.session.pump();await tick();}; - await submit(0);await submit(0);assert.equal(imageMessages(h.transport).length,2); - await submit(255);await until(()=>imageMessages(h.transport).length===3); - await submit(80);await submit(160); - const first=imageMessages(h.transport);ack(h.transport,first[2]);ack(h.transport,first[1]);await tick(); - assert.equal(h.session.state.frames,0);assert.equal(imageMessages(h.transport).length,3); - ack(h.transport,first[0]);await until(()=>imageMessages(h.transport).length===6); - for(const message of imageMessages(h.transport).slice(3)) ack(h.transport,message); - await until(()=>h.session.state.frames===3); - const {applyDisplayPayload}=require('./helpers/display-payload.cjs');let screen=new Uint8Array(320*480); - for(const {message} of imageMessages(h.transport)) screen=applyDisplayPayload(screen,message.payload); - assert.deepEqual(screen,p.packGray4(new Uint8Array(640*480).fill(160),640,480)); - assert.deepEqual(imageMessages(h.transport).map(s=>s.message.payload[0]),[26,28,26,28,26,28]); -}); - -test('NACK replays the unresolved window with fresh IDs and reset compression; stale ACKs are ignored', async t => { - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - for (const value of [0, 255, 0]) { h.session.setFrame(new Uint8Array(640 * 480).fill(value)); await h.session.pump(); await tick(); } - await until(() => imageMessages(h.transport).length === 3); - const old = imageMessages(h.transport); - ack(h.transport, old[2]); ack(h.transport, old[1], { nack: true, lenses: [2] }); - await until(() => imageMessages(h.transport).length === 6); - const replay = imageMessages(h.transport).slice(3); - for (const sent of old) ack(h.transport, sent); - await tick(); assert.equal(h.session.state.frames, 0); - replay.forEach((sent, i) => { assert.notEqual(sent.message.magic, old[i].message.magic); assert.ok(sent.message.flags & 8); assert.deepEqual(sent.message.payload, old[i].message.payload); ack(h.transport, sent); }); - await until(() => imageMessages(h.transport).length === 9); - imageMessages(h.transport).slice(6).forEach(sent=>ack(h.transport,sent)); - await until(() => h.session.state.frames === 3); -}); - -test('timeout starts after writes; missing ACK retries are bounded and invalidate the delta base', async t => { - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - const write = h.transport.write.bind(h.transport); let release; - const blocked = new Promise(resolve => { release = resolve; }); - h.transport.write = async (...args) => { if (args[0] === 'L') await blocked; await write(...args); }; - h.session.setFrame(new Uint8Array(640 * 480)); await h.session.pump(); - await new Promise(resolve => setTimeout(resolve, 550)); - assert.equal(h.session.state.phase, 'connected'); assert.equal(imageMessages(h.transport).length, 0); - release(); await until(() => imageMessages(h.transport).length === 2); await tick(); - for (let i = 1; i <= 4; i++) { - h.session.cfwPending.forEach(p => p.deadline = 1); h.session.recoverCfw(); - if (i < 4) await until(() => imageMessages(h.transport).length === 2 * (i + 1)); - } - assert.equal(h.session.state.phase, 'retrying'); assert.match(h.session.state.status, /retry limit/); - assert.equal(h.session.lastEnqueued, null); assert.equal(h.session.cfwPending.length, 0); - for (const sent of imageMessages(h.transport)) ack(h.transport, sent); - await tick(); assert.equal(h.session.state.frames, 0); -}); - -test('failed write poisons queued display work; disconnect cleanup uses the new SID', async t => { - const h = harness(t); await h.session.start(addresses); - const write = h.transport.write.bind(h.transport); let attempts = 0; - h.transport.write = async (...args) => { if (args[0] === 'L') { attempts++; throw new Error('test write failed'); } await write(...args); }; - h.session.setFrame(noisy()); await until(() => h.session.state.phase === 'retrying'); - assert.equal(attempts, 1); assert.equal(h.session.displayInFlight, 0); - await h.session.stop(); h.transport.write = write; await h.session.start(addresses); - h.transport.hold = true; h.session.setFrame(noisy()); await until(() => imageMessages(h.transport).length === 3); - const stale = imageMessages(h.transport); h.transport.hold = false; await h.session.stop(); - stale.forEach(s => ack(h.transport, s)); await tick(); - assert.equal(h.session.state.phase, 'disconnected'); assert.equal(h.session.state.frames, 0); - assert.equal(h.transport.sent.at(-1).message.sid, p.SID.cfw); - assert.deepEqual(h.transport.sent.at(-1).message.payload, new Uint8Array([11])); -}); - -test('full display window still services input and microphone control', async t => { - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - h.session.setFrame(noisy()); await until(() => imageMessages(h.transport).length === 3); - const input = p.bytes(13, p.bytes(3, p.concat(p.integer(1, 9), p.integer(2, 3)))); - h.transport.emit({ kind: 'notification', identifier: 'R', characteristic: p.G2_NOTIFY, data: hex(p.concat(...p.frameMessage(input, p.SID.hub, 1, 22))) }); - assert.equal(h.input.length, 1); - const audio = [], enabling = h.session.setMicrophone(true, packet => audio.push(hex(packet))); - await until(() => h.transport.sent.some(s => s.message.command === 15)); - ack(h.transport, h.transport.sent.find(s => s.message.command === 15)); await enabling; - h.transport.emit({ kind: 'notification', identifier: 'L', characteristic: p.G2_RENDER_NOTIFY, data: '010203' }); - assert.deepEqual(audio, ['010203']); assert.equal(h.session.displayInFlight, 3); -}); - -test('draw updates reconstruct moving and erased pixels while present gates frame completion', async t => { - const {applyDisplayPayload}=require('./helpers/display-payload.cjs'); - const h=harness(t);await h.session.start(addresses);h.transport.hold=true; - const base=new Uint8Array(640*480),a=base.slice(),b=base.slice();a[11*640+13]=255;b[11*640+101]=160; - let screen=new Uint8Array(320*480); - for(const [i,frame] of [base,a,b,base].entries()) { - h.session.setFrame(frame);await h.session.pump();await until(()=>imageMessages(h.transport).length===(i+1)*2); - const [draw,present]=imageMessages(h.transport).slice(i*2); - assert.equal(draw.message.payload[0],26);assert.equal(present.message.payload[0],28); - screen=applyDisplayPayload(screen,draw.message.payload);assert.deepEqual(screen,p.packGray4(frame,640,480)); - ack(h.transport,draw);await tick();assert.equal(h.session.state.frames,i); - ack(h.transport,present);await until(()=>h.session.state.frames===i+1); - } - assert.equal(imageMessages(h.transport)[2].message.payload[7],0); // compact bbox -}); - -test('reconnect reseeds the screen and unified draw calls carry no legacy frame id', async t => { - const h=harness(t);await h.session.start(addresses); - const submit=async gray=>{const before=h.session.state.frames;h.session.setFrame(gray);await until(()=>h.session.state.frames===before+1);return imageBody(imageMessages(h.transport).at(-2));}; - const base=new Uint8Array(640*480),next=base.slice();next[1234]=255; - assert.equal((await submit(base))[7],1); // wide full-screen bounds - const delta=await submit(next);assert.equal(delta[7],0); // compact bbox, immediately followed by RLE - const count=imageMessages(h.transport).length;h.session.setFrame(next);await h.session.pump();await tick();assert.equal(imageMessages(h.transport).length,count); - await h.session.stop();await h.session.start(addresses);assert.equal((await submit(next))[7],1); -}); - -const compassMessages = transport => transport.sent.filter(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 10); -const buzzerMessages = transport => transport.sent.filter(s => s.message.sid === p.SID.cfw && s.message.payload[0] === 5); -const buzzerPayload = () => new Uint8Array([5, 4, 2, 0xb8, 0x0b, 25, 80, 0, 1, 0, 0, 20, 0]); -test('buzzer snapshots the complete Android payload and waits for both lens ACKs without counting a frame', async t => { - const h = harness(t); - await h.session.playBuzzerSequence(buzzerPayload()); - assert.equal(h.transport.sent.length, 0); - await h.session.start(addresses); - await h.session.playBuzzerSequence(new Uint8Array()); - assert.equal(buzzerMessages(h.transport).length, 0); - h.transport.hold = true; - const payload = buzzerPayload(), expected = payload.slice(); - let complete = false; - const playing = h.session.playBuzzerSequence(payload).then(() => { complete = true; }); - payload.fill(0); - await until(() => buzzerMessages(h.transport).length === 1); - const sent = buzzerMessages(h.transport)[0]; - assert.equal(sent.id, 'L'); assert.deepEqual(sent.message.payload, expected); - h.transport.ack(sent.id, sent.message, { lenses: [1] }); await tick(); - assert.equal(complete, false); - h.transport.ack(sent.id, sent.message, { lenses: [2] }); await playing; - assert.equal(h.session.state.frames, 0); -}); - -test('buzzer shares display compression and ACK recovery while the frame window is full', async t => { - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - h.session.setFrame(noisy()); await until(() => imageMessages(h.transport).length === 3); - const playing = h.session.playBuzzerSequence(buzzerPayload()); - await until(() => buzzerMessages(h.transport).length === 1); - const sent = buzzerMessages(h.transport)[0]; - h.transport.ack(sent.id, sent.message, { nack: true }); - await until(() => buzzerMessages(h.transport).length === 2); - const replay = buzzerMessages(h.transport)[1]; - assert.notEqual(replay.message.magic, sent.message.magic); - assert.deepEqual(replay.message.payload, buzzerPayload()); - h.transport.hold = false; // Subsequent bands of the large frame can finish too. - for (const item of h.transport.sent.filter(s => s.message.sid === p.SID.cfw).slice(-4)) ack(h.transport, item); - await playing; - assert.equal(h.session.state.phase, 'connected'); - await until(() => h.session.state.frames === 1); -}); - -test('disconnect cancels queued buzzer work and does not play it on reconnect', async t => { - const h = harness(t); await h.session.start(addresses); h.transport.hold = true; - const playing = h.session.playBuzzerSequence(buzzerPayload()); - await until(() => buzzerMessages(h.transport).length === 1); - h.transport.emit({ kind: 'disconnected', identifier: 'R' }); await playing; - await h.session.playBuzzerSequence(buzzerPayload()); - h.transport.hold = false; await h.session.start(addresses, true); - assert.equal(buzzerMessages(h.transport).length, 1); -}); - -test('compass desired state survives connecting and reconnecting; explicit stop disables it first', async t => { - const h = harness(t); - h.session.setCompassEnabled(true); - await h.session.start(addresses); - assert.equal(compassMessages(h.transport).length, 1); - assert.equal(compassMessages(h.transport)[0].id, 'L'); - assert.deepEqual([...compassMessages(h.transport)[0].message.payload], [10, 2, 100, 0, 0, 0]); - await h.session.stop(); - assert.deepEqual([...compassMessages(h.transport).at(-1).message.payload], [10, 0]); - assert.equal(h.transport.sent.at(-1).message.payload[0], 11); - await h.session.start(addresses); - assert.equal(compassMessages(h.transport).at(-1).message.payload[1], 2); - h.transport.emit({ kind: 'disconnected', identifier: 'R' }); - assert.equal(h.session.state.phase, 'retrying'); - await h.session.start(addresses, true); - assert.equal(compassMessages(h.transport).at(-1).message.payload[1], 2); -}); -test('release during pending compass enable sends disable after the enable ACK', async t => { - const h = harness(t); await h.session.start(addresses); - assert.deepEqual([...compassMessages(h.transport)[0].message.payload], [10, 0]); - h.transport.hold = true; - h.session.setCompassEnabled(true); - await until(() => h.transport.held.length === 1); - h.session.setCompassEnabled(false); - const enabling = h.transport.held.shift(); - h.transport.hold = false; h.transport.ack(enabling.id, enabling.message); - await until(() => compassMessages(h.transport).length === 3); - assert.deepEqual(compassMessages(h.transport).map(s => s.message.payload[1]), [0, 2, 0]); -}); -test('compass notifications only come from the right arm and preserve diagnostics and calibration', async t => { - const h = harness(t); await h.session.start(addresses); - const payload = new Uint8Array(Buffer.from('080f1000520308e702a2060c434d010302038c0098badcfe', 'hex')); - const emit = (id, sid = 8, flag = 1, body = payload) => h.transport.emit({ kind: 'notification', identifier: id, - characteristic: p.G2_NOTIFY, data: hex(p.concat(...p.frameMessage(body, sid, flag, 20))) }); - emit('L'); emit('other'); emit('R', 9); emit('R', 8, 0x20); - assert.equal(h.compass.length, 0); - emit('R'); emit('R', 8, 6, new Uint8Array([8, 16, 16, 0])); - emit('R', 8, 1, new Uint8Array([8, 17, 16, 0])); - assert.deepEqual(h.compass, [{ command: 15, headingDegrees: 359, diagnostics: { - magneticAccuracy: 3, magneticAnomalies: 2, orientationSource: 3, flags: 140, sampleTimeMs: 0xfedcba98, - } }, { command: 16, headingDegrees: -1 }, { command: 17, headingDegrees: -1 }]); -}); - - -test('wear detection matches Android wire format and queries both arms on every connection', async t => { - const wear = require('../.test-build/app/g2/wear-protocol.js'); - assert.equal(hex(wear.enableWearDetection(42)), '0801102a1a042a020801'); - assert.equal(hex(wear.queryWearState()), '08011000aa0606464301070000'); - const h = harness(t); await h.session.start(addresses); - const queries = () => h.transport.sent.filter(({ message }) => hex(message.payload) === hex(wear.queryWearState())); - assert.deepEqual(queries().map(q => q.id).sort(), ['L', 'R']); - const enable = h.transport.sent.find(({ message }) => { - const body = p.readBytes(message.payload, 3); - return message.sid === p.SID.settings && message.command === 1 && body && p.readBytes(body, 5); - }); - assert.equal(enable.id, 'R'); assert.equal(enable.message.flag, 0x20); - await h.session.stop(); await h.session.start(addresses); - assert.equal(queries().length, 4); -}); - -test('wear notifications validate the event and peer and work during initial connection', async t => { - const h = harness(t); - const payload = state => p.concat(p.integer(1, 3), p.bytes(5, p.concat(p.integer(1, 1), p.integer(2, state)))); - const emit = (id, data, sid = 0x10) => h.transport.emit({ kind: 'notification', identifier: id, - characteristic: p.G2_NOTIFY, data: hex(p.concat(...p.frameMessage(data, sid, 1, 12))) }); - const originalWrite = h.transport.write.bind(h.transport); - h.transport.write = async (...args) => { - await originalWrite(...args); - if (h.transport.sent.at(-1)?.message.magic === 0) emit(args[0], payload(0)); - }; - await h.session.start(addresses); - assert.ok(h.wear.length >= 2); assert.ok(h.wear.every(value => value === false)); - h.wear.length = 0; - emit('stranger', payload(0)); emit('ring', payload(0)); emit('R', payload(2)); - emit('R', payload(0), p.SID.hub); emit('R', p.integer(1, 3)); - assert.deepEqual(h.wear, []); - emit('L', payload(0)); emit('R', payload(1)); - assert.deepEqual(h.wear, [false, true]); - await h.session.stop(); emit('R', payload(0)); - assert.deepEqual(h.wear, [false, true]); -}); - - -test('ANCS packets are scoped to the right link and cleared on disconnect and authorization revocation', async t => { - const transport = new FakeTransport(); transport.firmware = REQUIRED_FACECLAW_FIRMWARE_VERSION; - const h = harness(t, transport); await h.session.start(addresses); - await until(() => transport.ancs?.length); - const token = Array.from(transport.ancs[0].frame.subarray(4,8)); - assert.equal(transport.ancs[0].id, 'R'); - const frame = new Uint8Array([65,78,1,0,...token,0,0,3,1]); - const emit = id => transport.emit({kind:'notification',identifier:id,characteristic:p.G2_NOTIFY,data:hex(frame)}); - emit('L'); assert.equal(h.session.notifications.state, 'starting'); - emit('R'); assert.equal(h.session.notifications.state, 'ready'); - transport.emit({kind:'ancs-authorization',identifier:'R',authorized:false}); - assert.equal(h.session.notifications.state,'disconnected'); - emit('R'); assert.equal(h.session.notifications.state,'disconnected'); - await h.session.stop(); assert.deepEqual(h.session.notifications.read(),[]); -}); - -test('firmware 15 requires an upgrade before starting notification relay', async t => { - const transport = new FakeTransport(); transport.firmware = 15; - const h = harness(t, transport); await h.session.start(addresses); - assert.equal(h.session.notifications.state, 'disconnected'); - assert.equal(h.session.state.phase, 'error'); - assert.match(h.session.state.status, new RegExp(`requires revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}`)); - assert.equal(transport.ancs?.length ?? 0, 0); -}); - -test('ANCS app-name lookup uses the right-link write limit, including after reauthorization', async t => { - const transport = new FakeTransport(); transport.firmware = REQUIRED_FACECLAW_FIRMWARE_VERSION; - const h = harness(t, transport); await h.session.start(addresses); - await until(() => transport.ancs?.length); - const id = 'net.superblock.Pushover'; - const attr = (key, value) => { const bytes = [...Buffer.from(value)]; return [key, bytes.length & 255, bytes.length >> 8, ...bytes]; }; - for (let attempt = 0; attempt < 2; attempt++) { - if (attempt) { - transport.emit({kind:'ancs-authorization',identifier:'R',authorized:false}); - const count = transport.ancs.length; - transport.emit({kind:'ancs-authorization',identifier:'R',authorized:true}); - await until(() => transport.ancs.slice(count).some(p => p.frame[3] === 0)); - } - const start = transport.ancs.filter(p => p.frame[3] === 0).at(-1); - const token = [...start.frame.subarray(4,8)]; - let sequence = 0; - const feed = (kind, bytes) => transport.emit({kind:'notification',identifier:'R',characteristic:p.G2_NOTIFY, - data:hex(new Uint8Array([65,78,1,kind,...token,sequence++,0,3,...bytes]))}); - const count = transport.ancs.length; - feed(0,[1]);feed(1,[0,0,1,1,7,0,0,0]); - await until(() => transport.ancs.length === count+1); - feed(3,[]);feed(2,[0,7,0,0,0,...attr(0,id),...attr(1,'Title'),...attr(3,'Message')]); - await until(() => transport.ancs.length === count+2); - feed(3,[]);feed(2,[0,7,0,0,0,...attr(2,''),...attr(4,'7'),...attr(5,''),...attr(6,''),...attr(7,'')]); - await until(() => transport.ancs.length === count+3); - const request = transport.ancs.at(-1); - assert.equal(request.id,'R'); - assert.deepEqual([...request.frame.subarray(8)],[1,...Buffer.from(id),0,0]); - feed(3,[]);feed(2,[1,...Buffer.from(id),0,...attr(0,'Pushover Notifications')]); - assert.equal(h.session.notifications.read()[0].appName,'Pushover Notifications'); - } -}); - -test('brightness sends the Android settings payload to the right temple, including explicit zero and Auto', async () => { - const transport = new FakeTransport(), session = new GlassesSession(transport, () => {}, () => {}); - await session.setBrightness(50); - assert.equal(transport.sent.length, 0, 'preview mode must not send Bluetooth commands'); - const requests = []; - session.state.phase = 'connected'; - session.request = async (role, sid, build) => { requests.push({ role, sid, payload: hex(build(105)) }); }; - await session.setBrightness(0); - await session.setBrightness(80); - await session.setBrightness(null); - assert.deepEqual(requests, [ - { role: 'right', sid: 9, payload: '080110691a060a0408001000' }, - { role: 'right', sid: 9, payload: '080110691a060a0408001050' }, - { role: 'right', sid: 9, payload: '080110691a040a020801' }, - ]); -}); diff --git a/tests/ios-glanceboard.test.cjs b/tests/ios-glanceboard.test.cjs index 555acfe2..35f5808e 100644 --- a/tests/ios-glanceboard.test.cjs +++ b/tests/ios-glanceboard.test.cjs @@ -6,7 +6,6 @@ const vm = require('node:vm'); const ts = require('typescript'); const images = require('../.test-build/app/graphics/image.js'); const { SurfaceCompositor } = require('../.test-build/app/graphics/surface-compositor.js'); -const protocol = require('../.test-build/app/g2/ble-protocol.js'); const events = require('../.test-build/app/g2/events.js'); function load(file, modules, globals = {}) { @@ -24,8 +23,8 @@ const timings = load('app/native/frame-timings.ts', {}); function fixture() { const observers = new Map(), phoneState = { protectedDataAvailable: true }; - let settingsChanged, remoteHost; - let now = 1000, nextTask = 0, screenOn = true, shellOptions, session; + let settingsChanged, remoteHost, controller, bridge = null; + let now = 1000, nextTask = 0, screenOn = true, shellOptions; const tasks = new Map(), sent = [], previews = [], received = [], errors = []; const boardStats = { starts: 0, stops: 0, paints: 0 }; const settings = { lock: true, enabled: true, tap: true, hold: true, tilt: true, duration: 3000 }; @@ -39,8 +38,10 @@ function fixture() { '../util/render-freshness': { beginRenderPass() {}, endRenderPass: () => false }, './glance-state': require('../.test-build/app/g2/glance-state.js'), }, clock); + const launcherPixels = new Uint8Array(640 * 480).fill(75), fullRect = { x: 0, y: 0, width: 640, height: 480 }; const window = { windowId: 'launcher', surfaceId: 'launcher', appId: 'launcher', title: 'Apps', - requestRender() {}, setScreenOn() {} }; + // The launcher repaints into whichever display target the controller has after a switch. + requestRender() { void controller?.displayReady.then(() => controller.display?.submitSurfaceFrame('launcher', launcherPixels, fullRect, 'launcher')); }, setScreenOn() {} }; const shell = { configure: options => { shellOptions = options; }, registerWindow() {}, focusWindow() {}, wake: () => { screenOn = true; shellOptions.onScreenStateChanged(true); }, @@ -54,15 +55,43 @@ function fixture() { if (input.type === 'display-wake' || !screenOn && input.type === 'double-click') shell.wake(); }, }; - class Session { - state = { phase: 'disconnected' }; - constructor(_transport, onState, onInput, _log, _activity, _compass, onWear) { session = this; this.onState = onState; this.onInput = onInput; this.onWear = onWear; } - async enableWearDetectionAndRequestState() {} - async start() { this.state = { phase: 'connected' }; this.onState(this.state); } - async stop() { this.state = { phase: 'disconnected' }; this.onState(this.state); } - async setBrightness() {} - setFrame(pixels) { if (this.state.phase === 'connected') sent.push(pixels); } - wake() {} + // Both display targets compose with the real (TypeScript reference) compositor so + // the pixel assertions below exercise real layering, blanking and lock surfaces. + class Display { + compositor = new SurfaceCompositor(640, 480); + async configureCompositorScreen() {} + async configureSurface(id, options) { this.compositor.configureSurface(id, options); } + async removeSurface(id) { this.compositor.removeSurface(id); this.changed(); } + async setSurfaceVisible(id, visible) { this.compositor.setSurfaceVisible(id, visible); this.changed(); } + async setUnderlayDim(below, factor) { this.compositor.setUnderlayDim(below, factor); this.changed(); } + async setScreenBlanked(blanked) { this.compositor.setScreenBlanked(blanked); this.changed(); } + async submitSurfaceFrame(id, pixels, rect, _fingerprint, _paintMs, _frameId, draws = null) { this.compositor.submitSurfaceFrame(id, pixels, rect, draws); this.changed(); } + async submitShellScene(bytes) { this.compositor.setShellScene(bytes); this.changed(); } + getCompositePreview() { return this.compositor.composite(); } + changed() {} + } + class PreviewDisplayTarget extends Display { + activate(fn) { this.onFrame = fn; } release() { this.onFrame = null; } + changed() { this.onFrame?.(); } + waitForFrameFinished() { return Promise.resolve('composited'); } + } + const noop = () => () => {}; + class FaceclawCommunicatorBridge extends Display { + phase = 'disconnected'; listeners = {}; + constructor() { super(); bridge = this; } + on(kind, fn) { this.listeners[kind] = fn; return () => { if (this.listeners[kind] === fn) delete this.listeners[kind]; }; } + onStateChange(fn) { return this.on('state', fn); } onRingEvent(fn) { return this.on('ring', fn); } + onWearState(fn) { return this.on('wear', fn); } onBatteryState() { return noop(); } onFirmwareInfo() { return noop(); } + onFrameMetrics() { return noop(); } addCompassListener() { return noop(); } onAncsRelayFrame() { return noop(); } + onAncsAuthorization() { return noop(); } setRequiresAncs() {} rightWriteLimit() { return 20; } onPhoneLockSignal() {} + async writeRawToRight() {} async setBrightness() {} async enableWearDetectionAndRequestState() {} async playBuzzerSequence() {} async close() {} + emitState(phase, status = phase) { if (phase === 'connected' || phase === 'disconnected') this.phase = phase; this.listeners.state?.({ phase, status }); } + emitRing(input) { this.listeners.ring?.(input); } + emitWear(wearing) { this.listeners.wear?.(wearing); } + async start() { this.emitState('connected', 'Connected.'); } + async disconnect() { this.emitState('disconnected', 'Disconnected.'); } + waitForFrameFinished() { return Promise.resolve('sent'); } + changed() { if (this.phase === 'connected') sent.push(this.compositor.composite()); } } const provider = { isEnabled: () => settings.enabled, showOnTap: () => settings.tap, @@ -85,13 +114,14 @@ function fixture() { "../native/compass.ios": { bindCompassSession() {}, receiveCompassEvent() {} }, '@nativescript/core': { File: { fromPath: () => ({ writeTextSync() {} }) }, knownFolders: { documents: () => ({ path: '/tmp' }) }, path }, - '../native/ios-bluetooth': { iosBluetooth: () => ({}) }, '../native/ios-voice-input': { iosVoiceInput: { handleSessionEnded() {}, stopPhoneCapture() {} } }, - './glasses-session': { GlassesSession: Session }, + '../native/faceclaw-communicator.ios': { FaceclawCommunicatorBridge, resolveIosPeripherals: async addresses => addresses }, + '../native/preview-display.ios': { PreviewDisplayTarget }, + './ancs-client': { ANCS_FIRMWARE_VERSION: 16, AncsClient: class { state = 'disconnected'; start() {} stop() {} stopCommand() { return new Uint8Array(); } receive() { return false; } } }, '../native/nightscout-bridge': { nightscoutBridge: { async start() {}, async stop() {} } }, './glance-host': { GlanceHost }, './events': events, './lock-screen': { LOCK_SCREEN_SURFACE_ID: 'lock-screen', createLockScreenImage: () => new images.GrayImage(640, 480, 123) }, - './device-addresses': { loadDeviceAddresses: () => ({}) }, './ios-peripheral-identity': { deviceAddressError: () => null }, + './device-addresses': { loadDeviceAddresses: () => ({ right: 'AA', left: 'BB', ring: '' }) }, './ios-peripheral-identity': { deviceAddressError: () => null }, '../apps/launcher': { launcherEntries: () => [] }, '../apps/evenhub/installed-apps': {}, '../apps/evenhub/manager': {}, '../apps/evenhub/updates': {}, '../apps/evenhub': {}, '../apps/launcher/launcher-app': { createLauncherWindow: () => window, LAUNCHER_SURFACE_ID: 'launcher' }, @@ -103,9 +133,7 @@ function fixture() { '../native/phone-battery': { readPhoneBatteryState: () => ({ battery: 80, charging: false }) }, '../apps/ios-availability': { iosAppUnavailableReason: () => null }, '../graphics/glyph-wire': { prepareFrameDraws: () => null }, - '../native/texture-planner.ios': { IosTexturePlanner: class {} }, - '../graphics/surface-compositor': { SurfaceCompositor }, '../graphics/plane': planes, '../graphics/image': images, - '../native/ios-graphics': { previewPixels: pixels => pixels }, + '../graphics/plane': planes, '../graphics/image': images, '../ui/gestures': { makeInputEvent: event => event }, '../ui/layers': { noopLayerActions: {} }, '../apps/files/text-viewer': {}, '../ui/shell/shell': { shell, rawInputEventToInputEvent: event => ({ @@ -124,8 +152,8 @@ function fixture() { NSNotificationCenter: { defaultCenter: { addObserverForNameObjectQueueUsingBlock(name, _object, _queue, fn) { observers.set(name, fn); return name; }, removeObserver(name) { observers.delete(name); } } }, NSOperationQueue: { mainQueue: {} }, }); - const controller = new IosPreviewController((pixels, title) => previews.push({ pixels, title }), message => errors.push(message)); - controller.compositor.submitSurfaceFrame('launcher', new Uint8Array(640 * 480).fill(75), { x: 0, y: 0, width: 640, height: 480 }); + controller = new IosPreviewController((pixels, title) => previews.push({ pixels, title }), message => errors.push(message)); + window.requestRender(); controller.resume(); async function drain() { await controller.inputQueue; await controller.glance.queue; } async function advance(ms) { @@ -133,16 +161,18 @@ function fixture() { for (const [id, task] of [...tasks]) if (task.at <= now && tasks.delete(id)) task.fn(); await drain(); } - async function render() { await drain(); await advance(33); assert.deepEqual(errors, []); } + async function render() { await drain(); await advance(33); await drain(); assert.deepEqual(errors, []); } async function hardware(type, source = 2, ringTick) { - const payload = protocol.bytes(13, protocol.bytes(3, protocol.concat(protocol.integer(1, type), protocol.integer(2, source)))); - const input = protocol.decodeGlassesInput({ sid: protocol.SID.hub, flag: 1, payload }); - if (ringTick !== undefined) input.ringInput = { type: type === 3 ? 2 : 1, tick: ringTick, aux:0, speed:0 }; - session.onInput(input); + const input = { kind: type === 12 ? 'display-wake' : 'sys-event', containerName: '', eventType: type, eventSource: source, + systemExitReasonCode: 0, frameId: 0 }; + if (ringTick !== undefined) input.ringInput = { type: type === 3 ? 2 : 1, tick: ringTick, aux: 0, speed: 0 }; + bridge.emitRing(input); await render(); } async function phone(type, origin = 'ring') { controller.gesture(type, origin); await render(); } - return { controller, shell, remoteHost, keyboardChanged: session => shellOptions.onKeyboardInputChanged(session), settings, phoneState, observers, wear: wearing => session.onWear(wearing), settingsChanged: () => settingsChanged(), sent, previews, received, boardStats, hardware, phone, advance, render }; + async function connect() { await controller.connect(); await render(); } + return { controller, shell, remoteHost, keyboardChanged: session => shellOptions.onKeyboardInputChanged(session), settings, phoneState, observers, + get bridge() { return bridge; }, connect, wear: wearing => bridge.emitWear(wearing), settingsChanged: () => settingsChanged(), sent, previews, received, boardStats, hardware, phone, advance, render }; } const assertBlank = pixels => assert.ok(pixels.every(p => p === 0)); const assertBoard = pixels => { @@ -151,7 +181,7 @@ const assertBoard = pixels => { }; test('iOS sleep tap shows the shared board; repeated tap renews timeout and hides to black', async () => { - const f = fixture(); await f.controller.connect(); f.shell.sleep(); await f.render(); + const f = fixture(); await f.connect(); f.shell.sleep(); await f.render(); assertBlank(f.sent.at(-1)); await f.hardware(0); assertBoard(f.sent.at(-1)); assert.equal(f.shell.isScreenOn(), false); assert.equal(f.previews.at(-1).title, 'Glanceboard'); assert.equal(f.received.length, 0); @@ -165,7 +195,7 @@ test('iOS sleep tap shows the shared board; repeated tap renews timeout and hide }); test('iOS holds and tap-then-holds last until release, including with phone backgrounded', async () => { - const f = fixture(); await f.controller.connect(); f.shell.sleep(); f.controller.pause(); + const f = fixture(); await f.connect(); f.shell.sleep(); f.controller.pause(); const previews = f.previews.length; for (const type of [9, 11]) { await f.hardware(type, 1); assertBoard(f.sent.at(-1)); @@ -176,7 +206,7 @@ test('iOS holds and tap-then-holds last until release, including with phone back }); test('double-tap and other shell wakes replace Glanceboard without waking it again', async () => { - const f = fixture(); await f.controller.connect(); f.shell.sleep(); + const f = fixture(); await f.connect(); f.shell.sleep(); await f.hardware(9); await f.hardware(3); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.controller.glance.isVisible(), false); assert.equal(f.sent.at(-1)[0], 80); assert.equal(f.boardStats.stops, 1); @@ -186,14 +216,14 @@ test('double-tap and other shell wakes replace Glanceboard without waking it aga }); test('head tilt uses Glanceboard when enabled and otherwise wakes the regular UI', async () => { - const f = fixture(); await f.controller.connect(); f.shell.sleep(); + const f = fixture(); await f.connect(); f.shell.sleep(); await f.hardware(12, 1); assertBoard(f.sent.at(-1)); assert.equal(f.shell.isScreenOn(), false); await f.hardware(3); f.shell.sleep(); f.settings.tilt = false; await f.hardware(12, 1); assert.equal(f.shell.isScreenOn(), true); assert.equal(f.sent.at(-1)[0], 80); }); test('disabled triggers and scrolls do not show the board; awake taps still reach the shell', async () => { - const f = fixture(); await f.controller.connect(); + const f = fixture(); await f.connect(); await f.hardware(0); assert.equal(f.received.at(-1).type, 'click'); assert.equal(f.boardStats.starts, 0); f.shell.sleep(); f.settings.tap = false; f.settings.hold = false; for (const type of [0, 9, 11, 10, 1, 2]) await f.hardware(type); @@ -218,7 +248,7 @@ test('phone preview gestures use Glanceboard; losing runtime cleans up holds and test('iOS lock hides apps and Glanceboard, blocks input, and stays locked when put back on', async () => { - const f = fixture(); await f.controller.connect(); f.shell.sleep(); await f.hardware(0); + const f = fixture(); await f.connect(); f.shell.sleep(); await f.hardware(0); f.controller.pause(); // The notification precedes the property change: do not immediately undo it. f.observers.get('lock')(); f.wear(false); await f.render(); @@ -239,7 +269,7 @@ test('iOS lock hides apps and Glanceboard, blocks input, and stays locked when p }); test('iOS removal before phone lock, setting changes, and observer lifetime', async () => { - const f = fixture(); await f.controller.connect(); f.wear(false); await f.render(); + const f = fixture(); await f.connect(); f.wear(false); await f.render(); assert.equal(f.controller.glassesLocked, false); f.observers.get('lock')(); await f.render(); assert.equal(f.controller.glassesLocked, true); @@ -255,7 +285,7 @@ test('iOS removal before phone lock, setting changes, and observer lifetime', as }); test('iOS wear notifications catch protected-data changes missed while suspended', async () => { - const f = fixture(); await f.controller.connect(); f.controller.pause(); + const f = fixture(); await f.connect(); f.controller.pause(); f.phoneState.protectedDataAvailable = false; f.wear(false); await f.render(); assert.equal(f.controller.glassesLocked, true); f.controller.resume(); await f.render(); @@ -267,7 +297,7 @@ test('iOS wear notifications catch protected-data changes missed while suspended test('iOS locked phone controls cannot dispatch mirror, voice, or keyboard input', async () => { - const f = fixture(); await f.controller.connect(); f.wear(false); + const f = fixture(); await f.connect(); f.wear(false); f.observers.get('lock')(); await f.render(); await f.phone('tap', 'mirror'); await f.phone('long-press', 'watch'); f.controller.startVoiceInput(); @@ -276,16 +306,16 @@ test('iOS locked phone controls cannot dispatch mirror, voice, or keyboard input assert.equal(f.received.length, 0); assert.equal(f.controller.glassesLocked, true); // Locked state also survives transport recovery until a phone unlock. - f.controller.session.onState({ phase: 'retrying' }); - f.controller.session.onState({ phase: 'connecting' }); - f.controller.session.onState({ phase: 'connected' }); + f.bridge.emitState('retrying'); + f.bridge.emitState('connecting'); + f.bridge.emitState('connected'); await f.render(); assert.ok(f.sent.at(-1).every(p => p === 123)); }); test('iOS deduplicates original ring ticks before apps, lock toggles and Glanceboard', async () => { - const f = fixture(); await f.controller.connect(); + const f = fixture(); await f.connect(); await f.hardware(0,2,1000); await f.hardware(0,2,1050); assert.equal(f.received.length,1); await f.hardware(0,2,1100); assert.equal(f.received.length,2); @@ -299,8 +329,8 @@ test('iOS deduplicates original ring ticks before apps, lock toggles and Glanceb assert.equal(f.shell.isScreenOn(),true); await f.hardware(3,2,2050); assert.equal(f.shell.isScreenOn(),true); // A new transport session starts a fresh suppression window. - f.controller.session.onState({ phase:'retrying' }); - f.controller.session.onState({ phase:'connected' }); + f.bridge.emitState('retrying'); + f.bridge.emitState('connected'); await f.hardware(3,2,2051); assert.equal(f.shell.isScreenOn(),false); }); @@ -325,7 +355,7 @@ test('keyboard sessions cannot deliver text after the glasses lock or phone leav test('external input shares iOS dispatch, including hold release and phone-lock gating', async () => { - const f = fixture(); await f.controller.connect(); f.wear(false); + const f = fixture(); await f.connect(); f.wear(false); assert.equal(f.remoteHost.ready(), true); assert.equal(f.remoteHost.locked(), false); await f.remoteHost.input('swipe-left', 'watch'); diff --git a/tests/ios-onboarding.test.cjs b/tests/ios-onboarding.test.cjs index b0bfb58b..08fa8512 100644 --- a/tests/ios-onboarding.test.cjs +++ b/tests/ios-onboarding.test.cjs @@ -13,78 +13,110 @@ function load(file, modules = {}, globals = {}) { return context.exports; } const flush = () => new Promise(resolve => setImmediate(resolve)); -function flasherFixture({ hash = 'custom', failRole = '', backgroundRole = '' } = {}) { - const calls = [], events = new Map(), native = { idleTimerDisabled: false, applicationState: 0 }; +const settle = async (rounds = 6) => { for (let i = 0; i < rounds; i++) { await flush(); await new Promise(resolve => setTimeout(resolve, 0)); } }; +// The Kotlin facades (FaceclawKitIos*) deliver listener callbacks on the main queue; the +// fakes call the TypeScript listener object directly. NSObject.extend is how the wrappers +// implement Kotlin listener protocols. +const nsObject = { extend: methods => ({ new: () => ({ ...methods }) }) }; +function bluetooth(identifiers = { right: 'R-ID', left: 'L-ID' }, fail = null) { + return { iosBluetooth: () => ({ resolveDevices: async addresses => { + if (fail) throw new Error(fail); + return Object.fromEntries(Object.entries(identifiers).filter(([role]) => addresses[role])); + } }) }; +} +function flasherFixture({ hash = 'custom', outcome = 'success', backgroundOn = '', resolveError = null } = {}) { + const calls = [], events = new Map(), native = { idleTimerDisabled: false, applicationState: 0 }, instances = []; const app = { suspendEvent: 'suspend', on: (e, cb) => events.set(e, cb), off: e => events.delete(e) }; - class Link { - closed = false; - check() { if (this.closed) throw new Error('Cancelled'); } - async resolve() { calls.push('resolve'); } - async connect(role, ota) { this.check(); calls.push(`connect:${role}:${ota}`); } - async authenticate(role) { this.check(); calls.push(`auth:${role}`); } - disconnect(role) { calls.push(`disconnect:${role}`); } - close() { this.closed = true; calls.push('close'); } - } + const FaceclawKitIosFirmwareFlasher = { alloc: () => ({ initWithRightAddressLeftAddressFirmwarePath(right, left, path) { + const flasher = { listener: null, cancelled: false, closed: false, + setListenerListener(listener) { this.listener = listener; }, + start() { + calls.push(`start:${right}:${left}:${path}`); + setTimeout(() => { + for (const lens of ['left', 'right']) { + if (this.cancelled) break; + this.listener.onStateStateDetail('connecting', lens); this.listener.onStateStateDetail('flashing', lens); + this.listener.onProgressLensComponentIndexComponentCountBlockIndexBlockCountBytesSentBytesTotal(lens, 1, 1, 1, 1, 16, 16); + if (lens === backgroundOn) events.get('suspend')(); + if (outcome === 'fail' && lens === 'right') { this.listener.onCompleteSuccessDetail(false, 'END rejected'); return; } + } + if (this.cancelled) { this.listener.onCompleteSuccessDetail(false, 'Cancelled. Retry with both lenses powered on to complete installation.'); return; } + this.listener.onStateStateDetail('done', 'Both lenses flashed. Your glasses are rebooting.'); + this.listener.onCompleteSuccessDetail(true, 'Both lenses flashed. Your glasses are rebooting.'); + }, 0); + }, + cancel() { this.cancelled = true; calls.push('cancel'); }, close() { this.closed = true; calls.push('close'); } }; + instances.push(flasher); return flasher; + } }) }; const { FirmwareFlasher } = load('app/native/firmware-flasher.ios.ts', { - '@nativescript/core': { Application: app }, '../g2/stock-connection': { StockConnection: Link }, + '@nativescript/core': { Application: app }, '../g2/firmware/cfw-patches': { CFW_PATCH_SET: { outputSha256: 'custom', baseSha256: 'stock' } }, './firmware-files.ios': { readFirmwareFile: () => new Uint8Array(16), firmwareSha256: () => hash }, - './ios-bluetooth': { iosBluetooth: () => ({}) }, - '../g2/firmware-ota': { validateFirmware: () => { calls.push('validate'); return []; }, - flashLensImage: async (link, role) => { - calls.push(`flash:${role}`); - if (role === backgroundRole) events.get('suspend')(); - link.check(); - if (role === failRole) throw new Error('END rejected'); - } }, - }, { UIApplication: { sharedApplication: native }, UIApplicationState: { Active: 0 }, - setTimeout: fn => setTimeout(fn, 0) }); + './ios-bluetooth': bluetooth({ right: 'R-ID', left: 'L-ID' }, resolveError), './kotlin-listener.ios': listenerModule, + }, { UIApplication: { sharedApplication: native }, UIApplicationState: { Active: 0 }, FaceclawKitIosFirmwareFlasher, FaceclawKitFaceclawFirmwareFlasherListener: {} }); const flasher = new FirmwareFlasher({ right: 'r', left: 'l' }, 'prepared.bin'); + const states = [], progress = []; + flasher.onStateChange((state, detail) => states.push(`${state}:${detail}`)); flasher.onProgress(value => progress.push(value.lens)); const result = new Promise(resolve => flasher.onComplete((success, detail) => resolve({ success, detail }))); - return { calls, events, native, flasher, result }; + return { calls, events, native, flasher, result, instances, states, progress }; } +const listenerModule = load('app/native/kotlin-listener.ios.ts', {}, { NSObject: nsObject }); -test('iOS flashing authenticates and verifies both lenses in order before reporting success', async () => { +test('iOS flashing checks the image hash, resolves identifiers, runs the Kotlin OTA flow and reports success', async () => { for (const hash of ['custom', 'stock']) { const f = flasherFixture({ hash }); f.flasher.start(); f.flasher.start(); assert.equal((await f.result).success, true); - assert.deepEqual(f.calls, ['validate', 'resolve', 'connect:left:true', 'auth:left', 'flash:left', 'disconnect:left', - 'connect:right:true', 'auth:right', 'flash:right', 'disconnect:right', 'close']); + assert.deepEqual(f.calls, ['start:R-ID:L-ID:prepared.bin', 'close']); assert.equal(f.native.idleTimerDisabled, false); assert.equal(f.events.size, 0); + await settle(); + assert.deepEqual(f.states, ['validating:', 'connecting:left', 'flashing:left', 'connecting:right', 'flashing:right', 'done:Both lenses flashed. Your glasses are rebooting.']); + assert.deepEqual(f.progress, ['left', 'right']); } }); test('iOS flashing refuses a changed image before Bluetooth and never reports partial success', async () => { const invalid = flasherFixture({ hash: 'changed' }); invalid.flasher.start(); - assert.match((await invalid.result).detail, /SHA-256/); assert.deepEqual(invalid.calls, ['close']); - const failure = flasherFixture({ failRole: 'right' }); failure.flasher.start(); + assert.match((await invalid.result).detail, /SHA-256/); assert.deepEqual(invalid.calls, []); assert.equal(invalid.native.idleTimerDisabled, false); + const unresolved = flasherFixture({ resolveError: 'Could not find the left arm.' }); unresolved.flasher.start(); + assert.match((await unresolved.result).detail, /left arm/); assert.deepEqual(unresolved.calls, []); + const failure = flasherFixture({ outcome: 'fail' }); failure.flasher.start(); const result = await failure.result; assert.equal(result.success, false); assert.match(result.detail, /END rejected/); - assert.equal(failure.native.idleTimerDisabled, false); assert.equal(failure.events.size, 0); + assert.equal(failure.native.idleTimerDisabled, false); assert.equal(failure.events.size, 0); assert.equal(failure.calls.includes('close'), true); }); test('backgrounding during iOS OTA stops the transfer and directs retry of both lenses', async () => { - const f = flasherFixture({ backgroundRole: 'left' }); f.flasher.start(); + const f = flasherFixture({ backgroundOn: 'left' }); f.flasher.start(); const result = await f.result; assert.equal(result.success, false); assert.match(result.detail, /left the foreground.*retry both lenses/); - assert.equal(f.calls.includes('flash:right'), false); assert.equal(f.native.idleTimerDisabled, false); + assert.equal(f.instances[0].cancelled, true); assert.equal(f.progress.includes('right'), false); assert.equal(f.native.idleTimerDisabled, false); }); -test('iOS firmware prompt surfaces heartbeat disconnection instead of leaving confirmation stuck', async () => { - let heartbeat; - const p = require('../.test-build/app/g2/ble-protocol.js'); - class Link { - async resolve() {} async connect() {} async authenticate() {} async request() {} - onMessage() { return () => {}; } nextMagic() { return 1; } close() {} - async write() { throw new Error('Lost connection to the right lens.'); } - } +test('iOS firmware prompt maps addresses to identifiers, forwards the Kotlin flow events and surfaces its errors', async () => { + const instances = []; + const FaceclawKitIosFlashPrompt = { alloc: () => ({ initWithRightAddressLeftAddressWarningTextSkipPrompt(right, left, warning, skip) { + const prompt = { args: [right, left, warning, skip], listener: null, closed: false, started: 0, + setListenerListener(listener) { this.listener = listener; }, start() { this.started++; }, cancel() {}, close() { this.closed = true; } }; + instances.push(prompt); return prompt; + } }) }; const { FlashPromptCommunicator } = load('app/native/flash-prompt-communicator.ios.ts', { - '../g2/stock-connection': { StockConnection: Link }, '../g2/flash-prompt-protocol': {}, '../g2/ble-protocol': p, - './ios-bluetooth': { iosBluetooth: () => ({}) }, - }, { setInterval: fn => { heartbeat = fn; return 1; }, clearInterval() {} }); - const prompt = new FlashPromptCommunicator({ right: 'r', left: 'l' }, 'warning'), errors = []; - prompt.onStateChange((state, detail) => { if (state === 'error') errors.push(detail); }); - prompt.start(); await flush(); heartbeat(); await flush(); - assert.deepEqual(errors, ['Lost connection to the right lens.']); prompt.close(); + './ios-bluetooth': bluetooth(), './kotlin-listener.ios': listenerModule, + }, { FaceclawKitIosFlashPrompt, FaceclawKitFaceclawFlashPromptListener: {} }); + const prompt = new FlashPromptCommunicator({ right: 'r', left: 'l' }, 'warning', { skipPrompt: true }), states = [], results = [], batteries = []; + prompt.onStateChange((state, detail) => states.push(`${state}:${detail}`)); prompt.onResult(approved => results.push(approved)); prompt.onBattery(b => batteries.push(b)); + prompt.start(); prompt.start(); await settle(); + assert.equal(instances.length, 1); assert.deepEqual(instances[0].args, ['R-ID', 'L-ID', 'warning', true]); assert.equal(instances[0].started, 1); + const listener = instances[0].listener; + listener.onStateStateDetail('connected', ''); listener.onBatteryRightPercentLeftPercent(88, -1); listener.onResultApproved(true); + listener.onStateStateDetail('error', 'Lost connection to the right lens.'); await settle(); + assert.deepEqual(states, ['connecting:', 'connected:', 'error:Lost connection to the right lens.']); + assert.deepEqual(JSON.parse(JSON.stringify(batteries)), [{ right: 88, left: null }]); assert.deepEqual(results, [true]); + prompt.close(); assert.equal(instances[0].closed, true); + const unresolved = load('app/native/flash-prompt-communicator.ios.ts', { + './ios-bluetooth': bluetooth({}, 'Wake the glasses.'), './kotlin-listener.ios': listenerModule, + }, { FaceclawKitIosFlashPrompt, FaceclawKitFaceclawFlashPromptListener: {} }); + const failed = new unresolved.FlashPromptCommunicator({ right: 'r', left: 'l' }, 'warning'), errors = []; + failed.onStateChange((state, detail) => { if (state === 'error') errors.push(detail); }); + failed.start(); await settle(); assert.deepEqual(errors, ['Wake the glasses.']); assert.equal(instances.length, 1); }); test('iOS onboarding returns to the existing main controller, or creates it after first setup', () => { @@ -117,37 +149,34 @@ test('pinned stock firmware reproduces the custom image, extracts fonts, and pas '../util/hex-util': require('../.test-build/app/util/hex-util.js'), '../graphics/evenhub-font': { EvenHubFont: { invalidate() {} } }, '../native/firmware-files': { firmwareSha256: hash, writeFirmwareFile: (file, buffer) => fs.writeFileSync(file, new Uint8Array(buffer)) }, }); - const { validateFirmware } = require('../.test-build/app/g2/firmware-ota.js'); const stock = await builder.buildStockFirmware(); assert.equal(stock.sha256, patches.CFW_PATCH_SET.baseSha256); - assert.equal(validateFirmware(fs.readFileSync(stock.path)).length, 6); const custom = await builder.buildCustomFirmware(); assert.equal(hash(fs.readFileSync(custom.path)), patches.CFW_PATCH_SET.outputSha256); - assert.equal(validateFirmware(fs.readFileSync(custom.path)).length, 6); assert.equal(builder.hasExtractedEvenHubFonts(), true); }); -for (const unsolicited of [false, true]) test(`iOS firmware probe ${unsolicited ? 'accepts a version push with device-owned magic' : 'falls back to the left lens after a silent right lens'}`, async () => { - const p = require('../.test-build/app/g2/ble-protocol.js'), calls = []; - let listener; - const str = (field, text) => p.bytes(field, new Uint8Array(Buffer.from(text))); - const version = { sid: p.SID.settings, payload: p.concat(p.bytes(4, p.concat(str(5, '2.2.9.22'), str(6, '2.2.9.22'))), str(100, 'faceclaw/13')) }; - class Link { - onMessage(fn) { listener = fn; } async resolve() {} check() {} isConnected() { return true; } - async connect(role) { calls.push(`connect:${role}`); } - async authenticate(role) { calls.push(`auth:${role}`); } - async request(role, sid) { - if (sid === p.SID.launch) return {}; - if (role === 'right') { if (unsolicited) listener(role, version); throw new Error('Timeout'); } - return version; - } - close() { calls.push('close'); } - } +test('iOS firmware probe resolves identifiers, runs the Kotlin flow and settles once', async () => { + const instances = []; + const FaceclawKitIosDeviceInfoProbe = { alloc: () => ({ initWithRightAddressLeftAddress(right, left) { + const probe = { args: [right, left], listener: null, closed: 0, setListenerListener(listener) { this.listener = listener; }, start() { this.started = true; }, cancel() {}, close() { this.closed++; } }; + instances.push(probe); return probe; + } }) }; const { DeviceInfoProbe } = load('app/native/device-info-probe.ios.ts', { - '../g2/stock-connection': { StockConnection: Link, StockTimeout: class extends Error {} }, - '../g2/ble-protocol': p, './ios-bluetooth': { iosBluetooth: () => ({}) }, - }); - const info = await new DeviceInfoProbe('r', 'l').run(); - assert.equal(info.rightVersion, '2.2.9.22'); assert.equal(info.leftVersion, '2.2.9.22'); assert.equal(info.extension, 'faceclaw/13'); - assert.deepEqual(calls, ['connect:right', 'auth:right', 'connect:left', 'auth:left', 'close']); + './ios-bluetooth': bluetooth(), './kotlin-listener.ios': listenerModule, + }, { FaceclawKitIosDeviceInfoProbe, FaceclawKitFaceclawDeviceInfoProbeListener: {} }); + const probe = new DeviceInfoProbe('r', 'l'), states = []; + probe.onStateChange((state, detail) => states.push(`${state}:${detail}`)); + const pending = probe.run(); await settle(); + assert.deepEqual(instances[0].args, ['R-ID', 'L-ID']); assert.equal(instances[0].started, true); + instances[0].listener.onStateStateDetail('querying', 'right'); + instances[0].listener.onResultLeftVersionRightVersionExtension('2.2.9.22', '2.2.9.22', 'faceclaw/13'); + instances[0].listener.onErrorMessage('late error is ignored'); + const info = await pending; await settle(); + assert.deepEqual(JSON.parse(JSON.stringify(info)), { leftVersion: '2.2.9.22', rightVersion: '2.2.9.22', extension: 'faceclaw/13' }); + assert.deepEqual(states, ['connecting:right', 'querying:right']); assert.equal(instances[0].closed, 1); + const failing = new DeviceInfoProbe('r'); const failed = failing.run(); await settle(); + assert.deepEqual(instances[1].args, ['R-ID', '']); + instances[1].listener.onErrorMessage("Connected, but couldn't read a firmware version."); + await assert.rejects(failed, /firmware version/); }); test('iOS discovery stops pending scans on cancellation and ignores a late permission result', async () => { diff --git a/tests/ring-input-protocol.test.cjs b/tests/ring-input-protocol.test.cjs deleted file mode 100644 index 244fb255..00000000 --- a/tests/ring-input-protocol.test.cjs +++ /dev/null @@ -1,32 +0,0 @@ -const test = require('node:test'); -const assert = require('node:assert/strict'); -const protocol = require('../.test-build/app/g2/ble-protocol.js'); -const decode = (payload) => protocol.decodeGlassesInput({ sid:224,flag:1,payload }); -const packet = Buffer.from('08026a151a13080e1002a2060c524901010aabcd00efcdab89','hex'); - -test('timestamped CFW packet decodes atomically with source and original unsigned tick', () => { - const input = decode(packet); - assert.equal(input.eventType,14); assert.equal(input.eventSource,2); - assert.deepEqual(input.ringInput,{tick:0x89abcdef,type:10,aux:171,speed:205}); - for (const tick of [0,1,0xffffffff]) { - const p = Buffer.from(packet); p.writeUInt32LE(tick,21); - assert.equal(decode(p).ringInput.tick,tick); - } -}); -test('legacy/invalid metadata leaves input intact without inventing a clock', () => { - assert.equal(decode(Buffer.from('08026a041a02080e','hex')).ringInput,undefined); - for (const offset of [9,13,14,15,16,20]) { - const p = Buffer.from(packet); p[offset]++; - assert.equal(decode(p).ringInput,undefined); - } -}); - -// Firmware regression: MsgPbTxByBle sets flag 0; Thread_MsgPbNotifyByBle -// (also used by stock SysEvent) sets flag 1. Payload validity is insufficient. -test('ring input must use the notification envelope, never the reply envelope', () => { - assert.equal(protocol.decodeGlassesInput({ sid:224,flag:0,payload:packet }),null); - for (const flag of [1,6]) { - const input = protocol.decodeGlassesInput({ sid:224,flag,payload:packet }); - assert.equal(input.eventType,14); assert.equal(input.ringInput.tick,0x89abcdef); - } -}); diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 05e62fc8..4a66e3c4 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -2,7 +2,9 @@ "compilerOptions": { "module": "commonjs", "target": "ES2020", - "lib": ["ES2020"], + "lib": [ + "ES2020" + ], "strict": true, "esModuleInterop": true, "skipLibCheck": true, @@ -14,15 +16,10 @@ "../app/remote/protocol.ts", "../app/remote/listeners.ts", "../app/g2/ancs-client.ts", - "../app/g2/ble-protocol.ts", "../app/graphics/lvgl-font.ts", "../app/phone-ui/ble-bandwidth-meter.ts", "../app/apps/terminal/hub-header.ts", "../app/g2/ios-peripheral-identity.ts", - "../app/g2/glasses-session.ts", - "../app/g2/stock-connection.ts", - "../app/g2/firmware-ota.ts", - "../app/g2/flash-prompt-protocol.ts", "../app/graphics/surface-compositor.ts", "../app/graphics/image.ts", "../app/graphics/plane.ts", From c8d835176fa92e53ce4fd2a38324d83bbe927e1f Mon Sep 17 00:00:00 2001 From: James Babcock Date: Wed, 23 Sep 2026 01:13:03 -0700 Subject: [PATCH 14/27] Display-list based menu slide animation --- app/g2/firmware-compat.ts | 2 +- app/g2/firmware/cfw-patches.ts | 68 +-- app/graphics/image.ts | 9 +- app/graphics/presentation-wire.ts | 42 +- app/graphics/surface-compositor.ts | 5 +- app/ui/menu-highlight-motion.ts | 34 ++ app/ui/menu.ts | 12 +- .../app/graphics/DrawRedraw.android.kt | 15 + .../faceclaw/app/g2protocol/DrawExpression.kt | 260 ++++++++++ .../faceclaw/app/g2protocol/DrawProtocol.kt | 267 ++++++++-- .../com/faceclaw/app/g2protocol/DrawWire.kt | 68 +++ .../app/graphics/DisplayListPlayer.kt | 42 ++ .../app/graphics/DisplayListRenderer.kt | 461 ++++++++++++------ .../com/faceclaw/app/graphics/DrawRedraw.kt | 7 + .../faceclaw/app/graphics/MenuSelection.kt | 40 +- .../com/faceclaw/app/graphics/ShellScene.kt | 35 +- .../app/graphics/SurfaceCompositor.kt | 31 +- .../com/faceclaw/app/util/ByteReader.kt | 26 +- .../faceclaw/app/graphics/DrawRedraw.ios.kt | 15 + tests/brightness-picker.test.cjs | 1 + .../com/faceclaw/app/DisplayListTest.kt | 2 +- .../com/faceclaw/app/DrawExpressionTest.kt | 140 ++++++ .../kotlin/com/faceclaw/app/DrawWireTest.kt | 128 +++++ .../com/faceclaw/app/IosBleCentralTest.kt | 36 ++ tests/menu-display-list.test.cjs | 17 +- tests/menu-highlight-motion.test.cjs | 44 ++ tests/music-settings.test.cjs | 1 + tests/notification-filter.test.cjs | 1 + 28 files changed, 1546 insertions(+), 263 deletions(-) create mode 100644 app/ui/menu-highlight-motion.ts create mode 100644 native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.android.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawExpression.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawWire.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListPlayer.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.kt create mode 100644 native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.ios.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt create mode 100644 tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosBleCentralTest.kt create mode 100644 tests/menu-highlight-motion.test.cjs diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index e2bfad68..bc7e803e 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -26,7 +26,7 @@ export type FirmwareInfo = { }; /** The Faceclaw firmware revision this build of the app needs. */ -export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 26; +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 27; const FACECLAW_PREFIX = "Faceclaw/"; const LEGACY_PREFIX = "EVENCFW"; diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index fdbd123f..c1205e1d 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,12 +19,12 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "dc9808a442dd475f3cb2c2945a5afa1408458222842cd9fef6288e435920c9b0", + "outputSha256": "2d9f4200b3980156d65732e1d5fe4ba673768baf06683427710ff9a818cfb7ae", "patches": [ { "offset": 1045797, "old": "38b584b0", - "new": "5cf339be", + "new": "5cf31db9", "desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease" }, { @@ -36,49 +36,49 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1437923, "old": "fef788ff", - "new": "fdf248fb", + "new": "fcf22cfe", "desc": "cfw_ancs_event" }, { "offset": 1437951, "old": "fef7e8fb", - "new": "fdf282f8", + "new": "fcf266fb", "desc": "cfw_ancs_open" }, { "offset": 1437969, "old": "fef7e7fb", - "new": "fdf299f8", + "new": "fcf27dfb", "desc": "cfw_ancs_close" }, { "offset": 1388387, "old": "39694d00", - "new": "795e7d00", + "new": "41547d00", "desc": "connection-bound ANCS EUS write callback" }, { "offset": 971497, "old": "fff717f8", - "new": "6ef369ff", + "new": "6ef34dfa", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 971845, "old": "fef769ff", - "new": "6ef3bbfe", + "new": "6ef39ff9", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 979579, "old": "fdf74ef8", - "new": "6cf3a0ff", + "new": "6cf384fa", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 1428895, "old": "f8f76cfd", - "new": "fcf294f8", + "new": "fbf2c4fd", "desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)" }, { @@ -108,145 +108,145 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1248487, "old": "d4f712fb", - "new": "2af3c0f8", + "new": "29f354fc", "desc": "bl settings_send_wrapper (append caps field 100)" }, { "offset": 1246183, "old": "f5f7e2f8", - "new": "2af362fa", + "new": "29f330fe", "desc": "bl settings_decode_wrapper (Faceclaw lease field 101)" }, { "offset": 975219, "old": "02f083fc", - "new": "6cf3c4fa", + "new": "6bf39cfe", "desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)" }, { "offset": 975411, "old": "02f023fc", - "new": "6cf332fb", + "new": "6bf300ff", "desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)" }, { "offset": 975103, "old": "07f085fb", - "new": "6df372ff", + "new": "6df356fa", "desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)" }, { "offset": 830549, "old": "19f03efb", - "new": "91f321f9", + "new": "90f305fc", "desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)" }, { "offset": 830795, "old": "1ff071ff", - "new": "91f3daf8", + "new": "90f3befb", "desc": "bl gesture_press (owned event 9 before stock menu gate)" }, { "offset": 830887, "old": "1ff043ff", - "new": "91f3d4f8", + "new": "90f3b8fb", "desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)" }, { "offset": 831763, "old": "1ff08dfd", - "new": "90f30aff", + "new": "90f3eef9", "desc": "bl gesture_release (owned event 10 before stock menu gate)" }, { "offset": 1570209, "old": "7fb50600", - "new": "dbf251bc", + "new": "daf2e5bf", "desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline" }, { "offset": 1051545, "old": "f6f787f9", - "new": "55f3fdfb", + "new": "54f3cdff", "desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)" }, { "offset": 1051861, "old": "f6f7e9f8", - "new": "55f35ffb", + "new": "54f32fff", "desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)" }, { "offset": 1262237, "old": "d9f7d0fd", - "new": "26f335f9", + "new": "25f365fd", "desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)" }, { "offset": 1262337, "old": "d9f79efd", - "new": "26f303f9", + "new": "25f333fd", "desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)" }, { "offset": 1309405, "old": "67f02dff", - "new": "1af31bfa", + "new": "19f33dfe", "desc": "bl compass_decode_capture (sample-matched GAF diagnostics)" }, { "offset": 1307865, "old": "fff7c9fb", - "new": "1af399fd", + "new": "1af3bbf9", "desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)" }, { "offset": 1300937, "old": "00210170", - "new": "1cf37ffa", + "new": "1bf3a1fe", "desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)" }, { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc7b04ff690454ef66c6b4ff29c591446cff6ff75ccf2ff0bc2f229094ff6ff78002701260f93cde9100106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7007f0b6f8002800f0eb8129464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001f51457ff445afbff35f8f00bf49e8000121b159e8001f5145f8d039e71199012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ac804ff45c7006f0e8ff002800f01d8129464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb9427ff445afbff35f8f00bf49e8000121b159e8001fb942f8d039e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f08f811198002861d010980778a7f1170002285bd811980c2840f07881109e7078b178084300f07281f0780138022800f26d81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f07f83172f40f09583002a40f05481fe2800f0c987812800f0bb87002840f0d08751ea030040f0478101f060b904460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0e78051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0d680824692e74ff0ff3729e147f6df40c0f24f008047002701261397adf8507006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0b3804ff45c7006f09cfe002800f0ab8029464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f00bf49e8000159b159e8001fa142f8d039e706f5a9718847bae601211ee70020109999b1119a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00f9012a804f0e3f94ff0ff3701269df85100002812a818bf4ff0ff3704f001fb054646b99df8500028b94af21f30c0f247004c3080470f98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384647b0bde8f08f0f9012a8264004f0a2f91098007800f07f040f2c2ddd142c40f3a981152c00f01183162c00f01c831d2c40f0da83119801380228c0f04d8510994878897840ea0124b4f5007f00f2448504eb4400032101eb40001199884240f03b8505f031fe002800f036850e9600260127119400f053bd092c00f3d180052c00f00c82072c40f0af83002706e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f083864ff45c7006f035fd002800f07b86294600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed10121c0f800b08172a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff443afbff35f8f49e80001002900f0d98559e8001fa142f6d036e70a2c00f043810b2c40f0de82d9f800500320cff680702840b0f1005fbff35f8f41f0f2822868002758457ff4a3aec5f8687185f8667185f86471d5f86c01c5f8607185f86571c5f86c71c5f80073a5f86c7320b148f2a351c0f245018847d5f87802002818bf09f0c1f80024c5f87842d5f868030e9620b148f2a351c0f245018847c5f86843a5f86c43286c42f68d46c0f24406a5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f41f0ab810168594541f0a78190f8a811002901f09c8106f046ff01f09eb9102c00f07081112c40f0348211994ff0ff37022908bf11287ff402ae1098407800287ff4fdad45f64d50c0f24600804701284ff000077ff4f3ad40f20830c0f210003790ff208df8d80044f25220c0f20100359040f2c960c0f248003446cde93877804798b148f27e30c2f2070000880122c1b264298df8d72008d80721b0f5807f38bf03218df8d7108df8d80040f2d260adf8e000052037ae8df8e200f01d35a90522fff7ccf94ff22507c0f247070120092132460c23b84707462646afe500294ff0ff3708bf002b7ff4d6ad1328bff4d3ad102a4ff0000138bf01211228b2fa82f218bf510901297ff4c6ad00f0ddbd182f4ff0ff3708bf00297ff4bdad002b7ff4baad352800f33083002800f0b585012800f0c185312840f0b385082abff4abad00f0c2bd11980e960228c0f0fe8110984078fbe111980228c0f012830e960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0e6824ff45c7006f01efb002800f0a98729464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f03e8259e8001fa142f6d038e7109811990130013907f059fe07469ce4dde9100106f0dffe074696e4119801380228c0f0348210994ff0ff374878897840ea0120b0f5007f3ff687ac0321119a01eb400191427ff480ac002700288df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813718df814718df815718df816718df817718df818718df819718df81a718df81b713ff4fcab109937aa03314ff0010c4b78012b00f295810f7847ea0323db08d45c07f007070cfa07f7274240f08981d45c013847ea040701f10201d754e7d105f077fa002800f07c810e960027012643e300f07e001a2818bf1c2c40f0718105f067fa002800f06c8101f040f9814608f073fab9f1000f4ff0ff3718bf00283ff4bdab1b2c00f094851a2c40f0bf85804610980025471c11984ff48052b346461e4ff4a0704ff4f071cde9372537aa4ff420740592cde9011048463946324643463d95cde90355009408f0defd002840f0e7854ff48050cde9370537a805900120cde903504ff4a07002904ff4f070019048463946324643464ff420773d95009708f0c2fd074600f0cdbdff20002701260d9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7006f026f9002800f0b58229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e8000121b159e8001fa142f8d03ae790f84410dde90d5661b1016c39b142f68d42c0f244020446084690472046002180f844100121119a032a0ed36db910988078082800f2dd864bf63941c0f25101963188470027fff78aba119a052a39d3012d37d1109a00279078411e06293ff67eaad17803293ff67aaa1279002a3ff476aa4bf63943c0f2510303f59a7398470027fff76cba10990e9e4c78002c00f0eb80022c05d840f082861199062980f0c1844ff0ff37fff75aba362800f09d82462800f09782572840f08382002e7ff47baa92e2022d40f02a814bf63940c0f2510080470027fff742ba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0a1834ff45c7005f0f4ff002800f07f8429464218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800b08772a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f0f98259e8001fa142f6d038e7002780f8437145f64d50c0f24600804701287ff470a943f2a310c0f2560080470746fff768b90c294ff0ff377ff490a9b3f5005fc0f0a581fff78ab9481e1f284ff0ff373ff684a9c1f51630834240f29881fff77db9002b7ff478a9421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f07d81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f070819f284ff0ff377ff452a9042900f06881fff74db9119a072ac0f0b082032d40f0ad82109bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0ca8244ea0521012988bf0e4642f68d41c0f24401a1f140023146bbe200201199022902d31099497800e0ff21002800f0268502294ff0000736d0012930d000297ff4d3a84cf67e21caf2101187760783c9f8041007814760a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8080f83c70fff7a5b801218172fff7a1b88772fff79eb8dde90d5600210020fce548f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0f2824ff45c7005f04bfe002800f0d68229464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08672a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fa1427ff445afbff35f8f49e80001002900f04a8259e8001fa142f6d038e7022abef4fcaf13e0002a7ef4f8afa0f1fd0102290cd397287ef4f1af08e06ff0780002427ef4ebaf02e0402abef4e7af45f64d50c0f24600804710990128c9784ff001004ff0010408bf022008424ff0000708d1fef7d3bf48f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0ab804ff45c7005f058fd00283ef4b0af29464218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b08472a0f81c80a0f81e80a0f82080a0f82280a0f82480a0f82680a0f82880a0f82a80a0f82c80a0f82e80a0f83080a0f83280a0f83480a0f83680a0f83880a0f83a8059e8001fb1427ff445afbff35f8f49e8000121b159e8001fb142f8d03ae74af21f35c0f247050446a84794f86401109a00287ef400af94f80403214600287ef4faae107817281bd0d1f8640342f68d46c0f2440668b947f2c700c0f20000a6f594777844012100220023b847c4f8640340b3a6f140024ff47a719047214608bb01f206300e4610990c22fef7b9fa0f98002186f805030120bff35f8f86f804034ff4f07001904ff4207005f5106600900020002200230027b04700283ef4bdae84f8047305f14c0080474ff0ff37fef7b4bed0f86c110c90002900f01d8100204ff4006205e01b681a44b2f5403f80f0ce808b189f680137f5d05f68033727f0030738441030eee7119a0027032afef467ae2a1fb2fa82f25209b046114000f0f88011994cf6cd420339ccf6cc42a1fb0212109900f146038c780331b4eb920f88bf94082546302c28bf302505eb850206461846fef754fa0027002c86f8445086f8457000f0d580306c344630b9204600f0cefc0028206400f09f8342f68d41c0f24401a1f140020121904700274646fef726be0246119803287ef421ae109934464878897840ea01264ff6ff70864200f063824ff480503790002038903d9037a9cde902004ff4a070049101904ff4f077484631464ff4207300970af01afc002800f04a824ff0ff372646fef7f8bd0546119801287ef4f3adb34607f0e6fd00283fd00646b9f86c03002800f04a834ff48051a0f101084ff4a0703791002437a94ff4f077cde90341cde901044846414632464ff4207338943d9400970af0e9fbf8b9304629464ff41632fef7d8f94ff48050cde9370437a804900120cde902404ff4a07001904846414632464ff420734ff4f0773d9400970af0cbfb002800f016834ff0ff375e46fef7a9bd119a002a46d1b0f53e3f40f2eb810e9e4ff0ff37fef79dbd109fb978fa783b797f7941ea022143ea072232293791389280f0a9813221abe1d0f86c110027002900f0e6824ff400624ff0ff3c0df1dc0e05e02b681a44b2f5403f80f041818d18ac68b7eb542ff4d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e6e74646fef764bd1198002800f0a9810020109a4ff0000b02f1030e16324ff0ff3c1092cdf834e00beb4b020eeb420465784ff0ff37012d00f2a982a678e37856ea032900f0a3822379647953ea042800f09d82b9f5207f00f29982b8f5f07f00f2958209f101035b0803fb08f44ff6fb739c4200f28b821ef81220bbf1000f42ea0527109d62462cd015f8133c15f8126c43ea0623bb423ff478af12b315f80d3c15f80c6c43ea0623bb423ff46eaf012a17d015f8073c15f8066c43ea0623bb423ff463af022a0cd015f8013c2e7843ea0623bb423ff459af043a531c05f11805d2d100293ed0631d4ff4006201eb020edef80850bd423fd0def8006032444ff6ff76c0f20206b2422cd801eb020edef80850bd4230d0def8006032444ff6ff76c0f20206b2421dd801eb020edef80850bd4221d0def8006032444ff6ff76c0f20206b2420ed801eb020edef80850bd4212d0def8006032444ff6ff76c0f20206b242c3d94ff6fc7304f10802c0f201031a401044103020e0def804209a427ff404afdef80c209a427ff4ffae9ef81020042a7ff4faae9ef811209ef8123042ea03224a457ff4f1ae9ef813209ef8143042ea032242457ff4e8ae119a0bf1010bddf834e093450cf1010c7ff42cafb0f53e3f3ff6daae002500201090e3e090f8a911002918bf05f0a6fd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08e804af27366c0f246060021002200230027b0470e9efef739bc4ff0000c4ff400634ff0000ec0f800c30de0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe466ad2cf18ba68ce58013201d07746f3e7f418220c022ae6d80a1995680135e2d115682e443e6012681444220c022adad80a1995680135d6d115682e443e6012681444220c022aced80a1995680135cad115682e443e6012681444220c022ac2d80a1995680135bed115682e443e6012681444b4f5403fcfd3b5e7b1f5fa6f02d94ff4fa6137910121054680f8431145f64d50c0f24600804701281ed143f2a316c0f25606a6f188008047022c074608bf002f01d057b90fe04bf2110237a9c0f24b020220904738b10746b047002085f843010e9efef7b7bb0e9e0027fef7b3bb701ca9f86c0300272646fef7acbb0c99d1f86c114268836890454ff00002c0f80c8008bf00f1100241f82320109a1198013282424ff00007109200f0f38010980d9b00eb400003eb400213f81000937892f801b00a93d37809931379527940ea0b290b930892a1b3bbf1010f31d84ff400628b189f684f45d8d01b681a444ff6ff73c0f202039a4223d88b189f684f45ccd01b681a444ff6ff73c0f202039a4217d88b189f684f45c0d01b681a444ff6ff73c0f202039a420bd88b189f684f45b4d01b681a444ff6ff73c0f202039a42cfd9dde909730b9e43ea0721089c013146ea04224908514301f105088df8de004fea18208df8e1004fea18408df8e2000520079101218df8e60004208df8dc108df8e80037a811218df8dd508df8dfb08df8e0808df8e3508df8e5508df8e4508df8e7508df8e9308df8ea708df8eb608df8ec4006f0c9fc00287ff46aad0c98d0f86c110020a9b3bbf1010f32d84ff40062881883684b452cd0006802444ff6ff70c0f20200824223d8881883684b4520d0006802444ff6ff70c0f20200824217d8881883684b4514d0006802444ff6ff70c0f2020082420bd8881883684b4508d0006802444ff6ff70c0f202008242cfd90020079a002a3ff424af09990a9b0902089a41f0010119440b9b120249081a434a43511e032901d200210ae022f003030021471804318b427d75bd75fd753d76f7d112f003023ff401af00f11503012a5d543ff4fbae1944022a4d7018bf8d70f4e60e9efef79eba304629464ff41632fdf7a8fe13a807f0d3fb0027e6e44bf639400027c0f2510084f8447080474646fef788ba2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09e804ff45c7005f027f8002800f09680414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000129b155e8001fa142f8d04fe7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db03f0b3ff68b940460af033fc48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f098ff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f04982172f40f05482fe2804f22737884600f06d82002840f0788200980af0adfb414602e0022084f8200350460c22fdf7e4fb94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7b4fb47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf783fbb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f80080bff35f8f08ea0700b0f1005f47d1d8f80000b04243d198f8500338b1002088f86401c8f860014db0bde8f08f98f8640118b3d8f8604104b340f6b800c2f20000d0f8009006a802f00df9b9f1000f00f07581484621464ff41632b346ba464ff6ff75cdf81490fdf72dfb4ff29c5600274ff00109c2f2290620e098f8660170b1d8f8680140b147f64c61c2f207010968401a002802f3dc80002088f8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0a01b1f1005f03d10168594500f09f804ff45c7004f0b1fc002802f09c804ff69041cff6ff714218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa1427ff455afbff35f8f46e8000121b156e8001fa142f8d04ae7817a002942f00080027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e0002088f86401c8f8600188f86601012088f8650140f6a120c0f24700804701f074bf40460d460af0d3fad8b102304ff0030008bf022084f820032946bce584f85003d9f800204ef660231a44c4f8602380b140460d460af099fc0af06dfc294630b9a9e50af068fc002829463ff4a4ad03209fe5002084f866019de51868624600eb0620704400eb0b4000eb056138466546fdf779f90fe04eea062141ea0b4141ea05633946624665460af067fa00281cbf032084f8200305f1080084f84f03414679e501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0e48300218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f09a8000218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f346bef15f0f98bf4ff05f0bcbf1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f905eb0e0209f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd009fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0de460ae00ef1010e07e00ef1020e04e00ef1030e00e0de460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000a15f80a10002900f0c78005eb0a035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d00af1200abaf1600f7ff496af4ff0600a5ee00af1010a5be00af1020a58e00af1030a55e00af1040a52e00af1050a4fe00af1060a4ce00af1070a49e00af1080a46e00af1090a43e00af10a0a40e00af10b0a3de00af10c0a3ae00af10d0a37e00af10e0a34e000220a7162e70af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46d646baf15f0f98bf4ff05f0ecef1000942f2107c0aad19eb0a0b51d0b2fbf3f40a2b04f1300105f80a104cf6cd41ccf6cc41a3fb011747d31bf1010140d004fb1326ff08b6fbf7f405eb0a0204f13001517048f21f51c5f2eb11642ba3fb015135d31bf102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31bf1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb11420af1040a63454fea57330aadabd20ce0f2460ae0f24607e00af1010a05e00af1020a01e00af1030a0aad059f002205f80a20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a4609f0bbfcd4f870c272208df8280078208df8290020204ff0000b1ffa8cf28df82a008df82bb015f80b00002800f0c88005eb0b035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00bf1200bbbf1600f7ff496af4ff0600b5fe004460020887078e70bf1010b58e00bf1020b55e00bf1030b52e00bf1040b4fe00bf1050b4ce00bf1060b49e00bf1070b46e00bf1080b43e00bf1090b40e00bf10a0b3de00bf10b0b3ae00bf10c0b37e00bf10d0b34e00bf10e0b31e00bf10f0b2ee00bf1100b2be00bf1110b28e00bf1120b25e00bf1130b22e00bf1140b1fe00bf1150b1ce00bf1160b19e00bf1170b16e00bf1180b13e00bf1190b10e00bf11a0b0de00bf11b0b0ae00bf11c0b07e00bf11d0b04e00bf11e0b01e00bf11f0b01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d946bbf15f0f98bf4ff05f09c9f1000a42f2107e1aeb0b004fd0b2fbf3f50aa905f1300401f80b404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0b0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020bf1040b73454fea5633add209e0cb4607e00bf1010b04e00bf1020b01e00bf1030bddf8149000220aac04f80b20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06e8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df8870042f2941645f29c140aaa48460e21c2f22006c2f2130409f069f94ff6a42040f6b801cff6ff70c2f200010858a04266d14ff6b020cff6ff700858b0f54d2f5ed14ff6b420cff6ff700858a04257d145f610634ff0000ec2f213034cf6394506f1040c00274ff0ff32634548d8186830f003041ad09e4228bf0c2842d3f11a8c424ff0ff313fd8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e2d12ce00021417191e60421b7f5807f1ed300223d46b5f5007f14d3b5f5806f13d3b5f5006f12d30901b2eb153f4fea1515f0d10ce000219171fef765bf00211172fef71bbc490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006806f1080342f6941c9842c2f2270c4cd142f610674ff0000bc2f2200746f6b9700cf1040e00244ff0ff3a4ff0ff3977453bd83e6836f0030515d0bc4528bf0c2e35d3aceb07039d4233d82346a54288bf2b46f6071cbf1c46ab447b19013803f10407e4d121e00420b4f5807f16d300262546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b6eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea000ad94603e04ff0ff3a4ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834264d14ff69423cff6ff73fb58b3f5333f5cd14ff69823cff6ff73fb58834255d14ff29c5043f21063c2f229004ff0000bc2f2270342f6f935a0f1040ca0f1080e0024634542d81e6836f003071ad09e454ff0ff30049028bf0c2e3ad3aeeb030087424ff0ff3034d82046a74288bf3846f6071cbf0446bb44d819013d00f10403dfd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff00634505d17b4204ea03000490584602e04ff0ff300490064666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b7009f061f9059de05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f88000208df8870020464946524609f08cf80020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac049a2046314608f0bfff28461a21224608f03cfe002088f86401c8f8600105984ef217310a904ff416300b900aa8c0f247018847012088f8660106a800f036f9c8f810004db0bde8f08f0020c871d6e70021417207e700bf2de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff6904a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f09c804ff45c7002f0a6fb002800f0d28051464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff45bafbff35f8f00bf47e8000121b157e8001f4945f8d04fe74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c56d1f8009000684ff6904bccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108009007e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168b94200f09c804ff45c7002f08cfa002800f0f08059464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f51457ff457afbff35f8f00bf46e8000121b156e8001f5145f8d04be74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ce047f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422fd041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94217d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a9eb0501b1fbf0f001b0bde8f08f002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204607f01ffd854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f01f81207887f00301084200f01b81012039464246334600f054fa0446002898f8080018bf06240ee14ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f0f1804ef66c6a4ff29c574ff690480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168514500f09d804ff45c7002f0eff8002800f0be80414600bf4218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff455afbff35f8f47e8000121b157e8001f4945f8d04ae705eb450100eb011090f85d1201b300f513760024304629462a460323009407f0c3fc706840b14bf69b71c0f25d018847706804f0a7fc74603068b475002818bf04f0a0fc0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f058f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104607f0b0fb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009507f056fc606840b14bf69b71c0f25d018847606804f03afc65602068a575002818bf04f033fc00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff690498046ccf2ff05c2f229064ff6ff77cff6ff7900244ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09d804ff45c7001f08cff002800f0958049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff457afbff35f8f00bf46e8000129b156e8001f5945f8d04be7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46faf713fda81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450bcde90612cde9080303e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c7001f090fe002800f0398449464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70999089d01eb410100eb011095f9081000f51376b1f1ff3f01f0030409dd374617f8110fd0bb3068002818bf04f04cfa2fe3307cf0b1707ce0b10799099a002730460323009707f051fa706840b14bf69b71c0f25d018847706804f035fa77603068b775002818bf04f02efa00203060b06030823068002818bf04f025fa00204ff480713060b0603182a978b081092006f11107f174b17434757076b07ca978884240f0db82317da14240f0d782069b411ca3f10b00727e02971e2828bf1e209042b17488bf7076981e84b200270a2c4ff00008c0f0e782092241f221090920039419e030684f46002818bf04f0ecf9b089376001303774b760b081002c18bf4ff00608039cd146ddf814a00aeb0b0082b2a24280f0c782317c80b20429824600f28880aa5c00f1010a4b1c0129337405dd022906d0032970d1f28106e021b9727503e0338943ea02223281a24580f0aa8204296ed015f80a204ff0000c831c8f1c0129377406ddff290bd0032967460dd19a4652e000291cbf378947ea0222328100e072756746a34204d38be2f281a34280f08882022936d8ea5c00f1030acb1c0129337407dd022937d0fe2907d17275a2450cd376e231b9338943ea02223281a24504d36ee2f281a24580f06b8202292fd015f80a20031d41f00407fc29377408ddfd2909d0fe291cbf378947ea0222328103e079b9f28100e072756746a34280f0508209b19a4613e0ea5c00f1050a0520307401e09a466746f189308941ea0221f18128b107f086f80028306000f06a8233897089191a1ffa81fb1ffa8af1621a5a45b8bf93465fea0b4208d03268294410441ffa8bf2faf709fb70893389584481b2994270817ff44faf0025cdf81080d6f800808df82b50707db8f1000f06930df12b0108bf88460f2806d8317d00f00302511ab1fa81f14d09000706d4317e707e814238bf30760fe000bf706840b14bf69b71c0f25d018847706804f002f97760707e30760120f082cdf814a09db1707db57d400714d4002d4ff0000400f0898106984ff6ff7381b2002900f00d8101295ed10020d2e0707d400753d4002478e14ff4803007f015f8002d804600f07081b07d002800f06c81b8f1000f00f068817568002d00f0008130890428c0f0608131680a1812f8043c002b40f0598112f8033c002b40f0548112f8023cff2b40f04f8112f8012cff2a40f04a814ff4803429606860c5f80c802c610028019000f067814bf69b70c0f25d0000f58572284600219047002840f033812969002900f02f8168688c420c46e7d1019a0c468242e3d125e14ff4803006f0c3ff044620e1069a4ff6fe701040a44642426ff0010000bf08eb0005ac78ed7883ea04231cb25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead73787ea430383ea05231fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead737023087ea430309ead5371518023587ea430395d1023000276446069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003f0899ab2824270d1099b4046faf77dfa00286ad141f2210a4ff00009012375e0382006f002ff00285ed00546077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f8377047f2ab00c0f200007844286247f2b300c0f20000784468624bf69b70c0f25d0045f6e46200f13c0c28460f21c0f27c023823e04740b3284603f069ff4446706841f2210a40b14bf69b71c0f25d018847706803f05cff77604ff000090323b77506980799099a089dddf8108087b23046009706f05eff002c214604463ff455ad084603f044ff50e5756073e6c4f58030b4f5803f444606902f60ef607ff646aecde70799099a002430460323009406f040ff706840b14bf69b71c0f25d018847706803f024ff74603068b475002818bf03f01dff0020387000203060b06030824ff00a0840460bb0bde8f08f287a4006f8d5307c08b302980078e0b10799099a002430460323009406f013ff706840b14bf69b71c0f25d018847706803f0f7fe74603068b475002818bf03f0f0fe00203060b06030824ff00b083068002818bf03f0e5fe00203060b0603082cae702980078e0b10799099a002430460323009406f0e7fe706840b14bf69b71c0f25d018847706803f0cbfe74603068b475002818bf03f0c4fe00203060b06030824ff00608a7e700bf2de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7f3f9002869d006462846fff749fa21462a46fff71dfa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff7d0ba0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22f9f73ffe04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522f9f7fbfd0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522f9f7a5fd4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff764ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff690480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f09c804ff45c7000f03efe002800f0c18041464218373182f8705382f8715382f8725382f8735382f8745382f8755382f8765382f8775382f8785382f8795382f87a5382f87b5382f87c5382f87d5382f87e5382f87f5382f8805382f8815382f8825382f8835382f8845382f8855382f8865382f8875382f8885382f8895382f88a5382f88b5382f88c5382f88d5382f88e5382f88f5382f8905382f8915382f8925382f8935382f8945382f8955382f8965382f8975382f8985382f8995382f89a5382f89b5382f89c5382f89d5382f89e5382f89f5382f8a05382f8a15382f8a25382f8a35382f8a45382f8a55382f8a6538ed1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff456afbff35f8f46e8000121b156e8001f5945f8d04be7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff7f0fd2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420188b1b8f1010f40f08580d9f83c01002189f84211a9f84011e0b342f68d41c0f24401884736e0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421168b94ff61d40cff6ff70a4f59477784400214a460023b847c9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023a6e745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f850716fe701b0bde8f08300bf80b582b04ff0050ccdf800c0fff734ff02b080bd2de9f04f83b04468002c00f0bd828368002b00f0b98204eb030b4ff000090027002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310ceb0a0300275b451c464ff0000680f09d82a04618f9013b03f07f05bd40002b46ea050610d406f00703012b16dc0bb3012b40f08b82abeb0803082bc0f0868204f10903dee700bfd84580f07f82182f07f107074446dcd978e200bf022b3ad0052b40f07382abeb0803042bc0f06e82631dc7e7d84580f0698294f90130002b04f10203bed55b4580f0608294f90230b3f1ff3f04f10303b4dc5b4580f0568294f90330b3f1ff3f04f10403aadc5b4580f04c8294f90430b3f1ff3f04f10503a0dc5b4580f0428294f90530002b00f13d82a31d96e7d84580f0388294f9013004f1020c002b03f07f0a1ed5dc4580f02d8294f90270e31c07f07f05b7f1ff3f4aeac51a02dde0469c460ee05b4580f01d8294f9037004f1040c07f07f05b7f1ff3f4aea853a33dd9846abeb0c039a4500f20c82f308672b1dd0652b7ff460afbaf1060ffff45caf9cf80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf4ff29c54c2f229040290cde9002132e0044660460e4651461746654600f017fcac4631463a46204637e7dc4580f0db8194f90470631d07f07f05b7f1ff3f4aea455aaddc5b4580f0ce8194f90570002f00f1c98104f1060c4aea077ab1e748f2a3513046c0f24501bff32f8f8847dde900210298ac462768bff35f8f2668bff35f8f33466ff39603b3f1005f07d133684ef66c65ccf2ff05ab4200f0b0804ff45c70654600f079fbdde9002106460298ac46002e3ff4f1ae4ff69043cff6ff7300bff418373384f8709384f8719384f8729384f8739384f8749384f8759384f8769384f8779384f8789384f8799384f87a9384f87b9384f87c9384f87d9384f87e9384f87f9384f8809384f8819384f8829384f8839384f8849384f8859384f8869384f8879384f8889384f8899384f88a9384f88b9384f88c9384f88d9384f88e9384f88f9384f8909384f8919384f8929384f8939384f8949384f8959384f8969384f8979384f8989384f8999384f89a9384f89b9384f89c9384f89d9384f89e9384f89f9384f8a09384f8a19384f8a29384f8a39384f8a49384f8a59384f8a6938ed14ef66c63ccf2ff0333600123b3724ff6ff734ff29c54b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290454e8003fbb427ff43bafbff35f8f00bf44e8006323b154e8003fbb42f8d02fe798f8043098f8057098f80650032b47ea052437dd052b58dc042b78d0052b7ff43daed6f868313bb147f64c67c2f207073f68db1b002b18dcd6f86c3186f86691c6f86c91c6f80093a6f86c936bb10c4648f2a35180461846c0f24501174665468847ac4621463a46404647f64c63c2f207031b6845f69077c0f201073b44c6f868310be6012b3ff4fdad022b00f08780032b7ff403ae174688466546fff724fb03460298ac4641463a46002b3ff4f6ad96f84231002b3ff4f1ad304641f28831a6f8404106f070fc47e0062b4ad0072b7ff4e4ad80464df6db50c0f24a0016460f466446804703465d1ea446394632464046012d3ff6d2ad981eb0fa80f04009fff7dcfba446394632464046c6e5174688466546fff7e8fa03460298ac4641463a46002b3ff4baad96f84231002b3ff4b5adb6f84031a3427ff4b0add6f83c3186f84291002ba6f840913ff4a7ad42f68d411846c0f2440188470298ac4641463a469be5d6f86c31c6f86891002b86f86691c6f86c91c6f80093a6f86c933ff48dad0f4648f2a35104461846c0f24501164665468847ac463946324644e696f84231c6f83891002b3ff478ad0446d6f83c0165468846174686f84291a6f8409120b142f68d41c0f2440188474af273660120002100220023c0f24606b04720463a464146ac4659e54ff2a513c0f2490303b0bde8f04f18477fb50646002806d1fff772fa002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817047f28851c0f20001033079440b22f8f7e6ff0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f8f7aeff0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f8f7fffe1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f8f755fe4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f0eb800c46014600784d2840f0e5804878432840f0e1808878012840f0dd804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f03d10268424500f0a0804ff45c70fff766ff002800f0ae804ff690425146cff6ff728318373283f8705383f8715383f8725383f8735383f8745383f8755383f8765383f8775383f8785383f8795383f87a5383f87b5383f87c5383f87d5383f87e5383f87f5383f8805383f8815383f8825383f8835383f8845383f8855383f8865383f8875383f8885383f8895383f88a5383f88b5383f88c5383f88d5383f88e5383f88f5383f8905383f8915383f8925383f8935383f8945383f8955383f8965383f8975383f8985383f8995383f89a5383f89b5383f89c5383f89d5383f89e5383f89f5383f8a05383f8a15383f8a25383f8a35383f8a45383f8a55383f8a6538ed1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a457ff451afbff35f8f47e8000222b157e8002f4a45f8d046e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff6b922cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff61140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff35f2e0cde901100120cff680704ef66c644ff29c564ff6904bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f03d10168a14200f09b804ff45c70fff74dfb0028c5d059464218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff459afbff35f8f00bf46e8000121b156e8001f5145f8d04de7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff41faf00210025fff778fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff7f4fd0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff72afe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff6bd12cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff750fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef788fa014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef768fa0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef757fa204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd46f25240c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7a5f90028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f7f703ff4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7a3bd00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1f9f7cdfec8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f9bb00278437842ea0325b5f5007f04d94ff0ff301bb0bde8f08f4ef66c6a4ff29c56ccf2ff0ac2f229064ff6ff774ff000084ff0010b0791099008e000bf48f2a3512046c0f24501bff32f8f8847d6f80090bff35f8f3468bff35f8f20466ff39600b0f1005f03d12068504500f0a2804ff45c70fef7d3fb002800f09a8004464ff69040cff6ff7000bf2118373081f8708381f8718381f8728381f8738381f8748381f8758381f8768381f8778381f8788381f8798381f87a8381f87b8381f87c8381f87d8381f87e8381f87f8381f8808381f8818381f8828381f8838381f8848381f8858381f8868381f8878381f8888381f8898381f88a8381f88b8381f88c8381f88d8381f88e8381f88f8381f8908381f8918381f8928381f8938381f8948381f8958381f8968381f8978381f8988381f8998381f89a8381f89b8381f89c8381f89d8381f89e8381f89f8381f8a08381f8a18381f8a28381f8a38381f8a48381f8a58381f8a6838ed1c4f800a084f80ab0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f48457ff450afbff35f8f46e8004028b156e8000f4845f8d045e70024ddf824805db1fdf7fafb0146002c4ff0ff3018bf002902d11bb0bde8f08fb5fa85f040094ff000098df82c908df82d908df82e908df82f908df830908df831908df832908df833908df834908df835908df836908df837908df838908df839908df83a908df83b908df83c908df83d908df83e908df83f908df840908df841908df842908df843908df844908df845908df846908df847908df848908df849908df84a908df84b908df84c908df84d908df84e908df84f908df850908df851908df852908df853908df854908df855908df856908df857908df858908df859908df85a908df85b908df85c908df85d908df85e908df85f908df860908df861908df862908df863908df864908df865908df866908df867908df868908df869908df86a908df86b90bcb1d4f86c21a2b14ff4006304e03f683b44b3f5403f0cd2d718be680136f6d07e68033626f0030609eb060101f11009ede7002d4ff0020a039500f00581ddf81cc0acf102020a2ac0f00081002608eb0a0b9bf801504ff0ff30012d3ff648af9bf802209bf803309bf8047042ea03229bf8053042ea074747ea0361a1f1011212f5803f0a91fff433af9bf808109bf809e0029141ea0e210af10a020497aceb02034f1e9f42bff423afcde905269bf806209bf807300a9e42ea032cb6eb0c07fff416afb9423ff613af18f80a70089147ea052a4feada000ba90e5c07f00705012707fa05f5354240f003830e5c45ea06050d5407994ff6ff75c0f20205b4b3d4f86c0198b317461a0201924fea0e264ff4006200eb0208d8f8083053454bd0d8f800301a44aa4221d800eb0208d8f80830534540d0d8f800301a44aa4216d800eb0208d8f80830534535d0d8f800301a44aa420bd800eb0208d8f8083053452ad0d8f800301a44aa42d3d900bfbcf1000f40f0be8204980a464ff6fc710330c0f2030108404844944600f1100908980599069e00eb010a0398013686424ff0000028bf0120ddf824804fd2aceb0a02092a3ff64caf49e0d8f804000a9a904240f09782d8f80c006045c0f0928236d9089aa0eb0c00824200f28b827ab3029831180198c1f1000cc2199044a1f1010e002208eb02050beb0203287c9e7ab04240f0778296451cd06e7cdf7abe4240f070820ceb0207be1c13d0ae7c187b864240f06782079ef81c07d0e87c5b7b984240f05f8204329142dbd1b446a7e78c46a5e7ddf81cc0a2e7ddf81cc0002800f05082baeb0c004ff0000118bf0120b9f53e3f88bf0121014303980028c1f100003ff43eae00297ff43baed4f86cb1bbf1000f40f08b804ff44030fef75af9002800f02f82834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760222c0f2020600210ae00aeb080209f10101ddf8248071454ff000003ff498ad08eb02050a9218f80200aa786f7805922a7a95f803e095f8049095f805c095f806a0eb7908926a7a40ea0728cde906215cb3012f29d84ff400670beb0705a868404500f0a28028680744b7421dd80beb0705a868404500f0988028680744b74213d80beb0705a868404500f08e8028680744b74209d80beb0705a868404500f0848028680744b742d7d90598cdf810a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a002002930597b9f1000f26d00beb09035bf809105a68514580f09c80eab10beb02005bf80210d0f80490514580f08d80b9f1000f11d00beb09035bf809105a68514580f0878042b10beb02005bf80210d0f804905145d6d377e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f6f7adfe4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f8002311d90beb09004bf809104ff0ff3142608160c260c4f800930be0e868ddf80ce00a9a089f60e010b10268114401604ff000090020b9f1000f7bd00beb09035bf809105a68514522d2002a72d00beb02005bf80210d0f80490514513d2b9f1000f67d00beb09035bf809105a6851450ed2002a5ed00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf80ce00a9addf810a0029b089f00280cbfc4f800c3c0f804c005984ff6ff7668600020c0f20206c5f80880e8604aea0321069bddf81c9047ea032a814202f10a087ff4bdae05f110077818099952464144f346f6f7c0fde968de466868aa68d4f86cb15144e96081424ff0000018bf07464bf82270a3e600204ff400684ff4006703e02f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f6f7dffd4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f800831bb0bde8f08f00281ebf0168114401604ff0ff301bb0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7f1fe002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f86813002974d104464ff41630fdf74ffe014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8681300e00021084601b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff6904848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f09d804ff45c70fdf7a9fd002800f00e81414600bf4218373182f8707382f8717382f8727382f8737382f8747382f8757382f8767382f8777382f8787382f8797382f87a7382f87b7382f87c7382f87d7382f87e7382f87f7382f8807382f8817382f8827382f8837382f8847382f8857382f8867382f8877382f8887382f8897382f88a7382f88b7382f88c7382f88d7382f88e7382f88f7382f8907382f8917382f8927382f8937382f8947382f8957382f8967382f8977382f8987382f8997382f89a7382f89b7382f89c7382f89d7382f89e7382f89f7382f8a07382f8a17382f8a27382f8a37382f8a47382f8a57382f8a6738ed1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff45aafbff35f8f45e8000121b155e8001fa142f8d04fe7d0f87812002974d104464ff4163003f0abf8014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8781200e00021084601b0bde8f08f00bf2de9f04f83b04ef66c654ff29c564ff6904948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b029002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f09c804ff45c70fdf760fc002800f0c68049464218373182f8704382f8714382f8724382f8734382f8744382f8754382f8764382f8774382f8784382f8794382f87a4382f87b4382f87c4382f87d4382f87e4382f87f4382f8804382f8814382f8824382f8834382f8844382f8854382f8864382f8874382f8884382f8894382f88a4382f88b4382f88c4382f88d4382f88e4382f88f4382f8904382f8914382f8924382f8934382f8944382f8954382f8964382f8974382f8984382f8994382f89a4382f89b4382f89c4382f89d4382f89e4382f89f4382f8a04382f8a14382f8a24382f8a34382f8a44382f8a54382f8a6438ed1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff45bafbff35f8f00bf46e8000121b156e8001f4145f8d04fe70446fff7ebfd002c18bf002805d102990120487103b0bde8f08fc4f8600101254ff4f07084f8645101904ff420704af61f470090c0f2470700200021002200230026b84740b184f864610298c4f86061457103b0bde8f08f0298057103b0bde8f08f0024cde700bf014640f258304df69f22c2f20000c0f248021047022a3cbf4ff0ff3070472de9f04fadf2dc4d0f460e7849781b9246ea0126b6fa86f14c0922f0010102294ff00201209101f0c385002e0e901097cde90c3601f0bc850220209000200f90209a109b9818995c4078023241ea00251b982092801a854201f2a985022dc1f0a685ddf814753868411e0028396001f09e859e187778032f01f2998596f80080f807a5f1020c119511d1b01c2390ddf80805ddf804b528900c98ddf8009524900df1e00a022f6fd2ddf80c258ee0bcf1020f0df1e00ac1f07a850e98d0f86c01002801f07485f178012901f2708596f8029049ea012450f82410002901f067850a1a910741f063856ff4403140f60f031144cff6fd739942c1f05985104450f8081ca14241f0538550f80c1c0025a1f10113cff6ff75ab42c1f0498550f8043c8b4241f04485c2f54032914201f23f85002801f03c85027812f00b0f41f037850022534601f0cffd002801f03085301d23901198dde93a1ba0f1040c38980d462490ddf81405013180694908289140b1e20809f00701835c012606fa01f119438154a946022f8fd3bcf1000f01f00f85239845f64d5610f9014bc0f246062390acf10107b047012808bf0134601e81b2650800ebd130002c48bf4510b0470128ddf80c05bc4608bf6d422a18b8f1030fcde929b9cde925c25ad0b8f1020f32d0b8f1010f40f0f180bcf1000f01f0df84ddf88c8098f80010012901f2d88400294ff0090508bf0525ac45c1f0d08498f8012098f80300002900f0e18198f8023098f8047098f8056098f8064042ea032e40ea072398f8070098f8082046ea042740ea0226d4e1bcf10e0f41f0b08423984ff6fe71047840784e4644ea00258d422899ddf8909027910e994ff0010800f033824ff6ff72954240f0d681d1f868934ff4a0704ff420764ff4f07b279023e2bcf1060fc1f08b84239e70790630844541f08584bcf1060f30ad19d0062403e000bf0134644513d2305d01381e28f8d93019aceb040152462b4601f080fc002801f06d843898ddf894c004446445ebd3ddf81005002801f03e842498002801f05e84fcf7d4fa002801f0598475792599a81d814241f0538447f65420c2f20700d0f800a0baf1000f01f049849af80c009af80d109af80e209af80f3040ea012040ea024040ea036eaef1810010f1800f4ff00004c1f034849af810109af811209af8133041ea02219af8122041ea024141ea0360a0f1810111f5817f099041f21f84002d00f06b8606364ff0000b00270df1e0090df1c008cdf89ce009e000f1004049f824000137af4204f1010b80f02382f05d5c46411e1e29f0d9f019e91b42462cab01f00bfc002800f0118230992c980f4449f82400e6e708f0fe00042840f08780b8f1040f03d1bcf1070f41f0e683b8f1050f09d1bcf1080fc1f0df832398c0790830844541f0d9830e980024d0f86c71002f01f0d38323984178012901f2ce8390f800e04eea012257f82200002801f0c583c31b980741f0c1836ff440301e1840f60f00cff6fd708642c1f0b783fd1855f8080c904241f0b18355f80c1c0027a1f10110cff6ff77b842c1f0a783002d01f0a48355f8047c8f4241f09f83c3f54033994201f29a83ddf81405806940b1d4080ef00706035d012707fa06f21a430255b8f1040f40f06d812846002230ab01f01ffc0024ddf81015002808bf4ff0ff34239f002918bf002801f051830020389026982899cde902a025984a46019024985b46009701f078fc01f03ebbb8f1080f00f0cc81b8f1060f40f0fb83bcf1100f41f05a83239b00241879597950ea012c1ebf9979da7951ea022101f04e831e785f7846ea0725a945c1f04783a9eb0502944501f242839878da7840ea0229cb45c1f03b832795abeb0905279aa94201f23483ddf81005002801f00a834944299126993802084430440ceb020b03f1080a4fea800807e000bf299809f10109279a814581f0f58228982499269d09fb001e4646114605e000bf0131594506f10406ead26818f8d42a9a9042f5da44081ef80420042525ea060722fa07f7c7f342031af8033025ea8707fb4003f00f0702f00f0c02f0f002269d3a44c00708bf4cea03120ef80420d7e74fea820e98f8022098f80460530087007600002f4ff0000418bf002e01f0d982f145c1f0d682a9eb0e02974201f2d1829b45c1f0ce82abeb0302964201f2c982002900f0828300228ae3012801f2c082d1f86c01002801f0bb8250f82510002901f0b6820a1a910741f0b2826ff4403140f60f031144cff6fd739942c1f0a882104450f8081ca94241f0a28250f80c1c0027a1f10113cff6ff77bb42c1f0988250f8043c8b4241f09382c2f54032914201f28e82002801f08b82027812f00b0f41f086820022534601f01efb002801f07f82ddf81405dde93a6b8069ddf8e090711c4fea5101279138b1ea0804f00701835c08fa01f119438154b9f1000f4ff0000401f06682239991f806c0cb795cea03281ebf91f808a04f7a5aea072501f058828878c97840ea01229642c1f05182b11a884501f24d8223990879497940ea012100208b4538bf01202591abeb01018d424ff0000188bf01210843ddf810154442002901f00f82002841f00c82239e2292f07ab17a000640ea0140717b367b090641ea0641249e0014b1454fea214e00f07484002400f060bf239fc12930ac2fd3287801282cd1bcf1090f2397c1f0d681a5f13f002a902398acf1080600f1080802e0013e01f0ca8118f8010b421e1f2af7d342b2202a13db2a9b03eb400213f81000527840ea0222c12a09d3284623460f4601f088faddf894c039460028e0d14ff0ff3401f0beb9bbf1000f00f03d84abf101054ff000084f4609e000bf454508f10108a4f1010407f1040700f02b8459f828100029f2d40020434684421dd007eb80067268b2f1ff3f18dc5a1c954214d0b268b2f1ff3f11dc9a1c95420dd0f268b2f1ff3f0adcda1c954206d032690433002a00f10400e0d400e00022504630ab2cae009602f03ef80028b8d02c980028c4d04af20d3130a8c0f24e018847bde7bcf10c0f41f09281239e00243279717952ea012025901ebfb379f77953ea072701f085812598b0f5207f01f28081b7f5f07f01f27c81b07a0f281f9001f27781f37a102b229301f27281ddf81005002801f0488173783078f5781b06b47843ea00404fea204c280640ea044000140a90307a737a259d40ea03231846b3eb550f28bf6808b0eb570f28bf78084fea400e4043013b4fea80062698a5f102054ff0000938bf4b46bc1eb3eb550f1d9528bf6b08b3eb540f1a9428bf63085c005b439b001693229b0902102b4ff00003199438bf012323934b1e0ceb00080993a0eb0c0302f0010011440890081a1c90d8075242159004204c460792ca1e20ea880100eb88000692139105900b971e96cdf8508024e0269a4fea550c12f80c30042020ea850723fa07f71f9807f00f07874298bf0746002903f00f0103f0f003229818bf07463b43ed0708bf41ea071302f80c3000bf0b9f0134bc4201f0c380e14339448c42b8bf21460a986fea4102ceeb41017244c94323181a9821eae27101fb01f9621e011b8a421292b8bf114619986fea4102c0eb41010244c94321eae27101fb01f0189028982499ddf870c003fb0010079926900998002288426ff0010a4546279352d10898a8460028c2d02598d14301448a42b8bf11466fea4103ceeb41017344c94321eae37101fb0191b142b0d818eb0205add427980028aad42a988542a7da27985845a4da1a982399a042fff680af1d9823999042fff67baf1298531e53ea000123993ff574af2298c1b210294ff0000138bf01211d98821a9342b8bf1a4619986fea4203c0eb42020344d243189822eae37202fb0202169882424ff0000288bf0122114053e71a980021a042a8bf01212346002c18bf01231940dde9058781f00100179021942ce000bf269e4808315c042424ea080421fa04f4ddf87cb004f00f045c4598bf5c46002b229b18bf1c4601f00f03159d43ea041301f0f001002d08bf44ea01033354ddf8a4b0149d1e9e219c023208f108089445a7f102073ff46fafb91c8a42b8bf11466fea4103ceeb41017344c94321eae37101fb0191b1425dd8a9185bd42798002858d42a98814255da2798584552da1a98239bac46a04229db1d98239b824225dc1298a2f1010b5bea0003239b1ed42298c3b2102b4ff0000307f1010038bf01238345b8bf5846199d6fea4004c5eb40002c44c04320eae470189c00fb0040169ca0424ff0000088bf01200340269e4808315c139d6ff0010a21fa05f41f9d04f00f04ac4298bf2c46002b229b18bf1c4601f00f0301f0f00121435feacc7508bf43ea041131546546ddf8a4b0ddf870c0219c1e9e259b82ea0a01501c19448842b8bf01466fea4100ceeb41017044c94321eae07000fb0090b0423ff675afa818411c3ff571af279800283ff56daf2a988142bff669af27985845bff665af1d9882424ff00000a8bf0120179b1843239b7ff436af22983b46c0b210284ff0000038bf0120ba42b8bf1346199d6fea4304c5eb43032c44db4323eae473189cddf870c003fb0343169ca3424ff0000388bf0123034014e7b8f1070f4ff0000408bfbcf1020f40f05b8723994b4608784978cdf800b040ea0121ddf814050490ddf81005cde902202898249a01900e9801f03dfd00f01bbf26990022c80706d11eeb010003d438444845d8bf0122ac451c9607fb06f6cde917e5199240f25f81ddf810052699b0fa80f0400910438e440022c007cde91d6000bf18f805a05fea1a1101d0012418e0aceb0501012900f0168708eb050999f8010010b1022401460be00429c0f00b8799f8021099f8030051ea002100f003870424b01a814200f2fe861e98cde92145002840f08280481e0af00f0c03284fea0a1a1f9180f0878000251f99ddf8a890ddf88c8011f003046fd01544b5fbf7f01a9200fb175118440eeb010650ea060116d44e4514d2584512d22899249a00fb01207108425cf60702f00f0802f0f002624408bf48ea0a02ddf88c8042541a9a1f99012c49d0681cb0fbf7f101fb1702c8180eeb020650ea060115d44e4513d2584511d22899249a00fb01207108425cf60702f00f0802f0f002624408bf48ea0a02ddf88c8042541a9a1f99022c24d0a81cb0fbf7f101fb1702c8180eeb020450ea04011a9a1f9917d44c4515d2584513d22899249ae60700fb01204fea5401425c02f00f0502f0f002624408bf45ea0a0242541f991a9a00bfdde92105ddf894c0054465450a4480f08f841d9eb242fff447af98e021f003000025279006e000bf27980435a8424a463ff46eaf02eb0508b8fbf7f0914600fb178400eb030b74445bea040015d42a98844212d2299883450fd22898249962080bfb0010e407865c06f00f0106f0f006664408bf41ea0a06865408f10100b0fbf7f1ddf8a4b001fb1702c8180eeb020450ea040114d42a998c4211d258450fd22899249a00fb01206108425ce40702f00f0602f0f002624408bf46ea0a02425408f10200b0fbf7f101fb1702c8180eeb020450ea040114d42a998c4211d258450fd22899249a00fb01206108425ce40702f00f0602f0f002624408bf46ea0a02425408f10300b0fbf7f101fb1702c8180eeb020450ea04013ff586af2a998c42bff482af5845bff47faf2899249a00fb01206108425ce40702f00f0602f0f002624408bf46ea0a0242546de7002265454ff0000408bfb24240f0c985ddf81005002818bf012019990840012840f09a851899ddf870e027f001008c450efb00f240f0d9830120012100f0a7bd01204ff0000b0df1e0090de025998e4540f3e3820124e8e2002002e04ff0000b0120239eddf89ce031790f248f0601f00f0504eae7776f4389246743ff0a96f800c08df8b0700e277278b378f678279111f0200f08bf012705fb07f704fb07f74fead7278df8b1704ff00d0708bf022705fb07f704fb07f74fead7278df8b2704ff00c0708bf032705fb07f704fb07f74fead7278df8b3704ff00b0708bf042705fb07f704fb07f74fead7278df8b4704ff00a0708bf052705fb07f704fb07f74fead7278df8b5704ff0090708bf062705fb07f704fb07f74fead7278df8b6704ff0080708bf072705fb07f704fb07f74fead7278df8b7704ff0070708bf082705fb07f704fb07f74fead7278df8b8704ff0060708bf092705fb07f704fb07f74fead7278df8b9704ff0050708bf0a2705fb07f704fb07f74fead7278df8ba704ff0040708bf0b2705fb07f704fb07f74fead7278df8bb704ff0030708bf0c2705fb07f704fb07f74fead7278df8bc704ff0020708bf0d2705fb07f704fb07f74fead7278df8bd704ff0010708bf0e2705fb07f704fb07f74fead7278df8be704ff0000708bf0f276f436743ff0a00284ff000048df8bf7040f0ad841206300642ea0c41269a40ea034002eb2144abf101070eeb204000234ff001080890cde90aba139707e001f01f000b3801335b45044400f08f8459f82310b1f1ff3ff2dd16939f421bd009eb83004268b2f1ff3f16dc0133bb4212d08268b2f1ff3f0fdc0133bb420bd0c268b2f1ff3f08dc0133bb4204d002690133002ae2d400e00022504630ab2baf009701f026fb00283ff4a0aa2b990029189100f0b6819df8c8009df8c910ddf8a89050ea01272caa159400f098811d979df8cc709df8cd603f0447ea0667099e1d9c9df8c7009df8c61026444fea002c41ea00259df8ca0006eb2747089e9df8cb300004f41b159e40ea0360031406eb204e08eb550017900ceb0100471e1c9525461997f71801f00304f11a0ef1010314930ef102031293189b1a950133219308eb5003001b2590c8072690f8071d9fcde91e430023239008e0229b21981f990133bb420844219000f0498158192293f3d429998842f0d21c990029edd02899249b4ff0000b00fb013c1998032880f094801e981d9f1a9d0028ded0dde91710229b5feacb7403fb010327984fea5b01595c00f0100088ea101ac8b201f00f0108bf01090846002918bf012040ea0a00012815d11beb0e0012d4484510d245081cf80560515c06f00f0706f0f0060e43c00708bf47ea01161d9f0cf805601a9d1e980128a9d00bf101004008185c002cc1b24fea111108bf00f00f01c8b2002818bf012040ea0a00012816d1149810eb0b0012d4484510d245081cf80560515c06f00f0706f0f0060e43c00708bf47ea01161d9f0cf805601a9d1e9802283ff47caf0bf102004008185c002c00f00f01c3b208bf19090846002918bf012040ea0a0001287ff469af129810eb0b003ff564af4845bff461af43081cf80340515c04f00f0504f0f0040c43c00708bf45ea01141a9d0cf803404fe7219907e025980bf1040b584501f102013ff462af279811f8013c00f0100088ea101ad8b200230f2888bf012343ea0a03012b0eeb0b031ad1002b18d44b4516d25f0800091cf80760105cc1465feace7806f00f0506f0f006c846ddf8a89046ea00062caa08bf45ea00160cf8076011f8010c10f00f00054618bf012545ea0a05012d1bd15f1c19d44f4517d27d081cf80560105c6446f446c646ddf8988006f00f0747ea0017b8f1000ff046e646a44606f0f00608bf46ea0007675508780025c0b20f2888bf012545ea0a05012d16d19f1c14d44f4512d27d0800091cf80560105c1446239a06f00f0706f0f0060643002a224608bf47ea00160cf80560087810f00f00054618bf012545ea0a05012d7ff478af03333ff575af4b45bff472af5b081cf80350105c05f00f06269f46ea001605f0f005002f08bf45ea00060cf803605fe74af20d3130a8c0f24e0188479df8c4009df8c510dde90aba159c40ea01200df1e00905e09df8c4009df8c51040ea0120139f169b08e67ff4a3a82699002401449142c8bf012419023b0205fb08f2239243ea0a0241ea0c0102fb01f326995a1e00eb010a00f08d80cdf8989023f0010000214feac4791e9321901f9406e000bf2198611c8142a2f1020273d08b46b9f1000f18bf1146b1fbf8f505fb181605eb0e010aeb060451ea040025d42a98844222d2299881421fd22598dde92637284400fb0730229b249f1e440423750823ea8606289b405d01fb0371f04066088d5d00f00f0705f00f0c05f0f0053d44e40708bf4cea00158d550bf101046ff00100214680ea0b00b9f1000f239b18bf1918b1fbf8f505fb181605eb0e0c0aeb06015cea0100acd42a988142a9d229988445a6d225982844dde9263500fb0530229bf5186e08805d042323ea8505e840289b249d4e080cfb035700f00f03bd5dc90705f00f0c05f0f0052b4408bf4cea0013bb5585e7ddf89890dde91e340bf1020000e00020299ed90700f0f481e2076fea0001239a18bf5018b0fbf8f303fb180203eb0e010aeb020051ea000700f1e2812a9fb84280f0de81b14280f0db81259f3b44279f03fb0793229f3a445708db5d042727ea820223fa02f2289b249f02f00f0601fb03714308cf5cc00707f00f0507f0f007374408bf45ea0217cf54b9e11d9efff70cbc08eb01002590aceb0100239028982499229203fb00102699179a7c08114400eb510a00224ff0010b4ff0000c002700200026002124902990cde926a407e0012600272a9923980131814200f0a581002e40f0a1812598022f455c2a9100f0ed80012f76d0002f40f0ec802e0905f00f00299000f05f812298b042e0d3801b2290299800eb00150001219015e01af80200299900f0f00008440af802000132013e4ff0010ba24224bf00220cf1010cddf898a0002e00f03881f445c0d22898bbf1000f0cfb00aae1d0a01ab0eb560f88bf700850b383080aeb020819d0002708f10101a7eb83036ff0030e01eb0e040ef1040e03eb0e0919f10407e57025716571a571f2d10ef10401ddf870e0279c00e0002110f0030308d0012b08f8015004d04144022b4d7018bf8d70a6eb400602446eb1a242b6d21af80200219900f00f000843013e4ff0000b0af80200afe70026a8e7002d00f0eb802298a842fff46faf401b2290299800eb00160001219011e0b85c299900f0f0000843b8540132013d4ff0010ba24224bf00220cf1010c002d00f0ca80f445bff452af2898bbf1000f0cfb00a7e4d0a4eb020ebeeb550f88bf4fea550ebef1000f25d05fea9e0107eb020912d0002009f10104a0eb81086ff003016318043108eb01000430de701e715e719e71f5d1043100e000211ef0030309d0012b09f8016005d009eb0100022b467018bf8670a5eb4e05724485b1279cddf870e0a242b5d2b85c219900f00f000843013d4ff0000bb854002db2d17be0ddf870e0279c0025a4e7002603272495ffe6249f57ea052777d022982497b842fff4f5aec01b2290299800eb00150001219012e019f80200299900f0f000084309f802000132013f4ff0010ba24224bf00220cf1010c002f4ed0f445bff4d7ae2898bbf1000f0cfb00a9e3d0a01ab0eb570f88bf780848b3830809eb020818d0002608f10101a6eb83036ff0030e01eb0e040ef1040e03eb0e060436e57025716571a571f3d10ef10401ddf870e0279c00e0002110f0030308d0012b08f8015004d04144022b4d7018bf8d70a7eb400702447fb1a242b9d219f80200219900f00f000843013f4ff0000b09f80200002fb3d101e00027a9e70027002689e60026022786e60026012783e600200126002724907ee6ddf8100578b1002038902698289903902498239f4a465b46cde901ca009700f070fb044600e000241cbb209a11980f9902440d98013181424ff0000428bf0124209217d20f911b99891a01293ef65aaa10e00126b7fa87f0229a86f00101400900284ff0000418bf002903d0002adcd000e000241b99209a511a18bf012161ea040000f0010040420df2dc4dbde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe791429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f93b0054600284ff0ff3000f02c821d9f072f40f02882cde90651cde90823faf755fd002800f004814ef66c674ff29c594ff6904a48f2a355ccf2ff07c2f229094ff6ff7bcff6ff7a4ff000080124c0f2450502e0bff32f8fa847d9f80060bff35f8fd9f80000bff35f8f01466ff39601b1f1005f03d10168b94200f0ab804ff45c70fbf759fc002800f0d280514600bf4218373182f8708382f8718382f8728382f8738382f8748382f8758382f8768382f8778382f8788382f8798382f87a8382f87b8382f87c8382f87d8382f87e8382f87f8382f8808382f8818382f8828382f8838382f8848382f8858382f8868382f8878382f8888382f8898382f88a8382f88b8382f88c8382f88d8382f88e8382f88f8382f8908382f8918382f8928382f8938382f8948382f8958382f8968382f8978382f8988382f8998382f89a8382f89b8382f89c8382f89d8382f89e8382f89f8382f8a08382f8a18382f8a28382f8a38382f8a48382f8a58382f8a6838ed107608472a0f81cb0a0f81eb0a0f820b0a0f822b0a0f824b0a0f826b0a0f828b0a0f82ab0a0f82cb0a0f82eb0a0f830b0a0f832b0a0f834b0a0f836b0a0f838b0a0f83ab059e8001fb1427ff44aafbff35f8f49e8000121b159e8001fb142f8d03fe7d0f86c111c9d00294ff0ff3000f041816a78012a00f23d81287840ea022751f82700d8b1431a98074ff0ff3040f031816ff4403240f60f061a44cff6fd76b242c0f02781ca1852f8080cb84206d152f80c1ca1f1011010f5803f04d24ff0ff3013b0bde8f08f002a4ff0ff3000f0118152f8047c8f4240f00c81c3f54033994200f207810df138081046002243460024fff756fe0028e1d0e978a878090641ea00401f996b792a7901eb2047a8794fea036b4bea024982060f2300f00f0103eae27202fb01f389225343db0a8df828300e2310f0200f08bf0f2408bf012301fb03f302fb03f34fead3238df829304ff00d0308bf022301fb03f302fb03f34fead3238df82a304ff00c0308bf032301fb03f302fb03f34fead3238df82b304ff00b0308bf042301fb03f302fb03f34fead3238df82c304ff00a0308bf052301fb03f302fb03f34fead3238df82d304ff0090308bf062301fb03f302fb03f34fead3238df82e304ff0080308bf072301fb03f302fb03f34fead3238df82f304ff0070308bf082301fb03f302fb03f34fead3238df830304ff0060308bf092301fb03f302fb03f34fead3238df831304ff0050308bf0a2301fb03f302fb03f34fead3238df832304ff0040308bf0b2301fb03f302fb03f34fead3238df833304ff0030308bf0c2301fb03f302fb03f34fead3238df834304ff0020308bf0d2301fb03f302fb03f34fead3238df835304ff0010308bf0e234b4361435143c0f300105343c90a04900aa806ac099ddb0a8df83710039013cc4fea29468df8363022462b46cde90168009700f01cfcdde91001c21901eb2941a24227eae770b8bf1446a942b8bf0d46844212dd26eaeb718d420edd1e9a12680f2a0ad86b1a1e9d271a05ebc206f080501c31817781b3812860002013b0bde8f08f2de9f04f99b0824600284ff0ff3000f0a382239c082cc0f09f820f4616461d46faf71efb002800f01581229ad17901f10800844240f00e81cde90a171078577891794ef66c684ff29c5bcde90c6540ea0720ccf2ff08c2f2290b4ff6ff79002601250f910e9006e048f2a351c0f24501bff32f8f8847dbf80040bff35f8fdbf80000bff35f8f01466ff39601b1f1005f03d10168414500f0af804ff45c70fbf715fa002800f0d6804ff69041cff6ff714218373182f8706382f8716382f8726382f8736382f8746382f8756382f8766382f8776382f8786382f8796382f87a6382f87b6382f87c6382f87d6382f87e6382f87f6382f8806382f8816382f8826382f8836382f8846382f8856382f8866382f8876382f8886382f8896382f88a6382f88b6382f88c6382f88d6382f88e6382f88f6382f8906382f8916382f8926382f8936382f8946382f8956382f8966382f8976382f8986382f8996382f89a6382f89b6382f89c6382f89d6382f89e6382f89f6382f8a06382f8a16382f8a26382f8a36382f8a46382f8a56382f8a6638ed1c0f800808572a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a905be8001fa1427ff443afbff35f8f00bf4be8000121b15be8001fa142f8d037e7d0f86c21ddf888e00f9d002a4ff0ff3000f0a681012f00f2a3810e9852f82000e0b1811a88074ff0ff3040f099816ff4403340f60f060b44cff6fd76b342c0f08f81571857f8080c0e9a904206d157f80cbcabf1011010f5803f04d24ff0ff3019b0bde8f08f57f8040c58454ff0ff3040f07681c1f540318b4500f27181002f00f06e81bbf1c10fc0f06a8138780128e4d1a8060f2405f00f0604eae070704389246043c00a8df854000e209ef802809ef803209ef804c09ef8053015f0200f08bf012006fb00f004fb00f04fead0208df855004ff00d0008bf022006fb00f004fb00f04fead0208df856004ff00c0008bf032006fb00f004fb00f04fead0208df857004ff00b0008bf042006fb00f004fb00f04fead0208df858004ff00a0008bf052006fb00f004fb00f04fead0208df859004ff0090008bf062006fb00f004fb00f04fead0208df85a004ff0080008bf072006fb00f004fb00f04fead0208df85b004ff0070008bf082006fb00f004fb00f04fead0208df85c004ff0060008bf092006fb00f004fb00f04fead0208df85d004ff0050008bf0a2006fb00f004fb00f04fead0208df85e004ff0040008bf0b2006fb00f004fb00f04fead0208df85f004ff0030008bf0c2006fb00f004fb00f04fead0208df860004ff0020008bf0d2006fb00f004fb00f04fead0208df861004ff0010008bf0e2006fb00f004fb00f04fead0204ff000018df8620008bf0f2171430a9e61430020c90a002e8df8631000f09c801006259940ea084001eb2048180640ea0c400ef1080900140e90c5f30010a7f13f044d46099001e0013e1ad015f8010b411e1f29f8d341b22029fff6fbae04eb400114f81000497840ea0122c12afff4f1ae3846594610abfff716fb0028e3d1e8e60e980a9d20eae07008902498cde9064b0630059004e040440b38013d804659d019f8010b1f28f6d904eb400114f81000497810ac40ea0122c12acdf83c90fff4c8ae384659462346fff7edfa00283ff4c0ae0998dde90b1b0d9e049015a8ddf83890cde9024050465a463346cdf80490cdf8008000f079f9dde91201404401eb0902584528eae871b8bf8346b242a8bf32468b4519dd089eb24216dd249e34680f2c12d8ddf820c0abeb0103a2eb0c0e059a02ebc40622f83410249a611ca6f802c0b380a6f806e01160ddf83c90dde9064ba2e7002019b0bde8f08f00bf2de9f04f87b0149d6c68072c77d824b12f89b94273d0012c6ed1d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fdf7b6fb69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff486afaf89b942f4d0032c3ff480afef89b942eed0042c3ff47aaf2f8ab942e8d0052c3ff474af6f8ab942e2d0062c3ff46eafaf8ab9427ff46aafdae72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f87b00591dde91171ddf84cc00c692cb10c68844200f0948100259ee14f68002f00f0fc8100260021069609e0dde90361daf804703144ddf84cc0b94280f0ee81ddf848a00491daf80040655c2e0901d0012113e07f1a012f00f0e0810c4466780eb102210ae0042fc0f0d881a778e47857ea042600f0d281042100bf0391149915f00f04b1fa81f54fea55151cf804c018bf0124069945ea040e029616f00304ddf81490119e4fea0c188b4600f092800194daf80840b1fbf4f505fb1414109967180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990129069901f1010b5fd0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990229069901f1020b2ed0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050194fc07644604bf0f254446019f3d402c4301f80b40069901f1030b00bf029d6c1e032c2944069107d224e700bf06990bf1040b59453ff41eafdaf808401099bbfbf4f5002705fb14b40c44b4f1ff3fc8bf012707ea0e07012f1ad1ad1918d4944216d29d4214d205fb09056708e40715f807906ff00f04e24604bf0f24c24604ea0904ddf8149044ea0a04ddf848a0ec55daf808400bf10107b7fbf4f505fb147400270c44b4f1ff3fc8bf012707ea0e07012f14d1ad1912d4944210d29d420ed205fb09056708e407ee5d6ff00f04614604bf0f2441463440119e2143e955daf808100bf10204b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e01012914d1ad1912d4944210d29d420ed205fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c55daf808100bf10304b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e0101297ff46bafad193ff568af9442bff465af9d42bff462af05fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c5551e7002f01dd012508e0b7fa87f4109f00256409002fc8bf01252540d1f80880c96801fb08f9b9f1000f58d08e4614994ff0000ab1fa81f461094ff0ff3b0491e907069107e00af1010a0efb08f9ca45abf1010b43d2069954460029129918bf09eb0b04b4fbf8f50e6808f1010705fb18447f0805fb07666708f65d042121ea8407fe4016f00f094e4618bf012604990e43012ed7d1109964185cbf119915eb0105d0d49442ced29d42ccd20599660805fb01081cf8095018f80670129907f00f0907f0f0072f43e40708bf49ea051708f80670d1f80880d1f80ce0b3e707b0bde8f08f00bfb0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f3f753f906f1210506f1280029460722f3f74bf9284621460722f3f746f920465146032207f10905f3f73ff906f11d0049460422f3f739f9f07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f3f70df9a81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f059e60846fcf71fbf00bf2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f3f7c5f8012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f3f7acf8572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f3f795f8312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f3f77ff8462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f3f768f8362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f67320c0f20000784410f80b0041f66d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f7fdffcde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f7deff8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f7dffe284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f78bfe002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f759fe04a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f745fe0020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f72efe352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f70afe04a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f7f7fd002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f7e3fd04a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f7bffd04f14f0051460722f2f7b9fd84f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f26a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2f241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f72bfd84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f2f741fc284641462246c84703b0bde8f08370b50446d0f83c0142f665360d46c0f2440668b948f6e150cff6ff707844002122460023b0470028c4f83c0108bf70bd06f594718847d4f83c0106f1e8022946bde87040104700bf2de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3236000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff78afc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f037f8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef757fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef70dfe0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f0ecfa0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf00bfa48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf085f9414602e0022084f8200350460c22fef714f894f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7e4ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf7b3ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf75dff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf001f9d8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf0c7fa0bf09bfa294630b9ffe50bf096fa002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7fffd0fe04eea062141ea0b4141ea05633946624665460bf095f800281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af0bbf8d4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f2130409f06bfd4ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b7009f058fde05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f084fc059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f0b6fb28461a21224609f033fa00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f0a5f9854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f0a1f9706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f08ef8201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f034f9606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf793f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009507f0deff606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7e5fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009707f0effc002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009507f0d1fc606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009507f0a4fc606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f079fc606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf71dfa04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf7d9f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf783f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f096fa019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f2a011c0f20001033079440b22f9f752fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f71afc0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f76bfb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f7c1fa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f2ca10c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f71ffc4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f733fc4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f74cfbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f76bfb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009503f035f93eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb004460020a4f8800347f64c60c2f207000068002a8a461abfc4f874030146d4f87413401ac4f87c03fdf763f8002800f00081d4f86803002800f0fb8003f09bfe002800f0f6800646b4f86c0300284cd0a0f10109d4f87c034ff4a07100254ff4f0774ff4805bcde90d050df11808cde901152046494632464ff42073cdf818b007950c95cde90358009703f0def8002840f0cf80d4f8681330464ff41632f7f77cf9d4f87c034946cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906b50c95cdf81080009703f0bbf8002840f0ac809df8380094f88013084384f8800306e0d4f8681330464ff41632f7f751f94ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b07e000bf48f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168414548d04ff46d70fdf77bfe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8001f4945aad1bff35f8f00bf47e8000121b157e8001f4945f8d09fe7054603f0cdfd002d18bf002803d101208af8050022e0c5f860014ff001084ff4f07085f8648101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718af8058004e09af805008af8048030b14ff0ff300fb0bde8f08f0025cbe7204603f088fe00200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2e44d1c9008784f7801eb020c50ea072001f10204199002f0e7810df5a16e9ee860403aa8063000220f90cde9143c644502f0d481601c604502f0d08120786178a71c40ea0121aceb070081421d97209102f2c4811a92ddf81c2528a880e868401068ddf8141500282c91a0f10101116002f0b4812098002802f0b0812098871c032f02f0ab81e678032e02f2a7811d9890f80080f00703d104f1040e28e000bf209820f00100022802f0988194f8049065791c9849ea052b594628aa02f09ef9002842f08b81ddf8140504f1060e012d2c900dd8ddf81c05806948b14feadb0209f00701835c012505fa01f119438154022e04eb070b03d2ddf81405279025e0de4503d0744614f9015b01e000255c4645f64d5ac0f2460af146d047012808bf0135681e81b26e0800ebd130002d48bf4610d0470128ddf8140508bf76423118d945a64627912c9102f04881b8f1040fcdf894e000f39c80b8f1020f00f35081b8f1010f00f00882b8f1020f42f03681de4502f033810ef10100584502f02e810ef10200584502f029810ef10300584502f024810ef10400584502f01f810ef10500584502f01a810ef10600584502f015810ef10700584502f010810ef10800584502f00b810ef10900584502f006810ef10a00584502f001810ef10b00584502f0fc800ef10c00584502f0f7800ef10d00584502f0f2800ef10e00584542f0ed809ef80200289922909ef803009ef8009021909ef804009ef801601f909ef8050024913a91dde929211e909ef806709ef807409ef808b09ef809c09ef80a809ef80b309ef80ca09ef80de0cde92512cde93b212b9949ea06254ff6fe70854223913d9100f0c0864ff6ff70854240f094861c98d0f868634ff420703b904ff4f0703c904ff4a0703d9000f0aebe00bfb8f1060f00f34581b8f1050f00f0c381b8f1060f42f09a80de4502f097800ef10100584502f092800ef10200584502f08d800ef10300584502f088800ef10400584502f083800ef10500584502f07e800ef10600584502f079800ef10700584502f074800ef1080aabeb0a010829c2f06d800ef11001594542f068809ef804109ef8052051ea02201ebf9ef806109ef8073051ea032402f059809ef800509ef80160ddf8a4b045ea0621bbeb01032591c2f04c80984202f249809ef802309ef803702a9a43ea0721571ac2f03f80bc4202f23c800a46ddf81815002900f004872899134624912b9932022391e1182291259900eb0109279802442a449000219006e000bf269b22980133834280f0ec86dde92310219a03fb0107259d269304e001354d4502f10402ecd227984619f7d45e45f5da4fea560c17f80ce0042121ea02082efa08f3c3f342001af8000021ea8303d84000f00f030ef0f00423440ef00f01f60708bf41ea001307f80c30d7e7b8f1030f00f0b381b8f1040f41f0e687bbeb0e0401f0e2870ef10100584501f0dd871c98002801f0d987a01e0528c1f0d5870ef10700584541f0d0871c98d0f86c01002801f0ca879ef80110012901f2c5879ef8003043ea012250f82210002901f0bc870f1ab90741f0b8876ff4403140f60f063944cff6fd76b142c1f0ae87384450f8081c914241f0a88750f80c1ca1f1011616f5803fc1f0a087002801f09d8750f8046c8e4241f09887c7f54037b94201f29387ddf81c75bf6947b1d20803f00703be5c012505fa03f33343bb54dde928abdde92a56002232ab01f0daff00284ff0000908bf4ff0ff3901f00187ddf81805ddf854c000280df1b80801f0fa86072c4ff0ff3941f0f586baf1000f01f0f186fcf7befc002840f0358301f0e6beb8f1070f00f0d081b8f1080f41f05587ddf81c050021c0693aad32afdde9284adde92a863c91cde9320128463946cde93aeb02f0f0fd81462846394602f0ebfd3c99002900f0fb814ff0ff31ddf854c0894601f0bfbede4501f02f87714611f8010b012801f22987289a00281e92299a26922a9a25922b9a1f9200f0aa82594501f01b870ef10201594501f016870ef10301594501f011870ef10401594501f00c870ef10501594501f007870ef10601594501f002870ef10701594501f0fd860ef10801594501f0f8869ef801109ef802209ef8043041ea02219ef803209ef805709ef8064042ea032222929ef807209ef8083047ea042a0ef109070d9742ea032289e2bbeb0e0801f0d7860ef10100584501f0d286a8f102000528c1f0cd860ef10700584501f0c8861c98002801f0c4860ef1080a9ef80770abeb0a00b842c1f0bb860aeb0700584541f0b6861c98d0f86c31002b01f0b0869ef80100012801f2ab869ef8001041ea002053f82020002a01f0a286d21a960741f09e866ff4403640f60f051644cff6fd75ae42c1f094869e1856f8083c834241f08e8656f80c5ca5f1011313f5803fc1f08686002e01f0838656f8043cab4241f07e86c2f54032954201f27986ddf81c25926942b1c00801f00701135c012404fa01f119431154c12dc1f069863078012841f065862898002f2690299824902a9823902b98229000f0f780a6f13f04d14602e0013f00f0f08019f8010b411e1f29f7d341b22029c1f24a8604eb400114f81000497840ea0122c12ac1f04086304629463aab01f097fe0028e2d101f037beabeb0e09b9f1050fc1f031860ef10508d84501f02c860ef106059ef80570abeb0500b842c1f02386e819584541f01f8628981790299826902a981f902b981690afb1002402e00134bc4210d2285d01381e28f8d92819391b3aaa32ab02f0cdf8002801f004863a980444bc42eed3ddf81805002800f0c984b9f1050f01f0f7851798002801f0f385fcf74dfb002801f0ee8598f8008008f10600814541f0e78547f65420c2f20700d0f800b0bbf1000f01f0dd859bf80c009bf80d109bf80e209bf80f3040ea012040ea024040ea0366a6f1810010f1800fc1f0c9859bf810009bf811109bf8132040ea01209bf8121040ea014040ea02600890813810f5817f41f2b585b8f1000f4ff0000900f054844ff0000c00270be000bf00f100403aa941f824000137474504f1010c80f0f183e85d6446411e1e29efd9e819a8eb070132aa2eab02f059f8002801f0198532992e983aaa0f4442f82400e4e7de4501f086850ef10100584501f081850ef10200584541f07c859ef800009ef8011028af40ea0121ddf81c058ccf0490ddf818052b9e03902798019602901c98009702f06efb814601f0eebcddf81805002800f02c840020b8f1080f4ff0ff393a90c1f0e1842698002801f0dd84fcf7acfa002801f0d6842599cd7905f10800804541f0cf8408784f7891f8068040ea072600f018bcdde93a218a423ff400ae531c8b423ff4fcad931c8b423ff4f8add31c8b423ff4f4ad131d8b423ff4f0ad531d8b423ff4ecad931d8b423ff4e8add31d8b423ff4e4ad02f108038b427ff4dfad1178537851ea032c4ff0ff311ebf9378d77853ea07233ff4d4adbcf5207f3ff6d0adb3f5f07f3ff6ccad97790f2f21973ff6c7add579102d25953ff6c2adddf81c55229033982f6a1f933843ddf8187513795279002f1696cdf898a0286201f0878427980021604440428145fff6a9addde92670381a8145bff6a3ad1f9847422298b842fff69dad2298a346ddf858a01f9c80457ff795ad43ea0222b2eb5c0f28bf4fea5c02b2eb540f28bf62081792013a4ff0000338bf1a460992424202eae075a8eb0002a242a8bf224695421e92bff677ad279a179b91445a001b9203fb03f2920013920ceb09022392bcf1030f38bf01210022032c38bf012211431291611e0e91a11e0c9109994ff000084a0049438900069109f101010a9125990b920a0141ea011107916ff0080101eb43010d9120eae0710afb01b1002608922791cdf8409001f0e9b9594501f071840ef10201594501f06c840ef10301594501f067840ef10401594501f062849ef802209ef80110520022929ef803209ef804304fea820a0ef1050289000d925a00baf1000f0e9201f04c840e9a002a01f04884269a521ac1f04484924501f24184259a229bd21ac1f03c840e9b934201f2388400287bd02798002301eb000985e048f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914201f04b804ff46d70fdf711f8002801f093834ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001f259ba14295d1bff35f8f00bf42e80001002900f0fa8752e8001fa142f6d088e72798002301eb0009c00708d1b9f1000f05d426990aeb09008842d8bf01230d9e0e9aabeb06000b90ddf8180502fb0af2b0fa80f040091843c0070027109000200c932390cde9112b11e000bf23981b99084423901698189981424ff0000088bf01200743179ef80708bf0e44119af80704d02398824208d801f07cbb5e4500f024822398824240f22082bbeb060001f0718396f800805fea181301d0012111e0012801f0678373780bb102210ae00428c1f06083b178f37851ea032301f05a83042100bf18912399511a8b4201f252831099dde91eec00291b93cde91606b5d108f00f0027901b981397411e03294fea0811249180f082804ff000081b98dde912b710f00301a1d02398229a4044b0fbfaf303fb1a0713444f4453ea070617d4269a974214d2259eb34211d203fb0ce37e089d5d279a05f00f0e05f0f0051544ff07249a08bf4eea0205dde91eec9d55dde912b701293ff479af431cb3fbfaf7229a07fb1a36bb1806eb090753ea070617d4269a974214d2259eb34211d203fb0ce37e089d5d279a05f00f0e05f0f0051544ff07249a08bf4eea0205dde91eec9d55dde912b702293ff450af0230b0fbfaf1229a01fb1a008b18484453ea00013ff544af26998842bff440af25998b42bff43caf03fb0ce14308cf5c279a07f00f0607f0f0071744c007249808bf46ea0007ddf848b0cf54139f27e7229c20f003004ff00008219006e000bf219808f1040840453ff472af23984044b0fbfaf303fb1a061f1906eb090b57ea0b0319d426998b4516d225998f4213d207fb0ce34fea5b069f5d279907f00f0e07f0f0070f445feacb71249908bf4eea0107dde91eec9f55411cb1fbfaf3229c03fb1a11234401eb090753ea070115d426998f4212d225998b420fd203fb0ce17b08ce5c279a06f00f0506f0f0061644ff07249a08bf45ea0206ce54811cb1fbfaf303fb1a11234401eb090753ea070115d426998f4212d225998b420fd203fb0ce17b08ce5c279a06f00f0506f0f0061644ff07249a08bf45ea0206ce540330b0fbfaf101fb1a000b19484453ea00013ff586af26998842bff482af25998b42bff47eaf03fb0ce14308cf5c279d07f00f0607f0f0072f44c007249808bf46ea0007cf546ce71c9829463aaacde9163ecdf86c80cdf860a0e04601f025fa002841f09b81ddf81c05c4468069ddf860a0ddf86c80dde9163e60b1012e0ad8ea0809f00701855c012606fa01f1ddf860a0294381543a9e002e01f07f81cdf86c8057ea04284ff0ff3901f079815bea0c20189001f07481dde921213b9841ea02218842c1f06c81401a804501f268811d46dde91e323c9842ea03220023904238bf01232292801a189a82424ff0000088bf01201843c0f1000941f05181ddf81805002801f04c811b9a280640ea024005144fea0e60249a40ea0a4096424fea204e00f0fc848946002300f007bdbcf1000f249600f0f580259eacf101094ff000083aaf0ae0259eac46c14508f10108a4f1010407f1040700f0df803aa850f828100029f1d40020434684421dd007eb80056a68b2f1ff3f18dc5a1c914514d0aa68b2f1ff3f11dc9a1c91450dd0ea68b2f1ff3f0adcda1c914506d02a690433002a00f10400e0d400e00022584632ab2eae6546009601f0bafc002801f0ee802e980028bfd04af20d3132a8c0f24e018847b8e72496259e01204ff0000ca4e05e4541f052812398824241f04e81ddf81805002818bf01200c990840012812d1dde91e0322994fea5a0701fb03000b9900eb59020e98009701900d9801f005fa002801f03281ddf854c01a9a01f0beb848f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f02e834ff46d70fcf70dfd002801f08f804ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa14296d1bff35f8f42e80001002900f0de8252e8001fa142f6d08ae700204ff0000903e0259e4ff0000c0120317996f800e07278b378f7788e060f2501f00f0405eae676664389256e43f60a8df8b8600e26259111f0200f08bf012604fb06f605fb06f64fead6268df8b9604ff00d0608bf022604fb06f605fb06f64fead6268df8ba604ff00c0608bf032604fb06f605fb06f64fead6268df8bb604ff00b0608bf042604fb06f605fb06f64fead6268df8bc604ff00a0608bf052604fb06f605fb06f64fead6268df8bd604ff0090608bf062604fb06f605fb06f64fead6268df8be604ff0080608bf072604fb06f605fb06f64fead6268df8bf604ff0070608bf082604fb06f605fb06f64fead6268df8c0604ff0060608bf092604fb06f605fb06f64fead6268df8c1604ff0050608bf0a2604fb06f605fb06f64fead6268df8c2604ff0040608bf0b2604fb06f605fb06f64fead6268df8c3604ff0030608bf0c2604fb06f605fb06f64fead6268df8c4604ff0020608bf0d2604fb06f605fb06f64fead6268df8c5604ff0010608bf0e2604fb06f605fb06f64fead6268df8c6604ff0000608bf0f2666436e43f60a00280df1b8088df8c76040f07187120642ea0e41279a380602eb2144249940ea0340acf1010501eb204000260790cdf830c0cde9095b07e001f01f000b3801366645044400f0c4833aa850f82610b1f1ff3ff1dd33469d421cd03aa800eb83004268b2f1ff3f16dc0133ab4212d08268b2f1ff3f0fdc0133ab420bd0c268b2f1ff3f08dc0133ab4204d002690133002ae1d400e00022584632ab2daf009701f0eefa002800f022872d990029129100f0ac819df8d0009df8d1100d9650ea0126109400f092819df8d4701b969df8d5603f0447ea0667089e1b9d9df8cf009df8ce102e44020241ea00249df8d20006eb2747079e9df8d3300004f71b109e40ea0360031406eb204c0120239700eb54070a441197571e1397f71801f00305f11a0cf101030e930cf102030b93129b00eb52001b9e01332290501b1e951d4627904ff00009ca07f8071894249006e0229809f10109b145054400f04781239819eb0001f4d41f988142f1d218980028eed0dde91630002701fb030a13982195032880f097801e981b9e219d0028dfd0dde91110012409fb010325987908595c00f0100084ea101bc8b201f00f015feac77e08bf01090846002918bf012040ea0b00012816d117eb0c0513d42698854210d268081af8004018f8011004f00f0604f0f0040c43ed0708bf46ea01141b9e0af800401e98219d0128a9d0781c4008195cbef1000fc8b24fea101008bf01f00f00c1b2002918bf012141ea0b01012917d10e99c91914d4269ca14211d24c081af8045018f8000005f00f0605f0f0050543c90708bf46ea00151b9e0af80450219d1e9802283ff47bafb81c4008185cbef1000f00f00f01c3b208bf19090846002918bf012040ea0b0001287ff468af0b983b183ff564af26988342bff460af58081af8004018f8011004f00f0504f0f0040c43db0708bf45ea0114219d0af800404de7ab4606e027980437b8420bf1020b3ff460af25981bf8013c00f010010120ddb2002380ea11110f2d88bf01230b43012b0ceb070319d1002b17d42698834214d22e095d081af8054018f8066004f00f0004f0f0045feacc7844ea06040df1b80808bf40ea06140af805401bf8010c10f00f05284618bf01200843012815d15e1c13d42698864210d270081af8004018f8055004f00f0646ea051604f0f004002a08bf44ea05060af800609bf80000c5b200200f2d88bf01200843012818d19e1c16d42698864213d2740828091af8045018f8000005f00f0605f0f005ddf890e00543bef1000f08bf46ea00150af804509bf8000010f00f05284618bf0120084301287ff47fafd91c3ff57caf26988142bff478af48081af8001018f8053001f00f0444ea031401f0f001002a08bf41ea03040af8004065e74af20d3132a8c0f24e0188479df8cc009df8cd10109cdde9095bdde90cc605e09df8cc009df8cd10ddf830c040ea012010e6d0f86c114ff0ff39002900f06385012f00f2608551f82600002800f05b85401a820740f057856ff4403240f60f030244cff6fd739a42c0f04d850b1853f8081cb14240f0478553f80c7c0022a7f10111cff6ff729142c0f03d8553f8041cb94240f03885c0f540308742219700f232859b46002bcdf87ca000f02c852198c128c0f028859bf80000012840f023854fea88660f2408f00f0704eae6767e4389246643ddf894a0f60a8df8b8600e269af802109af803309af804009af8052018f0200f08bf012607fb06f604fb06f64fead6268df8b9604ff00d0608bf022607fb06f604fb06f64fead6268df8ba604ff00c0608bf032607fb06f604fb06f64fead6268df8bb604ff00b0608bf042607fb06f604fb06f64fead6268df8bc604ff00a0608bf052607fb06f604fb06f64fead6268df8bd604ff0090608bf062607fb06f604fb06f64fead6268df8be604ff0080608bf072607fb06f604fb06f64fead6268df8bf604ff0070608bf082607fb06f604fb06f64fead6268df8c0604ff0060608bf092607fb06f604fb06f64fead6268df8c1604ff0050608bf0a2607fb06f604fb06f64fead6268df8c2604ff0040608bf0b2607fb06f604fb06f64fead6268df8c3604ff0030608bf0c2607fb06f604fb06f64fead6268df8c4604ff0020608bf0d2607fb06f604fb06f64fead6268df8c5604ff0010608bf0e2607fb06f604fb06f64fead6268df8c6604ff0000608bf0f26774367434ff00009ff0a002d8df8c77000f055841b0643ea0141279b1f9e03eb2147110641ea004000141e90c8f30010abf13f092c461b9000f027bc2298864502dd8946012308e07ff4fcaa27988946284400238842c8bf0123189920024fea0c2201fb08f1219142ea0b013843414327983d9ab1f1010a05eb000b1f9200f08a8021f00100cdf89c901b9000204feac379179118931e9605e01b9a01309042aaf1020a72d00146b9f1000f18bf5046b0fbf8f505fb180405eb0e070beb040057ea000325d4269a904222d2259a97421fd2229aab181f9a03fb0263279aa51804226c0822ea8505dde923621b5d07fb0627eb4045087c5d03f00f0604f00f0204f0f0042644c00708bf42ea03167e551e9e6ff0010081ea0002481c0346b9f1000f219f18bfbb18b3fbf8f505fb183405eb0e0c0beb04075cea0702add4269a9742aad2259a9445a7d2229a1f9b2a4402fb0362279b7e0823445c08125d042424ea8303da40dde923430cfb043302f00f049d5d05f00f0c05f0f0052c44fd0708bf4cea02149c551e9e86e7881c279ddde9171301e000204d46c90702d14ff000098ce3da076fea0001219a18bf5018b0fbf8f74ff0000907fb180207eb0e010beb020051ea000300f17983269b984280f07583259b994280f07183229b2a443b441f9f03fb07635708db5d042727ea820223fa02f2dde9237302f00f0601fb07314308cf5cc00707f00f0507f0f007374408bf45ea0217cf5450e3259bd0f86c014ff0ff39002800f049835978012900f245831a7842ea012150f82120002a00f03d83121a930740f039836ff4403340f60f071344cff6fd77bb42c0f02f83104450f8083c8b4240f0298350f80c1c0027a1f10113cff6ff77bb42c0f01f83002800f01c8350f8043c8b4240f01783c2f54032914200f2128300223aab3446269500f0ddfb002800f00783259f0f25f978b87809067b7941ea004027993a7901eb2040190641ea0241ba790914970602f00f0305eae7775f4389256f43ff0a8df8b8700e2712f0200f08bf012703fb07f705fb07f74fead7278df8b9704ff00d0708bf022703fb07f705fb07f74fead7278df8ba704ff00c0708bf032703fb07f705fb07f74fead7278df8bb704ff00b0708bf042703fb07f705fb07f74fead7278df8bc704ff00a0708bf052703fb07f705fb07f74fead7278df8bd704ff0090708bf062703fb07f705fb07f74fead7278df8be704ff0080708bf072703fb07f705fb07f74fead7278df8bf704ff0070708bf082703fb07f705fb07f74fead7278df8c0704ff0060708bf092703fb07f705fb07f74fead7278df8c1704ff0050708bf0a2703fb07f705fb07f74fead7278df8c2704ff0040708bf0b2703fb07f705fb07f74fead7278df8c3704ff0030708bf0c2703fb07f705fb07f74fead7278df8c4704ff0020708bf0d2703fb07f705fb07f74fead7278df8c5704ff0010708bf0e2703fb07f705fb07f74fead7278df8c6704ff0000708bf0f277b436b43db0a8df8c730c2f30012269bcde90382cde90001504621465a463aaf4ff00009029700f094fe29e201200190184626993b46219f009701f050fa229827990135514427911e998d424ff00001bef654abe94321448d42b8bf29461b9a6fea4101114401295cdb139a4ff0ff3301fb1121179a921b012a03eb420231db02fb02f38b422ddd0d9aa2eb460303f10807032f03f106021edb02fb02f48c421add052f03f1040218db02fb02f48c4214dd072f03f1020212db02fb02f48c420edd0436092fa3f1080203db5b438b421346dcdc083204e0013602e0023600e003361f9c012e1edb0832931f5b438b4219dc022e16db131f5b438b4200f3ae80022e0fd0931e5b438b4200f3a980042e08db02fb02f38b4200f3a480043e02f10802e2d10026291801fb0ab3259906eb090210292399a1eb06073ff477af2493b5fa85f1129b490919434ad10e998d4247d00c99681e491b119718958842b8bf01466fea41000b9908440128c0f2a980069900fb10100999a1eb08034ff0ff31012b01eb430177db01fb01f7874273dd5900a1f1090303f10807032f03f1060162db01fb01f484425edd052f03f104015ddb01fb01f4844259dd072f03f1020158db01fb01f4844254dd08f10408092fa3f1080103db5b4383420b46dbdc08314ae0269922eae27c8f42a8bf0f46bc45bff626afbe465feacc7018950ad0249b4fea5c00195c259a01f0f00111430cf1010c19544fea5c02b2eb5e0f1ad22498279f079d00eb5e03b9180c4604f8015b9c4280f08480881c9842257080f08480cc1c9c4205707ed20437b81898422570ead379e0249800eb5c0075e0013e62e7023e60e7033e5ee708f1010804e008f1020801e008f10308b8f1010f23db08318b1f5b4383421edcb8f1020f19db0b1f5b43834200f3cf80b8f1020f11d08b1e5b43834200f3ca80b8f1040f09db01fb01f3834200f3c580b8f1040801f10801ded14ff000080a98ddf8989000eb080c22eae27ecc45b8bfe146ce454cda5feace700ad0249b4fea5e00195c259a01f0f00111430ef1010e19544fea5e07b7eb590f18d22498079d00eb59032798c1190c4604f8015b9c4213d28a1c9a4225701fd2cc1c9c4215701ad20430c2199a422570ecd315e0249800eb5e0211e0481c02e04a1c0de020465feace716bd0f44569d20178089a01f00f011143017062e022465feac97007d0ce4505d21078089900f00f000843107023996fea080001eb000a0120269c01902498219f214662465346009701f0a3f811982aeaea7ca042a8bf204684453eda86465feacc700ad0249b4fea5c00195c259a01f0f00111430cf1010c19544fea5c02b2eb5e0f18d22498279f079d00eb5e03b818044604f8015b9c4211d2811c9942257010d2c41c9c420d700bd20437b91899422570ecd306e0249800eb5c0102e0411c00e021465feace7007d0f44505d20878089a00f00f00104308702298ddf858a01f9cddf84090189d04e6a8f1010844e7a8f1020841e7a8f103083ee7013c31d016f8010b411e1f29f8d341b220290fdb09eb400119f81000497840ea0122c12a06d32199584632ab00f0d5f80028e5d14ff0ff39ddf854c01a9ab9f1000f6ed11998013282421d9820990df5a16e149b9ee8604000eb01047df48aae65e00021fef726b93a9827901e9820eae070259005e038440b38013d07463ff44bac1f9911f8010b1f281f91f3d909eb400119f81000497840ea0122c12ac9d32199584632ab00f098f80028c2d01b98249c04902ea8039032a8ddf88ca00290ddf878802698229922465346cdf80480009700f01afcdde93401384401eb0802a04227eae771b8bf04465245a8bf52468c42c2dd259fba42bfdd279f0f2fbcd8259e631aa2eb060c0f9c279a04ebc20724f8321001327e80bb80a7f806c02792abe74ff0ff300df2e44dbde8f08fb4eb0c0018bf4ff0ff300df2e44dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f87b00591dde91171ddf84cc00c692cb10c68844200f0948100259ee14f68002f00f0fc8100260021069609e0dde90361daf804703144ddf84cc0b94280f0ee81ddf848a00491daf80040655c2e0901d0012113e07f1a012f00f0e0810c4466780eb102210ae0042fc0f0d881a778e47857ea042600f0d281042100bf0391149915f00f04b1fa81f54fea55151cf804c018bf0124069945ea040e029616f00304ddf81490119e4fea0c188b4600f092800194daf80840b1fbf4f505fb1414109967180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990129069901f1010b5fd0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990229069901f1020b2ed0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050194fc07644604bf0f254446019f3d402c4301f80b40069901f1030b00bf029d6c1e032c2944069107d224e700bf06990bf1040b59453ff41eafdaf808401099bbfbf4f5002705fb14b40c44b4f1ff3fc8bf012707ea0e07012f1ad1ad1918d4944216d29d4214d205fb09056708e40715f807906ff00f04e24604bf0f24c24604ea0904ddf8149044ea0a04ddf848a0ec55daf808400bf10107b7fbf4f505fb147400270c44b4f1ff3fc8bf012707ea0e07012f14d1ad1912d4944210d29d420ed205fb09056708e407ee5d6ff00f04614604bf0f2441463440119e2143e955daf808100bf10204b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e01012914d1ad1912d4944210d29d420ed205fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c55daf808100bf10304b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e0101297ff46bafad193ff568af9442bff465af9d42bff462af05fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c5551e7002f01dd012508e0b7fa87f4109f00256409002fc8bf01252540d1f80880c96801fb08f9b9f1000f58d08e4614994ff0000ab1fa81f461094ff0ff3b0491e907069107e00af1010a0efb08f9ca45abf1010b43d2069954460029129918bf09eb0b04b4fbf8f50e6808f1010705fb18447f0805fb07666708f65d042121ea8407fe4016f00f094e4618bf012604990e43012ed7d1109964185cbf119915eb0105d0d49442ced29d42ccd20599660805fb01081cf8095018f80670129907f00f0907f0f0072f43e40708bf49ea051708f80670d1f80880d1f80ce0b3e707b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf78aff69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae72de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041b1e022eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70faf736f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f7c7ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f9f76ef8e0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f7dafc02a9284600224ff0000afbf78bff81464046f7f79ffdb9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f79dff06f1210506f1280029460722f2f795ff284621460722f2f790ff20465146032207f10905f2f789ff06f11d0049460422f2f783fff07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f757ffa81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f71dff012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f704ff572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f7edfe312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f7d7fe462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f7c0fe362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f755fecde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f736fe8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f737fd284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f7e3fc002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f7b1fc04a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f79dfc0020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f786fc352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f762fc04a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f74ffc002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f73bfc04a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f717fc04f14f0051460722f2f711fc84f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f783fb84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f2f799fa284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f8f793f90028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3237000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "dc443a00", + "new": "1c483a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "5c453a00", + "new": "9c483a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "dc443a04", + "new": "1c483a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "fe2d93a9", + "new": "b66f5542", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "13f7ac84", + "new": "d0697cd9", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "13f7ac84", + "new": "d0697cd9", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/graphics/image.ts b/app/graphics/image.ts index 05f7125d..0fe17b97 100644 --- a/app/graphics/image.ts +++ b/app/graphics/image.ts @@ -1,3 +1,4 @@ +import type { MenuHighlightAnimation } from "../ui/menu-highlight-motion"; import { Glyph } from "./bdffont"; import { wrapText } from "./textwrap"; @@ -73,7 +74,7 @@ export type PlacedGlyph = { * from the moment it is placed. */ export type PlacedImage = { - presentation?: { mode?: "image" | "masked-image"; radius: number; background: number; border: number; depth: number; occlusions?: readonly { x: number; y: number; width: number; height: number }[] }; + presentation?: { animation?: MenuHighlightAnimation; mode?: "image" | "masked-image"; radius: number; background: number; border: number; depth: number; occlusions?: readonly { x: number; y: number; width: number; height: number }[] }; kind: "image"; source: GrayImage; x: number; @@ -394,7 +395,7 @@ export class GrayImage { hash = mixInt(hash, placed.source.width); hash = mixInt(hash, placed.source.height); hash = mixInt(hash, placed.source.sourceContentHash32()); - if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0]) hash = mixInt(hash, value); } + if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0, p.animation?.token ?? 0, p.animation?.dx ?? 0, p.animation?.dy ?? 0]) hash = mixInt(hash, value); } } else { hash = mixInt(hash, 0xf17e); hash = mixInt(hash, placed.font.atlasTag); @@ -506,9 +507,9 @@ export class GrayImage { } /** Retain the selected row separately from the menu surface for glasses-side composition. */ - drawMenuSelection(source: GrayImage, x: number, y: number, background: number, border: number, radius = 8, depth = 2): void { + drawMenuSelection(source: GrayImage, x: number, y: number, background: number, border: number, radius = 8, depth = 2, animation?: MenuHighlightAnimation): void { this.drawList.push({ kind: "image", source: source.withDrawsBaked(), x, y, - presentation: { radius, background, border, depth } }); + presentation: { radius, background, border, depth, animation } }); } /** Replay an image at stereo depth. Masked images preserve intentional gray8 black (1). */ diff --git a/app/graphics/presentation-wire.ts b/app/graphics/presentation-wire.ts index 0524cc8c..2c58b546 100644 --- a/app/graphics/presentation-wire.ts +++ b/app/graphics/presentation-wire.ts @@ -1,20 +1,27 @@ import type { PlacedImage } from './image' -/** Bridge record: tag 3 (selection), 4 (image), 5 (gray8-masked image), signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, gray pixels, restore rectangles. */ +/** Bridge record: tag 3 (selection), 4 (image), 5 (gray8-masked image), 6 (animated selection), signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, gray pixels, restore rectangles. */ export function encodePresentation(draw: PlacedImage): Uint8Array { const p = draw.presentation! const { width, height, pixels } = draw.source if (width < 1 || height < 1 || width > 640 || height > 480 || 5 + Math.ceil(width / 2) * height > 65536) throw new Error('Presentation image exceeds the resource size limit') if (!Number.isInteger(p.depth) || p.depth < -128 || p.depth > 127) throw new Error('Invalid menu depth') if ((p.occlusions?.length ?? 0) > 2048) throw new Error('Too many menu occlusion rectangles') - const bytes = new Uint8Array(16 + width * height + (p.occlusions?.length ?? 0) * 8), view = new DataView(bytes.buffer) - bytes[0] = p.mode === "image" ? 4 : p.mode === "masked-image" ? 5 : 3 + const animation = p.animation; + const header = animation ? 26 : 16; + const bytes = new Uint8Array(header + width * height + (p.occlusions?.length ?? 0) * 8), view = new DataView(bytes.buffer) + bytes[0] = animation ? 6 : p.mode === "image" ? 4 : p.mode === "masked-image" ? 5 : 3 view.setInt16(1, draw.x, true); view.setInt16(3, draw.y, true) view.setUint16(5, width, true); view.setUint16(7, height, true); view.setUint16(9, p.radius, true) bytes[11] = p.background; bytes[12] = p.border; view.setInt8(13, p.depth) view.setUint16(14, p.occlusions?.length ?? 0, true) - bytes.set(pixels, 16) - let offset = 16 + pixels.length + if (animation) { + view.setInt16(16, animation.dx, true); view.setInt16(18, animation.dy, true); + view.setUint16(20, Math.max(0, Math.min(500, Date.now() - animation.startedAt)), true); + view.setUint32(22, animation.token, true); + } + bytes.set(pixels, header) + let offset = header + pixels.length for (const rect of p.occlusions ?? []) { view.setUint16(offset, rect.x, true); view.setUint16(offset + 2, rect.y, true) view.setUint16(offset + 4, rect.width, true); view.setUint16(offset + 6, rect.height, true); offset += 8 @@ -22,13 +29,16 @@ export function encodePresentation(draw: PlacedImage): Uint8Array { return bytes } -export type Selection = { mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } +export type Selection = { animation?: { dx: number; dy: number; startedAt: number; token: number }; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } export function readPresentation(bytes: Uint8Array, offset: number): { selection: Selection; end: number } { const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), w = v.getUint16(offset + 5, true), h = v.getUint16(offset + 7, true) + const header = bytes[offset] === 6 ? 26 : 16 const selection: Selection = { mode: bytes[offset] === 4 ? "image" : bytes[offset] === 5 ? "masked-image" : undefined, x: v.getInt16(offset+1,true), y: v.getInt16(offset+3,true), width:w, height:h, radius:v.getUint16(offset+9,true), background:bytes[offset+11]!, border:bytes[offset+12]!, depth:v.getInt8(offset+13), - pixels:bytes.slice(offset+16,offset+16+w*h), occlusions:[] } - let end=offset+16+w*h + pixels:bytes.slice(offset+header,offset+header+w*h), occlusions:[] } + if (header === 26) selection.animation = { dx:v.getInt16(offset+16,true), dy:v.getInt16(offset+18,true), + startedAt:Date.now()-v.getUint16(offset+20,true), token:v.getUint32(offset+22,true) } + let end=offset+header+w*h for(let i=0;i=width||y>=height || !inside(xx,yy,row.width,row.height,row.radius)) continue + const i=y*width+x + output[i]=!inside(xx-1,yy-1,row.width-2,row.height-2,Math.max(0,row.radius-1))?q(row.border)*16:Math.max(output[i]!,q(row.background)*16) + } for(let yy=0;yy=width||y>=height) continue - const i=y*width+x - if(!row.mode && inside(xx,yy,row.width,row.height,row.radius)) output[i]=!inside(xx-1,yy-1,row.width-2,row.height-2,Math.max(0,row.radius-1))?q(row.border)*16:Math.max(output[i]!,q(row.background)*16) const value=q(row.pixels[yy*row.width+xx]!) - if(row.mode === "masked-image" ? row.pixels[yy*row.width+xx] !== 0 : value !== 0) output[i]=value*16 + if(row.mode === "masked-image" ? row.pixels[yy*row.width+xx] !== 0 : value !== 0) output[y*width+x]=value*16 } for(const r of row.occlusions) for(let yy=r.y;yy=0&&yy>=0&&xx() private shellScene: Uint8Array | null = null - setShellScene(bytes: Uint8Array): void { this.shellScene = new Uint8Array(bytes) } + private shellReceivedAt = 0 + setShellScene(bytes: Uint8Array): void { this.shellScene = new Uint8Array(bytes); this.shellReceivedAt = Date.now() } private dimBelow = 0 private dimFactor = 1 private blanked = false @@ -92,7 +93,7 @@ export class SurfaceCompositor { if(x+xx+shift>=0 && y+yy>=0 && x+xx+shift visibleRowCount) { @@ -315,9 +321,11 @@ export class MenuLayer implements Layer { } switch (event.type) { case "scroll-up": + this.highlightMotion.navigate(this.selectedIndex, this.selectedIndex === 0); this.selectedIndex = (this.selectedIndex + this.items.length - 1) % this.items.length; return; case "scroll-down": + this.highlightMotion.navigate(this.selectedIndex, this.selectedIndex === this.items.length - 1); this.selectedIndex = (this.selectedIndex + 1) % this.items.length; return; case "double-click": diff --git a/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.android.kt b/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.android.kt new file mode 100644 index 00000000..3b2e422f --- /dev/null +++ b/native/kotlin/shared/src/androidMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.android.kt @@ -0,0 +1,15 @@ +package com.faceclaw.app + +import java.util.concurrent.ScheduledThreadPoolExecutor +import java.util.concurrent.TimeUnit + +private object DrawRedrawScheduler { + val executor = ScheduledThreadPoolExecutor(1) { task -> + Thread(task, "Faceclaw draw animation").apply { isDaemon = true } + }.apply { removeOnCancelPolicy = true } +} + +internal actual fun scheduleDrawRedraw(delayMs: Int, action: () -> Unit): () -> Unit { + val future = DrawRedrawScheduler.executor.schedule(action, delayMs.toLong(), TimeUnit.MILLISECONDS) + return { future.cancel(false); Unit } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawExpression.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawExpression.kt new file mode 100644 index 00000000..4545f009 --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawExpression.kt @@ -0,0 +1,260 @@ +package com.faceclaw.app + +/** Literal or branchless expression used by rounded-rectangle x/y in revision 27. */ +sealed class DrawValue { + class Integer(val value: Int) : DrawValue() + class Expression(val program: ByteArray) : DrawValue() + + companion object { + /** Smoothstep interpolation; time is measured from the next PRESENT. */ + fun animate(from: Int, to: Int, durationMs: Int = 500, elapsedMs: Int = 0): DrawValue { + require(durationMs > 0 && elapsedMs >= 0) + if (from == to || elapsedMs >= durationMs) return Integer(to) + val code = ByteSink() + fun integer(value: Int) { + code.write(DrawExpression.PUSH_I32) + code.write(ExtendedVarint.signed(value)) + } + integer(from) + code.write(DrawExpression.I2F) + integer(to) + code.write(DrawExpression.I2F) + integer(durationMs - elapsedMs) + code.write(DrawExpression.TIME) + integer(elapsedMs) + code.write(DrawExpression.IADD) + code.write(DrawExpression.I2F) + integer(durationMs) + code.write(DrawExpression.I2F) + code.write(DrawExpression.FDIV) + code.write(DrawExpression.SMOOTHSTEP) + code.write(DrawExpression.LERP) + code.write(DrawExpression.F2I) + return Expression(code.toByteArray()) + } + } +} + +/** Prefix payload is most-significant first; continuation bytes use all eight bits. */ +internal object ExtendedVarint { + private val widths = intArrayOf(7, 14, 21, 28, 32) + private val prefixes = intArrayOf(0, 0x80, 0xc0, 0xe0, 0xf0) + + fun signed(value: Int): ByteArray { + val size = widths.indexOfFirst { bits -> + bits == 32 || value.toLong() in -(1L shl (bits - 1)) until (1L shl (bits - 1)) + } + 1 + return encode(value, size) + } + + fun unsigned(value: UInt): ByteArray { + val size = widths.indexOfFirst { it == 32 || value.toLong() < (1L shl it) } + 1 + return encode(value.toInt(), size) + } + + private fun encode(value: Int, size: Int): ByteArray { + val bytes = ByteArray(size) + if (size == 5) { + bytes[0] = 0xf0.toByte() + } else { + val mask = (1 shl (8 - size)) - 1 + bytes[0] = (prefixes[size - 1] or ((value ushr (8 * (size - 1))) and mask)).toByte() + } + for (i in 1 until size) bytes[i] = (value ushr (8 * (size - 1 - i))).toByte() + return bytes + } + + fun read(reader: DrawReader, signed: Boolean, first: Int = reader.readU8()): Int { + val size = when { + first < 0x80 -> 1 + first < 0xc0 -> 2 + first < 0xe0 -> 3 + first < 0xf0 -> 4 + first == 0xf0 -> 5 + else -> error("Reserved extended-varint prefix") + } + var value = if (size == 5) 0 else first and ((1 shl (8 - size)) - 1) + repeat(size - 1) { value = (value shl 8) or reader.readU8() } + val bits = widths[size - 1] + return if (signed && bits < 32) (value shl (32 - bits)) shr (32 - bits) else value + } + + fun write(value: DrawValue): ByteArray = when (value) { + is DrawValue.Integer -> signed(value.value) + is DrawValue.Expression -> { + require(value.program.size <= DrawExpression.MAX_BYTES) + byteArrayOf(0xff.toByte()) + unsigned(value.program.size.toUInt()) + value.program + } + } + + fun evaluate(reader: DrawReader, frame: DrawEvaluation): Int { + val first = reader.readU8() + if (first != 0xff) return read(reader, true, first) + val length = read(reader, false).toUInt() + // Outer framing errors reject the call; errors inside a framed program yield zero. + require(length <= reader.remaining.toUInt()) + val program = reader.readSlice(length.toInt()) + if (length > DrawExpression.MAX_BYTES.toUInt()) return 0 + return DrawExpression.evaluate(program, frame) + } +} + +internal class DrawEvaluation(val elapsedMs: Long) { + var animationPending = false +} + +/** Typed i32/f32 stack machine. Keep opcode IDs and semantics in sync with draw_expression.c. */ +internal object DrawExpression { + const val MAX_BYTES = 1024 + const val MAX_STACK = 32 + const val PUSH_I32 = 1 + const val PUSH_F32 = 2 + const val DUP = 3 + const val DROP = 4 + const val SWAP = 5 + const val IADD = 16 + const val ISUB = 17 + const val IMUL = 18 + const val IDIV = 19 + const val IMOD = 20 + const val INEG = 21 + const val IMIN = 22 + const val IMAX = 23 + const val FADD = 32 + const val FSUB = 33 + const val FMUL = 34 + const val FDIV = 35 + const val FNEG = 36 + const val FMIN = 37 + const val FMAX = 38 + const val I2F = 48 + const val F2I = 49 + const val TIME = 50 + const val LERP = 64 + const val SMOOTHSTEP = 65 + const val EASE_IN_QUAD = 66 + const val EASE_OUT_QUAD = 67 + const val EASE_IN_OUT_QUAD = 68 + const val EASE_IN_CUBIC = 69 + const val EASE_OUT_CUBIC = 70 + const val EASE_IN_OUT_CUBIC = 71 + + fun evaluate(reader: DrawReader, frame: DrawEvaluation): Int { + val bits = IntArray(MAX_STACK) + val floats = BooleanArray(MAX_STACK) + var size = 0 + var pending = false + fun push(value: Int, float: Boolean = false) { + require(size < MAX_STACK) + bits[size] = value + floats[size++] = float + } + fun integer(): Int { + require(size > 0 && !floats[size - 1]) + return bits[--size] + } + fun float(): Float { + require(size > 0 && floats[size - 1]) + return Float.fromBits(bits[--size]) + } + fun pushFloat(value: Float) { + require(value.isFinite()) + push(value.toBits(), true) + } + fun toInteger(value: Float): Int { + require(value.isFinite() && value >= -2147483648f && value < 2147483648f) + return value.toInt() + } + try { + require(reader.remaining <= MAX_BYTES) + while (reader.remaining > 0) { + when (val op = reader.readU8()) { + PUSH_I32 -> push(ExtendedVarint.read(reader, true)) + PUSH_F32 -> { + val value = reader.readU8() or (reader.readU8() shl 8) or + (reader.readU8() shl 16) or (reader.readU8() shl 24) + pushFloat(Float.fromBits(value)) + } + DUP -> { + require(size > 0) + push(bits[size - 1], floats[size - 1]) + } + DROP -> { require(size > 0); size-- } + SWAP -> { + require(size >= 2) + val value = bits[size - 1] + val type = floats[size - 1] + bits[size - 1] = bits[size - 2] + floats[size - 1] = floats[size - 2] + bits[size - 2] = value + floats[size - 2] = type + } + IADD, ISUB, IMUL, IDIV, IMOD, IMIN, IMAX -> { + val b = integer() + val a = integer() + push(when (op) { + IADD -> a + b + ISUB -> a - b + IMUL -> a * b + IDIV -> { require(b != 0); if (a == Int.MIN_VALUE && b == -1) a else a / b } + IMOD -> { require(b != 0); if (a == Int.MIN_VALUE && b == -1) 0 else a % b } + IMIN -> minOf(a, b) + else -> maxOf(a, b) + }) + } + INEG -> push(-integer()) + FADD, FSUB, FMUL, FDIV, FMIN, FMAX -> { + val b = float() + val a = float() + pushFloat(when (op) { + FADD -> a + b + FSUB -> a - b + FMUL -> a * b + FDIV -> { require(b != 0f); a / b } + FMIN -> minOf(a, b) + else -> maxOf(a, b) + }) + } + FNEG -> pushFloat(-float()) + I2F -> pushFloat(integer().toFloat()) + F2I -> push(toInteger(float())) + TIME -> { + val maximum = integer() + require(maximum >= 0) + val time = frame.elapsedMs.coerceIn(0, maximum.toLong()).toInt() + if (time != maximum) pending = true + push(time) + } + LERP -> { + val t = float() + val b = float() + val a = float() + pushFloat(a + (b - a) * t) + } + in SMOOTHSTEP..EASE_IN_OUT_CUBIC -> { + val t = float().coerceIn(0f, 1f) + val u = 1f - t + pushFloat(when (op) { + SMOOTHSTEP -> t * t * (3f - 2f * t) + EASE_IN_QUAD -> t * t + EASE_OUT_QUAD -> 1f - u * u + EASE_IN_OUT_QUAD -> if (t < .5f) 2f * t * t else 1f - 2f * u * u + EASE_IN_CUBIC -> t * t * t + EASE_OUT_CUBIC -> 1f - u * u * u + else -> if (t < .5f) 4f * t * t * t else 1f - 4f * u * u * u + }) + } + else -> error("Unknown expression opcode") + } + } + require(size > 0) + val result = if (floats[size - 1]) toInteger(float()) else integer() + frame.animationPending = frame.animationPending || pending + return result + } catch (_: IllegalArgumentException) { + return 0 + } catch (_: IllegalStateException) { + return 0 + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt index 3546b093..0883a49f 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt @@ -1,6 +1,6 @@ package com.faceclaw.app -/** Revision 26 wire grammar, shared by scene planning and the local renderer. */ +/** Revision 27 wire grammar, shared by scene planning and the local renderer. */ object DrawProtocol { /** Mirrors g2flash/patches/zlib_glue.c. */ const val DRAW = CFW_MSG_DRAW_CALLS @@ -18,87 +18,274 @@ object DrawProtocol { /** Mirrors g2flash/patches/display_list.c. */ const val SCREEN = 65535 const val CURRENT = 65534 + + /** Fixed-width resource/legacy fields, separate from the draw numeric codec. */ fun u16(b: ByteArray, p: Int): Int = (b[p].toInt() and 255) or ((b[p + 1].toInt() and 255) shl 8) fun word(n: Int) = byteArrayOf(n.toByte(), (n ushr 8).toByte()) + + private fun encode(write: DrawWriter.() -> Unit): ByteArray = DrawWriter().apply(write).toByteArray() + fun call(op: Int, args: ByteArray, target: Int? = null, depth: Int? = null): ByteArray { require(depth == null || depth in -128..127) - val flags = (if (target == null) 0 else DRAW_FLAG_RESOURCE_TARGET) or (if (depth == null) 0 else DRAW_FLAG_DEPTH) - return byteArrayOf(op.toByte(), flags.toByte()) + (target?.let { word(it) } ?: byteArrayOf()) + - (depth?.let { byteArrayOf(it.toByte()) } ?: byteArrayOf()) + args + val flags = (if (target == null) 0 else DRAW_FLAG_RESOURCE_TARGET) or + (if (depth == null) 0 else DRAW_FLAG_DEPTH) + return encode { + writeU8(op) + writeU8(flags) + if (target != null) writeU16(target) + if (depth != null) writeS8(depth) + writeBytes(args) + } } + + private fun call(op: Int, target: Int? = null, depth: Int? = null, write: DrawWriter.() -> Unit): ByteArray = + call(op, encode(write), target, depth) + fun depthOffset(depth: Int, right: Boolean): Int = if (right) -floorHalf(depth + 1) else floorHalf(depth) + private fun floorHalf(n: Int): Int = if (n < 0) (n - 1) / 2 else n / 2 - fun roundedRect(x: Int, y: Int, width: Int, height: Int, radius: Int, background: Int, border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null): ByteArray { - require(width in 1..640 && height in 1..480 && radius in 0..65535 && background in 0..15 && border in 0..DRAW_ROUNDED_RECT_NO_BORDER) - return call(DRAW_OP_ROUNDED_RECT, word(x) + word(y) + word(width) + word(height) + word(radius) + byteArrayOf(background.toByte(), border.toByte()), depth = depth) + + fun roundedRect( + x: Int, y: Int, width: Int, height: Int, radius: Int, background: Int, + border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null, + ): ByteArray = roundedRect(DrawValue.Integer(x), DrawValue.Integer(y), width, height, radius, background, border, depth) + + fun roundedRect( + x: DrawValue, y: DrawValue, width: Int, height: Int, radius: Int, background: Int, + border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null, + ): ByteArray { + require(width in 1..640 && height in 1..480 && radius in 0..65535) + require(background in 0..15 && border in 0..DRAW_ROUNDED_RECT_NO_BORDER) + return call(DRAW_OP_ROUNDED_RECT, depth = depth) { + writeExtended(x) + writeExtended(y) + writeU16(width) + writeU16(height) + writeU16(radius) + writeU8(background) + writeU8(border) + } } + fun sequence(calls: List): ByteArray { require(calls.size <= 4096) - val out = ByteSink(); out.write(word(calls.size)) - for (call in calls) { require(call.size <= 65535); out.write(word(call.size)); out.write(call) } - return out.toByteArray() + return encode { + writeU16(calls.size) + for (call in calls) { + require(call.size <= 65535) + writeU16(call.size) + writeBytes(call) + } + } } + fun message(calls: List) = byteArrayOf(DRAW.toByte()) + sequence(calls) fun displayList(calls: List) = byteArrayOf(LIST.toByte()) + sequence(calls) - fun root(id: Int) = byteArrayOf(ROOT.toByte()) + word(id) - fun image(id: Int, x: Int, y: Int, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK, target: Int? = null, depth: Int? = null) = - call(DRAW_OP_IMAGE, word(id) + word(x) + word(y) + byteArrayOf(options.toByte()), target, depth) + fun root(id: Int) = byteArrayOf(ROOT.toByte()) + encode { writeU16(id) } + + fun image( + id: Int, x: Int, y: Int, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK, + target: Int? = null, depth: Int? = null, + ): ByteArray = call(DRAW_OP_IMAGE, target, depth) { + writeU16(id) + writeS16(x) + writeS16(y) + writeU8(options) + } + + fun rectCopy( + source: Int, x: Int, y: Int, width: Int, height: Int, dx: Int, dy: Int, + target: Int? = null, depth: Int? = null, + ): ByteArray = call(DRAW_OP_RECT_COPY, target, depth) { + writeU16(source) + writeU16(x) + writeU16(y) + writeU16(width) + writeU16(height) + writeS16(dx) + writeS16(dy) + } + + fun stockText(x: Int, y: Int, options: Int, text: ByteArray): ByteArray { + require(text.size <= 255) + return call(DRAW_OP_STOCK_FONT_STRING) { + writeS16(x) + writeS16(y) + writeU8(options) + writeU8(text.size) + writeBytes(text) + } + } + + fun text(id: Int, x: Int, y: Int, options: Int, text: ByteArray): ByteArray { + require(text.size <= 255) + return call(DRAW_OP_TEXT) { + writeU16(id) + writeS16(x) + writeS16(y) + writeU8(options) + writeU8(text.size) + writeBytes(text) + } + } + + fun playList(id: Int, target: Int? = null, depth: Int? = null): ByteArray = + call(DRAW_OP_DISPLAY_LIST, target, depth) { writeU16(id) } + fun lut(width: Int, height: Int, factor: Int): ByteArray { val table = ByteArray(8) { i -> - (((i * 2 * factor / 256).coerceIn(0, 15) shl 4) or ((i * 2 + 1) * factor / 256).coerceIn(0, 15)).toByte() + (((i * 2 * factor / 256).coerceIn(0, 15) shl 4) or + ((i * 2 + 1) * factor / 256).coerceIn(0, 15)).toByte() + } + return call(DRAW_OP_REMAP_COLORS) { + writeU16(0) + writeU16(0) + writeU16(width) + writeU16(height) + writeBytes(table) } - return call(DRAW_OP_REMAP_COLORS, word(0) + word(0) + word(width) + word(height) + table) } + fun rawImage(width: Int, height: Int, pixels: ByteArray = ByteArray(((width + 1) / 2) * height)): ByteArray { require(width in 1..640 && height in 1..480 && pixels.size == ((width + 1) / 2) * height) val result = byteArrayOf(LARGE.toByte()) + word(width) + word(height) + pixels require(result.size <= ResourceCacheState.MAX_RESOURCE_SIZE) return result } + + private fun boundingBox( + x: Int, y: Int, width: Int, height: Int, compact: Boolean, rle: ByteArray, target: Int? = null, + ): ByteArray = call(DRAW_OP_BOUNDING_BOX, target) { + writeU8(if (compact) 0 else DRAW_BBOX_FLAG_U16) + if (compact) { + writeU8(x / 4) + writeU8(y / 2) + writeU8(width / 4) + writeU8(height / 2) + } else { + writeU16(x) + writeU16(y) + writeU16(width) + writeU16(height) + } + writeBytes(rle) + } + /** Packed rows -> RLE of exactly width*height pixels, omitting odd-row padding. */ fun bbox(packed: ByteArray, stride: Int, x: Int, y: Int, width: Int, height: Int, target: Int? = null): ByteArray { - val compact = x % 4 == 0 && y % 2 == 0 && width % 4 == 0 && height % 2 == 0 && x / 4 < 256 && y / 2 < 256 && width / 4 < 256 && height / 2 < 256 - val header = if (compact) byteArrayOf(0, (x / 4).toByte(), (y / 2).toByte(), (width / 4).toByte(), (height / 2).toByte()) - else byteArrayOf(DRAW_BBOX_FLAG_U16.toByte()) + word(x) + word(y) + word(width) + word(height) - val out = ByteSink(); out.write(header) - var color = -1; var count = 0 + val compact = x % 4 == 0 && y % 2 == 0 && width % 4 == 0 && height % 2 == 0 && + x / 4 < 256 && y / 2 < 256 && width / 4 < 256 && height / 2 < 256 + // Pixel RLE is an opaque byte block, with its own fixed-width run lengths. + val out = ByteSink() + var color = -1 + var count = 0 fun flush() { if (count == 0) return - if (count <= 15) out.write((count shl 4) or color) - else { out.write(color); if (count <= 255) out.write(count) else { out.write(0); out.write(word(count)) } } + if (count <= 15) { + out.write((count shl 4) or color) + } else { + out.write(color) + if (count <= 255) { + out.write(count) + } else { + out.write(0) + out.write(word(count)) + } + } } for (yy in y until y + height) for (xx in x until x + width) { - val value = (packed[yy * stride + xx / 2].toInt() ushr (if (xx % 2 == 0) 4 else 0)) and 15 - if (value != color || count == 65535) { flush(); color = value; count = 0 } + val shift = if (xx % 2 == 0) 4 else 0 + val value = (packed[yy * stride + xx / 2].toInt() ushr shift) and 15 + if (value != color || count == 65535) { + flush() + color = value + count = 0 + } count++ } flush() - return call(DRAW_OP_BOUNDING_BOX, out.toByteArray(), target) + return boundingBox(x, y, width, height, compact, out.toByteArray(), target) } - /** Internal optimizer formats are translated here; they are never sent to revision 26. */ + + /** + * Optimizer records retain their internal fixed-width format. Decode their + * numeric fields here so every outgoing draw field goes through DrawWriter. + */ fun fromOptimized(payload: ByteArray, width: Int = 640, height: Int = 480): List { - return when (val mode = payload[0].toInt() and CFW_MSG_TYPE_MASK) { + val reader = ArrayByteReader(payload) + fun u8() = reader.get().toInt() and 255 + fun u16() = reader.getShort().toInt() and 65535 + fun s16() = reader.getShort().toInt() + fun bytes(count: Int): ByteArray = ByteArray(count).also { reader.get(it) } + val result = when (val mode = u8() and CFW_MSG_TYPE_MASK) { CFW_MSG_MULTI_SEGMENT -> { - val result = ArrayList(); var pos = 2 - repeat(payload[1].toInt() and 255) { val n = u16(payload, pos); pos += 2; result.addAll(fromOptimized(payload.copyOfRange(pos, pos + n), width, height)); pos += n } - require(pos == payload.size); result + val calls = ArrayList() + repeat(u8()) { + calls.addAll(fromOptimized(bytes(u16()), width, height)) + } + calls + } + CFW_MSG_BOUNDING_BOX -> { + val x = u8() * 4 + val y = u8() * 2 + val w = u8() * 4 + val h = u8() * 2 + u16() // Frame ID belongs only to the optimizer record. + listOf(boundingBox(x, y, w, h, true, bytes(reader.remaining()))) + } + CFW_MSG_FULL_FRAME -> listOf(boundingBox(0, 0, width, height, false, bytes(reader.remaining()))) + CFW_MSG_STOCK_FONT_STRING -> { + val x = s16() + val y = s16() + val options = u8() + listOf(stockText(x, y, options, bytes(u8()))) + } + CFW_MSG_CACHED_IMAGE -> { + val id = u16() + val x = s16() + val y = s16() + val options = u8() + listOf(image(id, x, y, options)) + } + CFW_MSG_CACHED_TEXT -> { + val id = u16() + val x = s16() + val y = s16() + val options = u8() + listOf(text(id, x, y, options, bytes(u8()))) + } + CFW_MSG_RECT_COPY -> { + val x = u16() + val y = u16() + val w = u16() + val h = u16() + val dx = s16() + val dy = s16() + listOf(rectCopy(CURRENT, x, y, w, h, dx, dy)) } - CFW_MSG_BOUNDING_BOX -> listOf(call(DRAW_OP_BOUNDING_BOX, byteArrayOf(0) + payload.copyOfRange(1, 5) + payload.copyOfRange(7, payload.size))) - CFW_MSG_FULL_FRAME -> listOf(call(DRAW_OP_BOUNDING_BOX, byteArrayOf(DRAW_BBOX_FLAG_U16.toByte()) + word(0) + word(0) + word(width) + word(height) + payload.copyOfRange(1, payload.size))) - CFW_MSG_STOCK_FONT_STRING -> listOf(call(DRAW_OP_STOCK_FONT_STRING, payload.copyOfRange(1, payload.size))) - CFW_MSG_CACHED_IMAGE -> listOf(call(DRAW_OP_IMAGE, payload.copyOfRange(1, payload.size))) - CFW_MSG_CACHED_TEXT -> listOf(call(DRAW_OP_TEXT, payload.copyOfRange(1, payload.size))) - CFW_MSG_RECT_COPY -> listOf(call(DRAW_OP_RECT_COPY, word(CURRENT) + payload.copyOfRange(1, 9) + payload.copyOfRange(9, 13))) else -> error("Unsupported internal draw format $mode") } + require(reader.remaining() == 0) + return result } + fun messages(calls: List, maxBytes: Int = 65535): List { - val result = ArrayList(); var batch = ArrayList(); var size = 3 + fun headerSize(count: Int) = 1 + encode { writeU16(count) }.size + val result = ArrayList() + var batch = ArrayList() + var bodySize = 0 for (call in calls) { - require(call.size + 5 <= maxBytes) - if (size + 2 + call.size > maxBytes) { result.add(message(batch)); batch = ArrayList(); size = 3 } - batch.add(call); size += call.size + 2 + require(call.size <= 65535) + val framedSize = encode { writeU16(call.size) }.size + call.size + require(headerSize(1) + framedSize <= maxBytes) + if (headerSize(batch.size + 1) + bodySize + framedSize > maxBytes || batch.size == 4096) { + result.add(message(batch)) + batch = ArrayList() + bodySize = 0 + } + batch.add(call) + bodySize += framedSize } if (batch.isNotEmpty()) result.add(message(batch)) return result diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawWire.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawWire.kt new file mode 100644 index 00000000..7068e27d --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawWire.kt @@ -0,0 +1,68 @@ +package com.faceclaw.app + +/** + * Numeric fields in the draw grammar go through this codec. Most fields still + * uses fixed-width little-endian values; rounded-rectangle x/y use extended varints and expressions. Byte blocks + * (RLE, text, LUTs and already-encoded calls) retain their own formats. + */ +internal class DrawReader( + private val bytes: ByteArray, + start: Int = 0, + private val end: Int = bytes.size, +) { + var position: Int = start + private set + val remaining: Int get() = end - position + + init { + require(start >= 0 && start <= end && end <= bytes.size) + } + + fun readU8(): Int { + require(remaining >= 1) { "Truncated draw field" } + return bytes[position++].toInt() and 255 + } + + fun readS8(): Int = readU8().toByte().toInt() + + fun readU16(): Int { + val low = readU8() + return low or (readU8() shl 8) + } + + fun readS16(): Int = readU16().toShort().toInt() + + fun readBytes(count: Int): ByteArray { + require(count >= 0 && count <= remaining) { "Truncated draw data" } + val result = bytes.copyOfRange(position, position + count) + position += count + return result + } + + /** A bounded view prevents a truncated call from consuming the next call. */ + fun readSlice(count: Int): DrawReader { + require(count >= 0 && count <= remaining) { "Truncated draw call" } + val result = DrawReader(bytes, position, position + count) + position += count + return result + } + + fun requireDone() { + require(remaining == 0) { "Trailing draw data" } + } +} + +internal class DrawWriter { + private val out = ByteSink() + + fun writeU8(value: Int) = out.write(value) + fun writeS8(value: Int) = out.write(value) + fun writeU16(value: Int) { + out.write(value) + out.write(value ushr 8) + } + fun writeS16(value: Int) = writeU16(value) + fun writeBytes(value: ByteArray) = out.write(value) + fun writeExtended(value: DrawValue) = out.write(ExtendedVarint.write(value)) + fun toByteArray(): ByteArray = out.toByteArray() +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListPlayer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListPlayer.kt new file mode 100644 index 00000000..0a1b23fb --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListPlayer.kt @@ -0,0 +1,42 @@ +package com.faceclaw.app + +/** + * PRESENT resets the clock; timer redraws preserve it. The owner serializes + * calls and supplies a cancellable 45 ms scheduler on its rendering thread. + */ +class DisplayListPlayer( + private val renderer: DisplayListRenderer, + private val screen: DisplayListRenderer.Target, + private val composition: DisplayListRenderer.Target, + private val clock: () -> Long, + private val schedule: (Int, () -> Unit) -> (() -> Unit), + private val displayed: () -> Unit, +) { + private var root = DrawProtocol.SCREEN + private var origin = 0L + private var generation = 0 + private var cancel: (() -> Unit)? = null + + fun present(root: Int) { + stop() + this.root = root + origin = clock() + draw(generation) + } + + fun stop() { + generation++ + cancel?.invoke() + cancel = null + } + + private fun draw(token: Int) { + if (token != generation) return + cancel = null + renderer.render(root, screen, composition, (clock() - origin).coerceAtLeast(0)) + displayed() + if (token == generation && renderer.animationPending) { + cancel = schedule(45) { draw(token) } + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt index 2166d3a5..5e386ee2 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt @@ -1,68 +1,132 @@ package com.faceclaw.app /** Reference interpreter. It uses the firmware's packed rows, clipping, LUT and call grammar. */ -class DisplayListRenderer(private val resources: Map, private val builtin: ((Int, Int) -> BuiltinGlyph)? = null, private val rightLens: Boolean = false) { +class DisplayListRenderer( + private val resources: Map, + private val builtin: ((Int, Int) -> BuiltinGlyph)? = null, + private val rightLens: Boolean = false, +) { class BuiltinGlyph(val image: ByteArray, val advance: Int, val x: Int = 0, val y: Int = 0) - class Target(val bytes: ByteArray, val width: Int, val height: Int, val offset: Int = 0, val shiftX: Int = 0) { + + class Target( + val bytes: ByteArray, + val width: Int, + val height: Int, + val offset: Int = 0, + val shiftX: Int = 0, + ) { val stride = (width + 1) / 2 - init { require(width > 0 && height > 0 && offset >= 0 && bytes.size - offset >= stride * height) } - fun get(x: Int, y: Int) = (bytes[offset + y * stride + x / 2].toInt() ushr (if (x % 2 == 0) 4 else 0)) and 15 + + init { + require(width > 0 && height > 0 && offset >= 0 && bytes.size - offset >= stride * height) + } + + fun get(x: Int, y: Int): Int { + val shift = if (x % 2 == 0) 4 else 0 + return (bytes[offset + y * stride + x / 2].toInt() ushr shift) and 15 + } + fun shifted(dx: Int) = Target(bytes, width, height, offset, shiftX + dx) - fun put(localX: Int, y: Int, v: Int) { + + fun put(localX: Int, y: Int, value: Int) { val x = localX + shiftX if (x !in 0 until width || y !in 0 until height) return - val index = offset + y * stride + x / 2; val old = bytes[index].toInt() - bytes[index] = (if (x % 2 == 0) (old and 15) or (v shl 4) else (old and 240) or v).toByte() + val index = offset + y * stride + x / 2 + val old = bytes[index].toInt() + bytes[index] = if (x % 2 == 0) { + ((old and 15) or (value shl 4)).toByte() + } else { + ((old and 240) or value).toByte() + } } } - private fun roundedContains(x: Int, y: Int, w: Int, h: Int, radius: Int): Boolean { - if (x !in 0 until w || y !in 0 until h) return false - val r = minOf(radius, w / 2, h / 2) - val dx = maxOf(0, 2 * r - (2 * minOf(x, w - 1 - x) + 1)) - val dy = maxOf(0, 2 * r - (2 * minOf(y, h - 1 - y) + 1)) - return dx * dx + dy * dy <= 4 * r * r + + /** Shared by nested calls, and reset between validation and drawing. */ + var animationPending: Boolean = false + private set + + private class Walk(val screen: Target, val apply: Boolean, val references: MutableSet, val frame: DrawEvaluation) { + val ancestors = mutableListOf() + var remainingCalls = 4096 } + private class Image(val width: Int, val height: Int, val pixels: IntArray) - private fun word(b: ByteArray, p: Int): Int { require(p >= 0 && p + 2 <= b.size); return DrawProtocol.u16(b, p) } - private fun signed(b: ByteArray, p: Int) = word(b, p).toShort().toInt() + private fun resource(id: Int) = requireNotNull(resources[id]) { "Missing resource $id" } - private fun decodeRle(b: ByteArray, start: Int, count: Int, exact: Boolean): IntArray { - var p = start; var i = 0; val result = IntArray(count) - while (i < count) { - require(p < b.size); val token = b[p++].toInt() and 255; var n = token ushr 4 - if (n == 0) { require(p < b.size); n = b[p++].toInt() and 255 - if (n == 0) { n = word(b, p); p += 2 } } - require(n > 0 && n <= count - i); result.fill(token and 15, i, i + n); i += n + + // Resource headers, font offsets and RLE have their own fixed-width grammar; + // they do not use the draw-call numeric codec. + private fun readU8(reader: ByteReader): Int = reader.get().toInt() and 255 + private fun readU16(reader: ByteReader): Int = reader.getShort().toInt() and 65535 + + private fun decodeRle(reader: ByteReader, count: Int, exact: Boolean): IntArray { + val pixels = IntArray(count) + var index = 0 + while (index < count) { + val token = readU8(reader) + var run = token ushr 4 + if (run == 0) { + run = readU8(reader) + if (run == 0) run = readU16(reader) + } + require(run > 0 && run <= count - index) + pixels.fill(token and 15, index, index + run) + index += run } - require(!exact || p == b.size) - return result + require(!exact || reader.remaining() == 0) + return pixels } - private fun image(b: ByteArray, start: Int = 0): Image { - require(start in b.indices); val flags = b[start].toInt() and 255 + + private fun image(bytes: ByteArray, start: Int = 0): Image { + require(start in bytes.indices) + val reader = ArrayByteReader(bytes, start) + val flags = readU8(reader) require(flags and CFW_RESOURCE_IMAGE_FLAGS_MASK == flags) - val header = if (flags and CFW_RESOURCE_FLAG_LARGE != 0) 5 else 3 - require(b.size - start >= header) - val w = if (header == 5) word(b, start + 1) else b[start + 1].toInt() and 255 - val h = if (header == 5) word(b, start + 3) else b[start + 2].toInt() and 255 - require(w in 1..640 && h in 1..480) - val pixels = if (flags and CFW_RESOURCE_FLAG_RLE != 0) decodeRle(b, start + header, w * h, false) - else { val t = Target(b, w, h, start + header); IntArray(w * h) { t.get(it % w, it / w) } } - return Image(w, h, pixels) + val large = flags and CFW_RESOURCE_FLAG_LARGE != 0 + val width = if (large) readU16(reader) else readU8(reader) + val height = if (large) readU16(reader) else readU8(reader) + require(width in 1..640 && height in 1..480) + val pixels = if (flags and CFW_RESOURCE_FLAG_RLE != 0) { + decodeRle(reader, width * height, false) + } else { + val offset = bytes.size - reader.remaining() + val target = Target(bytes, width, height, offset) + IntArray(width * height) { target.get(it % width, it / width) } + } + return Image(width, height, pixels) } + private fun target(id: Int): Target { - val b = resource(id); require(b.isNotEmpty() && b[0].toInt() and (CFW_RESOURCE_TYPE_MASK or CFW_RESOURCE_FLAG_RLE) == 0) - image(b) // Validate the complete raw image before exposing a write target. - return if (b[0].toInt() and CFW_RESOURCE_FLAG_LARGE != 0) Target(b, word(b, 1), word(b, 3), 5) - else Target(b, b[1].toInt() and 255, b[2].toInt() and 255, 3) + val bytes = resource(id) + val reader = ArrayByteReader(bytes) + val flags = readU8(reader) + require(flags and (CFW_RESOURCE_TYPE_MASK or CFW_RESOURCE_FLAG_RLE) == 0) + image(bytes) // Validate the complete raw image before exposing a write target. + val large = flags and CFW_RESOURCE_FLAG_LARGE != 0 + val width = if (large) readU16(reader) else readU8(reader) + val height = if (large) readU16(reader) else readU8(reader) + return Target(bytes, width, height, bytes.size - reader.remaining()) } + private fun draw(image: Image, target: Target, x: Int, y: Int, options: Int, apply: Boolean) { if (!apply) return for (i in image.pixels.indices) { - val v = image.pixels[i]; if (v == 0 && options and CFW_TEXTURE_OPT_TRANSPARENT != 0) continue - val source = if (options and CFW_TEXTURE_OPT_INVERSE != 0) 15 - v else v - target.put(x + i % image.width, y + i / image.width, source * (options and CFW_TEXTURE_OPT_BRIGHTNESS_MASK) / 15) + val value = image.pixels[i] + if (value == 0 && options and CFW_TEXTURE_OPT_TRANSPARENT != 0) continue + val source = if (options and CFW_TEXTURE_OPT_INVERSE != 0) 15 - value else value + val brightness = source * (options and CFW_TEXTURE_OPT_BRIGHTNESS_MASK) / 15 + target.put(x + i % image.width, y + i / image.width, brightness) } } + + private fun roundedContains(x: Int, y: Int, width: Int, height: Int, radius: Int): Boolean { + if (x !in 0 until width || y !in 0 until height) return false + val r = minOf(radius, width / 2, height / 2) + val dx = maxOf(0, 2 * r - (2 * minOf(x, width - 1 - x) + 1)) + val dy = maxOf(0, 2 * r - (2 * minOf(y, height - 1 - y) + 1)) + return dx * dx + dy * dy <= 4 * r * r + } + private fun copyScreen(screen: Target, composition: Target) { val source = screen.bytes val destination = composition.bytes @@ -93,107 +157,230 @@ class DisplayListRenderer(private val resources: Map, private va dst += destinationStride } } + /** Validate the whole graph before changing any pixels. Resource writes remain call-scoped. */ - fun render(root: Int, screen: Target, composition: Target): Set { + fun render(root: Int, screen: Target, composition: Target, elapsedMs: Long = 0): Set { + animationPending = false + val frame = DrawEvaluation(elapsedMs) val references = mutableSetOf() for (apply in listOf(false, true)) { if (apply) copyScreen(screen, composition) - if (root != DrawProtocol.SCREEN) executeList(root, composition, screen, apply, mutableListOf(), intArrayOf(4096), references) - } - return references - } - fun execute(sequence: ByteArray, target: Target, screen: Target = target): Set { - val references = mutableSetOf() - for (apply in listOf(false, true)) executeSequence(sequence, target, screen, apply, mutableListOf(), intArrayOf(4096), references) - return references - } - private fun executeList(id: Int, t: Target, screen: Target, apply: Boolean, stack: MutableList, budget: IntArray, refs: MutableSet) { - require(stack.size < 8 && id !in stack); val b = resource(id); require(b.size >= 3 && b[0].toInt() == CFW_RESOURCE_TYPE_DISPLAY_LIST) - refs.add(id); stack.add(id); executeSequence(b.copyOfRange(1, b.size), t, screen, apply, stack, budget, refs); stack.removeAt(stack.lastIndex) - } - private fun executeSequence(b: ByteArray, inherited: Target, screen: Target, apply: Boolean, stack: MutableList, budget: IntArray, refs: MutableSet) { - val count = word(b, 0); var pos = 2 - repeat(count) { - val n = word(b, pos); pos += 2; require(n >= 2 && n <= b.size - pos && budget[0]-- > 0) - val call = b.copyOfRange(pos, pos + n); pos += n - val flags = call[1].toInt() and 255; require(flags and DRAW_FLAGS_MASK.inv() == 0) - var t = inherited; var header = 2 - if (flags and DRAW_FLAG_RESOURCE_TARGET != 0) { val id = word(call, 2); refs.add(id); t = target(id).shifted(inherited.shiftX); header += 2 } - if (flags and DRAW_FLAG_DEPTH != 0) { require(header < call.size); t = t.shifted(DrawProtocol.depthOffset(call[header++].toInt(), rightLens)) } - val p = call.copyOfRange(header, call.size) - when (call[0].toInt()) { - DRAW_OP_BOUNDING_BOX -> { - require(p.isNotEmpty() && (p[0].toInt() and 255) and DRAW_BBOX_FLAG_U16.inv() == 0); val wide = p[0].toInt() and DRAW_BBOX_FLAG_U16 != 0 - require(p.size >= if (wide) 9 else 5) - val x = if (wide) word(p, 1) else (p[1].toInt() and 255) * 4 - val y = if (wide) word(p, 3) else (p[2].toInt() and 255) * 2 - val w = if (wide) word(p, 5) else (p[3].toInt() and 255) * 4 - val h = if (wide) word(p, 7) else (p[4].toInt() and 255) * 2 - require(w > 0 && h > 0 && x + w <= t.width && y + h <= t.height) - val pixels = decodeRle(p, if (wide) 9 else 5, w * h, true) - if (apply) for (i in pixels.indices) t.put(x + i % w, y + i / w, pixels[i]) - } - DRAW_OP_RECT_COPY -> { - require(p.size == 14); val id = word(p, 0) - val src = when(id) { DrawProtocol.SCREEN -> screen; DrawProtocol.CURRENT -> t; else -> { refs.add(id); target(id) } } - val x = word(p, 2); val y = word(p, 4); val w = word(p, 6); val h = word(p, 8) - require(w > 0 && h > 0 && x + w <= src.width && y + h <= src.height) - val dx = signed(p, 10); val dy = signed(p, 12) - if (apply) { val copy = IntArray(w * h) { src.get(x + it % w, y + it / w) } - for (i in copy.indices) t.put(dx + i % w, dy + i / w, copy[i]) } - } - DRAW_OP_STOCK_FONT_STRING -> { - require(p.size >= 6 && p.size == 6 + (p[5].toInt() and 255)) - val text = p.copyOfRange(6, p.size).decodeToString(throwOnInvalidSequence = true) - val cps = ArrayList(); var i = 0 - while (i < text.length) { val c = text[i++].code - cps.add(if (c in 0xd800..0xdbff) { require(i < text.length); 0x10000 + ((c - 0xd800) shl 10) + text[i++].code - 0xdc00 } else c) } - var x = signed(p, 0); val y = signed(p, 2) - for (j in cps.indices) { val cp = cps[j] - if (cp in 1..31) { x += cp - 11; continue } - val next = cps.drop(j + 1).firstOrNull { it !in 1..31 } ?: 0 - val g = requireNotNull(builtin) { "Builtin font provider required" }(cp, next) - draw(image(g.image), t, x + g.x, y + g.y, p[4].toInt() and 255, apply); x += g.advance - } - } - DRAW_OP_IMAGE, DRAW_OP_TEXT -> { - val font = call[0].toInt() == DRAW_OP_TEXT; require(if(font) p.size >= 8 && p.size == 8 + (p[7].toInt() and 255) else p.size == 7) - val id = word(p, 0); refs.add(id); val data = resource(id) - var x = signed(p, 2); val y = signed(p, 4); val options = p[6].toInt() and 255 - if (!font) draw(image(data), t, x, y, options, apply) - else { require(data.size >= 193 && data[0].toInt() == CFW_RESOURCE_TYPE_FONT) - for (j in 8 until p.size) { val ch = p[j].toInt() and 255 - if(ch in 1..31) { x += ch - 11; continue }; require(ch in 32..127) - val offset = word(data, 1 + (ch - 32) * 2); require(offset >= 193) - val glyph = image(data, offset); draw(glyph, t, x, y, options, apply); x += glyph.width - } - } - } - DRAW_OP_REMAP_COLORS -> { - require(p.size == 16); val x = word(p, 0); val y = word(p, 2); val w = word(p, 4); val h = word(p, 6) - require(w > 0 && h > 0 && x + w <= t.width && y + h <= t.height) - if (apply) for(yy in y until y + h) for(xx in x until x + w) { - if (xx + t.shiftX !in 0 until t.width) continue - val v = t.get(xx + t.shiftX, yy) - t.put(xx, yy, (p[8 + v / 2].toInt() ushr (if(v % 2 == 0) 4 else 0)) and 15) } - } - DRAW_OP_ROUNDED_RECT -> { - require(p.size == 12) - val x = signed(p, 0); val y = signed(p, 2); val w = word(p, 4); val h = word(p, 6) - val radius = word(p, 8); val fill = p[10].toInt() and 255; val border = p[11].toInt() and 255 - require(w in 1..640 && h in 1..480 && fill <= 15 && border <= DRAW_ROUNDED_RECT_NO_BORDER) - if (apply) for (yy in 0 until h) for (xx in 0 until w) { - if (!roundedContains(xx, yy, w, h, radius)) continue - val tx = x + xx + t.shiftX; val ty = y + yy - if (tx !in 0 until t.width || ty !in 0 until t.height) continue - val edge = !roundedContains(xx - 1, yy - 1, w - 2, h - 2, maxOf(0, radius - 1)) - t.put(x + xx, ty, if (edge && border < DRAW_ROUNDED_RECT_NO_BORDER) border else maxOf(fill, t.get(tx, ty))) - } - } - DRAW_OP_DISPLAY_LIST -> { require(p.size == 2); executeList(word(p, 0), t, screen, apply, stack, budget, refs) } - else -> error("Unknown draw opcode") + if (root != DrawProtocol.SCREEN) { + executeList(root, composition, Walk(screen, apply, references, frame)) } } - require(pos == b.size) + animationPending = frame.animationPending + return references + } + + fun execute(sequence: ByteArray, target: Target, screen: Target = target, elapsedMs: Long = 0): Set { + animationPending = false + val frame = DrawEvaluation(elapsedMs) + val references = mutableSetOf() + for (apply in listOf(false, true)) { + executeSequence(DrawReader(sequence), target, Walk(screen, apply, references, frame)) + } + animationPending = frame.animationPending + return references + } + + private fun executeList(id: Int, target: Target, walk: Walk) { + require(walk.ancestors.size < 8 && id !in walk.ancestors) + val bytes = resource(id) + require(bytes.size >= 3 && bytes[0].toInt() == CFW_RESOURCE_TYPE_DISPLAY_LIST) + walk.references.add(id) + walk.ancestors.add(id) + executeSequence(DrawReader(bytes, start = 1), target, walk) + walk.ancestors.removeAt(walk.ancestors.lastIndex) + } + + private fun executeSequence(reader: DrawReader, inherited: Target, walk: Walk) { + val count = reader.readU16() + repeat(count) { + val length = reader.readU16() + require(walk.remainingCalls > 0) + walk.remainingCalls-- + executeCall(reader.readSlice(length), inherited, walk) + } + reader.requireDone() + } + + private fun executeCall(reader: DrawReader, inherited: Target, walk: Walk) { + val opcode = reader.readU8() + val flags = reader.readU8() + require(flags and DRAW_FLAGS_MASK.inv() == 0) + var target = inherited + if (flags and DRAW_FLAG_RESOURCE_TARGET != 0) { + val id = reader.readU16() + walk.references.add(id) + target = target(id).shifted(inherited.shiftX) + } + if (flags and DRAW_FLAG_DEPTH != 0) { + target = target.shifted(DrawProtocol.depthOffset(reader.readS8(), rightLens)) + } + when (opcode) { + DRAW_OP_BOUNDING_BOX -> drawBoundingBox(reader, target, walk) + DRAW_OP_RECT_COPY -> drawRectCopy(reader, target, walk) + DRAW_OP_STOCK_FONT_STRING -> drawStockText(reader, target, walk) + DRAW_OP_IMAGE -> drawImage(reader, target, walk) + DRAW_OP_TEXT -> drawText(reader, target, walk) + DRAW_OP_REMAP_COLORS -> remapColors(reader, target, walk) + DRAW_OP_ROUNDED_RECT -> drawRoundedRect(reader, target, walk) + DRAW_OP_DISPLAY_LIST -> { + val id = reader.readU16() + reader.requireDone() + executeList(id, target, walk) + } + else -> error("Unknown draw opcode $opcode") + } + } + + private fun drawBoundingBox(reader: DrawReader, target: Target, walk: Walk) { + val flags = reader.readU8() + require(flags and DRAW_BBOX_FLAG_U16.inv() == 0) + val wide = flags and DRAW_BBOX_FLAG_U16 != 0 + val x = if (wide) reader.readU16() else reader.readU8() * 4 + val y = if (wide) reader.readU16() else reader.readU8() * 2 + val width = if (wide) reader.readU16() else reader.readU8() * 4 + val height = if (wide) reader.readU16() else reader.readU8() * 2 + require(width > 0 && height > 0 && x + width <= target.width && y + height <= target.height) + val rle = ArrayByteReader(reader.readBytes(reader.remaining)) + val pixels = decodeRle(rle, width * height, true) + if (walk.apply) { + for (i in pixels.indices) target.put(x + i % width, y + i / width, pixels[i]) + } + } + + private fun drawRectCopy(reader: DrawReader, target: Target, walk: Walk) { + val id = reader.readU16() + val x = reader.readU16() + val y = reader.readU16() + val width = reader.readU16() + val height = reader.readU16() + val dx = reader.readS16() + val dy = reader.readS16() + reader.requireDone() + val source = when (id) { + DrawProtocol.SCREEN -> walk.screen + DrawProtocol.CURRENT -> target + else -> { + walk.references.add(id) + target(id) + } + } + require(width > 0 && height > 0 && x + width <= source.width && y + height <= source.height) + if (walk.apply) { + // Snapshot the rectangle so overlapping copies have memmove semantics. + val copy = IntArray(width * height) { source.get(x + it % width, y + it / width) } + for (i in copy.indices) target.put(dx + i % width, dy + i / width, copy[i]) + } + } + + private fun drawStockText(reader: DrawReader, target: Target, walk: Walk) { + var x = reader.readS16() + val y = reader.readS16() + val options = reader.readU8() + val bytes = reader.readBytes(reader.readU8()) + reader.requireDone() + val text = bytes.decodeToString(throwOnInvalidSequence = true) + val codePoints = ArrayList() + var index = 0 + while (index < text.length) { + val char = text[index++].code + val codePoint = if (char in 0xd800..0xdbff) { + require(index < text.length) + 0x10000 + ((char - 0xd800) shl 10) + text[index++].code - 0xdc00 + } else { + char + } + codePoints.add(codePoint) + } + for (i in codePoints.indices) { + val codePoint = codePoints[i] + if (codePoint in 1..31) { + x += codePoint - 11 + continue + } + val next = codePoints.drop(i + 1).firstOrNull { it !in 1..31 } ?: 0 + val glyph = requireNotNull(builtin) { "Builtin font provider required" }(codePoint, next) + draw(image(glyph.image), target, x + glyph.x, y + glyph.y, options, walk.apply) + x += glyph.advance + } + } + + private fun drawImage(reader: DrawReader, target: Target, walk: Walk) { + val id = reader.readU16() + val x = reader.readS16() + val y = reader.readS16() + val options = reader.readU8() + reader.requireDone() + walk.references.add(id) + draw(image(resource(id)), target, x, y, options, walk.apply) + } + + private fun drawText(reader: DrawReader, target: Target, walk: Walk) { + val id = reader.readU16() + var x = reader.readS16() + val y = reader.readS16() + val options = reader.readU8() + val text = reader.readBytes(reader.readU8()) + reader.requireDone() + walk.references.add(id) + val data = resource(id) + require(data.size >= 193 && data[0].toInt() == CFW_RESOURCE_TYPE_FONT) + for (byte in text) { + val char = byte.toInt() and 255 + if (char in 1..31) { + x += char - 11 + continue + } + require(char in 32..127) + val offset = DrawProtocol.u16(data, 1 + (char - 32) * 2) + require(offset >= 193) + val glyph = image(data, offset) + draw(glyph, target, x, y, options, walk.apply) + x += glyph.width + } + } + + private fun remapColors(reader: DrawReader, target: Target, walk: Walk) { + val x = reader.readU16() + val y = reader.readU16() + val width = reader.readU16() + val height = reader.readU16() + val table = reader.readBytes(8) + reader.requireDone() + require(width > 0 && height > 0 && x + width <= target.width && y + height <= target.height) + if (!walk.apply) return + for (yy in y until y + height) for (xx in x until x + width) { + if (xx + target.shiftX !in 0 until target.width) continue + val value = target.get(xx + target.shiftX, yy) + val shift = if (value % 2 == 0) 4 else 0 + target.put(xx, yy, (table[value / 2].toInt() ushr shift) and 15) + } + } + + private fun drawRoundedRect(reader: DrawReader, target: Target, walk: Walk) { + val x = ExtendedVarint.evaluate(reader, walk.frame) + val y = ExtendedVarint.evaluate(reader, walk.frame) + val width = reader.readU16() + val height = reader.readU16() + val radius = reader.readU16() + val fill = reader.readU8() + val border = reader.readU8() + reader.requireDone() + require(width in 1..640 && height in 1..480 && fill <= 15 && border <= DRAW_ROUNDED_RECT_NO_BORDER) + if (!walk.apply) return + if (x < -width - target.shiftX || x >= target.width - target.shiftX || + y < -height || y >= target.height) return + for (yy in 0 until height) for (xx in 0 until width) { + if (!roundedContains(xx, yy, width, height, radius)) continue + val tx = x + xx + target.shiftX + val ty = y + yy + if (tx !in 0 until target.width || ty !in 0 until target.height) continue + val edge = !roundedContains(xx - 1, yy - 1, width - 2, height - 2, maxOf(0, radius - 1)) + val value = if (edge && border < DRAW_ROUNDED_RECT_NO_BORDER) border else maxOf(fill, target.get(tx, ty)) + target.put(x + xx, ty, value) + } } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.kt new file mode 100644 index 00000000..ee21f65a --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.kt @@ -0,0 +1,7 @@ +package com.faceclaw.app + +/** One-shot scheduler; the owner acquires its rendering lock in [action]. */ +internal expect fun scheduleDrawRedraw(delayMs: Int, action: () -> Unit): () -> Unit + +private val drawTimeOrigin = kotlin.time.TimeSource.Monotonic.markNow() +internal fun drawAnimationTimeMs(): Long = drawTimeOrigin.elapsedNow().inWholeMilliseconds diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt index 5a6c3e6b..2f9915b5 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt @@ -2,28 +2,36 @@ package com.faceclaw.app /** A retained selection or image, replayed at stereo depth over the screen and shell surfaces. */ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val radius: Int, - val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = 3, val mask: List = emptyList()) { + val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = 3, val mask: List = emptyList(), val animation: Animation? = null) { + class Animation(val dx: Int, val dy: Int, val startedAt: Long, val token: Int) val resource = CachedResource(DrawProtocol.rawImage(width, height, packed)) - val fingerprint = "$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" - fun translated(dx: Int, dy: Int) = MenuSelection(x + dx, y + dy, width, height, radius, background, border, depth, packed, occlusions.map { intArrayOf(it[0] + dx, it[1] + dy, it[2], it[3]) }, kind, mask) - fun calls(id: Int): List { + val fingerprint = "${animation?.token},${animation?.dx},${animation?.dy},$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" + fun translated(dx: Int, dy: Int) = MenuSelection(x + dx, y + dy, width, height, radius, background, border, depth, packed, occlusions.map { intArrayOf(it[0] + dx, it[1] + dy, it[2], it[3]) }, kind, mask, animation) + fun calls(id: Int, nowMs: Long = drawAnimationTimeMs()): List { + val elapsed = animation?.let { (nowMs - it.startedAt).coerceIn(0, 500).toInt() } ?: 500 + val highlightX = animation?.let { DrawValue.animate(x + it.dx, x, 500, elapsed) } ?: DrawValue.Integer(x) + val highlightY = animation?.let { DrawValue.animate(y + it.dy, y, 500, elapsed) } ?: DrawValue.Integer(y) val image = when (kind) { - 3 -> listOf(DrawProtocol.roundedRect(x, y, width, height, radius, background, border, depth), + 3 -> listOf(DrawProtocol.roundedRect(highlightX, highlightY, width, height, radius, background, border, depth), DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) 4 -> listOf(DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) // Gray8 zero is transparent but gray8 one is opaque black. Rect copies preserve // that distinction after packing, including the transparent corners of app menus. - 5 -> mask.map { r -> DrawProtocol.call(DRAW_OP_RECT_COPY, DrawProtocol.word(id) + - r.flatMap { DrawProtocol.word(it).toList() }.toByteArray() + - DrawProtocol.word(x + r[0]) + DrawProtocol.word(y + r[1]), depth = depth) } + 5 -> mask.map { rect -> + DrawProtocol.rectCopy(id, rect[0], rect[1], rect[2], rect[3], + x + rect[0], y + rect[1], depth = depth) + } else -> error("Invalid presentation kind") } - return image + occlusions.map { r -> DrawProtocol.call(DRAW_OP_RECT_COPY, DrawProtocol.word(DrawProtocol.SCREEN) + r.flatMap { DrawProtocol.word(it).toList() }.toByteArray() + DrawProtocol.word(r[0]) + DrawProtocol.word(r[1])) } + return image + occlusions.map { rect -> + DrawProtocol.rectCopy(DrawProtocol.SCREEN, rect[0], rect[1], rect[2], rect[3], rect[0], rect[1]) + } } + companion object { - /** The caller has consumed the presentation tag (3, 4 or 5). Colors cross the bridge in gray8, pixels in gray8 rows. */ + /** The caller has consumed the presentation tag (3–6). Colors cross the bridge in gray8, pixels in gray8 rows. */ fun read(reader: ByteReader, kind: Int = 3): MenuSelection { - require(kind in 3..5) + require(kind in 3..6) require(reader.remaining() >= 15) val x = reader.getShort().toInt(); val y = reader.getShort().toInt() val w = reader.getShort().toInt() and 65535; val h = reader.getShort().toInt() and 65535 @@ -34,6 +42,14 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val val count = reader.getShort().toInt() and 65535 require(count <= 2048) require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) + val animation = if (kind == 6) { + require(reader.remaining() >= 10) + val dx = reader.getShort().toInt() + val dy = reader.getShort().toInt() + val elapsed = reader.getShort().toInt() and 65535 + require(elapsed <= 500) + Animation(dx, dy, drawAnimationTimeMs() - elapsed, reader.getInt()) + } else null val gray = ByteArray(w * h); reader.get(gray) require(reader.remaining() >= count * 8) val occlusions = List(count) { IntArray(4) { reader.getShort().toInt() and 65535 } } @@ -50,7 +66,7 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val } } } - return MenuSelection(x, y, w, h, radius, background, border, depth, BmpUtil.pack4bppFromGray8(gray, w, h), occlusions, kind, mask) + return MenuSelection(x, y, w, h, radius, background, border, depth, BmpUtil.pack4bppFromGray8(gray, w, h), occlusions, if (kind == 6) 3 else kind, mask, animation) } } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt index 1338b9af..17195151 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt @@ -7,11 +7,12 @@ class ShellScene(val layers: List, val selections: List = val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${it.depth},${CachedResource(it.packed).hash},${it.selections.joinToString { row -> row.fingerprint }}" } + selections.joinToString { it.fingerprint } fun calls(width: Int, height: Int, surfaces: IntArray, selected: IntArray): List { val calls = ArrayList(); var rowId = 0 - for (row in selections) calls.addAll(row.calls(selected[rowId++])) + val now = drawAnimationTimeMs() + for (row in selections) calls.addAll(row.calls(selected[rowId++], now)) for ((index, layer) in layers.withIndex()) { if (layer.dim < 256) calls.add(DrawProtocol.lut(width, height, layer.dim)) calls.add(DrawProtocol.image(surfaces[index], layer.x, layer.y, depth = layer.depth)) - for (row in layer.selections) calls.addAll(row.calls(selected[rowId++])) + for (row in layer.selections) calls.addAll(row.calls(selected[rowId++], now)) } return calls } @@ -27,6 +28,36 @@ class ShellScene(val layers: List, val selections: List = val target = DisplayListRenderer.Target(output, width, height) return ByteArray(width * height) { (target.get(it % width, it / width) * 16).toByte() } } + internal class AnimatedPreview(val player: DisplayListPlayer, var pixels: ByteArray) + + internal fun animatedPreview( + screenGray: ByteArray, width: Int, height: Int, + schedule: (Int, () -> Unit) -> (() -> Unit), + ): AnimatedPreview { + val screen = BmpUtil.pack4bppFromGray8(screenGray, width, height) + val output = ByteArray(screen.size) + val resources = HashMap() + val surfaces = IntArray(layers.size) { id -> + val layer = layers[id] + resources[id] = DrawProtocol.rawImage(layer.width, layer.height, layer.packed) + id + } + val rows = IntArray(allSelections.size) { id -> + resources[id + layers.size] = allSelections[id].resource.bytes + id + layers.size + } + resources[511] = DrawProtocol.displayList(calls(width, height, surfaces, rows)) + val target = DisplayListRenderer.Target(output, width, height) + lateinit var preview: AnimatedPreview + val player = DisplayListPlayer(DisplayListRenderer(resources), + DisplayListRenderer.Target(screen, width, height), target, + clock = { drawAnimationTimeMs() }, schedule = schedule, + displayed = { preview.pixels = ByteArray(width * height) { (target.get(it % width, it / width) * 16).toByte() } }) + preview = AnimatedPreview(player, screenGray) + player.present(511) + return preview + } + companion object { val EMPTY = ShellScene(emptyList()) fun decode(reader: ByteReader): ShellScene { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index 21f937ee..3a0c19bf 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -51,7 +51,7 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr var out: MutableList = ArrayList() while ((cursor.remaining() >= 1)) { var kind: Int = (cursor.get() and 0xff) - if (kind in 3..5) { out.add(ScreenDraw.image(0, 0, 0).also { it.selection = MenuSelection.read(cursor, kind) }); continue } + if (kind in 3..6) { out.add(ScreenDraw.image(0, 0, 0).also { it.selection = MenuSelection.read(cursor, kind) }); continue } if (((kind == ScreenDraw.KIND_GLYPH) && (cursor.remaining() >= 11))) { var fontId: Int = (cursor.getShort().toInt() and 0xffff) var encoding: Int = cursor.getInt() @@ -287,6 +287,18 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr } private val lock = protocolPlatform().createLock() + private var animatedPreview: ShellScene.AnimatedPreview? = null + private var previewKey: String? = null + + private fun previewScene(scene: ShellScene, gray: ByteArray, key: String): ByteArray { + if (previewKey != key) { + animatedPreview?.player?.stop() + animatedPreview = scene.animatedPreview(gray, screenWidth, screenHeight, + schedule = { delay, action -> scheduleDrawRedraw(delay) { lock.withLock(action) } }) + previewKey = key + } + return animatedPreview!!.pixels + } private var screenWidth: Int = 0 @@ -602,6 +614,9 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr private fun compositeLocked(includePreview: Boolean = includePreviewInFrames): Composite { var gray: ByteArray = ByteArray((screenWidth * screenHeight)) if (blanked) { + animatedPreview?.player?.stop() + animatedPreview = null + previewKey = null return Composite( gray, screenWidth, @@ -667,8 +682,18 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr } } val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene.EMPTY else ShellScene(shellScene?.layers ?: emptyList(), selections) - val preview = if (includePreview && (shellScene != null || selections.isNotEmpty())) scene.preview(gray, screenWidth, screenHeight) else gray - return Composite(preview, screenWidth, screenHeight, fingerprint.append("|shell:").append(scene.fingerprint).toString(), + val sceneKey = fingerprint.append("|shell:").append(scene.fingerprint).toString() + val preview = if (includePreview && (shellScene != null || selections.isNotEmpty())) { + previewScene(scene, gray, sceneKey) + } else { + if (includePreview) { + animatedPreview?.player?.stop() + animatedPreview = null + previewKey = null + } + gray + } + return Composite(preview, screenWidth, screenHeight, sceneKey, nextCompositeSeq++, draws.toTypedArray()).also { it.screenGray = gray; it.shellScene = scene } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/ByteReader.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/ByteReader.kt index cfb69420..c870bbf8 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/ByteReader.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/util/ByteReader.kt @@ -1,5 +1,7 @@ package com.faceclaw.app +import kotlin.jvm.JvmOverloads + /** Sequential little-endian input. Platform adapters can read native buffers without a copy. */ abstract class ByteReader { abstract fun remaining(): Int @@ -23,14 +25,28 @@ abstract class ByteReader { fun getInt(): Int = (getShort().toInt() and 65535) or (getShort().toInt() shl 16) } -class ArrayByteReader(private val bytes: ByteArray) : ByteReader() { - private var position = 0 +class ArrayByteReader @JvmOverloads constructor( + private val bytes: ByteArray, + private val start: Int = 0, + private val end: Int = bytes.size, +) : ByteReader() { + private var position = start - override fun remaining(): Int = bytes.size - position + init { + require(start >= 0 && start <= end && end <= bytes.size) + } - override fun get(): Byte = bytes[position++] + override fun remaining(): Int = end - position - override fun get(index: Int): Byte = bytes[index] + override fun get(): Byte { + require(remaining() > 0) + return bytes[position++] + } + + override fun get(index: Int): Byte { + require(index >= 0 && index < end - start) + return bytes[start + index] + } override fun get(bytes: ByteArray, offset: Int, length: Int): ByteReader { require( diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.ios.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.ios.kt new file mode 100644 index 00000000..c8ddc0c2 --- /dev/null +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/graphics/DrawRedraw.ios.kt @@ -0,0 +1,15 @@ +package com.faceclaw.app + +import platform.darwin.DISPATCH_TIME_NOW +import platform.darwin.dispatch_after +import platform.darwin.dispatch_get_main_queue +import platform.darwin.dispatch_time + +internal actual fun scheduleDrawRedraw(delayMs: Int, action: () -> Unit): () -> Unit { + val lock = protocolPlatform().createLock() + var cancelled = false + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delayMs.toLong() * 1_000_000L), dispatch_get_main_queue()) { + if (lock.withLock { !cancelled }) action() + } + return { lock.withLock { cancelled = true } } +} diff --git a/tests/brightness-picker.test.cjs b/tests/brightness-picker.test.cjs index 80a83431..59569452 100644 --- a/tests/brightness-picker.test.cjs +++ b/tests/brightness-picker.test.cjs @@ -27,6 +27,7 @@ const layers = load('app/ui/layers.ts', { '../native/frame-timings': { spanCurrent: (_name, paint) => paint() }, }); const menu = load('app/ui/menu.ts', { + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap, '../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'), }); diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt index 385ba448..802d54fa 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt @@ -75,7 +75,7 @@ class DisplayListTest { @Test fun roundedRectsAndNestedOddNegativeDepthMatchFirmwareOnBothLenses() { val resources = mapOf( 40 to hex("0404000200f00f0ff0"), - 41 to hex("0202000f00080202010001000c0008000300040a0a000402022800050004001f"), + 41 to hex("0202000d0008020201010c0008000300040a0a000402022800050004001f"), 42 to hex("02010005000702fd2900")) val screen = hex("012345601234560112345601234560122345601234560123345601234560123445601234560123455601234f60123456601234560123456001234560123456011234560123456012234560123456012334560123456012344560123456012345") val expected = listOf("01234560123456011aaaaaaaaaa56012aa45644444aa0123a4564444456a1234a564f44f564a2345a6444fff644a3456a4444456444a4560aa44456444aa56011aaaaaaaaaa56012234560123456012334560123456012344560123456012345", "012345601234560112aaaaaaaaaa60122aa56444445aa1233a5644444564a2344a644f44f644a3455a4444ff6444a4566a4444564444a5600aa44564444aa60112aaaaaaaaaa6012234560123456012334560123456012344560123456012345") diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt new file mode 100644 index 00000000..330bc4ba --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt @@ -0,0 +1,140 @@ +package com.faceclaw.app + +import kotlin.test.* + +class DrawExpressionTest { + private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray() + private fun evaluate(code: ByteArray, elapsed: Long = 0): Pair { + val frame = DrawEvaluation(elapsed) + return DrawExpression.evaluate(DrawReader(code), frame) to frame.animationPending + } + + @Test fun integerWidthsSignExtensionAndReservedPrefixes() { + val signed = mapOf( + 0 to "00", 63 to "3f", -64 to "40", -1 to "7f", 64 to "8040", -65 to "bfbf", + 8191 to "9fff", -8192 to "a000", 8192 to "c02000", -8193 to "dfdfff", + 1048575 to "cfffff", -1048576 to "d00000", 1048576 to "e0100000", + -1048577 to "efefffff", 134217727 to "e7ffffff", -134217728 to "e8000000", + 134217728 to "f008000000", Int.MAX_VALUE to "f07fffffff", Int.MIN_VALUE to "f080000000", + ) + for ((number, bytes) in signed) { + assertContentEquals(hex(bytes), ExtendedVarint.signed(number)) + assertEquals(number, ExtendedVarint.read(DrawReader(hex(bytes)), true)) + } + for (value in listOf(0u, 127u, 128u, 16383u, 16384u, 2097151u, 2097152u, 268435455u, 268435456u, UInt.MAX_VALUE)) { + val bytes = ExtendedVarint.unsigned(value) + assertEquals(value, ExtendedVarint.read(DrawReader(bytes), false).toUInt()) + for (n in 0 until bytes.size) assertFails { ExtendedVarint.read(DrawReader(bytes.copyOf(n)), false) } + } + for (prefix in 0xf1..0xff) assertFails { ExtendedVarint.read(DrawReader(byteArrayOf(prefix.toByte())), true) } + assertEquals(-1, ExtendedVarint.read(DrawReader(hex("bfff")), true)) // valid non-minimal form + assertFails { ExtendedVarint.evaluate(DrawReader(hex("ff05")), DrawEvaluation(0)) } + } + + @Test fun arithmeticTypesStackErrorsAndTimeTracking() { + val vectors = listOf( + "0107010510" to 12, "0107010511" to 2, "0107010512" to 35, + "0179010213" to -3, "0179010214" to -1, "017915" to 7, + "0107010516" to 5, "0107010517" to 7, "01010109" to 9, + "01040310" to 8, "010401070504" to 7, + "010430010230202431" to -6, + "020000c03f02000000402231" to 3, + "01003001806430020000003f4031" to 50, + "01f07fffffff010110" to Int.MIN_VALUE, + "01f080000000017f13" to Int.MIN_VALUE, + "01f080000000017f14" to 0, + ) + for ((code, expected) in vectors) assertEquals(expected to false, evaluate(hex(code)), code) + for (bad in listOf("", "10", "0101010013", "010130010110", "020000807f", "ff", "0180", "01013210")) { + assertEquals(0 to false, evaluate(hex(bad)), bad) + } + assertEquals(0 to false, evaluate(ByteArray(66) { if (it % 2 == 0) 1 else 0 })) // stack overflow + assertEquals(0 to false, evaluate(ByteArray(1025))) + for (op in DrawExpression.SMOOTHSTEP..DrawExpression.EASE_IN_OUT_CUBIC) { + assertEquals(0 to false, evaluate(hex("0200000000") + byteArrayOf(op.toByte(), 49))) + assertEquals(1 to false, evaluate(hex("020000803f") + byteArrayOf(op.toByte(), 49))) + } + assertEquals(499 to true, evaluate(hex("0181f432"), 499)) + assertEquals(500 to false, evaluate(hex("0181f432"), 500)) + assertEquals(500 to false, evaluate(hex("0181f432"), 900)) + assertEquals(0 to false, evaluate(hex("0181f432ff"), 250)) // errors discard pending time + } + + @Test fun smoothstepCoordinatesMatchFirmwareAndSurvivePresentTimeReset() { + val value = DrawValue.animate(10, 110) as DrawValue.Expression + val code = "010a3001806e300181f432010010300181f43023414031" + assertContentEquals(hex(code), value.program) + for ((time, expected) in listOf(0L to 10, 125L to 25, 250L to 60, 375L to 94, 500L to 110, 900L to 110)) { + assertEquals(expected to (time < 500), evaluate(value.program, time)) + } + val continued = DrawValue.animate(10, 110, elapsedMs = 250) as DrawValue.Expression + assertEquals(60 to true, evaluate(continued.program, 0)) + assertEquals(110 to false, evaluate(continued.program, 250)) + } + + @Test fun animatedMenuBridgePreservesElapsedTimeAndTranslation() { + // Tag 6 record emitted by the TypeScript bridge: elapsed=200, delta=(-2,-4). + val wire = hex("06030002000200020001001030020000fefffcffc8002a000000ffffffff") + val input = ArrayByteReader(wire) + assertEquals(6, input.get().toInt()) + val row = MenuSelection.read(input, 6).translated(10, 10) + assertEquals(0, input.remaining()) + val motion = assertNotNull(row.animation) + assertEquals(42, motion.token) + assertEquals(-2, motion.dx) + assertEquals(-4, motion.dy) + val call = row.calls(7, motion.startedAt + 200).first() + for ((elapsed, expected) in listOf(0L to (11 to 9), 300L to (13 to 12))) { + val reader = DrawReader(call) + assertEquals(8, reader.readU8()) + assertEquals(DRAW_FLAG_DEPTH, reader.readU8()) + assertEquals(2, reader.readS8()) + val frame = DrawEvaluation(elapsed) + assertEquals(expected.first, ExtendedVarint.evaluate(reader, frame)) + assertEquals(expected.second, ExtendedVarint.evaluate(reader, frame)) + assertEquals(elapsed < 300, frame.animationPending) + } + for (end in 1 until wire.size) assertFails { + MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), 6) + } + } + + @Test fun playerSchedulesOnlyUnfinishedFramesAndCancelsStaleCallbacks() { + val call = DrawProtocol.roundedRect(DrawValue.Integer(0), DrawValue.animate(0, 4), 2, 2, 0, 15) + val renderer = DisplayListRenderer(mapOf(1 to DrawProtocol.displayList(listOf(call)))) + val screen = DisplayListRenderer.Target(ByteArray(16), 4, 8) + val output = DisplayListRenderer.Target(ByteArray(16), 4, 8) + var now = 1000L + val queued = mutableListOf<() -> Unit>() + var cancelled = 0 + var displayed = 0 + val player = DisplayListPlayer(renderer, screen, output, { now }, { delay, callback -> + assertEquals(45, delay) + queued.add(callback); + { cancelled++ } + }, { displayed++ }) + player.present(1) + assertEquals(15, output.get(0, 0)) + val first = queued.removeAt(0) + now += 250 + first() + assertEquals(15, output.get(0, 2)) + assertEquals(0, output.get(0, 0)) + val stale = queued.removeAt(0) + player.present(1) + assertEquals(15, output.get(0, 0)) + stale() + assertEquals(3, displayed) + now += 500 + queued.removeAt(0)() + assertEquals(15, output.get(0, 4)) + assertFalse(renderer.animationPending) + assertTrue(queued.isEmpty()) + player.present(1) + val stopped = queued.removeAt(0) + player.stop() + stopped() + assertEquals(5, displayed) + assertTrue(cancelled >= 2) + } +} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt new file mode 100644 index 00000000..90e0cff8 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt @@ -0,0 +1,128 @@ +package com.faceclaw.app + +import kotlin.test.* + +class DrawWireTest { + private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray() + + @Test fun encodersUseRevision27CoordinatesAndPreserveOtherWireBytes() { + // Literal vectors pin the firmware grammar independently of the reader. + val calls = listOf( + DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to + "0403ff018034120080ff7f1f", + DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to + "0200feff0100020003000400fbfffaff", + DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9", + DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f", + DrawProtocol.playList(511, depth = 127) to "07027fff01", + DrawProtocol.roundedRect(-1, 2, 640, 480, 65535, 15, 16) to + "08007f028002e001ffff0f10", + DrawProtocol.lut(640, 480, 256) to "0600000000008002e0010123456789abcdef", + DrawProtocol.bbox(hex("ffffffffffffffff"), 4, 0, 0, 8, 2) to "010000000002010f10", + DrawProtocol.bbox(hex("0f"), 1, 1, 0, 1, 1) to "01000101000000010001001f", + ) + for ((call, expected) in calls) assertContentEquals(hex(expected), call) + assertContentEquals(hex("0100050007027fff01"), DrawProtocol.sequence(listOf(calls[4].first))) + assertContentEquals(hex("1a0100050007027fff01"), DrawProtocol.message(listOf(calls[4].first))) + assertContentEquals(hex("020100050007027fff01"), DrawProtocol.displayList(listOf(calls[4].first))) + assertContentEquals(hex("1bffff"), DrawProtocol.root(DrawProtocol.SCREEN)) + } + + @Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() { + val records = listOf( + "1300020080ff7f1f" to "040000020080ff7f1f", + "14ff01ffff02000f0341017f" to "0500ff01ffff02000f0341017f", + "0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9", + "030001020134120f10" to "010000000102010f10", + "060f10" to "01000100000000080002000f10", + "090100020003000400fbfffaff" to "0200feff0100020003000400fbfffaff", + ) + for ((record, expected) in records) { + val calls = DrawProtocol.fromOptimized(hex(record), 8, 2) + assertEquals(1, calls.size) + assertContentEquals(hex(expected), calls.single(), record) + } + val nested = hex("0802") + records.take(2).fold(byteArrayOf()) { bytes, (record, _) -> + val payload = hex(record) + bytes + DrawProtocol.word(payload.size) + payload + } + val calls = DrawProtocol.fromOptimized(nested) + assertEquals(2, calls.size) + for (i in calls.indices) assertContentEquals(hex(records[i].second), calls[i]) + assertFails { DrawProtocol.fromOptimized(hex("1300020080ff7f")) } + assertFails { DrawProtocol.fromOptimized(hex("1300020080ff7f1f00")) } + assertFails { DrawProtocol.fromOptimized(hex("0fffff02001f0441c3a9")) } + } + + @Test fun everyTruncatedOrOverlongCallIsRejectedBeforeMutation() { + val font = ByteArray(197) + font[0] = 1 + font[67] = 193.toByte() // Glyph A. + hex("0801011f").copyInto(font, 193) + val resources = mapOf( + 1 to hex("0401000100f0"), + 2 to font, + 3 to DrawProtocol.displayList(emptyList()), + ) + val renderer = DisplayListRenderer(resources, builtin = { _, _ -> + DisplayListRenderer.BuiltinGlyph(hex("0801011f"), 1) + }) + val calls = listOf( + DrawProtocol.image(1, 0, 0, target = 1, depth = -1), + DrawProtocol.rectCopy(DrawProtocol.CURRENT, 0, 0, 2, 2, 1, 1), + DrawProtocol.stockText(0, 0, 15, hex("41")), + DrawProtocol.text(2, 0, 0, 15, hex("41")), + DrawProtocol.playList(3), + DrawProtocol.roundedRect(0, 0, 4, 4, 1, 15), + DrawProtocol.lut(8, 4, 128), + DrawProtocol.bbox(ByteArray(16) { -1 }, 4, 0, 0, 8, 4), + ) + val screen = ByteArray(16) { 0x12 } + val target = DisplayListRenderer.Target(screen, 8, 4) + val valid = DrawProtocol.roundedRect(0, 0, 4, 4, 0, 15) + for (call in calls) { + // Establish that each fixture is valid before testing malformed forms. + renderer.execute(DrawProtocol.sequence(listOf(call)), target) + screen.fill(0x12) + val savedResources = resources.mapValues { it.value.copyOf() } + val malformed = (0 until call.size).map { call.copyOf(it) } + listOf(call + byteArrayOf(0)) + for (bad in malformed) { + assertFails { renderer.execute(DrawProtocol.sequence(listOf(valid, bad, valid)), target) } + assertContentEquals(ByteArray(16) { 0x12 }, screen) + for ((id, bytes) in savedResources) assertContentEquals(bytes, resources[id]) + } + } + val sequence = DrawProtocol.sequence(listOf(valid)) + for (length in 0 until sequence.size) { + assertFails { renderer.execute(sequence.copyOf(length), target) } + assertContentEquals(ByteArray(16) { 0x12 }, screen) + } + assertFails { renderer.execute(sequence + byteArrayOf(0), target) } + assertContentEquals(ByteArray(16) { 0x12 }, screen) + } + + @Test fun batchesRespectEncodedLengthsAndCallBudget() { + val call = DrawProtocol.playList(511) + val messages = DrawProtocol.messages(List(3) { call }, maxBytes = 15) + assertEquals(listOf(15, 9), messages.map { it.size }) + assertContentEquals(hex("1a020004000700ff0104000700ff01"), messages[0]) + assertFails { DrawProtocol.messages(listOf(call), maxBytes = 8) } + val many = DrawProtocol.messages(List(4097) { call }) + assertEquals(listOf(4096, 1), many.map { DrawProtocol.u16(it, 1) }) + assertTrue(DrawProtocol.messages(emptyList()).isEmpty()) + } + + @Test fun resourceReaderViewsUseRelativeOffsetsAndCannotEscapeTheirBounds() { + val reader = ArrayByteReader(hex("ff123456ee"), 1, 4) + assertEquals(0x12.toByte(), reader.get(0)) + assertEquals(0x3412.toShort(), reader.getShort()) + assertEquals(1, reader.remaining()) + assertFails { reader.get(ByteArray(2)) } + assertEquals(0x56.toByte(), reader.get()) + assertEquals(0, reader.remaining()) + assertFails { reader.get() } + assertFails { reader.get(3) } + assertFails { reader.get(-1) } + assertFails { ArrayByteReader(byteArrayOf(1), 1, 2) } + } +} diff --git a/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosBleCentralTest.kt b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosBleCentralTest.kt new file mode 100644 index 00000000..c32f405e --- /dev/null +++ b/tests/kotlin/src/iosTest/kotlin/com/faceclaw/app/IosBleCentralTest.kt @@ -0,0 +1,36 @@ +package com.faceclaw.app + +import kotlin.test.Test +import kotlin.test.assertTrue +import platform.Foundation.NSDate +import platform.Foundation.NSDefaultRunLoopMode +import platform.Foundation.NSRunLoop +import platform.Foundation.NSThread +import platform.Foundation.dateWithTimeIntervalSinceNow +import platform.Foundation.runMode + +class IosBleCentralTest { + /** Registering a state listener must create the central and report a state without any scan. */ + @Test + fun scanListenerAloneReceivesABluetoothStateReport() { + val central = IosBleCentral(IosProtocolPlatform) + val states = ArrayList() + var offMain = 0 + central.setScanListener(object : IosBleScanListener { + override fun onBluetoothState(state: Int, authorization: Int) { + if (!NSThread.isMainThread) offMain++ + states.add(state) + } + + override fun onAdvertisement(identifier: String, name: String, manufacturerDataHex: String, rssi: Int, connectable: Boolean) {} + }) + val deadline = IosProtocolPlatform.elapsedRealtimeMs() + 5_000 + while (IosProtocolPlatform.elapsedRealtimeMs() < deadline && states.none { it != 0 }) { + NSRunLoop.mainRunLoop.runMode(NSDefaultRunLoopMode, NSDate.dateWithTimeIntervalSinceNow(0.02)) + } + // The simulator reports unsupported/powered-off; a real phone powered-on. Any non-unknown state proves the central exists. + assertTrue(states.any { it != 0 }, "no CBManagerState reported: $states") + assertTrue(offMain == 0, "state reports must arrive on the main queue") + central.close() + } +} diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs index 4abe3feb..6d6167e3 100644 --- a/tests/menu-display-list.test.cjs +++ b/tests/menu-display-list.test.cjs @@ -18,7 +18,8 @@ const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4, const {MenuLayer}=load('app/ui/menu.ts',{ '../graphics/image':graphics,'../graphics/textwrap':{},'../graphics/ui-fonts':{getDefaultSmallFont:()=>font}, '../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{}, - './metrics':require('../.test-build/app/ui/metrics.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), + './metrics':require('../.test-build/app/ui/metrics.js'), }); const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}}); function menu() { @@ -26,9 +27,9 @@ function menu() { const context={stack:{getBaseSize:()=>({width:80,height:80}),isFocused:()=>true}}; return {layer,paint:()=>layer.paint(context,()=>new graphics.GrayImage(80,80)),context}; } -test('menu retains the selected text and rounded highlight at depth +2',async()=>{ +test('menu retains the selected text and rounded highlight on the menu plane',async()=>{ const m=menu(),image=m.paint(),row=image.draws.find(d=>d.presentation); - assert.equal(row.presentation.depth,2);assert.equal(row.presentation.radius,8); + assert.equal(row.presentation.depth,0);assert.equal(row.presentation.radius,8); assert.ok(row.source.pixels.some(v=>v===255));assert.ok(!image.withDrawsBaked(false).pixels.some(v=>v===255)); const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0}]); const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.equal(records.length,1); @@ -37,7 +38,7 @@ test('menu retains the selected text and rounded highlight at depth +2',async()= const screen=flat.image.pixels.slice(),preview=c.composite(); assert.ok(preview.some(v=>v===240));assert.deepEqual(flat.image.pixels,screen); await m.layer.handleInput({type:'scroll-down'},m.context); - const next=m.paint().draws.find(d=>d.presentation);assert.ok(next.y>row.y);assert.equal(next.presentation.depth,2); + const next=m.paint().draws.find(d=>d.presentation);assert.ok(next.y>row.y);assert.equal(next.presentation.depth,0); }); test('shell menu selection survives serialization and is not baked into its surface',()=>{ const image=menu().paint(),bytes=encodeShellScene([{image,x:0,y:0,shellKey:7}]); @@ -58,14 +59,14 @@ test('later opaque planes occlude a replayed selection without erasing its visib const {LayerStack,noopLayerActions}=load('app/ui/layers.ts',{ '../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},'./gestures':{}, }); -test('context menu surface uses +4 and selected row +6 without changing the app screen',()=>{ +test('context menu surface and selected row both use +4 without changing the app screen',()=>{ const base=new graphics.GrayImage(100,90,96); const stack=new LayerStack({paint:()=>base},noopLayerActions,{width:100,height:90}); stack.push(new MenuLayer(null,[{label:'FIRST',onSelect(){}}],{x:10,y:8,width:80,minHeight:70,maxHeight:70,depth:4})); const frame=planes.flattenPlanesWithDraws(stack.paint()); assert.deepEqual(frame.image.pixels,base.pixels); const records=wire.presentationRecords(prepareFrameDraws(frame.draws)); - assert.deepEqual(records.map(r=>r.depth),[4,6]);assert.equal(records[0].mode,'masked-image'); + assert.deepEqual(records.map(r=>r.depth),[4,4]);assert.equal(records[0].mode,'masked-image'); const c=new SurfaceCompositor(100,90);c.configureSurface('app',{x:0,y:0,width:100,height:90,zOrder:0,transparency:'opaque'}); c.submitSurfaceFrame('app',frame.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(frame.draws)); const preview=c.composite(); @@ -77,11 +78,11 @@ test('context menu surface uses +4 and selected row +6 without changing the app c.submitSurfaceFrame('app',closed.image.pixels,{x:0,y:0,width:100,height:90},prepareFrameDraws(closed.draws)); assert.deepEqual(c.composite(),base.pixels); }); -test('system menu bridge shifts its surface +4 and selected row +6',()=>{ +test('system menu bridge shifts its surface and selected row together by +4',()=>{ const image=menu().paint(),bytes=encodeShellScene([{image,x:8,y:0,shellKey:7,depth:4}]); const view=new DataView(bytes.buffer),w=view.getUint16(8,true),h=view.getUint16(10,true); assert.equal(view.getInt16(16,true),4); - assert.equal(wire.readPresentation(bytes,18+w*h).selection.depth,6); + assert.equal(wire.readPresentation(bytes,18+w*h).selection.depth,4); const c=new SurfaceCompositor(100,80);c.setShellScene(bytes);const preview=c.composite(); assert.equal(preview[40*100+8],0);assert.equal(preview[40*100+10],80); }); diff --git a/tests/menu-highlight-motion.test.cjs b/tests/menu-highlight-motion.test.cjs new file mode 100644 index 00000000..a1417dfb --- /dev/null +++ b/tests/menu-highlight-motion.test.cjs @@ -0,0 +1,44 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { MenuHighlightMotion } = require('../.test-build/app/ui/menu-highlight-motion.js'); +const { GrayImage } = require('../.test-build/app/graphics/image.js'); +const { encodePresentation, readPresentation } = require('../.test-build/app/graphics/presentation-wire.js'); + +test('highlight animates only navigation that preserves the scroll window', () => { + const motion = new MenuHighlightMotion(); + assert.equal(motion.paint(0, 0, 10, 20, 100, 20, 0), undefined); + motion.navigate(0, false); + const moved = motion.paint(1, 0, 10, 40, 100, 20, 100); + assert.equal(moved.dx, 0); + assert.equal(moved.dy, -20); + assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 350).token, moved.token); + motion.navigate(1, false); + const next = motion.paint(2, 0, 10, 60, 100, 20, 350); + assert.equal(next.dy, -30, 'continue from the halfway position'); + motion.navigate(2, false); + assert.equal(motion.paint(3, 1, 10, 60, 100, 20, 400), undefined, 'scroll snaps'); + motion.navigate(3, true); + assert.equal(motion.paint(0, 0, 10, 20, 100, 20, 500), undefined, 'wrap snaps'); + motion.navigate(0, false); + motion.paint(1, 0, 10, 40, 100, 20, 600); + assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 1100), undefined, 'finished after 500 ms'); + assert.equal(motion.paint(2, 0, 10, 60, 100, 20, 1200), undefined, 'programmatic changes snap'); +}); + +test('animated selection bridge carries relative start, elapsed time and stable token', () => { + const now = Date.now; + Date.now = () => 1200; + try { + const image = new GrayImage(8, 4); + image.drawMenuSelection(new GrayImage(2, 2, 255), 3, 2, 16, 48, 1, 2, + { dx: -2, dy: -4, startedAt: 1000, token: 42 }); + const bytes = encodePresentation(image.draws[0]); + assert.equal(bytes[0], 6); + assert.equal(bytes.length, 30); + const record = readPresentation(bytes, 0); + assert.equal(record.end, bytes.length); + assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42 }); + assert.equal(record.selection.x, 3); + assert.equal(record.selection.y, 2); + } finally { Date.now = now; } +}); diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index ab843e61..bffedd4d 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -153,6 +153,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp '../graphics/textwrap': textwrap, '../graphics/ui-fonts': { getDefaultSmallFont: () => font }, '../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), './metrics': load('app/ui/metrics.ts'), './gestures': {}, }; const menu = load('app/ui/menu.ts', (name) => deps[name]); diff --git a/tests/notification-filter.test.cjs b/tests/notification-filter.test.cjs index 93505eeb..81811ca5 100644 --- a/tests/notification-filter.test.cjs +++ b/tests/notification-filter.test.cjs @@ -84,6 +84,7 @@ function ui(fontSize = 12) { '../native/notification-sources': prefs, '../native/notification-access': { isNotificationListenerEnabled: () => true }, '../util/render-freshness': { renderPassAllowsStaleData: () => false }, + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), './metrics': load('app/ui/metrics.ts'), './gestures': {}, }; From 08f1b9a2a298e50b455b287e7a123449f08a070d Mon Sep 17 00:00:00 2001 From: James Babcock Date: Wed, 23 Sep 2026 02:58:29 -0700 Subject: [PATCH 15/27] Optimize on-glasses animation --- app/g2/firmware/cfw-patches.ts | 16 ++++---- app/graphics/image.ts | 2 +- app/graphics/presentation-wire.ts | 21 ++++++---- app/ui/menu-highlight-motion.ts | 9 +++-- .../faceclaw/app/g2protocol/DrawExpression.kt | 2 +- .../faceclaw/app/graphics/MenuSelection.kt | 18 +++++---- .../com/faceclaw/app/DrawExpressionTest.kt | 33 +++++++++++----- tests/menu-highlight-motion.test.cjs | 39 +++++++++++++++---- 8 files changed, 94 insertions(+), 46 deletions(-) diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index c1205e1d..214ae1f1 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,7 +19,7 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "2d9f4200b3980156d65732e1d5fe4ba673768baf06683427710ff9a818cfb7ae", + "outputSha256": "62ed330a71d6be45a4482e6007b00fc7f029a01d238f358f69ba992f83769590", "patches": [ { "offset": 1045797, @@ -210,43 +210,43 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff78afc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f037f8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef757fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef70dfe0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f0ecfa0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf00bfa48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf085f9414602e0022084f8200350460c22fef714f894f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7e4ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf7b3ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf75dff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf001f9d8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf0c7fa0bf09bfa294630b9ffe50bf096fa002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7fffd0fe04eea062141ea0b4141ea05633946624665460bf095f800281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af0bbf8d4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f2130409f06bfd4ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b7009f058fde05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f084fc059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f0b6fb28461a21224609f033fa00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f0a5f9854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f0a1f9706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f08ef8201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f034f9606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf793f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009507f0deff606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7e5fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009707f0effc002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009507f0d1fc606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009507f0a4fc606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f079fc606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf71dfa04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf7d9f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf783f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f096fa019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f2a011c0f20001033079440b22f9f752fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f71afc0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f76bfb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f7c1fa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f2ca10c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f71ffc4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f733fc4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f74cfbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f76bfb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009503f035f93eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb004460020a4f8800347f64c60c2f207000068002a8a461abfc4f874030146d4f87413401ac4f87c03fdf763f8002800f00081d4f86803002800f0fb8003f09bfe002800f0f6800646b4f86c0300284cd0a0f10109d4f87c034ff4a07100254ff4f0774ff4805bcde90d050df11808cde901152046494632464ff42073cdf818b007950c95cde90358009703f0def8002840f0cf80d4f8681330464ff41632f7f77cf9d4f87c034946cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906b50c95cdf81080009703f0bbf8002840f0ac809df8380094f88013084384f8800306e0d4f8681330464ff41632f7f751f94ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b07e000bf48f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168414548d04ff46d70fdf77bfe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8001f4945aad1bff35f8f00bf47e8000121b157e8001f4945f8d09fe7054603f0cdfd002d18bf002803d101208af8050022e0c5f860014ff001084ff4f07085f8648101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718af8058004e09af805008af8048030b14ff0ff300fb0bde8f08f0025cbe7204603f088fe00200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2e44d1c9008784f7801eb020c50ea072001f10204199002f0e7810df5a16e9ee860403aa8063000220f90cde9143c644502f0d481601c604502f0d08120786178a71c40ea0121aceb070081421d97209102f2c4811a92ddf81c2528a880e868401068ddf8141500282c91a0f10101116002f0b4812098002802f0b0812098871c032f02f0ab81e678032e02f2a7811d9890f80080f00703d104f1040e28e000bf209820f00100022802f0988194f8049065791c9849ea052b594628aa02f09ef9002842f08b81ddf8140504f1060e012d2c900dd8ddf81c05806948b14feadb0209f00701835c012505fa01f119438154022e04eb070b03d2ddf81405279025e0de4503d0744614f9015b01e000255c4645f64d5ac0f2460af146d047012808bf0135681e81b26e0800ebd130002d48bf4610d0470128ddf8140508bf76423118d945a64627912c9102f04881b8f1040fcdf894e000f39c80b8f1020f00f35081b8f1010f00f00882b8f1020f42f03681de4502f033810ef10100584502f02e810ef10200584502f029810ef10300584502f024810ef10400584502f01f810ef10500584502f01a810ef10600584502f015810ef10700584502f010810ef10800584502f00b810ef10900584502f006810ef10a00584502f001810ef10b00584502f0fc800ef10c00584502f0f7800ef10d00584502f0f2800ef10e00584542f0ed809ef80200289922909ef803009ef8009021909ef804009ef801601f909ef8050024913a91dde929211e909ef806709ef807409ef808b09ef809c09ef80a809ef80b309ef80ca09ef80de0cde92512cde93b212b9949ea06254ff6fe70854223913d9100f0c0864ff6ff70854240f094861c98d0f868634ff420703b904ff4f0703c904ff4a0703d9000f0aebe00bfb8f1060f00f34581b8f1050f00f0c381b8f1060f42f09a80de4502f097800ef10100584502f092800ef10200584502f08d800ef10300584502f088800ef10400584502f083800ef10500584502f07e800ef10600584502f079800ef10700584502f074800ef1080aabeb0a010829c2f06d800ef11001594542f068809ef804109ef8052051ea02201ebf9ef806109ef8073051ea032402f059809ef800509ef80160ddf8a4b045ea0621bbeb01032591c2f04c80984202f249809ef802309ef803702a9a43ea0721571ac2f03f80bc4202f23c800a46ddf81815002900f004872899134624912b9932022391e1182291259900eb0109279802442a449000219006e000bf269b22980133834280f0ec86dde92310219a03fb0107259d269304e001354d4502f10402ecd227984619f7d45e45f5da4fea560c17f80ce0042121ea02082efa08f3c3f342001af8000021ea8303d84000f00f030ef0f00423440ef00f01f60708bf41ea001307f80c30d7e7b8f1030f00f0b381b8f1040f41f0e687bbeb0e0401f0e2870ef10100584501f0dd871c98002801f0d987a01e0528c1f0d5870ef10700584541f0d0871c98d0f86c01002801f0ca879ef80110012901f2c5879ef8003043ea012250f82210002901f0bc870f1ab90741f0b8876ff4403140f60f063944cff6fd76b142c1f0ae87384450f8081c914241f0a88750f80c1ca1f1011616f5803fc1f0a087002801f09d8750f8046c8e4241f09887c7f54037b94201f29387ddf81c75bf6947b1d20803f00703be5c012505fa03f33343bb54dde928abdde92a56002232ab01f0daff00284ff0000908bf4ff0ff3901f00187ddf81805ddf854c000280df1b80801f0fa86072c4ff0ff3941f0f586baf1000f01f0f186fcf7befc002840f0358301f0e6beb8f1070f00f0d081b8f1080f41f05587ddf81c050021c0693aad32afdde9284adde92a863c91cde9320128463946cde93aeb02f0f0fd81462846394602f0ebfd3c99002900f0fb814ff0ff31ddf854c0894601f0bfbede4501f02f87714611f8010b012801f22987289a00281e92299a26922a9a25922b9a1f9200f0aa82594501f01b870ef10201594501f016870ef10301594501f011870ef10401594501f00c870ef10501594501f007870ef10601594501f002870ef10701594501f0fd860ef10801594501f0f8869ef801109ef802209ef8043041ea02219ef803209ef805709ef8064042ea032222929ef807209ef8083047ea042a0ef109070d9742ea032289e2bbeb0e0801f0d7860ef10100584501f0d286a8f102000528c1f0cd860ef10700584501f0c8861c98002801f0c4860ef1080a9ef80770abeb0a00b842c1f0bb860aeb0700584541f0b6861c98d0f86c31002b01f0b0869ef80100012801f2ab869ef8001041ea002053f82020002a01f0a286d21a960741f09e866ff4403640f60f051644cff6fd75ae42c1f094869e1856f8083c834241f08e8656f80c5ca5f1011313f5803fc1f08686002e01f0838656f8043cab4241f07e86c2f54032954201f27986ddf81c25926942b1c00801f00701135c012404fa01f119431154c12dc1f069863078012841f065862898002f2690299824902a9823902b98229000f0f780a6f13f04d14602e0013f00f0f08019f8010b411e1f29f7d341b22029c1f24a8604eb400114f81000497840ea0122c12ac1f04086304629463aab01f097fe0028e2d101f037beabeb0e09b9f1050fc1f031860ef10508d84501f02c860ef106059ef80570abeb0500b842c1f02386e819584541f01f8628981790299826902a981f902b981690afb1002402e00134bc4210d2285d01381e28f8d92819391b3aaa32ab02f0cdf8002801f004863a980444bc42eed3ddf81805002800f0c984b9f1050f01f0f7851798002801f0f385fcf74dfb002801f0ee8598f8008008f10600814541f0e78547f65420c2f20700d0f800b0bbf1000f01f0dd859bf80c009bf80d109bf80e209bf80f3040ea012040ea024040ea0366a6f1810010f1800fc1f0c9859bf810009bf811109bf8132040ea01209bf8121040ea014040ea02600890813810f5817f41f2b585b8f1000f4ff0000900f054844ff0000c00270be000bf00f100403aa941f824000137474504f1010c80f0f183e85d6446411e1e29efd9e819a8eb070132aa2eab02f059f8002801f0198532992e983aaa0f4442f82400e4e7de4501f086850ef10100584501f081850ef10200584541f07c859ef800009ef8011028af40ea0121ddf81c058ccf0490ddf818052b9e03902798019602901c98009702f06efb814601f0eebcddf81805002800f02c840020b8f1080f4ff0ff393a90c1f0e1842698002801f0dd84fcf7acfa002801f0d6842599cd7905f10800804541f0cf8408784f7891f8068040ea072600f018bcdde93a218a423ff400ae531c8b423ff4fcad931c8b423ff4f8add31c8b423ff4f4ad131d8b423ff4f0ad531d8b423ff4ecad931d8b423ff4e8add31d8b423ff4e4ad02f108038b427ff4dfad1178537851ea032c4ff0ff311ebf9378d77853ea07233ff4d4adbcf5207f3ff6d0adb3f5f07f3ff6ccad97790f2f21973ff6c7add579102d25953ff6c2adddf81c55229033982f6a1f933843ddf8187513795279002f1696cdf898a0286201f0878427980021604440428145fff6a9addde92670381a8145bff6a3ad1f9847422298b842fff69dad2298a346ddf858a01f9c80457ff795ad43ea0222b2eb5c0f28bf4fea5c02b2eb540f28bf62081792013a4ff0000338bf1a460992424202eae075a8eb0002a242a8bf224695421e92bff677ad279a179b91445a001b9203fb03f2920013920ceb09022392bcf1030f38bf01210022032c38bf012211431291611e0e91a11e0c9109994ff000084a0049438900069109f101010a9125990b920a0141ea011107916ff0080101eb43010d9120eae0710afb01b1002608922791cdf8409001f0e9b9594501f071840ef10201594501f06c840ef10301594501f067840ef10401594501f062849ef802209ef80110520022929ef803209ef804304fea820a0ef1050289000d925a00baf1000f0e9201f04c840e9a002a01f04884269a521ac1f04484924501f24184259a229bd21ac1f03c840e9b934201f2388400287bd02798002301eb000985e048f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914201f04b804ff46d70fdf711f8002801f093834ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001f259ba14295d1bff35f8f00bf42e80001002900f0fa8752e8001fa142f6d088e72798002301eb0009c00708d1b9f1000f05d426990aeb09008842d8bf01230d9e0e9aabeb06000b90ddf8180502fb0af2b0fa80f040091843c0070027109000200c932390cde9112b11e000bf23981b99084423901698189981424ff0000088bf01200743179ef80708bf0e44119af80704d02398824208d801f07cbb5e4500f024822398824240f22082bbeb060001f0718396f800805fea181301d0012111e0012801f0678373780bb102210ae00428c1f06083b178f37851ea032301f05a83042100bf18912399511a8b4201f252831099dde91eec00291b93cde91606b5d108f00f0027901b981397411e03294fea0811249180f082804ff000081b98dde912b710f00301a1d02398229a4044b0fbfaf303fb1a0713444f4453ea070617d4269a974214d2259eb34211d203fb0ce37e089d5d279a05f00f0e05f0f0051544ff07249a08bf4eea0205dde91eec9d55dde912b701293ff479af431cb3fbfaf7229a07fb1a36bb1806eb090753ea070617d4269a974214d2259eb34211d203fb0ce37e089d5d279a05f00f0e05f0f0051544ff07249a08bf4eea0205dde91eec9d55dde912b702293ff450af0230b0fbfaf1229a01fb1a008b18484453ea00013ff544af26998842bff440af25998b42bff43caf03fb0ce14308cf5c279a07f00f0607f0f0071744c007249808bf46ea0007ddf848b0cf54139f27e7229c20f003004ff00008219006e000bf219808f1040840453ff472af23984044b0fbfaf303fb1a061f1906eb090b57ea0b0319d426998b4516d225998f4213d207fb0ce34fea5b069f5d279907f00f0e07f0f0070f445feacb71249908bf4eea0107dde91eec9f55411cb1fbfaf3229c03fb1a11234401eb090753ea070115d426998f4212d225998b420fd203fb0ce17b08ce5c279a06f00f0506f0f0061644ff07249a08bf45ea0206ce54811cb1fbfaf303fb1a11234401eb090753ea070115d426998f4212d225998b420fd203fb0ce17b08ce5c279a06f00f0506f0f0061644ff07249a08bf45ea0206ce540330b0fbfaf101fb1a000b19484453ea00013ff586af26998842bff482af25998b42bff47eaf03fb0ce14308cf5c279d07f00f0607f0f0072f44c007249808bf46ea0007cf546ce71c9829463aaacde9163ecdf86c80cdf860a0e04601f025fa002841f09b81ddf81c05c4468069ddf860a0ddf86c80dde9163e60b1012e0ad8ea0809f00701855c012606fa01f1ddf860a0294381543a9e002e01f07f81cdf86c8057ea04284ff0ff3901f079815bea0c20189001f07481dde921213b9841ea02218842c1f06c81401a804501f268811d46dde91e323c9842ea03220023904238bf01232292801a189a82424ff0000088bf01201843c0f1000941f05181ddf81805002801f04c811b9a280640ea024005144fea0e60249a40ea0a4096424fea204e00f0fc848946002300f007bdbcf1000f249600f0f580259eacf101094ff000083aaf0ae0259eac46c14508f10108a4f1010407f1040700f0df803aa850f828100029f1d40020434684421dd007eb80056a68b2f1ff3f18dc5a1c914514d0aa68b2f1ff3f11dc9a1c91450dd0ea68b2f1ff3f0adcda1c914506d02a690433002a00f10400e0d400e00022584632ab2eae6546009601f0bafc002801f0ee802e980028bfd04af20d3132a8c0f24e018847b8e72496259e01204ff0000ca4e05e4541f052812398824241f04e81ddf81805002818bf01200c990840012812d1dde91e0322994fea5a0701fb03000b9900eb59020e98009701900d9801f005fa002801f03281ddf854c01a9a01f0beb848f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f02e834ff46d70fcf70dfd002801f08f804ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa14296d1bff35f8f42e80001002900f0de8252e8001fa142f6d08ae700204ff0000903e0259e4ff0000c0120317996f800e07278b378f7788e060f2501f00f0405eae676664389256e43f60a8df8b8600e26259111f0200f08bf012604fb06f605fb06f64fead6268df8b9604ff00d0608bf022604fb06f605fb06f64fead6268df8ba604ff00c0608bf032604fb06f605fb06f64fead6268df8bb604ff00b0608bf042604fb06f605fb06f64fead6268df8bc604ff00a0608bf052604fb06f605fb06f64fead6268df8bd604ff0090608bf062604fb06f605fb06f64fead6268df8be604ff0080608bf072604fb06f605fb06f64fead6268df8bf604ff0070608bf082604fb06f605fb06f64fead6268df8c0604ff0060608bf092604fb06f605fb06f64fead6268df8c1604ff0050608bf0a2604fb06f605fb06f64fead6268df8c2604ff0040608bf0b2604fb06f605fb06f64fead6268df8c3604ff0030608bf0c2604fb06f605fb06f64fead6268df8c4604ff0020608bf0d2604fb06f605fb06f64fead6268df8c5604ff0010608bf0e2604fb06f605fb06f64fead6268df8c6604ff0000608bf0f2666436e43f60a00280df1b8088df8c76040f07187120642ea0e41279a380602eb2144249940ea0340acf1010501eb204000260790cdf830c0cde9095b07e001f01f000b3801366645044400f0c4833aa850f82610b1f1ff3ff1dd33469d421cd03aa800eb83004268b2f1ff3f16dc0133ab4212d08268b2f1ff3f0fdc0133ab420bd0c268b2f1ff3f08dc0133ab4204d002690133002ae1d400e00022584632ab2daf009701f0eefa002800f022872d990029129100f0ac819df8d0009df8d1100d9650ea0126109400f092819df8d4701b969df8d5603f0447ea0667089e1b9d9df8cf009df8ce102e44020241ea00249df8d20006eb2747079e9df8d3300004f71b109e40ea0360031406eb204c0120239700eb54070a441197571e1397f71801f00305f11a0cf101030e930cf102030b93129b00eb52001b9e01332290501b1e951d4627904ff00009ca07f8071894249006e0229809f10109b145054400f04781239819eb0001f4d41f988142f1d218980028eed0dde91630002701fb030a13982195032880f097801e981b9e219d0028dfd0dde91110012409fb010325987908595c00f0100084ea101bc8b201f00f015feac77e08bf01090846002918bf012040ea0b00012816d117eb0c0513d42698854210d268081af8004018f8011004f00f0604f0f0040c43ed0708bf46ea01141b9e0af800401e98219d0128a9d0781c4008195cbef1000fc8b24fea101008bf01f00f00c1b2002918bf012141ea0b01012917d10e99c91914d4269ca14211d24c081af8045018f8000005f00f0605f0f0050543c90708bf46ea00151b9e0af80450219d1e9802283ff47bafb81c4008185cbef1000f00f00f01c3b208bf19090846002918bf012040ea0b0001287ff468af0b983b183ff564af26988342bff460af58081af8004018f8011004f00f0504f0f0040c43db0708bf45ea0114219d0af800404de7ab4606e027980437b8420bf1020b3ff460af25981bf8013c00f010010120ddb2002380ea11110f2d88bf01230b43012b0ceb070319d1002b17d42698834214d22e095d081af8054018f8066004f00f0004f0f0045feacc7844ea06040df1b80808bf40ea06140af805401bf8010c10f00f05284618bf01200843012815d15e1c13d42698864210d270081af8004018f8055004f00f0646ea051604f0f004002a08bf44ea05060af800609bf80000c5b200200f2d88bf01200843012818d19e1c16d42698864213d2740828091af8045018f8000005f00f0605f0f005ddf890e00543bef1000f08bf46ea00150af804509bf8000010f00f05284618bf0120084301287ff47fafd91c3ff57caf26988142bff478af48081af8001018f8053001f00f0444ea031401f0f001002a08bf41ea03040af8004065e74af20d3132a8c0f24e0188479df8cc009df8cd10109cdde9095bdde90cc605e09df8cc009df8cd10ddf830c040ea012010e6d0f86c114ff0ff39002900f06385012f00f2608551f82600002800f05b85401a820740f057856ff4403240f60f030244cff6fd739a42c0f04d850b1853f8081cb14240f0478553f80c7c0022a7f10111cff6ff729142c0f03d8553f8041cb94240f03885c0f540308742219700f232859b46002bcdf87ca000f02c852198c128c0f028859bf80000012840f023854fea88660f2408f00f0704eae6767e4389246643ddf894a0f60a8df8b8600e269af802109af803309af804009af8052018f0200f08bf012607fb06f604fb06f64fead6268df8b9604ff00d0608bf022607fb06f604fb06f64fead6268df8ba604ff00c0608bf032607fb06f604fb06f64fead6268df8bb604ff00b0608bf042607fb06f604fb06f64fead6268df8bc604ff00a0608bf052607fb06f604fb06f64fead6268df8bd604ff0090608bf062607fb06f604fb06f64fead6268df8be604ff0080608bf072607fb06f604fb06f64fead6268df8bf604ff0070608bf082607fb06f604fb06f64fead6268df8c0604ff0060608bf092607fb06f604fb06f64fead6268df8c1604ff0050608bf0a2607fb06f604fb06f64fead6268df8c2604ff0040608bf0b2607fb06f604fb06f64fead6268df8c3604ff0030608bf0c2607fb06f604fb06f64fead6268df8c4604ff0020608bf0d2607fb06f604fb06f64fead6268df8c5604ff0010608bf0e2607fb06f604fb06f64fead6268df8c6604ff0000608bf0f26774367434ff00009ff0a002d8df8c77000f055841b0643ea0141279b1f9e03eb2147110641ea004000141e90c8f30010abf13f092c461b9000f027bc2298864502dd8946012308e07ff4fcaa27988946284400238842c8bf0123189920024fea0c2201fb08f1219142ea0b013843414327983d9ab1f1010a05eb000b1f9200f08a8021f00100cdf89c901b9000204feac379179118931e9605e01b9a01309042aaf1020a72d00146b9f1000f18bf5046b0fbf8f505fb180405eb0e070beb040057ea000325d4269a904222d2259a97421fd2229aab181f9a03fb0263279aa51804226c0822ea8505dde923621b5d07fb0627eb4045087c5d03f00f0604f00f0204f0f0042644c00708bf42ea03167e551e9e6ff0010081ea0002481c0346b9f1000f219f18bfbb18b3fbf8f505fb183405eb0e0c0beb04075cea0702add4269a9742aad2259a9445a7d2229a1f9b2a4402fb0362279b7e0823445c08125d042424ea8303da40dde923430cfb043302f00f049d5d05f00f0c05f0f0052c44fd0708bf4cea02149c551e9e86e7881c279ddde9171301e000204d46c90702d14ff000098ce3da076fea0001219a18bf5018b0fbf8f74ff0000907fb180207eb0e010beb020051ea000300f17983269b984280f07583259b994280f07183229b2a443b441f9f03fb07635708db5d042727ea820223fa02f2dde9237302f00f0601fb07314308cf5cc00707f00f0507f0f007374408bf45ea0217cf5450e3259bd0f86c014ff0ff39002800f049835978012900f245831a7842ea012150f82120002a00f03d83121a930740f039836ff4403340f60f071344cff6fd77bb42c0f02f83104450f8083c8b4240f0298350f80c1c0027a1f10113cff6ff77bb42c0f01f83002800f01c8350f8043c8b4240f01783c2f54032914200f2128300223aab3446269500f0ddfb002800f00783259f0f25f978b87809067b7941ea004027993a7901eb2040190641ea0241ba790914970602f00f0305eae7775f4389256f43ff0a8df8b8700e2712f0200f08bf012703fb07f705fb07f74fead7278df8b9704ff00d0708bf022703fb07f705fb07f74fead7278df8ba704ff00c0708bf032703fb07f705fb07f74fead7278df8bb704ff00b0708bf042703fb07f705fb07f74fead7278df8bc704ff00a0708bf052703fb07f705fb07f74fead7278df8bd704ff0090708bf062703fb07f705fb07f74fead7278df8be704ff0080708bf072703fb07f705fb07f74fead7278df8bf704ff0070708bf082703fb07f705fb07f74fead7278df8c0704ff0060708bf092703fb07f705fb07f74fead7278df8c1704ff0050708bf0a2703fb07f705fb07f74fead7278df8c2704ff0040708bf0b2703fb07f705fb07f74fead7278df8c3704ff0030708bf0c2703fb07f705fb07f74fead7278df8c4704ff0020708bf0d2703fb07f705fb07f74fead7278df8c5704ff0010708bf0e2703fb07f705fb07f74fead7278df8c6704ff0000708bf0f277b436b43db0a8df8c730c2f30012269bcde90382cde90001504621465a463aaf4ff00009029700f094fe29e201200190184626993b46219f009701f050fa229827990135514427911e998d424ff00001bef654abe94321448d42b8bf29461b9a6fea4101114401295cdb139a4ff0ff3301fb1121179a921b012a03eb420231db02fb02f38b422ddd0d9aa2eb460303f10807032f03f106021edb02fb02f48c421add052f03f1040218db02fb02f48c4214dd072f03f1020212db02fb02f48c420edd0436092fa3f1080203db5b438b421346dcdc083204e0013602e0023600e003361f9c012e1edb0832931f5b438b4219dc022e16db131f5b438b4200f3ae80022e0fd0931e5b438b4200f3a980042e08db02fb02f38b4200f3a480043e02f10802e2d10026291801fb0ab3259906eb090210292399a1eb06073ff477af2493b5fa85f1129b490919434ad10e998d4247d00c99681e491b119718958842b8bf01466fea41000b9908440128c0f2a980069900fb10100999a1eb08034ff0ff31012b01eb430177db01fb01f7874273dd5900a1f1090303f10807032f03f1060162db01fb01f484425edd052f03f104015ddb01fb01f4844259dd072f03f1020158db01fb01f4844254dd08f10408092fa3f1080103db5b4383420b46dbdc08314ae0269922eae27c8f42a8bf0f46bc45bff626afbe465feacc7018950ad0249b4fea5c00195c259a01f0f00111430cf1010c19544fea5c02b2eb5e0f1ad22498279f079d00eb5e03b9180c4604f8015b9c4280f08480881c9842257080f08480cc1c9c4205707ed20437b81898422570ead379e0249800eb5c0075e0013e62e7023e60e7033e5ee708f1010804e008f1020801e008f10308b8f1010f23db08318b1f5b4383421edcb8f1020f19db0b1f5b43834200f3cf80b8f1020f11d08b1e5b43834200f3ca80b8f1040f09db01fb01f3834200f3c580b8f1040801f10801ded14ff000080a98ddf8989000eb080c22eae27ecc45b8bfe146ce454cda5feace700ad0249b4fea5e00195c259a01f0f00111430ef1010e19544fea5e07b7eb590f18d22498079d00eb59032798c1190c4604f8015b9c4213d28a1c9a4225701fd2cc1c9c4215701ad20430c2199a422570ecd315e0249800eb5e0211e0481c02e04a1c0de020465feace716bd0f44569d20178089a01f00f011143017062e022465feac97007d0ce4505d21078089900f00f000843107023996fea080001eb000a0120269c01902498219f214662465346009701f0a3f811982aeaea7ca042a8bf204684453eda86465feacc700ad0249b4fea5c00195c259a01f0f00111430cf1010c19544fea5c02b2eb5e0f18d22498279f079d00eb5e03b818044604f8015b9c4211d2811c9942257010d2c41c9c420d700bd20437b91899422570ecd306e0249800eb5c0102e0411c00e021465feace7007d0f44505d20878089a00f00f00104308702298ddf858a01f9cddf84090189d04e6a8f1010844e7a8f1020841e7a8f103083ee7013c31d016f8010b411e1f29f8d341b220290fdb09eb400119f81000497840ea0122c12a06d32199584632ab00f0d5f80028e5d14ff0ff39ddf854c01a9ab9f1000f6ed11998013282421d9820990df5a16e149b9ee8604000eb01047df48aae65e00021fef726b93a9827901e9820eae070259005e038440b38013d07463ff44bac1f9911f8010b1f281f91f3d909eb400119f81000497840ea0122c12ac9d32199584632ab00f098f80028c2d01b98249c04902ea8039032a8ddf88ca00290ddf878802698229922465346cdf80480009700f01afcdde93401384401eb0802a04227eae771b8bf04465245a8bf52468c42c2dd259fba42bfdd279f0f2fbcd8259e631aa2eb060c0f9c279a04ebc20724f8321001327e80bb80a7f806c02792abe74ff0ff300df2e44dbde8f08fb4eb0c0018bf4ff0ff300df2e44dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f87b00591dde91171ddf84cc00c692cb10c68844200f0948100259ee14f68002f00f0fc8100260021069609e0dde90361daf804703144ddf84cc0b94280f0ee81ddf848a00491daf80040655c2e0901d0012113e07f1a012f00f0e0810c4466780eb102210ae0042fc0f0d881a778e47857ea042600f0d281042100bf0391149915f00f04b1fa81f54fea55151cf804c018bf0124069945ea040e029616f00304ddf81490119e4fea0c188b4600f092800194daf80840b1fbf4f505fb1414109967180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990129069901f1010b5fd0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050094fc07644604bf0f254446009f3d402c4301f80b4001990229069901f1020b2ed0daf808401099bbfbf4f505fb14b467180024b7f1ff3fc8bf012404ea0e04012c19d115eb060b16d4974214d29b4512d20bfb09014fea570b11f80b406ff00f050194fc07644604bf0f254446019f3d402c4301f80b40069901f1030b00bf029d6c1e032c2944069107d224e700bf06990bf1040b59453ff41eafdaf808401099bbfbf4f5002705fb14b40c44b4f1ff3fc8bf012707ea0e07012f1ad1ad1918d4944216d29d4214d205fb09056708e40715f807906ff00f04e24604bf0f24c24604ea0904ddf8149044ea0a04ddf848a0ec55daf808400bf10107b7fbf4f505fb147400270c44b4f1ff3fc8bf012707ea0e07012f14d1ad1912d4944210d29d420ed205fb09056708e407ee5d6ff00f04614604bf0f2441463440119e2143e955daf808100bf10204b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e01012914d1ad1912d4944210d29d420ed205fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c55daf808100bf10304b4fbf1f505fb1141109c0c440021b4f1ff3fc8bf012101ea0e0101297ff46bafad193ff568af9442bff465af9d42bff462af05fb09016508e4074e5d6ff00f04674604bf0f2447463440119e3c434c5551e7002f01dd012508e0b7fa87f4109f00256409002fc8bf01252540d1f80880c96801fb08f9b9f1000f58d08e4614994ff0000ab1fa81f461094ff0ff3b0491e907069107e00af1010a0efb08f9ca45abf1010b43d2069954460029129918bf09eb0b04b4fbf8f50e6808f1010705fb18447f0805fb07666708f65d042121ea8407fe4016f00f094e4618bf012604990e43012ed7d1109964185cbf119915eb0105d0d49442ced29d42ccd20599660805fb01081cf8095018f80670129907f00f0907f0f0072f43e40708bf49ea051708f80670d1f80880d1f80ce0b3e707b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf78aff69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae72de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041b1e022eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70faf736f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f7c7ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f9f76ef8e0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f7dafc02a9284600224ff0000afbf78bff81464046f7f79ffdb9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f79dff06f1210506f1280029460722f2f795ff284621460722f2f790ff20465146032207f10905f2f789ff06f11d0049460422f2f783fff07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f757ffa81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f71dff012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f704ff572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f7edfe312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f7d7fe462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f7c0fe362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f755fecde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f736fe8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f737fd284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f7e3fc002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f7b1fc04a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f79dfc0020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f786fc352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f762fc04a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f74ffc002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f73bfc04a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f717fc04f14f0051460722f2f711fc84f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f783fb84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f2f799fa284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f8f793f90028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3237000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff78afc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f037f8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef757fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef70dfe0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f0ecfa0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf0f1fc48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf06bfc414602e0022084f8200350460c22fef714f894f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7e4ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf7b3ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf75dff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf0e7fbd8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf0adfd0bf081fd294630b9ffe50bf07cfd002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7fffd0fe04eea062141ea0b4141ea05633946624665460bf07bfb00281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af0a1fbd4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f213040af051f84ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b700af03ef8e05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f06aff059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f09cfe28461a21224609f019fd00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f08bfc854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f087fc706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f074fb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f01afc606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf793f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009508f0c4fa606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7e5fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009707f0d5ff002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009507f0b7ff606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009507f08aff606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f05fff606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf71dfa04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf7d9f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf783f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f07cfd019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f26c71c0f20001033079440b22f9f752fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f71afc0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f76bfb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f7c1fa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f29670c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f71ffc4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f733fc4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f74cfbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f76bfb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009503f01bfc3eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb004460020a4f8800347f64c60c2f207000068002a8a461abfc4f874030146d4f87413401ac4f87c03fdf763f8002800f00081d4f86803002800f0fb8004f081f9002800f0f6800646b4f86c0300284cd0a0f10109d4f87c034ff4a07100254ff4f0774ff4805bcde90d050df11808cde901152046494632464ff42073cdf818b007950c95cde90358009703f0c4fb002840f0cf80d4f8681330464ff41632f7f77cf9d4f87c034946cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906b50c95cdf81080009703f0a1fb002840f0ac809df8380094f88013084384f8800306e0d4f8681330464ff41632f7f751f94ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b07e000bf48f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168414548d04ff46d70fdf77bfe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8001f4945aad1bff35f8f00bf47e8000121b157e8001f4945f8d09fe7054604f0b3f8002d18bf002803d101208af8050022e0c5f860014ff001084ff4f07085f8648101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718af8058004e09af805008af8048030b14ff0ff300fb0bde8f08f0025cbe7204604f06ef900200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2045d259008784f780a4450ea072001f10204209002f05382ddf830c5ddf82ce5ddf8285542a8063000271790cde91d23944202f03e82601c904202f03a8220786178a61c40ea0121901b814229962a9102f22f82ddf83c2530a880e828401068ddf8341500283491a0f101012197cdf8ccc0116002f01d822a98002802f019822a98871c032f02f01482e678032e02f21082299890f80080f00703d104f1040a28e000bf2a9820f00100022802f0018294f804906579259849ea052b594630aa02f006fa002842f0f481ddf8340504f1060a012d34900dd8ddf83c05806948b14feadb0209f00701835c012505fa01f119438154022e04eb070b03d2ddf834052b9024e0da4503d0544614f9015b01e000255c4645f64d57c0f24607b847012808bf0135681e81b26e0800ebd130002d48bf4610b8470128ddf8340508bf76423118da45a2462b91349102f0b281b8f1040f00f39f80b8f1020f00f31581b8f1010f00f08d82b8f1020f42f0a281da4502f09f810af10100584502f09a810af10200584502f095810af10300584502f090810af10400584502f08b810af10500584502f086810af10600584502f081810af10700584502f07c810af10800584502f077810af10900584502f072810af10a00584502f06d810af10b00584502f068810af10c00584502f063810af10d00584502f05e810af10e00584542f059819af802009af800402f909af803009af801702e909af80500ddf8c0c02d909af80a009af804b028909af80b009af8063027909af80d009af807609af808909af809809af80c202690dde931a1ddf8cce044ea07254ff6fe708542cdf808c12c91cde943a1cdf814e100f055864ff6ff70854240f02d862598d0f868134ff4207043904ff4f07044904ff4a070459000f043be00bfb8f1060f00f30481b8f1050f00f04482b8f1060f42f00381da4502f000810af10100584502f0fb800af10200584502f0f6800af10300584502f0f1800af10400584502f0ec800af10500584502f0e7800af10600584502f0e2800af10700584502f0dd800af1080cabeb0c000828c2f0d6800af11000584542f0d1809af804009af8051050ea01261ebf9af806009af8071050ea012502f0c2809af800009af80120319940ea0224081bc2f0b880864202f2b5809af802009af80330329a40ea0327d01bc2f0ab80854202f2a880ddf83805002800f0f0873098339bcde901472b9fcdf814c0cde90365009703f002f800f0e2bfb8f1030f00f07382b8f1040f42f08d80bbeb0a0602f089800af10100584502f084802598002802f08080b01e0528c2f07c800af10700584542f077802598d0f86c01002802f071809af80110012902f26c809af8003043ea012250f82210002902f063800f1ab90742f05f806ff4403140f60f053944cff6fd75a942c2f05580384450f8081c914242f04f8050f80c1ca1f1011515f5803fc2f04780002802f0448050f8045c8d4242f03f80c7f54037b94202f23a80ddf83c75bf6947b1d20803f00703bd5c012404fa03f32b43bb54dde93049dde9327500223aab02f080f800284ff0000b08bf4ff0ff3b01f0a987ddf838050df1d808002801f0a287072e4ff0ff3b41f09d87002c01f09a87fcf7fdfc002840f0258301f091bfb8f1070f00f08a82b8f1080f41f0ff87ddf83c050021c06942ae3aaddde93079dde932844491cde93a0130462946cde942ab03f015f982463046294603f010f94499002941f06d87dde942218a4201f06887531c8b4201f06487931c8b4201f06087d31c8b4201f05c87131d8b4201f05887531d8b4201f05487931d8b4201f05087d31d8b4201f04c8702f108038b4241f04787117853784ff0ff3b51ea03212e9401f040879378d67853ea06232f9301f03987b1f5207f01f235872f9bb3f5f07f01f2308793792c970f2b269301f22a87d779102f2d9701f22587ddf83c3527903b981e6a92f804c03043ddf838655279002e186201f087872b984ff0000b084440428245c1f20e872b98a9eb0000824581f208872f9846422798b042c1f202872798804541f3fe864cea0222b2eb510f28bf4a082f9bb2eb530f28bf5a081f92013a38bf5a461292424202eae075a8eb00029a42a8bf1a469542249281f2e2862b9a1f9f92447a00239207fb07f292001c9201eb0a0203294ff00001289238bf01212f9b0022032b38bf012211431b91591e1891991e159112992e9b4a00494389000f910af1010113912d9914920a0141ea011110916ff00801119201eb47012c9a169120eae07103fb012e4ff000080024cdf864a001f0fdbada4501f01687514611f8010b012801f21087309a00282c92319a2f92329a2e92339a2d9200f0d981594501f002870af10201594501f0fd860af10301594501f0f8860af10401594501f0f3860af10501594501f0ee860af10601594501f0e9860af10701594501f0e4860af10801594501f0df869af801109af802209af8043041ea022c9af803209af805609af8061042ea032746ea01269af807109af808200af109031a9341ea0221b8e1bbeb0a0801f0bf860af10100584501f0ba86a8f102000528c1f0b5860af10700584501f0b0862598002801f0ac860af108099af80740abeb0900a042c1f0a38609eb0400584541f09e862598d0f86c31002b01f098869af80100012801f293869af8001041ea002053f82020002a01f08a86d21a970741f086866ff4403740f60f061744cff6fd76b742c1f07c869e1856f8083c834241f0768656f80cbcabf1011313f5803fc1f06e86002e01f06b8656f8043c5b4541f06686c2f54032934501f26186ddf83c25926942b1c00801f00701135c012707fa01f119431154bbf1c10fc1f050863078012841f04c863098002c2f9031982e9032982d9033982c9000f0ee80a6f13f074d4602e0013c00f0e78015f8010b411e1f29f7d341b22029c1f2318607eb400117f81000497840ea0122c12ac1f027863046594642ab01f07dfe0028e2d101f01ebeabeb0a09b9f1050fc1f018860af105055d4501f013860af106079af80560abeb0700b042c1f00a86b819584541f0068630981b9031982c903298229033981a90aeb1002402e00134b44210d2385d01381e28f8d93819311b42aa3aab02f0b3f8002801f0eb8542980444b442eed3ddf83805002800f02f85b9f1050f01f0de851b98002801f0da85fcf7c9fa002801f0d5852d78a81d814541f0d08547f65420c2f207000668002e01f0c885307b717bb27bf37b40ea012040ea024040ea0363a3f1810010f1800fc1f0b885307c717cf27c40ea0120b17c40ea014040ea02600e90813810f5817f41f2a885002d4ff0000b0df1d8082e93159600f09b83ddf8b0904ff0000c00260ae000f1004042a941f824000136ae4204f1010c80f03b83b85d6446411e1e29efd9b819a91b3aaa434602f048f8002801f00a853a99369842aa0e4442f82400e5e7da4501f076850af10100584501f071850af10200584541f06c859af800009af8011030af40ea0121ddf83c058ccf0490ddf83805339e03902b98019602902598009702f0d9fd834601f0dfbcddf83805002800f09b840020b8f1080f4ff0ff3b4290c1f0d2842f98002801f0ce84fcf731fa002801f0c7849af8075005f10800804541f0c0849af800009af801609af8068040ea062400f083bc594501f029850af10201594501f024850af10301594501f01f850af10401594501f01a859af802209af8011057009af803209af804304fea810c0af1050196001a915900002e1b9101f006851b99002901f002852f99b1eb0c02c1f0fd84964201f2fa842e99ca1bc1f0f6841b99914201f2f284002878d02b9800250ceb000280e048f2a351c0f24501bff32f8f88474ff29c50c2f229000668bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f0cb824ff46d70fdf760f8002801f04e844ff64c41cff6ff71002342180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fb14297d1bff35f8f42e80001002900f07c8252e8001fb142f6d08be72b9800250ceb0002c00706d1002a04d42f99b0188842d8bf01251a991b9babeb01001890ddf8380503fb06f8b0fa80f040092843c007199500231f900d4600202b90cdf870b0cdf8888012e02b98289908442b902398269981424ff0000088bf0120279b249d0343d80708bf0d44ddf88880d807279305d02b98804509d801f036bc00bf5d4500f05e832b98804540f25a83bbeb050001f02a8495f800e05fea1e1401d0012111e0012801f020846c780cb102210ae00428c1f0198495f802c0eb785cea032401f01284042126912b99a8eb01039c4201f20a841f9928940029cde92305b2d128980ef00f0a431e032b4fea0e1c76d24ff000082898ddf870b010f00309a2d02b988044b8fbf6f000fb1681c319881853ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd54b9f1010f3ff47eaf08f10100b0fbf6f101fb1600cb19104453ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd54b9f1020f3ff459af08f10200b0fbf6f101fb1600cb19104453ea00013ff54daf2f998842bff449af2e998b42bff445afdde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd5433e720f003094ff0000805e000bf08f10408c1453ff480af2b9800eb080bbbfbf6f000fb16b300eb070e98185eea000315d42f99884212d22e998e450fd2dde92c310efb013341085c5cc00704f00f0504f0f004544408bf45ea0c045c540bf10100b0fbf6f101fb1600cb19104453ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd540bf10200b0fbf6f101fb1600cb19104453ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd540bf10300b0fbf6f101fb1600cb19104453ea00018ad42f998842bff487af2e998b42bff483afdde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd5471e725982492294642aacdf86cb0cde922e3e34601f0f5fa002841f06d82ddf83c05dc468069ddf86cb0dde922e3249a50b1012f08d8ed0804f00701445d012707fa01f1214341554299002901f054825d4653ea06204ff0ff3b23931c961cbf249159ea082801f04982dde92e41439b41ea04218b42c1f041825b1a984201f23d822d9b449f45ea03239f424ff00006a7eb030738bf0126b8454ff0000788bf01273743c7f1000b41f02882ddf83875002f01f02382279c2b9e2706289c4ff0000b47ea04473f143744574581f21682269c260646ea024634142c9eb44281f20d824642b74241f30982c8f10006b44241f30482cdf888e007eae77e27eae77b7044aaeb0b071b95b84228bf38462c9da1eb0e0904eae47124eae47401eb08022d1baa4238bf1546ddf890a05e1ae245cdf860c000f02186002201f03eb8bcf1000f00f01882acf10109002542ae09e0bc46a94505f10105a4f1010406f1040600f0058242a850f825100029f1d400202b4684421dd006eb80077a68b2f1ff3f18dc5a1c914514d0ba68b2f1ff3f11dc9a1c91450dd0fa68b2f1ff3f0adcda1c914506d03a690433002a00f10400e0d400e0002215983aab6746cdf8008001f062fd002801f0988136980028c0d04af20d313aa8c0f24e018847b9e701204ff0000cc5e1d0f86c014ff0ff3b002801f085819af80110012901f280819af8002042ea012150f82120002a01f07781121a930741f073816ff440332f9740f60f071344cff6fd77bb42c1f06881104450f8083c8b4241f0628150f80c1c0027a1f10113cff6ff77bb42c1f05881002801f0558150f8043c8b4241f05081c2f54032914201f24b81002242ab01f016fa002801f042819af803109af8020009069af8053041ea00402b999af8042001eb2040190641ea02419af806200f26970602f00f0306eae7775f4389267743ff0a8df8d8700e2712f0200f08bf012703fb07f706fb07f74fead7278df8d9704ff00d0708bf022703fb07f706fb07f74fead7278df8da704ff00c0708bf032703fb07f706fb07f74fead7278df8db704ff00b0708bf042703fb07f706fb07f74fead7278df8dc704ff00a0708bf052703fb07f706fb07f74fead7278df8dd704ff0090708bf062703fb07f706fb07f74fead7278df8de704ff0080708bf072703fb07f706fb07f74fead7278df8df704ff0070708bf082703fb07f706fb07f74fead7278df8e0704ff0060708bf092703fb07f706fb07f74fead7278df8e1704ff0050708bf0a2703fb07f706fb07f74fead7278df8e2704ff0040708bf0b2703fb07f706fb07f74fead7278df8e3704ff0030708bf0c2703fb07f706fb07f74fead7278df8e4704ff0020708bf0d2703fb07f706fb07f74fead7278df8e5704ff0010708bf0e2703fb07f706fb07f74fead7278df8e6704ff0000708bf0f277b437343db0a09148df8e730c2f300122f9bcde90382cde90001204629464a4642af4ff0000b029701f0c9fc01f060b85d4541f0d1802b98804541f0cd80ddf83805002818bf012019990840012810d1dde92c03189907fb0300770800eb52021b98009701901a9801f085f9002801f0b380219901f040b848f2a351c0f24501bff32f8f88474ff29c50c2f229000768bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f035834ff46d70fcf725fc002801f013804ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fb94296d1bff35f8f42e80001002900f0e58252e8001fb942f6d08ae70020ddf8b09002e04ff0000c01209af804100f248d0601f00f0604eae575754389246543ed0a9af800e08df8d8500e259af801209af802309af803702f9111f0200f08bf012506fb05f504fb05f54fead5258df8d9504ff00d0508bf022506fb05f504fb05f54fead5258df8da504ff00c0508bf032506fb05f504fb05f54fead5258df8db504ff00b0508bf042506fb05f504fb05f54fead5258df8dc504ff00a0508bf052506fb05f504fb05f54fead5258df8dd504ff0090508bf062506fb05f504fb05f54fead5258df8de504ff0080508bf072506fb05f504fb05f54fead5258df8df504ff0070508bf082506fb05f504fb05f54fead5258df8e0504ff0060508bf092506fb05f504fb05f54fead5258df8e1504ff0050508bf0a2506fb05f504fb05f54fead5258df8e2504ff0040508bf0b2506fb05f504fb05f54fead5258df8e3504ff0030508bf0c2506fb05f504fb05f54fead5258df8e4504ff0020508bf0d2506fb05f504fb05f54fead5258df8e5504ff0010508bf0e2506fb05f504fb05f54fead5258df8e6504ff0000508bf0f256e436643f60a00288df8e76040f0f486120642ea0e412b9a380602eb21452e9940ea0340ddf854a0acf1010601eb204000240d90cdf844c00f9607e001f01f000b3801346445054400f0478742a850f82410b1f1ff3ff1dd23469e421cd042a800eb83004268b2f1ff3f16dc0133b34212d08268b2f1ff3f0fdc0133b3420bd0c268b2f1ff3f08dc0133b34204d002690133002ae1d400e0002250463aab35af009701f06efa002800f0a48635990029189100f0b1819df8f0009df8f110129450ea01201495289000f096819df8f4709df8f5603f0447ea06670e9e289d9df8ef009df8ee102e4406eb27470d9e020241ea00249df8f2009df8f330f71b00042797149d012740ea036007eb54060a44031405eb20401696561e1c941996ee1801f00304e91a431c1393831c1093189bc9075d1c07eb52031f94121b00242e91f10726932d922b9106e0289901348c4226990d4400f0508127990919f5d4229a9142f2d21c9a002aefd0dde91a324ff0000a01fb032e199924940329239580f099801f99dde923540029ded01899169a012704fb02132f994fea5a029a5c01f0100187ea111c02f00f01d5b25feaca7b08bf29090a46002918bf012242ea0c02012a14d11aeb000611d44e450fd272081ef8025018f8011005f00f0705f0f0050d43f60708bf47ea01150ef802501f99dde923540129a8d00af101014908595cbbf1000fcab24fea121208bf01f00f02d1b2002918bf012141ea0c01012917d1139911eb0a0113d4494511d24d081ef8056018f8022006f00f0706f0f0061643c90708bf47ea02160ef80560dde923541f9902293ff479af0af102014908595cbbf1000fcab201f00f0108bf11090a46002918bf012242ea0c02012a7ff465af109a1aeb02033ff560af4b45bff45daf5a081ef8027018f8011007f00f0607f0f0070f43db0708bf46ea0117249c0ef802704ae7ac4608e000bf2d990af1040a51450cf1020c3ff45caf2f991cf8013c01f010010122deb2002382ea11110f2e88bf01230b43012b00eb0a031ad1002b18d44b4516d235095e081ef8062018f8055002f00f0802f0f0025feac07942ea0502ddf8b09008bf48ea05120df1d8080ef806201cf8012c12f00f06324618bf01220a43012a19d15d1c17d44d4515d26a081ef8025018f80660c346ddf8b88005f00f0747ea0617b8f1000fd84605f0f00508bf45ea06070ef802709cf80020d6b200220f2e88bf01220a43012a17d19d1c15d44d4513d26d0832091ef8056018f8022004462b9806f00f0706f0f00616430028204608bf47ea02160ef805609cf8002012f00f06324618bf0122114301297ff47aafd91c3ff577af4945bff474af49081ef8012018f8063002f00f052e9e45ea031502f0f002002e08bf42ea03050ef8015060e74af20d313aa8c0f24e0188479df8ec009df8ed10dde9145a0f9edde911c405e09df8ec009df8ed10ddf844c040ea01200be6d0f86c114ff0ff3b002900f0e084012e00f2dd8451f82400002800f0d884401a820740f0d4846ff4403240f60f030244cff6fd739a42c0f0ca840b1853f8081ca14240f0c48453f80c7c0022a7f10111cff6ff729142c0f0ba8453f8041c2893b94240f0b484c0f540308742279700f2ae842898002800f0aa842798c128c0f0a68428980078012840f0a1844fea88670f2408f00f0604eae777774389246743ff0a8df8d8700e279af802109af803309af804009af8052018f0200f08bf012706fb07f704fb07f74fead7278df8d9704ff00d0708bf022706fb07f704fb07f74fead7278df8da704ff00c0708bf032706fb07f704fb07f74fead7278df8db704ff00b0708bf042706fb07f704fb07f74fead7278df8dc704ff00a0708bf052706fb07f704fb07f74fead7278df8dd704ff0090708bf062706fb07f704fb07f74fead7278df8de704ff0080708bf072706fb07f704fb07f74fead7278df8df704ff0070708bf082706fb07f704fb07f74fead7278df8e0704ff0060708bf092706fb07f704fb07f74fead7278df8e1704ff0050708bf0a2706fb07f704fb07f74fead7278df8e2704ff0040708bf0b2706fb07f704fb07f74fead7278df8e3704ff0030708bf0c2706fb07f704fb07f74fead7278df8e4704ff0020708bf0d2706fb07f704fb07f74fead7278df8e5704ff0010708bf0e2706fb07f704fb07f74fead7278df8e6704ff0000708bf0f27774367434ff0000bff0a002d8df8e77000f0d5831b0643ea01412b9b4e4603eb2144110641ea004000142490c8f30010239028982f46a0f13f08a6e3b44240f2148201221ae20120019018463b46269f49460097774601f05bfe2798be4624990135b6448d424ff0000b80f2a8832f9ae94311448d42b8bf2946239a6fea4101114401295bdb1c9a4ff0ff3301fb11211f9a121b012a03eb420230db02fb02f38b422cdd169aa2eb440303f10807032f03f106021edb02fb02f68e421add052f03f1040218db02fb02f68e4214dd072f03f1020212db02fb02f68e420edd0434092fa3f1080203db5b438b421346dcdc083204e0013402e0023400e00334012c1edb0832931f5b438b4219dc022c16db131f5b438b4200f3b480022c0fd0931e5b438b4200f3af80042c08db02fb02f38b4200f3aa80043c02f10802e2d100242e9e2c9b291801fb06332d9904eb0a0210292899a1eb04073ff475af2b93b5fa85f11b9b490919434cd118998d4249d01599681e491bcdf888e01a958842b8bf01466fea41001499ba4608440128c0f2ab800f9900fb10101299a1eb08034ff0ff31012b01eb430179db01fb01f7874275dd5900a1f1090303f10807032f03f1060164db01fb01f6864260dd052f03f104015fdb01fb01f686425bdd072f03f102015adb01fb01f6864256dd08f10408092fa3f1080103db5b4383420b46dbdc08314ce022eae27c4f45a8bf4f46bc45bff625afbb465feacc70cdf888e00ad02b9b4fea5c00195c2d9a01f0f00111430cf1010c19544fea5c0ebeeb5b0f1cd22b98229f109a00eb5b0307eb0e010e4606f8012b9e4280f08480881c9842327080f08480ce1c9e4202707ed2043707eb0e0098423270e8d378e02b9800eb5c0074e0013c5ce7023c5ae7033c58e708f1010804e008f1020801e008f10308b8f1010f23db08318b1f5b4383421edcb8f1020f19db0b1f5b43834200f3cd80b8f1020f11d08b1e5b43834200f3c880b8f1040f09db01fb01f3834200f3c380b8f1040801f10801ded14ff00008139822eae27e00eb080ccc45cb46b8bfe346de454eda5feace700ad02b9b4fea5e00195c2d9a01f0f00111430ef1010e19544fea5e07b7eb5b0f18d22b98229b109d00eb5b06d919084600f8015bb04213d28a1cb242057021d2c81cb04215701cd20433da19b2420570ecd317e02b9800eb5e0213e0481c02e04a1c0fe030465feacb7107d0dc4505d20178119a01f00f011143017027982e9e62e002465feacb7007d0de4505d21078119900f00f000843107028996fea08000e18012001902b98269f494662463346009701f0aafc26eae67cca45a8bfca46d4453edad6465feacc700ad02b9b4fea5c00195c2d9a01f0f00111430cf1010c19544fea5c02b2eb5e0f18d22b98229f109d00eb5e03b818064606f8015b9e4211d2811c9942357010d2c61c9e420d700bd20437b91899423570ecd306e02b9800eb5c0102e0411c00e031465feace7007d0f44505d20878119a00f00f001043087027982e9e1a9dddf864a0ddf888e002e6a8f1010846e7a8f1020843e7a8f1030840e7a21bb2fa82f252090023cb4588bf01231a40002d2c9200f00e822e9a1f9612022e922d9a4fea590612022d921c9a0e941302239a734413441696bb4238bf1f4607eb0b030bf0010803f0010343442695042500eb0b0aa7eb030c25ea89030af001041593dde92e322e9444441344021b09eb0004013c6008139025ea840012901b982d9f269c0744781a09eb08070c9078081c904fea5b0011904fea5a0089ea0b0110904fea5c090120cdf8bc80b9f1010f88bf4fea5c00434408eb0b0600f0030720f003082498a3eb0e03ddf860e000eb530370081b900eeb5600451c03380a90c8071a9045980e9e289050080f904ff0ff3000eb5c0027906ff0010000eb5c002390981e09906ff00200cdf82cc000eb5c00ddf888c04ff0000a0d97079514920893199006e00af1010aa2454ff0000b00f00f812c996fea0a005246002918bf22181f982499289b104400fb03112f9808b9002005e01698159b085cd84000f00f002d902e9808b9002004e01398129b085cd84000011a9c93192b9003fb0ceb1b98002c1c9c584421441fd10f9af4f7e5ffddf888c0ddf860e02f9840b111992d9a1bf8010000f0f00010440bf801002e98269c0028b6d010992b9a1bf8010000f00f0010430bf80100ace72c9c03fb0cf7002c42d014980228ded30c9828991044099a01fb00200a990022394400eb09039f785c78279dc7f3031747ea041401eb09079542bc70c7d05c7810f80950c4f3031444ea0515239c7d709442bcd010f8095013f8014cc5f3031545ea0415199c01f809509442afd013f8015c13f8023cc5f30315043245ea031304389145a1f1040107f8013cc9d19ee7149b022b9bd30b9b082b01d200222ce00c9b289e1a44089b06fb023c079a174400220ceb02056c781cf80260c4f3031444ea0616bc1804f8016cae786b78c6f3031646ea0313bb54eb78ae78c3f3031343ea061363702b79ee780432c3f3031343ea06139045a370dbd10d9bddf888c00e9e002b3ff463af531ccf5c8e5cc7f3031747ea0617dde90d468754012c3ff456af971cce5dcd5cc6f3031646ea05160d9cc6540e9e022c3ff449af0a44d278c95dc2f3031242ea0111c1553fe7013f2fd016f8010b411e1f29f8d341b220290fdb08eb400118f81000497840ea0122c12a06d3dde927103aab00f0d3f80028e5d14ff0ff3b2199bbf1000f6fd120984f1c8742dde92902ddf830c500eb0204dde91d23ddf82ce5ddf828557df41eae63e042982b90249820eae070269004e020440b38013d04464ed019f8010b1f28f6d908eb400118f81000497840ea0122c12aced3dde927103aab00f09bf80028c7d02398ddf8b4a0049036a803903aa80290dde92e70ddf890b02c993a465346cdf804b0009400f01dfcdde93c013b46204401eb0b02b84224eae471b8bf03465245a8bf52468b42c4dd269fba42c1dd2b9f0f2fbed8269e179ca2eb060c2b9a5b1a04ebc20724f8321001327e80bb80a7f806c02b92ade74ff0000b8be74ff0ff300df2045dbde8f08fa01a18bf4ff0ff300df2045dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f91b00df1700b9be8400a10913169ddf868a0002900f05c813768bbf1000f40f05181874200f04e8199f80f100f2940f0498199f80e100e2940f0448199f80d100d2940f03f8199f80c100c2940f03a8199f80b100b2940f0358199f80a100a2940f0308199f80910092940f02b8199f80810082940f0268199f80710072940f0218199f80610062940f01c8199f80510052940f0178199f80410042940f0128199f80310032940f00d8199f80210022940f0088199f80110012940f0038199f80010002940f0fe80ddf86cc0caf10001d6f808e001eaea75ccf10001f76801eaec740895aeeb05062aeaea75391b2ceaec77521b9642a3eb07030d97b8bf32469942b8bf0b46012a0e930992c0f2ea820e990129c0f2e6820ef10101a4464c08089900eb55000c9048100b90042020ea81000790099801310138cde905014810049004fb0cf000f102094ff0000a0a94cde901c507e000bf0e980af1010a8245a14400f0bf821c98109bd0f800e00aeb0c0000fb04e20d980c9e504400fb0360eb0703d10b9edde9083810e00b9b2f46d35c079d0678eb4006f0f00603f00f03334400f8013b069bdde904683d469119da074fea58070f9208d13a468b466446f4f76ef9a4460a9c68e000bf8b46b8f1020f63d37a1e032a04d2002117f0030237d15be06ff0030202ea58034e44c3f1000c0eeb0601461c039700bf8d18ef78ac78c7f3031747ea0417b418e7702f79eb78c7f3031747ea031323716b792f79c3f3031343ea07136371ab796f79c3f30313043243ea07130ceb02070437a371dcd1dde901c50a9c039f111d17f0030224d04b1cbe461bf803701bf80160c7f3031747ea0617012a4754774616d08e1c1bf806701bf80350c7f3031747ea0517029d022ac754774608d05944c9781bf80620c1f3031141ea021181555feac8713ff45aaf0f9a1bf80710002a4ff0000208bf0422c35dd14003f00f0242ea0111c15549e7874200f09f815c460021aae17568002d00f0068200214ff0000e09e0dde90e71d8f804503944dde91d9ba94280f0f881ddf870800f91d8f80060775c3c0901d0012117e06d1a012d00f0ea8106eb010c9cf8016016b1344602210be0042dc0f0df819cf802509cf8036055ea062400f0d781042117f00f07bbfa8bf60e914fea561619f807b018bf012746ea07091b9f4fea0b1c14f00301754600f09980d8f808504ff00008befbf5f60d9106fb15e55544b5f1ff3fc8bf4ff0010809ea080101291ad1f61918d4954216d29e4214d210990b9406fb01046e08a15ded070c916ff00f05594604bf0f256146ddf8308005ea08052943a1550b9c0d99ddf8708001290ef1010563d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080b91895ded070c916ff00f05594604bf0f256146ddf8308005ea080529430b9dddf87080a9550d990ef10205022930d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080c91895ded070d916ff00f05594604bf0f256146ddf8348005ea080529430c9dddf87080a9550ef1030500bf611e0329a64405d220e700bf0435ae453ff41cafd8f808100024b5fbf1f606fb11515144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f808106c1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ac1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ec1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c7ff46aaff6193ff567af9142bff464af9e42bff461af109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa1554be71b995c46002901dd012108e0b1fa81f149090027baf1000fc8bf01273940d6f808e0f76807fb0ef8b8f1000f56d0b4fa84f4bb4600274ff0ff3c6409c9070e940f9106e001370bfb0ef84745acf1010c44d20f990ef101050029394618bf08eb0c01b1fbfef46d0804fb1e161c99096804fb05117508495d042525ea8605e94011f00f08454618bf01250e990d43012dd8d116eb0a065cbf1b9d14eb0504d1d49642cfd29c42cdd2109d19f8081004fb050e74081ef80450f60705f00f0805f0f00545ea010508bf48ea01151c990ef80450d1f808e0d1f80cb0b3e711b0bde8f08f00bf2de9f04fc8b0dde95162549f1644ba1926eae6778a42b8bf11468f42039080f203815698cde90071a0f1030a6ff007076ff004044ff0000b0df1200e4ff000090293cdf810a000bf56984fea5903c05c4ff0100c00f0f0080590cde9064700bf1af8041f0eeb07001af8012c9af8013048ea121602f00f0242ea0802427248ea111201f00f01827241ea08010eeb0402117248ea13119af802500672517203f00f0141ea0801917248ea1511817305f00f0141ea08010837bcf1080c04f10804c173cdd10598ddf810a00401102753465d4600bf13f8040f0eeb050213f8011c5e7844ea111801f00f012143517444ea101100f00f002043d07444ea161093f802c0107506f00f002043507544ea1c1090750cf00f002043083f05f1080582f810809174d075d5d1079f069c09f1020920372034b9f1100f0bf1200b84d15598029bdde90086539900286dd00844079008f10100069003984fea580a03fb01074fea660c4feac87b06e000bf079809f1010181421f4457d20398894601fb0301bbf1000f45460bd011f80a00069d1ef8002000f0f00002f00f02104401f80a00bceb550f28dd680801eb0c033e4600bf315c06eb00081ef80120414601f8012b99421ed20a7808f102041ef802209c420a7018d221781ef80110217008f103049c4210d2217804361ef80110217034189c42ddd307e000bf01eb5504f00707d1b4e708f10104029bdde90086f007add0b542abda20781ef8001000f00f0001f0f00108442070a1e748b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf7a4fc69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae72de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041b1e022eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70f9f750fd002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f7e1fc00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f8f788fde0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f7f4f902a9284600224ff0000afbf7a5fc81464046f7f7b9fab9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f7b7fc06f1210506f1280029460722f2f7affc284621460722f2f7aafc20465146032207f10905f2f7a3fc06f11d0049460422f2f79dfcf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f771fca81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f737fc012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f71efc572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f707fc312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f7f1fb462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f7dafb362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f76ffbcde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f750fb8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f751fa284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f7fdf9002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f7cbf904a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f7b7f90020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f7a0f9352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f77cf904a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f769f9002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f755f904a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f731f904f14f0051460722f2f72bf984f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f79df884f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f1f7b3ff284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f7f7adfe0028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3237000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "1c483a00", + "new": "e84d3a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "9c483a00", + "new": "684e3a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "1c483a04", + "new": "e84d3a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "b66f5542", + "new": "e5d1780a", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "d0697cd9", + "new": "e2593a34", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "d0697cd9", + "new": "e2593a34", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/graphics/image.ts b/app/graphics/image.ts index 0fe17b97..8541ab7c 100644 --- a/app/graphics/image.ts +++ b/app/graphics/image.ts @@ -395,7 +395,7 @@ export class GrayImage { hash = mixInt(hash, placed.source.width); hash = mixInt(hash, placed.source.height); hash = mixInt(hash, placed.source.sourceContentHash32()); - if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0, p.animation?.token ?? 0, p.animation?.dx ?? 0, p.animation?.dy ?? 0]) hash = mixInt(hash, value); } + if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0, p.animation?.token ?? 0, p.animation?.dx ?? 0, p.animation?.dy ?? 0, p.animation?.durationMs ?? 0]) hash = mixInt(hash, value); } } else { hash = mixInt(hash, 0xf17e); hash = mixInt(hash, placed.font.atlasTag); diff --git a/app/graphics/presentation-wire.ts b/app/graphics/presentation-wire.ts index 2c58b546..486b5992 100644 --- a/app/graphics/presentation-wire.ts +++ b/app/graphics/presentation-wire.ts @@ -1,4 +1,5 @@ import type { PlacedImage } from './image' +import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion' /** Bridge record: tag 3 (selection), 4 (image), 5 (gray8-masked image), 6 (animated selection), signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, gray pixels, restore rectangles. */ export function encodePresentation(draw: PlacedImage): Uint8Array { @@ -8,7 +9,8 @@ export function encodePresentation(draw: PlacedImage): Uint8Array { if (!Number.isInteger(p.depth) || p.depth < -128 || p.depth > 127) throw new Error('Invalid menu depth') if ((p.occlusions?.length ?? 0) > 2048) throw new Error('Too many menu occlusion rectangles') const animation = p.animation; - const header = animation ? 26 : 16; + if (animation && (!Number.isInteger(animation.durationMs) || animation.durationMs < 1 || animation.durationMs > 65535)) throw new Error('Invalid menu animation duration') + const header = animation ? 28 : 16; const bytes = new Uint8Array(header + width * height + (p.occlusions?.length ?? 0) * 8), view = new DataView(bytes.buffer) bytes[0] = animation ? 6 : p.mode === "image" ? 4 : p.mode === "masked-image" ? 5 : 3 view.setInt16(1, draw.x, true); view.setInt16(3, draw.y, true) @@ -17,8 +19,9 @@ export function encodePresentation(draw: PlacedImage): Uint8Array { view.setUint16(14, p.occlusions?.length ?? 0, true) if (animation) { view.setInt16(16, animation.dx, true); view.setInt16(18, animation.dy, true); - view.setUint16(20, Math.max(0, Math.min(500, Date.now() - animation.startedAt)), true); + view.setUint16(20, Math.max(0, Math.min(animation.durationMs, Date.now() - animation.startedAt)), true); view.setUint32(22, animation.token, true); + view.setUint16(26, animation.durationMs, true); } bytes.set(pixels, header) let offset = header + pixels.length @@ -29,15 +32,19 @@ export function encodePresentation(draw: PlacedImage): Uint8Array { return bytes } -export type Selection = { animation?: { dx: number; dy: number; startedAt: number; token: number }; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } +export type Selection = { animation?: MenuHighlightAnimation; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } export function readPresentation(bytes: Uint8Array, offset: number): { selection: Selection; end: number } { const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), w = v.getUint16(offset + 5, true), h = v.getUint16(offset + 7, true) - const header = bytes[offset] === 6 ? 26 : 16 + const header = bytes[offset] === 6 ? 28 : 16 const selection: Selection = { mode: bytes[offset] === 4 ? "image" : bytes[offset] === 5 ? "masked-image" : undefined, x: v.getInt16(offset+1,true), y: v.getInt16(offset+3,true), width:w, height:h, radius:v.getUint16(offset+9,true), background:bytes[offset+11]!, border:bytes[offset+12]!, depth:v.getInt8(offset+13), pixels:bytes.slice(offset+header,offset+header+w*h), occlusions:[] } - if (header === 26) selection.animation = { dx:v.getInt16(offset+16,true), dy:v.getInt16(offset+18,true), - startedAt:Date.now()-v.getUint16(offset+20,true), token:v.getUint32(offset+22,true) } + if (header === 28) { + const durationMs = v.getUint16(offset+26,true), elapsed = v.getUint16(offset+20,true) + if (!durationMs || elapsed > durationMs) throw new Error('Invalid menu animation timing') + selection.animation = { dx:v.getInt16(offset+16,true), dy:v.getInt16(offset+18,true), + startedAt:Date.now()-elapsed, token:v.getUint32(offset+22,true), durationMs } + } let end=offset+header+w*h for(let i=0;i 0 && elapsedMs >= 0) if (from == to || elapsedMs >= durationMs) return Integer(to) val code = ByteSink() diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt index 2f9915b5..efdaa23f 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt @@ -3,14 +3,14 @@ package com.faceclaw.app /** A retained selection or image, replayed at stereo depth over the screen and shell surfaces. */ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val radius: Int, val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = 3, val mask: List = emptyList(), val animation: Animation? = null) { - class Animation(val dx: Int, val dy: Int, val startedAt: Long, val token: Int) + class Animation(val dx: Int, val dy: Int, val startedAt: Long, val token: Int, val durationMs: Int) val resource = CachedResource(DrawProtocol.rawImage(width, height, packed)) - val fingerprint = "${animation?.token},${animation?.dx},${animation?.dy},$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" + val fingerprint = "${animation?.token},${animation?.dx},${animation?.dy},${animation?.durationMs},$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" fun translated(dx: Int, dy: Int) = MenuSelection(x + dx, y + dy, width, height, radius, background, border, depth, packed, occlusions.map { intArrayOf(it[0] + dx, it[1] + dy, it[2], it[3]) }, kind, mask, animation) fun calls(id: Int, nowMs: Long = drawAnimationTimeMs()): List { - val elapsed = animation?.let { (nowMs - it.startedAt).coerceIn(0, 500).toInt() } ?: 500 - val highlightX = animation?.let { DrawValue.animate(x + it.dx, x, 500, elapsed) } ?: DrawValue.Integer(x) - val highlightY = animation?.let { DrawValue.animate(y + it.dy, y, 500, elapsed) } ?: DrawValue.Integer(y) + val elapsed = animation?.let { (nowMs - it.startedAt).coerceIn(0, it.durationMs.toLong()).toInt() } ?: 0 + val highlightX = animation?.let { DrawValue.animate(x + it.dx, x, it.durationMs, elapsed) } ?: DrawValue.Integer(x) + val highlightY = animation?.let { DrawValue.animate(y + it.dy, y, it.durationMs, elapsed) } ?: DrawValue.Integer(y) val image = when (kind) { 3 -> listOf(DrawProtocol.roundedRect(highlightX, highlightY, width, height, radius, background, border, depth), DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) @@ -43,12 +43,14 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val require(count <= 2048) require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) val animation = if (kind == 6) { - require(reader.remaining() >= 10) + require(reader.remaining() >= 12) val dx = reader.getShort().toInt() val dy = reader.getShort().toInt() val elapsed = reader.getShort().toInt() and 65535 - require(elapsed <= 500) - Animation(dx, dy, drawAnimationTimeMs() - elapsed, reader.getInt()) + val token = reader.getInt() + val duration = reader.getShort().toInt() and 65535 + require(duration > 0 && elapsed <= duration) + Animation(dx, dy, drawAnimationTimeMs() - elapsed, token, duration) } else null val gray = ByteArray(w * h); reader.get(gray) require(reader.remaining() >= count * 8) diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt index 330bc4ba..604b8d82 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt @@ -61,30 +61,31 @@ class DrawExpressionTest { } @Test fun smoothstepCoordinatesMatchFirmwareAndSurvivePresentTimeReset() { - val value = DrawValue.animate(10, 110) as DrawValue.Expression + val value = DrawValue.animate(10, 110, 500) as DrawValue.Expression val code = "010a3001806e300181f432010010300181f43023414031" assertContentEquals(hex(code), value.program) for ((time, expected) in listOf(0L to 10, 125L to 25, 250L to 60, 375L to 94, 500L to 110, 900L to 110)) { assertEquals(expected to (time < 500), evaluate(value.program, time)) } - val continued = DrawValue.animate(10, 110, elapsedMs = 250) as DrawValue.Expression + val continued = DrawValue.animate(10, 110, 500, elapsedMs = 250) as DrawValue.Expression assertEquals(60 to true, evaluate(continued.program, 0)) assertEquals(110 to false, evaluate(continued.program, 250)) } @Test fun animatedMenuBridgePreservesElapsedTimeAndTranslation() { - // Tag 6 record emitted by the TypeScript bridge: elapsed=200, delta=(-2,-4). - val wire = hex("06030002000200020001001030020000fefffcffc8002a000000ffffffff") + // Tag 6 record emitted by the TypeScript bridge: elapsed=200, delta=(-2,-4), duration=300. + val wire = hex("06030002000200020001001030020000fefffcffc8002a0000002c01ffffffff") val input = ArrayByteReader(wire) assertEquals(6, input.get().toInt()) val row = MenuSelection.read(input, 6).translated(10, 10) assertEquals(0, input.remaining()) val motion = assertNotNull(row.animation) assertEquals(42, motion.token) + assertEquals(300, motion.durationMs) assertEquals(-2, motion.dx) assertEquals(-4, motion.dy) val call = row.calls(7, motion.startedAt + 200).first() - for ((elapsed, expected) in listOf(0L to (11 to 9), 300L to (13 to 12))) { + for ((elapsed, expected) in listOf(0L to (12 to 10), 100L to (13 to 12))) { val reader = DrawReader(call) assertEquals(8, reader.readU8()) assertEquals(DRAW_FLAG_DEPTH, reader.readU8()) @@ -92,15 +93,29 @@ class DrawExpressionTest { val frame = DrawEvaluation(elapsed) assertEquals(expected.first, ExtendedVarint.evaluate(reader, frame)) assertEquals(expected.second, ExtendedVarint.evaluate(reader, frame)) - assertEquals(elapsed < 300, frame.animationPending) + assertEquals(elapsed < 100, frame.animationPending) } for (end in 1 until wire.size) assertFails { MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), 6) } } + @Test fun menuCoordinatesUseTheSuppliedDuration() { + val row = MenuSelection(0, 4, 2, 2, 0, 15, 16, 0, ByteArray(2), + animation = MenuSelection.Animation(0, -4, 1000, 42, 120)) + val call = row.calls(7, 1000).first() + for ((elapsed, y) in listOf(0L to 0, 60L to 2, 120L to 4)) { + val reader = DrawReader(call) + reader.readBytes(3) // opcode, flags, depth + val frame = DrawEvaluation(elapsed) + assertEquals(0, ExtendedVarint.evaluate(reader, frame)) + assertEquals(y, ExtendedVarint.evaluate(reader, frame)) + assertEquals(elapsed < 120, frame.animationPending) + } + } + @Test fun playerSchedulesOnlyUnfinishedFramesAndCancelsStaleCallbacks() { - val call = DrawProtocol.roundedRect(DrawValue.Integer(0), DrawValue.animate(0, 4), 2, 2, 0, 15) + val call = DrawProtocol.roundedRect(DrawValue.Integer(0), DrawValue.animate(0, 4, 300), 2, 2, 0, 15) val renderer = DisplayListRenderer(mapOf(1 to DrawProtocol.displayList(listOf(call)))) val screen = DisplayListRenderer.Target(ByteArray(16), 4, 8) val output = DisplayListRenderer.Target(ByteArray(16), 4, 8) @@ -116,7 +131,7 @@ class DrawExpressionTest { player.present(1) assertEquals(15, output.get(0, 0)) val first = queued.removeAt(0) - now += 250 + now += 150 first() assertEquals(15, output.get(0, 2)) assertEquals(0, output.get(0, 0)) @@ -125,7 +140,7 @@ class DrawExpressionTest { assertEquals(15, output.get(0, 0)) stale() assertEquals(3, displayed) - now += 500 + now += 300 queued.removeAt(0)() assertEquals(15, output.get(0, 4)) assertFalse(renderer.animationPending) diff --git a/tests/menu-highlight-motion.test.cjs b/tests/menu-highlight-motion.test.cjs index a1417dfb..f74279b9 100644 --- a/tests/menu-highlight-motion.test.cjs +++ b/tests/menu-highlight-motion.test.cjs @@ -1,8 +1,8 @@ const test = require('node:test'); const assert = require('node:assert/strict'); -const { MenuHighlightMotion } = require('../.test-build/app/ui/menu-highlight-motion.js'); +const { MenuHighlightMotion, MENU_HIGHLIGHT_DURATION_MS } = require('../.test-build/app/ui/menu-highlight-motion.js'); const { GrayImage } = require('../.test-build/app/graphics/image.js'); -const { encodePresentation, readPresentation } = require('../.test-build/app/graphics/presentation-wire.js'); +const { encodePresentation, readPresentation, paintPresentation } = require('../.test-build/app/graphics/presentation-wire.js'); test('highlight animates only navigation that preserves the scroll window', () => { const motion = new MenuHighlightMotion(); @@ -11,9 +11,10 @@ test('highlight animates only navigation that preserves the scroll window', () = const moved = motion.paint(1, 0, 10, 40, 100, 20, 100); assert.equal(moved.dx, 0); assert.equal(moved.dy, -20); - assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 350).token, moved.token); + assert.equal(moved.durationMs, 300); + assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 250).token, moved.token); motion.navigate(1, false); - const next = motion.paint(2, 0, 10, 60, 100, 20, 350); + const next = motion.paint(2, 0, 10, 60, 100, 20, 250); assert.equal(next.dy, -30, 'continue from the halfway position'); motion.navigate(2, false); assert.equal(motion.paint(3, 1, 10, 60, 100, 20, 400), undefined, 'scroll snaps'); @@ -21,23 +22,45 @@ test('highlight animates only navigation that preserves the scroll window', () = assert.equal(motion.paint(0, 0, 10, 20, 100, 20, 500), undefined, 'wrap snaps'); motion.navigate(0, false); motion.paint(1, 0, 10, 40, 100, 20, 600); - assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 1100), undefined, 'finished after 500 ms'); + assert.ok(motion.paint(1, 0, 10, 40, 100, 20, 899)); + assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 900), undefined, 'finished after 300 ms'); assert.equal(motion.paint(2, 0, 10, 60, 100, 20, 1200), undefined, 'programmatic changes snap'); }); +test('bridge and fallback preview use the supplied animation duration', () => { + const now = Date.now; + Date.now = () => 1050; + try { + const image = new GrayImage(8, 2); + image.drawMenuSelection(new GrayImage(2, 2), 5, 0, 0, 255, 0, 0, + { dx: -4, dy: 0, startedAt: 1000, token: 1, durationMs: 100 }); + const record = readPresentation(encodePresentation(image.draws[0]), 0); + assert.equal(record.selection.animation.durationMs, 100); + const screen = new Uint8Array(16), output = new Uint8Array(16); + paintPresentation(output, screen, 8, 2, record.selection); + assert.equal(output[3], 240, 'halfway at 50 ms'); + assert.equal(output[1], 0); + Date.now = () => 1100; + output.fill(0); + paintPresentation(output, screen, 8, 2, record.selection); + assert.equal(output[5], 240, 'complete at 100 ms'); + assert.equal(output[3], 0); + } finally { Date.now = now; } +}); + test('animated selection bridge carries relative start, elapsed time and stable token', () => { const now = Date.now; Date.now = () => 1200; try { const image = new GrayImage(8, 4); image.drawMenuSelection(new GrayImage(2, 2, 255), 3, 2, 16, 48, 1, 2, - { dx: -2, dy: -4, startedAt: 1000, token: 42 }); + { dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS }); const bytes = encodePresentation(image.draws[0]); assert.equal(bytes[0], 6); - assert.equal(bytes.length, 30); + assert.equal(bytes.length, 32); const record = readPresentation(bytes, 0); assert.equal(record.end, bytes.length); - assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42 }); + assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS }); assert.equal(record.selection.x, 3); assert.equal(record.selection.y, 2); } finally { Date.now = now; } From 063d8a0b037337b39bc521d1292b8237b77b00b2 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Wed, 23 Sep 2026 11:34:20 -0700 Subject: [PATCH 16/27] Clean up magic-numbers used in menu animation --- app/graphics/glyph-wire.ts | 8 ++-- app/graphics/presentation-wire.ts | 37 ++++++++++++++----- .../faceclaw/app/graphics/DrawRecordKind.kt | 17 +++++++++ .../faceclaw/app/graphics/MenuSelection.kt | 21 ++++++----- .../app/graphics/SurfaceCompositor.kt | 8 ++-- .../com/faceclaw/app/DrawExpressionTest.kt | 4 +- 6 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DrawRecordKind.kt diff --git a/app/graphics/glyph-wire.ts b/app/graphics/glyph-wire.ts index bfd1c5bd..624137ec 100644 --- a/app/graphics/glyph-wire.ts +++ b/app/graphics/glyph-wire.ts @@ -1,4 +1,4 @@ -import { encodePresentation } from "./presentation-wire"; +import { DrawRecordKind, encodePresentation } from "./presentation-wire"; /** * Marshals deferred-draw identity (text glyphs and icon images) to the Kotlin * side for the texture-cache pipeline (CFW modes 18/19/20; see @@ -201,7 +201,7 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | if (!inRange16(placed.x) || !inRange16(placed.y)) continue; const state = fontWireState(placed.font); if (!state || !representableGlyph(placed.font, placed.glyph)) continue; - out.setUint8(offset, 0); + out.setUint8(offset, DrawRecordKind.GLYPH); out.setUint16(offset + 1, state.fontId, true); out.setUint32(offset + 3, placed.glyph.encoding, true); out.setInt16(offset + 7, placed.x, true); @@ -213,14 +213,14 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | if (placed.presentation) { const bytes = encodePresentation(placed); new Uint8Array(out.buffer).set(bytes, offset); offset += bytes.length; continue; } const id = imageId(placed); if (id === null) continue; - out.setUint8(offset, 1); + out.setUint8(offset, DrawRecordKind.TEXTURE_IMAGE); out.setUint32(offset + 1, id, true); out.setInt16(offset + 5, placed.x, true); out.setInt16(offset + 7, placed.y, true); offset += IMAGE_RECORD_BYTES; } else { if (!fwRunOk.get(placed)) continue; - out.setUint8(offset, 2); + out.setUint8(offset, DrawRecordKind.FIRMWARE_TEXT); out.setInt16(offset + 1, placed.x, true); out.setInt16(offset + 3, placed.y, true); out.setUint8(offset + 5, placed.value); diff --git a/app/graphics/presentation-wire.ts b/app/graphics/presentation-wire.ts index 486b5992..4dca3be1 100644 --- a/app/graphics/presentation-wire.ts +++ b/app/graphics/presentation-wire.ts @@ -1,7 +1,23 @@ import type { PlacedImage } from './image' import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion' -/** Bridge record: tag 3 (selection), 4 (image), 5 (gray8-masked image), 6 (animated selection), signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, gray pixels, restore rectangles. */ +/** TS/native bridge tags, not firmware draw opcodes. Keep in sync with DrawRecordKind.kt. */ +export const DrawRecordKind = { + GLYPH: 0, + TEXTURE_IMAGE: 1, + FIRMWARE_TEXT: 2, + MENU_SELECTION: 3, + TRANSPARENT_IMAGE: 4, + MASKED_IMAGE: 5, + ANIMATED_MENU_SELECTION: 6, +} as const + +export function isPresentationKind(kind: number | undefined): boolean { + return kind === DrawRecordKind.MENU_SELECTION || kind === DrawRecordKind.TRANSPARENT_IMAGE || + kind === DrawRecordKind.MASKED_IMAGE || kind === DrawRecordKind.ANIMATED_MENU_SELECTION +} + +/** Presentation record: tag, signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, optional animation, gray pixels, restore rectangles. */ export function encodePresentation(draw: PlacedImage): Uint8Array { const p = draw.presentation! const { width, height, pixels } = draw.source @@ -12,7 +28,9 @@ export function encodePresentation(draw: PlacedImage): Uint8Array { if (animation && (!Number.isInteger(animation.durationMs) || animation.durationMs < 1 || animation.durationMs > 65535)) throw new Error('Invalid menu animation duration') const header = animation ? 28 : 16; const bytes = new Uint8Array(header + width * height + (p.occlusions?.length ?? 0) * 8), view = new DataView(bytes.buffer) - bytes[0] = animation ? 6 : p.mode === "image" ? 4 : p.mode === "masked-image" ? 5 : 3 + bytes[0] = animation ? DrawRecordKind.ANIMATED_MENU_SELECTION + : p.mode === "image" ? DrawRecordKind.TRANSPARENT_IMAGE + : p.mode === "masked-image" ? DrawRecordKind.MASKED_IMAGE : DrawRecordKind.MENU_SELECTION view.setInt16(1, draw.x, true); view.setInt16(3, draw.y, true) view.setUint16(5, width, true); view.setUint16(7, height, true); view.setUint16(9, p.radius, true) bytes[11] = p.background; bytes[12] = p.border; view.setInt8(13, p.depth) @@ -35,11 +53,12 @@ export function encodePresentation(draw: PlacedImage): Uint8Array { export type Selection = { animation?: MenuHighlightAnimation; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } export function readPresentation(bytes: Uint8Array, offset: number): { selection: Selection; end: number } { const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), w = v.getUint16(offset + 5, true), h = v.getUint16(offset + 7, true) - const header = bytes[offset] === 6 ? 28 : 16 - const selection: Selection = { mode: bytes[offset] === 4 ? "image" : bytes[offset] === 5 ? "masked-image" : undefined, x: v.getInt16(offset+1,true), y: v.getInt16(offset+3,true), width:w, height:h, + const kind = bytes[offset] + const header = kind === DrawRecordKind.ANIMATED_MENU_SELECTION ? 28 : 16 + const selection: Selection = { mode: kind === DrawRecordKind.TRANSPARENT_IMAGE ? "image" : kind === DrawRecordKind.MASKED_IMAGE ? "masked-image" : undefined, x: v.getInt16(offset+1,true), y: v.getInt16(offset+3,true), width:w, height:h, radius:v.getUint16(offset+9,true), background:bytes[offset+11]!, border:bytes[offset+12]!, depth:v.getInt8(offset+13), pixels:bytes.slice(offset+header,offset+header+w*h), occlusions:[] } - if (header === 28) { + if (kind === DrawRecordKind.ANIMATED_MENU_SELECTION) { const durationMs = v.getUint16(offset+26,true), elapsed = v.getUint16(offset+20,true) if (!durationMs || elapsed > durationMs) throw new Error('Invalid menu animation timing') selection.animation = { dx:v.getInt16(offset+16,true), dy:v.getInt16(offset+18,true), @@ -53,10 +72,10 @@ export function presentationRecords(buffer: ArrayBuffer | null): Selection[] { if (!buffer) return [] const bytes=new Uint8Array(buffer), result:Selection[]=[] for(let p=0;p true + else -> false + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt index efdaa23f..c386a6e4 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt @@ -2,7 +2,7 @@ package com.faceclaw.app /** A retained selection or image, replayed at stereo depth over the screen and shell surfaces. */ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val radius: Int, - val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = 3, val mask: List = emptyList(), val animation: Animation? = null) { + val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = DrawRecordKind.MENU_SELECTION, val mask: List = emptyList(), val animation: Animation? = null) { class Animation(val dx: Int, val dy: Int, val startedAt: Long, val token: Int, val durationMs: Int) val resource = CachedResource(DrawProtocol.rawImage(width, height, packed)) val fingerprint = "${animation?.token},${animation?.dx},${animation?.dy},${animation?.durationMs},$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" @@ -12,12 +12,12 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val val highlightX = animation?.let { DrawValue.animate(x + it.dx, x, it.durationMs, elapsed) } ?: DrawValue.Integer(x) val highlightY = animation?.let { DrawValue.animate(y + it.dy, y, it.durationMs, elapsed) } ?: DrawValue.Integer(y) val image = when (kind) { - 3 -> listOf(DrawProtocol.roundedRect(highlightX, highlightY, width, height, radius, background, border, depth), + DrawRecordKind.MENU_SELECTION -> listOf(DrawProtocol.roundedRect(highlightX, highlightY, width, height, radius, background, border, depth), DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) - 4 -> listOf(DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) + DrawRecordKind.TRANSPARENT_IMAGE -> listOf(DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) // Gray8 zero is transparent but gray8 one is opaque black. Rect copies preserve // that distinction after packing, including the transparent corners of app menus. - 5 -> mask.map { rect -> + DrawRecordKind.MASKED_IMAGE -> mask.map { rect -> DrawProtocol.rectCopy(id, rect[0], rect[1], rect[2], rect[3], x + rect[0], y + rect[1], depth = depth) } @@ -29,9 +29,9 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val } companion object { - /** The caller has consumed the presentation tag (3–6). Colors cross the bridge in gray8, pixels in gray8 rows. */ - fun read(reader: ByteReader, kind: Int = 3): MenuSelection { - require(kind in 3..6) + /** The caller has consumed a presentation tag from [DrawRecordKind]. Colors and pixels cross in gray8. */ + fun read(reader: ByteReader, kind: Int = DrawRecordKind.MENU_SELECTION): MenuSelection { + require(DrawRecordKind.isPresentation(kind)) require(reader.remaining() >= 15) val x = reader.getShort().toInt(); val y = reader.getShort().toInt() val w = reader.getShort().toInt() and 65535; val h = reader.getShort().toInt() and 65535 @@ -42,7 +42,7 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val val count = reader.getShort().toInt() and 65535 require(count <= 2048) require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) - val animation = if (kind == 6) { + val animation = if (kind == DrawRecordKind.ANIMATED_MENU_SELECTION) { require(reader.remaining() >= 12) val dx = reader.getShort().toInt() val dy = reader.getShort().toInt() @@ -56,7 +56,7 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val require(reader.remaining() >= count * 8) val occlusions = List(count) { IntArray(4) { reader.getShort().toInt() and 65535 } } val mask = ArrayList() - if (kind == 5) for (yy in 0 until h) { + if (kind == DrawRecordKind.MASKED_IMAGE) for (yy in 0 until h) { var start = -1 for (xx in 0..w) { val covered = xx < w && gray[yy * w + xx].toInt() != 0 @@ -68,7 +68,8 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val } } } - return MenuSelection(x, y, w, h, radius, background, border, depth, BmpUtil.pack4bppFromGray8(gray, w, h), occlusions, if (kind == 6) 3 else kind, mask, animation) + val normalizedKind = if (kind == DrawRecordKind.ANIMATED_MENU_SELECTION) DrawRecordKind.MENU_SELECTION else kind + return MenuSelection(x, y, w, h, radius, background, border, depth, BmpUtil.pack4bppFromGray8(gray, w, h), occlusions, normalizedKind, mask, animation) } } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index 3a0c19bf..c862d47d 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -51,7 +51,7 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr var out: MutableList = ArrayList() while ((cursor.remaining() >= 1)) { var kind: Int = (cursor.get() and 0xff) - if (kind in 3..6) { out.add(ScreenDraw.image(0, 0, 0).also { it.selection = MenuSelection.read(cursor, kind) }); continue } + if (DrawRecordKind.isPresentation(kind)) { out.add(ScreenDraw.image(0, 0, 0).also { it.selection = MenuSelection.read(cursor, kind) }); continue } if (((kind == ScreenDraw.KIND_GLYPH) && (cursor.remaining() >= 11))) { var fontId: Int = (cursor.getShort().toInt() and 0xffff) var encoding: Int = cursor.getInt() @@ -110,12 +110,12 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr class ScreenDraw { @JvmField var selection: MenuSelection? = null companion object { - const val KIND_GLYPH: Int = 0 + const val KIND_GLYPH: Int = DrawRecordKind.GLYPH - const val KIND_IMAGE: Int = 1 + const val KIND_IMAGE: Int = DrawRecordKind.TEXTURE_IMAGE /** A firmware-builtin-font text run (CFW mode 15). */ - const val KIND_FWTEXT: Int = 2 + const val KIND_FWTEXT: Int = DrawRecordKind.FIRMWARE_TEXT @JvmStatic fun glyph(fontId: Int, encoding: Int, penX: Int, lineY: Int, value: Int): ScreenDraw { diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt index 604b8d82..dae59f65 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt @@ -77,7 +77,7 @@ class DrawExpressionTest { val wire = hex("06030002000200020001001030020000fefffcffc8002a0000002c01ffffffff") val input = ArrayByteReader(wire) assertEquals(6, input.get().toInt()) - val row = MenuSelection.read(input, 6).translated(10, 10) + val row = MenuSelection.read(input, DrawRecordKind.ANIMATED_MENU_SELECTION).translated(10, 10) assertEquals(0, input.remaining()) val motion = assertNotNull(row.animation) assertEquals(42, motion.token) @@ -96,7 +96,7 @@ class DrawExpressionTest { assertEquals(elapsed < 100, frame.animationPending) } for (end in 1 until wire.size) assertFails { - MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), 6) + MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), DrawRecordKind.ANIMATED_MENU_SELECTION) } } From 440674b261c808d848fb0e375eb3a2127cc6bcac Mon Sep 17 00:00:00 2001 From: James Babcock Date: Wed, 23 Sep 2026 22:05:06 -0700 Subject: [PATCH 17/27] Animations are mainly on the typescript side, not kotlin --- app/graphics/display-list.md | 84 ++++++++++ app/graphics/display-list.ts | 133 +++++++++++++++ app/graphics/draw-expression.ts | 152 ++++++++++++++++++ app/graphics/glyph-wire.ts | 5 +- app/graphics/image.ts | 26 ++- app/graphics/menu-selection-list.ts | 18 +++ app/graphics/presentation-wire.ts | 50 +++--- app/graphics/surface-compositor.ts | 2 +- .../faceclaw/app/g2protocol/ScenePlanner.kt | 2 +- .../faceclaw/app/graphics/DrawRecordKind.kt | 4 +- .../faceclaw/app/graphics/FrameDisplayList.kt | 133 +++++++++++++++ .../faceclaw/app/graphics/MenuSelection.kt | 31 ++-- .../com/faceclaw/app/graphics/ShellScene.kt | 24 +-- .../app/graphics/SurfaceCompositor.kt | 6 +- tests/ai-chat.test.cjs | 2 +- tests/brightness-picker.test.cjs | 2 +- tests/compass-debug.test.cjs | 2 +- tests/compass-texture-cache.test.cjs | 4 +- tests/display-list-authoring.test.cjs | 83 ++++++++++ tests/input-events.test.cjs | 2 +- .../com/faceclaw/app/DrawExpressionTest.kt | 42 ----- .../com/faceclaw/app/FrameDisplayListTest.kt | 90 +++++++++++ tests/menu-display-list.test.cjs | 2 +- tests/menu-highlight-motion.test.cjs | 8 +- tests/music-settings.test.cjs | 2 +- tests/notification-filter.test.cjs | 2 +- 26 files changed, 783 insertions(+), 128 deletions(-) create mode 100644 app/graphics/display-list.md create mode 100644 app/graphics/display-list.ts create mode 100644 app/graphics/draw-expression.ts create mode 100644 app/graphics/menu-selection-list.ts create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt create mode 100644 tests/display-list-authoring.test.cjs create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt diff --git a/app/graphics/display-list.md b/app/graphics/display-list.md new file mode 100644 index 00000000..38462c02 --- /dev/null +++ b/app/graphics/display-list.md @@ -0,0 +1,84 @@ +# TypeScript display lists + +`GrayImage.drawDisplayList(list, x, y, width, height, depth)` retains a list alongside +the image's ordinary pixels. Existing frame submission (`prepareFrameDraws`) and +shell scene submission carry it to Kotlin. Bounds describe its footprint for plane +occlusion; draw coordinates are relative to its placement. Keep the list, its image +resources, and their pixel buffers immutable after submission. + +```ts +import { DrawExpression as E } from './draw-expression'; +import { DrawOp, type DisplayList } from './display-list'; + +const list: DisplayList = { + resources: [], + timeline: { token: animationId, startedAt: Date.now() }, + calls: [{ + op: DrawOp.ROUNDED_RECT, + x: E.progress(300).ease().lerp(E.f32(0), E.f32(100)).toInt(), + y: 0, + width: 40, height: 20, radius: 6, + background: 4, border: 15, + }], +}; +frame.drawDisplayList(list, 20, 30, 140, 20, 0); +``` + +Supported calls in this first pass: + +- `ROUNDED_RECT`: literal or expression `x`/`y`, literal dimensions/radius, and + 4-bit colors (0–15). Border 16 means no border. Fill takes the maximum of the + background color and existing pixels. +- `IMAGE`: a local resource index, integer `x`/`y`, and `transparent`. Transparent + images skip pixels quantized to zero. Resources have `width`, `height`, and + gray8 `pixels`; a baked `GrayImage` can be used directly. +- `RECT_COPY`: a local resource index, integer source rectangle and destination + `dx`/`dy`. `SCREEN` reads the uncomposed frame; its source coordinates are also + relative to this list's placement. Each call may add its own `depth` to the + list's depth. A screen restore normally uses the negative of the list depth. + +Kotlin allocates/cache-pins all image resources, resolves the local indices, applies +surface placement, and includes the calls in the root firmware display list. The +phone's existing display-list renderer consumes the same compiled calls. This uses +the current firmware protocol; no firmware update is needed for this bridge change. + +## Expressions and time + +`E.i32` and `E.f32` construct typed constants. Builders support arithmetic, min/max, +integer remainder, negation, explicit conversions, lerp, and the easing functions +in `ExprOp`. `ease()` defaults to smoothstep. Integers wrap at 32 bits; float +operations round to f32. The firmware's existing stack/error semantics apply. +Only rounded-rectangle x/y accept expressions in this first pass. + +`maximum.time()` returns `min(milliseconds since PRESENT, maximum)`. The existing +45 ms repaint timer remains active while this is below maximum. `E.elapsed()` is +a bridge binding: Kotlin replaces it with the timeline's elapsed milliseconds when +building a new root list. It is a constant within that PRESENT, not a second clock. +`E.progress(durationMs)` combines the two and clamps to 0..1 so intervening frames +and PRESENTs continue an animation instead of restarting it. + +Keep `timeline.token` and `timeline.startedAt` stable for an animation; use a new +token when restarting it. JS sends an elapsed duration, so JS and native clocks +need not share an epoch. Fingerprints include the token and expression code but +exclude the changing elapsed duration. Without a timeline, raw `time()` expressions +start at each PRESENT. Native compilation strips the bridge-only elapsed opcode. + +`menu-selection-list.ts` authors both the rounded highlight and the transparent row +image using this API. Navigation eligibility, duration, and easing remain in +TypeScript. There is no animated-menu tag or menu animation policy in Kotlin. + +## Bridge framing + +Tag 7 is followed by a little-endian u32 byte length and a bounded body: +placement (i16 x/y, u16 width/height, i8 depth), timeline (u32 token/elapsed), +u16 resource count, gray8 images (u16 width/height followed by pixels), u16 call +count, then calls. Calls start with the firmware opcode and an i16 relative depth; +operands otherwise use their fixed-width fields, except rounded x/y which use +extended varints. Expressions use the firmware bytecode plus bridge-only +`ELAPSED = 128`. Resource indices are local to this record, never firmware IDs. +Rect-copy source x/y are signed here to permit relative SCREEN coordinates. + +Limits: 256 images per record, 64 KiB per packed image, 4 MiB per bridge record, +4096 calls, and 900 input bytes per expression. Native validates the bound program +against the firmware's 1024-byte limit. The combined scene must also fit the +existing resource cache, root-list size, and VM stack limits. diff --git a/app/graphics/display-list.ts b/app/graphics/display-list.ts new file mode 100644 index 00000000..a7eb5c36 --- /dev/null +++ b/app/graphics/display-list.ts @@ -0,0 +1,133 @@ +import { DrawBytes, encodeValue, evaluate, integer, readValue, type DrawValue } from './draw-expression'; + +/** Local resources are assigned firmware cache IDs by Kotlin. SCREEN reads the uncomposed frame. */ +export const SCREEN = 65535; +export const DrawOp = { RECT_COPY: 2, IMAGE: 4, ROUNDED_RECT: 8 } as const; +export const DISPLAY_LIST_RECORD = 7; +export type ListImage = { readonly width: number; readonly height: number; readonly pixels: Uint8Array }; +export type ListCall = ( + | { op: typeof DrawOp.ROUNDED_RECT; x: DrawValue; y: DrawValue; width: number; height: number; radius: number; background: number; border: number } + | { op: typeof DrawOp.IMAGE; resource: number; x: number; y: number; transparent: boolean } + | { op: typeof DrawOp.RECT_COPY; resource: number; x: number; y: number; width: number; height: number; dx: number; dy: number } +) & { depth?: number }; +export type DisplayList = { + readonly resources: readonly ListImage[]; + readonly calls: readonly ListCall[]; + /** Stable identity plus JS clock origin. Native binds ELAPSED again for each PRESENT. */ + /** Set by the decoder: the local PRESENT origin for software replay. */ + readonly presentedAt?: number; + readonly timeline?: { readonly token: number; readonly startedAt: number }; +}; +export type PlacedDisplayList = { displayList: DisplayList; x: number; y: number; width: number; height: number; depth: number }; + +class Writer { + bytes: number[] = []; + u8(n: number): void { this.bytes.push(integer(n, 0, 255)); } + i8(n: number): void { this.u8(integer(n, -128, 127) & 255); } + u16(n: number): void { integer(n, 0, 65535); this.bytes.push(n & 255, n >>> 8); } + i16(n: number): void { this.u16(integer(n, -32768, 32767) & 65535); } + u32(n: number): void { integer(n, 0, 4294967295); this.u16(n & 65535); this.u16(n >>> 16); } + raw(bytes: ArrayLike): void { for (let i = 0; i < bytes.length; i++) this.bytes.push(bytes[i]); } +} + +/** Length-delimited bridge envelope; call operands use fixed widths except extended x/y. */ +export function encodeDisplayList(placed: PlacedDisplayList, now = Date.now()): Uint8Array { + const { displayList: list } = placed, out = new Writer(); + integer(placed.width, 1, 640); integer(placed.height, 1, 480); + out.i16(placed.x); out.i16(placed.y); out.u16(placed.width); out.u16(placed.height); out.i8(placed.depth); + out.u32(list.timeline?.token ?? 0); + out.u32(list.timeline ? Math.min(2147483647, Math.max(0, Math.trunc(now - list.timeline.startedAt))) : 0); + integer(list.resources.length, 0, 256); out.u16(list.resources.length); + for (const image of list.resources) { + integer(image.width, 1, 640); integer(image.height, 1, 480); + if (image.pixels.length !== image.width * image.height || 5 + Math.ceil(image.width / 2) * image.height > 65536) throw new Error('Invalid display-list image'); + out.u16(image.width); out.u16(image.height); out.raw(image.pixels); + } + integer(list.calls.length, 0, 4096); out.u16(list.calls.length); + for (const call of list.calls) { + out.u8(call.op); out.i16(call.depth ?? 0); + integer(placed.depth + (call.depth ?? 0), -128, 127); + if (call.op === DrawOp.ROUNDED_RECT) { + out.raw(encodeValue(call.x)); out.raw(encodeValue(call.y)); + out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480)); out.u16(call.radius); + out.u8(integer(call.background, 0, 15)); out.u8(integer(call.border, 0, 16)); + } else { + if (call.resource !== SCREEN) integer(call.resource, 0, list.resources.length - 1); + if (call.op === DrawOp.RECT_COPY && call.resource !== SCREEN && (call.x < 0 || call.y < 0)) throw new Error('Negative image source coordinate'); + if (call.op === DrawOp.IMAGE && call.resource === SCREEN) throw new Error('Use rectCopy to read SCREEN'); + out.u16(call.resource); + if (call.op === DrawOp.IMAGE) { out.i16(call.x); out.i16(call.y); out.u8(call.transparent ? 31 : 15); } + else { + out.i16(call.x); out.i16(call.y); out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480)); out.i16(call.dx); out.i16(call.dy); + } + } + } + if (out.bytes.length > 4 * 1024 * 1024) throw new Error('Display list exceeds bridge limit'); + const header = new Writer(); header.u8(DISPLAY_LIST_RECORD); header.u32(out.bytes.length); header.raw(out.bytes); + return Uint8Array.from(header.bytes); +} + +export function readDisplayList(bytes: Uint8Array, offset: number, now = Date.now()): { placed: PlacedDisplayList; end: number } { + const envelope = new DrawBytes(bytes.subarray(offset)); + if (envelope.u8() !== DISPLAY_LIST_RECORD) throw new Error('Invalid display-list record'); + const length = envelope.u32(); integer(length, 0, 4 * 1024 * 1024); + const r = new DrawBytes(envelope.take(length)); + const x = r.i16(), y = r.i16(), width = r.u16(), height = r.u16(), depth = r.u8() << 24 >> 24; + const token = r.u32(), elapsed = r.u32(), count = r.u16(); integer(count, 0, 256); + const resources: ListImage[] = []; + for (let i = 0; i < count; i++) { const width = r.u16(), height = r.u16(); resources.push({ width, height, pixels: r.take(width * height) }); } + const calls: ListCall[] = [], callCount = r.u16(); integer(callCount, 0, 4096); + for (let i = 0; i < callCount; i++) { + const op = r.u8(), depth = r.i16(); + if (op === DrawOp.ROUNDED_RECT) calls.push({ op, depth, x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), radius: r.u16(), background: r.u8(), border: r.u8() }); + else if (op === DrawOp.IMAGE) calls.push({ op, depth, resource: r.u16(), x: r.i16(), y: r.i16(), transparent: (r.u8() & 16) !== 0 }); + else if (op === DrawOp.RECT_COPY) calls.push({ op, depth, resource: r.u16(), x: r.i16(), y: r.i16(), width: r.u16(), height: r.u16(), dx: r.i16(), dy: r.i16() }); + else throw new Error('Unsupported display-list call'); + } + if (r.offset !== length) throw new Error('Trailing display-list bytes'); + const placed = { x, y, width, height, depth, displayList: { resources, calls, presentedAt: now, timeline: { token, startedAt: now - elapsed } } }; + // The writer is also the shared structural validator for software preview records. + encodeDisplayList(placed, now); + return { placed, end: offset + envelope.offset }; +} + +export function dimDisplayList(list: DisplayList, factor: number): DisplayList { + const dim = (v: number) => v === 0 ? 0 : Math.max(1, Math.round(v * factor)); + return { ...list, resources: list.resources.map(r => ({ ...r, pixels: r.pixels.map(dim) })), + calls: list.calls.map(c => c.op === DrawOp.ROUNDED_RECT ? { ...c, background: Math.min(15, Math.round(c.background * factor)), border: c.border === 16 ? 16 : Math.min(15, Math.round(c.border * factor)) } : c) }; +} + +/** Fallback compositor; native preview and glasses replay the compiled list with their existing timers. */ +export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width: number, height: number, placed: PlacedDisplayList, right = false, now = Date.now()): void { + const q = (n: number) => Math.min(15, (n + 8) >> 4) * 16; + const list = placed.displayList; + const elapsed = list.timeline ? Math.max(0, (list.presentedAt ?? now) - list.timeline.startedAt) : 0; + const presentTime = list.presentedAt === undefined ? 0 : Math.max(0, now - list.presentedAt); + const inside = (x: number, y: number, w: number, h: number, radius: number) => { + if (x < 0 || y < 0 || x >= w || y >= h) return false; + const r = Math.min(radius, Math.floor(w / 2), Math.floor(h / 2)); + const dx = Math.max(0, 2 * r - (2 * Math.min(x, w - 1 - x) + 1)), dy = Math.max(0, 2 * r - (2 * Math.min(y, h - 1 - y) + 1)); + return dx * dx + dy * dy <= 4 * r * r; + }; + for (const c of placed.displayList.calls) { + const depth = placed.depth + (c.depth ?? 0), shift = right ? -Math.floor((depth + 1) / 2) : Math.floor(depth / 2); + if (c.op === DrawOp.ROUNDED_RECT) { + const x = placed.x + evaluate(c.x, elapsed, presentTime).value + shift, y = placed.y + evaluate(c.y, elapsed, presentTime).value; + for (let yy = 0; yy < c.height; yy++) for (let xx = 0; xx < c.width; xx++) { + if (x + xx < 0 || y + yy < 0 || x + xx >= width || y + yy >= height || !inside(xx, yy, c.width, c.height, c.radius)) continue; + const p = (y + yy) * width + x + xx; + output[p] = c.border !== 16 && !inside(xx - 1, yy - 1, c.width - 2, c.height - 2, Math.max(0, c.radius - 1)) ? c.border * 16 : Math.max(output[p], c.background * 16); + } + } else { + const source = c.resource === SCREEN ? { width, height, pixels: screen } : placed.displayList.resources[c.resource]; + const w = c.op === DrawOp.IMAGE ? source.width : c.width, h = c.op === DrawOp.IMAGE ? source.height : c.height; + const sx = c.op === DrawOp.IMAGE ? 0 : c.x + (c.resource === SCREEN ? placed.x : 0), sy = c.op === DrawOp.IMAGE ? 0 : c.y + (c.resource === SCREEN ? placed.y : 0); + const x = placed.x + (c.op === DrawOp.IMAGE ? c.x : c.dx) + shift, y = placed.y + (c.op === DrawOp.IMAGE ? c.y : c.dy); + for (let yy = 0; yy < h; yy++) for (let xx = 0; xx < w; xx++) { + if (x + xx < 0 || y + yy < 0 || x + xx >= width || y + yy >= height || sx + xx < 0 || sy + yy < 0 || sx + xx >= source.width || sy + yy >= source.height) continue; + const v = q(source.pixels[(sy + yy) * source.width + sx + xx]); + if (c.op !== DrawOp.IMAGE || !c.transparent || v !== 0) output[(y + yy) * width + x + xx] = v; + } + } + } +} diff --git a/app/graphics/draw-expression.ts b/app/graphics/draw-expression.ts new file mode 100644 index 00000000..869ea641 --- /dev/null +++ b/app/graphics/draw-expression.ts @@ -0,0 +1,152 @@ +/** Revision 27 expression bytecode. ELAPSED is a bridge binding, never sent to firmware. */ +export const ExprOp = { + I32: 1, F32: 2, DUP: 3, DROP: 4, SWAP: 5, + IADD: 16, ISUB: 17, IMUL: 18, IDIV: 19, IMOD: 20, INEG: 21, IMIN: 22, IMAX: 23, + FADD: 32, FSUB: 33, FMUL: 34, FDIV: 35, FNEG: 36, FMIN: 37, FMAX: 38, + I2F: 48, F2I: 49, TIME: 50, LERP: 64, SMOOTHSTEP: 65, + EASE_IN_QUAD: 66, EASE_OUT_QUAD: 67, EASE_IN_OUT_QUAD: 68, + EASE_IN_CUBIC: 69, EASE_OUT_CUBIC: 70, EASE_IN_OUT_CUBIC: 71, + ELAPSED: 128, +} as const; + +export function integer(value: number, min: number, max: number): number { + if (!Number.isInteger(value) || value < min || value > max) throw new Error('Draw integer out of range'); + return value; +} +export function varint(value: number, signed = true): number[] { + integer(value, signed ? -2147483648 : 0, signed ? 2147483647 : 4294967295); + const widths = [7, 14, 21, 28, 32], prefixes = [0, 128, 192, 224, 240]; + const size = widths.findIndex(bits => bits === 32 || (signed + ? value >= -(2 ** (bits - 1)) && value < 2 ** (bits - 1) : value < 2 ** bits)) + 1; + const bytes = [size === 5 ? 240 : prefixes[size - 1] | ((value >>> (8 * (size - 1))) & ((1 << (8 - size)) - 1))]; + for (let i = 1; i < size; i++) bytes.push((value >>> (8 * (size - 1 - i))) & 255); + return bytes; +} + +export class DrawBytes { + offset = 0; + constructor(readonly bytes: Uint8Array) {} + take(size: number): Uint8Array { + integer(size, 0, this.bytes.length - this.offset); + const result = this.bytes.slice(this.offset, this.offset + size); this.offset += size; return result; + } + u8(): number { return this.take(1)[0]; } + u16(): number { return this.u8() | this.u8() << 8; } + i16(): number { return this.u16() << 16 >> 16; } + u32(): number { return (this.u16() | this.u16() << 16) >>> 0; } + variable(signed = true): number { + const first = this.u8(); + const size = first < 128 ? 1 : first < 192 ? 2 : first < 224 ? 3 : first < 240 ? 4 : first === 240 ? 5 : 0; + if (!size) throw new Error('Reserved extended-varint prefix'); + let value = size === 5 ? 0 : first & ((1 << (8 - size)) - 1); + for (let i = 1; i < size; i++) value = (value << 8) | this.u8(); + const bits = [7, 14, 21, 28, 32][size - 1]; + return signed ? bits < 32 ? value << (32 - bits) >> (32 - bits) : value : value >>> 0; + } +} + +/** Immutable, typed expression builder; operations use firmware i32/f32 semantics. */ +export class DrawExpression { + private constructor(readonly type: T, readonly code: readonly number[]) { + // Leave room for native elapsed bindings and surface translation. + if (code.length > 900) throw new Error('Draw expression too large'); + } + static i32(value: number): DrawExpression<'i32'> { return new DrawExpression('i32', [ExprOp.I32, ...varint(value)]); } + static f32(value: number): DrawExpression<'f32'> { + if (!Number.isFinite(Math.fround(value))) throw new Error('Invalid draw float'); + const bytes = new Uint8Array(4); new DataView(bytes.buffer).setFloat32(0, value, true); + return new DrawExpression('f32', [ExprOp.F32, ...bytes]); + } + /** Time already elapsed on this list's timeline when the next PRESENT happens. */ + static elapsed(): DrawExpression<'i32'> { return new DrawExpression('i32', [ExprOp.ELAPSED]); } + /** A 0..1 timeline fraction that survives subsequent PRESENT clock resets. */ + static progress(durationMs: number): DrawExpression<'f32'> { + const duration = DrawExpression.i32(integer(durationMs, 1, 2147483647)); + const elapsed = DrawExpression.elapsed().min(duration); + return duration.sub(elapsed).max(DrawExpression.i32(0)).time() + .add(elapsed).toFloat().div(duration.toFloat()); + } + static decode(code: Uint8Array): DrawExpression<'i32'> { return new DrawExpression('i32', Array.from(code)); } + private binary(other: DrawExpression, i: number, f: number): DrawExpression { + if (other.type !== this.type) throw new Error('Draw expression type mismatch'); + return new DrawExpression(this.type, [...this.code, ...other.code, this.type === 'i32' ? i : f]); + } + add(b: DrawExpression): DrawExpression { return this.binary(b, ExprOp.IADD, ExprOp.FADD); } + sub(b: DrawExpression): DrawExpression { return this.binary(b, ExprOp.ISUB, ExprOp.FSUB); } + mul(b: DrawExpression): DrawExpression { return this.binary(b, ExprOp.IMUL, ExprOp.FMUL); } + div(b: DrawExpression): DrawExpression { return this.binary(b, ExprOp.IDIV, ExprOp.FDIV); } + min(b: DrawExpression): DrawExpression { return this.binary(b, ExprOp.IMIN, ExprOp.FMIN); } + max(b: DrawExpression): DrawExpression { return this.binary(b, ExprOp.IMAX, ExprOp.FMAX); } + mod(this: DrawExpression<'i32'>, b: DrawExpression<'i32'>): DrawExpression<'i32'> { return this.binary(b, ExprOp.IMOD, ExprOp.IMOD); } + neg(): DrawExpression { return new DrawExpression(this.type, [...this.code, this.type === 'i32' ? ExprOp.INEG : ExprOp.FNEG]); } + toFloat(this: DrawExpression<'i32'>): DrawExpression<'f32'> { return new DrawExpression('f32', [...this.code, ExprOp.I2F]); } + toInt(this: DrawExpression<'f32'>): DrawExpression<'i32'> { return new DrawExpression('i32', [...this.code, ExprOp.F2I]); } + time(this: DrawExpression<'i32'>): DrawExpression<'i32'> { return new DrawExpression('i32', [...this.code, ExprOp.TIME]); } + ease(this: DrawExpression<'f32'>, op: number = ExprOp.SMOOTHSTEP): DrawExpression<'f32'> { + integer(op, ExprOp.SMOOTHSTEP, ExprOp.EASE_IN_OUT_CUBIC); + return new DrawExpression('f32', [...this.code, op]); + } + lerp(this: DrawExpression<'f32'>, from: DrawExpression<'f32'>, to: DrawExpression<'f32'>): DrawExpression<'f32'> { + return new DrawExpression('f32', [...from.code, ...to.code, ...this.code, ExprOp.LERP]); + } +} +export type DrawValue = number | DrawExpression<'i32'>; +export function encodeValue(value: DrawValue): number[] { + return typeof value === 'number' ? varint(value) : [255, ...varint(value.code.length, false), ...value.code]; +} +export function readValue(reader: DrawBytes): DrawValue { + if (reader.bytes[reader.offset] !== 255) return reader.variable(); + reader.u8(); return DrawExpression.decode(reader.take(reader.variable(false))); +} + +/** Software preview of the same VM; invalid programs return zero and discard pending animation. */ +export function evaluate(value: DrawValue, elapsed: number, presentTime = 0): { value: number; pending: boolean } { + if (typeof value === 'number') return { value, pending: false }; + const reader = new DrawBytes(Uint8Array.from(value.code)), stack: { value: number; float: boolean }[] = []; + let pending = false; + const push = (value: number, float = false) => { + value = float ? Math.fround(value) : value | 0; + if (!Number.isFinite(value) || stack.length === 32) throw new Error('Invalid expression stack'); + stack.push({ value, float }); + }; + const pop = (float: boolean) => { const v = stack.pop(); if (!v || v.float !== float) throw new Error('Expression type mismatch'); return v.value; }; + const toInt = (v: number) => { if (v < -2147483648 || v >= 2147483648) throw new Error('Invalid integer conversion'); return Math.trunc(v); }; + try { + while (reader.offset < reader.bytes.length) { + const op = reader.u8(); + if (op === ExprOp.I32) push(reader.variable()); + else if (op === ExprOp.F32) { const b = reader.take(4); push(new DataView(b.buffer).getFloat32(0, true), true); } + else if (op === ExprOp.ELAPSED) push(Math.min(2147483647, Math.max(0, elapsed))); + else if (op === ExprOp.I2F) push(pop(false), true); + else if (op === ExprOp.F2I) push(toInt(pop(true))); + else if (op === ExprOp.TIME) { const max = pop(false); if (max < 0) throw new Error('Invalid time'); const t = Math.min(Math.max(0, presentTime), max); pending ||= t !== max; push(t); } + else if (op === ExprOp.INEG || op === ExprOp.FNEG) push(-pop(op === ExprOp.FNEG), op === ExprOp.FNEG); + else if (op >= ExprOp.IADD && op <= ExprOp.IMAX || op >= ExprOp.FADD && op <= ExprOp.FMAX) { + const float = op >= ExprOp.FADD, b = pop(float), a = pop(float); + const key = float ? op - ExprOp.FADD : op - ExprOp.IADD; + if ((key === 3 || !float && key === 4) && b === 0) throw new Error('Division by zero'); + const result = key === 0 ? a + b : key === 1 ? a - b : key === 2 ? float ? a * b : Math.imul(a, b) : key === 3 ? a / b : !float && key === 4 ? a % b : key === (float ? 5 : 6) ? Math.min(a, b) : Math.max(a, b); + push(result, float); + } else if (op === ExprOp.LERP) { const t = pop(true), b = pop(true), a = pop(true); push(a + Math.fround(Math.fround(b - a) * t), true); } + else if (op >= ExprOp.SMOOTHSTEP && op <= ExprOp.EASE_IN_OUT_CUBIC) { + const t = Math.max(0, Math.min(1, pop(true))), u = Math.fround(1 - t), f = Math.fround; + let result: number; + switch (op) { + case ExprOp.SMOOTHSTEP: result = f(t * t) * f(3 - f(2 * t)); break; + case ExprOp.EASE_IN_QUAD: result = t * t; break; + case ExprOp.EASE_OUT_QUAD: result = 1 - f(u * u); break; + case ExprOp.EASE_IN_OUT_QUAD: result = t < .5 ? f(2 * t) * t : 1 - f(f(2 * u) * u); break; + case ExprOp.EASE_IN_CUBIC: result = f(t * t) * t; break; + case ExprOp.EASE_OUT_CUBIC: result = 1 - f(f(u * u) * u); break; + default: result = t < .5 ? f(f(4 * t) * t) * t : 1 - f(f(f(4 * u) * u) * u); + } + push(result, true); + } else if (op === ExprOp.DUP) { const a = stack[stack.length - 1]; if (!a) throw new Error('Underflow'); push(a.value, a.float); } + else if (op === ExprOp.DROP) { if (!stack.pop()) throw new Error('Underflow'); } + else if (op === ExprOp.SWAP) { if (stack.length < 2) throw new Error('Underflow'); const a = stack.pop()!, b = stack.pop()!; stack.push(a, b); } + else throw new Error('Unknown expression opcode'); + } + const top = stack.pop(); if (!top) throw new Error('Empty expression'); + return { value: top.float ? toInt(top.value) : top.value, pending }; + } catch { return { value: 0, pending: false }; } +} diff --git a/app/graphics/glyph-wire.ts b/app/graphics/glyph-wire.ts index 624137ec..cd15f0e2 100644 --- a/app/graphics/glyph-wire.ts +++ b/app/graphics/glyph-wire.ts @@ -159,6 +159,7 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | // Pass 1: resolve ids, register unseen rasters, size the buffer. let registration: Map | null = null; const fwRunOk = new Map(); + const presentations = new Map(); let bytes = 0; for (const placed of draws) { if (placed.kind === "glyph") { @@ -177,7 +178,7 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | (placed.glyph.coverage ? group.aaGlyphs : group.glyphs).push(placed.glyph); } else if (placed.kind === "image") { if (!inRange16(placed.x) || !inRange16(placed.y)) continue; - if (placed.presentation) bytes += encodePresentation(placed).length; + if (placed.presentation) { const record = encodePresentation(placed); presentations.set(placed, record); bytes += record.length; } else if (imageId(placed) !== null) bytes += IMAGE_RECORD_BYTES; } else { const ok = prepareFwTextRun(placed); @@ -210,7 +211,7 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer | offset += GLYPH_RECORD_BYTES; } else if (placed.kind === "image") { if (!inRange16(placed.x) || !inRange16(placed.y)) continue; - if (placed.presentation) { const bytes = encodePresentation(placed); new Uint8Array(out.buffer).set(bytes, offset); offset += bytes.length; continue; } + if (placed.presentation) { const bytes = presentations.get(placed)!; new Uint8Array(out.buffer).set(bytes, offset); offset += bytes.length; continue; } const id = imageId(placed); if (id === null) continue; out.setUint8(offset, DrawRecordKind.TEXTURE_IMAGE); diff --git a/app/graphics/image.ts b/app/graphics/image.ts index 8541ab7c..ac339a3d 100644 --- a/app/graphics/image.ts +++ b/app/graphics/image.ts @@ -1,3 +1,5 @@ +import { menuSelectionList } from "./menu-selection-list"; +import { encodeDisplayList, dimDisplayList, paintDisplayList, type DisplayList } from "./display-list"; import type { MenuHighlightAnimation } from "../ui/menu-highlight-motion"; import { Glyph } from "./bdffont"; import { wrapText } from "./textwrap"; @@ -74,7 +76,7 @@ export type PlacedGlyph = { * from the moment it is placed. */ export type PlacedImage = { - presentation?: { animation?: MenuHighlightAnimation; mode?: "image" | "masked-image"; radius: number; background: number; border: number; depth: number; occlusions?: readonly { x: number; y: number; width: number; height: number }[] }; + presentation?: { displayList?: DisplayList; mode?: "image" | "masked-image"; radius: number; background: number; border: number; depth: number; occlusions?: readonly { x: number; y: number; width: number; height: number }[] }; kind: "image"; source: GrayImage; x: number; @@ -395,7 +397,9 @@ export class GrayImage { hash = mixInt(hash, placed.source.width); hash = mixInt(hash, placed.source.height); hash = mixInt(hash, placed.source.sourceContentHash32()); - if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0, p.animation?.token ?? 0, p.animation?.dx ?? 0, p.animation?.dy ?? 0, p.animation?.durationMs ?? 0]) hash = mixInt(hash, value); } + if (placed.presentation) { const p = placed.presentation; for (const value of [p.radius, p.background, p.border, p.depth, p.mode === "image" ? 1 : p.mode === "masked-image" ? 2 : 0]) hash = mixInt(hash, value); + if (p.displayList) for (const byte of encodeDisplayList({ displayList: p.displayList, x: 0, y: 0, width: placed.source.width, height: placed.source.height, depth: p.depth }, p.displayList.timeline?.startedAt ?? 0)) hash = mixInt(hash, byte); + } } else { hash = mixInt(hash, 0xf17e); hash = mixInt(hash, placed.font.atlasTag); @@ -508,8 +512,15 @@ export class GrayImage { /** Retain the selected row separately from the menu surface for glasses-side composition. */ drawMenuSelection(source: GrayImage, x: number, y: number, background: number, border: number, radius = 8, depth = 2, animation?: MenuHighlightAnimation): void { - this.drawList.push({ kind: "image", source: source.withDrawsBaked(), x, y, - presentation: { radius, background, border, depth, animation } }); + const baked = source.withDrawsBaked(); + this.drawList.push({ kind: "image", source: baked, x, y, + presentation: { radius, background, border, depth, displayList: menuSelectionList(baked, background, border, radius, animation) } }); + } + + /** Submit a retained list alongside this frame; coordinates are relative to x/y. */ + drawDisplayList(displayList: DisplayList, x: number, y: number, width: number, height: number, depth = 0): void { + this.drawList.push({ kind: "image", source: new GrayImage(width, height), x, y, + presentation: { radius: 0, background: 0, border: 0, depth, displayList } }); } /** Replay an image at stereo depth. Masked images preserve intentional gray8 black (1). */ @@ -570,7 +581,7 @@ export class GrayImage { for (const placed of this.drawList) { if (placed.kind === "image" && placed.presentation) { const p = placed.presentation; - copy.drawList.push({ ...placed, source: placed.source.dimmed(factor), presentation: { ...p, background: dimValue(p.background, scale), border: dimValue(p.border, scale) } }); + copy.drawList.push({ ...placed, source: placed.source.dimmed(factor), presentation: { ...p, background: dimValue(p.background, scale), border: dimValue(p.border, scale), displayList: p.displayList && dimDisplayList(p.displayList, factor) } }); } else if (placed.kind !== "image") { copy.drawList.push({ ...placed, value: dimValue(placed.value, scale) }); } @@ -613,6 +624,11 @@ export class GrayImage { } else if (placed.kind === "image") { if (placed.presentation) { if (!presentations) continue; + if (placed.presentation.displayList) { + paintDisplayList(target.pixels, target.pixels.slice(), target.width, target.height, + { displayList: placed.presentation.displayList, x: placed.x + dx, y: placed.y + dy, width: placed.source.width, height: placed.source.height, depth: placed.presentation.depth }); + continue; + } if (placed.presentation.mode) { target.bitBlt(placed.source, placed.x + dx, placed.y + dy, { transparentZero: true }); continue; diff --git a/app/graphics/menu-selection-list.ts b/app/graphics/menu-selection-list.ts new file mode 100644 index 00000000..6a334039 --- /dev/null +++ b/app/graphics/menu-selection-list.ts @@ -0,0 +1,18 @@ +import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion'; +import { DrawExpression as E } from './draw-expression'; +import { DrawOp, type DisplayList, type ListImage } from './display-list'; + +/** Menu policy and easing live in TypeScript; the bridge carries only generic calls/expressions. */ +export function menuSelectionList(image: ListImage, background: number, border: number, radius: number, animation?: MenuHighlightAnimation): DisplayList { + const coordinate = (delta: number) => { + if (!animation || !delta) return 0; + const progress = E.progress(animation.durationMs).ease(); + return progress.lerp(E.i32(delta).toFloat(), E.f32(0)).toInt(); + }; + const q = (n: number) => Math.min(15, (n + 8) >> 4); + return { resources: [image], timeline: animation, + calls: [ + { op: DrawOp.ROUNDED_RECT, x: coordinate(animation?.dx ?? 0), y: coordinate(animation?.dy ?? 0), width: image.width, height: image.height, radius, background: q(background), border: q(border) }, + { op: DrawOp.IMAGE, resource: 0, x: 0, y: 0, transparent: true }, + ] }; +} diff --git a/app/graphics/presentation-wire.ts b/app/graphics/presentation-wire.ts index 4dca3be1..0e8c361d 100644 --- a/app/graphics/presentation-wire.ts +++ b/app/graphics/presentation-wire.ts @@ -1,5 +1,5 @@ import type { PlacedImage } from './image' -import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion' +import { DISPLAY_LIST_RECORD, DrawOp, SCREEN, encodeDisplayList, readDisplayList, paintDisplayList, type DisplayList } from './display-list' /** TS/native bridge tags, not firmware draw opcodes. Keep in sync with DrawRecordKind.kt. */ export const DrawRecordKind = { @@ -9,38 +9,36 @@ export const DrawRecordKind = { MENU_SELECTION: 3, TRANSPARENT_IMAGE: 4, MASKED_IMAGE: 5, - ANIMATED_MENU_SELECTION: 6, + DISPLAY_LIST: DISPLAY_LIST_RECORD, } as const export function isPresentationKind(kind: number | undefined): boolean { return kind === DrawRecordKind.MENU_SELECTION || kind === DrawRecordKind.TRANSPARENT_IMAGE || - kind === DrawRecordKind.MASKED_IMAGE || kind === DrawRecordKind.ANIMATED_MENU_SELECTION + kind === DrawRecordKind.MASKED_IMAGE || kind === DrawRecordKind.DISPLAY_LIST } -/** Presentation record: tag, signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, optional animation, gray pixels, restore rectangles. */ +/** Presentation record: tag, signed xy, u16 wh/radius, gray fill/stroke, signed depth, restore-count, gray pixels, restore rectangles. */ export function encodePresentation(draw: PlacedImage): Uint8Array { const p = draw.presentation! const { width, height, pixels } = draw.source - if (width < 1 || height < 1 || width > 640 || height > 480 || 5 + Math.ceil(width / 2) * height > 65536) throw new Error('Presentation image exceeds the resource size limit') + if (width < 1 || height < 1 || width > 640 || height > 480 || !p.displayList && 5 + Math.ceil(width / 2) * height > 65536) throw new Error('Presentation image exceeds the resource size limit') if (!Number.isInteger(p.depth) || p.depth < -128 || p.depth > 127) throw new Error('Invalid menu depth') if ((p.occlusions?.length ?? 0) > 2048) throw new Error('Too many menu occlusion rectangles') - const animation = p.animation; - if (animation && (!Number.isInteger(animation.durationMs) || animation.durationMs < 1 || animation.durationMs > 65535)) throw new Error('Invalid menu animation duration') - const header = animation ? 28 : 16; + if (p.displayList) { + const calls = [...p.displayList.calls, ...(p.occlusions ?? []).map(r => ({ + op: DrawOp.RECT_COPY, resource: SCREEN, x: r.x - draw.x, y: r.y - draw.y, + width: r.width, height: r.height, dx: r.x - draw.x, dy: r.y - draw.y, depth: -p.depth, + }))]; + return encodeDisplayList({ displayList: { ...p.displayList, calls }, x: draw.x, y: draw.y, width, height, depth: p.depth }); + } + const header = 16; const bytes = new Uint8Array(header + width * height + (p.occlusions?.length ?? 0) * 8), view = new DataView(bytes.buffer) - bytes[0] = animation ? DrawRecordKind.ANIMATED_MENU_SELECTION - : p.mode === "image" ? DrawRecordKind.TRANSPARENT_IMAGE + bytes[0] = p.mode === "image" ? DrawRecordKind.TRANSPARENT_IMAGE : p.mode === "masked-image" ? DrawRecordKind.MASKED_IMAGE : DrawRecordKind.MENU_SELECTION view.setInt16(1, draw.x, true); view.setInt16(3, draw.y, true) view.setUint16(5, width, true); view.setUint16(7, height, true); view.setUint16(9, p.radius, true) bytes[11] = p.background; bytes[12] = p.border; view.setInt8(13, p.depth) view.setUint16(14, p.occlusions?.length ?? 0, true) - if (animation) { - view.setInt16(16, animation.dx, true); view.setInt16(18, animation.dy, true); - view.setUint16(20, Math.max(0, Math.min(animation.durationMs, Date.now() - animation.startedAt)), true); - view.setUint32(22, animation.token, true); - view.setUint16(26, animation.durationMs, true); - } bytes.set(pixels, header) let offset = header + pixels.length for (const rect of p.occlusions ?? []) { @@ -50,20 +48,18 @@ export function encodePresentation(draw: PlacedImage): Uint8Array { return bytes } -export type Selection = { animation?: MenuHighlightAnimation; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } +export type Selection = { displayList?: DisplayList; mode?: "image" | "masked-image"; x: number; y: number; width: number; height: number; radius: number; background: number; border: number; depth: number; pixels: Uint8Array; occlusions: { x: number; y: number; width: number; height: number }[] } export function readPresentation(bytes: Uint8Array, offset: number): { selection: Selection; end: number } { + if (bytes[offset] === DrawRecordKind.DISPLAY_LIST) { + const { placed, end } = readDisplayList(bytes, offset); + return { selection: { ...placed, radius: 0, background: 0, border: 0, pixels: new Uint8Array(0), occlusions: [] }, end }; + } const v = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), w = v.getUint16(offset + 5, true), h = v.getUint16(offset + 7, true) const kind = bytes[offset] - const header = kind === DrawRecordKind.ANIMATED_MENU_SELECTION ? 28 : 16 + const header = 16 const selection: Selection = { mode: kind === DrawRecordKind.TRANSPARENT_IMAGE ? "image" : kind === DrawRecordKind.MASKED_IMAGE ? "masked-image" : undefined, x: v.getInt16(offset+1,true), y: v.getInt16(offset+3,true), width:w, height:h, radius:v.getUint16(offset+9,true), background:bytes[offset+11]!, border:bytes[offset+12]!, depth:v.getInt8(offset+13), pixels:bytes.slice(offset+header,offset+header+w*h), occlusions:[] } - if (kind === DrawRecordKind.ANIMATED_MENU_SELECTION) { - const durationMs = v.getUint16(offset+26,true), elapsed = v.getUint16(offset+20,true) - if (!durationMs || elapsed > durationMs) throw new Error('Invalid menu animation timing') - selection.animation = { dx:v.getInt16(offset+16,true), dy:v.getInt16(offset+18,true), - startedAt:Date.now()-elapsed, token:v.getUint32(offset+22,true), durationMs } - } let end=offset+header+w*h for(let i=0;iMath.min(15,(n+8)>>4), shift=right?-Math.floor((row.depth+1)/2):Math.floor(row.depth/2) const inside=(x:number,y:number,w:number,h:number,r:number)=>{ if(x<0||y<0||x>=w||y>=h) return false @@ -88,10 +85,7 @@ export function paintPresentation(output: Uint8Array, screen: Uint8Array, width: const dx=Math.max(0,2*r-(2*Math.min(x,w-1-x)+1)),dy=Math.max(0,2*r-(2*Math.min(y,h-1-y)+1)) return dx*dx+dy*dy<=4*r*r } - const t = row.animation ? Math.max(0, Math.min(1, (Date.now() - row.animation.startedAt) / row.animation.durationMs)) : 1 - const remaining = 1 - t * t * (3 - 2 * t) - const highlightX = Math.trunc(row.x + (row.animation?.dx ?? 0) * remaining) - const highlightY = Math.trunc(row.y + (row.animation?.dy ?? 0) * remaining) + const highlightX = row.x, highlightY = row.y if (!row.mode) for(let yy=0;yy=width||y>=height || !inside(xx,yy,row.width,row.height,row.radius)) continue diff --git a/app/graphics/surface-compositor.ts b/app/graphics/surface-compositor.ts index 9d0fa772..e110bac9 100644 --- a/app/graphics/surface-compositor.ts +++ b/app/graphics/surface-compositor.ts @@ -93,7 +93,7 @@ export class SurfaceCompositor { if(x+xx+shift>=0 && y+yy>=0 && x+xx+shift true + MENU_SELECTION, TRANSPARENT_IMAGE, MASKED_IMAGE, DISPLAY_LIST -> true else -> false } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt new file mode 100644 index 00000000..0d7c467f --- /dev/null +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt @@ -0,0 +1,133 @@ +package com.faceclaw.app + +/** A retained draw submitted with frame pixels, before cache IDs have been assigned. */ +interface RetainedDrawing { + val resources: List + val fingerprint: String + fun translated(dx: Int, dy: Int): RetainedDrawing + fun calls(ids: IntArray, nowMs: Long): List +} + +internal fun readRetainedDrawing(reader: ByteReader, kind: Int): RetainedDrawing = + if (kind == DrawRecordKind.DISPLAY_LIST) FrameDisplayList.read(reader) else MenuSelection.read(reader, kind) + +/** Generic TS-authored calls. No menu or easing policy lives in this bridge. */ +class FrameDisplayList private constructor( + private val x: Int, private val y: Int, private val depth: Int, + override val resources: List, private val commands: List, + internal val startedAt: Long, private val identity: String, +) : RetainedDrawing { + override val fingerprint: String get() = "$x,$y,$depth,$identity" + override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity) + + private class Command(val op: Int, val depth: Int, val values: IntArray, + val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0)) + + override fun calls(ids: IntArray, nowMs: Long): List { + require(ids.size == resources.size) + val elapsed = (nowMs - startedAt).coerceIn(0, Int.MAX_VALUE.toLong()).toInt() + fun resource(index: Int) = if (index == DrawProtocol.SCREEN) index else ids[index] + return commands.map { c -> + val v = c.values + when (c.op) { + DRAW_OP_ROUNDED_RECT -> DrawProtocol.roundedRect(bind(c.x, elapsed, x), bind(c.y, elapsed, y), + v[0], v[1], v[2], v[3], v[4], depth + c.depth) + DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), x + v[1], y + v[2], v[3], depth = depth + c.depth) + DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]), + v[1] + if (v[0] == DrawProtocol.SCREEN) x else 0, + v[2] + if (v[0] == DrawProtocol.SCREEN) y else 0, + v[3], v[4], x + v[5], y + v[6], depth = depth + c.depth) + else -> error("Unsupported frame display-list opcode") + } + } + } + + companion object { + // Bridge-only constant binding, removed before a program reaches either renderer. + private const val ELAPSED = 128 + private const val MAX_RECORD_BYTES = 4 * 1024 * 1024 + + private fun bind(value: DrawValue, elapsed: Int, offset: Int): DrawValue { + if (value is DrawValue.Integer) return DrawValue.Integer(value.value + offset) + val reader = DrawReader((value as DrawValue.Expression).program) + val out = ByteSink() + while (reader.remaining > 0) { + when (val op = reader.readU8()) { + ELAPSED -> { out.write(DrawExpression.PUSH_I32); out.write(ExtendedVarint.signed(elapsed)) } + DrawExpression.PUSH_I32 -> { out.write(op); out.write(ExtendedVarint.signed(ExtendedVarint.read(reader, true))) } + DrawExpression.PUSH_F32 -> { out.write(op); out.write(reader.readBytes(4)) } + else -> out.write(op) + } + } + if (offset != 0) { + out.write(DrawExpression.PUSH_I32); out.write(ExtendedVarint.signed(offset)); out.write(DrawExpression.IADD) + } + val program = out.toByteArray() + require(program.size <= DrawExpression.MAX_BYTES) + return DrawValue.Expression(program) + } + + fun read(input: ByteReader, nowMs: Long = drawAnimationTimeMs()): FrameDisplayList { + val length = input.getInt() + require(length in 21..MAX_RECORD_BYTES && length <= input.remaining()) + val bytes = ByteArray(length).also { input.get(it) } + val r = DrawReader(bytes) + val x = r.readS16(); val y = r.readS16() + val width = r.readU16(); val height = r.readU16() + require(width in 1..640 && height in 1..480) + val depth = r.readS8() + r.readBytes(4) // Stable timeline token is included in the identity below. + val elapsed = r.readU16() or (r.readU16() shl 16) + require(elapsed >= 0) + val resourceCount = r.readU16(); require(resourceCount <= 256) + val resources = List(resourceCount) { + val w = r.readU16(); val h = r.readU16() + require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536) + val gray = r.readBytes(w * h) + CachedResource(DrawProtocol.rawImage(w, h, BmpUtil.pack4bppFromGray8(gray, w, h))) + } + fun value(): DrawValue { + val first = r.readU8() + if (first != 255) return DrawValue.Integer(ExtendedVarint.read(r, true, first)) + val size = ExtendedVarint.read(r, false).toUInt() + require(size <= 900u) + return DrawValue.Expression(r.readBytes(size.toInt())).also { + // Validate framing and worst-case binding growth before retaining the frame. + bind(it, Int.MAX_VALUE, Int.MAX_VALUE) + } + } + fun resource(): Int = r.readU16().also { require(it == DrawProtocol.SCREEN || it in resources.indices) } + val count = r.readU16(); require(count <= 4096) + val calls = List(count) { + val op = r.readU8(); val d = r.readS16(); require(depth + d in -128..127) + when (op) { + DRAW_OP_ROUNDED_RECT -> { + val xx = value(); val yy = value() + val w = r.readU16(); val h = r.readU16(); val radius = r.readU16() + val background = r.readU8(); val border = r.readU8() + require(w in 1..640 && h in 1..480 && background in 0..15 && border in 0..16) + Command(op, d, intArrayOf(w, h, radius, background, border), xx, yy) + } + DRAW_OP_IMAGE -> { + val id = resource(); require(id != DrawProtocol.SCREEN) + val xx = r.readS16(); val yy = r.readS16(); val options = r.readU8() + require(options == 15 || options == 31) + Command(op, d, intArrayOf(id, xx, yy, options)) + } + DRAW_OP_RECT_COPY -> { + val id = resource(); val sx = r.readS16(); val sy = r.readS16() + val w = r.readU16(); val h = r.readU16(); val dx = r.readS16(); val dy = r.readS16() + require(w in 1..640 && h in 1..480) + require(id == DrawProtocol.SCREEN || sx >= 0 && sy >= 0) + Command(op, d, intArrayOf(id, sx, sy, w, h, dx, dy)) + } + else -> error("Unsupported frame display-list opcode") + } + } + r.requireDone() + // Elapsed changes while the same timeline is resubmitted; it is not content identity. + bytes.fill(0, 13, 17) + return FrameDisplayList(x, y, depth, resources, calls, nowMs - elapsed, CachedResource(bytes).hash.toString()) + } + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt index c386a6e4..fda4e8e6 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/MenuSelection.kt @@ -2,17 +2,15 @@ package com.faceclaw.app /** A retained selection or image, replayed at stereo depth over the screen and shell surfaces. */ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val radius: Int, - val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = DrawRecordKind.MENU_SELECTION, val mask: List = emptyList(), val animation: Animation? = null) { - class Animation(val dx: Int, val dy: Int, val startedAt: Long, val token: Int, val durationMs: Int) + val background: Int, val border: Int, val depth: Int, val packed: ByteArray, val occlusions: List = emptyList(), val kind: Int = DrawRecordKind.MENU_SELECTION, val mask: List = emptyList()) : RetainedDrawing { val resource = CachedResource(DrawProtocol.rawImage(width, height, packed)) - val fingerprint = "${animation?.token},${animation?.dx},${animation?.dy},${animation?.durationMs},$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" - fun translated(dx: Int, dy: Int) = MenuSelection(x + dx, y + dy, width, height, radius, background, border, depth, packed, occlusions.map { intArrayOf(it[0] + dx, it[1] + dy, it[2], it[3]) }, kind, mask, animation) - fun calls(id: Int, nowMs: Long = drawAnimationTimeMs()): List { - val elapsed = animation?.let { (nowMs - it.startedAt).coerceIn(0, it.durationMs.toLong()).toInt() } ?: 0 - val highlightX = animation?.let { DrawValue.animate(x + it.dx, x, it.durationMs, elapsed) } ?: DrawValue.Integer(x) - val highlightY = animation?.let { DrawValue.animate(y + it.dy, y, it.durationMs, elapsed) } ?: DrawValue.Integer(y) + override val resources = listOf(resource) + override val fingerprint = "$kind,${mask.joinToString { it.joinToString() }},$x,$y,$width,$height,$radius,$background,$border,$depth,${resource.hash},${occlusions.joinToString { it.joinToString() }}" + override fun translated(dx: Int, dy: Int) = MenuSelection(x + dx, y + dy, width, height, radius, background, border, depth, packed, occlusions.map { intArrayOf(it[0] + dx, it[1] + dy, it[2], it[3]) }, kind, mask) + override fun calls(ids: IntArray, nowMs: Long) = calls(ids.single()) + fun calls(id: Int): List { val image = when (kind) { - DrawRecordKind.MENU_SELECTION -> listOf(DrawProtocol.roundedRect(highlightX, highlightY, width, height, radius, background, border, depth), + DrawRecordKind.MENU_SELECTION -> listOf(DrawProtocol.roundedRect(x, y, width, height, radius, background, border, depth), DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) DrawRecordKind.TRANSPARENT_IMAGE -> listOf(DrawProtocol.image(id, x, y, CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT, depth = depth)) // Gray8 zero is transparent but gray8 one is opaque black. Rect copies preserve @@ -31,7 +29,7 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val companion object { /** The caller has consumed a presentation tag from [DrawRecordKind]. Colors and pixels cross in gray8. */ fun read(reader: ByteReader, kind: Int = DrawRecordKind.MENU_SELECTION): MenuSelection { - require(DrawRecordKind.isPresentation(kind)) + require(kind in listOf(DrawRecordKind.MENU_SELECTION, DrawRecordKind.TRANSPARENT_IMAGE, DrawRecordKind.MASKED_IMAGE)) require(reader.remaining() >= 15) val x = reader.getShort().toInt(); val y = reader.getShort().toInt() val w = reader.getShort().toInt() and 65535; val h = reader.getShort().toInt() and 65535 @@ -42,16 +40,6 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val val count = reader.getShort().toInt() and 65535 require(count <= 2048) require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) - val animation = if (kind == DrawRecordKind.ANIMATED_MENU_SELECTION) { - require(reader.remaining() >= 12) - val dx = reader.getShort().toInt() - val dy = reader.getShort().toInt() - val elapsed = reader.getShort().toInt() and 65535 - val token = reader.getInt() - val duration = reader.getShort().toInt() and 65535 - require(duration > 0 && elapsed <= duration) - Animation(dx, dy, drawAnimationTimeMs() - elapsed, token, duration) - } else null val gray = ByteArray(w * h); reader.get(gray) require(reader.remaining() >= count * 8) val occlusions = List(count) { IntArray(4) { reader.getShort().toInt() and 65535 } } @@ -68,8 +56,7 @@ class MenuSelection(val x: Int, val y: Int, val width: Int, val height: Int, val } } } - val normalizedKind = if (kind == DrawRecordKind.ANIMATED_MENU_SELECTION) DrawRecordKind.MENU_SELECTION else kind - return MenuSelection(x, y, w, h, radius, background, border, depth, BmpUtil.pack4bppFromGray8(gray, w, h), occlusions, normalizedKind, mask, animation) + return MenuSelection(x, y, w, h, radius, background, border, depth, BmpUtil.pack4bppFromGray8(gray, w, h), occlusions, kind, mask) } } } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt index 17195151..c48a81c2 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt @@ -1,18 +1,24 @@ package com.faceclaw.app /** Immutable shell snapshot. Keys identify writable surfaces across repaints, not their pixels. */ -class ShellScene(val layers: List, val selections: List = emptyList()) { - class Layer(val key: Int, val x: Int, val y: Int, val width: Int, val height: Int, val dim: Int, val packed: ByteArray, val selections: List = emptyList(), val depth: Int = 0) +class ShellScene(val layers: List, val selections: List = emptyList()) { + class Layer(val key: Int, val x: Int, val y: Int, val width: Int, val height: Int, val dim: Int, val packed: ByteArray, val selections: List = emptyList(), val depth: Int = 0) val allSelections = selections + layers.flatMap { it.selections } + val retainedResources = allSelections.flatMap { it.resources } + init { require(retainedResources.size + layers.size < 511) } val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${it.depth},${CachedResource(it.packed).hash},${it.selections.joinToString { row -> row.fingerprint }}" } + selections.joinToString { it.fingerprint } fun calls(width: Int, height: Int, surfaces: IntArray, selected: IntArray): List { val calls = ArrayList(); var rowId = 0 val now = drawAnimationTimeMs() - for (row in selections) calls.addAll(row.calls(selected[rowId++], now)) + fun add(row: RetainedDrawing) { + calls.addAll(row.calls(selected.copyOfRange(rowId, rowId + row.resources.size), now)) + rowId += row.resources.size + } + for (row in selections) add(row) for ((index, layer) in layers.withIndex()) { if (layer.dim < 256) calls.add(DrawProtocol.lut(width, height, layer.dim)) calls.add(DrawProtocol.image(surfaces[index], layer.x, layer.y, depth = layer.depth)) - for (row in layer.selections) calls.addAll(row.calls(selected[rowId++], now)) + for (row in layer.selections) add(row) } return calls } @@ -22,7 +28,7 @@ class ShellScene(val layers: List, val selections: List = val surfaces = IntArray(layers.size) { id -> val layer = layers[id]; resources[id] = DrawProtocol.rawImage(layer.width, layer.height, layer.packed); id } - val rows = IntArray(allSelections.size) { id -> resources[id + layers.size] = allSelections[id].resource.bytes; id + layers.size } + val rows = IntArray(retainedResources.size) { id -> resources[id + layers.size] = retainedResources[id].bytes; id + layers.size } resources[511] = DrawProtocol.displayList(calls(width, height, surfaces, rows)) DisplayListRenderer(resources, rightLens = rightLens).render(511, DisplayListRenderer.Target(screen, width, height), DisplayListRenderer.Target(output, width, height)) val target = DisplayListRenderer.Target(output, width, height) @@ -42,8 +48,8 @@ class ShellScene(val layers: List, val selections: List = resources[id] = DrawProtocol.rawImage(layer.width, layer.height, layer.packed) id } - val rows = IntArray(allSelections.size) { id -> - resources[id + layers.size] = allSelections[id].resource.bytes + val rows = IntArray(retainedResources.size) { id -> + resources[id + layers.size] = retainedResources[id].bytes id + layers.size } resources[511] = DrawProtocol.displayList(calls(width, height, surfaces, rows)) @@ -73,11 +79,11 @@ class ShellScene(val layers: List, val selections: List = val depth = reader.getShort().toInt(); require(depth in -128..127) require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536 && reader.remaining() >= w * h) val gray = ByteArray(w * h); reader.get(gray) - val selections = List(selectionCount) { MenuSelection.read(reader, reader.get().toInt()) } + val selections = List(selectionCount) { readRetainedDrawing(reader, reader.get().toInt()) } layers.add(Layer(key, x, y, w, h, dim, BmpUtil.pack4bppFromGray8(gray, w, h), selections, depth)) } require(reader.remaining() == 0) - require(layers.sumOf { it.selections.size } + layers.size < 511) + require(layers.sumOf { layer -> layer.selections.sumOf { it.resources.size } } + layers.size < 511) require(layers.map { it.key }.toSet().size == layers.size) return ShellScene(layers) } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index c862d47d..0a52c70e 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -51,7 +51,7 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr var out: MutableList = ArrayList() while ((cursor.remaining() >= 1)) { var kind: Int = (cursor.get() and 0xff) - if (DrawRecordKind.isPresentation(kind)) { out.add(ScreenDraw.image(0, 0, 0).also { it.selection = MenuSelection.read(cursor, kind) }); continue } + if (DrawRecordKind.isPresentation(kind)) { out.add(ScreenDraw.image(0, 0, 0).also { it.selection = readRetainedDrawing(cursor, kind) }); continue } if (((kind == ScreenDraw.KIND_GLYPH) && (cursor.remaining() >= 11))) { var fontId: Int = (cursor.getShort().toInt() and 0xffff) var encoding: Int = cursor.getInt() @@ -108,7 +108,7 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr * raster comes from ImageAtlas under imageId. */ class ScreenDraw { - @JvmField var selection: MenuSelection? = null + @JvmField var selection: RetainedDrawing? = null companion object { const val KIND_GLYPH: Int = DrawRecordKind.GLYPH @@ -631,7 +631,7 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr var fingerprint: StringBuilder = StringBuilder() fingerprint.append(screenWidth).append('x').append(screenHeight) var draws: MutableList = ArrayList() - val selections = ArrayList() + val selections = ArrayList() for (surface in ordered) { if (!surface.visible || (shellScene != null && surface.id == "shell")) { continue diff --git a/tests/ai-chat.test.cjs b/tests/ai-chat.test.cjs index 8367b291..bfbcf03b 100644 --- a/tests/ai-chat.test.cjs +++ b/tests/ai-chat.test.cjs @@ -355,7 +355,7 @@ function chatLayerEnv() { const env = conversations(); const textwrap = load('app/graphics/textwrap.ts', {}); const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} }); - const graphics = load('app/graphics/image.ts', { './textwrap': textwrap }); + const graphics = require('../.test-build/app/graphics/image.js'); const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/terminus/ter-u12n.bdf'), 'utf8')); let windowOptions; const { createAiChatWindow } = load('app/apps/ai-chat/ai-chat-app.ts', { diff --git a/tests/brightness-picker.test.cjs b/tests/brightness-picker.test.cjs index 59569452..037d45c5 100644 --- a/tests/brightness-picker.test.cjs +++ b/tests/brightness-picker.test.cjs @@ -15,7 +15,7 @@ function load(file, modules = {}) { } const textwrap = load('app/graphics/textwrap.ts'); -const graphics = load('app/graphics/image.ts', { './textwrap': textwrap }); +const graphics = require('../.test-build/app/graphics/image.js'); const plane = load('app/graphics/plane.ts', { './image': graphics }); const gestures = load('app/ui/gestures.ts'); const numeric = load('app/util/numeric-util.ts'); diff --git a/tests/compass-debug.test.cjs b/tests/compass-debug.test.cjs index d9057409..215dcc88 100644 --- a/tests/compass-debug.test.cjs +++ b/tests/compass-debug.test.cjs @@ -17,7 +17,7 @@ function load(file, modules = {}, globals = {}) { return context.exports; } const textwrap = load('app/graphics/textwrap.ts'); -const graphics = load('app/graphics/image.ts', { './textwrap': textwrap }); +const graphics = require('../.test-build/app/graphics/image.js'); const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} }); const font = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8')); const small = font(18), large = font(32); diff --git a/tests/compass-texture-cache.test.cjs b/tests/compass-texture-cache.test.cjs index 08e36e12..8cc9670f 100644 --- a/tests/compass-texture-cache.test.cjs +++ b/tests/compass-texture-cache.test.cjs @@ -19,7 +19,7 @@ function load(file, modules = {}, extra = '', globals = {}) { const textwrap = load('app/graphics/textwrap.ts'); const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} }); -const graphics = load('app/graphics/image.ts', { './textwrap': textwrap }); +const graphics = require('../.test-build/app/graphics/image.js'); const { GrayImage } = graphics; const font = (size) => BdfFont.parse(fs.readFileSync( path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8')); @@ -156,7 +156,7 @@ test('the background registers once and uses a nine-byte image reference on late return 1; } } } } }, }); - const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas, './presentation-wire': load('app/graphics/presentation-wire.ts') }); + const { prepareFrameDraws } = load('app/graphics/glyph-wire.ts', { '../native/texture-atlas': atlas, './presentation-wire': require('../.test-build/app/graphics/presentation-wire.js') }); const background = compass.createCompassBackground(576, 260, 256, 193.25, 98, 140, 1); for (const heading of [0, 1, 2, 45, 90]) { const image = background.clone(); diff --git a/tests/display-list-authoring.test.cjs b/tests/display-list-authoring.test.cjs new file mode 100644 index 00000000..d3f7cc61 --- /dev/null +++ b/tests/display-list-authoring.test.cjs @@ -0,0 +1,83 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { DrawExpression: E, ExprOp, varint, DrawBytes, evaluate } = require('../.test-build/app/graphics/draw-expression.js'); +const { DrawOp, SCREEN, encodeDisplayList, readDisplayList, paintDisplayList } = require('../.test-build/app/graphics/display-list.js'); +const { GrayImage } = require('../.test-build/app/graphics/image.js'); +const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js'); +// Also consumed by FrameDisplayListTest.kt: bridge bytes, not independently rebuilt native calls. +const MENU = '077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f'; +const MULTI = '074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000'; + +test('extended integers agree with firmware widths and sign extension', () => { + const vectors = [[63,'3f'],[-64,'40'],[64,'8040'],[-65,'bfbf'],[8191,'9fff'],[-8192,'a000'],[8192,'c02000'],[-8193,'dfdfff'],[1048575,'cfffff'],[-1048576,'d00000'],[1048576,'e0100000'],[-1048577,'efefffff'],[134217727,'e7ffffff'],[-134217728,'e8000000'],[134217728,'f008000000'],[2147483647,'f07fffffff'],[-2147483648,'f080000000']]; + for (const [value, hex] of vectors) { + assert.equal(Buffer.from(varint(value)).toString('hex'), hex); + assert.equal(new DrawBytes(Buffer.from(hex, 'hex')).variable(), value); + } + for (const n of [0,127,128,16383,16384,2097151,2097152,268435455,268435456,4294967295]) assert.equal(new DrawBytes(Uint8Array.from(varint(n,false))).variable(false), n); + assert.throws(() => E.i32(2147483648)); + assert.throws(() => E.f32(Infinity)); +}); + +test('typed expressions follow i32/f32 arithmetic, easing, time and error semantics', () => { + assert.equal(evaluate(E.i32(2147483647).add(E.i32(1)),0).value, -2147483648); + assert.equal(evaluate(E.i32(7).neg().div(E.i32(2)),0).value, -3); + assert.equal(evaluate(E.i32(-2147483648).div(E.i32(-1)),0).value, -2147483648); + assert.equal(evaluate(E.f32(1.5).mul(E.f32(2)).toInt(),0).value, 3); + for (let op = ExprOp.SMOOTHSTEP; op <= ExprOp.EASE_IN_OUT_CUBIC; op++) { + assert.equal(evaluate(E.f32(0).ease(op),0).value, 0); + assert.equal(evaluate(E.f32(1).ease(op),0).value, 1); + } + assert.deepEqual(evaluate(E.i32(300).time(),0,150), {value:150,pending:true}); + assert.deepEqual(evaluate(E.i32(300).time(),0,300), {value:300,pending:false}); + assert.deepEqual(evaluate(E.i32(300).time().div(E.i32(0)),0,150), {value:0,pending:false}); + assert.deepEqual(evaluate(E.decode(Uint8Array.of(ExprOp.IADD)),0), {value:0,pending:false}); +}); + +test('menu authors the golden generic list and stable timeline identity', () => { + const original = Date.now; Date.now = () => 1150; + try { + const image = new GrayImage(8,4); + image.drawMenuSelection(new GrayImage(2,2,255),3,2,16,48,1,2,{dx:-2,dy:-4,startedAt:1000,token:42,durationMs:300}); + assert.equal(Buffer.from(encodePresentation(image.draws[0])).toString('hex'), MENU); + const before = image.fingerprint(); Date.now = () => 1250; + assert.equal(image.fingerprint(), before, 'wall time does not change frame identity'); + const decoded = readDisplayList(Buffer.from(MENU,'hex'),0,1150).placed; + const y = decoded.displayList.calls[0].y; + assert.deepEqual(evaluate(y,150,0), {value:-2,pending:true}); + assert.deepEqual(evaluate(y,150,150), {value:0,pending:false}); + assert.deepEqual(evaluate(y,300,0), {value:0,pending:false}); + } finally { Date.now = original; } +}); + +test('local resources, relative placement, stereo and screen restoration round-trip', () => { + const list = { resources:[{width:2,height:1,pixels:Uint8Array.of(0,255)},{width:1,height:1,pixels:Uint8Array.of(96)}], calls:[ + {op:DrawOp.IMAGE,resource:0,x:0,y:0,transparent:true}, + {op:DrawOp.RECT_COPY,resource:1,x:0,y:0,width:1,height:1,dx:2,dy:0}, + {op:DrawOp.RECT_COPY,resource:SCREEN,x:-1,y:0,width:1,height:1,dx:-1,dy:0,depth:-2}, + ] }; + const bytes = encodeDisplayList({displayList:list,x:3,y:2,width:4,height:1,depth:2}); + assert.equal(Buffer.from(bytes).toString('hex'), MULTI); + const {placed,end} = readDisplayList(bytes,0); + assert.equal(end,bytes.length); + for (const right of [false,true]) { + const screen = new Uint8Array(64).fill(32), output = screen.slice(); + paintDisplayList(output,screen,8,8,placed,right); + assert.equal(output[2*8+(right?3:5)],240); + assert.equal(output[2*8+(right?4:6)],96); + assert.equal(output[2*8+2],32); + } + for (let i=0;i readDisplayList(bytes.slice(0,i),0)); + const invalid = {...list, calls:[{op:DrawOp.IMAGE,resource:2,x:0,y:0,transparent:true}]}; + assert.throws(() => encodeDisplayList({displayList:invalid,x:0,y:0,width:4,height:1,depth:0})); +}); + +test('frame submission supports resource-free lists and plain PRESENT-relative time', () => { + const image = new GrayImage(8,8); + image.drawDisplayList({resources:[],calls:[{op:DrawOp.ROUNDED_RECT,x:E.i32(4).time(),y:0,width:2,height:2,radius:0,background:15,border:16}]},0,0,8,8); + const bytes = encodePresentation(image.draws[0]); + const {placed} = readDisplayList(bytes,0,1000); + const output = new Uint8Array(64), screen = output.slice(); + paintDisplayList(output,screen,8,8,placed,false,1002); + assert.equal(output[2],240); assert.equal(output[0],0); +}); diff --git a/tests/input-events.test.cjs b/tests/input-events.test.cjs index cf20fa8c..41735ccb 100644 --- a/tests/input-events.test.cjs +++ b/tests/input-events.test.cjs @@ -83,7 +83,7 @@ test('bounded history preserves equal-time events, snapshots and arrival gaps; p test('Input events captures while visible, pauses for history, and unsubscribes on removal', () => { const textwrap = load('app/graphics/textwrap.ts'); - const graphics = load('app/graphics/image.ts', { './textwrap': textwrap }); + const graphics = require('../.test-build/app/graphics/image.js'); const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} }); const font = BdfFont.parse(read('app/fonts/terminus/ter-u18n.bdf')); class RecordingImage extends graphics.GrayImage { diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt index dae59f65..11fd7001 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt @@ -72,48 +72,6 @@ class DrawExpressionTest { assertEquals(110 to false, evaluate(continued.program, 250)) } - @Test fun animatedMenuBridgePreservesElapsedTimeAndTranslation() { - // Tag 6 record emitted by the TypeScript bridge: elapsed=200, delta=(-2,-4), duration=300. - val wire = hex("06030002000200020001001030020000fefffcffc8002a0000002c01ffffffff") - val input = ArrayByteReader(wire) - assertEquals(6, input.get().toInt()) - val row = MenuSelection.read(input, DrawRecordKind.ANIMATED_MENU_SELECTION).translated(10, 10) - assertEquals(0, input.remaining()) - val motion = assertNotNull(row.animation) - assertEquals(42, motion.token) - assertEquals(300, motion.durationMs) - assertEquals(-2, motion.dx) - assertEquals(-4, motion.dy) - val call = row.calls(7, motion.startedAt + 200).first() - for ((elapsed, expected) in listOf(0L to (12 to 10), 100L to (13 to 12))) { - val reader = DrawReader(call) - assertEquals(8, reader.readU8()) - assertEquals(DRAW_FLAG_DEPTH, reader.readU8()) - assertEquals(2, reader.readS8()) - val frame = DrawEvaluation(elapsed) - assertEquals(expected.first, ExtendedVarint.evaluate(reader, frame)) - assertEquals(expected.second, ExtendedVarint.evaluate(reader, frame)) - assertEquals(elapsed < 100, frame.animationPending) - } - for (end in 1 until wire.size) assertFails { - MenuSelection.read(ArrayByteReader(wire.copyOf(end), 1), DrawRecordKind.ANIMATED_MENU_SELECTION) - } - } - - @Test fun menuCoordinatesUseTheSuppliedDuration() { - val row = MenuSelection(0, 4, 2, 2, 0, 15, 16, 0, ByteArray(2), - animation = MenuSelection.Animation(0, -4, 1000, 42, 120)) - val call = row.calls(7, 1000).first() - for ((elapsed, y) in listOf(0L to 0, 60L to 2, 120L to 4)) { - val reader = DrawReader(call) - reader.readBytes(3) // opcode, flags, depth - val frame = DrawEvaluation(elapsed) - assertEquals(0, ExtendedVarint.evaluate(reader, frame)) - assertEquals(y, ExtendedVarint.evaluate(reader, frame)) - assertEquals(elapsed < 120, frame.animationPending) - } - } - @Test fun playerSchedulesOnlyUnfinishedFramesAndCancelsStaleCallbacks() { val call = DrawProtocol.roundedRect(DrawValue.Integer(0), DrawValue.animate(0, 4, 300), 2, 2, 0, 15) val renderer = DisplayListRenderer(mapOf(1 to DrawProtocol.displayList(listOf(call)))) diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt new file mode 100644 index 00000000..29975bc8 --- /dev/null +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt @@ -0,0 +1,90 @@ +package com.faceclaw.app + +import kotlin.test.* + +class FrameDisplayListTest { + // Golden records emitted by display-list-authoring.test.cjs. + private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f" + private val multi = "074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000" + private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray() + private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList { + val reader = ArrayByteReader(bytes) + assertEquals(DrawRecordKind.DISPLAY_LIST, reader.get().toInt()) + return FrameDisplayList.read(reader, now).also { assertEquals(0, reader.remaining()) } + } + + @Test fun authoredExpressionsRebindOnPresentAndTranslateWithTheSurface() { + val row = read(hex(menu)).translated(10, 10) + assertEquals(1, row.resources.size) + fun coordinates(now: Long, elapsed: Long): Triple { + val call = DrawReader(row.calls(intArrayOf(7), now).first()) + assertEquals(DRAW_OP_ROUNDED_RECT, call.readU8()) + assertEquals(DRAW_FLAG_DEPTH, call.readU8()) + assertEquals(2, call.readS8()) + val frame = DrawEvaluation(elapsed) + val x = ExtendedVarint.evaluate(call, frame) + val y = ExtendedVarint.evaluate(call, frame) + return Triple(x, y, frame.animationPending) + } + assertEquals(Triple(12, 10, true), coordinates(1150, 0)) + assertEquals(Triple(13, 12, false), coordinates(1150, 150)) + assertEquals(coordinates(1150, 75), coordinates(1225, 0), "another PRESENT preserves progress") + assertEquals(Triple(13, 12, false), coordinates(1400, 0)) + val later = hex(menu).also { it[18] = 200.toByte() } // envelope 5 + elapsed offset 13 + assertEquals(read(hex(menu)).fingerprint, read(later).fingerprint) + val other = hex(menu).also { it[14] = 43 } // timeline token + assertNotEquals(read(hex(menu)).fingerprint, read(other).fingerprint) + } + + @Test fun localResourceIdsAreResolvedAndScreenCopiesStayAtScreenDepth() { + val list = read(hex(multi)).translated(10, 10) + val calls = list.calls(intArrayOf(41, 42), 1150) + assertContentEquals(DrawProtocol.image(41, 13, 12, 31, depth = 2), calls[0]) + assertContentEquals(DrawProtocol.rectCopy(42, 0, 0, 1, 1, 15, 12, depth = 2), calls[1]) + assertContentEquals(DrawProtocol.rectCopy(DrawProtocol.SCREEN, 12, 12, 1, 1, 12, 12, depth = 0), calls[2]) + val scene = ShellScene(emptyList(), listOf(read(hex(multi)))) + assertEquals(2, scene.retainedResources.size) + for (right in listOf(false, true)) { + val pixels = scene.preview(ByteArray(64) { 32 }, 8, 8, right) + assertEquals(240, pixels[16 + if (right) 3 else 5].toInt() and 255) + assertEquals(96, pixels[16 + if (right) 4 else 6].toInt() and 255) + assertEquals(32, pixels[18].toInt() and 255) + } + val cache = ResourceCacheState() + val planner = ScenePlanner(cache) + val screen = ByteArray(32) { 0x22 } + planner.plan(screen, 8, 8, null, scene, 1) + val ids = scene.retainedResources.map { cache.resourceId(it) } + assertTrue(ids.all { it >= 0 }); assertNotEquals(ids[0], ids[1]) + planner.plan(screen, 8, 8, null, scene, 1) + assertEquals(ids, scene.retainedResources.map { cache.resourceId(it) }) + } + + @Test fun frameAndShellSubmissionUseTheSameGenericDecoder() { + val c = SurfaceCompositor() + c.configureScreen(8, 8) + c.configureSurface("app", 0, 0, 8, 8, 0, 0) + c.submitSurface("app", ArrayByteReader(ByteArray(64) { 32 }), 0, 0, 8, 8, "list", + ArrayByteReader(hex(multi))) + val frame = c.composite() + assertEquals(2, frame.shellScene.retainedResources.size) + assertEquals(240, frame.gray[21].toInt() and 255) + assertTrue(frame.screenGray.all { it.toInt() == 32 }) + // One opaque 1x1 shell layer, with one generic list after its pixels. + val layer = DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(0) + DrawProtocol.word(0) + + DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(256) + DrawProtocol.word(1) + + DrawProtocol.word(0) + byteArrayOf(32) + hex(multi) + val shell = ShellScene.decode(ArrayByteReader(layer)) + assertEquals(2, shell.retainedResources.size) + assertEquals(240, shell.preview(ByteArray(64) { 32 }, 8, 8)[21].toInt() and 255) + } + + @Test fun rejectsTruncationBadResourcesAndTrailingData() { + val bytes = hex(multi) + for (end in 1 until bytes.size) assertFails { read(bytes.copyOf(end)) } + assertFails { read(bytes.copyOf().also { it[40] = 9 }) } // first image's local resource + val trailing = bytes + byteArrayOf(0) + trailing[1] = (trailing[1] + 1).toByte() + assertFails { read(trailing) } + } +} diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs index 6d6167e3..2709219b 100644 --- a/tests/menu-display-list.test.cjs +++ b/tests/menu-display-list.test.cjs @@ -48,7 +48,7 @@ test('shell menu selection survives serialization and is not baked into its surf test('later opaque planes occlude a replayed selection without erasing its visible part',()=>{ const image=menu().paint(),row=image.draws.find(d=>d.presentation),cover=new graphics.GrayImage(10,8,1); const flat=planes.flattenPlanesWithDraws([{image,x:0,y:0},{image:cover,x:row.x+10,y:row.y+2}]); - const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.ok(records[0].occlusions.length); + const records=wire.presentationRecords(prepareFrameDraws(flat.draws));assert.ok(records[0].displayList.calls.some(c => c.op === 2 && c.resource === 65535)); const c=new SurfaceCompositor(80,80);c.configureSurface('app',{x:0,y:0,width:80,height:80,zOrder:0,transparency:'opaque'}); c.submitSurfaceFrame('app',flat.image.pixels,{x:0,y:0,width:80,height:80},prepareFrameDraws(flat.draws)); const preview=c.composite(); diff --git a/tests/menu-highlight-motion.test.cjs b/tests/menu-highlight-motion.test.cjs index f74279b9..ca561f4b 100644 --- a/tests/menu-highlight-motion.test.cjs +++ b/tests/menu-highlight-motion.test.cjs @@ -35,7 +35,7 @@ test('bridge and fallback preview use the supplied animation duration', () => { image.drawMenuSelection(new GrayImage(2, 2), 5, 0, 0, 255, 0, 0, { dx: -4, dy: 0, startedAt: 1000, token: 1, durationMs: 100 }); const record = readPresentation(encodePresentation(image.draws[0]), 0); - assert.equal(record.selection.animation.durationMs, 100); + assert.ok(record.selection.displayList); const screen = new Uint8Array(16), output = new Uint8Array(16); paintPresentation(output, screen, 8, 2, record.selection); assert.equal(output[3], 240, 'halfway at 50 ms'); @@ -56,11 +56,11 @@ test('animated selection bridge carries relative start, elapsed time and stable image.drawMenuSelection(new GrayImage(2, 2, 255), 3, 2, 16, 48, 1, 2, { dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS }); const bytes = encodePresentation(image.draws[0]); - assert.equal(bytes[0], 6); - assert.equal(bytes.length, 32); + assert.equal(bytes[0], 7); const record = readPresentation(bytes, 0); assert.equal(record.end, bytes.length); - assert.deepEqual(record.selection.animation, { dx: -2, dy: -4, startedAt: 1000, token: 42, durationMs: MENU_HIGHLIGHT_DURATION_MS }); + assert.deepEqual(record.selection.displayList.timeline, { startedAt: 1000, token: 42 }); + assert.equal(record.selection.displayList.calls[0].op, 8); assert.equal(record.selection.x, 3); assert.equal(record.selection.y, 2); } finally { Date.now = now; } diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index bffedd4d..248b8caf 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -137,7 +137,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp const { prefs } = store(); let refreshes = 0, closes = 0; const textwrap = load('app/graphics/textwrap.ts'); - const graphics = load('app/graphics/image.ts', () => textwrap); + const graphics = require('../.test-build/app/graphics/image.js'); const { BdfFont } = load('app/graphics/bdffont.ts', () => ({})); const font = BdfFont.parse(source('app/fonts/terminus/ter-u20n.bdf')); class RecordingImage extends graphics.GrayImage { diff --git a/tests/notification-filter.test.cjs b/tests/notification-filter.test.cjs index 81811ca5..07d2c57b 100644 --- a/tests/notification-filter.test.cjs +++ b/tests/notification-filter.test.cjs @@ -53,7 +53,7 @@ function ui(fontSize = 12) { let dismissals = 0; let closes = 0; const textwrap = load('app/graphics/textwrap.ts'); - const graphics = load('app/graphics/image.ts', () => textwrap); + const graphics = require('../.test-build/app/graphics/image.js'); const { BdfFont } = load('app/graphics/bdffont.ts', () => ({})); const font = BdfFont.parse(source(`app/fonts/terminus/ter-u${fontSize}n.bdf`)); class RecordingImage extends graphics.GrayImage { From 123c1142d65f044a5225bdcacc611c6330babdf4 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Wed, 23 Sep 2026 22:05:44 -0700 Subject: [PATCH 18/27] Better menu class; use it in the Music app --- app/apps/music/music-app.ts | 142 +++++------- app/ui/menu-core.ts | 335 +++++++++++++++++++++++++++++ app/ui/menu.ts | 129 +++++------ tests/brightness-picker.test.cjs | 3 + tests/menu-core.test.cjs | 240 +++++++++++++++++++++ tests/menu-display-list.test.cjs | 5 +- tests/music-settings.test.cjs | 1 + tests/notification-filter.test.cjs | 1 + tests/tsconfig.json | 1 + 9 files changed, 694 insertions(+), 163 deletions(-) create mode 100644 app/ui/menu-core.ts create mode 100644 tests/menu-core.test.cjs diff --git a/app/apps/music/music-app.ts b/app/apps/music/music-app.ts index 40eb5600..0996ad82 100644 --- a/app/apps/music/music-app.ts +++ b/app/apps/music/music-app.ts @@ -3,7 +3,8 @@ import { GrayImage } from "../../graphics/image"; import { wrapText, truncateText } from "../../graphics/textwrap"; import { clamp } from "../../util/numeric-util"; import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL_DOWN, GESTURE_SCROLL_UP, type InputEvent, isDirectionalInput } from "../../ui/gestures"; -import { MenuLayer, drawSelectionHighlight, drawSubmenuIndicator } from "../../ui/menu"; +import { MenuLayer, drawSubmenuIndicator } from "../../ui/menu"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { lineStep, tightRowHeight } from "../../ui/metrics"; import { mediaControllerBridge, type MediaControllerState, type MediaQueueItem } from "../../native/media-controller"; import { mediaBrowserBridge, type MediaBrowserApp } from "../../native/media-browser"; @@ -28,6 +29,8 @@ const ACTION_X = 22; const ACTION_WIDTH = 154; const COLUMN_DIVIDER_X = 190; const QUEUE_X = 204; +/** Horizontal inset of row text from its selection box. */ +const LIST_TEXT_INSET = 6; const PLAYLIST_ACTION_INDEX = 1; type MusicAction = @@ -49,9 +52,20 @@ class MusicAppLayer implements Layer { // Watch swipes skip tracks: right = next, left = previous. readonly acceptsDirectional = true; private focusColumn: FocusColumn = "actions"; - private selectedActionIndex = 0; - private selectedQueueIndex = 0; - private queueScrollRow = 0; + private readonly actionsMenu = new Menu({ + wrap: true, + rowGap: 1, + highlight: { radius: 4 }, + getHeight: () => tightRowHeight(getDefaultSmallFont()), + draw: (args) => this.drawAction(args), + }); + private readonly queueMenu = new Menu({ + wrap: false, + rowGap: 1, + highlight: { radius: 4 }, + getHeight: () => tightRowHeight(getDefaultSmallFont()), + draw: (args) => this.drawQueueItem(args), + }); private art: GrayImage | null = null; private artKey = ""; @@ -124,83 +138,49 @@ class MusicAppLayer implements Layer { const actions = this.buildActions(media, queue); this.reconcileSelection(actions, queue); const listHeight = height - LIST_TOP - LIST_BOTTOM_MARGIN; - const rowH = tightRowHeight(font); - const visibleRows = Math.max(1, (listHeight / rowH) | 0); - if (this.selectedQueueIndex < this.queueScrollRow) { - this.queueScrollRow = this.selectedQueueIndex; - } else if (this.selectedQueueIndex >= this.queueScrollRow + visibleRows) { - this.queueScrollRow = this.selectedQueueIndex - visibleRows + 1; - } - this.queueScrollRow = clamp(this.queueScrollRow, 0, Math.max(0, queue.length - visibleRows)); - - for (let index = 0; index < actions.length; index++) { - const action = actions[index]!; - const y = LIST_TOP + index * rowH; - const selected = index === this.selectedActionIndex; - const highlightX = ACTION_X - 6; - const highlightY = y - 1; - const highlightWidth = ACTION_WIDTH + 8; - const highlightHeight = rowH - 1; - if (selected) { - drawSelectionHighlight( - image, - highlightX, - highlightY, - highlightWidth, - highlightHeight, - ctx.stack.isFocused() && this.focusColumn === "actions", - 4, - ); - } - const value = !action.enabled ? (selected ? 130 : 90) : selected ? 255 : 200; - image.drawText(font, ACTION_X, y + 1, truncateText(font, action.label, ACTION_WIDTH - 16), value); - if ((action.kind === "playlist" || action.kind === "browse") && action.enabled) { - drawSubmenuIndicator(image, font, highlightX, highlightY, highlightWidth, highlightHeight, value); - } - } + const focused = ctx.stack.isFocused(); + // Row boxes start one pixel above LIST_TOP so the text lands at LIST_TOP + 1. + this.actionsMenu.paint( + image, + { x: ACTION_X - LIST_TEXT_INSET, y: LIST_TOP - 1, width: ACTION_WIDTH + 2 * LIST_TEXT_INSET - 4, height: listHeight }, + focused && this.focusColumn === "actions", + ); image.drawLine(COLUMN_DIVIDER_X, LIST_TOP - 3, COLUMN_DIVIDER_X, height - LIST_BOTTOM_MARGIN - 3, 45); if (!queue.length) { image.drawText(font, QUEUE_X, LIST_TOP + 1, "Playlist unavailable", 90); } else { const queueWidth = width - QUEUE_X - 20; - const lastVisible = Math.min(queue.length, this.queueScrollRow + visibleRows); - for (let index = this.queueScrollRow; index < lastVisible; index++) { - const item = queue[index]!; - const y = LIST_TOP + (index - this.queueScrollRow) * rowH; - const selected = index === this.selectedQueueIndex; - if (selected) { - drawSelectionHighlight( - image, - QUEUE_X - 6, - y - 1, - queueWidth + 8, - rowH - 1, - ctx.stack.isFocused() && this.focusColumn === "playlist", - 4, - ); - } - const label = `${item.active ? "> " : " "}${item.title || "(untitled)"}`; - image.drawText(font, QUEUE_X, y + 1, truncateText(font, label, queueWidth - 4), selected ? 255 : 200); - } - if (queue.length > visibleRows) { - const trackHeight = visibleRows * rowH - 4; - const trackX = width - 12; - image.fillRect(trackX, LIST_TOP, 3, trackHeight, 30); - const thumbHeight = Math.max(8, (trackHeight * visibleRows / queue.length) | 0); - const maxScrollRow = queue.length - visibleRows; - const thumbY = LIST_TOP + (((trackHeight - thumbHeight) * this.queueScrollRow / maxScrollRow) | 0); - image.fillRect(trackX, thumbY, 3, thumbHeight, 120); - } + this.queueMenu.paint( + image, + { x: QUEUE_X - LIST_TEXT_INSET, y: LIST_TOP - 1, width: queueWidth + 2 * LIST_TEXT_INSET - 4, height: listHeight }, + focused && this.focusColumn === "playlist", + ); + this.queueMenu.drawScrollbar(image, width - 12, LIST_TOP, listHeight - 4); } return image; } + private drawAction({ image, item: action, x, y, width, height, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const value = !action.enabled ? (selected ? 130 : 90) : selected ? 255 : 200; + image.drawText(font, x + LIST_TEXT_INSET, y + 2, truncateText(font, action.label, ACTION_WIDTH - 16), value); + if ((action.kind === "playlist" || action.kind === "browse") && action.enabled) { + drawSubmenuIndicator(image, font, x, y, width, height, value); + } + } + + private drawQueueItem({ image, item, x, y, width, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const label = `${item.active ? "> " : " "}${item.title || "(untitled)"}`; + image.drawText(font, x + LIST_TEXT_INSET, y + 2, truncateText(font, label, width - 2 * LIST_TEXT_INSET), selected ? 255 : 200); + } + async handleInput(event: InputEvent, ctx: LayerContext): Promise { if (event.type === "double-click" && this.focusColumn === "playlist") { this.focusColumn = "actions"; - this.selectedActionIndex = PLAYLIST_ACTION_INDEX; + this.actionsMenu.select(PLAYLIST_ACTION_INDEX); return; } const media = mediaControllerBridge.snapshot(); @@ -237,31 +217,20 @@ class MusicAppLayer implements Layer { case "swipe-down": return this.handleInput({ type: "scroll-down", timestampMs: event.timestampMs }, ctx); case "scroll-up": - if (this.focusColumn === "playlist") { - this.selectedQueueIndex = Math.max(0, this.selectedQueueIndex - 1); - } else { - this.selectedActionIndex = (this.selectedActionIndex + actions.length - 1) % actions.length; - } - return; case "scroll-down": - if (this.focusColumn === "playlist") { - this.selectedQueueIndex = Math.min(Math.max(0, queue.length - 1), this.selectedQueueIndex + 1); - } else { - this.selectedActionIndex = (this.selectedActionIndex + 1) % actions.length; - } + await (this.focusColumn === "playlist" ? this.queueMenu : this.actionsMenu).handleInput(event); return; case "click": { if (this.focusColumn === "playlist") { - const item = queue[this.selectedQueueIndex]; + const item = this.queueMenu.selectedItem; if (item) { await mediaControllerBridge.skipToQueueItem(item.id); // The player rebuilds the queue with the chosen track at index 0. - this.selectedQueueIndex = 0; - this.queueScrollRow = 0; + this.queueMenu.select(0); } return; } - const action = actions[this.selectedActionIndex]; + const action = this.actionsMenu.selectedItem; if (!action || !action.enabled) return; if (action.kind === "play-pause") await mediaControllerBridge.playPause(); else if (action.kind === "previous") await mediaControllerBridge.skipPrevious(); @@ -271,7 +240,7 @@ class MusicAppLayer implements Layer { ctx.stack.push(new VolumeModalLayer(mediaControllerBridge.getMediaVolumePercent())); } else if (action.kind === "playlist") { const activeIndex = queue.findIndex((item) => item.active); - if (activeIndex >= 0) this.selectedQueueIndex = activeIndex; + if (activeIndex >= 0) this.queueMenu.select(activeIndex); this.focusColumn = "playlist"; } return; @@ -332,12 +301,13 @@ class MusicAppLayer implements Layer { ]; } + /** Hand the menus the freshly built rows; each keeps its selection index, clamped. */ private reconcileSelection(actions: MusicAction[], queue: MediaQueueItem[]): void { - this.selectedActionIndex = clamp(this.selectedActionIndex, 0, actions.length - 1); - this.selectedQueueIndex = clamp(this.selectedQueueIndex, 0, Math.max(0, queue.length - 1)); + this.actionsMenu.setItems(actions); + this.queueMenu.setItems(queue); if (!queue.length && this.focusColumn === "playlist") { this.focusColumn = "actions"; - this.selectedActionIndex = PLAYLIST_ACTION_INDEX; + this.actionsMenu.select(PLAYLIST_ACTION_INDEX); } } diff --git a/app/ui/menu-core.ts b/app/ui/menu-core.ts new file mode 100644 index 00000000..121ceb5d --- /dev/null +++ b/app/ui/menu-core.ts @@ -0,0 +1,335 @@ +import { GrayImage } from "../graphics/image"; +import type { InputEvent } from "./gestures"; +import { MenuHighlightMotion } from "./menu-highlight-motion"; + +/** Selected-row fill while the menu owns input; the outline alone marks an unfocused menu's selection. */ +export const MENU_HIGHLIGHT_FILL = 15; +export const MENU_HIGHLIGHT_STROKE = 45; +const SCROLLBAR_TRACK_VALUE = 30; +const SCROLLBAR_THUMB_VALUE = 120; +const SCROLLBAR_WIDTH = 3; +const SCROLLBAR_MIN_THUMB = 8; + +/** A rectangle in image coordinates. */ +export type MenuBox = { x: number; y: number; width: number; height: number }; + +export type MenuDrawArgs = { + /** + * Draw into this image, inside the (x, y, width, height) rect. For the + * selected row this is a scratch image exactly the rect's size (so x and y + * are 0), replayed over the highlight. Never draw relative to image.width + * or image.height, and never outside the rect. + */ + image: GrayImage; + item: T; + index: number; + x: number; + y: number; + width: number; + height: number; + selected: boolean; + /** Whether the menu owns input right now: the `focused` flag the host passed to paint. */ + focused: boolean; +}; + +export type MenuHighlightStyle = { + /** Corner radius of the selection box. Default 8. */ + radius?: number; + /** Stereo depth of the selection box. Default 0. */ + depth?: number; +}; + +export type MenuOptions = { + items?: readonly T[]; + /** Initial selection. Default: the first selectable item. */ + selectedIndex?: number | null; + /** Row pitch in pixels (including rowGap) for an item laid out at this width. */ + getHeight: (item: T, width: number) => number; + /** Default: every item is selectable. Non-selectable items (group labels) are skipped by navigation. */ + isSelectable?: (item: T) => boolean; + draw: (args: MenuDrawArgs) => void; + /** Called by activate() / a click with the selected item. */ + onSelect?: (item: T, index: number) => void | Promise; + /** + * Whether scrolling past either end wraps to the other. When false the + * selection stays put and onExitTop / onExitBottom is called instead. + */ + wrap?: boolean; + onExitTop?: () => void; + onExitBottom?: () => void; + /** Pixels between consecutive rows, excluded from each row's drawable box and highlight. Default 0. */ + rowGap?: number; + /** Selection box style, or false to draw no highlight (the draw callback shows the selection itself). */ + highlight?: MenuHighlightStyle | false; +}; + +type MenuLayout = { tops: number[]; heights: number[]; total: number }; + +/** + * A vertical list with one selected row: the menu proper, independent of the + * Layer stack. A host paints it into a rect of its own image and forwards + * scroll / click events while the menu has focus; the host keeps the rest + * (title, box, focus between several menus, back navigation). + * + * Rows may vary in height and some may be unselectable; navigation skips + * those. Scrolling is pixel-based: the viewport moves the minimum needed to + * keep the selection fully visible, then aligns to a row top so the list + * never starts with a partially visible row. Rows that don't fully fit at + * the bottom are not drawn. + */ +export class Menu { + private itemList: readonly T[]; + private selected: number | null; + private scrollY = 0; + private lastBox: MenuBox | null = null; + private readonly motion = new MenuHighlightMotion(); + + constructor(private readonly options: MenuOptions) { + this.itemList = options.items ?? []; + this.selected = options.selectedIndex === undefined + ? this.nextSelectable(null, 1) + : this.resolve(options.selectedIndex); + } + + get items(): readonly T[] { + return this.itemList; + } + + get selectedIndex(): number | null { + this.reconcile(); + return this.selected; + } + + get selectedItem(): T | null { + const index = this.selectedIndex; + return index === null ? null : this.itemList[index]!; + } + + /** Content offset of the viewport's top edge, in pixels. */ + get scrollTop(): number { + return this.scrollY; + } + + /** True when the content did not fit the box given to the last paint. */ + get overflows(): boolean { + if (!this.lastBox) return false; + return this.layout(this.lastBox.width).total > this.lastBox.height; + } + + /** + * Replace the items. `selectedIndex` names the new selection (null for + * none); left out, the selection stays at the same index, clamped into + * range. The viewport keeps the selected row at the same on-screen + * position when it can. + */ + setItems(items: readonly T[], selectedIndex?: number | null): void { + const width = this.lastBox?.width; + const before = this.selected !== null && width !== undefined + ? this.layout(width).tops[this.selected]! - this.scrollY + : null; + this.itemList = items; + this.selected = this.resolve(selectedIndex === undefined ? this.selected : selectedIndex); + if (before !== null && this.selected !== null && width !== undefined) { + this.scrollY = Math.max(0, this.layout(width).tops[this.selected]! - before); + } + } + + /** Move the selection; a non-selectable or out-of-range index lands on the nearest selectable one. */ + select(index: number | null): void { + this.selected = this.resolve(index); + } + + /** Step the selection by one selectable row; handles wrap and the exit callbacks. */ + moveSelection(delta: -1 | 1): void { + this.reconcile(); + const from = this.selected; + const next = this.nextSelectable(from, delta); + if (next !== null) { + if (from !== null) this.motion.navigate(from, false); + this.selected = next; + return; + } + if (from === null && this.scrollContent(delta)) return; + if (this.options.wrap) { + const wrapped = this.nextSelectable(null, delta); + if (wrapped !== null && wrapped !== from) { + if (from !== null) this.motion.navigate(from, true); + this.selected = wrapped; + } else if (from === null && this.lastBox) { + this.scrollY = delta > 0 ? 0 : this.maxScroll(this.layout(this.lastBox.width), this.lastBox.height); + } + return; + } + if (delta > 0) this.options.onExitBottom?.(); + else this.options.onExitTop?.(); + } + + /** Invoke onSelect for the selected item. Returns false when nothing is selected. */ + async activate(): Promise { + this.reconcile(); + if (this.selected === null) return false; + await this.options.onSelect?.(this.itemList[this.selected]!, this.selected); + return true; + } + + /** Handle scroll-up, scroll-down and click. Returns false for any other event, or a click with nothing selected. */ + async handleInput(event: InputEvent): Promise { + switch (event.type) { + case "scroll-up": + this.moveSelection(-1); + return true; + case "scroll-down": + this.moveSelection(1); + return true; + case "click": + return this.activate(); + default: + return false; + } + } + + /** The selectable item under image-coordinate y in the last painted box, for touch/mirror input. */ + indexAt(y: number): number | null { + const box = this.lastBox; + if (!box || y < box.y || y >= box.y + box.height) return null; + const layout = this.layout(box.width); + const contentY = y - box.y + this.scrollY; + for (let index = 0; index < this.itemList.length; index++) { + if (contentY >= layout.tops[index]! && contentY < layout.tops[index]! + layout.heights[index]!) { + return this.isSelectable(index) ? index : null; + } + } + return null; + } + + paint(image: GrayImage, box: MenuBox, focused: boolean): void { + this.lastBox = box; + this.reconcile(); + const layout = this.layout(box.width); + this.ensureVisible(layout, box.height); + const gap = this.options.rowGap ?? 0; + const highlight = this.options.highlight; + for (let index = 0; index < this.itemList.length; index++) { + const top = layout.tops[index]! - this.scrollY; + const height = layout.heights[index]! - gap; + const selected = index === this.selected; + if (top < 0 || top >= box.height) continue; + // Rows cut off by the bottom edge are not drawn, except a selected row + // taller than the box, which has nowhere better to be. + if (top + height > box.height && !selected) continue; + const rowY = box.y + top; + const item = this.itemList[index]!; + if (selected && highlight !== false) { + const row = new GrayImage(box.width, height, 0); + this.options.draw({ image: row, item, index, x: 0, y: 0, width: box.width, height, selected, focused }); + const animation = this.motion.paint(index, this.scrollY, box.x, rowY, box.width, height, Date.now()); + image.drawMenuSelection(row, box.x, rowY, focused ? MENU_HIGHLIGHT_FILL : 0, MENU_HIGHLIGHT_STROKE, + highlight?.radius ?? 8, highlight?.depth ?? 0, animation); + } else { + this.options.draw({ image, item, index, x: box.x, y: rowY, width: box.width, height, selected, focused }); + } + } + } + + /** Draw a vertical scrollbar for the last painted box (no-op unless the content overflows it). */ + drawScrollbar(image: GrayImage, x: number, y: number, height: number): void { + const box = this.lastBox; + if (!box) return; + const layout = this.layout(box.width); + if (layout.total <= box.height) return; + const maxScroll = this.maxScroll(layout, box.height); + const thumbHeight = Math.max(SCROLLBAR_MIN_THUMB, (height * box.height / layout.total) | 0); + const fraction = Math.min(1, Math.max(0, this.scrollY) / maxScroll); + image.fillRect(x, y, SCROLLBAR_WIDTH, height, SCROLLBAR_TRACK_VALUE); + image.fillRect(x, y + (((height - thumbHeight) * fraction) | 0), SCROLLBAR_WIDTH, thumbHeight, SCROLLBAR_THUMB_VALUE); + } + + private isSelectable(index: number): boolean { + return this.options.isSelectable?.(this.itemList[index]!) ?? true; + } + + /** The next selectable index after `from` in direction `delta`; from null, the first (or last) selectable. */ + private nextSelectable(from: number | null, delta: -1 | 1): number | null { + const count = this.itemList.length; + let index = from === null ? (delta > 0 ? 0 : count - 1) : from + delta; + for (; index >= 0 && index < count; index += delta) { + if (this.isSelectable(index)) return index; + } + return null; + } + + /** Clamp an index into range and onto a selectable row (nearest below, else nearest above). */ + private resolve(index: number | null): number | null { + if (index === null || !this.itemList.length) return null; + const clamped = Math.max(0, Math.min(this.itemList.length - 1, index | 0)); + if (this.isSelectable(clamped)) return clamped; + return this.nextSelectable(clamped, 1) ?? this.nextSelectable(clamped, -1); + } + + /** Re-validate the selection against the current items (they may have been edited in place). */ + private reconcile(): void { + this.selected = this.resolve(this.selected); + } + + private layout(width: number): MenuLayout { + const tops: number[] = []; + const heights: number[] = []; + let total = 0; + for (const item of this.itemList) { + const height = Math.max(0, this.options.getHeight(item, width) | 0); + tops.push(total); + heights.push(height); + total += height; + } + if (this.itemList.length) total -= this.options.rowGap ?? 0; + return { tops, heights, total }; + } + + private maxScroll(layout: MenuLayout, viewportHeight: number): number { + return Math.max(0, layout.total - viewportHeight); + } + + /** Scroll the viewport so the selected row is fully inside it, aligning the top to a row edge when it moves. */ + private ensureVisible(layout: MenuLayout, viewportHeight: number): void { + if (this.selected === null) { + this.scrollY = Math.max(0, Math.min(this.maxScroll(layout, viewportHeight), this.scrollY)); + return; + } + const top = layout.tops[this.selected]!; + const bottom = top + layout.heights[this.selected]! - (this.options.rowGap ?? 0); + let target = this.scrollY; + if (top < target) { + target = top; + } else if (bottom > target + viewportHeight) { + // A row taller than the viewport shows from its top. + target = Math.min(top, bottom - viewportHeight); + // Snap to the first row that starts inside the viewport: the selected + // row still fits (its bottom is within viewportHeight of that top). + for (let index = 0; index <= this.selected; index++) { + if (layout.tops[index]! >= target) { + target = layout.tops[index]!; + break; + } + } + } + this.scrollY = Math.max(0, target); + } + + /** With nothing selectable, up/down page the content by rows. Returns false at the end being scrolled past. */ + private scrollContent(delta: -1 | 1): boolean { + if (!this.lastBox) return false; + const layout = this.layout(this.lastBox.width); + const maxScroll = this.maxScroll(layout, this.lastBox.height); + if (delta > 0) { + if (this.scrollY >= maxScroll) return false; + const next = layout.tops.find((top) => top > this.scrollY); + this.scrollY = Math.min(maxScroll, next ?? maxScroll); + } else { + if (this.scrollY <= 0) return false; + let previous = 0; + for (const top of layout.tops) if (top < this.scrollY) previous = top; + this.scrollY = Math.max(0, previous); + } + return true; + } +} diff --git a/app/ui/menu.ts b/app/ui/menu.ts index ba108426..f3f4b8ad 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -1,9 +1,9 @@ -import { MenuHighlightMotion } from "./menu-highlight-motion"; import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage, type UiFont } from "../graphics/image"; import { wrapText } from "../graphics/textwrap"; import { getDefaultSmallFont } from "../graphics/ui-fonts"; import { clamp } from "../util/numeric-util"; import { Layer, LayerContext, PaintBelow } from "./layers"; +import { Menu, MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "./menu-core"; import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures"; import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight, menuTitleHeight } from "./metrics"; @@ -16,8 +16,10 @@ const DEFAULT_MENU_MIN_HEIGHT = G2_LENS_HEIGHT / 2 - 2 * DEFAULT_MENU_Y; const MENU_BODY_PADDING = 8; /** Gap between the last item row and a footer hint line. */ const MENU_FOOTER_GAP = 8; -const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15; -const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45; +/** Horizontal inset of the row (highlight) boxes from the menu box's edges. */ +const MENU_ROW_INSET = 12; +/** Horizontal inset of row text from the row box. */ +const MENU_ROW_TEXT_INSET = 10; export type MenuLayout = { /** Stereo depth of the menu surface, including the selected row. */ @@ -85,9 +87,9 @@ export function drawSelectionHighlight( radius = 6, ): void { if (focused) { - image.fillRoundedRect(x, y, width, height, MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL, radius); + image.fillRoundedRect(x, y, width, height, MENU_HIGHLIGHT_FILL, radius); } - image.drawRoundedRect(x, y, width, height, MENU_HIGHLIGHT_SELECTED_BORDER_STROKE, radius); + image.drawRoundedRect(x, y, width, height, MENU_HIGHLIGHT_STROKE, radius); } /** @@ -192,9 +194,9 @@ export function drawRightValueMenuItem( export const CONTEXT_MENU_DIM = 0.25; export class MenuLayer implements Layer { - private selectedIndex = 0; - private scrollRow = 0; - private readonly highlightMotion = new MenuHighlightMotion(); + private readonly menu: Menu; + /** The context of the paint in progress, handed to item render callbacks. */ + private paintCtx: LayerContext | null = null; get depth(): number { return this.layout.depth ?? 0; } @@ -211,11 +213,38 @@ export class MenuLayer implements Layer { width: DEFAULT_MENU_WIDTH, }, public readonly paintOverBase = false, - ) {} + ) { + this.menu = new Menu({ + items, + wrap: true, + rowGap: 1, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: ({ image, item, x, y, width, height, selected }) => { + const font = getDefaultSmallFont(); + const disabled = isMenuItemDisabled(item); + if (item.render) { + item.render({ + image, + x: x + MENU_ROW_TEXT_INSET, + y, + width: width - 2 * MENU_ROW_TEXT_INSET, + height: height - 2, + selected, + disabled, + text: item.label, + ctx: this.paintCtx!, + }); + } else { + image.drawText(font, x + MENU_ROW_TEXT_INSET, y + LIST_ROW_TEXT_INSET, item.label, + disabled ? 70 : selected ? 255 : 200); + } + }, + }); + } /** Start a newly opened picker on its current value. */ selectItem(index: number): this { - this.selectedIndex = clamp(index, 0, Math.max(0, this.items.length - 1)); + this.menu.select(index); return this; } @@ -242,12 +271,6 @@ export class MenuLayer implements Layer { 1, ((height - chromeTop - footerHeight - MENU_BODY_PADDING) / rowHeight) | 0, ); - this.scrollRow = scrollToKeepSelectionVisible( - this.scrollRow, - this.selectedIndex, - visibleRowCount, - this.items.length, - ); // Fill 1, not 0: identical after 4bpp quantization, but 0 is the // transparent color key when a menu paints on the shell surface. @@ -265,78 +288,32 @@ export class MenuLayer implements Layer { } const bodyY = y + chromeTop; - const focused = ctx.stack.isFocused(); - const lastVisibleRow = Math.min(this.items.length, this.scrollRow + visibleRowCount); - for (let index = this.scrollRow; index < lastVisibleRow; index++) { - const item = this.items[index]!; - const rowY = bodyY + (index - this.scrollRow) * rowHeight; - const selected = index === this.selectedIndex; - const disabled = isMenuItemDisabled(item); - const row = selected ? new GrayImage(width - 24, rowHeight - 1, 0) : image; - const textX = selected ? 10 : x + 22; - const textY = selected ? 0 : rowY; - if (item.render) { - item.render({ - image: row, - x: textX, - y: textY, - width: width - 44, - height: rowHeight - 3, - selected, - disabled, - text: item.label, - ctx, - }); - } else { - row.drawText(font, textX, textY + LIST_ROW_TEXT_INSET, item.label, disabled ? 70 : selected ? 255 : 200); - } - if (selected) { - const animation = this.highlightMotion.paint(index, this.scrollRow, x + 12, rowY, width - 24, rowHeight - 1, Date.now()); - image.drawMenuSelection(row, x + 12, rowY, focused ? MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL : 0, - MENU_HIGHLIGHT_SELECTED_BORDER_STROKE, 8, 0, animation); - } + const listHeight = visibleRowCount * rowHeight; + this.paintCtx = ctx; + try { + this.menu.paint(image, { x: x + MENU_ROW_INSET, y: bodyY, width: width - 2 * MENU_ROW_INSET, height: listHeight }, + ctx.stack.isFocused()); + } finally { + this.paintCtx = null; } - - if (this.items.length > visibleRowCount) { - drawListScrollbar( - image, - x + width - 7, - bodyY, - visibleRowCount * rowHeight - 4, - this.scrollRow, - visibleRowCount, - this.items.length, - ); - } - + this.menu.drawScrollbar(image, x + width - 7, bodyY, listHeight - 4); return image; } async handleInput(event: InputEvent, ctx: LayerContext): Promise { - if (!this.items.length) { - if (event.type === "double-click") { - ctx.stack.pop(); - } - return; - } switch (event.type) { - case "scroll-up": - this.highlightMotion.navigate(this.selectedIndex, this.selectedIndex === 0); - this.selectedIndex = (this.selectedIndex + this.items.length - 1) % this.items.length; - return; - case "scroll-down": - this.highlightMotion.navigate(this.selectedIndex, this.selectedIndex === this.items.length - 1); - this.selectedIndex = (this.selectedIndex + 1) % this.items.length; - return; case "double-click": ctx.stack.pop(); return; - case "click": - if (!isMenuItemDisabled(this.items[this.selectedIndex]!)) { - await this.items[this.selectedIndex]!.onSelect(ctx, this); + case "click": { + const item = this.menu.selectedItem; + if (item && !isMenuItemDisabled(item)) { + await item.onSelect(ctx, this); } return; + } default: + await this.menu.handleInput(event); return; } } diff --git a/tests/brightness-picker.test.cjs b/tests/brightness-picker.test.cjs index 037d45c5..4163c5ba 100644 --- a/tests/brightness-picker.test.cjs +++ b/tests/brightness-picker.test.cjs @@ -30,6 +30,9 @@ const menu = load('app/ui/menu.ts', { './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap, '../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'), + './menu-core': load('app/ui/menu-core.ts', { + '../graphics/image': graphics, './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), + }), }); function fixture(initial = '50', viewport = { x: 64, y: 124, width: 576, height: 260 }) { diff --git a/tests/menu-core.test.cjs b/tests/menu-core.test.cjs new file mode 100644 index 00000000..01b4cc24 --- /dev/null +++ b/tests/menu-core.test.cjs @@ -0,0 +1,240 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { Menu } = require('../.test-build/app/ui/menu-core.js'); +const { GrayImage } = require('../.test-build/app/graphics/image.js'); + +/** A menu of string items whose draw callback records every row it paints. */ +function stringMenu(overrides = {}) { + const drawn = []; + const exits = { top: 0, bottom: 0 }; + const selected = []; + const menu = new Menu({ + items: ['a', 'b', 'c', 'd', 'e'], + getHeight: () => 20, + draw: (args) => drawn.push({ item: args.item, x: args.x, y: args.y, width: args.width, height: args.height, + selected: args.selected, focused: args.focused, scratch: args.image !== drawn.image }), + onSelect: (item, index) => selected.push({ item, index }), + onExitTop: () => exits.top++, + onExitBottom: () => exits.bottom++, + ...overrides, + }); + const image = new GrayImage(100, 100); + drawn.image = image; + const paint = (focused = true, box = { x: 10, y: 5, width: 80, height: 60 }) => { + drawn.length = 0; + menu.paint(image, box, focused); + return drawn.slice(); + }; + return { menu, paint, drawn, exits, selected, image }; +} + +test('defaults to the first selectable item and lays rows out from the box top', () => { + const { menu, paint } = stringMenu(); + assert.equal(menu.selectedIndex, 0); + const rows = paint(); + assert.deepEqual(rows.map((r) => r.item), ['a', 'b', 'c'], 'only rows that fully fit are drawn'); + assert.deepEqual(rows.map((r) => r.y), [0, 25, 45], 'the selected row draws into a scratch image at y 0'); + assert.equal(rows[0].scratch, true); + assert.equal(rows[1].scratch, false); + assert.equal(rows[0].width, 80); + assert.equal(rows[0].height, 20); + assert.ok(rows.every((r) => r.focused)); + assert.equal(paint(false)[0].focused, false); +}); + +test('rowGap shrinks the drawable box without changing the pitch', () => { + const { paint } = stringMenu({ rowGap: 1 }); + const rows = paint(); + assert.deepEqual(rows.map((r) => r.height), [19, 19, 19]); + assert.deepEqual(rows.map((r) => r.y), [0, 25, 45]); +}); + +test('scrolling keeps the selection visible and aligns the viewport to a row top', async () => { + const { menu, paint } = stringMenu(); + await menu.handleInput({ type: 'scroll-down' }); + await menu.handleInput({ type: 'scroll-down' }); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 3); + assert.deepEqual(paint().map((r) => r.item), ['b', 'c', 'd']); + assert.equal(menu.scrollTop, 20); + await menu.handleInput({ type: 'scroll-up' }); + await menu.handleInput({ type: 'scroll-up' }); + await menu.handleInput({ type: 'scroll-up' }); + assert.equal(menu.selectedIndex, 0); + assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c']); + assert.equal(menu.scrollTop, 0); +}); + +test('without wrap the ends call the exit callbacks and hold the selection', async () => { + const { menu, exits } = stringMenu(); + await menu.handleInput({ type: 'scroll-up' }); + assert.equal(menu.selectedIndex, 0); + assert.equal(exits.top, 1); + menu.select(4); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 4); + assert.equal(exits.bottom, 1); +}); + +test('with wrap the ends connect and the exit callbacks stay quiet', async () => { + const { menu, exits } = stringMenu({ wrap: true }); + await menu.handleInput({ type: 'scroll-up' }); + assert.equal(menu.selectedIndex, 4); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 0); + assert.deepEqual(exits, { top: 0, bottom: 0 }); +}); + +test('navigation skips unselectable items and never lands on them', async () => { + const { menu } = stringMenu({ + items: ['Group', 'a', 'b', 'Group 2', 'c'], + isSelectable: (item) => !item.startsWith('Group'), + }); + assert.equal(menu.selectedIndex, 1, 'initial selection skips the leading heading'); + await menu.handleInput({ type: 'scroll-down' }); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 4, 'the heading between b and c is skipped'); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 4); + menu.select(3); + assert.equal(menu.selectedIndex, 4, 'selecting a heading lands on the next selectable item'); + menu.select(0); + assert.equal(menu.selectedIndex, 1); +}); + +test('a null selection draws no highlight, and scrolling from it picks an end', async () => { + const { menu, paint } = stringMenu({ selectedIndex: null }); + assert.equal(menu.selectedIndex, null); + assert.equal(menu.selectedItem, null); + assert.ok(paint().every((r) => !r.selected && !r.scratch)); + assert.equal(await menu.handleInput({ type: 'click' }), false); + await menu.handleInput({ type: 'scroll-up' }); + assert.equal(menu.selectedIndex, 4); + menu.select(null); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 0); +}); + +test('with nothing selectable, up and down page the content and exit at the ends', async () => { + const { menu, paint, exits } = stringMenu({ isSelectable: () => false }); + paint(); + assert.equal(menu.selectedIndex, null); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.scrollTop, 20); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.scrollTop, 40, 'clamped to the content end'); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(exits.bottom, 1); + await menu.handleInput({ type: 'scroll-up' }); + await menu.handleInput({ type: 'scroll-up' }); + assert.equal(menu.scrollTop, 0); + await menu.handleInput({ type: 'scroll-up' }); + assert.equal(exits.top, 1); +}); + +test('click activates the selected item and reports other events as unhandled', async () => { + const { menu, selected } = stringMenu(); + menu.select(2); + assert.equal(await menu.handleInput({ type: 'click' }), true); + assert.deepEqual(selected, [{ item: 'c', index: 2 }]); + assert.equal(await menu.handleInput({ type: 'double-click' }), false); +}); + +test('setItems keeps the index by default, takes an explicit one, and holds the selected row in place', () => { + const { menu, paint } = stringMenu(); + menu.select(3); + paint(); + assert.equal(menu.scrollTop, 20, 'row d sits at the bottom of the viewport'); + menu.setItems(['x', 'y', 'z', 'd2', 'e2', 'f2', 'g2']); + assert.equal(menu.selectedIndex, 3); + assert.equal(menu.scrollTop, 20); + menu.setItems(['x', 'y', 'z', 'w', 'v', 'u', 'd3'], 6); + assert.equal(menu.selectedIndex, 6); + paint(); + assert.equal(menu.scrollTop, 80, 'row d3 (top 120) stays 40 px below the viewport top'); + menu.setItems(['only'], null); + assert.equal(menu.selectedIndex, null); + menu.setItems(['p', 'q'], 9); + assert.equal(menu.selectedIndex, 1, 'an out-of-range index clamps'); +}); + +test('variable heights: the layout follows getHeight and partial rows are hidden', () => { + const heights = { a: 10, b: 30, c: 15, d: 40, e: 5 }; + const { menu, paint } = stringMenu({ getHeight: (item) => heights[item] }); + let rows = paint(); + assert.deepEqual(rows.map((r) => [r.item, r.y, r.height]), [['a', 0, 10], ['b', 15, 30], ['c', 45, 15]]); + menu.select(3); + rows = paint(); + assert.equal(menu.scrollTop, 40, 'aligned to the top of row c'); + assert.deepEqual(rows.map((r) => [r.item, r.y]), [['c', 5], ['d', 0], ['e', 60]], 'e fits under d exactly'); + assert.equal(menu.overflows, true); +}); + +test('a selected row taller than the box is drawn from its top', () => { + const { menu, paint } = stringMenu({ getHeight: (item) => (item === 'c' ? 90 : 20) }); + menu.select(2); + const rows = paint(); + assert.deepEqual(rows.map((r) => r.item), ['c']); + assert.equal(menu.scrollTop, 40); +}); + +test('the selection re-validates against items edited in place', async () => { + const items = ['a', 'b', 'c']; + const { menu } = stringMenu({ items }); + menu.select(2); + items.length = 1; + assert.equal(menu.selectedIndex, 0); + items.length = 0; + assert.equal(menu.selectedIndex, null); + items.push('z'); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 0); +}); + +test('the highlight is a replayed selection over the row scratch image', () => { + const { paint, image } = stringMenu(); + paint(); + const selection = image.draws.find((d) => d.presentation); + assert.ok(selection); + assert.equal(selection.x, 10); + assert.equal(selection.y, 5); + assert.equal(selection.presentation.radius, 8); + assert.equal(selection.presentation.background, 15); + assert.equal(selection.presentation.border, 45); + const unfocused = new GrayImage(100, 100); + stringMenu().menu.paint(unfocused, { x: 0, y: 0, width: 50, height: 50 }, false); + assert.equal(unfocused.draws.find((d) => d.presentation).presentation.background, 0); + const plain = new GrayImage(100, 100); + stringMenu({ highlight: false }).menu.paint(plain, { x: 0, y: 0, width: 50, height: 50 }, true); + assert.equal(plain.draws.some((d) => d.presentation), false); +}); + +test('indexAt maps a viewport coordinate to the selectable item under it', () => { + const { menu, paint } = stringMenu({ isSelectable: (item) => item !== 'b' }); + paint(); + assert.equal(menu.indexAt(4), null, 'above the box'); + assert.equal(menu.indexAt(5), 0); + assert.equal(menu.indexAt(30), null, 'row b is not selectable'); + assert.equal(menu.indexAt(50), 2); + assert.equal(menu.indexAt(65), null, 'below the box'); +}); + +test('the scrollbar tracks the pixel scroll fraction', () => { + const { menu, paint, image } = stringMenu(); + paint(); + image.clear(); + menu.drawScrollbar(image, 95, 5, 60); + assert.equal(image.getPixel(95, 5), 120, 'thumb at the top'); + assert.equal(image.getPixel(95, 60), 30, 'track below it'); + menu.select(4); + paint(); + image.clear(); + menu.drawScrollbar(image, 95, 5, 60); + assert.equal(image.getPixel(95, 5), 30); + assert.equal(image.getPixel(95, 64), 120, 'thumb at the bottom'); + const short = stringMenu({ items: ['a'] }); + short.paint(); + short.image.clear(); + short.menu.drawScrollbar(short.image, 95, 5, 60); + assert.equal(short.image.getPixel(95, 5), 0, 'no scrollbar when the content fits'); +}); diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs index 2709219b..fc541512 100644 --- a/tests/menu-display-list.test.cjs +++ b/tests/menu-display-list.test.cjs @@ -15,11 +15,14 @@ function load(file,modules) { } const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4, drawText:(image,x,y,text,value)=>{for(let i=0;ifont}, '../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{}, './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), - './metrics':require('../.test-build/app/ui/metrics.js'), + './metrics':require('../.test-build/app/ui/metrics.js'),'./menu-core':menuCore, }); const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}}); function menu() { diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index 248b8caf..32d693f2 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -156,6 +156,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), './metrics': load('app/ui/metrics.ts'), './gestures': {}, }; + deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]); const menu = load('app/ui/menu.ts', (name) => deps[name]); const uiDeps = { '../../graphics/image': deps['../graphics/image'], diff --git a/tests/notification-filter.test.cjs b/tests/notification-filter.test.cjs index 07d2c57b..669675bb 100644 --- a/tests/notification-filter.test.cjs +++ b/tests/notification-filter.test.cjs @@ -92,6 +92,7 @@ function ui(fontSize = 12) { assert.ok(name in dependencies, `Unexpected dependency ${name}`); return dependencies[name]; }; + dependencies['./menu-core'] = load('app/ui/menu-core.ts', requireModule); dependencies['./menu'] = load('app/ui/menu.ts', requireModule); const { SingleNotificationLayer } = load('app/ui/notifications.ts', requireModule); const { NotificationFilterLayer } = load('app/ui/notification-filter.ts', requireModule); diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 4a66e3c4..a4d6a71f 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -25,6 +25,7 @@ "../app/graphics/plane.ts", "../app/graphics/shell-scene.ts", "../app/ui/metrics.ts", + "../app/ui/menu-core.ts", "../app/phone-ui/phone-gestures.ts", "../app/g2/firmware-compat.ts", "../app/g2/glasses-hardware-identity.ts", From 71c19719925873b9b33c5f4864c5202e00ec6c0e Mon Sep 17 00:00:00 2001 From: James Babcock Date: Wed, 23 Sep 2026 23:57:50 -0700 Subject: [PATCH 19/27] Use animated menus in a bunch more places --- app/apps/developer/bandwidth-benchmark.ts | 71 ++++---- app/apps/developer/buzzer-demo.ts | 49 +++--- app/apps/evenhub/api-key-dialog.ts | 39 +++-- app/apps/evenhub/store-detail-layer.ts | 54 +++--- app/apps/evenhub/store-layer.ts | 151 +++++++++------- app/apps/files/file-browser.ts | 73 ++++---- app/apps/files/file-info-dialog.ts | 44 ++--- app/apps/glanceboard/glanceboard-app.ts | 134 +++++++------- app/apps/music/media-browse.ts | 132 ++++++-------- app/apps/music/music-app.ts | 10 +- app/apps/music/music-settings.ts | 44 +++-- app/apps/navigate/navigate-app.worker.ts | 126 ++++++-------- app/apps/teleprompter/teleprompter-app.ts | 10 +- app/apps/terminal/terminal-app.worker.ts | 153 +++++++--------- app/apps/timer/timer-app.ts | 193 +++++++++++---------- app/apps/weather/weather.ts | 83 ++++++--- app/ui/dashboard/settings-panel.ts | 189 ++++++++++---------- app/ui/font-picker.ts | 60 ++++--- app/ui/menu-core.ts | 55 ++++-- app/ui/menu-highlight-motion.ts | 2 +- app/ui/menu.ts | 25 ++- app/ui/metrics.ts | 70 +++++++- app/ui/notification-filter.ts | 44 +++-- app/ui/notifications.ts | 143 ++++++++------- app/ui/shell/assistant.ts | 93 +++------- app/ui/shell/input-dialog.ts | 76 +++++--- app/ui/shell/keyboard-input.ts | 30 ++-- app/ui/shell/voice-input.ts | 34 ++-- tests/evenhub-install-performance.test.cjs | 2 +- tests/evenhub-signin.test.cjs | 3 +- tests/ios-terminal-input.test.cjs | 5 +- tests/menu-core.test.cjs | 48 +++++ tests/menu-highlight-motion.test.cjs | 11 +- tests/navigate-worker.test.cjs | 1 + tests/row-metrics.test.cjs | 87 ++++++++++ tests/settings-panel.test.cjs | 112 ++++++++++++ tests/voice-finalization.test.cjs | 6 +- 37 files changed, 1457 insertions(+), 1005 deletions(-) create mode 100644 tests/row-metrics.test.cjs create mode 100644 tests/settings-panel.test.cjs diff --git a/app/apps/developer/bandwidth-benchmark.ts b/app/apps/developer/bandwidth-benchmark.ts index 8af80ceb..192b967e 100644 --- a/app/apps/developer/bandwidth-benchmark.ts +++ b/app/apps/developer/bandwidth-benchmark.ts @@ -2,8 +2,8 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { GrayImage } from "../../graphics/image"; import { Layer, type LayerContext } from "../../ui/layers"; import { type InputEvent } from "../../ui/gestures"; -import { drawSelectionHighlight } from "../../ui/menu"; -import { tightRowHeight } from "../../ui/metrics"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; +import { centeredTextY, tightRowHeight } from "../../ui/metrics"; import { cancelBandwidthBenchmark, getBandwidthBenchmarkStatus, @@ -29,6 +29,7 @@ const LIST_X = 20; const VALUE_X = 150; type Phase = "config" | "arming" | "running" | "done"; +type ConfigRow = "size" | "window" | "link" | "start"; /** * BLE bandwidth benchmark: pick a message size and pipeline window, stream @@ -38,7 +39,14 @@ type Phase = "config" | "arming" | "running" | "done"; */ export class BandwidthBenchmarkLayer implements Layer { private phase: Phase = "config"; - private selectedRow = 0; // size, window, link preference, start + private readonly menu = new Menu({ + items: ["size", "window", "link", "start"], + wrap: false, + rowGap: 1, + highlight: { radius: 4 }, + getHeight: () => tightRowHeight(getDefaultSmallFont()) + 4, + draw: (args) => this.drawRow(args), + }); private sizeIndex = 2; private windowIndex = 2; private linkModeIndex = 0; @@ -134,26 +142,14 @@ export class BandwidthBenchmarkLayer implements Layer { } const rowH = tightRowHeight(font) + 4; - const rows: Array<[string, string]> = [ - ["Message size", `${MESSAGE_SIZES[this.sizeIndex]} B`], - ["Window size", `${WINDOW_SIZES[this.windowIndex]}`], - ["Link request", LINK_MODES[this.linkModeIndex]!], - [this.phase === "done" ? "Run again" : "Start", ""], - ]; - for (let index = 0; index < rows.length; index++) { - const [label, value] = rows[index]!; - const y = HEADER_HEIGHT + index * rowH; - const selected = index === this.selectedRow; - if (selected) { - drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, rowH - 1, ctx.stack.isFocused(), 4); - } - image.drawText(font, LIST_X, y + 2, label, selected ? 255 : 200); - if (value) { - image.drawText(font, VALUE_X, y + 2, value, selected ? 235 : 160); - } - } + const rowCount = this.menu.items.length; + this.menu.paint( + image, + { x: LIST_X - 6, y: HEADER_HEIGHT - 1, width: width - 2 * LIST_X + 12, height: rowCount * rowH }, + ctx.stack.isFocused(), + ); - let y = HEADER_HEIGHT + rows.length * rowH + 10; + let y = HEADER_HEIGHT + rowCount * rowH + 10; if (this.error) { image.drawText(font, LIST_X, y, this.error, 180); } else if (this.result) { @@ -176,6 +172,21 @@ export class BandwidthBenchmarkLayer implements Layer { return image; } + private drawRow({ image, item, x, y, height, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const [label, value]: [string, string] = + item === "size" ? ["Message size", `${MESSAGE_SIZES[this.sizeIndex]} B`] + : item === "window" ? ["Window size", `${WINDOW_SIZES[this.windowIndex]}`] + : item === "link" ? ["Link request", LINK_MODES[this.linkModeIndex]!] + : [this.phase === "done" ? "Run again" : "Start", ""]; + const textY = centeredTextY(font, y, height); + // Text sits 6px in from the row box (LIST_X), values at VALUE_X. + image.drawText(font, x + 6, textY, label, selected ? 255 : 200); + if (value) { + image.drawText(font, x + 6 + VALUE_X - LIST_X, textY, value, selected ? 235 : 160); + } + } + async handleInput(event: InputEvent, ctx: LayerContext): Promise { if (this.phase === "arming" || this.phase === "running") { // A static screen during the run: only allow bailing out. @@ -186,22 +197,22 @@ export class BandwidthBenchmarkLayer implements Layer { } switch (event.type) { case "scroll-up": - this.selectedRow = Math.max(0, this.selectedRow - 1); - return; case "scroll-down": - this.selectedRow = Math.min(3, this.selectedRow + 1); + await this.menu.handleInput(event); return; - case "click": - if (this.selectedRow === 0) { + case "click": { + const row = this.menu.selectedItem; + if (row === "size") { this.sizeIndex = (this.sizeIndex + 1) % MESSAGE_SIZES.length; - } else if (this.selectedRow === 1) { + } else if (row === "window") { this.windowIndex = (this.windowIndex + 1) % WINDOW_SIZES.length; - } else if (this.selectedRow === 2) { + } else if (row === "link") { this.linkModeIndex = (this.linkModeIndex + 1) % LINK_MODES.length; - } else { + } else if (row === "start") { this.startRun(); } return; + } case "double-click": ctx.stack.pop(); return; diff --git a/app/apps/developer/buzzer-demo.ts b/app/apps/developer/buzzer-demo.ts index c88e18c2..1772d555 100644 --- a/app/apps/developer/buzzer-demo.ts +++ b/app/apps/developer/buzzer-demo.ts @@ -1,10 +1,9 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { GrayImage } from "../../graphics/image"; -import { clamp } from "../../util/numeric-util"; import { Layer, type LayerActions, type LayerContext } from "../../ui/layers"; import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/gestures"; -import { drawSelectionHighlight, scrollToKeepSelectionVisible } from "../../ui/menu"; -import { tightRowHeight } from "../../ui/metrics"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; +import { centeredTextY, tightRowHeight } from "../../ui/metrics"; import { buildSoundSequencePayload, CFW_SEQ_MAX, @@ -28,8 +27,14 @@ function sleep(ms: number): Promise { * sequencer message lands as the previous phrase finishes. */ export class BuzzerDemoLayer implements Layer { - private selectedIndex = 0; - private scrollRow = 0; + private readonly menu = new Menu({ + items: SOUND_EFFECTS, + wrap: false, + rowGap: 1, + highlight: { radius: 4 }, + getHeight: () => tightRowHeight(getDefaultSmallFont()), + draw: (args) => drawEffectRow(args), + }); private playing: string | null = null; paint(ctx: LayerContext): GrayImage { @@ -42,21 +47,11 @@ export class BuzzerDemoLayer implements Layer { image.drawText(font, width - 24 - font.measureText(status), 8, status, 140); const listHeight = height - HEADER_HEIGHT - FOOTER_HEIGHT; - const rowH = tightRowHeight(font); - const visibleRows = Math.max(1, (listHeight / rowH) | 0); - this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedIndex, visibleRows, SOUND_EFFECTS.length); - - const lastVisible = Math.min(SOUND_EFFECTS.length, this.scrollRow + visibleRows); - for (let index = this.scrollRow; index < lastVisible; index++) { - const effect = SOUND_EFFECTS[index]!; - const y = HEADER_HEIGHT + (index - this.scrollRow) * rowH; - const selected = index === this.selectedIndex; - if (selected) { - drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, rowH - 1, ctx.stack.isFocused(), 4); - } - image.drawText(font, LIST_X, y + 1, effect.name, selected ? 255 : 200); - image.drawText(font, LIST_X + 110, y + 1, effect.desc, selected ? 180 : 120); - } + this.menu.paint( + image, + { x: LIST_X - 6, y: HEADER_HEIGHT - 1, width: width - 2 * LIST_X + 12, height: listHeight }, + ctx.stack.isFocused(), + ); return image; } @@ -64,13 +59,11 @@ export class BuzzerDemoLayer implements Layer { async handleInput(event: InputEvent, ctx: LayerContext): Promise { switch (event.type) { case "scroll-up": - this.selectedIndex = Math.max(0, this.selectedIndex - 1); - return; case "scroll-down": - this.selectedIndex = Math.min(SOUND_EFFECTS.length - 1, this.selectedIndex + 1); + await this.menu.handleInput(event); return; case "click": { - const effect = SOUND_EFFECTS[clamp(this.selectedIndex, 0, SOUND_EFFECTS.length - 1)]; + const effect = this.menu.selectedItem; if (effect && !this.playing) { // Fire-and-forget: playback paces itself with sleeps between // phrases; awaiting it here would stall input for seconds. @@ -106,3 +99,11 @@ export class BuzzerDemoLayer implements Layer { } } } + +/** Effect name, then its description in a second column 110px to the right. */ +function drawEffectRow({ image, item: effect, x, y, height, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const textY = centeredTextY(font, y, height); + image.drawText(font, x + 6, textY, effect.name, selected ? 255 : 200); + image.drawText(font, x + 6 + 110, textY, effect.desc, selected ? 180 : 120); +} diff --git a/app/apps/evenhub/api-key-dialog.ts b/app/apps/evenhub/api-key-dialog.ts index bd41fec8..825357bf 100644 --- a/app/apps/evenhub/api-key-dialog.ts +++ b/app/apps/evenhub/api-key-dialog.ts @@ -3,8 +3,8 @@ import { GrayImage } from "../../graphics/image"; import { truncateText } from "../../graphics/textwrap"; import { type InputEvent } from "../../ui/gestures"; import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers"; -import { drawSelectionHighlight } from "../../ui/menu"; -import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; +import { lineStep, listRowHeight } from "../../ui/metrics"; const DIALOG_X = 8; const DIALOG_Y = 8; @@ -21,6 +21,8 @@ const SERVICE_LABELS: Record = { export type ApiKeyRequestItem = { id: string; configured: boolean }; +type ConsentAction = "Allow" | "Deny"; + /** * Consent dialog shown when an EvenHub app calls requestApiKeyAccess: lists the * requested API-key services (marking any the user hasn't configured) and asks @@ -28,8 +30,14 @@ export type ApiKeyRequestItem = { id: string; configured: boolean }; * double-click) shares nothing. */ export class EvenHubApiKeyDialogLayer implements Layer { - /** 0 = Allow, 1 = Deny. */ - private selectedIndex = 0; + private readonly menu = new Menu({ + items: ["Allow", "Deny"], + wrap: true, + rowGap: 1, + highlight: { radius: 8 }, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: (args) => drawActionRow(args), + }); private resolved = false; constructor( @@ -67,16 +75,11 @@ export class EvenHubApiKeyDialogLayer implements Layer { } y += 4; - const focused = ctx.stack.isFocused(); - const actions = ["Allow", "Deny"]; - for (let index = 0; index < actions.length; index++) { - const rowY = y + index * actionRowH; - const selected = index === this.selectedIndex; - if (selected) { - drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, actionRowH - 1, focused, 8); - } - image.drawText(font, DIALOG_X + 22, rowY + 3, actions[index]!, selected ? 255 : 200); - } + this.menu.paint( + image, + { x: DIALOG_X + 12, y, width: DIALOG_WIDTH - 24, height: Math.max(0, DIALOG_Y + height - PADDING - y) }, + ctx.stack.isFocused(), + ); return image; } @@ -84,10 +87,10 @@ export class EvenHubApiKeyDialogLayer implements Layer { switch (event.type) { case "scroll-up": case "scroll-down": - this.selectedIndex = (this.selectedIndex + 1) % 2; + void this.menu.handleInput(event); return; case "click": - this.resolve(ctx, this.selectedIndex === 0); + this.resolve(ctx, this.menu.selectedItem === "Allow"); return; case "double-click": this.resolve(ctx, false); @@ -113,3 +116,7 @@ export class EvenHubApiKeyDialogLayer implements Layer { else this.onCancel(); } } + +function drawActionRow({ image, item, x, y, selected }: MenuDrawArgs): void { + image.drawText(getDefaultSmallFont(), x + 10, y + 3, item, selected ? 255 : 200); +} diff --git a/app/apps/evenhub/store-detail-layer.ts b/app/apps/evenhub/store-detail-layer.ts index f3b93803..e7bd52f8 100644 --- a/app/apps/evenhub/store-detail-layer.ts +++ b/app/apps/evenhub/store-detail-layer.ts @@ -3,7 +3,7 @@ import { GrayImage } from "../../graphics/image"; import { truncateText, wrapText } from "../../graphics/textwrap"; import { type InputEvent } from "../../ui/gestures"; import { type Layer, type LayerContext } from "../../ui/layers"; -import { drawSelectionHighlight } from "../../ui/menu"; +import { Menu } from "../../ui/menu-core"; import { TextViewerLayer } from "../files/text-viewer"; import { evenHubApi, type EvenHubStoreApp } from "./even-api"; import { @@ -18,6 +18,9 @@ import { lineStep, listRowHeight } from "../../ui/metrics"; const X = 18; +type DetailAction = "about" | "whats-new" | "primary"; +const ACTIONS: readonly DetailAction[] = ["about", "whats-new", "primary"]; + export type EvenHubStoreDetailOptions = { launchApp: (appId: string) => Promise | void; appendLog: (message: string) => void; @@ -27,8 +30,22 @@ export type EvenHubStoreDetailOptions = { /** Storefront metadata and the Install/Launch action for one public app. */ export class EvenHubStoreDetailLayer implements Layer { - /** About, What's New, Install/Launch. */ - private selectedIndex = 2; + /** About, What's New, Install/Launch; starts on the primary action. */ + private readonly actions = new Menu({ + items: ACTIONS, + selectedIndex: 2, + rowGap: 1, + highlight: { radius: 8 }, + getHeight: () => listRowHeight(getDefaultSmallFont()) + 4, + draw: ({ image, item, x, y, width, selected }) => { + const font = getDefaultSmallFont(); + const label = item === "about" ? "About" : item === "whats-new" ? "What's New" : this.primaryLabel; + const value = this.working && item === "primary" ? 145 : selected ? 245 : 190; + image.drawText(font, x + 11, y + 5, truncateText(font, label, width - 18), value); + }, + }); + /** The primary action's label for the paint in progress. */ + private primaryLabel = ""; private working = false; private detailPromise: Promise | null = null; private status = ""; @@ -47,7 +64,7 @@ export class EvenHubStoreDetailLayer implements Layer { const actionRowH = listRowHeight(font) + 4; const installed = getInstalledEvenHubApp(this.app.packageId); - const actions = ["About", "What's New", this.working ? "Installing..." : this.primaryActionLabel(installed)]; + this.primaryLabel = this.working ? "Installing..." : this.primaryActionLabel(installed); // Detail lines as (text, shade, extra gap below); built per candidate // width so the layout choice below can measure before drawing. @@ -90,7 +107,7 @@ export class EvenHubStoreDetailLayer implements Layer { // Stacked layout (details full-width, actions at the bottom) when it // fits; otherwise the actions become a narrow top-right menu and the // details flow down a left column beside it. - const stackedActionTop = height - 6 - actions.length * actionRowH; + const stackedActionTop = height - 6 - ACTIONS.length * actionRowH; const stacked = 8 + linesHeight(buildLines(width - X * 2)) + 6 <= stackedActionTop; const menuW = 150; const menuX = width - menuW - 12; @@ -105,15 +122,11 @@ export class EvenHubStoreDetailLayer implements Layer { const actionX = stacked ? X : menuX; const actionW = stacked ? textWidth : menuW; const actionTop = stacked ? stackedActionTop : 8; - for (let index = 0; index < actions.length; index++) { - const actionY = actionTop + index * actionRowH; - const selected = index === this.selectedIndex; - if (selected) { - drawSelectionHighlight(image, actionX - 5, actionY, actionW + 10, actionRowH - 1, ctx.stack.isFocused(), 8); - } - const value = this.working && index === 2 ? 145 : selected ? 245 : 190; - image.drawText(font, actionX + 6, actionY + 5, truncateText(font, actions[index]!, actionW - 8), value); - } + this.actions.paint( + image, + { x: actionX - 5, y: actionTop, width: actionW + 10, height: ACTIONS.length * actionRowH - 1 }, + ctx.stack.isFocused(), + ); return image; } @@ -123,12 +136,8 @@ export class EvenHubStoreDetailLayer implements Layer { return; } if (this.working) return; - if (event.type === "scroll-up") { - this.selectedIndex = Math.max(0, this.selectedIndex - 1); - return; - } - if (event.type === "scroll-down") { - this.selectedIndex = Math.min(2, this.selectedIndex + 1); + if (event.type === "scroll-up" || event.type === "scroll-down") { + await this.actions.handleInput(event); return; } if (event.type !== "click") return; @@ -143,11 +152,12 @@ export class EvenHubStoreDetailLayer implements Layer { try { await this.ensureDetail(ctx); - if (this.selectedIndex === 0) { + const action = this.actions.selectedItem; + if (action === "about") { ctx.stack.push(new TextViewerLayer(this.app.description || "No description supplied.", "About")); return; } - if (this.selectedIndex === 1) { + if (action === "whats-new") { ctx.stack.push(new TextViewerLayer(this.app.changelog || "No release notes supplied.", "What's New")); return; } diff --git a/app/apps/evenhub/store-layer.ts b/app/apps/evenhub/store-layer.ts index a19a8c15..765593a0 100644 --- a/app/apps/evenhub/store-layer.ts +++ b/app/apps/evenhub/store-layer.ts @@ -1,10 +1,10 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { GrayImage, type UiFont } from "../../graphics/image"; import { truncateText, wrapText } from "../../graphics/textwrap"; -import { clamp } from "../../util/numeric-util"; import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures"; import { type Layer, type LayerActions, type LayerContext, type LayerStack } from "../../ui/layers"; -import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu"; +import { drawSelectionHighlight, type MenuItem } from "../../ui/menu"; +import { Menu } from "../../ui/menu-core"; import { shell } from "../../ui/shell/shell"; import { ConfigSettingString } from "../../ui/dashboard-settings"; import { evenHubApi, EvenHubAuthenticationError, isEvenHubStoreConfigured, type EvenHubStoreApp, type EvenHubStorePage } from "./even-api"; @@ -24,6 +24,11 @@ function headerHeight(font: UiFont): number { return 8 + lineStep(font) + font.lineHeight + 6; } +/** Row pitch of the two-line app list (title + detail), including the 2px gap between highlights. */ +function storeRowHeight(font: UiFont): number { + return Math.max(30, 2 * lineStep(font) + 4); +} + /** Last search typed on the phone; kept so reopening the store shows it again. */ export const evenHubSearchQuerySetting = new ConfigSettingString({ id: "evenhub-search-query", @@ -64,27 +69,46 @@ type TabState = { loading: boolean; /** Progress or error text for the subtitle line. */ status: string; - selectedIndex: number; - scrollRow: number; + /** Selection and scroll over `rows` (resynced before each paint and input). */ + menu: Menu; /** Search only: the query the rows belong to. */ query: string; }; function emptyTab(): TabState { + const rows: StoreRow[] = []; return { - rows: [], + rows, total: 0, nextPage: 1, exhausted: false, loaded: false, loading: false, status: "", - selectedIndex: 0, - scrollRow: 0, + menu: new Menu({ + items: rows, + rowGap: 2, + highlight: { radius: 5 }, + getHeight: () => storeRowHeight(getDefaultSmallFont()), + draw: ({ image, item, x, y, width }) => { + const font = getDefaultSmallFont(); + const { title, detail, titleValue } = rowText(item); + const textX = x + 6; + const textW = width - 12; + image.drawText(font, textX, y + 2, truncateText(font, title, textW), titleValue); + image.drawText(font, textX, y + 2 + lineStep(font), truncateText(font, detail, textW), 115); + }, + }), query: "", }; } +/** The tab's menu, with its items brought up to date with `rows` (which loads replace or extend). */ +function tabMenu(tab: TabState): Menu { + if (tab.menu.items !== tab.rows) tab.menu.setItems(tab.rows); + return tab.menu; +} + export type EvenHubStoreLayerOptions = { launchApp: (appId: string) => Promise | void; appendLog: (message: string) => void; @@ -170,25 +194,16 @@ export class EvenHubStoreLayer implements Layer { return image; } - tab.selectedIndex = clamp(tab.selectedIndex, 0, tab.rows.length - 1); - const rowH = Math.max(30, 2 * lineStep(font) + 4); + const rowH = storeRowHeight(font); const visibleRows = Math.max(1, Math.floor((height - headerH - 4) / rowH)); - tab.scrollRow = scrollToKeepSelectionVisible(tab.scrollRow, tab.selectedIndex, visibleRows, tab.rows.length); - const last = Math.min(tab.rows.length, tab.scrollRow + visibleRows); const listFocused = ctx.stack.isFocused() && this.focus === "list"; - for (let index = tab.scrollRow; index < last; index++) { - const row = tab.rows[index]!; - const y = headerH + (index - tab.scrollRow) * rowH; - if (index === tab.selectedIndex) { - drawSelectionHighlight(image, LIST_X - 6, y, width - LIST_X * 2 + 12, rowH - 2, listFocused, 5); - } - const { title, detail, titleValue } = this.rowText(row); - image.drawText(font, LIST_X, y + 2, truncateText(font, title, width - LIST_X * 2), titleValue); - image.drawText(font, LIST_X, y + 2 + lineStep(font), truncateText(font, detail, width - LIST_X * 2), 115); - } - if (tab.rows.length > visibleRows) { - drawListScrollbar(image, width - 5, headerH, visibleRows * rowH - 3, tab.scrollRow, visibleRows, tab.rows.length); - } + const menu = tabMenu(tab); + menu.paint( + image, + { x: LIST_X - 6, y: headerH, width: width - LIST_X * 2 + 12, height: visibleRows * rowH - 2 }, + listFocused, + ); + menu.drawScrollbar(image, width - 5, headerH, visibleRows * rowH - 3); return image; } @@ -250,41 +265,6 @@ export class EvenHubStoreLayer implements Layer { } } - private rowText(row: StoreRow): { title: string; detail: string; titleValue: number } { - switch (row.kind) { - case "search-query": { - const query = evenHubSearchQuerySetting.get(); - return { - title: query ? `Search: ${query}` : "Search: (enter a query)", - detail: "Click to type on the phone, or use voice input.", - titleValue: 200, - }; - } - case "orphan": - return { - title: row.update.installed.name, - detail: row.update.error - ? `Package missing · store lookup failed: ${row.update.error}` - : "Package missing · not in the store · click to forget", - titleValue: 170, - }; - case "app": { - const { app, update } = row; - if (!update) { - return { - title: app.name, - detail: app.tagline || `${app.creatorName} · ${formatCount(app.installCount)} installs`, - titleValue: 215, - }; - } - const detail = update.packageMissing - ? `Package missing · reinstall ${app.version ? `version ${app.version}` : ""}`.trim() - : `Version ${update.installed.version} installed · ${app.version} available`; - return { title: app.name, detail, titleValue: 215 }; - } - } - } - async handleInput(event: InputEvent, ctx: LayerContext): Promise { if (this.showingLogin) { if (event.type === "click" && !this.loginBusy) { @@ -299,16 +279,17 @@ export class EvenHubStoreLayer implements Layer { return; } const tab = this.tabs[this.activeTab]; + const menu = tabMenu(tab); switch (event.type) { case "scroll-up": - tab.selectedIndex = Math.max(0, tab.selectedIndex - 1); + await menu.handleInput(event); return; case "scroll-down": - tab.selectedIndex = Math.min(Math.max(0, tab.rows.length - 1), tab.selectedIndex + 1); - if (tab.selectedIndex >= tab.rows.length - 4) void this.loadNextPage(ctx, this.activeTab); + await menu.handleInput(event); + if ((menu.selectedIndex ?? 0) >= tab.rows.length - 4) void this.loadNextPage(ctx, this.activeTab); return; case "click": - await this.activateRow(ctx, tab.rows[tab.selectedIndex]); + await this.activateRow(ctx, menu.selectedItem ?? undefined); return; case "double-click": this.focus = "tabs"; @@ -540,7 +521,7 @@ export class EvenHubStoreLayer implements Layer { state.rows = [{ kind: "search-query" }]; state.loaded = !query; // Keep the cursor on the first result once there are some. - state.selectedIndex = query ? 1 : 0; + state.menu.setItems(state.rows, query ? 1 : 0); this.tabs.search = state; ctx.actions.requestRender(); if (query) await this.loadNextPage(ctx, "search"); @@ -566,8 +547,8 @@ export class EvenHubStoreLayer implements Layer { update.latest ? { kind: "app", app: update.latest, update } : { kind: "orphan", update }, ); state.rows = rows; - state.selectedIndex = 0; - state.scrollRow = 0; + state.menu.setItems(rows, 0); + state.menu.scrollTop = 0; state.status = ""; state.exhausted = true; } catch (error) { @@ -643,7 +624,7 @@ export class EvenHubStoreLayer implements Layer { state.rows = state.rows.filter((row) => row.kind === "search-query" ? true : row.kind === "app" ? row.app.packageId !== packageId : row.update.installed.packageId !== packageId, ); - state.selectedIndex = clamp(state.selectedIndex, 0, Math.max(0, state.rows.length - 1)); + state.menu.setItems(state.rows); } // ---- login and phone editors -------------------------------------------- @@ -755,6 +736,42 @@ export class EvenHubStoreLayer implements Layer { } } +/** A list row's title (with its shade) and dim detail line. */ +function rowText(row: StoreRow): { title: string; detail: string; titleValue: number } { + switch (row.kind) { + case "search-query": { + const query = evenHubSearchQuerySetting.get(); + return { + title: query ? `Search: ${query}` : "Search: (enter a query)", + detail: "Click to type on the phone, or use voice input.", + titleValue: 200, + }; + } + case "orphan": + return { + title: row.update.installed.name, + detail: row.update.error + ? `Package missing · store lookup failed: ${row.update.error}` + : "Package missing · not in the store · click to forget", + titleValue: 170, + }; + case "app": { + const { app, update } = row; + if (!update) { + return { + title: app.name, + detail: app.tagline || `${app.creatorName} · ${formatCount(app.installCount)} installs`, + titleValue: 215, + }; + } + const detail = update.packageMissing + ? `Package missing · reinstall ${app.version ? `version ${app.version}` : ""}`.trim() + : `Version ${update.installed.version} installed · ${app.version} available`; + return { title: app.name, detail, titleValue: 215 }; + } + } +} + /** A registry entry dressed as a store record, for pages opened before the store record arrives. */ function placeholderStoreApp(installed: InstalledEvenHubApp): EvenHubStoreApp { return { diff --git a/app/apps/files/file-browser.ts b/app/apps/files/file-browser.ts index eac9645e..2227b4cc 100644 --- a/app/apps/files/file-browser.ts +++ b/app/apps/files/file-browser.ts @@ -4,7 +4,8 @@ import { GrayImage, type UiFont } from "../../graphics/image"; import { renderIcon, type IconName } from "../../graphics/icons"; import { clamp } from "../../util/numeric-util"; import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu"; -import { iconGridMinRowHeight, tightRowHeight } from "../../ui/metrics"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; +import { centeredTextY, iconGridMinRowHeight, tightRowHeight } from "../../ui/metrics"; import { ConfigSettingEnum } from "../../ui/dashboard-settings"; import { getStringSetting, setStringSetting } from "../../native/settings-store"; import { @@ -20,6 +21,8 @@ import { Layer, type LayerContext } from "../../ui/layers"; import { shell } from "../../ui/shell/shell"; const LIST_X = 20; +/** List view: the selection box extends this far left and right of the row text. */ +const LIST_HIGHLIGHT_PAD = 6; /** Header: one line holding both the title and the current path. */ function headerHeight(font: UiFont): number { @@ -133,7 +136,14 @@ export class FileBrowserLayer implements Layer { private entries: DirectoryEntry[] | null = null; private listingFailed = false; - private listIndex = 0; + /** List view. Its selected index is the flat-row index both views translate through (setViewMode). */ + private readonly listMenu = new Menu({ + wrap: false, + rowGap: 1, + highlight: { radius: 4 }, + getHeight: () => tightRowHeight(getDefaultSmallFont()), + draw: (args) => this.drawListRow(args), + }); private selectedRow = 0; private selectedCol = 0; private iconMode: IconMode = "row"; @@ -162,25 +172,20 @@ export class FileBrowserLayer implements Layer { private paintList(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void { const { width, height } = ctx.stack.getBaseSize(); - this.listIndex = clamp(this.listIndex, 0, Math.max(0, rows.length - 1)); - - const rowH = tightRowHeight(font); const headerH = headerHeight(font); - const listHeight = height - headerH - 4; - const visibleRows = Math.max(1, (listHeight / rowH) | 0); - this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.listIndex, visibleRows, rows.length); + this.listMenu.setItems(rows); + // Row boxes start one pixel above the header's bottom edge. + this.listMenu.paint( + image, + { x: LIST_X - LIST_HIGHLIGHT_PAD, y: headerH - 1, width: width - 2 * LIST_X + 2 * LIST_HIGHLIGHT_PAD, height: height - headerH - 4 }, + ctx.stack.isFocused(), + ); + } - const lastVisible = Math.min(rows.length, this.scrollRow + visibleRows); - for (let index = this.scrollRow; index < lastVisible; index++) { - const row = rows[index]!; - const y = headerH + (index - this.scrollRow) * rowH; - const selected = index === this.listIndex; - if (selected) { - drawSelectionHighlight(image, LIST_X - 6, y - 1, width - 2 * LIST_X + 12, rowH - 1, ctx.stack.isFocused(), 4); - } - const value = itemValue(row, selected); - image.drawText(font, LIST_X, y + 1, truncateText(font, row.label, width - 2 * LIST_X), value); - } + private drawListRow({ image, item, x, y, width, height, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const label = truncateText(font, item.label, width - 2 * LIST_HIGHLIGHT_PAD); + image.drawText(font, x + LIST_HIGHLIGHT_PAD, centeredTextY(font, y, height), label, itemValue(item, selected)); } private paintIcons(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void { @@ -276,16 +281,14 @@ export class FileBrowserLayer implements Layer { } private async handleListInput(event: InputEvent, ctx: LayerContext): Promise { - const rows = this.flatRows(); + this.listMenu.setItems(this.flatRows()); switch (event.type) { case "scroll-up": - this.listIndex = Math.max(0, this.listIndex - 1); - return; case "scroll-down": - this.listIndex = Math.min(Math.max(0, rows.length - 1), this.listIndex + 1); + await this.listMenu.handleInput(event); return; case "click": { - const row = rows[clamp(this.listIndex, 0, Math.max(0, rows.length - 1))]; + const row = this.listMenu.selectedItem; if (row) await this.activateItem(row, ctx); return; } @@ -461,8 +464,7 @@ export class FileBrowserLayer implements Layer { label: isBookmarked(path) ? `Remove bookmark: ${name}` : `Bookmark: ${name}`, onSelect: (ctx) => { toggleBookmark(path); - const rows = this.flatRows(); - this.listIndex = clamp(this.listIndex, 0, Math.max(0, rows.length - 1)); + this.listMenu.setItems(this.flatRows()); ctx.stack.pop(); }, }); @@ -475,7 +477,8 @@ export class FileBrowserLayer implements Layer { const rows = this.flatRows(); if (!rows.length) return null; if (filesViewModeSetting.get() === "list") { - return rows[clamp(this.listIndex, 0, rows.length - 1)] ?? null; + this.listMenu.setItems(rows); + return this.listMenu.selectedItem; } const iconRows = buildIconRows(rows); const row = iconRows[clamp(this.selectedRow, 0, iconRows.length - 1)]; @@ -489,20 +492,23 @@ export class FileBrowserLayer implements Layer { if (filesViewModeSetting.get() === mode) return; const rows = this.flatRows(); const iconRows = buildIconRows(rows); + this.listMenu.setItems(rows); if (mode === "list") { // Carry the icon-grid selection into the flat list (clamped column when // only a row was selected). const row = iconRows[clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1))]; if (row) { - this.listIndex = - row.kind === "special" ? row.flatIndex : row.firstIndex + clamp(this.selectedCol, 0, row.items.length - 1); + this.listMenu.select( + row.kind === "special" ? row.flatIndex : row.firstIndex + clamp(this.selectedCol, 0, row.items.length - 1), + ); } } else { - this.setGridSelectionFromFlatIndex(rows, clamp(this.listIndex, 0, Math.max(0, rows.length - 1))); + this.setGridSelectionFromFlatIndex(rows, this.listMenu.selectedIndex ?? 0); this.iconMode = "row"; } filesViewModeSetting.set(mode); this.scrollRow = 0; + this.listMenu.scrollTop = 0; } private async activateItem(item: BrowserItem, ctx: LayerContext): Promise { @@ -548,7 +554,8 @@ export class FileBrowserLayer implements Layer { } private resetSelection(): void { - this.listIndex = 0; + this.listMenu.select(0); + this.listMenu.scrollTop = 0; this.selectedRow = 0; this.selectedCol = 0; this.iconMode = "row"; @@ -560,7 +567,9 @@ export class FileBrowserLayer implements Layer { const rows = this.flatRows(); const index = rows.findIndex((row) => row.kind === "entry" && row.entry.path === path); if (index < 0) return; - this.listIndex = index; + // Items first, then the selection, so the viewport scrolls minimally from the top. + this.listMenu.setItems(rows); + this.listMenu.select(index); this.setGridSelectionFromFlatIndex(rows, index); } diff --git a/app/apps/files/file-info-dialog.ts b/app/apps/files/file-info-dialog.ts index ff44fec2..5a35528b 100644 --- a/app/apps/files/file-info-dialog.ts +++ b/app/apps/files/file-info-dialog.ts @@ -4,7 +4,7 @@ import { wrapText } from "../../graphics/textwrap"; import type { DirectoryEntry } from "../../native/file-access"; import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures"; import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers"; -import { drawSelectionHighlight } from "../../ui/menu"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics"; const DIALOG_X = 8; @@ -25,12 +25,21 @@ export type FileInfoAction = { * double-click closes it. */ export class FileInfoDialogLayer implements Layer { - private selectedIndex = 0; + private readonly menu: Menu; constructor( private readonly entry: DirectoryEntry, private readonly actions: FileInfoAction[], - ) {} + ) { + this.menu = new Menu({ + items: actions, + wrap: true, + rowGap: 1, + highlight: { radius: 8 }, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: (args) => drawActionRow(args), + }); + } paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { const font = getDefaultSmallFont(); @@ -69,32 +78,23 @@ export class FileInfoDialogLayer implements Layer { image.drawText(font, DIALOG_X + PADDING + 2, y + 3, `${GESTURE_DOUBLE_CLICK} close`, 110); return image; } - const focused = ctx.stack.isFocused(); - for (let index = 0; index < this.actions.length; index++) { - const rowY = y + index * rowH; - const selected = index === this.selectedIndex; - if (selected) { - drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, rowH - 1, focused, 8); - } - image.drawText(font, DIALOG_X + 22, rowY + LIST_ROW_TEXT_INSET, this.actions[index]!.label, selected ? 255 : 200); - } + // The rows fill the rest of the dialog (and scroll if a clamped dialog is too short). + this.menu.paint( + image, + { x: DIALOG_X + 12, y, width: DIALOG_WIDTH - 24, height: Math.max(0, DIALOG_Y + height - PADDING - y) }, + ctx.stack.isFocused(), + ); return image; } async handleInput(event: InputEvent, ctx: LayerContext): Promise { switch (event.type) { case "scroll-up": - if (this.actions.length) { - this.selectedIndex = (this.selectedIndex + this.actions.length - 1) % this.actions.length; - } - return; case "scroll-down": - if (this.actions.length) { - this.selectedIndex = (this.selectedIndex + 1) % this.actions.length; - } + await this.menu.handleInput(event); return; case "click": - await this.actions[this.selectedIndex]?.onSelect(ctx); + await this.menu.selectedItem?.onSelect(ctx); return; case "double-click": ctx.stack.pop(); @@ -105,6 +105,10 @@ export class FileInfoDialogLayer implements Layer { } } +function drawActionRow({ image, item, x, y, selected }: MenuDrawArgs): void { + image.drawText(getDefaultSmallFont(), x + 10, y + LIST_ROW_TEXT_INSET, item.label, selected ? 255 : 200); +} + function formatSize(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; diff --git a/app/apps/glanceboard/glanceboard-app.ts b/app/apps/glanceboard/glanceboard-app.ts index a0e2b236..dd10e848 100644 --- a/app/apps/glanceboard/glanceboard-app.ts +++ b/app/apps/glanceboard/glanceboard-app.ts @@ -3,9 +3,10 @@ import { truncateText, wrapText } from "../../graphics/textwrap"; import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { enumSettingMenuItem, onAnySettingChanged, toggleSettingMenuItem } from "../../ui/dashboard-settings"; import { type InputEvent } from "../../ui/gestures"; -import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers"; -import { drawSelectionHighlight, MenuLayer, openModalMenu, type MenuItem } from "../../ui/menu"; -import { LIST_ROW_TEXT_INSET, lineStep } from "../../ui/metrics"; +import { type Layer, type LayerContext } from "../../ui/layers"; +import { drawSelectionHighlight, isMenuItemDisabled, MenuLayer, openModalMenu, type MenuItem } from "../../ui/menu"; +import { Menu } from "../../ui/menu-core"; +import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics"; import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window"; import { shell } from "../../ui/shell/shell"; import { GlanceBoard } from "./board"; @@ -35,6 +36,15 @@ const PARAGRAPH_X = 24; const PREVIEW_MARGIN = 8; const PREVIEW_MIN_LINE_VALUE = 20; const PREVIEW_LINE_VALUE = 100; +/** The entry menu's row boxes: left inset, gap below the paragraph, and inset from the page's bottom. */ +const HOME_MENU_X = 20; +const HOME_MENU_TOP_GAP = 12; +const HOME_MENU_BOTTOM_MARGIN = 8; +/** Horizontal inset of row text (and custom row content) from its selection box. */ +const HOME_ROW_TEXT_X = 10; +// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the +// entry page's items never use it (they act via ctx only). +const NO_MENU = new MenuLayer(null, []); const INTRO = "Your Glanceboard is a display for things you want to look at quickly. Starting " + @@ -55,25 +65,21 @@ function pageMenuLayout(width: number) { * a double-tap returns focus to the menu. */ class GlanceboardHomeLayer implements Layer { - private menu: MenuLayer | null = null; - private menuTop = 0; - private menuHeight = 0; + private readonly menu: Menu; private focus: "menu" | "preview" = "menu"; private selectedSlot = 0; + /** The context of the paint in progress, handed to item render callbacks. */ + private paintCtx: LayerContext | null = null; - constructor(private readonly setPreviewVisible: (visible: boolean) => void) {} - - private currentMenu(ctx: LayerContext, menuTop: number): MenuLayer { - const { width, height } = ctx.stack.getBaseSize(); - if (!this.menu || this.menuTop !== menuTop || this.menuHeight !== height) { - const half = (width / 2) | 0; - const items: MenuItem[] = [ + constructor(private readonly setPreviewVisible: (visible: boolean) => void) { + this.menu = new Menu({ + items: [ toggleSettingMenuItem(glanceboardEnabledSetting), { label: "Preview", - onSelect: (menuCtx) => { - menuCtx.stack.push(new GlancePreviewLayer( - () => menuCtx.actions.requestRender(), + onSelect: (ctx) => { + ctx.stack.push(new GlancePreviewLayer( + () => ctx.actions.requestRender(), () => this.setPreviewVisible(false), )); this.setPreviewVisible(true); @@ -87,17 +93,32 @@ class GlanceboardHomeLayer implements Layer { }, { label: "Settings", - onSelect: (menuCtx) => menuCtx.stack.push(new GlanceSettingsLayer()), + onSelect: openGlanceSettings, }, - ]; - this.menuTop = menuTop; - this.menuHeight = height; - this.menu = new MenuLayer(null, items, { - x: 8, y: menuTop, width: half - 16, - showBorder: false, minHeight: 0, maxHeight: height - menuTop, - }); - } - return this.menu; + ], + wrap: true, + rowGap: 1, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: ({ image, item, x, y, width, height, selected }) => { + const disabled = isMenuItemDisabled(item); + if (item.render) { + item.render({ + image, + x: x + HOME_ROW_TEXT_X, + y, + width: width - 2 * HOME_ROW_TEXT_X, + height: height - 2, + selected, + disabled, + text: item.label, + ctx: this.paintCtx!, + }); + } else { + image.drawText(getDefaultSmallFont(), x + HOME_ROW_TEXT_X, y + LIST_ROW_TEXT_INSET, item.label, + disabled ? 70 : selected ? 255 : 200); + } + }, + }); } /** Where the scaled board sits: the right half, board aspect, vertically centred. */ @@ -128,13 +149,19 @@ class GlanceboardHomeLayer implements Layer { image.drawText(font, PARAGRAPH_X, y, line, 160); y += step; } - // The menu paints onto this page below the paragraph (its fill is raster, - // so the deferred paragraph glyphs above stay untouched either way). - // While the preview has focus the menu keeps its outline-only selection. - const menu = this.currentMenu(ctx, y + 4); - const menuFocused = ctx.stack.isFocused() && this.focus === "menu"; - const menuCtx: LayerContext = { ...ctx, stack: Object.assign(Object.create(ctx.stack), { isFocused: () => menuFocused }) }; - menu.paint(menuCtx, () => image); + // The menu sits below the paragraph in the left half. While the preview + // has focus the menu keeps its outline-only selection. + const menuTop = y + HOME_MENU_TOP_GAP; + const menuWidth = half - 2 * HOME_MENU_X; + const menuHeight = Math.max(0, height - menuTop - HOME_MENU_BOTTOM_MARGIN); + this.paintCtx = ctx; + try { + this.menu.paint(image, { x: HOME_MENU_X, y: menuTop, width: menuWidth, height: menuHeight }, + ctx.stack.isFocused() && this.focus === "menu"); + } finally { + this.paintCtx = null; + } + this.menu.drawScrollbar(image, HOME_MENU_X + menuWidth + 5, menuTop, menuHeight - 4); this.selectedSlot = Math.min(this.selectedSlot, glanceLayout().slots.length - 1); const preview = this.previewRect(width, height); @@ -173,7 +200,12 @@ class GlanceboardHomeLayer implements Layer { shell.yieldFocusToSidebar(); return; } - await this.currentMenu(ctx, this.menuTop).handleInput(event, ctx); + if (event.type === "click") { + const item = this.menu.selectedItem; + if (item && !isMenuItemDisabled(item)) await item.onSelect(ctx, NO_MENU); + return; + } + await this.menu.handleInput(event); } } @@ -266,31 +298,15 @@ function openSlotPicker(ctx: LayerContext, slotIndex: number): void { } /** Settings: layout, sleep gestures, duration, and slot lines. */ -class GlanceSettingsLayer implements Layer { - private menu: MenuLayer | null = null; - - private currentMenu(ctx: LayerContext): MenuLayer { - if (!this.menu) { - const { width } = ctx.stack.getBaseSize(); - const items: MenuItem[] = [ - enumSettingMenuItem(glanceLayoutSetting), - enumSettingMenuItem(glanceTapDurationSetting), - toggleSettingMenuItem(glanceShowOnLongPressSetting), - toggleSettingMenuItem(glanceShowOnHeadTiltSetting), - toggleSettingMenuItem(glanceShowLinesSetting), - ]; - this.menu = new MenuLayer("Glanceboard settings", items, pageMenuLayout(width)); - } - return this.menu; - } - - paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { - return this.currentMenu(ctx).paint(ctx, paintBelow); - } - - async handleInput(event: InputEvent, ctx: LayerContext): Promise { - await this.currentMenu(ctx).handleInput(event, ctx); - } +function openGlanceSettings(ctx: LayerContext): void { + const items: MenuItem[] = [ + enumSettingMenuItem(glanceLayoutSetting), + enumSettingMenuItem(glanceTapDurationSetting), + toggleSettingMenuItem(glanceShowOnLongPressSetting), + toggleSettingMenuItem(glanceShowOnHeadTiltSetting), + toggleSettingMenuItem(glanceShowLinesSetting), + ]; + ctx.stack.push(new MenuLayer("Glanceboard settings", items, pageMenuLayout(ctx.stack.getBaseSize().width))); } /** The live board in the window; any click or double-click returns to the list. */ diff --git a/app/apps/music/media-browse.ts b/app/apps/music/media-browse.ts index 51e50d9a..3876c67e 100644 --- a/app/apps/music/media-browse.ts +++ b/app/apps/music/media-browse.ts @@ -1,15 +1,9 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { GrayImage, type UiFont } from "../../graphics/image"; -import { clamp } from "../../util/numeric-util"; import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL, type InputEvent } from "../../ui/gestures"; -import { - MenuLayer, - drawListScrollbar, - drawSelectionHighlight, - drawSubmenuIndicator, - scrollToKeepSelectionVisible, -} from "../../ui/menu"; -import { lineStep, tightRowHeight } from "../../ui/metrics"; +import { MenuLayer, drawSubmenuIndicator } from "../../ui/menu"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; +import { centeredTextY, lineStep, tightRowHeight } from "../../ui/metrics"; import { mediaBrowserBridge, type MediaBrowseItem, @@ -22,6 +16,8 @@ function headerHeight(font: UiFont): number { return 8 + lineStep(font) + font.lineHeight; } const LIST_X = 20; +/** The selection box extends this far left and right of the row text. */ +const LIST_HIGHLIGHT_PAD = 6; export type MediaBrowseOptions = { app: MediaBrowserApp; @@ -37,8 +33,8 @@ type BrowseLevel = { /** null while the listing is loading. */ items: MediaBrowseItem[] | null; error: string; - selectedIndex: number; - scrollRow: number; + /** Holds the loaded items; keeps this level's selection and scroll while a child level is open. */ + menu: Menu; }; type BrowsePhase = "idle" | "connecting" | "ready" | "failed"; @@ -97,50 +93,16 @@ export class MediaBrowseLayer implements Layer { return image; } - level.selectedIndex = clamp(level.selectedIndex, 0, items.length - 1); - const listHeight = height - headerHeight(font) - font.lineHeight - 10; - const rowH = tightRowHeight(font); - const visibleRows = Math.max(1, (listHeight / rowH) | 0); - level.scrollRow = scrollToKeepSelectionVisible(level.scrollRow, level.selectedIndex, visibleRows, items.length); - - const rowWidth = width - 2 * LIST_X; - const lastVisible = Math.min(items.length, level.scrollRow + visibleRows); - for (let index = level.scrollRow; index < lastVisible; index++) { - const item = items[index]!; - const y = headerHeight(font) + (index - level.scrollRow) * rowH; - const selected = index === level.selectedIndex; - const highlightX = LIST_X - 6; - const highlightY = y - 1; - const highlightWidth = rowWidth + 12; - const highlightHeight = rowH - 1; - if (selected) { - drawSelectionHighlight(image, highlightX, highlightY, highlightWidth, highlightHeight, ctx.stack.isFocused(), 4); - } - const value = selected ? 255 : 200; - const title = truncateRight(font, item.title || "(untitled)", rowWidth - 16); - image.drawText(font, LIST_X, y + 1, title, value); - if (item.subtitle) { - const titleWidth = font.measureText(title); - const subtitleWidth = font.measureText(item.subtitle); - if (titleWidth + subtitleWidth + 24 <= rowWidth - 16) { - image.drawText(font, LIST_X + rowWidth - 16 - subtitleWidth, y + 1, item.subtitle, 110); - } - } - if (item.browsable) { - drawSubmenuIndicator(image, font, highlightX, highlightY, highlightWidth, highlightHeight, selected ? value : 110); - } - } - if (items.length > visibleRows) { - drawListScrollbar( - image, - width - 12, - headerHeight(font), - visibleRows * rowH - 4, - level.scrollRow, - visibleRows, - items.length, - ); - } + const listTop = headerHeight(font); + const listHeight = height - listTop - font.lineHeight - 10; + const visibleRows = Math.max(1, (listHeight / tightRowHeight(font)) | 0); + // Row boxes start one pixel above the header's bottom edge. + level.menu.paint( + image, + { x: LIST_X - LIST_HIGHLIGHT_PAD, y: listTop - 1, width: width - 2 * LIST_X + 2 * LIST_HIGHLIGHT_PAD, height: listHeight }, + ctx.stack.isFocused(), + ); + level.menu.drawScrollbar(image, width - 12, listTop, visibleRows * tightRowHeight(font) - 4); image.drawText( font, @@ -175,13 +137,11 @@ export class MediaBrowseLayer implements Layer { if (!level || !items || !items.length) return; switch (event.type) { case "scroll-up": - level.selectedIndex = Math.max(0, level.selectedIndex - 1); - return; case "scroll-down": - level.selectedIndex = Math.min(items.length - 1, level.selectedIndex + 1); + await level.menu.handleInput(event); return; case "click": { - const item = items[clamp(level.selectedIndex, 0, items.length - 1)]; + const item = level.menu.selectedItem; if (!item) return; if (item.browsable && item.playable) { ctx.stack.push( @@ -233,18 +193,46 @@ export class MediaBrowseLayer implements Layer { } private descendInto(ctx: LayerContext, item: MediaBrowseItem): void { - const level: BrowseLevel = { - parentId: item.mediaId, - title: item.title || "(untitled)", - items: null, - error: "", - selectedIndex: 0, - scrollRow: 0, - }; + const level = this.createLevel(item.mediaId, item.title || "(untitled)"); this.levels.push(level); this.loadLevel(ctx, level); } + private createLevel(parentId: string, title: string): BrowseLevel { + return { + parentId, + title, + items: null, + error: "", + menu: new Menu({ + wrap: false, + rowGap: 1, + highlight: { radius: 4 }, + getHeight: () => tightRowHeight(getDefaultSmallFont()), + draw: (args) => this.drawItem(args), + }), + }; + } + + private drawItem({ image, item, x, y, width, height, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const value = selected ? 255 : 200; + const textWidth = width - 2 * LIST_HIGHLIGHT_PAD - 16; + const textY = centeredTextY(font, y, height); + const title = truncateRight(font, item.title || "(untitled)", textWidth); + image.drawText(font, x + LIST_HIGHLIGHT_PAD, textY, title, value); + if (item.subtitle) { + const titleWidth = font.measureText(title); + const subtitleWidth = font.measureText(item.subtitle); + if (titleWidth + subtitleWidth + 24 <= textWidth) { + image.drawText(font, x + LIST_HIGHLIGHT_PAD + textWidth - subtitleWidth, textY, item.subtitle, 110); + } + } + if (item.browsable) { + drawSubmenuIndicator(image, font, x, y, width, height, selected ? value : 110); + } + } + private startConnect(ctx: LayerContext): void { this.phase = "connecting"; mediaBrowserBridge @@ -252,14 +240,7 @@ export class MediaBrowseLayer implements Layer { .then((rootId) => { if (this.removed) return; this.phase = "ready"; - const root: BrowseLevel = { - parentId: rootId, - title: "Library", - items: null, - error: "", - selectedIndex: 0, - scrollRow: 0, - }; + const root = this.createLevel(rootId, "Library"); this.levels = [root]; this.loadLevel(ctx, root); ctx.actions.requestRender(); @@ -278,6 +259,7 @@ export class MediaBrowseLayer implements Layer { .then((items) => { if (this.removed) return; level.items = items; + level.menu.setItems(items, 0); ctx.actions.requestRender(); }) .catch((error) => { diff --git a/app/apps/music/music-app.ts b/app/apps/music/music-app.ts index 0996ad82..7c08867a 100644 --- a/app/apps/music/music-app.ts +++ b/app/apps/music/music-app.ts @@ -5,7 +5,7 @@ import { clamp } from "../../util/numeric-util"; import { directionalFallback, GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL_DOWN, GESTURE_SCROLL_UP, type InputEvent, isDirectionalInput } from "../../ui/gestures"; import { MenuLayer, drawSubmenuIndicator } from "../../ui/menu"; import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; -import { lineStep, tightRowHeight } from "../../ui/metrics"; +import { centeredTextY, lineStep, tightRowHeight } from "../../ui/metrics"; import { mediaControllerBridge, type MediaControllerState, type MediaQueueItem } from "../../native/media-controller"; import { mediaBrowserBridge, type MediaBrowserApp } from "../../native/media-browser"; import { MediaBrowseLayer } from "./media-browse"; @@ -139,7 +139,7 @@ class MusicAppLayer implements Layer { this.reconcileSelection(actions, queue); const listHeight = height - LIST_TOP - LIST_BOTTOM_MARGIN; const focused = ctx.stack.isFocused(); - // Row boxes start one pixel above LIST_TOP so the text lands at LIST_TOP + 1. + // Row boxes start one pixel above LIST_TOP, level with the column divider. this.actionsMenu.paint( image, { x: ACTION_X - LIST_TEXT_INSET, y: LIST_TOP - 1, width: ACTION_WIDTH + 2 * LIST_TEXT_INSET - 4, height: listHeight }, @@ -165,16 +165,16 @@ class MusicAppLayer implements Layer { private drawAction({ image, item: action, x, y, width, height, selected }: MenuDrawArgs): void { const font = getDefaultSmallFont(); const value = !action.enabled ? (selected ? 130 : 90) : selected ? 255 : 200; - image.drawText(font, x + LIST_TEXT_INSET, y + 2, truncateText(font, action.label, ACTION_WIDTH - 16), value); + image.drawText(font, x + LIST_TEXT_INSET, centeredTextY(font, y, height), truncateText(font, action.label, ACTION_WIDTH - 16), value); if ((action.kind === "playlist" || action.kind === "browse") && action.enabled) { drawSubmenuIndicator(image, font, x, y, width, height, value); } } - private drawQueueItem({ image, item, x, y, width, selected }: MenuDrawArgs): void { + private drawQueueItem({ image, item, x, y, width, height, selected }: MenuDrawArgs): void { const font = getDefaultSmallFont(); const label = `${item.active ? "> " : " "}${item.title || "(untitled)"}`; - image.drawText(font, x + LIST_TEXT_INSET, y + 2, truncateText(font, label, width - 2 * LIST_TEXT_INSET), selected ? 255 : 200); + image.drawText(font, x + LIST_TEXT_INSET, centeredTextY(font, y, height), truncateText(font, label, width - 2 * LIST_TEXT_INSET), selected ? 255 : 200); } async handleInput(event: InputEvent, ctx: LayerContext): Promise { diff --git a/app/apps/music/music-settings.ts b/app/apps/music/music-settings.ts index 52dac95d..c4c45207 100644 --- a/app/apps/music/music-settings.ts +++ b/app/apps/music/music-settings.ts @@ -10,39 +10,45 @@ import { drawToggleMenuItem, MenuLayer, type MenuItem } from "../../ui/menu"; /** Discovered apps stay visible even when ignored or no longer publishing a session. */ export class MusicSettingsLayer implements Layer { private menu: MenuLayer | null = null; - private signature = ""; - private selectedPackage = ""; + private menuWidth = 0; + /** The package behind each current row, parallel to the menu's items. */ + private packages: string[] = []; constructor() { // Refresh installed browser services, remembering ignored services too. mediaBrowserBridge.listBrowsableApps(true); } + /** Refresh the rows from the remembered apps, keeping the selection on the same package. */ private currentMenu(ctx: LayerContext): MenuLayer { const apps = readMediaApps().sort((a, b) => a.appName.localeCompare(b.appName) || a.packageName.localeCompare(b.packageName)); + const items: MenuItem[] = apps.map((app) => ({ + label: app.appName, + onSelect: () => setMediaAppEnabled(app, !isMediaAppEnabled(app.packageName)), + render: ({ image, x, y, width, selected }) => { + const font = getDefaultSmallFont(); + const duplicateName = apps.some((other) => other !== app && other.appName === app.appName); + const label = duplicateName ? `${app.appName} (${app.packageName})` : app.appName; + drawToggleMenuItem(image, font, x, y, width, truncateText(font, label, width - 48), + isMediaAppEnabled(app.packageName), selected); + }, + })); + if (!items.length) items.push({ label: "No media apps discovered yet.", disabled: true, onSelect: () => {} }); + const selectedPackage = this.menu?.selectedIndex != null ? this.packages[this.menu.selectedIndex] : undefined; + const index = apps.findIndex((app) => app.packageName === selectedPackage); + this.packages = apps.map((app) => app.packageName); + const width = ctx.stack.getBaseSize().width; - const signature = JSON.stringify([width, apps.map((app) => [app.packageName, app.appName])]); - if (!this.menu || signature !== this.signature) { - this.signature = signature; - const items: MenuItem[] = apps.map((app) => ({ - label: app.appName, - onSelect: () => setMediaAppEnabled(app, !isMediaAppEnabled(app.packageName)), - render: ({ image, x, y, width, selected }) => { - if (selected) this.selectedPackage = app.packageName; - const font = getDefaultSmallFont(); - const duplicateName = apps.some((other) => other !== app && other.appName === app.appName); - const label = duplicateName ? `${app.appName} (${app.packageName})` : app.appName; - drawToggleMenuItem(image, font, x, y, width, truncateText(font, label, width - 48), - isMediaAppEnabled(app.packageName), selected); - }, - })); - if (!items.length) items.push({ label: "No media apps discovered yet.", disabled: true, onSelect: () => {} }); + if (!this.menu || width !== this.menuWidth) { + this.menuWidth = width; this.menu = new MenuLayer("Music settings", items, { x: 8, y: 8, width: width - 16, opaque: true, showBorder: false, footer: "On = enabled Off = ignored", - }).selectItem(Math.max(0, apps.findIndex((app) => app.packageName === this.selectedPackage))); + }).selectItem(Math.max(0, index)); + } else { + this.menu.setItems(items, index >= 0 ? index : undefined); } return this.menu; } diff --git a/app/apps/navigate/navigate-app.worker.ts b/app/apps/navigate/navigate-app.worker.ts index 5bfa6194..14cdd830 100644 --- a/app/apps/navigate/navigate-app.worker.ts +++ b/app/apps/navigate/navigate-app.worker.ts @@ -16,14 +16,12 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import * as frameTimings from "../../native/frame-timings"; import { getActiveDisplay } from "../../native/active-display"; import { - drawListScrollbar, drawRightValueMenuItem, - drawSelectionHighlight, drawSubmenuIndicator, drawToggleMenuItem, - scrollToKeepSelectionVisible, type MenuItem, } from "../../ui/menu"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { LIST_ROW_TEXT_INSET, listRowHeight } from "../../ui/metrics"; import { WindowMenu, WindowMenuLayer } from "../../ui/window-menu"; import type { LayerContext } from "../../ui/layers"; @@ -205,9 +203,8 @@ type IdleEntry = | { kind: "recent"; destination: RecentDestination } | { kind: "action"; label: string; detail: string; run: () => void }; -/** Idle-page list selection (index into idleEntries()). */ -let idleSelection = 0; -let idleScrollRow = 0; +/** The idle page's list; created on first use (idleList) so module load stays free of paint dependencies. */ +let idleMenu: Menu | null = null; /** * In-progress destination edit: the phone text editor is open on `setting` @@ -948,7 +945,7 @@ function windowMenuItems(win: NavWindow): MenuItem[] { onSelect: () => { const enabled = navigateRememberRecentSetting.toggle(); if (!enabled) clearRecentDestinations(); - clampIdleSelection(); + syncIdleList(); }, render: ({ image, x, y, width, selected }) => { drawToggleMenuItem( @@ -963,7 +960,7 @@ function windowMenuItems(win: NavWindow): MenuItem[] { ); }, }); - const selectedEntry = phase === "idle" ? idleEntries()[idleSelection] : undefined; + const selectedEntry = phase === "idle" ? syncIdleList().selectedItem : null; if (selectedEntry?.kind === "recent") { const recent = selectedEntry.destination; items.push({ @@ -971,7 +968,7 @@ function windowMenuItems(win: NavWindow): MenuItem[] { onSelect: (ctx) => { ctx.stack.pop(); removeRecentDestination(recent); - clampIdleSelection(); + syncIdleList(); }, }); } @@ -981,7 +978,7 @@ function windowMenuItems(win: NavWindow): MenuItem[] { onSelect: (ctx) => { ctx.stack.pop(); clearRecentDestinations(); - clampIdleSelection(); + syncIdleList(); }, }); } @@ -1066,7 +1063,7 @@ function customDestinationMenuItems(destination: SavedDestination): MenuItem[] { onSelect: (ctx) => { closeMenusAnd(ctx, () => { removeCustomDestination(destination.id); - clampIdleSelection(); + syncIdleList(); }); }, }, @@ -1121,7 +1118,7 @@ function finishEdit(confirmed: boolean): void { if (!editing) { navigateDestinationNameDraftSetting.set(""); navigateDestinationAddressDraftSetting.set(""); - clampIdleSelection(); + syncIdleList(); render(); } } @@ -1206,9 +1203,27 @@ function idleEntries(): IdleEntry[] { return entries; } -function clampIdleSelection(): void { - const count = idleEntries().length; - idleSelection = Math.max(0, Math.min(idleSelection, count - 1)); +/** Horizontal inset of the idle list's selection boxes. */ +const IDLE_LIST_X = 20; +/** Pixels between consecutive idle rows' selection boxes. */ +const IDLE_ROW_GAP = 2; + +function idleList(): Menu { + idleMenu ??= new Menu({ + wrap: false, + rowGap: IDLE_ROW_GAP, + highlight: { radius: 6 }, + getHeight: () => listRowHeight(smallFont), + draw: drawIdleRow, + }); + return idleMenu; +} + +/** Refresh the idle list from idleEntries(); the selection keeps its index, clamped into range. */ +function syncIdleList(): Menu { + const list = idleList(); + list.setItems(idleEntries()); + return list; } function navigateToIdleEntry(entry: IdleEntry): void { @@ -1282,7 +1297,7 @@ function handleInput(win: NavWindow, event: InputEvent, frameId: number): void { } else if (phase === "arrived" || phase === "map") { stopNavigation(""); } else if (phase === "idle") { - const entry = idleEntries()[idleSelection]; + const entry = syncIdleList().selectedItem; if (!entry) { frameTimings.finishFrame(frameId, "discarded: navigate ignored click"); return; @@ -1301,8 +1316,7 @@ function handleInput(win: NavWindow, event: InputEvent, frameId: number): void { maybeRefreshMap(); renderAndSubmit(win, frameId); } else if (phase === "idle" && idleEntries().length > 1) { - const count = idleEntries().length; - idleSelection = Math.max(0, Math.min(count - 1, idleSelection + (event.type === "scroll-down" ? 1 : -1))); + syncIdleList().moveSelection(event.type === "scroll-down" ? 1 : -1); renderAndSubmit(win, frameId); } else { frameTimings.finishFrame(frameId, "discarded: navigate ignored scroll"); @@ -1392,59 +1406,33 @@ function paintIdleList(image: GrayImage, win: NavWindow, entries: IdleEntry[], t const rowHeight = listRowHeight(smallFont); const listBottom = image.height - 30; const visibleRows = Math.max(1, Math.floor((listBottom - top) / rowHeight)); - idleSelection = Math.max(0, Math.min(idleSelection, entries.length - 1)); - idleScrollRow = scrollToKeepSelectionVisible(idleScrollRow, idleSelection, visibleRows, entries.length); - const rowX = 20; const rowWidth = image.width - 40 - (entries.length > visibleRows ? 10 : 0); - const labelWidth = Math.floor(rowWidth * 0.4); - for (let row = 0; row < visibleRows; row++) { - const index = idleScrollRow + row; - const entry = entries[index]; - if (!entry) break; - const y = top + row * rowHeight; - const selected = index === idleSelection; - if (selected) drawSelectionHighlight(image, rowX, y, rowWidth, rowHeight - 2, win.focused); - const textX = rowX + 6; - const textY = y + LIST_ROW_TEXT_INSET; - if (entry.kind === "action") { - const label = truncateText(smallFont, entry.label, labelWidth); - image.drawText(smallFont, textX, textY, label, selected ? 245 : 210); - const detailX = textX + labelWidth + 8; - image.drawText( - smallFont, - detailX, - textY, - truncateText(smallFont, entry.detail, rowX + rowWidth - 6 - detailX), - selected ? 170 : 130, - ); - } else if (entry.kind === "saved") { - const label = truncateText(smallFont, entry.destination.name, labelWidth); - image.drawText(smallFont, textX, textY, label, selected ? 245 : 210); - const detailX = textX + labelWidth + 8; - image.drawText( - smallFont, - detailX, - textY, - truncateText(smallFont, entry.destination.address, rowX + rowWidth - 6 - detailX), - selected ? 170 : 130, - ); - } else { - const label = truncateText(smallFont, entry.destination.name, labelWidth); - image.drawText(smallFont, textX, textY, label, selected ? 245 : 210); - const detailX = textX + labelWidth + 8; - const detail = entry.destination.place ? `${entry.destination.place} (recent)` : "(recent)"; - image.drawText( - smallFont, - detailX, - textY, - truncateText(smallFont, detail, rowX + rowWidth - 6 - detailX), - selected ? 170 : 130, - ); - } - } - if (entries.length > visibleRows) { - drawListScrollbar(image, rowX + rowWidth + 4, top, visibleRows * rowHeight - 2, idleScrollRow, visibleRows, entries.length); + const list = idleList(); + list.setItems(entries); + list.paint(image, { x: IDLE_LIST_X, y: top, width: rowWidth, height: visibleRows * rowHeight - IDLE_ROW_GAP }, win.focused); + list.drawScrollbar(image, IDLE_LIST_X + rowWidth + 4, top, visibleRows * rowHeight - 2); +} + +/** Two columns: the entry's name, then its detail (action hint, address or place). */ +function drawIdleRow({ image, item: entry, x, y, width, selected }: MenuDrawArgs): void { + const labelWidth = Math.floor(width * 0.4); + const textX = x + 6; + const textY = y + LIST_ROW_TEXT_INSET; + let label: string; + let detail: string; + if (entry.kind === "action") { + label = entry.label; + detail = entry.detail; + } else if (entry.kind === "saved") { + label = entry.destination.name; + detail = entry.destination.address; + } else { + label = entry.destination.name; + detail = entry.destination.place ? `${entry.destination.place} (recent)` : "(recent)"; } + image.drawText(smallFont, textX, textY, truncateText(smallFont, label, labelWidth), selected ? 245 : 210); + const detailX = textX + labelWidth + 8; + image.drawText(smallFont, detailX, textY, truncateText(smallFont, detail, x + width - 6 - detailX), selected ? 170 : 130); } function paintNavigating(image: GrayImage, win: NavWindow): void { diff --git a/app/apps/teleprompter/teleprompter-app.ts b/app/apps/teleprompter/teleprompter-app.ts index bbd3be46..c615297b 100644 --- a/app/apps/teleprompter/teleprompter-app.ts +++ b/app/apps/teleprompter/teleprompter-app.ts @@ -52,10 +52,8 @@ export type TeleprompterAppOptions = InProcessAppOptions & { * over the home page. */ export function createTeleprompterAppWindow(options: TeleprompterAppOptions): InProcessWindow { - // The home menu's items are rebuilt in place whenever the recents change - // (MenuLayer reads the array each paint). - const homeItems: MenuItem[] = []; - const home = new MenuLayer("Teleprompter", homeItems, HOME_LAYOUT); + // The home menu's items are replaced (refreshHome) whenever the recents change. + const home = new MenuLayer("Teleprompter", [], HOME_LAYOUT); let created: InProcessWindow | null = null; let notice = ""; @@ -142,10 +140,8 @@ export function createTeleprompterAppWindow(options: TeleprompterAppOptions): In if (notice) { items.push({ label: notice, disabled: true, onSelect: () => {} }); } - homeItems.length = 0; - homeItems.push(...items); // Land on the most recent script (one click resumes it), else on Browse. - home.selectItem(getRecentScripts().length > 0 ? 1 : 0); + home.setItems(items, getRecentScripts().length > 0 ? 1 : 0); } refreshHome(); diff --git a/app/apps/terminal/terminal-app.worker.ts b/app/apps/terminal/terminal-app.worker.ts index 29c112ce..fd110ad5 100644 --- a/app/apps/terminal/terminal-app.worker.ts +++ b/app/apps/terminal/terminal-app.worker.ts @@ -54,7 +54,8 @@ import { clamp } from "../../util/numeric-util"; import { terminalAutoReconnectSetting, terminalLaunchPresetsSetting, terminalNewConnectionSetting, terminalWakeOnBellSetting } from "../../ui/dashboard-settings"; import { connectionDisplayName, loadConnections, parseConnectionString, saveConnections, TERMINAL_CONNECTIONS_KEY, updateConnection, type TerminalConnection } from "./connections"; import { TerminalEmulator } from "./terminal-emulator"; -import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu"; +import { type MenuItem } from "../../ui/menu"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { lineStep, listRowHeight } from "../../ui/metrics"; import { WindowMenu } from "../../ui/window-menu"; import { appViewportSize } from "../../ui/shell/geometry"; @@ -126,8 +127,8 @@ type HubMode = "sessions" | "connections" | "add"; type HubWindow = BaseWindow & { kind: "hub"; mode: HubMode; - selectedIndex: number; - scrollRow: number; + /** The section's item list; created on first paint or input (hubMenu). */ + list: Menu | null; /** * Session recency keys in display order, captured when the window last * became visible so the list doesn't reshuffle under the user while it's @@ -507,8 +508,7 @@ function openWindow(windowId: string, surfaceId: string, title: string, viewport lastSubmittedFingerprint: "", menu: null, mode: "sessions", - selectedIndex: 0, - scrollRow: 0, + list: null, sessionOrder: [], addError: "", }); @@ -1189,11 +1189,48 @@ type HubItem = { onSelect?: () => void; }; +/** Vertical offset of a row's text line from the top of its selection box. */ +const HUB_ROW_TEXT_INSET = 4; +/** Horizontal inset of the list's selection boxes from the viewport edges. */ +const HUB_LIST_X = 20; + +/** The hub window's list, created on first use so openWindow stays free of paint dependencies. */ +function hubMenu(window: HubWindow): Menu { + window.list ??= new Menu({ + wrap: false, + rowGap: 1, + getHeight: () => listRowHeight(chromeFont()), + isSelectable: (item) => Boolean(item.onSelect), + onSelect: (item) => item.onSelect?.(), + draw: drawHubRow, + }); + return window.list; +} + +function drawHubRow({ image, item, x, y, width, selected }: MenuDrawArgs): void { + const font = chromeFont(); + if (item.heading) { + image.drawText(font, x, y + HUB_ROW_TEXT_INSET, item.label, 140); + return; + } + // Activity gutter, open-window number column, then the label, truncated + // to the row (shared with the Glanceboard's Terminal widget). + drawSessionRow(image, font, { + x: x + 2, + y: y + HUB_ROW_TEXT_INSET, + width: width - 8, + label: item.label, + openGlyph: item.openGlyph ?? null, + active: Boolean(item.active), + phase: hubAnimationPhase, + value: selected ? 255 : 200, + }); +} + /** Switch the hub between its sections, resetting selection state. */ function setHubMode(window: HubWindow, mode: HubMode): void { window.mode = mode; - window.selectedIndex = 0; - window.scrollRow = 0; + window.list?.select(0); window.addError = ""; } @@ -1423,34 +1460,6 @@ function endAddConnection(window: HubWindow): void { post({ type: "end-text-setting-edit" }); } -/** Move the hub selection to the next selectable item in `direction`. */ -function moveHubSelection(window: HubWindow, items: HubItem[], direction: -1 | 1): void { - let index = window.selectedIndex + direction; - while (index >= 0 && index < items.length && !items[index]!.onSelect) { - index += direction; - } - if (index >= 0 && index < items.length) { - window.selectedIndex = index; - } -} - -/** Clamp the selection into range and off heading rows (prefer moving down). */ -function clampHubSelection(window: HubWindow, items: HubItem[]): void { - if (!items.length) { - window.selectedIndex = 0; - return; - } - let index = Math.max(0, Math.min(window.selectedIndex, items.length - 1)); - if (!items[index]!.onSelect) { - let forward = index; - while (forward < items.length && !items[forward]!.onSelect) forward++; - let backward = index; - while (backward >= 0 && !items[backward]!.onSelect) backward--; - index = forward < items.length ? forward : Math.max(0, backward); - } - window.selectedIndex = index; -} - function handleHubInput(window: HubWindow, event: InputEvent, frameId: number): void { if (window.mode === "add") { if (event.type === "click") { @@ -1461,23 +1470,18 @@ function handleHubInput(window: HubWindow, event: InputEvent, frameId: number): frameTimings.finishFrame(frameId, "discarded: terminal add-connection ignored input"); return; } - const items = hubItems(window); - clampHubSelection(window, items); + const list = hubMenu(window); + list.setItems(hubItems(window)); switch (event.type) { case "scroll-up": - moveHubSelection(window, items, -1); - renderAndSubmit(window, frameId); - return; case "scroll-down": - moveHubSelection(window, items, 1); + case "click": + // The menu's input handler is async only to await onSelect; hub item + // callbacks are synchronous, so the selection move or action has + // already applied when it returns and the frame can paint right away. + list.handleInput(event).catch((error) => console.error("terminal hub action failed", error)); renderAndSubmit(window, frameId); return; - case "click": { - const item = items[window.selectedIndex]; - item?.onSelect?.(); - renderAndSubmit(window, frameId); - return; - } default: frameTimings.finishFrame(frameId, "discarded: terminal hub ignored input"); return; @@ -1601,49 +1605,18 @@ function paintHub(window: HubWindow): GrayImage { listTop += 2 * step + 6; } - const items = hubItems(window); - clampHubSelection(window, items); - const hubRowH = listRowHeight(chromeFont()); - const visibleRowCount = Math.max(1, ((window.viewportHeight - 6 - listTop) / hubRowH) | 0); - window.scrollRow = scrollToKeepSelectionVisible(window.scrollRow, window.selectedIndex, visibleRowCount, items.length); - const lastVisibleRow = Math.min(items.length, window.scrollRow + visibleRowCount); - for (let index = window.scrollRow; index < lastVisibleRow; index++) { - const y = listTop + (index - window.scrollRow) * hubRowH; - const item = items[index]!; - if (item.heading) { - image.drawText(chromeFont(), 20, y + 2, item.label, 140); - continue; - } - const selected = index === window.selectedIndex; - if (selected) { - // Match the shell convention: fill only when this window has focus, so - // an outline-only selection signals the sidebar owns input. - drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, hubRowH - 1, window.focused, 8); - } - // Activity gutter, open-window number column, then the label, truncated - // to the row (shared with the Glanceboard's Terminal widget). - drawSessionRow(image, chromeFont(), { - x: 22, - y: y + 2, - width: window.viewportWidth - 22 - 26, - label: item.label, - openGlyph: item.openGlyph ?? null, - active: Boolean(item.active), - phase: hubAnimationPhase, - value: selected ? 255 : 200, - }); - } - if (items.length > visibleRowCount) { - drawListScrollbar( - image, - window.viewportWidth - 10, - listTop, - visibleRowCount * hubRowH - 4, - window.scrollRow, - visibleRowCount, - items.length, - ); - } + const list = hubMenu(window); + list.setItems(hubItems(window)); + // Selection boxes start above the text line; the menu fills the selected + // box only while this window has focus (an outline alone means the sidebar + // owns input), matching the shell convention. + const listHeight = window.viewportHeight - 6 - listTop; + list.paint( + image, + { x: HUB_LIST_X, y: listTop - 2, width: window.viewportWidth - 2 * HUB_LIST_X, height: listHeight }, + window.focused, + ); + list.drawScrollbar(image, window.viewportWidth - 10, listTop, listHeight - 4); return image; } diff --git a/app/apps/timer/timer-app.ts b/app/apps/timer/timer-app.ts index 0555aecf..af61c195 100644 --- a/app/apps/timer/timer-app.ts +++ b/app/apps/timer/timer-app.ts @@ -31,14 +31,12 @@ import { } from "../../ui/gestures"; import { type Layer, type LayerContext } from "../../ui/layers"; import { - drawListScrollbar, drawRightValueMenuItem, - drawSelectionHighlight, drawToggleMenuItem, - scrollToKeepSelectionVisible, TextPageLayer, type MenuItem, } from "../../ui/menu"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics"; import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window"; import { shell } from "../../ui/shell/shell"; @@ -91,6 +89,8 @@ const LIST_SHARE = 0.4; const LIST_MIN_WIDTH = 190; const LIST_MAX_WIDTH = 240; const LIST_TOP = 6; +/** Pixels between consecutive list rows' selection boxes. */ +const LIST_ROW_GAP = 1; const STAGE_X = 10; /** Gap between the stage's right edge and the list's divider. */ const STAGE_LIST_GAP = 14; @@ -183,8 +183,22 @@ function fittingDigitFont(text: string, maxWidth: number, sizes: readonly number export class TimersLayer implements Layer { readonly acceptsDirectional = true; + /** + * The selected row's key: the source of truth for the selection, which + * survives row rebuilds and is pinned to newly ringing items. The list + * menu is re-synced from it before each paint, hit test and move. + */ private selectionKey = ""; - private scrollRow = 0; + private readonly list = new Menu({ + wrap: true, + rowGap: LIST_ROW_GAP, + highlight: { radius: 6 }, + getHeight: () => listRowHeight(smallFont()), + isSelectable: (row) => row.kind !== "header", + draw: (args) => this.drawListRow(args), + }); + /** Per-paint inputs to drawListRow. */ + private listPaint = { dim: 1, now: 0 }; private mode: Mode = { kind: "list" }; /** Which of the ringing stage's two buttons is highlighted. */ private ringButton = 0; @@ -232,7 +246,8 @@ export class TimersLayer implements Layer { let index = rows.findIndex((row) => row.key === this.selectionKey); if (index < 0) { // The row went away (a dismissed timer, a deleted alarm): stay in place. - index = clamp(this.scrollRow, 0, rows.length - 1); + const firstVisibleRow = Math.floor(this.list.scrollTop / listRowHeight(smallFont())); + index = clamp(firstVisibleRow, 0, rows.length - 1); while (index < rows.length && rows[index]!.kind === "header") index++; if (index >= rows.length) index = rows.findIndex((row) => row.kind !== "header"); this.selectionKey = rows[index]!.key; @@ -244,14 +259,16 @@ export class TimersLayer implements Layer { return rows[this.reconcileSelection(rows)]!; } - private moveSelection(rows: Row[], delta: number): void { - const count = rows.length; - let index = this.reconcileSelection(rows); - for (let step = 0; step < count; step++) { - index = (index + delta + count) % count; - if (rows[index]!.kind !== "header") break; - } - this.selectionKey = rows[index]!.key; + /** Point the list menu at these rows and the current selection. */ + private syncList(rows: Row[]): void { + this.list.setItems(rows, this.reconcileSelection(rows)); + } + + private moveSelection(rows: Row[], delta: -1 | 1): void { + this.syncList(rows); + this.list.moveSelection(delta); + const index = this.list.selectedIndex; + if (index !== null) this.selectionKey = rows[index]!.key; } /** Called on every engine change: jump to a newly ringing item. */ @@ -547,15 +564,14 @@ export class TimersLayer implements Layer { /** A mirror touch: on the list, select the row under it. */ hitTest(x: number, y: number, ctx: LayerContext): boolean { if (this.mode.kind !== "list") return false; - const { width, height } = ctx.stack.getBaseSize(); + const { width } = ctx.stack.getBaseSize(); const listX = width - listWidthFor(width); if (x < listX) return false; const rows = this.buildRows(Date.now()); - this.reconcileSelection(rows); - const rowHeight = listRowHeight(smallFont()); - const index = this.scrollRow + Math.floor((y - LIST_TOP) / rowHeight); - const row = rows[index]; - if (!row || row.kind === "header" || y < LIST_TOP || y > height) return true; + this.syncList(rows); + const index = this.list.indexAt(y); + if (index === null) return true; + const row = rows[index]!; if (this.selectionKey === row.key) { this.activateRow(row); } else { @@ -882,79 +898,78 @@ export class TimersLayer implements Layer { dim: number, now: number, ): void { - const font = smallFont(); - const rowHeight = listRowHeight(font); + const rowHeight = listRowHeight(smallFont()); const visible = Math.max(1, Math.floor((height - 2 * LIST_TOP) / rowHeight)); - this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, selectedIndex, visible, rows.length); + this.listPaint = { dim, now }; + // While a picker owns the stage the list has no live selection, so no + // highlight; drawListRow still brightens the selected row by key. + this.list.setItems(rows, dim === 1 ? selectedIndex : null); + this.list.paint(image, { x: listX, y: LIST_TOP, width: listWidth - 12, height: visible * rowHeight - LIST_ROW_GAP }, focused); + this.list.drawScrollbar(image, listX + listWidth - 7, LIST_TOP, visible * rowHeight - 4); + } + + private drawListRow({ image, item: row, x, y, width, height }: MenuDrawArgs): void { + const font = smallFont(); + const { dim, now } = this.listPaint; + const rowHeight = height + LIST_ROW_GAP; const shade = (value: number) => Math.round(value * dim); - const textX = listX + 8; - const textWidth = listWidth - 24; - const last = Math.min(rows.length, this.scrollRow + visible); - for (let index = this.scrollRow; index < last; index++) { - const row = rows[index]!; - const y = LIST_TOP + (index - this.scrollRow) * rowHeight; - const textY = y + LIST_ROW_TEXT_INSET; - if (row.kind === "header") { - image.drawText(font, textX, textY, row.title!, shade(90)); - continue; - } - const selected = index === selectedIndex; - if (selected && dim === 1) { - drawSelectionHighlight(image, listX, y, listWidth - 12, rowHeight - 1, focused, 6); - } - const bright = shade(selected ? 250 : 210); - const soft = shade(selected ? 170 : 130); - switch (row.kind) { - case "timer": { - const timer = row.timer!; - const phase = timerPhase(timer); - const digits = phase === "rung" ? "0:00" : formatCountdown(timerRemainingMs(timer, now)); - const digitsValue = phase === "rung" ? (Math.floor(now / 1000) % 2 ? bright : soft) : phase === "paused" ? soft : bright; - image.drawText(font, textX, textY, digits, digitsValue); - const digitsWidth = font.measureText(digits) + 8; - const nameWidth = textWidth - digitsWidth - (phase === "paused" ? 12 : 0); - if (nameWidth > 12) { - image.drawText(font, textX + digitsWidth, textY, truncateText(font, timerDisplayName(timer), nameWidth), soft); - } - if (phase === "paused") drawPauseMark(image, listX + listWidth - 22, y + Math.floor(rowHeight / 2) - 5, soft); - break; - } - case "new-timer": - image.drawText(font, textX, textY, "+ New timer", shade(selected ? 220 : 150)); - break; - case "stopwatch": { - const stopwatch = timerEngine.state.stopwatch; - const running = stopwatchIsRunning(stopwatch); - const elapsed = formatElapsed(stopwatchElapsedMs(stopwatch, now), false); - image.drawText(font, textX, textY, "Stopwatch", running ? bright : soft); - image.drawText(font, listX + listWidth - 16 - font.measureText(elapsed), textY, elapsed, running ? bright : soft); - break; - } - case "alarm": { - const alarm = row.alarm!; - const on = alarm.enabled; - const time = formatTimeOfDay(alarm.hour, alarm.minute, twelveHour()); - image.drawText(font, textX, textY, time, on ? bright : soft); - const timeWidth = font.measureText(time) + 8; - const daysWidth = textWidth - timeWidth - 14; - if (daysWidth > 12) { - image.drawText(font, textX + timeWidth, textY, truncateText(font, alarm.label || formatDays(alarm.days), daysWidth), on ? soft : shade(80)); - } - const dotX = listX + listWidth - 22; - const dotY = y + Math.floor(rowHeight / 2) - 4; - if (alarm.ringingSinceMs !== null || on) image.fillRoundedRect(dotX, dotY, 8, 8, on ? shade(220) : shade(90), 4); - else image.drawRoundedRect(dotX, dotY, 8, 8, shade(90), 4); - break; - } - case "new-alarm": - image.drawText(font, textX, textY, "+ New alarm", shade(selected ? 220 : 150)); - break; - default: - break; - } + const textX = x + 8; + const textWidth = width - 12; + const textY = y + LIST_ROW_TEXT_INSET; + if (row.kind === "header") { + image.drawText(font, textX, textY, row.title!, shade(90)); + return; } - if (rows.length > visible) { - drawListScrollbar(image, listX + listWidth - 7, LIST_TOP, visible * rowHeight - 4, this.scrollRow, visible, rows.length); + const selected = row.key === this.selectionKey; + const bright = shade(selected ? 250 : 210); + const soft = shade(selected ? 170 : 130); + switch (row.kind) { + case "timer": { + const timer = row.timer!; + const phase = timerPhase(timer); + const digits = phase === "rung" ? "0:00" : formatCountdown(timerRemainingMs(timer, now)); + const digitsValue = phase === "rung" ? (Math.floor(now / 1000) % 2 ? bright : soft) : phase === "paused" ? soft : bright; + image.drawText(font, textX, textY, digits, digitsValue); + const digitsWidth = font.measureText(digits) + 8; + const nameWidth = textWidth - digitsWidth - (phase === "paused" ? 12 : 0); + if (nameWidth > 12) { + image.drawText(font, textX + digitsWidth, textY, truncateText(font, timerDisplayName(timer), nameWidth), soft); + } + if (phase === "paused") drawPauseMark(image, x + width - 10, y + Math.floor(rowHeight / 2) - 5, soft); + break; + } + case "new-timer": + image.drawText(font, textX, textY, "+ New timer", shade(selected ? 220 : 150)); + break; + case "stopwatch": { + const stopwatch = timerEngine.state.stopwatch; + const running = stopwatchIsRunning(stopwatch); + const elapsed = formatElapsed(stopwatchElapsedMs(stopwatch, now), false); + image.drawText(font, textX, textY, "Stopwatch", running ? bright : soft); + image.drawText(font, x + width - 4 - font.measureText(elapsed), textY, elapsed, running ? bright : soft); + break; + } + case "alarm": { + const alarm = row.alarm!; + const on = alarm.enabled; + const time = formatTimeOfDay(alarm.hour, alarm.minute, twelveHour()); + image.drawText(font, textX, textY, time, on ? bright : soft); + const timeWidth = font.measureText(time) + 8; + const daysWidth = textWidth - timeWidth - 14; + if (daysWidth > 12) { + image.drawText(font, textX + timeWidth, textY, truncateText(font, alarm.label || formatDays(alarm.days), daysWidth), on ? soft : shade(80)); + } + const dotX = x + width - 10; + const dotY = y + Math.floor(rowHeight / 2) - 4; + if (alarm.ringingSinceMs !== null || on) image.fillRoundedRect(dotX, dotY, 8, 8, on ? shade(220) : shade(90), 4); + else image.drawRoundedRect(dotX, dotY, 8, 8, shade(90), 4); + break; + } + case "new-alarm": + image.drawText(font, textX, textY, "+ New alarm", shade(selected ? 220 : 150)); + break; + default: + break; } } diff --git a/app/apps/weather/weather.ts b/app/apps/weather/weather.ts index 5b16fbf8..d32d2e3f 100644 --- a/app/apps/weather/weather.ts +++ b/app/apps/weather/weather.ts @@ -1,12 +1,11 @@ import { getDefaultLargeFont, getDefaultMediumFont, getDefaultSmallFont } from "../../graphics/ui-fonts"; import { GrayImage, type UiFont } from "../../graphics/image"; import { wrapText, truncateText } from "../../graphics/textwrap"; -import { clamp } from "../../util/numeric-util"; import { type ForecastPeriod, type WeatherState } from "../../native/weather"; import { GESTURE_CLICK, type InputEvent } from "../../ui/gestures"; import { type Layer, type LayerContext } from "../../ui/layers"; -import { drawSelectionHighlight, scrollToKeepSelectionVisible } from "../../ui/menu"; -import { lineStep, tightRowHeight } from "../../ui/metrics"; +import { Menu, type MenuDrawArgs } from "../../ui/menu-core"; +import { centeredTextY, lineStep, tightRowHeight } from "../../ui/metrics"; const PAGE_X = 18; const HEADER_Y = 8; @@ -18,11 +17,26 @@ const FORECAST_TOP = 124; const FORECAST_MIN_ROW_HEIGHT = 23; /** Gap between forecast columns. */ const FORECAST_COL_GAP = 14; +/** Left edge of the forecast rows' selection boxes. */ +const FORECAST_BOX_X = PAGE_X - 7; +/** Pixels between consecutive forecast rows' selection boxes. */ +const FORECAST_ROW_GAP = 2; + +/** Forecast column x offsets from the row box's left edge. */ +type ForecastColumns = { name: number; temp: number; precip: number; summary: number }; /** Weather's current-conditions summary and scrollable 12-hour forecast. */ export class WeatherLayer implements Layer { - private selectedIndex = 0; - private scrollRow = 0; + /** Forecast table rows: selection only, a click does nothing there. */ + private readonly forecastMenu = new Menu({ + wrap: false, + rowGap: FORECAST_ROW_GAP, + highlight: { radius: 5 }, + getHeight: () => forecastRowHeight(getDefaultSmallFont()), + draw: (args) => this.drawForecastRow(args), + }); + /** Column layout for drawForecastRow, set by each drawForecast. */ + private columns: ForecastColumns = { name: 0, temp: 0, precip: 0, summary: 0 }; constructor( private readonly state: () => WeatherState, @@ -81,10 +95,9 @@ export class WeatherLayer implements Layer { return; } if (!weather.forecast.length || weather.phase !== "ready") return; - if (event.type === "scroll-up") { - this.selectedIndex = Math.max(0, this.selectedIndex - 1); - } else if (event.type === "scroll-down") { - this.selectedIndex = Math.min(weather.forecast.length - 1, this.selectedIndex + 1); + if (event.type === "scroll-up" || event.type === "scroll-down") { + this.forecastMenu.setItems(weather.forecast); + void this.forecastMenu.handleInput(event); } } @@ -134,12 +147,14 @@ export class WeatherLayer implements Layer { image.drawText(font, PAGE_X, FORECAST_TOP, "No upcoming forecast periods.", 160); return; } - this.selectedIndex = clamp(this.selectedIndex, 0, forecast.length - 1); - const rowH = Math.max(FORECAST_MIN_ROW_HEIGHT, tightRowHeight(font) + 3); + const rowH = forecastRowHeight(font); // The last row only needs its text line (not a full row pitch of // clearance below), which usually fits one more row before the bottom. + // The menu only draws rows whose whole selection box fits, so the box + // holds that many rows, cut at the image's bottom edge. const visibleRows = Math.max(1, 1 + Math.floor((height - FORECAST_TOP - (font.lineHeight + 4)) / rowH)); - this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedIndex, visibleRows, forecast.length); + const boxTop = FORECAST_TOP - 2; + const boxHeight = Math.min(visibleRows * rowH - FORECAST_ROW_GAP, height - boxTop); // Columns are sized to the widest period name so names ("Wednesday // Night") never truncate; the summary column absorbs what's left. @@ -155,20 +170,31 @@ export class WeatherLayer implements Layer { image.drawText(font, tempX, FORECAST_HEADER_Y, "Temp", 105); image.drawText(font, precipX, FORECAST_HEADER_Y, "Rain", 105); - const last = Math.min(forecast.length, this.scrollRow + visibleRows); - for (let index = this.scrollRow; index < last; index++) { - const period = forecast[index]!; - const y = FORECAST_TOP + (index - this.scrollRow) * rowH; - const selected = index === this.selectedIndex; - if (selected) { - drawSelectionHighlight(image, PAGE_X - 7, y - 2, width - 2 * (PAGE_X - 7), rowH - 2, ctx.stack.isFocused(), 5); - } - const shade = selected ? 245 : 190; - image.drawText(font, PAGE_X, y + 2, period.name, shade); - image.drawText(font, tempX, y + 2, period.temperatureF === null ? "--" : `${Math.round(period.temperatureF)}°F`, shade); - image.drawText(font, precipX, y + 2, period.precipitationPercent === null ? "--" : `${Math.round(period.precipitationPercent)}%`, selected ? 220 : 155); - image.drawText(font, summaryX, y + 2, truncateText(font, period.shortForecast, width - summaryX - PAGE_X), selected ? 220 : 165); - } + this.columns = { + name: PAGE_X - FORECAST_BOX_X, + temp: tempX - FORECAST_BOX_X, + precip: precipX - FORECAST_BOX_X, + summary: summaryX - FORECAST_BOX_X, + }; + this.forecastMenu.setItems(forecast); + this.forecastMenu.paint( + image, + { x: FORECAST_BOX_X, y: boxTop, width: width - 2 * FORECAST_BOX_X, height: boxHeight }, + ctx.stack.isFocused(), + ); + } + + private drawForecastRow({ image, item: period, x, y, width, height, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const columns = this.columns; + const shade = selected ? 245 : 190; + const textY = centeredTextY(font, y, height); + image.drawText(font, x + columns.name, textY, period.name, shade); + image.drawText(font, x + columns.temp, textY, period.temperatureF === null ? "--" : `${Math.round(period.temperatureF)}°F`, shade); + image.drawText(font, x + columns.precip, textY, period.precipitationPercent === null ? "--" : `${Math.round(period.precipitationPercent)}%`, selected ? 220 : 155); + // The summary stops PAGE_X short of the viewport's right edge, as the name starts PAGE_X in from the left. + const summaryWidth = width - columns.summary - columns.name; + image.drawText(font, x + columns.summary, textY, truncateText(font, period.shortForecast, summaryWidth), selected ? 220 : 165); } private drawMessage( @@ -190,6 +216,11 @@ export class WeatherLayer implements Layer { } } +/** Forecast row pitch, including the gap between selection boxes. */ +function forecastRowHeight(font: UiFont): number { + return Math.max(FORECAST_MIN_ROW_HEIGHT, tightRowHeight(font) + 3); +} + function formatAge(ageMs: number): string { const minutes = Math.max(0, Math.round(ageMs / 60_000)); if (minutes < 1) return "just now"; diff --git a/app/ui/dashboard/settings-panel.ts b/app/ui/dashboard/settings-panel.ts index ec006487..1dd957df 100644 --- a/app/ui/dashboard/settings-panel.ts +++ b/app/ui/dashboard/settings-panel.ts @@ -1,10 +1,10 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts"; import { GrayImage, type UiFont } from "../../graphics/image"; import { wrapText } from "../../graphics/textwrap"; -import { clamp } from "../../util/numeric-util"; import { InputEvent } from "../gestures"; import { Layer, LayerContext, PaintBelow } from "../layers"; -import { drawSelectionHighlight, isMenuItemDisabled, MenuItem, MenuLayer, openModalMenu } from "../menu"; +import { isMenuItemDisabled, MenuItem, MenuLayer, openModalMenu } from "../menu"; +import { Menu } from "../menu-core"; import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../metrics"; import { shell } from "../shell/shell"; @@ -30,6 +30,10 @@ export type SettingsSection = { const PAD = 8; const LEFT_W = 150; +/** Gap between a row's selection box and the next row. */ +const ROW_GAP = 2; +/** Horizontal inset of row text (and custom row content) from its selection box. */ +const ROW_TEXT_X = 10; const MAX_DESCRIPTION_LINES = 3; // A throwaway menu to satisfy MenuItem.onSelect's second parameter; the // settings items never use it (they act via ctx only). @@ -45,23 +49,62 @@ export class SettingsPanelLayer implements Layer { // Watch swipes map onto the two columns: right goes into a section's // items, left comes back out (and out to the sidebar from the left column). readonly acceptsDirectional = true; - private leftIndex = 0; - private rightIndex = 0; private focus: "left" | "right" = "left"; - private leftScroll = 0; - private rightScroll = 0; + private readonly leftMenu: Menu; + /** The highlighted section's items; unselected while focus is in the left column (a preview). */ + private readonly rightMenu: Menu; + /** The context of the paint in progress, handed to item render callbacks. */ + private paintCtx: LayerContext | null = null; - constructor(private readonly sections: SettingsSection[]) {} + constructor(private readonly sections: SettingsSection[]) { + this.leftMenu = new Menu({ + items: sections, + wrap: true, + rowGap: ROW_GAP, + highlight: { radius: 6 }, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: ({ image, item, x, y, selected }) => { + image.drawText(getDefaultSmallFont(), x + ROW_TEXT_X, y + LIST_ROW_TEXT_INSET, item.label, selected ? 255 : 200); + }, + }); + this.rightMenu = new Menu({ + items: this.section().items, + selectedIndex: null, + wrap: true, + rowGap: ROW_GAP, + highlight: { radius: 6 }, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: ({ image, item, x, y, width, height, selected }) => { + const disabled = isMenuItemDisabled(item); + if (item.render) { + item.render({ + image, + x: x + ROW_TEXT_X, + y, + width: width - ROW_TEXT_X - 8, + height: height - 1, + selected, + disabled, + text: item.label, + ctx: this.paintCtx!, + }); + } else { + image.drawText(getDefaultSmallFont(), x + ROW_TEXT_X, y + LIST_ROW_TEXT_INSET, item.label, + disabled ? 70 : selected ? 255 : 200); + } + }, + }); + } private section(): SettingsSection { - return this.sections[clamp(this.leftIndex, 0, this.sections.length - 1)]!; + return this.leftMenu.selectedItem ?? this.sections[0]!; } /** Select a left-column section by label (deep link, e.g. from an app's menu). */ focusSection(label: string): void { const index = this.sections.findIndex((section) => section.label === label); if (index < 0) return; - this.leftIndex = index; + this.leftMenu.select(index); this.focus = "left"; this.resetRight(); } @@ -71,27 +114,16 @@ export class SettingsPanelLayer implements Layer { const { width, height } = ctx.stack.getBaseSize(); const image = new GrayImage(width, height, 0); const appFocused = ctx.stack.isFocused(); - - this.leftIndex = clamp(this.leftIndex, 0, this.sections.length - 1); const section = this.section(); const rightItems = section.items; - this.rightIndex = clamp(this.rightIndex, 0, Math.max(0, rightItems.length - 1)); + this.rightMenu.setItems(rightItems); - const rowH = listRowHeight(font); const top = PAD; const listBottom = height - PAD; // Left column: section labels. - const leftRows = Math.max(1, ((listBottom - top) / rowH) | 0); - this.leftScroll = clampScroll(this.leftIndex, this.leftScroll, leftRows, this.sections.length); - for (let i = this.leftScroll; i < Math.min(this.sections.length, this.leftScroll + leftRows); i++) { - const rowY = top + (i - this.leftScroll) * rowH; - const selected = i === this.leftIndex; - if (selected) { - drawSelectionHighlight(image, PAD - 2, rowY, LEFT_W, rowH - 2, appFocused && this.focus === "left", 6); - } - image.drawText(font, PAD + 8, rowY + LIST_ROW_TEXT_INSET, this.sections[i]!.label, selected ? 255 : 200); - } + this.leftMenu.paint(image, { x: PAD - 2, y: top, width: LEFT_W, height: listBottom - top }, + appFocused && this.focus === "left"); // Column divider (a light rule, not a full border). const divX = PAD + LEFT_W + 6; @@ -108,38 +140,15 @@ export class SettingsPanelLayer implements Layer { if (rightItems.length && rightTop < listBottom) { // Once focus is in the right column, the selected item's extended // description (when it has one) is drawn over the bottom of the pane by - // the companion SettingsDescriptionOverlayLayer. The row list keeps the - // full column height — rows the description band covers are drawn and - // partially occluded by the overlay's plane — but the scroll clamp uses - // the shrunk height so the selected row always stays clear of it. - const descriptionH = this.descriptionHeight(font, rightW); - const clampRows = Math.max(1, ((listBottom - descriptionH - rightTop) / rowH) | 0); - const rightRows = Math.max(1, ((listBottom - rightTop) / rowH) | 0); - this.rightScroll = clampScroll(this.rightIndex, this.rightScroll, clampRows, rightItems.length); - for (let i = this.rightScroll; i < Math.min(rightItems.length, this.rightScroll + rightRows); i++) { - const item = rightItems[i]!; - const rowY = rightTop + (i - this.rightScroll) * rowH; - // A selection only appears once focus is in the right column; before - // that the pane is a preview of what tapping would open. - const selected = this.focus === "right" && i === this.rightIndex; - const disabled = isMenuItemDisabled(item); - if (selected) { - drawSelectionHighlight(image, rightX - 2, rowY, rightW + 2, rowH - 2, appFocused, 6); - } - if (item.render) { - item.render({ - image, - x: rightX + 8, - y: rowY, - width: rightW - 16, - height: rowH - 3, - selected, - disabled, - text: item.label, - ctx, - }); - } else { - image.drawText(font, rightX + 8, rowY + LIST_ROW_TEXT_INSET, item.label, disabled ? 70 : selected ? 255 : 200); + // the companion SettingsDescriptionOverlayLayer. The list stops above + // that band, so the selected row always stays clear of it. + const listHeight = listBottom - this.descriptionHeight(font, rightW) - rightTop; + if (listHeight > 0) { + this.paintCtx = ctx; + try { + this.rightMenu.paint(image, { x: rightX - 2, y: rightTop, width: rightW + 2, height: listHeight }, appFocused); + } finally { + this.paintCtx = null; } } } @@ -150,8 +159,7 @@ export class SettingsPanelLayer implements Layer { /** The selected item's wrapped help text, or [] when none applies. */ private descriptionLines(font: UiFont, rightW: number): string[] { if (this.focus !== "right") return []; - const items = this.section().items; - const item = items[clamp(this.rightIndex, 0, Math.max(0, items.length - 1))]; + const item = this.rightMenu.selectedItem; if (!item?.description) return []; return wrapText(font, item.description, rightW - 4).slice(0, MAX_DESCRIPTION_LINES); } @@ -164,9 +172,8 @@ export class SettingsPanelLayer implements Layer { /** * Draw the selected item's help text band (separator + text on an opaque * background) at the bottom of the right column. Called by the companion - * overlay layer with the overlay's own canvas: as a separate plane its - * raster covers the row list's glyphs, so it can partially occlude a row — - * which raster drawn into the panel's own image cannot do. + * overlay layer with the overlay's own canvas, so the band stays above + * whatever the panel paints (including a section's detail content). */ paintDescriptionOverlay(image: GrayImage, ctx: LayerContext): void { const font = getDefaultSmallFont(); @@ -186,18 +193,15 @@ export class SettingsPanelLayer implements Layer { } async handleInput(event: InputEvent, ctx: LayerContext): Promise { + const scroll = scrollEventFor(event); if (this.focus === "left") { + if (scroll) { + const before = this.leftMenu.selectedIndex; + await this.leftMenu.handleInput(scroll); + if (this.leftMenu.selectedIndex !== before) this.resetRight(); + return; + } switch (event.type) { - case "scroll-up": - case "swipe-up": - this.leftIndex = (this.leftIndex + this.sections.length - 1) % this.sections.length; - this.resetRight(); - return; - case "scroll-down": - case "swipe-down": - this.leftIndex = (this.leftIndex + 1) % this.sections.length; - this.resetRight(); - return; case "click": case "swipe-right": // Only enter sections that have something interactive on the right. @@ -215,38 +219,42 @@ export class SettingsPanelLayer implements Layer { } } - const items = this.section().items; + if (scroll) { + await this.rightMenu.handleInput(scroll); + return; + } switch (event.type) { - case "scroll-up": - case "swipe-up": - if (items.length) this.rightIndex = (this.rightIndex + items.length - 1) % items.length; - return; - case "scroll-down": - case "swipe-down": - if (items.length) this.rightIndex = (this.rightIndex + 1) % items.length; - return; case "click": - case "swipe-right": - if (items.length) { - const item = items[clamp(this.rightIndex, 0, items.length - 1)]!; - if (!isMenuItemDisabled(item)) await item.onSelect(ctx, NO_MENU); - } + case "swipe-right": { + const item = this.rightMenu.selectedItem; + if (item && !isMenuItemDisabled(item)) await item.onSelect(ctx, NO_MENU); return; + } case "double-click": case "swipe-left": + // Back to a preview: the right column keeps its scroll but shows no selection. this.focus = "left"; + this.rightMenu.select(null); return; default: return; } } + /** Show the highlighted section's items from the top, selected on the first only when focus is there. */ private resetRight(): void { - this.rightIndex = 0; - this.rightScroll = 0; + this.rightMenu.setItems(this.section().items, this.focus === "right" ? 0 : null); + this.rightMenu.scrollTop = 0; } } +/** Scroll and watch swipe-up/down both move a column's selection. */ +function scrollEventFor(event: InputEvent): InputEvent | null { + if (event.type === "scroll-up" || event.type === "swipe-up") return { ...event, type: "scroll-up" } as InputEvent; + if (event.type === "scroll-down" || event.type === "swipe-down") return { ...event, type: "scroll-down" } as InputEvent; + return null; +} + /** * Companion layer for SettingsPanelLayer, sitting permanently above it in the * settings app's stack: paints the selected item's help text as its own plane @@ -276,12 +284,3 @@ export class SettingsDescriptionOverlayLayer implements Layer { export function openSettingsSubMenu(ctx: LayerContext, title: string, items: MenuItem[]): void { openModalMenu(ctx, title, items); } - -function clampScroll(selected: number, scroll: number, visible: number, count: number): number { - if (selected < scroll) { - scroll = selected; - } else if (selected >= scroll + visible) { - scroll = selected - visible + 1; - } - return clamp(scroll, 0, Math.max(0, count - visible)); -} diff --git a/app/ui/font-picker.ts b/app/ui/font-picker.ts index 70b113ca..ba06b1b6 100644 --- a/app/ui/font-picker.ts +++ b/app/ui/font-picker.ts @@ -23,7 +23,8 @@ import { type UiFontSelection, } from "../graphics/ui-fonts"; import { GESTURE_DOUBLE_CLICK, type InputEvent } from "./gestures"; -import { drawRightValueMenuItem, drawSelectionHighlight, openModalMenu, type MenuItem } from "./menu"; +import { drawRightValueMenuItem, openModalMenu, type MenuItem } from "./menu"; +import { Menu, type MenuDrawArgs } from "./menu-core"; import { LIST_ROW_TEXT_INSET, listRowHeight } from "./metrics"; import type { Layer, LayerContext } from "./layers"; @@ -62,7 +63,14 @@ type RowId = (typeof ROWS)[number]; export class FontPickerLayer implements Layer { private readonly families: FontFamily[]; private draft: Draft; - private selectedRow = 0; + private readonly menu = new Menu({ + items: ROWS, + wrap: true, + rowGap: 2, + highlight: { radius: 8 }, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: (args) => this.drawRow(args), + }); constructor(private readonly options: FontPickerOptions) { this.families = collectFamilies(options.monospaceOnly); @@ -111,26 +119,7 @@ export class FontPickerLayer implements Layer { const rowWidth = width - 2 * rowX; const rowHeight = listRowHeight(font); const rowsTop = 24 + font.lineHeight; - for (let index = 0; index < ROWS.length; index++) { - const row = ROWS[index]!; - const y = rowsTop + index * rowHeight; - const disabled = this.rowDisabled(row); - if (index === this.selectedRow) { - drawSelectionHighlight(image, rowX - 10, y, rowWidth + 20, rowHeight - 2, focused, 8); - } - if (row === "save") { - image.drawText(font, rowX, y + LIST_ROW_TEXT_INSET, "Save", index === this.selectedRow ? 255 : 200); - continue; - } - const label = row === "face" ? "Font" : row === "weight" ? "Weight" : "Size"; - const value = this.rowValue(row); - if (disabled) { - image.drawText(font, rowX, y + LIST_ROW_TEXT_INSET, label, 70); - image.drawText(font, rowX + rowWidth - font.measureText(value) - 2, y + LIST_ROW_TEXT_INSET, value, 70); - } else { - drawRightValueMenuItem(image, font, rowX, y, rowWidth, label, value); - } - } + this.menu.paint(image, { x: rowX - 10, y: rowsTop, width: rowWidth + 20, height: ROWS.length * rowHeight }, focused); // Preview: a separator, then the sample line in the draft font. const previewTop = rowsTop + ROWS.length * rowHeight + 10; @@ -145,6 +134,25 @@ export class FontPickerLayer implements Layer { return image; } + /** Row box = highlight box; text sits 10px in from its left edge and 10px from its right. */ + private drawRow({ image, item: row, x, y, width, selected }: MenuDrawArgs): void { + const font = getDefaultSmallFont(); + const textX = x + 10; + const textWidth = width - 20; + if (row === "save") { + image.drawText(font, textX, y + LIST_ROW_TEXT_INSET, "Save", selected ? 255 : 200); + return; + } + const label = row === "face" ? "Font" : row === "weight" ? "Weight" : "Size"; + const value = this.rowValue(row); + if (this.rowDisabled(row)) { + image.drawText(font, textX, y + LIST_ROW_TEXT_INSET, label, 70); + image.drawText(font, textX + textWidth - font.measureText(value) - 2, y + LIST_ROW_TEXT_INSET, value, 70); + } else { + drawRightValueMenuItem(image, font, textX, y, textWidth, label, value); + } + } + private rowDisabled(row: RowId): boolean { return (row === "weight" || row === "size") && this.draft.kind === "bitmap"; } @@ -165,14 +173,12 @@ export class FontPickerLayer implements Layer { handleInput(event: InputEvent, ctx: LayerContext): void { switch (event.type) { case "scroll-up": - this.selectedRow = (this.selectedRow + ROWS.length - 1) % ROWS.length; - return; case "scroll-down": - this.selectedRow = (this.selectedRow + 1) % ROWS.length; + void this.menu.handleInput(event); return; case "click": { - const row = ROWS[this.selectedRow]!; - if (this.rowDisabled(row)) return; + const row = this.menu.selectedItem; + if (!row || this.rowDisabled(row)) return; if (row === "face") this.openFaceMenu(ctx); else if (row === "weight") this.openWeightMenu(ctx); else if (row === "size") this.openSizeMenu(ctx); diff --git a/app/ui/menu-core.ts b/app/ui/menu-core.ts index 121ceb5d..108e07b3 100644 --- a/app/ui/menu-core.ts +++ b/app/ui/menu-core.ts @@ -80,15 +80,20 @@ type MenuLayout = { tops: number[]; heights: number[]; total: number }; export class Menu { private itemList: readonly T[]; private selected: number | null; + /** + * The caller asked for no selection. Otherwise a null selection only means + * nothing was selectable, and the first selectable item is chosen as soon + * as one exists (a menu created empty and filled later starts on it). + */ + private deselected: boolean; private scrollY = 0; private lastBox: MenuBox | null = null; private readonly motion = new MenuHighlightMotion(); constructor(private readonly options: MenuOptions) { this.itemList = options.items ?? []; - this.selected = options.selectedIndex === undefined - ? this.nextSelectable(null, 1) - : this.resolve(options.selectedIndex); + this.deselected = options.selectedIndex === null; + this.selected = this.settle(options.selectedIndex ?? null); } get items(): readonly T[] { @@ -110,6 +115,11 @@ export class Menu { return this.scrollY; } + /** Move the viewport's top edge; the next paint clamps it and scrolls the selection back into view. */ + set scrollTop(value: number) { + this.scrollY = Math.max(0, value | 0); + } + /** True when the content did not fit the box given to the last paint. */ get overflows(): boolean { if (!this.lastBox) return false; @@ -119,8 +129,8 @@ export class Menu { /** * Replace the items. `selectedIndex` names the new selection (null for * none); left out, the selection stays at the same index, clamped into - * range. The viewport keeps the selected row at the same on-screen - * position when it can. + * range, or lands on the first selectable item if there was none. The + * viewport keeps the selected row at the same on-screen position when it can. */ setItems(items: readonly T[], selectedIndex?: number | null): void { const width = this.lastBox?.width; @@ -128,15 +138,21 @@ export class Menu { ? this.layout(width).tops[this.selected]! - this.scrollY : null; this.itemList = items; - this.selected = this.resolve(selectedIndex === undefined ? this.selected : selectedIndex); + if (selectedIndex !== undefined) this.deselected = selectedIndex === null; + this.selected = this.settle(selectedIndex === undefined ? this.selected : selectedIndex); if (before !== null && this.selected !== null && width !== undefined) { this.scrollY = Math.max(0, this.layout(width).tops[this.selected]! - before); } } - /** Move the selection; a non-selectable or out-of-range index lands on the nearest selectable one. */ + /** + * Move the selection; a non-selectable or out-of-range index lands on the + * nearest selectable one. null clears it until the user scrolls or a + * number is selected. + */ select(index: number | null): void { - this.selected = this.resolve(index); + this.deselected = index === null; + this.selected = this.settle(index); } /** Step the selection by one selectable row; handles wrap and the exit callbacks. */ @@ -147,6 +163,7 @@ export class Menu { if (next !== null) { if (from !== null) this.motion.navigate(from, false); this.selected = next; + this.deselected = false; return; } if (from === null && this.scrollContent(delta)) return; @@ -155,6 +172,7 @@ export class Menu { if (wrapped !== null && wrapped !== from) { if (from !== null) this.motion.navigate(from, true); this.selected = wrapped; + this.deselected = false; } else if (from === null && this.lastBox) { this.scrollY = delta > 0 ? 0 : this.maxScroll(this.layout(this.lastBox.width), this.lastBox.height); } @@ -258,9 +276,15 @@ export class Menu { return null; } + /** Resolve a stored selection: null stays null only when the caller deselected. */ + private settle(index: number | null): number | null { + if (index === null) return this.deselected ? null : this.nextSelectable(null, 1); + return this.resolve(index); + } + /** Clamp an index into range and onto a selectable row (nearest below, else nearest above). */ - private resolve(index: number | null): number | null { - if (index === null || !this.itemList.length) return null; + private resolve(index: number): number | null { + if (!this.itemList.length) return null; const clamped = Math.max(0, Math.min(this.itemList.length - 1, index | 0)); if (this.isSelectable(clamped)) return clamped; return this.nextSelectable(clamped, 1) ?? this.nextSelectable(clamped, -1); @@ -268,7 +292,7 @@ export class Menu { /** Re-validate the selection against the current items (they may have been edited in place). */ private reconcile(): void { - this.selected = this.resolve(this.selected); + this.selected = this.settle(this.selected); } private layout(width: number): MenuLayout { @@ -312,6 +336,15 @@ export class Menu { } } } + // Never scroll past the end (setItems can leave the viewport there when + // rows are removed or inserted above the selection): pull back to the + // first row top that still shows the last row, so no partial row starts + // the list. The selected row stays visible, since it ends by the list's end. + const maxScroll = this.maxScroll(layout, viewportHeight); + if (target > maxScroll) { + const aligned = layout.tops.find((rowTop) => rowTop >= maxScroll); + target = aligned !== undefined && aligned <= target ? aligned : maxScroll; + } this.scrollY = Math.max(0, target); } diff --git a/app/ui/menu-highlight-motion.ts b/app/ui/menu-highlight-motion.ts index 8d63b91d..e7c09121 100644 --- a/app/ui/menu-highlight-motion.ts +++ b/app/ui/menu-highlight-motion.ts @@ -1,4 +1,4 @@ -export const MENU_HIGHLIGHT_DURATION_MS = 300; +export const MENU_HIGHLIGHT_DURATION_MS = 240; export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number; token: number; durationMs: number }; let nextToken = 1; diff --git a/app/ui/menu.ts b/app/ui/menu.ts index f3f4b8ad..39af0a14 100644 --- a/app/ui/menu.ts +++ b/app/ui/menu.ts @@ -6,7 +6,7 @@ import { Layer, LayerContext, PaintBelow } from "./layers"; import { Menu, MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE } from "./menu-core"; import { GESTURE_DOUBLE_CLICK, InputEvent } from "./gestures"; -import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight, menuTitleHeight } from "./metrics"; +import { LIST_ROW_TEXT_INSET, centeredTextY, lineStep, listRowHeight, menuTitleHeight } from "./metrics"; const DEFAULT_MENU_X = 8; const DEFAULT_MENU_Y = 8; const DEFAULT_MENU_WIDTH = 272; @@ -148,7 +148,7 @@ export function drawSubmenuIndicator( ): void { const arrow = ">"; const x = highlightX + highlightWidth - font.measureText(arrow) - 4; - const y = highlightY + (((highlightHeight - font.lineHeight) / 2) | 0); + const y = centeredTextY(font, highlightY, highlightHeight); image.drawText(font, x, y, arrow, value); } @@ -206,7 +206,7 @@ export class MenuLayer implements Layer { constructor( private readonly title: string | null, - private readonly items: MenuItem[], + private items: MenuItem[], private readonly layout: MenuLayout = { x: DEFAULT_MENU_X, y: DEFAULT_MENU_Y, @@ -248,6 +248,25 @@ export class MenuLayer implements Layer { return this; } + /** The selected row's index, or null when nothing is selectable. */ + get selectedIndex(): number | null { + return this.menu.selectedIndex; + } + + get selectedItem(): MenuItem | null { + return this.menu.selectedItem; + } + + /** + * Replace the rows in place, keeping scroll and highlight state. The + * selection follows Menu.setItems: pass the new index of the previously + * selected row, or leave it out to keep the same index, clamped. + */ + setItems(items: MenuItem[], selectedIndex?: number | null): void { + this.items = items; + this.menu.setItems(items, selectedIndex); + } + paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { const font = getDefaultSmallFont(); const rowHeight = listRowHeight(font); diff --git a/app/ui/metrics.ts b/app/ui/metrics.ts index 4c99f4d6..3cdb2397 100644 --- a/app/ui/metrics.ts +++ b/app/ui/metrics.ts @@ -8,6 +8,8 @@ * * The formulas reproduce the pre-TTF constants exactly at the 12px default: * listRowHeight 20, tightRowHeight 16, lineStep 14, menuTitleHeight 16. + * tightRowHeight follows the measured ink rather than the line box, which + * for Terminus is the same thing. */ import type { UiFont } from "../graphics/image"; @@ -20,13 +22,71 @@ export function listRowHeight(font: UiFont): number { export const LIST_ROW_TEXT_INSET = 4; /** - * Height of one row in dense lists (file browser, track lists). Grows at - * half the lineHeight's rate above the 12px anchor: TTF line heights carry - * internal leading that already reads as row spacing, so full-rate growth - * made large-font rows feel too tall. + * Characters whose ink bounds a font's text rows: accented capitals (the + * highest Latin marks), descenders, brackets, and digits. + */ +const INK_SAMPLE = "ÅÉÎÖÇÑbdfhklgjpqy()[]{}|/_0123456789"; + +export type TextInkBounds = { + /** First inked row, relative to the drawText y (the line top); may be negative. */ + top: number; + /** One past the last inked row, relative to the line top; may exceed lineHeight. */ + bottom: number; +}; + +const inkBoundsCache = new WeakMap(); + +/** + * The vertical extent of a font's ink over a representative sample, measured + * from the rendered glyphs. Bitmap faces fill their line box exactly; TTF + * faces may leave internal leading inside it or overshoot it with marks. + * Falls back to the line box when the font renders no sample ink. + */ +export function textInkBounds(font: UiFont): TextInkBounds { + const cached = inkBoundsCache.get(font); + if (cached) return cached; + let top = Infinity; + let bottom = -Infinity; + if (typeof font.getGlyph === "function") { + for (const char of INK_SAMPLE) { + const glyph = font.getGlyph(char.codePointAt(0)!); + if (!glyph || glyph.bbxHeight <= 0) continue; + // Same placement as rasterizeGlyph: baseline at y + ascent, bbxY up from it. + const glyphTop = font.ascent - (glyph.bbxHeight + glyph.bbxY); + top = Math.min(top, glyphTop); + bottom = Math.max(bottom, glyphTop + glyph.bbxHeight); + } + } + const bounds = top < bottom ? { top, bottom } : { top: 0, bottom: font.lineHeight }; + inkBoundsCache.set(font, bounds); + return bounds; +} + +/** Height of a font's ink extent (see textInkBounds). */ +export function textInkHeight(font: UiFont): number { + const { top, bottom } = textInkBounds(font); + return bottom - top; +} + +/** + * The drawText y that centers a font's ink vertically in a box, rounding the + * spare pixel to the bottom. Pair with row heights derived from + * textInkHeight so the ink fits whatever the face's internal leading. + */ +export function centeredTextY(font: UiFont, boxTop: number, boxHeight: number): number { + const { top } = textInkBounds(font); + return boxTop + Math.floor((boxHeight - textInkHeight(font)) / 2) - top; +} + +/** + * Row pitch in dense lists (file browser, track lists): the font's ink height + * plus 4px, so a selection box one pixel shorter than the pitch keeps at + * least a pixel of clearance around the ink. Draw the text with + * centeredTextY; a fixed offset from the row top can overflow faces whose + * ink starts below their line top. */ export function tightRowHeight(font: UiFont): number { - return font.lineHeight + 4 - Math.floor(Math.max(0, font.lineHeight - 12) / 2); + return textInkHeight(font) + 4; } /** Step between consecutive lines of body/paragraph text. */ diff --git a/app/ui/notification-filter.ts b/app/ui/notification-filter.ts index 93bb9144..123f5d9e 100644 --- a/app/ui/notification-filter.ts +++ b/app/ui/notification-filter.ts @@ -7,35 +7,41 @@ import { type InputEvent } from "./gestures"; import { type Layer, type LayerContext, type PaintBelow } from "./layers"; import { drawToggleMenuItem, MenuLayer, type MenuItem } from "./menu"; -/** Rebuild rows when new sources arrive, keeping the current selection by package. */ +/** Refresh rows as new sources arrive, keeping the current selection by package. */ export class NotificationFilterLayer implements Layer { private menu: MenuLayer | null = null; - private packages = ""; - private selectedPackage = ""; + private menuWidth = 0; + /** The package behind each current row, parallel to the menu's items. */ + private packages: string[] = []; private currentMenu(ctx: LayerContext): MenuLayer { readActiveNotifications(ALL_NOTIFICATIONS); const sources = readNotificationSources().sort((a, b) => a.appName.localeCompare(b.appName) || a.packageName.localeCompare(b.packageName)); - const signature = JSON.stringify([ctx.stack.getBaseSize().width, sources.map((source) => [source.packageName, source.appName])]); - if (!this.menu || signature !== this.packages) { - this.packages = signature; - const items: MenuItem[] = sources.map((source) => ({ - label: source.appName, - onSelect: () => setNotificationSourceEnabled(source, !shouldShowNotificationOnGlasses(source.packageName)), - render: ({ image, x, y, width, selected }) => { - if (selected) this.selectedPackage = source.packageName; - const font = getDefaultSmallFont(); - drawToggleMenuItem(image, font, x, y, width, truncateText(font, source.appName, width - 48), - shouldShowNotificationOnGlasses(source.packageName), selected); - }, - })); - if (!items.length) items.push({ label: "No notification sources discovered yet.", disabled: true, onSelect: () => {} }); + const items: MenuItem[] = sources.map((source) => ({ + label: source.appName, + onSelect: () => setNotificationSourceEnabled(source, !shouldShowNotificationOnGlasses(source.packageName)), + render: ({ image, x, y, width, selected }) => { + const font = getDefaultSmallFont(); + drawToggleMenuItem(image, font, x, y, width, truncateText(font, source.appName, width - 48), + shouldShowNotificationOnGlasses(source.packageName), selected); + }, + })); + if (!items.length) items.push({ label: "No notification sources discovered yet.", disabled: true, onSelect: () => {} }); + const selectedPackage = this.menu?.selectedIndex != null ? this.packages[this.menu.selectedIndex] : undefined; + const index = sources.findIndex((source) => source.packageName === selectedPackage); + this.packages = sources.map((source) => source.packageName); + + const width = ctx.stack.getBaseSize().width; + if (!this.menu || width !== this.menuWidth) { + this.menuWidth = width; this.menu = new MenuLayer("Notification filter", items, { - x: 8, y: 8, width: ctx.stack.getBaseSize().width - 16, + x: 8, y: 8, width: width - 16, opaque: true, showBorder: false, footer: "On = show popups on glasses", - }).selectItem(Math.max(0, sources.findIndex((source) => source.packageName === this.selectedPackage))); + }).selectItem(Math.max(0, index)); + } else { + this.menu.setItems(items, index >= 0 ? index : undefined); } return this.menu; } diff --git a/app/ui/notifications.ts b/app/ui/notifications.ts index 3b9ad386..e52adfaa 100644 --- a/app/ui/notifications.ts +++ b/app/ui/notifications.ts @@ -4,7 +4,7 @@ import { getDefaultSmallFont } from "../graphics/ui-fonts"; import { truncateText } from "../graphics/textwrap"; import { GrayImage, type UiFont } from "../graphics/image"; import { wrapText } from "../graphics/textwrap"; -import { lineStep, listRowHeight } from "./metrics"; +import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "./metrics"; import { ALL_NOTIFICATIONS, dismissNotification, @@ -19,7 +19,7 @@ import { notificationEmptyMessage } from "../native/notification-access"; import { noteStaleDataUsed, renderPassAllowsStaleData } from "../util/render-freshness"; import { type InputEvent } from "./gestures"; import { type Layer, type LayerContext, type PaintBelow } from "./layers"; -import { MenuLayer } from "./menu"; +import { Menu, type MenuBox } from "./menu-core"; const PAGE_X = 12; const PAGE_Y = 12; @@ -35,7 +35,19 @@ const CARD_GAP = 6; const MAX_NOTIFICATIONS = 50; // Right-hand action menu of the detail view. const DETAIL_MENU_WIDTH = 148; +/** Top of the action menu's first row box, and the space kept below its last. */ +const DETAIL_MENU_TOP = 22; +const DETAIL_MENU_BOTTOM_MARGIN = 17; +const DETAIL_MENU_ROW_GAP = 3; +/** Row text inset from the row box: horizontal, then vertical. */ +const DETAIL_MENU_TEXT_X = 8; +const DETAIL_MENU_TEXT_Y = 4; const DETAIL_CONTENT_X = 24; +// Disable-source confirmation: actions on top, the explanation below them. +const CONFIRM_X = 24; +const CONFIRM_Y = 8; +const CONFIRM_TEXT_X = 10; +const CONFIRM_PROMPT_GAP = 16; /** Icon for a paint pass: allow-stale, reporting staleness to the render loop. */ function iconForNotification(key: string): GrayImage | null { @@ -58,6 +70,8 @@ type DetailMenuItem = | { kind: "dismiss"; label: string } | { kind: "disable-source"; label: string }; +type ConfirmationItem = { label: string; run: (ctx: LayerContext) => void }; + export type SingleNotificationLayerOrigin = "notifications-list" | "new-notification-modal"; type SingleNotificationLayerOptions = { @@ -168,8 +182,24 @@ export class NotificationsListLayer implements Layer { * new-notification modal. */ export class SingleNotificationLayer implements Layer { - private selectedMenuIndex = 0; - private confirmation: { source: AndroidNotification; menu: MenuLayer } | null = null; + /** The action column; its items are rebuilt from the live notification on every paint and input. */ + private readonly detailMenu = new Menu({ + wrap: false, + rowGap: DETAIL_MENU_ROW_GAP, + highlight: { radius: 6 }, + getHeight: (item, width) => { + const font = getDefaultSmallFont(); + return detailMenuRowLines(font, item, width).length * lineStep(font) + 8; + }, + draw: ({ image, item, x, y, width, selected }) => { + const font = getDefaultSmallFont(); + const lines = detailMenuRowLines(font, item, width); + for (let line = 0; line < lines.length; line++) { + image.drawText(font, x + DETAIL_MENU_TEXT_X, y + DETAIL_MENU_TEXT_Y + line * lineStep(font), lines[line]!, selected ? 255 : 185); + } + }, + }); + private confirmation: { source: AndroidNotification; menu: Menu } | null = null; constructor( private readonly notificationKey: string, @@ -187,17 +217,18 @@ export class SingleNotificationLayer implements Layer { return this.closeUnavailableNotification(ctx, paintBelow); } - const menu = buildDetailMenu(notification, this.options.origin); - this.selectedMenuIndex = clamp(this.selectedMenuIndex, 0, Math.max(0, menu.length - 1)); + this.detailMenu.setItems(buildDetailMenu(notification, this.options.origin)); drawDetailContent(image, font, notification, iconForNotification(notification.key), width, height); - drawDetailMenu(image, font, menu, this.selectedMenuIndex, width); + this.detailMenu.paint(image, detailMenuBox(width, height), ctx.stack.isFocused()); return image; } async handleInput(event: InputEvent, ctx: LayerContext): Promise { if (this.confirmation) { + const { menu } = this.confirmation; if (event.type === "double-click") this.close(ctx); - else await this.confirmation.menu.handleInput(event, ctx); + else if (event.type === "click") menu.selectedItem?.run(ctx); + else await menu.handleInput(event); return; } const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === this.notificationKey); @@ -205,24 +236,21 @@ export class SingleNotificationLayer implements Layer { this.closeUnavailableNotification(ctx); return; } - const menu = buildDetailMenu(notification, this.options.origin); - this.selectedMenuIndex = clamp(this.selectedMenuIndex, 0, menu.length - 1); + this.detailMenu.setItems(buildDetailMenu(notification, this.options.origin)); if (event.type === "double-click") { this.close(ctx); return; } - if (event.type === "scroll-up") { - this.selectedMenuIndex = Math.max(0, this.selectedMenuIndex - 1); - return; - } - if (event.type === "scroll-down") { - this.selectedMenuIndex = Math.min(menu.length - 1, this.selectedMenuIndex + 1); + if (event.type === "scroll-up" || event.type === "scroll-down") { + await this.detailMenu.handleInput(event); return; } if (event.type !== "click") return; - const item = menu[this.selectedMenuIndex]!; + // "(unavailable)" actions stay clickable: Android decides whether they do anything. + const item = this.detailMenu.selectedItem; + if (!item) return; if (item.kind === "back") { this.close(ctx); } else if (item.kind === "action") { @@ -237,13 +265,21 @@ export class SingleNotificationLayer implements Layer { // Keep the modal alive for confirmation even after Android removes the notification. this.confirmation = { source: notification, - menu: new MenuLayer(null, [ - { label: "Cancel", onSelect: () => this.close(ctx) }, - { label: "Turn off popups", onSelect: () => { - setNotificationSourceEnabled(notification, false); - this.close(ctx); - } }, - ], { x: 12, y: 0, width: ctx.stack.getBaseSize().width - 24, minHeight: 0, showBorder: false }), + menu: new Menu({ + items: [ + { label: "Cancel", run: (runCtx) => this.close(runCtx) }, + { label: "Turn off popups", run: (runCtx) => { + setNotificationSourceEnabled(notification, false); + this.close(runCtx); + } }, + ], + wrap: true, + rowGap: 1, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: ({ image, item, x, y, selected }) => { + image.drawText(getDefaultSmallFont(), x + CONFIRM_TEXT_X, y + LIST_ROW_TEXT_INSET, item.label, selected ? 255 : 200); + }, + }), }; dismissNotification(this.notificationKey); } @@ -255,15 +291,21 @@ export class SingleNotificationLayer implements Layer { const { width, height } = ctx.stack.getBaseSize(); const image = new GrayImage(width, height, 0); // Put actions first so they remain reachable even with a large UI font. - menu.paint(ctx, () => image); - const top = 24 + 2 * listRowHeight(font); + const menuBox: MenuBox = { + x: CONFIRM_X, + y: CONFIRM_Y, + width: width - 2 * CONFIRM_X, + height: Math.min(menu.items.length * listRowHeight(font), height - CONFIRM_Y), + }; + menu.paint(image, menuBox, ctx.stack.isFocused()); + const top = menuBox.y + menuBox.height + CONFIRM_PROMPT_GAP; const prompt = `Turn off notification popups from ${source.appName || source.packageName}? You can turn them back on in the Notifications app's Notification filter.`; - const lines = wrapText(font, prompt, width - 48); + const lines = wrapText(font, prompt, width - 2 * CONFIRM_X); const maxLines = Math.max(1, Math.floor((height - top - 12) / lineStep(font))); for (let index = 0; index < Math.min(lines.length, maxLines); index++) { const text = index === maxLines - 1 && lines.length > maxLines - ? truncateText(font, lines[index] + "...", width - 48) : lines[index]!; - image.drawText(font, 24, top + index * lineStep(font), text, 210); + ? truncateText(font, lines[index] + "...", width - 2 * CONFIRM_X) : lines[index]!; + image.drawText(font, CONFIRM_X, top + index * lineStep(font), text, 210); } return image; } @@ -404,35 +446,20 @@ function drawDetailContent( } } -function drawDetailMenu(image: GrayImage, font: UiFont, menu: DetailMenuItem[], selectedIndex: number, width: number): void { - const menuX = width - DETAIL_MENU_WIDTH - 24; - const menuY = 24; - const rows = menu.map((item) => { - const lines = item.kind === "disable-source" - ? wrapText(font, item.label, DETAIL_MENU_WIDTH - 16) - : [truncateText(font, item.label, DETAIL_MENU_WIDTH - 16)]; - return { lines, height: lines.length * lineStep(font) + 8 }; - }); - const selectedBottom = rows.slice(0, selectedIndex + 1).reduce((sum, row) => sum + row.height, 0); - const scrollY = Math.max(0, selectedBottom - (image.height - menuY - 12)); - let y = menuY - scrollY; - for (let index = 0; index < menu.length; index++) { - const row = rows[index]!; - if (y < menuY) { - y += row.height; - continue; - } - if (y + row.height > image.height - 12) break; - const selected = index === selectedIndex; - if (selected) { - image.fillRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, row.height - 3, 18, 6); - image.drawRoundedRect(menuX - 8, y - 2, DETAIL_MENU_WIDTH, row.height - 3, 60, 6); - } - for (let line = 0; line < row.lines.length; line++) { - image.drawText(font, menuX, y + 2 + line * lineStep(font), row.lines[line]!, selected ? 255 : 185); - } - y += row.height; - } +/** The action column's row boxes: right of the content, from DETAIL_MENU_TOP to the bottom margin. */ +function detailMenuBox(width: number, height: number): MenuBox { + return { + x: width - DETAIL_MENU_WIDTH - 32, + y: DETAIL_MENU_TOP, + width: DETAIL_MENU_WIDTH, + height: height - DETAIL_MENU_TOP - DETAIL_MENU_BOTTOM_MARGIN, + }; +} + +/** An action row's text lines: the disable-source row wraps, the rest truncate to one line. */ +function detailMenuRowLines(font: UiFont, item: DetailMenuItem, rowWidth: number): string[] { + const textWidth = rowWidth - 2 * DETAIL_MENU_TEXT_X; + return item.kind === "disable-source" ? wrapText(font, item.label, textWidth) : [truncateText(font, item.label, textWidth)]; } function buildDetailMenu(notification: AndroidNotification, origin: SingleNotificationLayerOrigin): DetailMenuItem[] { diff --git a/app/ui/shell/assistant.ts b/app/ui/shell/assistant.ts index 05f5b0ec..1df039d7 100644 --- a/app/ui/shell/assistant.ts +++ b/app/ui/shell/assistant.ts @@ -1,26 +1,13 @@ -import { G2_LENS_WIDTH, GrayImage } from "../../graphics/image"; -import { type BdfFont } from "../../graphics/bdffont"; -import { getDefaultSmallFont } from "../../graphics/ui-fonts"; +import { type GrayImage } from "../../graphics/image"; import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../gestures"; -import { drawSelectionHighlight } from "../menu"; -import { listRowHeight } from "../metrics"; import { Layer, type LayerActions, type LayerContext } from "../layers"; -import { wrapText, truncateText } from "../../graphics/textwrap"; -import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry"; +import { createInputDialogMenu, paintInputDialog, type InputDialogRow } from "./input-dialog"; -const DIALOG_X = 40; -const DIALOG_W = G2_LENS_WIDTH - 80; -// The dialog fits inside the min-height window band (like the other shell -// overlays), wherever the vertical position setting puts it. -const DIALOG_MARGIN_Y = 28; -const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y; -const TEXT_MAX_WIDTH = DIALOG_W - 32; -const MENU_ROWS = 2; - -/** Dialog top edge; band-relative, so computed per paint. */ -function dialogY(): number { - return minWindowTop() + DIALOG_MARGIN_Y; -} +const FOLLOW_UP_ROW = 0; +const MENU_ROWS: readonly InputDialogRow[] = [ + { label: "Follow-up", dim: false }, + { label: "Done", dim: false }, +]; /** thinking: turn running; done/error: finished, showing the Follow-up/Done menu. */ type AssistantPhase = "thinking" | "done" | "error"; @@ -46,7 +33,7 @@ export class AssistantLayer implements Layer { private phase: AssistantPhase = "thinking"; private replyText = ""; private status = "Thinking..."; - private menuIndex = 0; + private readonly menu = createInputDialogMenu(MENU_ROWS); constructor( private readonly actions: LayerActions, @@ -58,7 +45,7 @@ export class AssistantLayer implements Layer { this.phase = "thinking"; this.replyText = ""; this.status = "Thinking..."; - this.menuIndex = 0; + this.menu.select(0); this.actions.requestRender(); } @@ -76,61 +63,28 @@ export class AssistantLayer implements Layer { onTurnDone(): void { this.phase = "done"; this.status = this.replyText.trim() ? "" : "(no reply)"; - this.menuIndex = 0; + this.menu.select(0); this.actions.requestRender(); } onError(message: string): void { this.phase = "error"; this.status = message; - this.menuIndex = 0; + this.menu.select(0); this.actions.requestRender(); } paint(_ctx: LayerContext, paintBelow: () => GrayImage): GrayImage { - const font = getDefaultSmallFont(); - const menuRowH = listRowHeight(font); const image = paintBelow(); - const top = dialogY(); - - // Solid dialog box (fill 1, matching the voice dialog: opaque after 4bpp - // quantization, but not the color-key transparent 0). - image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1); - image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90); - - const left = DIALOG_X + 16; - image.drawText(font, left, top + 12, this.phase === "thinking" ? "Assistant ●" : "Assistant", 220); - if (this.status) { - const statusValue = this.phase === "error" ? 200 : 130; - image.drawText(font, left, top + 30, truncateText(font, this.status, TEXT_MAX_WIDTH), statusValue); - } - const inMenu = this.phase !== "thinking"; - const textBottom = inMenu ? top + DIALOG_H - MENU_ROWS * menuRowH - 8 : top + DIALOG_H - 8; - const textTop = top + 56; - const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0); - - const wrapped = wrapText(font, this.replyText, TEXT_MAX_WIDTH); - // Keep the tail visible as text streams past the bottom. - const firstLine = Math.max(0, wrapped.length - maxLines); - for (let index = firstLine; index < wrapped.length; index++) { - image.drawText(font, left, textTop + (index - firstLine) * 16, wrapped[index]!, 235); - } - - if (inMenu) { - const rows = ["Follow-up", "Done"]; - const menuTop = top + DIALOG_H - MENU_ROWS * menuRowH - 2; - for (let i = 0; i < rows.length; i++) { - const rowY = menuTop + i * menuRowH; - const selected = i === this.menuIndex; - if (selected) { - drawSelectionHighlight(image, left - 4, rowY - 2, DIALOG_W - 24, menuRowH - 2, true, 6); - } - image.drawText(font, left + 4, rowY + 2, rows[i]!, selected ? 255 : 200); - } - } else { - image.drawText(font, left, top + DIALOG_H - 14, `${GESTURE_DOUBLE_CLICK} cancel`, 110 - font.lineHeight); - } + paintInputDialog(image, { + title: this.phase === "thinking" ? "Assistant ●" : "Assistant", + status: this.status, + statusValue: this.phase === "error" ? 200 : 130, + text: this.replyText, + menu: inMenu ? this.menu : null, + hint: inMenu ? undefined : `${GESTURE_DOUBLE_CLICK} cancel`, + }); return image; } @@ -140,7 +94,7 @@ export class AssistantLayer implements Layer { this.callbacks.onCancel(); this.phase = "done"; this.status = "Cancelled"; - this.menuIndex = 0; + this.menu.select(0); this.actions.requestRender(); } return; @@ -148,15 +102,12 @@ export class AssistantLayer implements Layer { // done / error: the Follow-up / Done menu. switch (event.type) { case "scroll-up": - this.menuIndex = (this.menuIndex + MENU_ROWS - 1) % MENU_ROWS; - this.actions.requestRender(); - return; case "scroll-down": - this.menuIndex = (this.menuIndex + 1) % MENU_ROWS; + void this.menu.handleInput(event); this.actions.requestRender(); return; case "click": - if (this.menuIndex === 0) { + if (this.menu.selectedIndex === FOLLOW_UP_ROW) { this.callbacks.onFollowUp(); } else { this.callbacks.onClose(); diff --git a/app/ui/shell/input-dialog.ts b/app/ui/shell/input-dialog.ts index 17d89fed..ef4956c2 100644 --- a/app/ui/shell/input-dialog.ts +++ b/app/ui/shell/input-dialog.ts @@ -1,13 +1,13 @@ import { G2_LENS_WIDTH, type GrayImage } from "../../graphics/image"; import { wrapText, truncateText } from "../../graphics/textwrap"; import { getDefaultSmallFont } from "../../graphics/ui-fonts"; -import { drawSelectionHighlight } from "../menu"; +import { Menu, type MenuDrawArgs } from "../menu-core"; import { listRowHeight } from "../metrics"; import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry"; /** - * The shared look of the shell's text-entry dialogs (voice input and phone - * keyboard input): a solid box over whatever is on screen with a title line, + * The shared look of the shell's text dialogs (voice input, phone keyboard + * input, and the assistant's reply): a solid box over whatever is on screen with a title line, * a status line, the message so far, and either a menu of destinations at * the bottom or a gesture hint. */ @@ -19,6 +19,14 @@ const DIALOG_W = G2_LENS_WIDTH - 80; const DIALOG_MARGIN_Y = 28; const DIALOG_H = MIN_WINDOW_HEIGHT - 2 * DIALOG_MARGIN_Y; const TEXT_MAX_WIDTH = DIALOG_W - 32; +const TEXT_LEFT = DIALOG_X + 16; +// Menu row boxes: 4px left of the text column, 2px shorter than the row +// pitch, with each row's label inset 8px / 4px into its box. +const MENU_X = TEXT_LEFT - 4; +const MENU_W = DIALOG_W - 24; +const MENU_ROW_GAP = 2; +const MENU_LABEL_INSET_X = 8; +const MENU_LABEL_INSET_Y = 4; /** Dialog top edge; band-relative, so computed per paint. */ function dialogY(): number { @@ -31,20 +39,47 @@ export type InputDialogRow = { dim: boolean; }; -export type InputDialogContent = { +export type InputDialogContent = { title: string; status: string; + /** Gray level of the status line. Default 130. */ + statusValue?: number; /** The message body (a placeholder when nothing has been captured yet). */ text: string; - /** Menu rows along the bottom edge; empty for no menu. */ - rows: readonly InputDialogRow[]; - selectedRow: number; + /** + * Menu along the bottom edge (see createInputDialogMenu), or null for none. + * Height is reserved for every item. + */ + menu: Menu | null; /** Gesture hint drawn along the bottom edge when there is no menu. */ hint?: string; }; +/** + * A wrapping menu of dialog rows, laid out and drawn the way paintInputDialog + * expects. The owning layer keeps it across paints (so the selection sticks), + * refreshes its rows with setItems, forwards scroll events to it, and hands + * it to paintInputDialog while the menu is showing. + */ +export function createInputDialogMenu(items: readonly T[] = [], selectedIndex = 0): Menu { + return new Menu({ + items, + selectedIndex, + wrap: true, + rowGap: MENU_ROW_GAP, + highlight: { radius: 6 }, + getHeight: () => listRowHeight(getDefaultSmallFont()), + draw: drawMenuRow, + }); +} + +function drawMenuRow({ image, item, x, y, selected }: MenuDrawArgs): void { + const value = item.dim ? 90 : selected ? 255 : 200; + image.drawText(getDefaultSmallFont(), x + MENU_LABEL_INSET_X, y + MENU_LABEL_INSET_Y, item.label, value); +} + /** Paint the dialog onto `image` (an already-painted canvas of the layers below). */ -export function paintInputDialog(image: GrayImage, content: InputDialogContent): void { +export function paintInputDialog(image: GrayImage, content: InputDialogContent): void { const font = getDefaultSmallFont(); const menuRowH = listRowHeight(font); const top = dialogY(); @@ -54,14 +89,14 @@ export function paintInputDialog(image: GrayImage, content: InputDialogContent): image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1); image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90); - const left = DIALOG_X + 16; + const left = TEXT_LEFT; image.drawText(font, left, top + 12, content.title, 220); - image.drawText(font, left, top + 30, truncateText(font, content.status, TEXT_MAX_WIDTH), 130); + image.drawText(font, left, top + 30, truncateText(font, content.status, TEXT_MAX_WIDTH), content.statusValue ?? 130); - const rows = content.rows; - const hasMenu = rows.length > 0; + const menu = content.menu; + const rowCount = menu?.items.length ?? 0; // Reserve space for the actual number of rows this menu has. - const textBottom = hasMenu ? top + DIALOG_H - rows.length * menuRowH - 8 : top + DIALOG_H - 8; + const textBottom = rowCount > 0 ? top + DIALOG_H - rowCount * menuRowH - 8 : top + DIALOG_H - 8; const textTop = top + 56; const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0); @@ -73,17 +108,10 @@ export function paintInputDialog(image: GrayImage, content: InputDialogContent): image.drawText(font, left, textTop + (index - firstLine) * 16, wrapped[index]!, 235); } - if (hasMenu) { - const menuTop = top + DIALOG_H - rows.length * menuRowH - 2; - for (let i = 0; i < rows.length; i++) { - const rowY = menuTop + i * menuRowH; - const selected = i === content.selectedRow; - if (selected) { - drawSelectionHighlight(image, left - 4, rowY - 2, DIALOG_W - 24, menuRowH - 2, true, 6); - } - const row = rows[i]!; - image.drawText(font, left + 4, rowY + 2, row.label, row.dim ? 90 : selected ? 255 : 200); - } + if (menu && rowCount > 0) { + // Row boxes are one pitch apart, the last ending 6px above the dialog's bottom edge. + const menuTop = top + DIALOG_H - rowCount * menuRowH - 4; + menu.paint(image, { x: MENU_X, y: menuTop, width: MENU_W, height: rowCount * menuRowH - MENU_ROW_GAP }, true); } else if (content.hint) { image.drawText(font, left, top + DIALOG_H - 14, content.hint, 110 - font.lineHeight); } diff --git a/app/ui/shell/keyboard-input.ts b/app/ui/shell/keyboard-input.ts index 22f51014..b8952070 100644 --- a/app/ui/shell/keyboard-input.ts +++ b/app/ui/shell/keyboard-input.ts @@ -1,9 +1,13 @@ import { type GrayImage } from "../../graphics/image"; import { type InputEvent } from "../gestures"; import { Layer, type LayerActions, type LayerContext } from "../layers"; -import { paintInputDialog } from "./input-dialog"; +import { type Menu } from "../menu-core"; +import { createInputDialogMenu, paintInputDialog, type InputDialogRow } from "./input-dialog"; import { type VoiceSendTarget } from "./voice-input"; +/** A menu row: a send target, or Discard (no target). */ +type KeyboardMenuRow = InputDialogRow & { target?: VoiceSendTarget }; + /** * The phone side's handle on an open keyboard-input dialog: the phone types * into it and picks where the text goes. The layer itself implements this; @@ -46,7 +50,7 @@ export type KeyboardInputLayerOptions = { */ export class KeyboardInputLayer implements Layer, KeyboardInputSession { private text = ""; - private menuIndex: number; + private readonly menu: Menu; private closed = false; private readonly actions: LayerActions; @@ -62,7 +66,7 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession { this.sendTargets = options.sendTargets; const defaultIndex = options.defaultTargetIndex ?? 0; this.defaultTargetIndex = Math.min(Math.max(0, defaultIndex), Math.max(0, this.sendTargets.length - 1)); - this.menuIndex = this.defaultTargetIndex; + this.menu = createInputDialogMenu(this.menuRows(), this.defaultTargetIndex); } get targets(): ReadonlyArray<{ id: string; label: string }> { @@ -76,8 +80,7 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession { } send(): void { - const row = this.menuRows()[this.menuIndex]; - const target = row?.target ?? this.sendTargets[this.defaultTargetIndex]; + const target = this.menu.selectedItem?.target ?? this.sendTargets[this.defaultTargetIndex]; if (target) this.sendToTarget(target); } @@ -101,9 +104,9 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession { } /** The menu rows: one per send target, then Discard. */ - private menuRows(): Array<{ label: string; dim: boolean; target?: VoiceSendTarget }> { + private menuRows(): KeyboardMenuRow[] { const hasText = this.text.trim().length > 0; - const rows: Array<{ label: string; dim: boolean; target?: VoiceSendTarget }> = []; + const rows: KeyboardMenuRow[] = []; for (const target of this.sendTargets) { rows.push({ label: target.label, dim: !hasText, target }); } @@ -113,29 +116,26 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession { paint(_ctx: LayerContext, paintBelow: () => GrayImage): GrayImage { const image = paintBelow(); + this.menu.setItems(this.menuRows()); paintInputDialog(image, { title: "Keyboard", status: "Type on the phone", text: this.text || "(nothing typed yet)", - rows: this.menuRows(), - selectedRow: this.menuIndex, + menu: this.menu, }); return image; } handleInput(event: InputEvent, _ctx: LayerContext): void { - const rowCount = this.menuRows().length; + this.menu.setItems(this.menuRows()); switch (event.type) { case "scroll-up": - this.menuIndex = (this.menuIndex + rowCount - 1) % rowCount; - this.actions.requestRender(); - return; case "scroll-down": - this.menuIndex = (this.menuIndex + 1) % rowCount; + void this.menu.handleInput(event); this.actions.requestRender(); return; case "click": { - const row = this.menuRows()[this.menuIndex]; + const row = this.menu.selectedItem; if (!row) return; if (row.target) { this.sendToTarget(row.target); diff --git a/app/ui/shell/voice-input.ts b/app/ui/shell/voice-input.ts index 2e8832fe..e96bc8ee 100644 --- a/app/ui/shell/voice-input.ts +++ b/app/ui/shell/voice-input.ts @@ -4,7 +4,8 @@ import { refineDictation, type AnthropicStreamHandle } from "../../native/anthro import { anthropicApiKeySetting } from "../dashboard-settings"; import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, gestureHints, type InputEvent } from "../gestures"; import { Layer, type LayerActions, type LayerContext } from "../layers"; -import { paintInputDialog } from "./input-dialog"; +import { type Menu } from "../menu-core"; +import { createInputDialogMenu, paintInputDialog, type InputDialogRow } from "./input-dialog"; // After native recognition finishes, a cloud final can still trail in. const FOLLOWUP_FINALIZE_TIMEOUT_MS = 1200; @@ -16,6 +17,9 @@ const FOLLOWUP_FINALIZE_TIMEOUT_MS = 1200; */ type VoicePhase = "capturing" | "menu" | "continuing" | "refining"; +/** A menu row; dim rows still take clicks, and onSelect decides what they do. */ +type VoiceMenuRow = InputDialogRow & { onSelect: () => void }; + /** * A destination the captured text can be sent to. The shell supplies these per * entry point: "Send to Assistant" (hand off to the voice assistant) and/or @@ -84,7 +88,8 @@ export class VoiceInputLayer implements Layer { private stopGeneration = 0; private acceptingTranscript = true; private refineHandle: AnthropicStreamHandle | null = null; - private menuIndex = 0; + /** The send / Continue / Discard menu; its rows are rebuilt on every paint and input. */ + private readonly menu: Menu; /** Auto-send (wakeword skip-confirmation) is waiting to fire. */ private pendingAutoSend = false; private autoSendTimer: ReturnType | null = null; @@ -111,7 +116,7 @@ export class VoiceInputLayer implements Layer { this.autoSend = options.autoSend ?? false; const defaultIndex = options.defaultTargetIndex ?? 0; this.defaultTargetIndex = Math.min(Math.max(0, defaultIndex), Math.max(0, this.sendTargets.length - 1)); - this.menuIndex = this.defaultTargetIndex; + this.menu = createInputDialogMenu(this.menuRows(), this.defaultTargetIndex); } startCapture(): void { @@ -221,11 +226,11 @@ export class VoiceInputLayer implements Layer { } /** The menu rows: one per send target, then Continue, then Discard. */ - private menuRows(): Array<{ label: string; dim: boolean; onSelect: () => void }> { + private menuRows(): VoiceMenuRow[] { const text = this.displayText().trim(); const hasText = text.length > 0 && !this.stoppingCapture; const hasLlmKey = anthropicApiKeySetting.get().trim().length > 0; - const rows: Array<{ label: string; dim: boolean; onSelect: () => void }> = []; + const rows: VoiceMenuRow[] = []; for (const target of this.sendTargets) { rows.push({ label: target.label, @@ -251,12 +256,12 @@ export class VoiceInputLayer implements Layer { paint(_ctx: LayerContext, paintBelow: () => GrayImage): GrayImage { const image = paintBelow(); const inMenu = this.phase === "menu"; + if (inMenu) this.menu.setItems(this.menuRows()); paintInputDialog(image, { title: this.capturing && this.listening ? "Voice ●" : "Voice", status: this.stoppingCapture ? "Finishing transcription..." : this.status, text: this.displayText() || this.placeholderText(), - rows: inMenu ? this.menuRows() : [], - selectedRow: this.menuIndex, + menu: inMenu ? this.menu : null, hint: inMenu ? undefined : this.hintText(), }); return image; @@ -290,21 +295,16 @@ export class VoiceInputLayer implements Layer { } private handleMenuInput(event: InputEvent): void { - const rowCount = this.menuRows().length; + this.menu.setItems(this.menuRows()); switch (event.type) { case "scroll-up": - this.menuIndex = (this.menuIndex + rowCount - 1) % rowCount; - this.actions.requestRender(); - return; case "scroll-down": - this.menuIndex = (this.menuIndex + 1) % rowCount; + void this.menu.handleInput(event); this.actions.requestRender(); return; - case "click": { - const row = this.menuRows()[this.menuIndex]; - row?.onSelect(); + case "click": + this.menu.selectedItem?.onSelect(); return; - } case "double-click": this.dismiss(); return; @@ -397,7 +397,7 @@ export class VoiceInputLayer implements Layer { this.finalizedText = text; this.liveText = ""; this.phase = "menu"; - this.menuIndex = 0; + this.menu.select(0); this.status = status; this.actions.requestRender(); } diff --git a/tests/evenhub-install-performance.test.cjs b/tests/evenhub-install-performance.test.cjs index 7422183e..c01e53e0 100644 --- a/tests/evenhub-install-performance.test.cjs +++ b/tests/evenhub-install-performance.test.cjs @@ -44,7 +44,7 @@ test('store install releases serialized input before download and permission app const download = new Promise(resolve => { completeDownload = resolve; }); const manifest = { name: 'Test', packageId: 'test', permissions: [{ name: 'network' }], privacyPolicyUrl: '' }; const load = loader({}, { - '../../graphics/ui-fonts': {}, '../../graphics/image': {}, '../../graphics/textwrap': {}, '../../ui/menu': {}, '../files/text-viewer': {}, '../../ui/metrics': {}, + '../../graphics/ui-fonts': {}, '../../graphics/image': {}, '../../graphics/textwrap': {}, '../../ui/menu-core': require('../.test-build/app/ui/menu-core.js'), '../files/text-viewer': {}, '../../ui/metrics': {}, './even-api': { evenHubApi: { getStoreAppDetail: async () => null, downloadApp: () => download } }, './installed-apps': { getInstalledEvenHubApp: () => null, readEvenHubPackageManifestBytes: () => manifest, readEvenHubPackageManifest: () => null, installedEvenHubPackagePath: () => '', installedEvenHubAppId: id => id, diff --git a/tests/evenhub-signin.test.cjs b/tests/evenhub-signin.test.cjs index 6350a6fe..55b19801 100644 --- a/tests/evenhub-signin.test.cjs +++ b/tests/evenhub-signin.test.cjs @@ -26,7 +26,8 @@ const loadStoreLayer = () => { '../../graphics/textwrap': { truncateText: (_f, text) => text, wrapText: (_f, text) => [text] }, '../../util/numeric-util': { clamp: (v, lo, hi) => Math.min(hi, Math.max(lo, v)) }, '../../ui/gestures': { GESTURE_CLICK: 'click' }, - '../../ui/menu': { drawListScrollbar() {}, drawSelectionHighlight() {}, scrollToKeepSelectionVisible() {} }, + '../../ui/menu': { drawSelectionHighlight() {} }, + '../../ui/menu-core': require('../.test-build/app/ui/menu-core.js'), '../../ui/shell/shell': { shell: { yieldFocusToSidebar() {} } }, '../../ui/metrics': { lineStep: () => 12 }, '../../ui/dashboard-settings': { diff --git a/tests/ios-terminal-input.test.cjs b/tests/ios-terminal-input.test.cjs index e58e02ce..df6e1138 100644 --- a/tests/ios-terminal-input.test.cjs +++ b/tests/ios-terminal-input.test.cjs @@ -3,6 +3,7 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const vm = require('node:vm'); const ts = require('typescript'); +const { Menu } = require('../.test-build/app/ui/menu-core.js'); function load(file, context) { const sandbox = { exports: {}, ...context }; vm.runInNewContext(ts.transpileModule(fs.readFileSync(file, 'utf8'), { @@ -23,7 +24,9 @@ test('iOS Type Into App submits UTF-8 terminal text and delays Enter at the byte client.handleMessage(JSON.stringify({ type: 'connect', command: 'test' })); const { VoiceInputLayer } = load('app/ui/shell/voice-input.ts', { require: id => id.includes('voice-control') ? { voiceControlBridge: { stop() {} } } - : id.includes('dashboard-settings') ? { anthropicApiKeySetting: { get: () => '' } } : {}, + : id.includes('dashboard-settings') ? { anthropicApiKeySetting: { get: () => '' } } + : id.includes('input-dialog') ? { createInputDialogMenu: (items, selectedIndex) => + new Menu({ items, selectedIndex, wrap: true, getHeight: () => 1, draw() {} }) } : {}, global: { isIOS: true }, }); for (const text of ['hello terminal', 'café π 🔋', 'line one\n第二行', '']) { diff --git a/tests/menu-core.test.cjs b/tests/menu-core.test.cjs index 01b4cc24..ce64f813 100644 --- a/tests/menu-core.test.cjs +++ b/tests/menu-core.test.cjs @@ -238,3 +238,51 @@ test('the scrollbar tracks the pixel scroll fraction', () => { short.menu.drawScrollbar(short.image, 95, 5, 60); assert.equal(short.image.getPixel(95, 5), 0, 'no scrollbar when the content fits'); }); + +test('a menu created empty starts on the first selectable item once items arrive', () => { + const { menu } = stringMenu({ items: [], isSelectable: (item) => !item.startsWith('Group') }); + assert.equal(menu.selectedIndex, null); + menu.setItems(['Group', 'a', 'b']); + assert.equal(menu.selectedIndex, 1, 'skips a leading heading'); + menu.setItems([]); + assert.equal(menu.selectedIndex, null); + menu.setItems(['x', 'y']); + assert.equal(menu.selectedIndex, 0, 'emptying and refilling starts over at the top'); +}); + +test('an explicit deselection survives setItems until the user or caller selects', async () => { + const { menu } = stringMenu({ items: [] , selectedIndex: null }); + menu.setItems(['a', 'b']); + assert.equal(menu.selectedIndex, null, 'constructed with no selection'); + menu.select(1); + menu.setItems(['a', 'b', 'c'], null); + menu.setItems(['a', 'b', 'c', 'd']); + assert.equal(menu.selectedIndex, null, 'setItems without an index keeps the deselection'); + await menu.handleInput({ type: 'scroll-down' }); + assert.equal(menu.selectedIndex, 0); + menu.setItems([]); + menu.setItems(['p', 'q']); + assert.equal(menu.selectedIndex, 0, 'scrolling ended the deselection'); +}); + +test('setItems never leaves the viewport scrolled past the end of the list', () => { + // Box 60px, rows 20px: a 3-row list fits, so it must sit at the top. + const { menu, paint } = stringMenu({ items: ['b', 'c', 'd'] }); + menu.select(2); + paint(); + assert.equal(menu.scrollTop, 0); + menu.setItems(['a', 'b', 'c'], 2); + assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c'], 'a row sorted in above stays visible'); + assert.equal(menu.scrollTop, 0); + // The selected row at the top of a scrolled viewport loses the rows below it: + // keeping its on-screen position would leave a gap, so pull back to show the end. + const long = stringMenu({ items: ['a', 'b', 'c', 'd', 'e', 'f', 'g'] }); + long.menu.select(6); + long.paint(); + long.menu.select(4); + long.paint(); + assert.equal(long.menu.scrollTop, 80, 'e is the top row'); + long.menu.setItems(['a', 'b', 'c', 'd', 'e'], 4); + assert.deepEqual(long.paint().map((r) => r.item), ['c', 'd', 'e']); + assert.equal(long.menu.scrollTop, 40); +}); diff --git a/tests/menu-highlight-motion.test.cjs b/tests/menu-highlight-motion.test.cjs index ca561f4b..0684b5d0 100644 --- a/tests/menu-highlight-motion.test.cjs +++ b/tests/menu-highlight-motion.test.cjs @@ -5,16 +5,17 @@ const { GrayImage } = require('../.test-build/app/graphics/image.js'); const { encodePresentation, readPresentation, paintPresentation } = require('../.test-build/app/graphics/presentation-wire.js'); test('highlight animates only navigation that preserves the scroll window', () => { + const D = MENU_HIGHLIGHT_DURATION_MS; const motion = new MenuHighlightMotion(); assert.equal(motion.paint(0, 0, 10, 20, 100, 20, 0), undefined); motion.navigate(0, false); const moved = motion.paint(1, 0, 10, 40, 100, 20, 100); assert.equal(moved.dx, 0); assert.equal(moved.dy, -20); - assert.equal(moved.durationMs, 300); - assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 250).token, moved.token); + assert.equal(moved.durationMs, D); + assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 100 + D / 4).token, moved.token); motion.navigate(1, false); - const next = motion.paint(2, 0, 10, 60, 100, 20, 250); + const next = motion.paint(2, 0, 10, 60, 100, 20, 100 + D / 2); assert.equal(next.dy, -30, 'continue from the halfway position'); motion.navigate(2, false); assert.equal(motion.paint(3, 1, 10, 60, 100, 20, 400), undefined, 'scroll snaps'); @@ -22,8 +23,8 @@ test('highlight animates only navigation that preserves the scroll window', () = assert.equal(motion.paint(0, 0, 10, 20, 100, 20, 500), undefined, 'wrap snaps'); motion.navigate(0, false); motion.paint(1, 0, 10, 40, 100, 20, 600); - assert.ok(motion.paint(1, 0, 10, 40, 100, 20, 899)); - assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 900), undefined, 'finished after 300 ms'); + assert.ok(motion.paint(1, 0, 10, 40, 100, 20, 600 + D - 1)); + assert.equal(motion.paint(1, 0, 10, 40, 100, 20, 600 + D), undefined, `finished after ${D} ms`); assert.equal(motion.paint(2, 0, 10, 60, 100, 20, 1200), undefined, 'programmatic changes snap'); }); diff --git a/tests/navigate-worker.test.cjs b/tests/navigate-worker.test.cjs index 319234da..2cd297c9 100644 --- a/tests/navigate-worker.test.cjs +++ b/tests/navigate-worker.test.cjs @@ -31,6 +31,7 @@ function fixture() { '../compass/calibration': { calibrateHeading: value => value + 5, normalizeHeading: value => (value + 360) % 360 }, '../../native/frame-timings': { startFrame: () => 1, finishFrame() {}, logFrame() {}, span: (_id, _name, fn) => fn(), runWithFrame: (_id, fn) => fn() }, '../../native/active-display': { getActiveDisplay: () => null }, + '../../ui/menu-core': require('../.test-build/app/ui/menu-core.js'), '../../ui/window-menu': { WindowMenu: class { paint() { return []; } isOpen() { return false; } resize() {} } }, '../../graphics/plane': { planesFingerprint: () => 'frame' }, '../../native/mapbox': { diff --git a/tests/row-metrics.test.cjs b/tests/row-metrics.test.cjs new file mode 100644 index 00000000..7a2adc81 --- /dev/null +++ b/tests/row-metrics.test.cjs @@ -0,0 +1,87 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); +const ts = require('typescript'); +const { GrayImage } = require('../.test-build/app/graphics/image.js'); +const { textInkBounds, textInkHeight, centeredTextY, tightRowHeight } = require('../.test-build/app/ui/metrics.js'); +const { Menu } = require('../.test-build/app/ui/menu-core.js'); + +function load(file) { + const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8'); + const context = { exports: {}, require: () => ({}) }; + vm.runInNewContext(ts.transpileModule(source, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText, context); + return context.exports; +} +const { BdfFont } = load('app/graphics/bdffont.ts'); +const terminus = (size) => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8')); +const SIZES = [12, 14, 16, 18, 20, 22, 24]; + +/** A font whose glyphs sit `leading` px below the line top and end `trim` px above its bottom. */ +function leadingFont(lineHeight, leading, trim) { + const ascent = lineHeight - 3; + const inkHeight = lineHeight - leading - trim; + return { + lineHeight, ascent, descent: 3, + // bbxY is the ink bottom's height above the baseline (negative below it). + getGlyph: () => ({ bbxHeight: inkHeight, bbxY: ascent - leading - inkHeight, bbxWidth: 1, bbxX: 0 }), + }; +} + +test('Terminus ink fills its line box, so the compact row keeps its 12px pitch of 16', () => { + for (const size of SIZES) { + const font = terminus(size); + assert.deepEqual(textInkBounds(font), { top: 0, bottom: font.lineHeight }, `ter-u${size}n`); + assert.equal(tightRowHeight(font), font.lineHeight + 4); + } + assert.equal(tightRowHeight(terminus(12)), 16); +}); + +test('ink bounds follow the rendered glyphs, not the line box', () => { + const font = leadingFont(21, 4, 1); + assert.deepEqual(textInkBounds(font), { top: 4, bottom: 20 }); + assert.equal(textInkHeight(font), 16); + assert.equal(tightRowHeight(font), 20); + // Centered in a 19px box: 3 spare pixels, 1 above; the line top sits 3 above the box to put ink at +1. + assert.equal(centeredTextY(font, 100, 19), 100 + 1 - 4); +}); + +test('fonts without glyph access fall back to the line box', () => { + const font = { lineHeight: 14, ascent: 11, descent: 3 }; + assert.deepEqual(textInkBounds(font), { top: 0, bottom: 14 }); + assert.equal(centeredTextY(font, 10, 20), 13); +}); + +test('centered text keeps at least a pixel of clearance inside a compact selection box', () => { + for (const font of [...SIZES.map(terminus), leadingFont(21, 4, 1), leadingFont(17, 0, 2)]) { + const box = tightRowHeight(font) - 1; + const offset = centeredTextY(font, 0, box); + const { top, bottom } = textInkBounds(font); + assert.ok(offset + top >= 1, `top clearance at lineHeight ${font.lineHeight}`); + assert.ok(offset + bottom <= box - 1, `bottom clearance at lineHeight ${font.lineHeight}`); + } +}); + +test('a selected compact row keeps every inked pixel of its text', () => { + const label = 'Jgpqy (É|Å) 0189'; + const inked = (image) => image.withDrawsBaked().pixels.reduce((n, v) => n + (v !== 0 ? 1 : 0), 0); + for (const size of SIZES) { + const font = terminus(size); + const reference = new GrayImage(400, 80); + reference.drawText(font, 0, 20, label, 255); + const menu = new Menu({ + items: [label], + rowGap: 1, + getHeight: () => tightRowHeight(font), + draw: ({ image, item, x, y, height }) => image.drawText(font, x + 6, centeredTextY(font, y, height), item, 255), + }); + const page = new GrayImage(420, 120); + menu.paint(page, { x: 4, y: 4, width: 400, height: 100 }, true); + const selection = page.draws.find((draw) => draw.presentation); + assert.ok(selection, `ter-u${size}n selection`); + assert.equal(inked(selection.source), inked(reference), `ter-u${size}n keeps all ink`); + } +}); diff --git a/tests/settings-panel.test.cjs b/tests/settings-panel.test.cjs new file mode 100644 index 00000000..dcfbabac --- /dev/null +++ b/tests/settings-panel.test.cjs @@ -0,0 +1,112 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); +const ts = require('typescript'); + +function load(file, modules) { + const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8'); + const context = { exports: {}, console, require(name) { assert.ok(name in modules, name); return modules[name]; } }; + vm.runInNewContext(ts.transpileModule(source, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText, context); + return context.exports; +} + +const graphics = require('../.test-build/app/graphics/image.js'); +const metrics = require('../.test-build/app/ui/metrics.js'); +const menuCore = require('../.test-build/app/ui/menu-core.js'); +const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} }); +const font = BdfFont.parse(fs.readFileSync(path.join(__dirname, '../app/fonts/terminus/ter-u12n.bdf'), 'utf8')); +const textwrap = load('app/graphics/textwrap.ts', {}); +const fonts = { getDefaultSmallFont: () => font }; +const menu = load('app/ui/menu.ts', { + '../graphics/image': graphics, '../graphics/textwrap': textwrap, '../graphics/ui-fonts': fonts, + '../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, './gestures': {}, + './metrics': metrics, './menu-core': menuCore, +}); +let yields = 0; +const { SettingsPanelLayer } = load('app/ui/dashboard/settings-panel.ts', { + '../../graphics/ui-fonts': fonts, '../../graphics/image': graphics, '../../graphics/textwrap': textwrap, + '../gestures': {}, '../layers': {}, '../menu': menu, '../menu-core': menuCore, '../metrics': metrics, + '../shell/shell': { shell: { yieldFocusToSidebar: () => yields++ } }, +}); + +/** A panel over three sections; records which item callbacks fire. */ +function panel() { + const selected = []; + const item = (label, extra = {}) => ({ label, onSelect: () => selected.push(label), ...extra }); + const layer = new SettingsPanelLayer([ + { label: 'Display', items: [item('Brightness'), item('Font'), item('Off', { disabled: true })] }, + { label: 'Voice', items: Array.from({ length: 20 }, (_, i) => item(`Voice ${i}`, { description: 'Help text for this option.' })) }, + { label: 'About', items: [], renderDetail: () => {} }, + ]); + const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 260 }), isFocused: () => true } }; + const input = (type) => layer.handleInput({ type, timestampMs: 0 }, ctx); + return { layer, input, paint: () => layer.paint(ctx), selected }; +} + +const selections = (image) => image.draws.filter((d) => d.kind === 'image' && d.presentation); + +test('the right column previews the section without a selection until focus enters it', async () => { + const p = panel(); + assert.equal(selections(p.paint()).length, 1, 'only the left column is highlighted'); + await p.input('click'); + const both = selections(p.paint()); + assert.equal(both.length, 2); + assert.equal(both[0].presentation.background, 0, 'left column shows an outline once focus moves right'); + assert.ok(both[1].x > 150, 'the right highlight lands in the right column'); + await p.input('click'); + assert.deepEqual(p.selected, ['Brightness']); + await p.input('double-click'); + assert.equal(selections(p.paint()).length, 1, 'back to a preview'); + const before = yields; + await p.input('double-click'); + assert.equal(yields, before + 1, 'double-click from the left column yields to the sidebar'); +}); + +test('moving between sections resets the right column to its top, unselected', async () => { + const p = panel(); + await p.input('scroll-down'); + await p.input('click'); + for (let i = 0; i < 15; i++) await p.input('scroll-down'); + p.paint(); + await p.input('double-click'); + await p.input('scroll-up'); + await p.input('scroll-down'); + assert.equal(selections(p.paint()).length, 1); + await p.input('click'); + await p.input('click'); + assert.deepEqual(p.selected, ['Voice 0'], 'entering starts at the first item'); +}); + +test('watch swipes move within a column, wrap, and skip disabled activation', async () => { + const p = panel(); + await p.input('swipe-up'); + await p.input('click'); + assert.deepEqual(p.selected, [], 'About has no items, so focus stays in the left column'); + await p.input('swipe-down'); + await p.input('swipe-right'); + await p.input('swipe-up'); + await p.input('swipe-right'); + assert.deepEqual(p.selected, [], 'the wrapped-to item is disabled'); + await p.input('swipe-up'); + await p.input('swipe-right'); + assert.deepEqual(p.selected, ['Font']); +}); + +test('the selected row stays clear of its description band', async () => { + const p = panel(); + await p.input('scroll-down'); + await p.input('click'); + await p.input('scroll-up'); + const row = selections(p.paint())[1]; + const overlay = new graphics.GrayImage(576, 260); + p.layer.paintDescriptionOverlay(overlay, { stack: { getBaseSize: () => ({ width: 576, height: 260 }) } }); + let bandTop = -1; + for (let y = 0; y < 260 && bandTop < 0; y++) if (overlay.getPixel(300, y) !== 0) bandTop = y; + assert.ok(bandTop > 0, 'the band is drawn'); + assert.ok(row.y + row.source.height <= bandTop, `row ends at ${row.y + row.source.height}, band starts at ${bandTop}`); + assert.ok(row.y + row.source.height > bandTop - 30, 'the last item scrolled down to just above the band'); +}); diff --git a/tests/voice-finalization.test.cjs b/tests/voice-finalization.test.cjs index c656a94f..2d4e638a 100644 --- a/tests/voice-finalization.test.cjs +++ b/tests/voice-finalization.test.cjs @@ -4,6 +4,7 @@ const fs = require('node:fs'); const path = require('node:path'); const vm = require('node:vm'); const ts = require('typescript'); +const { Menu } = require('../.test-build/app/ui/menu-core.js'); function load(file, deps, globals = {}) { const exports = {}; @@ -27,7 +28,10 @@ function dialog({ autoSend = false, deferred = true, synchronousFinal, isIOS = f '../../native/anthropic': { refineDictation(options) { refinements.push(options); return { cancel() {} }; } }, '../dashboard-settings': { anthropicApiKeySetting: { get: () => 'key' } }, '../gestures': { gestureHints: () => '' }, - './input-dialog': { paintInputDialog(_image, options) { frame = options; } }, + './input-dialog': { + paintInputDialog(_image, options) { frame = options; }, + createInputDialogMenu: (items, selectedIndex) => new Menu({ items, selectedIndex, wrap: true, getHeight: () => 1, draw() {} }), + }, }, { global: { isIOS }, setTimeout(cb) { const id = ++timerId; timers.set(id, cb); return id; }, From 915f155819b2727d11ff4e91cf1701f7b1b020aa Mon Sep 17 00:00:00 2001 From: James Babcock Date: Thu, 24 Sep 2026 02:26:20 -0700 Subject: [PATCH 20/27] Add Glanceboard depth setting --- .../faceclaw/app/FaceclawBleCommunicator.kt | 2 + .../faceclaw/app/FaceclawPreviewCompositor.kt | 4 ++ CHANGELOG | 1 + app/apps/app-definition.ts | 2 + app/apps/glanceboard/glanceboard-app.ts | 4 +- app/apps/glanceboard/glanceboard-settings.ts | 25 +++++++ app/apps/glanceboard/index.ts | 2 + app/g2/firmware-compat.ts | 2 +- app/g2/firmware/cfw-patches.ts | 68 +++++++++---------- app/g2/glance-host.ts | 11 ++- app/g2/ios-preview-controller.ts | 1 + app/graphics/surface-compositor.ios.ts | 1 + app/graphics/surface-compositor.ts | 2 + app/native/faceclaw-communicator.ios.ts | 4 ++ app/native/faceclaw-communicator.ts | 10 +++ app/native/preview-display.ios.ts | 5 ++ app/native/preview-display.ts | 5 ++ .../faceclaw/app/g2protocol/DrawCallType.kt | 1 + .../faceclaw/app/g2protocol/DrawProtocol.kt | 16 ++++- .../g2protocol/session/GlassesSessionCore.kt | 3 + .../app/graphics/DisplayListRenderer.kt | 12 +++- .../com/faceclaw/app/graphics/ShellScene.kt | 7 +- .../app/graphics/SurfaceCompositor.kt | 28 +++++++- .../kotlin/com/faceclaw/app/IosNativeApi.kt | 2 + .../com/faceclaw/app/ble/IosGlassesSession.kt | 2 + tests/ios-glanceboard.test.cjs | 16 ++++- .../com/faceclaw/app/DisplayListTest.kt | 64 ++++++++++++++++- .../com/faceclaw/app/DrawExpressionTest.kt | 2 +- .../kotlin/com/faceclaw/app/DrawWireTest.kt | 10 ++- 29 files changed, 262 insertions(+), 50 deletions(-) diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt index d07ffde4..97d98665 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt @@ -291,6 +291,8 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre fun setSurfaceVisible(id: String, visible: Boolean) = core.setSurfaceVisible(id, visible) + fun setSurfaceDepth(id: String, depth: Int) = core.setSurfaceDepth(id, depth) + fun setScreenBlanked(blanked: Boolean) = core.setScreenBlanked(blanked) fun configureSurface(id: String?, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) = diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt index 570ad3f2..4f4c65fa 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawPreviewCompositor.kt @@ -87,6 +87,10 @@ class FaceclawPreviewCompositor(context: Context) { compositor.setSurfaceVisible(id, visible) } + fun setSurfaceDepth(id: String, depth: Int) { + compositor.setSurfaceDepth(id, depth) + } + /** Blank (screen off) or unblank the output; retained surface state survives. */ fun setScreenBlanked(blanked: Boolean) { compositor.setBlanked(blanked) diff --git a/CHANGELOG b/CHANGELOG index 4b57d7fb..1cf5da58 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ * Add tokens and faceclaw-input script, which allows using a CLI utility as an input device for the glasses * Navigate app: Add map-without-destination mode * Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space +* Glanceboard: Add distance setting ### iOS port: diff --git a/app/apps/app-definition.ts b/app/apps/app-definition.ts index 0f73ad9d..b2e69a01 100644 --- a/app/apps/app-definition.ts +++ b/app/apps/app-definition.ts @@ -54,6 +54,8 @@ export type GlanceboardProvider = { showOnLongPress: () => boolean; /** Whether the head-tilt wake goes to the board rather than the regular UI. */ showOnHeadTilt: () => boolean; + /** Stereo depth (firmware units; positive is nearer) while the board covers the screen. */ + depth: () => number; /** A fresh board; requestRender asks the host to repaint it. */ createBoard: (requestRender: () => void) => GlanceBoardInstance; }; diff --git a/app/apps/glanceboard/glanceboard-app.ts b/app/apps/glanceboard/glanceboard-app.ts index dd10e848..e6bc38f7 100644 --- a/app/apps/glanceboard/glanceboard-app.ts +++ b/app/apps/glanceboard/glanceboard-app.ts @@ -13,6 +13,7 @@ import { GlanceBoard } from "./board"; import { clearConflictingSlots, glanceboardEnabledSetting, + glanceDepthSetting, glanceLayout, glanceLayoutSetting, glanceShowLinesSetting, @@ -297,7 +298,7 @@ function openSlotPicker(ctx: LayerContext, slotIndex: number): void { openModalMenu(ctx, setting.label, items, Math.max(0, setting.values.indexOf(current))); } -/** Settings: layout, sleep gestures, duration, and slot lines. */ +/** Settings: layout, sleep gestures, duration, slot lines, and stereo depth. */ function openGlanceSettings(ctx: LayerContext): void { const items: MenuItem[] = [ enumSettingMenuItem(glanceLayoutSetting), @@ -305,6 +306,7 @@ function openGlanceSettings(ctx: LayerContext): void { toggleSettingMenuItem(glanceShowOnLongPressSetting), toggleSettingMenuItem(glanceShowOnHeadTiltSetting), toggleSettingMenuItem(glanceShowLinesSetting), + enumSettingMenuItem(glanceDepthSetting), ]; ctx.stack.push(new MenuLayer("Glanceboard settings", items, pageMenuLayout(ctx.stack.getBaseSize().width))); } diff --git a/app/apps/glanceboard/glanceboard-settings.ts b/app/apps/glanceboard/glanceboard-settings.ts index bcb13948..9478e695 100644 --- a/app/apps/glanceboard/glanceboard-settings.ts +++ b/app/apps/glanceboard/glanceboard-settings.ts @@ -103,6 +103,31 @@ export const glanceShowOnHeadTiltSetting = new ConfigSettingBoolean({ description: "Tilting your head up while asleep shows the Glanceboard instead of waking the regular UI.", }); +const DEPTH_VALUES = ["-64", "-48", "-32", "-16", "0", "16", "32", "48", "64"] as const; +export type GlanceDepth = (typeof DEPTH_VALUES)[number]; + +/** + * Stereo depth of the board, in the firmware's depth units: the lenses shift + * it by half this many pixels each, in opposite directions. + */ +export const glanceDepthSetting = new ConfigSettingEnum({ + id: "glanceboard-depth", + label: "Depth", + storageKey: "glanceboard.depth", + defaultValue: "0", + values: DEPTH_VALUES, + formatValue: (value) => { + const depth = Number(value); + return depth === 0 ? "0" : depth > 0 ? `+${depth} (nearer)` : `${depth} (farther)`; + }, + description: + "Moves the Glanceboard nearer (positive) or farther away (negative) by shifting it in opposite directions on the two lenses.", +}); + +export function glanceDepth(): number { + return Number(glanceDepthSetting.get()); +} + /** Hairlines between the board's slots. */ export const glanceShowLinesSetting = new ConfigSettingBoolean({ id: "glanceboard-show-lines", diff --git a/app/apps/glanceboard/index.ts b/app/apps/glanceboard/index.ts index 354bef25..65affdfa 100644 --- a/app/apps/glanceboard/index.ts +++ b/app/apps/glanceboard/index.ts @@ -3,6 +3,7 @@ import { GlanceBoard } from "./board"; import { createGlanceboardAppWindow, GLANCEBOARD_SURFACE_ID, GLANCEBOARD_WINDOW_ID } from "./glanceboard-app"; import { glanceboardEnabledSetting, + glanceDepth, glanceLayout, glanceShowOnHeadTiltSetting, glanceShowOnLongPressSetting, @@ -25,6 +26,7 @@ const glanceboardApp: AppDefinition = { tapTimeoutMs: glanceTapTimeoutMs, showOnLongPress: () => glanceShowOnLongPressSetting.get(), showOnHeadTilt: () => glanceShowOnHeadTiltSetting.get(), + depth: glanceDepth, createBoard: (requestRender) => new GlanceBoard(requestRender), }, }; diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index bc7e803e..943d7166 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -26,7 +26,7 @@ export type FirmwareInfo = { }; /** The Faceclaw firmware revision this build of the app needs. */ -export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 27; +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 28; const FACECLAW_PREFIX = "Faceclaw/"; const LEGACY_PREFIX = "EVENCFW"; diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index 214ae1f1..f5af85fd 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,12 +19,12 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "62ed330a71d6be45a4482e6007b00fc7f029a01d238f358f69ba992f83769590", + "outputSha256": "8dbb39ad4acaf430e889ff98fe698ccb54d55c19d90a4d7053ce0fb804adb11b", "patches": [ { "offset": 1045797, "old": "38b584b0", - "new": "5cf31db9", + "new": "5cf35fb9", "desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease" }, { @@ -36,49 +36,49 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1437923, "old": "fef788ff", - "new": "fcf22cfe", + "new": "fcf26efe", "desc": "cfw_ancs_event" }, { "offset": 1437951, "old": "fef7e8fb", - "new": "fcf266fb", + "new": "fcf2a8fb", "desc": "cfw_ancs_open" }, { "offset": 1437969, "old": "fef7e7fb", - "new": "fcf27dfb", + "new": "fcf2bffb", "desc": "cfw_ancs_close" }, { "offset": 1388387, "old": "39694d00", - "new": "41547d00", + "new": "c5547d00", "desc": "connection-bound ANCS EUS write callback" }, { "offset": 971497, "old": "fff717f8", - "new": "6ef34dfa", + "new": "6ef38ffa", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 971845, "old": "fef769ff", - "new": "6ef39ff9", + "new": "6ef3e1f9", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 979579, "old": "fdf74ef8", - "new": "6cf384fa", + "new": "6cf3c6fa", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 1428895, "old": "f8f76cfd", - "new": "fbf2c4fd", + "new": "fbf206fe", "desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)" }, { @@ -108,145 +108,145 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1248487, "old": "d4f712fb", - "new": "29f354fc", + "new": "29f396fc", "desc": "bl settings_send_wrapper (append caps field 100)" }, { "offset": 1246183, "old": "f5f7e2f8", - "new": "29f330fe", + "new": "29f372fe", "desc": "bl settings_decode_wrapper (Faceclaw lease field 101)" }, { "offset": 975219, "old": "02f083fc", - "new": "6bf39cfe", + "new": "6bf3defe", "desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)" }, { "offset": 975411, "old": "02f023fc", - "new": "6bf300ff", + "new": "6bf342ff", "desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)" }, { "offset": 975103, "old": "07f085fb", - "new": "6df356fa", + "new": "6df398fa", "desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)" }, { "offset": 830549, "old": "19f03efb", - "new": "90f305fc", + "new": "90f347fc", "desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)" }, { "offset": 830795, "old": "1ff071ff", - "new": "90f3befb", + "new": "90f300fc", "desc": "bl gesture_press (owned event 9 before stock menu gate)" }, { "offset": 830887, "old": "1ff043ff", - "new": "90f3b8fb", + "new": "90f3fafb", "desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)" }, { "offset": 831763, "old": "1ff08dfd", - "new": "90f3eef9", + "new": "90f330fa", "desc": "bl gesture_release (owned event 10 before stock menu gate)" }, { "offset": 1570209, "old": "7fb50600", - "new": "daf2e5bf", + "new": "dbf227b8", "desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline" }, { "offset": 1051545, "old": "f6f787f9", - "new": "54f3cdff", + "new": "55f30ff8", "desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)" }, { "offset": 1051861, "old": "f6f7e9f8", - "new": "54f32fff", + "new": "54f371ff", "desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)" }, { "offset": 1262237, "old": "d9f7d0fd", - "new": "25f365fd", + "new": "25f3a7fd", "desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)" }, { "offset": 1262337, "old": "d9f79efd", - "new": "25f333fd", + "new": "25f375fd", "desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)" }, { "offset": 1309405, "old": "67f02dff", - "new": "19f33dfe", + "new": "19f37ffe", "desc": "bl compass_decode_capture (sample-matched GAF diagnostics)" }, { "offset": 1307865, "old": "fff7c9fb", - "new": "1af3bbf9", + "new": "1af3fdf9", "desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)" }, { "offset": 1300937, "old": "00210170", - "new": "1bf3a1fe", + "new": "1bf3e3fe", "desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)" }, { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff78afc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f037f8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef757fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef70dfe0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f0ecfa0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf0f1fc48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf06bfc414602e0022084f8200350460c22fef714f894f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7e4ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf7b3ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf75dff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf0e7fbd8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf0adfd0bf081fd294630b9ffe50bf07cfd002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7fffd0fe04eea062141ea0b4141ea05633946624665460bf07bfb00281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af0a1fbd4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f213040af051f84ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b700af03ef8e05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f06aff059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f09cfe28461a21224609f019fd00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f08bfc854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f087fc706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f074fb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f01afc606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf793f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009508f0c4fa606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7e5fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009707f0d5ff002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009507f0b7ff606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009507f08aff606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f05fff606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf71dfa04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf7d9f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf783f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f07cfd019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f26c71c0f20001033079440b22f9f752fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f71afc0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f76bfb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f7c1fa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f29670c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f71ffc4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f733fc4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f74cfbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f76bfb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009503f01bfc3eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb004460020a4f8800347f64c60c2f207000068002a8a461abfc4f874030146d4f87413401ac4f87c03fdf763f8002800f00081d4f86803002800f0fb8004f081f9002800f0f6800646b4f86c0300284cd0a0f10109d4f87c034ff4a07100254ff4f0774ff4805bcde90d050df11808cde901152046494632464ff42073cdf818b007950c95cde90358009703f0c4fb002840f0cf80d4f8681330464ff41632f7f77cf9d4f87c034946cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906b50c95cdf81080009703f0a1fb002840f0ac809df8380094f88013084384f8800306e0d4f8681330464ff41632f7f751f94ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b07e000bf48f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168414548d04ff46d70fdf77bfe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8001f4945aad1bff35f8f00bf47e8000121b157e8001f4945f8d09fe7054604f0b3f8002d18bf002803d101208af8050022e0c5f860014ff001084ff4f07085f8648101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718af8058004e09af805008af8048030b14ff0ff300fb0bde8f08f0025cbe7204604f06ef900200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2045d259008784f780a4450ea072001f10204209002f05382ddf830c5ddf82ce5ddf8285542a8063000271790cde91d23944202f03e82601c904202f03a8220786178a61c40ea0121901b814229962a9102f22f82ddf83c2530a880e828401068ddf8341500283491a0f101012197cdf8ccc0116002f01d822a98002802f019822a98871c032f02f01482e678032e02f21082299890f80080f00703d104f1040a28e000bf2a9820f00100022802f0018294f804906579259849ea052b594630aa02f006fa002842f0f481ddf8340504f1060a012d34900dd8ddf83c05806948b14feadb0209f00701835c012505fa01f119438154022e04eb070b03d2ddf834052b9024e0da4503d0544614f9015b01e000255c4645f64d57c0f24607b847012808bf0135681e81b26e0800ebd130002d48bf4610b8470128ddf8340508bf76423118da45a2462b91349102f0b281b8f1040f00f39f80b8f1020f00f31581b8f1010f00f08d82b8f1020f42f0a281da4502f09f810af10100584502f09a810af10200584502f095810af10300584502f090810af10400584502f08b810af10500584502f086810af10600584502f081810af10700584502f07c810af10800584502f077810af10900584502f072810af10a00584502f06d810af10b00584502f068810af10c00584502f063810af10d00584502f05e810af10e00584542f059819af802009af800402f909af803009af801702e909af80500ddf8c0c02d909af80a009af804b028909af80b009af8063027909af80d009af807609af808909af809809af80c202690dde931a1ddf8cce044ea07254ff6fe708542cdf808c12c91cde943a1cdf814e100f055864ff6ff70854240f02d862598d0f868134ff4207043904ff4f07044904ff4a070459000f043be00bfb8f1060f00f30481b8f1050f00f04482b8f1060f42f00381da4502f000810af10100584502f0fb800af10200584502f0f6800af10300584502f0f1800af10400584502f0ec800af10500584502f0e7800af10600584502f0e2800af10700584502f0dd800af1080cabeb0c000828c2f0d6800af11000584542f0d1809af804009af8051050ea01261ebf9af806009af8071050ea012502f0c2809af800009af80120319940ea0224081bc2f0b880864202f2b5809af802009af80330329a40ea0327d01bc2f0ab80854202f2a880ddf83805002800f0f0873098339bcde901472b9fcdf814c0cde90365009703f002f800f0e2bfb8f1030f00f07382b8f1040f42f08d80bbeb0a0602f089800af10100584502f084802598002802f08080b01e0528c2f07c800af10700584542f077802598d0f86c01002802f071809af80110012902f26c809af8003043ea012250f82210002902f063800f1ab90742f05f806ff4403140f60f053944cff6fd75a942c2f05580384450f8081c914242f04f8050f80c1ca1f1011515f5803fc2f04780002802f0448050f8045c8d4242f03f80c7f54037b94202f23a80ddf83c75bf6947b1d20803f00703bd5c012404fa03f32b43bb54dde93049dde9327500223aab02f080f800284ff0000b08bf4ff0ff3b01f0a987ddf838050df1d808002801f0a287072e4ff0ff3b41f09d87002c01f09a87fcf7fdfc002840f0258301f091bfb8f1070f00f08a82b8f1080f41f0ff87ddf83c050021c06942ae3aaddde93079dde932844491cde93a0130462946cde942ab03f015f982463046294603f010f94499002941f06d87dde942218a4201f06887531c8b4201f06487931c8b4201f06087d31c8b4201f05c87131d8b4201f05887531d8b4201f05487931d8b4201f05087d31d8b4201f04c8702f108038b4241f04787117853784ff0ff3b51ea03212e9401f040879378d67853ea06232f9301f03987b1f5207f01f235872f9bb3f5f07f01f2308793792c970f2b269301f22a87d779102f2d9701f22587ddf83c3527903b981e6a92f804c03043ddf838655279002e186201f087872b984ff0000b084440428245c1f20e872b98a9eb0000824581f208872f9846422798b042c1f202872798804541f3fe864cea0222b2eb510f28bf4a082f9bb2eb530f28bf5a081f92013a38bf5a461292424202eae075a8eb00029a42a8bf1a469542249281f2e2862b9a1f9f92447a00239207fb07f292001c9201eb0a0203294ff00001289238bf01212f9b0022032b38bf012211431b91591e1891991e159112992e9b4a00494389000f910af1010113912d9914920a0141ea011110916ff00801119201eb47012c9a169120eae07103fb012e4ff000080024cdf864a001f0fdbada4501f01687514611f8010b012801f21087309a00282c92319a2f92329a2e92339a2d9200f0d981594501f002870af10201594501f0fd860af10301594501f0f8860af10401594501f0f3860af10501594501f0ee860af10601594501f0e9860af10701594501f0e4860af10801594501f0df869af801109af802209af8043041ea022c9af803209af805609af8061042ea032746ea01269af807109af808200af109031a9341ea0221b8e1bbeb0a0801f0bf860af10100584501f0ba86a8f102000528c1f0b5860af10700584501f0b0862598002801f0ac860af108099af80740abeb0900a042c1f0a38609eb0400584541f09e862598d0f86c31002b01f098869af80100012801f293869af8001041ea002053f82020002a01f08a86d21a970741f086866ff4403740f60f061744cff6fd76b742c1f07c869e1856f8083c834241f0768656f80cbcabf1011313f5803fc1f06e86002e01f06b8656f8043c5b4541f06686c2f54032934501f26186ddf83c25926942b1c00801f00701135c012707fa01f119431154bbf1c10fc1f050863078012841f04c863098002c2f9031982e9032982d9033982c9000f0ee80a6f13f074d4602e0013c00f0e78015f8010b411e1f29f7d341b22029c1f2318607eb400117f81000497840ea0122c12ac1f027863046594642ab01f07dfe0028e2d101f01ebeabeb0a09b9f1050fc1f018860af105055d4501f013860af106079af80560abeb0700b042c1f00a86b819584541f0068630981b9031982c903298229033981a90aeb1002402e00134b44210d2385d01381e28f8d93819311b42aa3aab02f0b3f8002801f0eb8542980444b442eed3ddf83805002800f02f85b9f1050f01f0de851b98002801f0da85fcf7c9fa002801f0d5852d78a81d814541f0d08547f65420c2f207000668002e01f0c885307b717bb27bf37b40ea012040ea024040ea0363a3f1810010f1800fc1f0b885307c717cf27c40ea0120b17c40ea014040ea02600e90813810f5817f41f2a885002d4ff0000b0df1d8082e93159600f09b83ddf8b0904ff0000c00260ae000f1004042a941f824000136ae4204f1010c80f03b83b85d6446411e1e29efd9b819a91b3aaa434602f048f8002801f00a853a99369842aa0e4442f82400e5e7da4501f076850af10100584501f071850af10200584541f06c859af800009af8011030af40ea0121ddf83c058ccf0490ddf83805339e03902b98019602902598009702f0d9fd834601f0dfbcddf83805002800f09b840020b8f1080f4ff0ff3b4290c1f0d2842f98002801f0ce84fcf731fa002801f0c7849af8075005f10800804541f0c0849af800009af801609af8068040ea062400f083bc594501f029850af10201594501f024850af10301594501f01f850af10401594501f01a859af802209af8011057009af803209af804304fea810c0af1050196001a915900002e1b9101f006851b99002901f002852f99b1eb0c02c1f0fd84964201f2fa842e99ca1bc1f0f6841b99914201f2f284002878d02b9800250ceb000280e048f2a351c0f24501bff32f8f88474ff29c50c2f229000668bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f0cb824ff46d70fdf760f8002801f04e844ff64c41cff6ff71002342180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fb14297d1bff35f8f42e80001002900f07c8252e8001fb142f6d08be72b9800250ceb0002c00706d1002a04d42f99b0188842d8bf01251a991b9babeb01001890ddf8380503fb06f8b0fa80f040092843c007199500231f900d4600202b90cdf870b0cdf8888012e02b98289908442b902398269981424ff0000088bf0120279b249d0343d80708bf0d44ddf88880d807279305d02b98804509d801f036bc00bf5d4500f05e832b98804540f25a83bbeb050001f02a8495f800e05fea1e1401d0012111e0012801f020846c780cb102210ae00428c1f0198495f802c0eb785cea032401f01284042126912b99a8eb01039c4201f20a841f9928940029cde92305b2d128980ef00f0a431e032b4fea0e1c76d24ff000082898ddf870b010f00309a2d02b988044b8fbf6f000fb1681c319881853ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd54b9f1010f3ff47eaf08f10100b0fbf6f101fb1600cb19104453ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd54b9f1020f3ff459af08f10200b0fbf6f101fb1600cb19104453ea00013ff54daf2f998842bff449af2e998b42bff445afdde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd5433e720f003094ff0000805e000bf08f10408c1453ff480af2b9800eb080bbbfbf6f000fb16b300eb070e98185eea000315d42f99884212d22e998e450fd2dde92c310efb013341085c5cc00704f00f0504f0f004544408bf45ea0c045c540bf10100b0fbf6f101fb1600cb19104453ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd540bf10200b0fbf6f101fb1600cb19104453ea000115d42f99884212d22e998b420fd2dde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd540bf10300b0fbf6f101fb1600cb19104453ea00018ad42f998842bff487af2e998b42bff483afdde92c5103fb01514308cd5cc00705f00f0405f0f005554408bf44ea0c05cd5471e725982492294642aacdf86cb0cde922e3e34601f0f5fa002841f06d82ddf83c05dc468069ddf86cb0dde922e3249a50b1012f08d8ed0804f00701445d012707fa01f1214341554299002901f054825d4653ea06204ff0ff3b23931c961cbf249159ea082801f04982dde92e41439b41ea04218b42c1f041825b1a984201f23d822d9b449f45ea03239f424ff00006a7eb030738bf0126b8454ff0000788bf01273743c7f1000b41f02882ddf83875002f01f02382279c2b9e2706289c4ff0000b47ea04473f143744574581f21682269c260646ea024634142c9eb44281f20d824642b74241f30982c8f10006b44241f30482cdf888e007eae77e27eae77b7044aaeb0b071b95b84228bf38462c9da1eb0e0904eae47124eae47401eb08022d1baa4238bf1546ddf890a05e1ae245cdf860c000f02186002201f03eb8bcf1000f00f01882acf10109002542ae09e0bc46a94505f10105a4f1010406f1040600f0058242a850f825100029f1d400202b4684421dd006eb80077a68b2f1ff3f18dc5a1c914514d0ba68b2f1ff3f11dc9a1c91450dd0fa68b2f1ff3f0adcda1c914506d03a690433002a00f10400e0d400e0002215983aab6746cdf8008001f062fd002801f0988136980028c0d04af20d313aa8c0f24e018847b9e701204ff0000cc5e1d0f86c014ff0ff3b002801f085819af80110012901f280819af8002042ea012150f82120002a01f07781121a930741f073816ff440332f9740f60f071344cff6fd77bb42c1f06881104450f8083c8b4241f0628150f80c1c0027a1f10113cff6ff77bb42c1f05881002801f0558150f8043c8b4241f05081c2f54032914201f24b81002242ab01f016fa002801f042819af803109af8020009069af8053041ea00402b999af8042001eb2040190641ea02419af806200f26970602f00f0306eae7775f4389267743ff0a8df8d8700e2712f0200f08bf012703fb07f706fb07f74fead7278df8d9704ff00d0708bf022703fb07f706fb07f74fead7278df8da704ff00c0708bf032703fb07f706fb07f74fead7278df8db704ff00b0708bf042703fb07f706fb07f74fead7278df8dc704ff00a0708bf052703fb07f706fb07f74fead7278df8dd704ff0090708bf062703fb07f706fb07f74fead7278df8de704ff0080708bf072703fb07f706fb07f74fead7278df8df704ff0070708bf082703fb07f706fb07f74fead7278df8e0704ff0060708bf092703fb07f706fb07f74fead7278df8e1704ff0050708bf0a2703fb07f706fb07f74fead7278df8e2704ff0040708bf0b2703fb07f706fb07f74fead7278df8e3704ff0030708bf0c2703fb07f706fb07f74fead7278df8e4704ff0020708bf0d2703fb07f706fb07f74fead7278df8e5704ff0010708bf0e2703fb07f706fb07f74fead7278df8e6704ff0000708bf0f277b437343db0a09148df8e730c2f300122f9bcde90382cde90001204629464a4642af4ff0000b029701f0c9fc01f060b85d4541f0d1802b98804541f0cd80ddf83805002818bf012019990840012810d1dde92c03189907fb0300770800eb52021b98009701901a9801f085f9002801f0b380219901f040b848f2a351c0f24501bff32f8f88474ff29c50c2f229000768bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f035834ff46d70fcf725fc002801f013804ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fb94296d1bff35f8f42e80001002900f0e58252e8001fb942f6d08ae70020ddf8b09002e04ff0000c01209af804100f248d0601f00f0604eae575754389246543ed0a9af800e08df8d8500e259af801209af802309af803702f9111f0200f08bf012506fb05f504fb05f54fead5258df8d9504ff00d0508bf022506fb05f504fb05f54fead5258df8da504ff00c0508bf032506fb05f504fb05f54fead5258df8db504ff00b0508bf042506fb05f504fb05f54fead5258df8dc504ff00a0508bf052506fb05f504fb05f54fead5258df8dd504ff0090508bf062506fb05f504fb05f54fead5258df8de504ff0080508bf072506fb05f504fb05f54fead5258df8df504ff0070508bf082506fb05f504fb05f54fead5258df8e0504ff0060508bf092506fb05f504fb05f54fead5258df8e1504ff0050508bf0a2506fb05f504fb05f54fead5258df8e2504ff0040508bf0b2506fb05f504fb05f54fead5258df8e3504ff0030508bf0c2506fb05f504fb05f54fead5258df8e4504ff0020508bf0d2506fb05f504fb05f54fead5258df8e5504ff0010508bf0e2506fb05f504fb05f54fead5258df8e6504ff0000508bf0f256e436643f60a00288df8e76040f0f486120642ea0e412b9a380602eb21452e9940ea0340ddf854a0acf1010601eb204000240d90cdf844c00f9607e001f01f000b3801346445054400f0478742a850f82410b1f1ff3ff1dd23469e421cd042a800eb83004268b2f1ff3f16dc0133b34212d08268b2f1ff3f0fdc0133b3420bd0c268b2f1ff3f08dc0133b34204d002690133002ae1d400e0002250463aab35af009701f06efa002800f0a48635990029189100f0b1819df8f0009df8f110129450ea01201495289000f096819df8f4709df8f5603f0447ea06670e9e289d9df8ef009df8ee102e4406eb27470d9e020241ea00249df8f2009df8f330f71b00042797149d012740ea036007eb54060a44031405eb20401696561e1c941996ee1801f00304e91a431c1393831c1093189bc9075d1c07eb52031f94121b00242e91f10726932d922b9106e0289901348c4226990d4400f0508127990919f5d4229a9142f2d21c9a002aefd0dde91a324ff0000a01fb032e199924940329239580f099801f99dde923540029ded01899169a012704fb02132f994fea5a029a5c01f0100187ea111c02f00f01d5b25feaca7b08bf29090a46002918bf012242ea0c02012a14d11aeb000611d44e450fd272081ef8025018f8011005f00f0705f0f0050d43f60708bf47ea01150ef802501f99dde923540129a8d00af101014908595cbbf1000fcab24fea121208bf01f00f02d1b2002918bf012141ea0c01012917d1139911eb0a0113d4494511d24d081ef8056018f8022006f00f0706f0f0061643c90708bf47ea02160ef80560dde923541f9902293ff479af0af102014908595cbbf1000fcab201f00f0108bf11090a46002918bf012242ea0c02012a7ff465af109a1aeb02033ff560af4b45bff45daf5a081ef8027018f8011007f00f0607f0f0070f43db0708bf46ea0117249c0ef802704ae7ac4608e000bf2d990af1040a51450cf1020c3ff45caf2f991cf8013c01f010010122deb2002382ea11110f2e88bf01230b43012b00eb0a031ad1002b18d44b4516d235095e081ef8062018f8055002f00f0802f0f0025feac07942ea0502ddf8b09008bf48ea05120df1d8080ef806201cf8012c12f00f06324618bf01220a43012a19d15d1c17d44d4515d26a081ef8025018f80660c346ddf8b88005f00f0747ea0617b8f1000fd84605f0f00508bf45ea06070ef802709cf80020d6b200220f2e88bf01220a43012a17d19d1c15d44d4513d26d0832091ef8056018f8022004462b9806f00f0706f0f00616430028204608bf47ea02160ef805609cf8002012f00f06324618bf0122114301297ff47aafd91c3ff577af4945bff474af49081ef8012018f8063002f00f052e9e45ea031502f0f002002e08bf42ea03050ef8015060e74af20d313aa8c0f24e0188479df8ec009df8ed10dde9145a0f9edde911c405e09df8ec009df8ed10ddf844c040ea01200be6d0f86c114ff0ff3b002900f0e084012e00f2dd8451f82400002800f0d884401a820740f0d4846ff4403240f60f030244cff6fd739a42c0f0ca840b1853f8081ca14240f0c48453f80c7c0022a7f10111cff6ff729142c0f0ba8453f8041c2893b94240f0b484c0f540308742279700f2ae842898002800f0aa842798c128c0f0a68428980078012840f0a1844fea88670f2408f00f0604eae777774389246743ff0a8df8d8700e279af802109af803309af804009af8052018f0200f08bf012706fb07f704fb07f74fead7278df8d9704ff00d0708bf022706fb07f704fb07f74fead7278df8da704ff00c0708bf032706fb07f704fb07f74fead7278df8db704ff00b0708bf042706fb07f704fb07f74fead7278df8dc704ff00a0708bf052706fb07f704fb07f74fead7278df8dd704ff0090708bf062706fb07f704fb07f74fead7278df8de704ff0080708bf072706fb07f704fb07f74fead7278df8df704ff0070708bf082706fb07f704fb07f74fead7278df8e0704ff0060708bf092706fb07f704fb07f74fead7278df8e1704ff0050708bf0a2706fb07f704fb07f74fead7278df8e2704ff0040708bf0b2706fb07f704fb07f74fead7278df8e3704ff0030708bf0c2706fb07f704fb07f74fead7278df8e4704ff0020708bf0d2706fb07f704fb07f74fead7278df8e5704ff0010708bf0e2706fb07f704fb07f74fead7278df8e6704ff0000708bf0f27774367434ff0000bff0a002d8df8e77000f0d5831b0643ea01412b9b4e4603eb2144110641ea004000142490c8f30010239028982f46a0f13f08a6e3b44240f2148201221ae20120019018463b46269f49460097774601f05bfe2798be4624990135b6448d424ff0000b80f2a8832f9ae94311448d42b8bf2946239a6fea4101114401295bdb1c9a4ff0ff3301fb11211f9a121b012a03eb420230db02fb02f38b422cdd169aa2eb440303f10807032f03f106021edb02fb02f68e421add052f03f1040218db02fb02f68e4214dd072f03f1020212db02fb02f68e420edd0434092fa3f1080203db5b438b421346dcdc083204e0013402e0023400e00334012c1edb0832931f5b438b4219dc022c16db131f5b438b4200f3b480022c0fd0931e5b438b4200f3af80042c08db02fb02f38b4200f3aa80043c02f10802e2d100242e9e2c9b291801fb06332d9904eb0a0210292899a1eb04073ff475af2b93b5fa85f11b9b490919434cd118998d4249d01599681e491bcdf888e01a958842b8bf01466fea41001499ba4608440128c0f2ab800f9900fb10101299a1eb08034ff0ff31012b01eb430179db01fb01f7874275dd5900a1f1090303f10807032f03f1060164db01fb01f6864260dd052f03f104015fdb01fb01f686425bdd072f03f102015adb01fb01f6864256dd08f10408092fa3f1080103db5b4383420b46dbdc08314ce022eae27c4f45a8bf4f46bc45bff625afbb465feacc70cdf888e00ad02b9b4fea5c00195c2d9a01f0f00111430cf1010c19544fea5c0ebeeb5b0f1cd22b98229f109a00eb5b0307eb0e010e4606f8012b9e4280f08480881c9842327080f08480ce1c9e4202707ed2043707eb0e0098423270e8d378e02b9800eb5c0074e0013c5ce7023c5ae7033c58e708f1010804e008f1020801e008f10308b8f1010f23db08318b1f5b4383421edcb8f1020f19db0b1f5b43834200f3cd80b8f1020f11d08b1e5b43834200f3c880b8f1040f09db01fb01f3834200f3c380b8f1040801f10801ded14ff00008139822eae27e00eb080ccc45cb46b8bfe346de454eda5feace700ad02b9b4fea5e00195c2d9a01f0f00111430ef1010e19544fea5e07b7eb5b0f18d22b98229b109d00eb5b06d919084600f8015bb04213d28a1cb242057021d2c81cb04215701cd20433da19b2420570ecd317e02b9800eb5e0213e0481c02e04a1c0fe030465feacb7107d0dc4505d20178119a01f00f011143017027982e9e62e002465feacb7007d0de4505d21078119900f00f000843107028996fea08000e18012001902b98269f494662463346009701f0aafc26eae67cca45a8bfca46d4453edad6465feacc700ad02b9b4fea5c00195c2d9a01f0f00111430cf1010c19544fea5c02b2eb5e0f18d22b98229f109d00eb5e03b818064606f8015b9e4211d2811c9942357010d2c61c9e420d700bd20437b91899423570ecd306e02b9800eb5c0102e0411c00e031465feace7007d0f44505d20878119a00f00f001043087027982e9e1a9dddf864a0ddf888e002e6a8f1010846e7a8f1020843e7a8f1030840e7a21bb2fa82f252090023cb4588bf01231a40002d2c9200f00e822e9a1f9612022e922d9a4fea590612022d921c9a0e941302239a734413441696bb4238bf1f4607eb0b030bf0010803f0010343442695042500eb0b0aa7eb030c25ea89030af001041593dde92e322e9444441344021b09eb0004013c6008139025ea840012901b982d9f269c0744781a09eb08070c9078081c904fea5b0011904fea5a0089ea0b0110904fea5c090120cdf8bc80b9f1010f88bf4fea5c00434408eb0b0600f0030720f003082498a3eb0e03ddf860e000eb530370081b900eeb5600451c03380a90c8071a9045980e9e289050080f904ff0ff3000eb5c0027906ff0010000eb5c002390981e09906ff00200cdf82cc000eb5c00ddf888c04ff0000a0d97079514920893199006e00af1010aa2454ff0000b00f00f812c996fea0a005246002918bf22181f982499289b104400fb03112f9808b9002005e01698159b085cd84000f00f002d902e9808b9002004e01398129b085cd84000011a9c93192b9003fb0ceb1b98002c1c9c584421441fd10f9af4f7e5ffddf888c0ddf860e02f9840b111992d9a1bf8010000f0f00010440bf801002e98269c0028b6d010992b9a1bf8010000f00f0010430bf80100ace72c9c03fb0cf7002c42d014980228ded30c9828991044099a01fb00200a990022394400eb09039f785c78279dc7f3031747ea041401eb09079542bc70c7d05c7810f80950c4f3031444ea0515239c7d709442bcd010f8095013f8014cc5f3031545ea0415199c01f809509442afd013f8015c13f8023cc5f30315043245ea031304389145a1f1040107f8013cc9d19ee7149b022b9bd30b9b082b01d200222ce00c9b289e1a44089b06fb023c079a174400220ceb02056c781cf80260c4f3031444ea0616bc1804f8016cae786b78c6f3031646ea0313bb54eb78ae78c3f3031343ea061363702b79ee780432c3f3031343ea06139045a370dbd10d9bddf888c00e9e002b3ff463af531ccf5c8e5cc7f3031747ea0617dde90d468754012c3ff456af971cce5dcd5cc6f3031646ea05160d9cc6540e9e022c3ff449af0a44d278c95dc2f3031242ea0111c1553fe7013f2fd016f8010b411e1f29f8d341b220290fdb08eb400118f81000497840ea0122c12a06d3dde927103aab00f0d3f80028e5d14ff0ff3b2199bbf1000f6fd120984f1c8742dde92902ddf830c500eb0204dde91d23ddf82ce5ddf828557df41eae63e042982b90249820eae070269004e020440b38013d04464ed019f8010b1f28f6d908eb400118f81000497840ea0122c12aced3dde927103aab00f09bf80028c7d02398ddf8b4a0049036a803903aa80290dde92e70ddf890b02c993a465346cdf804b0009400f01dfcdde93c013b46204401eb0b02b84224eae471b8bf03465245a8bf52468b42c4dd269fba42c1dd2b9f0f2fbed8269e179ca2eb060c2b9a5b1a04ebc20724f8321001327e80bb80a7f806c02b92ade74ff0000b8be74ff0ff300df2045dbde8f08fa01a18bf4ff0ff300df2045dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f91b00df1700b9be8400a10913169ddf868a0002900f05c813768bbf1000f40f05181874200f04e8199f80f100f2940f0498199f80e100e2940f0448199f80d100d2940f03f8199f80c100c2940f03a8199f80b100b2940f0358199f80a100a2940f0308199f80910092940f02b8199f80810082940f0268199f80710072940f0218199f80610062940f01c8199f80510052940f0178199f80410042940f0128199f80310032940f00d8199f80210022940f0088199f80110012940f0038199f80010002940f0fe80ddf86cc0caf10001d6f808e001eaea75ccf10001f76801eaec740895aeeb05062aeaea75391b2ceaec77521b9642a3eb07030d97b8bf32469942b8bf0b46012a0e930992c0f2ea820e990129c0f2e6820ef10101a4464c08089900eb55000c9048100b90042020ea81000790099801310138cde905014810049004fb0cf000f102094ff0000a0a94cde901c507e000bf0e980af1010a8245a14400f0bf821c98109bd0f800e00aeb0c0000fb04e20d980c9e504400fb0360eb0703d10b9edde9083810e00b9b2f46d35c079d0678eb4006f0f00603f00f03334400f8013b069bdde904683d469119da074fea58070f9208d13a468b466446f4f76ef9a4460a9c68e000bf8b46b8f1020f63d37a1e032a04d2002117f0030237d15be06ff0030202ea58034e44c3f1000c0eeb0601461c039700bf8d18ef78ac78c7f3031747ea0417b418e7702f79eb78c7f3031747ea031323716b792f79c3f3031343ea07136371ab796f79c3f30313043243ea07130ceb02070437a371dcd1dde901c50a9c039f111d17f0030224d04b1cbe461bf803701bf80160c7f3031747ea0617012a4754774616d08e1c1bf806701bf80350c7f3031747ea0517029d022ac754774608d05944c9781bf80620c1f3031141ea021181555feac8713ff45aaf0f9a1bf80710002a4ff0000208bf0422c35dd14003f00f0242ea0111c15549e7874200f09f815c460021aae17568002d00f0068200214ff0000e09e0dde90e71d8f804503944dde91d9ba94280f0f881ddf870800f91d8f80060775c3c0901d0012117e06d1a012d00f0ea8106eb010c9cf8016016b1344602210be0042dc0f0df819cf802509cf8036055ea062400f0d781042117f00f07bbfa8bf60e914fea561619f807b018bf012746ea07091b9f4fea0b1c14f00301754600f09980d8f808504ff00008befbf5f60d9106fb15e55544b5f1ff3fc8bf4ff0010809ea080101291ad1f61918d4954216d29e4214d210990b9406fb01046e08a15ded070c916ff00f05594604bf0f256146ddf8308005ea08052943a1550b9c0d99ddf8708001290ef1010563d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080b91895ded070c916ff00f05594604bf0f256146ddf8308005ea080529430b9dddf87080a9550d990ef10205022930d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080c91895ded070d916ff00f05594604bf0f256146ddf8348005ea080529430c9dddf87080a9550ef1030500bf611e0329a64405d220e700bf0435ae453ff41cafd8f808100024b5fbf1f606fb11515144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f808106c1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ac1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ec1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c7ff46aaff6193ff567af9142bff464af9e42bff461af109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa1554be71b995c46002901dd012108e0b1fa81f149090027baf1000fc8bf01273940d6f808e0f76807fb0ef8b8f1000f56d0b4fa84f4bb4600274ff0ff3c6409c9070e940f9106e001370bfb0ef84745acf1010c44d20f990ef101050029394618bf08eb0c01b1fbfef46d0804fb1e161c99096804fb05117508495d042525ea8605e94011f00f08454618bf01250e990d43012dd8d116eb0a065cbf1b9d14eb0504d1d49642cfd29c42cdd2109d19f8081004fb050e74081ef80450f60705f00f0805f0f00545ea010508bf48ea01151c990ef80450d1f808e0d1f80cb0b3e711b0bde8f08f00bf2de9f04fc8b0dde95162549f1644ba1926eae6778a42b8bf11468f42039080f203815698cde90071a0f1030a6ff007076ff004044ff0000b0df1200e4ff000090293cdf810a000bf56984fea5903c05c4ff0100c00f0f0080590cde9064700bf1af8041f0eeb07001af8012c9af8013048ea121602f00f0242ea0802427248ea111201f00f01827241ea08010eeb0402117248ea13119af802500672517203f00f0141ea0801917248ea1511817305f00f0141ea08010837bcf1080c04f10804c173cdd10598ddf810a00401102753465d4600bf13f8040f0eeb050213f8011c5e7844ea111801f00f012143517444ea101100f00f002043d07444ea161093f802c0107506f00f002043507544ea1c1090750cf00f002043083f05f1080582f810809174d075d5d1079f069c09f1020920372034b9f1100f0bf1200b84d15598029bdde90086539900286dd00844079008f10100069003984fea580a03fb01074fea660c4feac87b06e000bf079809f1010181421f4457d20398894601fb0301bbf1000f45460bd011f80a00069d1ef8002000f0f00002f00f02104401f80a00bceb550f28dd680801eb0c033e4600bf315c06eb00081ef80120414601f8012b99421ed20a7808f102041ef802209c420a7018d221781ef80110217008f103049c4210d2217804361ef80110217034189c42ddd307e000bf01eb5504f00707d1b4e708f10104029bdde90086f007add0b542abda20781ef8001000f00f0001f0f00108442070a1e748b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf7a4fc69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae72de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041b1e022eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70f9f750fd002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f7e1fc00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f8f788fde0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f7f4f902a9284600224ff0000afbf7a5fc81464046f7f7b9fab9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f7b7fc06f1210506f1280029460722f2f7affc284621460722f2f7aafc20465146032207f10905f2f7a3fc06f11d0049460422f2f79dfcf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f771fca81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f737fc012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f71efc572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f707fc312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f7f1fb462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f7dafb362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f76ffbcde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f750fb8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f751fa284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f7fdf9002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f7cbf904a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f7b7f90020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f7a0f9352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f77cf904a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f769f9002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f755f904a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f731f904f14f0051460722f2f72bf984f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f2f79df884f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f1f7b3ff284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f7f7adfe0028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3237000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f05df8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef715fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef7cbfd0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f012fb0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf069fd48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf0e3fc414602e0022084f8200350460c22fdf7d2ff94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7a2ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf771ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf71bff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf05ffcd8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf025fe0bf0f9fd294630b9ffe50bf0f4fd002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7bdfd0fe04eea062141ea0b4141ea05633946624665460bf0f3fb00281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af019fcd4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f213040af0c9f84ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b700af0b6f8e05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f0e2ff059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f014ff28461a21224609f091fd00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f003fd854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f0fffc706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f0ecfb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f092fc606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf751f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009508f03cfb606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7a3fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009708f04df8002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009508f02ff8606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009508f002f8606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f0d7ff606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf7dbf904f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf797f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf741f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f0f4fd019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f65c01c0f20001033079440b22f9f710fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f7d8fb0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f729fb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f77ffa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f68600c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f7ddfb4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f7f1fb4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f70afbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f729fb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009503f093fc3eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb00446002047f64c68a4f88003c2f20708d8f80000002a8b461abfc4f874030146d4f87413401ac4f87c03fdf762f8002800f0f980d4f86803002800f0f48004f0f8f9002800f0ef800646b4f86c03002848d0a0f10108d4f87c0300254ff4a0714ff4f0774ff48059cde90d050df1180acde901152046414632464ff42073cde906950c95cde9035a009703f03cfc002840f0c980d4f87c034146cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906950c95cdf810a0009703f020fc002840f0ad809df8380094f8801347f64c68084384f88003c2f2070806e0d4f8681330464ff41632f7f712f94ef66c694ff29c57ccf2ff09c2f229074ff6ff76002506e048f2a351c0f24501bff32f8f8847d7f800a0bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168494548d04ff46d70fdf781fe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d10121c0f8009081728683c683068446848684c684068546858685c685068646868686c6860687468757e8001f5145aad1bff35f8f00bf47e8000121b157e8001f5145f8d09fe7054604f031f9002d18bf002803d101208bf8050022e0c5f860014ff001094ff4f07085f8649101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718bf8059004e09bf805008bf8049030b14ff0ff300fb0bde8f08f0025cbe794f8800384f8810348b3d4f8700342f66535c0f2440528b1d8f800102d31c4f8781311e044f21740c0f200007844002122460023a847c4f87003d8f8001001f12d01c4f8781320b105f1e8022d21904728b1002084f881030fb0bde8f08f00200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2045d279008784f7801eb020c50ea072001f10204239002f0a3820df5a567e0cf42a8063000211690cde9203c644502f09182601c604502f08d82269120786178a21c40ea0121aceb020081422892299102f28082ddf83c2530a8e8c01068ddf8341500283491a0f10101116002f072822998002802f06e822998871c032f02f06982e678032e02f26582289890f80090f00703d104f1040828e000bf299820f00100022802f0568294f804a0657927984aea052b594630aa02f05cfa002842f04982ddf8340504f10608012d34900dd8ddf83c05806948b14feadb020af00701835c012505fa01f119438154022e04eb070503d2ddf834052b9026e0a8452f4603d0444614f9015b01e000253c4645f64d5ac0f2460ad047012808bf0135681e81b26e0800ebd130002d48bf4610d0470128ddf8340508bf76423118b845a0463d462b91349102f00582b9f1040f29ddb9f1060f40f35081b9f1070f00f0ad83b9f1080f00f0be81b9f1090f42f0f281a84502f0ef8118f8011ba84542f0ea810f2902f2e781ddf83805002801f01081dde93223309801eb01115a43f7f73af801f006b9b9f1020f00f39680b9f1010f00f08082b9f1020f42f0cc81a84502f0c98108f10100a84202f0c48108f10200a84202f0bf8108f10300a84202f0ba8108f10400a84202f0b58108f10500a84202f0b08108f10600a84202f0ab8108f10700a84202f0a68108f10800a84202f0a18108f10900a84202f09c8108f10a00a84202f0978108f10b00a84202f0928108f10c00a84202f08d8108f10d00a84202f0888108f10e00a84242f0838198f8020098f800a02e9098f8030098f801b02d9098f80500309c2c9098f8080098f804e02f9098f80a0098f80630249098f80b0098f8072098f80990229098f80cc098f80d60dde93181339f4aea0b254ff6fe70854242942591cde94381459700f05b864ff6ff70854240f02c862798d0f868134ff4207043904ff4f07044904ff4a070459000f049beb9f1030f00f03e82b9f1040f42f03681b5eb080402f0328108f10100a84202f02d812798002802f02981a01e0528c2f0258108f10700a84242f020812798d0f86c01002802f01a8198f80110012902f2158198f8003043ea012250f82210002902f00c810f1ab90742f008816ff4403140f60f063944cff6fd76b142c2f0fe80384450f8081c914242f0f88050f80c1ca1f1011616f5803fc2f0f080002802f0ed8050f8046c8e4242f0e880c7f54037b94202f2e380ddf83c75bf6947b1d20803f00703be5c012505fa03f33343bb540df1c00a9ae84006339d00223aab02f029f900284ff0000708bf4ff0ff3702f05280ddf83805ddf884c02699002802f04d80072c4ff0ff3742f04880002e02f04580fcf72dfd002840f0998302f039b8b9f1050f00f08382b9f1060f42f0a680a84502f0a38008f10100a84202f09e8008f10200a84202f0998008f10300a84202f0948008f10400a84202f08f8008f10500a84202f08a8008f10600a84202f0858008f10700a84202f0808008f1080ca5eb0c000828c2f0798008f11000a84242f0748098f8040098f8051050ea01261ebf98f8060098f8071050ea012502f0658098f8000098f80120319940ea0224081bc2f05b80864202f2588098f8020098f80330329a40ea0327d01bc2f04e80854202f24b80ddf83805002800f074873098339bcde901472b9fcdf814c0cde90365009702f0a6ff00f066bfddf83c05cde94285c069002142af3aaddde9304bdde932964491cde93a013846294603f04ff982463846294603f04af94499002941f0a787dde942218a4201f0a287531c8b4201f09e87931c8b4201f09a87d31c8b4201f09687131d8b4201f09287531d8b4201f08e87931d8b4201f08a87d31d8b4201f0868702f108038b4241f08187117853784ff0ff3c51ea032101f08e879378d77853ea072301f08887b1f5207f01f28487b3f5f07f01f2808797790f2f259701f27b87d5796746102d2f9501f262872493ddf83c352c903b981f6a92f804c03843ddf838755279002f1c962a94186201f032872b980023084440428245c1f25e872b98abeb0000824581f25887249847422c98b842c1f252872c98ddf870e0249c81451f4641f335874cea0222b2eb510f28bf4a08b2eb540f28bf62081d92013a4ff0000738bf3a461292424202eae078a9eb0002a242a8bf22469045229281f218872b9a1d9b92445a001f9203fb03f292001b9201eb0a0203294ff000012d9238bf01210022032c38bf012211431a91611e1891a11e159112994ff000094a00494389000f910af1010113912f9914920a0141ea011110916ff00801119201eb43012a9a179120eae0710efb01250026cdf864a001f03dbba84501f04d87414611f8010b012801f24787309addf8cce02d92319a00282f92329a2e9200f0df81a94201f0398708f10201a94201f0348708f10301a94201f02f8708f10401a94201f02a8708f10501a94201f0258708f10601a94201f0208708f10701a94201f01b8708f10801a94201f0168798f8011098f8022098f8043041ea022198f80320474698f8056098f8064042ea0328fa793b7a093746ea04261a9742ea0322bee1a5eb080bbbf1050fc1f0f68608f10509a94501f0f18608f1060698f80570a81bb842c1f0e986f019a84241f0e58630981b90dde93150249033981a90b7b1002403e000bf0134bc4210d2305d01381e28f8d93019391b42aa3aab02f093f9002801f0ca8642980444bc42eed3ddf83805002800f0ef85bbf1050f2c9501f0bc861b98002801f0b886fcf730fb002801f0b38699f800a00af10600834541f0ac8647f65420c2f20700d0f800b0bbf1000f01f0a2869bf80c009bf80d109bf80e209bf80f3040ea012040ea024040ea0365a5f1810010f1800fc1f08e869bf810009bf811109bf8132040ea01209bf8121040ea014040ea02600c90813810f5817f41f27a86baf1000f4ff000002e9000f04a844ff0000900270be000bf00f1004042a941f824000137574504f1010980f0ea83f05d4c46411e1e29efd9f019aaeb07013aaa36ab02f01df9002801f0df853a99369842aa0f4442f82400e4e7a84501f04a8608f10100a84201f0458608f10200a84241f0408698f8000098f8011030af40ea0121ddf83c058ccf0490ddf83805339e03902b98019602902798009702f0aefe074601f0b4bdb5eb080a01f0238608f10100a84201f01e86aaf102000528c1f0198608f10700a84201f014862798002801f0108608f1080998f80740a5eb0900a042c1f0078609eb0400a84241f002862798d0f86c31002b01f0fc8598f80100012801f2f78598f8001041ea002053f82020002a01f0ee85d21a970741f0ea856ff4403740f60f061744cff6fd76b742c1f0e0859e1856f8083c834241f0da8556f80cbcabf1011313f5803fc1f0d285002e01f0cf8556f8043c5b4541f0ca85c2f54032934501f2c585ddf83c25926942b1c00801f00701135c012707fa01f119431154bbf1c10fc1f0b4853078012841f0b08530982f9031982e9032982d9033982c9014b3a6f13f074d4602e000bf013c1bd015f8010b411e1f29f8d341b22029c1f2978507eb400117f81000497840ea0122c12ac1f08d853046594642ab01f0e4fd0028e3d101f084bdddf83805002800f0ad840020baf1080f4ff0ff374290c1f004852f98002801f00085fcf7ebf9002801f0f98498f8074004f10800824541f0f28498f8000098f8017098f806a040ea072600f097bca94201f05a8508f10201a94201f0558508f10301a94201f0508508f10401a94201f04b8598f80220474698f801104fea4208fa783b7996007a1d89001a925a00002e1b9201f039851b9a002a01f035852f9a521ac1f03185964201f22e852e9ab2eb0802c1f029851b9b934201f22585002878d02b98002301eb000a82e048f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f0da824ff46d70fdf71cf8002801f082844ff64c41cff6ff71002342180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa14297d1bff35f8f42e80001002900f08b8252e8001fa142f6d08be72b98002301eb000ac00708d1baf1000f05d42f9906eb0a008842d8bf01231a991b9a681a1890ddf8380502fb06fcb0fa80f040091843c00700241e900a46002019932c90cde91c5c0fe000bf2c982a9918442c90249881424ff0000088bf01200443259ae00708bf0a44e00704d02c98844508d801f06ebcaa4200f078832c98844540f27483af1a01f064841078030902d0012112e000bf012f01f05b8453780bb102210ae0042fc1f054849178d37851ea032301f04e84042100bf2a912c99aceb01018b4201f245841e99cde924720029bbd1591e00f00f0903294fea001b1f94229380f080800021229bdde91c5c1f9c13f00300a9d02c9a1144b1fbf6f202fb161702eb080307eb0a0453ea040215d42f9a944212d22e9a93420fd22d9a03fb0e226308d75ce40707f00f0507f0f0074f4408bf45ea0b071c9dd754ddf874c01f9c229b01283ff480af4a1cb2fbf6f303fb1622434402eb0a0453ea040217d42f9a944214d22e9a934211d22d9a03fb0e226308d75ce40707f00f0507f0f0074f4408bf45ea0b071c9dddf874c0d7541f9c229b02283ff458af881cb0fbf6f101fb16004144504451ea00023ff54daf2f9a9042bff449af2e9a9142bff445af2d9a01fb0e2142088b5cc00703f00f0703f0f0034b4408bf47ea0b03ddf874c08b54229b31e723f0030000212b9005e000bf2b98043188423ff476af2c980844b0fbf6f303fb160503eb080405eb0a0c54ea0c0318d42f9a944515d22e9a944212d22d9a5feacc7704fb0e234fea5c041d5d724605f00f0e05f0f0054d4408bf4eea0b0596461d55431cb3fbf6f707fb163507eb080305eb0a0453ea040714d42f9a944211d22e9a93420ed22d9a670803fb0e23e407dd5d05f00f0205f0f0054d4408bf42ea0b05dd55821cb2fbf6f303fb1622434402eb0a0453ea040214d42f9a944211d22e9a93420ed22d9a03fb0e226308d75ce40707f00f0507f0f0074f4408bf45ea0b07d7540330b0fbf6f202fb160002eb0803504453ea00023ff588af2f9a9042bff484af2e9a9342bff480af2d9a03fb0e224308d75cc00707f00f0507f0f0074f4408bf45ea0b07d7546fe72798cde91e26294642aacdf8a8c0cde91ce301f025fb002841f09d82ddf83c05dde91ce38069ddf8a8c0dde91e2688b1bbf1010f0ed8ea080af0070110f802c0012505fa01f141ea0c011f9eddf8a8c081541e9a4299002901f07d822a9753ea02204ff0ff371fbfcde91d321f912f9951ea092501f07182dde92d31439a41ea03218a42c1f06982521a904201f265822c9a449be2464eea022cb34663454ff00006a3eb0c0338bf01269d424ff0000388bf01233343c3f1000741f04e82ddf83835002b01f04982229a2b9e1306249a002743ea02431b149a19424581f23d824fea0b6343ea0a43259e1b14b34281f234824642b24241f330826e42b34241f32c82cdf870e002eae27e0eeb000622eae270a8eb0007a1eb0e09be4228bf3e46259903eae37b23eae3725d448b1a9d4238bf2b46ddf87ca01794a245aceb0b042b9300f04f860021154601f070b8b9f1000f2d9500f01f825d46a9f1010b4ff0000a42af08e0d3450af1010aa4f1010407f1040700f00c8242a850f82a100029f1d40020534684421dd007eb80067268b2f1ff3f18dc5a1c934514d0b268b2f1ff3f11dc9a1c93450dd0f268b2f1ff3f0adcda1c934506d032690433002a00f10400e0d400e0002228463aab36ae009601f088fd002801f0be8136980028c2d04af20d313aa8c0f24e018847bbe72d9501204ff00009d1e1d0f86c014ff0ff37002801f0aa8198f80110012901f2a58198f8002042ea012150f82120002a01f09c81121a930741f098816ff440333c4640f60f071344cff6fd77bb422746c1f08c81104450f8083c8b4241f0848150f80c1c0027a1f10113cff6ff77bb42c1f07a8100284ff0ff3701f0778150f8043c8b4241f07281c2f54032914201f26d81002242ab01f038fa002801f0648198f8031098f80200090698f8053041ea00402b9998f8042001eb2040190641ea024198f806200f24970602f00f0304eae7775f4389246743ff0a8df8d8700e2712f0200f08bf012703fb07f704fb07f74fead7278df8d9704ff00d0708bf022703fb07f704fb07f74fead7278df8da704ff00c0708bf032703fb07f704fb07f74fead7278df8db704ff00b0708bf042703fb07f704fb07f74fead7278df8dc704ff00a0708bf052703fb07f704fb07f74fead7278df8dd704ff0090708bf062703fb07f704fb07f74fead7278df8de704ff0080708bf072703fb07f704fb07f74fead7278df8df704ff0070708bf082703fb07f704fb07f74fead7278df8e0704ff0060708bf092703fb07f704fb07f74fead7278df8e1704ff0050708bf0a2703fb07f704fb07f74fead7278df8e2704ff0040708bf0b2703fb07f704fb07f74fead7278df8e3704ff0030708bf0c2703fb07f704fb07f74fead7278df8e4704ff0020708bf0d2703fb07f704fb07f74fead7278df8e5704ff0010708bf0e2703fb07f704fb07f74fead7278df8e6704ff0000708bf0f277b436343c2f300120914db0a049236aa4ff0000c8df8e7300392cde90001304629464a46534642af0297674601f0e9fc01f080b8aa4241f0f0802c98844541f0ec80ddf83805002818bf012019990840012810d12d98189908fb0e00770800eb5a021b98734601901a98009701f0a5f9002801f0d280ddf884c0269901f05fb848f2a351c0f24501bff32f8f88474ff29c50c2f229000568bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f059834ff46d70fcf7cbfb002801f031804ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa94296d1bff35f8f42e80001002900f0098352e8001fa942f6d08ae70020ab4602e04ff00009012098f804100f258c0601f00f0605eae474744389256c43e40a98f800e08df8d8400e2498f8012098f8023098f803702f9111f0200f08bf012406fb04f405fb04f44fead4248df8d9404ff00d0408bf022406fb04f405fb04f44fead4248df8da404ff00c0408bf032406fb04f405fb04f44fead4248df8db404ff00b0408bf042406fb04f405fb04f44fead4248df8dc404ff00a0408bf052406fb04f405fb04f44fead4248df8dd404ff0090408bf062406fb04f405fb04f44fead4248df8de404ff0080408bf072406fb04f405fb04f44fead4248df8df404ff0070408bf082406fb04f405fb04f44fead4248df8e0404ff0060408bf092406fb04f405fb04f44fead4248df8e1404ff0050408bf0a2406fb04f405fb04f44fead4248df8e2404ff0040408bf0b2406fb04f405fb04f44fead4248df8e3404ff0030408bf0c2406fb04f405fb04f44fead4248df8e4404ff0020408bf0d2406fb04f405fb04f44fead4248df8e5404ff0010408bf0e2406fb04f405fb04f44fead4248df8e6404ff0000408bf0f2466436e43ddf8b0a0f60a00288df8e76040f02a82120642ea0e412b9a380602eb21442d9940ea0340a9f1010501eb204000260b90cdf84090cde90d5b07e001f01f000b3801364e45044400f0088242a850f82610b1f1ff3ff1dd33469d421cd042a800eb83004268b2f1ff3f16dc0133ab4212d08268b2f1ff3f0fdc0133ab420bd0c268b2f1ff3f08dc0133ab4204d002690133002ae1d400e0002258463aab35af009701f08cfa002800f0da8135990029179100f0ca819df8f0009df8f110129650ea012e149400f0af819df8f4709df8f5603f049df8ef009df8ee1047ea06670c9e4fea002c41ea00229df8f20076449df8f33006eb27470b9e0004149d40ea0360f41b0126031405eb204706eb520015900ceb01001d92421e19927a1c1392ba1c0f92179a01f00301cdf870e005eb030ceb1a02f1010e06eb5002401a2e90d807ddf870b00df1d809229100212d904feacc702b90cde91e2406e000bf2a9996440131594500f05f8108192a91f6d424998842f3d21d990029f0d0dde91a214ff0000800fb021c1998cdf894e0032880f0b7802298ddf870b0dde91e24ddf894e00028dbd0179815992a9a5feac87602fb01032f984fea5801595c00f010004ff0010282ea101501f00f00cab208bf10090146002818bf01212943012918951ed118eb070e1bd4d64519d24fea5e011cf8012019f8000002f00f0402f0f00202431d4633465feace7608bf44ea0012ddf870b00df1d8091e462b460cf801202298dde91e24ddf894e0012897d008f101004008195c002ec8b24fea101008bf01f00f00c1b2002918bf0121189d294301291cd1139911eb080118d4514516d24fea510e11961cf80e6036ad285c06f00f0506f0f0060643c90708bf45ea00160cf80e60ddf894e0119e0df1d809229802283ff464af08f102004008185c002ec1b200f00f0008bf08090146002818bf0121189b194301297ff451af0f9911eb08013ff54caf5145bff449af4d081cf8053019f8000003f00f0603f0f00303430df1d809c90708bf46ea00130cf8053035e72e9808f1040840450ef1020e3ff449af2f981ef8013c00f01000012181ea1011d8b200230f2888bf01230b43012b07eb080318d1002b16d4534514d25c0800091cf804a019f800000af00f050af0f002ddf8b0a002430df1d809fe0708bf45ea00120cf804201ef8010c10f00f00024618bf01220a43012a17d15c1c15d4544513d262081cf8024019f8000004f00f05ddf8b4b045ea001504f0f004bbf1000f08bf44ea00050cf802509ef800000022c0b20f2888bf01220a43012a17d19c1c15d4544513d2620800091cf8024019f800003e462b9f04f00f0504f0f0040443002f374608bf45ea00140cf802409ef8000010f00f00024618bf0122114301297ff47eafd91c3ff57baf5145bff478af49081cf8012019f8000002f00f032d9c43ea001302f0f002002c08bf42ea00030cf8013064e74af20d313aa8c0f24e0188479df8ec009df8ed10ddf84090149cdde90d5b129e05e09df8ec009df8ed10ddf8409040ea0120f2e5002001e04ff0ff302e90ddf884c026992e9f00f0e4bcd0f86c114ff0ff3000293ef423af012f074600f2d68451f82600002800f0cf84401a82074ff0ff3740f0cb846ff4403240f60f030244cff6fd739a42c0f0c1840b1853f8081cb14240f0bb8453f80c6c0022a6f10111cff6ff729142c0f0b18453f8041cb14240f0ac84c0f5403086422a9600f2a6849b46002b00f0a2842a98c128c0f09e849bf80000012840f099844fea8a660f250af00f0705eae6767e4389256e43f60a8df8d8600e2698f8021098f8033098f804c098f805201af0200f08bf012607fb06f605fb06f64fead6268df8d9604ff00d0608bf022607fb06f605fb06f64fead6268df8da604ff00c0608bf032607fb06f605fb06f64fead6268df8db604ff00b0608bf042607fb06f605fb06f64fead6268df8dc604ff00a0608bf052607fb06f605fb06f64fead6268df8dd604ff0090608bf062607fb06f605fb06f64fead6268df8de604ff0080608bf072607fb06f605fb06f64fead6268df8df604ff0070608bf082607fb06f605fb06f64fead6268df8e0604ff0060608bf092607fb06f605fb06f64fead6268df8e1604ff0050608bf0a2607fb06f605fb06f64fead6268df8e2604ff0040608bf0b2607fb06f605fb06f64fead6268df8e3604ff0030608bf0c2607fb06f605fb06f64fead6268df8e4604ff0020608bf0d2607fb06f605fb06f64fead6268df8e5604ff0010608bf0e2607fb06f605fb06f64fead6268df8e6604ff0000608bf0f2677436f430020ff0a002c8df8e7703ef417ae1b0643ea01412b9b4d4603eb2146110641ea0c4000142490caf30010abf13f0a27462290a0e3a242154640f2168201211ee20120019018463b46259f59460097774601f054fe2c98be46229908f10108754488454ff0000780f2a0836fea080121448845b8bf41461f9a6fea4101114401295cdb1b9a4ff0ff3301fb11211d9a921b012a03eb420231db02fb02f38b422ddd179aa2eb460303f10807032f03f106021edb02fb02f48c421add052f03f1040218db02fb02f48c4214dd072f03f1020212db02fb02f48c420edd0436092fa3f1080203db5b438b421346dcdc083204e0013602e0023600e00336249c012e1edb0832931f5b438b4219dc022e16db131f5b438b4200f3b380022e0fd0931e5b438b4200f3ae80042e08db02fb02f38b4200f3a980043e02f10802e2d100262a9b08eb000101fb0e332f9906eb0a0210292d99a1eb06073ff473af2e93b8fa88f11a9b490919434cd11899884549d01599a8f10100a1eb08012b971e958842b8bf01466fea4100149908440128c0f2aa800f9900fb10101299a1eb09034ff0ff31012b01eb430178db01fb01f7874274dd5900a1f1090303f10807032f03f1060163db01fb01f484425fdd052f03f104015edb01fb01f484425add072f03f1020159db01fb01f4844255dd09f10409092fa3f1080103db5b4383420b46dbdc08314be022eae27c5f45a8bf5f46bc452b97bff622af5feacc701e950ad02e9b4fea5c00195c2f9a01f0f00111430cf1010c19542b984fea5c02b2eb500f1bd22e982b991e9f109d00eb5103b9180c4604f8015b9c4280f08380881c9842257080f08380cc1c9c4205707dd20437b81898422570ead378e02e9800eb5c0074e0013e5de7023e5be7033e59e709f1010904e009f1020901e009f10309b9f1010f23db08318b1f5b4383421edcb9f1020f19db0b1f5b43834200f3ce80b9f1020f11d08b1e5b43834200f3c980b9f1040f09db01fb01f3834200f3c480b9f1040901f10801ded14ff00009139822eae27e00eb090cdc45da46b8bfe246d6454dda5feace700ad02e9b4fea5e00195c2f9a01f0f00111430ef1010e19544fea5e07b7eb5a0f18d22e981e9b109d00eb5a04d919084600f8015ba04213d28a1ca242057020d2c81ca04215701bd20433da19a2420570ecd316e02e9800eb5e0212e0481c02e04a1c0ee020462b99c9076bd02b998c4568d20178119a01f00f011143017061e002465feaca7007d0d64505d21078119900f00f00084310702d996fea090001eb000a012001902e98259f594662465346009701f0a2fc2b982aeaea7c5845a8bf584684453eda86465feacc700ad02e9b4fea5c00195c2f9a01f0f00111430cf1010c19544fea5c02b2eb5e0f18d22e981e9f109d00eb5e03b818044604f8015b9c4211d2811c9942257010d2c41c9c420d700bd20437b91899422570ecd306e02e9800eb5c0102e0411c00e021465feace7007d0f44505d20878119a00f00f00104308702c98ddf870e0249cddf864a01e9d00e6a9f1010945e7a9f1020942e7a9f103093fe72a1bb2fa82f200235209484588bf012302ea03012b9b002b00f07581cde918142c9922954fea012c1e992d9a0b021d9d73444fea022832182b444fea590500f0010402f001011595bb4238bf1f463b1803f00103651823442f91711b09eb0605a7eb030a0427013d27ea890327ea850711971c9f6e086744a7eb0b070c9709eb04077f08129626181d9789ea0007400814932e9b109050080f904fea5a0b01204344dde9185cbbf1010f88bf4fea5a00234400f0030220f003081f98a3eb0e03ddf85ce00d9200eb530270081c900eeb5600461c03380a90f8071b9045982b9b2c9048080e904ff0ff3000eb5a0025906ff0010000eb5a002490901e09906ff00200cdf82ca000eb5a004ff0000a0796139108921a901e9406e00af1010a9a454ff0000700f00d8152466fea0a00002d18bf1a181f992c9b02eb0c0000fb03110cb9002005e01598149b085cd84000f00f002e902f982a9f08b9002004e01298119b085cd84000012d9022981b9c131803fb07e91c98002c1d9c484421441fd10e9af4f729ffddf864c0dde917e51e9c44b110992e9a19f8010000f0f000104409f801002f982b9b0028b6d00f992d9a19f8010000f00f00104309f80100ace7002d03fb07f642d013980228dfd30c982c991044099a01fb00200a990022314400eb0b039e785c78259fc6f3031646ea041401eb0b069742b470c8d05c7810f80b70c4f3031444ea0717249c77709442bdd010f80b7013f8014cc7f3031747ea04171a9c01f80b709442b0d013f8017c13f8023cc7f30317043247ea031304389345a1f1040106f8013cc9d19fe7139b022b9cd30b9b082b01d200222ce00c9b2c9f1a44089b07fb023c079a164400220ceb02077c781cf80250c4f3031444ea0515b41804f8015cbd787b78c5f3031545ea0313b354fb78bd78c3f3031343ea051363703b79ff780432c3f3031343ea07139045a370dbd10d9bdde9185c002b3ff465af531ccf5c8e5c0d9cc7f3031747ea0617012c87543ff459af961c8f5dcc5cc7f3031747ea04170d9cc754022c3ff44daf0a44d278895dc2f3031242ea0111815543e700271be0013f30d015f8010b411e1f29f8d341b220290fdb0aeb40011af81000497840ea0122c12a06d32a9958463aab00f0d3f80028e5d14ff0ff37ddf884c02699002f6dd1239801318142dde928020df5a567209be0cf00eb02047df4cdad65e06746eae71f46e8e742982b90249820eae070259004e030440b38013c06464cd019f8010b1f28f6d90aeb40011af81000497840ea0122c12acdd32a9958463aab00f09af80028c6d02298ddf8b480049036a803903aa80290dde92e70249d2c993a4643460195009600f01efcdde93c013b4630444a19b84226eae671b8bf03464245a8bf42468b42c7dd259fba42c4dd2b9f0f2fc1d8ddf894c0169e2b9da2eb0c025b1a06ebc50726f835100135a7f802c0bb80fa802b95afe70020fef7d6b94ff0ff300df2045dbde8f08fb4eb0c0018bf4ff0ff300df2045dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f91b00df1700b9be8400a10913169ddf868a0002900f05c813768bbf1000f40f05181874200f04e8199f80f100f2940f0498199f80e100e2940f0448199f80d100d2940f03f8199f80c100c2940f03a8199f80b100b2940f0358199f80a100a2940f0308199f80910092940f02b8199f80810082940f0268199f80710072940f0218199f80610062940f01c8199f80510052940f0178199f80410042940f0128199f80310032940f00d8199f80210022940f0088199f80110012940f0038199f80010002940f0fe80ddf86cc0caf10001d6f808e001eaea75ccf10001f76801eaec740895aeeb05062aeaea75391b2ceaec77521b9642a3eb07030d97b8bf32469942b8bf0b46012a0e930992c0f2ea820e990129c0f2e6820ef10101a4464c08089900eb55000c9048100b90042020ea81000790099801310138cde905014810049004fb0cf000f102094ff0000a0a94cde901c507e000bf0e980af1010a8245a14400f0bf821c98109bd0f800e00aeb0c0000fb04e20d980c9e504400fb0360eb0703d10b9edde9083810e00b9b2f46d35c079d0678eb4006f0f00603f00f03334400f8013b069bdde904683d469119da074fea58070f9208d13a468b466446f4f7b4f8a4460a9c68e000bf8b46b8f1020f63d37a1e032a04d2002117f0030237d15be06ff0030202ea58034e44c3f1000c0eeb0601461c039700bf8d18ef78ac78c7f3031747ea0417b418e7702f79eb78c7f3031747ea031323716b792f79c3f3031343ea07136371ab796f79c3f30313043243ea07130ceb02070437a371dcd1dde901c50a9c039f111d17f0030224d04b1cbe461bf803701bf80160c7f3031747ea0617012a4754774616d08e1c1bf806701bf80350c7f3031747ea0517029d022ac754774608d05944c9781bf80620c1f3031141ea021181555feac8713ff45aaf0f9a1bf80710002a4ff0000208bf0422c35dd14003f00f0242ea0111c15549e7874200f09f815c460021aae17568002d00f0068200214ff0000e09e0dde90e71d8f804503944dde91d9ba94280f0f881ddf870800f91d8f80060775c3c0901d0012117e06d1a012d00f0ea8106eb010c9cf8016016b1344602210be0042dc0f0df819cf802509cf8036055ea062400f0d781042117f00f07bbfa8bf60e914fea561619f807b018bf012746ea07091b9f4fea0b1c14f00301754600f09980d8f808504ff00008befbf5f60d9106fb15e55544b5f1ff3fc8bf4ff0010809ea080101291ad1f61918d4954216d29e4214d210990b9406fb01046e08a15ded070c916ff00f05594604bf0f256146ddf8308005ea08052943a1550b9c0d99ddf8708001290ef1010563d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080b91895ded070c916ff00f05594604bf0f256146ddf8308005ea080529430b9dddf87080a9550d990ef10205022930d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080c91895ded070d916ff00f05594604bf0f256146ddf8348005ea080529430c9dddf87080a9550ef1030500bf611e0329a64405d220e700bf0435ae453ff41cafd8f808100024b5fbf1f606fb11515144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f808106c1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ac1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ec1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c7ff46aaff6193ff567af9142bff464af9e42bff461af109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa1554be71b995c46002901dd012108e0b1fa81f149090027baf1000fc8bf01273940d6f808e0f76807fb0ef8b8f1000f56d0b4fa84f4bb4600274ff0ff3c6409c9070e940f9106e001370bfb0ef84745acf1010c44d20f990ef101050029394618bf08eb0c01b1fbfef46d0804fb1e161c99096804fb05117508495d042525ea8605e94011f00f08454618bf01250e990d43012dd8d116eb0a065cbf1b9d14eb0504d1d49642cfd29c42cdd2109d19f8081004fb050e74081ef80450f60705f00f0805f0f00545ea010508bf48ea01151c990ef80450d1f808e0d1f80cb0b3e711b0bde8f08f00bf2de9f04fc8b0dde95162549f1644ba1926eae6778a42b8bf11468f42039080f203815698cde90071a0f1030a6ff007076ff004044ff0000b0df1200e4ff000090293cdf810a000bf56984fea5903c05c4ff0100c00f0f0080590cde9064700bf1af8041f0eeb07001af8012c9af8013048ea121602f00f0242ea0802427248ea111201f00f01827241ea08010eeb0402117248ea13119af802500672517203f00f0141ea0801917248ea1511817305f00f0141ea08010837bcf1080c04f10804c173cdd10598ddf810a00401102753465d4600bf13f8040f0eeb050213f8011c5e7844ea111801f00f012143517444ea101100f00f002043d07444ea161093f802c0107506f00f002043507544ea1c1090750cf00f002043083f05f1080582f810809174d075d5d1079f069c09f1020920372034b9f1100f0bf1200b84d15598029bdde90086539900286dd00844079008f10100069003984fea580a03fb01074fea660c4feac87b06e000bf079809f1010181421f4457d20398894601fb0301bbf1000f45460bd011f80a00069d1ef8002000f0f00002f00f02104401f80a00bceb550f28dd680801eb0c033e4600bf315c06eb00081ef80120414601f8012b99421ed20a7808f102041ef802209c420a7018d221781ef80110217008f103049c4210d2217804361ef80110217034189c42ddd307e000bf01eb5504f00707d1b4e708f10104029bdde90086f007add0b542abda20781ef8001000f00f0001f0f00108442070a1e748b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf752fc69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae72de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041b1e022eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70f9f7d8fc002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f769fc00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f8f710fde0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f77cf902a9284600224ff0000afbf72dfc81464046f7f741fab9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f7fdfb06f1210506f1280029460722f2f7f5fb284621460722f2f7f0fb20465146032207f10905f2f7e9fb06f11d0049460422f2f7e3fbf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f7b7fba81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f77dfb012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f764fb572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f74dfb312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f737fb462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f720fb362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f7b5facde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f796fa8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f797f9284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f743f9002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f711f904a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f7fdf80020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f7e6f8352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f7c2f804a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f7aff8002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f79bf804a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f777f804f14f0051460722f2f771f884f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f1f7e3ff84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f1f7f9fe284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f7f735fe0028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3238000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "e84d3a00", + "new": "5c4f3a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "684e3a00", + "new": "dc4f3a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "e84d3a04", + "new": "5c4f3a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "e5d1780a", + "new": "56bcf2ba", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "e2593a34", + "new": "8dff7648", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "e2593a34", + "new": "8dff7648", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/g2/glance-host.ts b/app/g2/glance-host.ts index 002fc147..845e4cf8 100644 --- a/app/g2/glance-host.ts +++ b/app/g2/glance-host.ts @@ -23,7 +23,7 @@ export const GLANCE_SURFACE_Z_ORDER = 900; /** Surface operations needed by the board, shared by Android and iOS. */ export type GlanceDisplay = Pick; + "configureSurface" | "setSurfaceVisible" | "setSurfaceDepth" | "setScreenBlanked" | "submitSurfaceFrame">; export type GlanceHostOptions = { getDisplay: () => GlanceDisplay | null; @@ -52,6 +52,8 @@ export class GlanceHost { private shown = false; private hideTimer: ReturnType | null = null; private configuredFor: GlanceDisplay | null = null; + /** Last depth given to the surface; null forces the next render to set it. */ + private configuredDepth: number | null = null; /** Serializes show/hide against each other and against in-flight renders. */ private queue: Promise = Promise.resolve(); private rendering = false; @@ -158,6 +160,7 @@ export class GlanceHost { transparency: "opaque", }); await display.setSurfaceVisible(GLANCE_SURFACE_ID, false); + this.configuredDepth = null; this.configuredFor = display; } @@ -256,6 +259,12 @@ export class GlanceHost { const { image, draws } = frameTimings.span(frameId, "flatten", () => flattenPlanesWithDraws(planes)); const buffer = frameTimings.span(frameId, "to8bpp", () => image.to8bppBuffer()); const preparedDraws = frameTimings.span(frameId, "prepareFrameDraws", () => prepareFrameDraws(draws)); + // The glasses copy the screen shifted per lens while the board covers it. + const depth = this.options.getProvider()?.depth() ?? 0; + if (depth !== this.configuredDepth) { + await display.setSurfaceDepth(GLANCE_SURFACE_ID, depth); + this.configuredDepth = depth; + } await frameTimings.spanAsync(frameId, "submit", () => display.submitSurfaceFrame( GLANCE_SURFACE_ID, diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts index cd5b4b82..568c3abf 100644 --- a/app/g2/ios-preview-controller.ts +++ b/app/g2/ios-preview-controller.ts @@ -86,6 +86,7 @@ export class IosPreviewController { private readonly glanceDisplay: GlanceDisplay = { configureSurface: async (id, options) => { await this.display?.configureSurface(id, options) }, setSurfaceVisible: async (id, visible) => { await this.display?.setSurfaceVisible(id, visible); this.schedulePreviewUpdate() }, + setSurfaceDepth: async (id, depth) => { await this.display?.setSurfaceDepth(id, depth) }, setScreenBlanked: async blanked => { await this.display?.setScreenBlanked(blanked); this.schedulePreviewUpdate() }, submitSurfaceFrame: async (id, pixels, rect, fingerprint, paintMs, frameId, draws) => { await this.display?.submitSurfaceFrame(id, pixels, rect, fingerprint, paintMs, frameId, draws); this.schedulePreviewUpdate() diff --git a/app/graphics/surface-compositor.ios.ts b/app/graphics/surface-compositor.ios.ts index 42b8c402..be080bfc 100644 --- a/app/graphics/surface-compositor.ios.ts +++ b/app/graphics/surface-compositor.ios.ts @@ -18,6 +18,7 @@ export class SurfaceCompositor { } removeSurface(id: string): void { this.native.removeId(id); this.surfaces.delete(id) } setSurfaceVisible(id: string, visible: boolean): void { this.native.visibleIdVisible(id, visible) } + setSurfaceDepth(id: string, depth: number): void { this.native.depthIdDepth(id, depth) } setUnderlayDim(belowZOrder: number, factor: number): void { if (!Number.isFinite(factor)) throw new Error('Invalid dim factor') this.native.dimBelowFactor(belowZOrder, factor) diff --git a/app/graphics/surface-compositor.ts b/app/graphics/surface-compositor.ts index e110bac9..30a86dfa 100644 --- a/app/graphics/surface-compositor.ts +++ b/app/graphics/surface-compositor.ts @@ -33,6 +33,8 @@ export class SurfaceCompositor { const surface = this.surfaces.get(id) if (surface) surface.visible = visible } + /** Stereo depth only shifts the lenses; this local composite shows the unshifted screen. */ + setSurfaceDepth(_id: string, _depth: number): void {} setUnderlayDim(belowZOrder: number, factor: number): void { if (!Number.isFinite(factor)) throw new Error('Invalid dim factor') this.dimBelow = belowZOrder diff --git a/app/native/faceclaw-communicator.ios.ts b/app/native/faceclaw-communicator.ios.ts index aad20272..2a32aad8 100644 --- a/app/native/faceclaw-communicator.ios.ts +++ b/app/native/faceclaw-communicator.ios.ts @@ -524,6 +524,10 @@ export class FaceclawCommunicatorBridge { await this.enqueueNativeCall(() => { this.communicator.setSurfaceVisibleIdVisible(id, Boolean(visible)); }); } + async setSurfaceDepth(id: string, depth: number): Promise { + await this.enqueueNativeCall(() => { this.communicator.setSurfaceDepthIdDepth(id, Math.round(depth)); }); + } + async setScreenBlanked(blanked: boolean): Promise { await this.enqueueNativeCall(() => { this.communicator.setScreenBlankedBlanked(Boolean(blanked)); }); } diff --git a/app/native/faceclaw-communicator.ts b/app/native/faceclaw-communicator.ts index 5d36a3f7..806cf7ad 100644 --- a/app/native/faceclaw-communicator.ts +++ b/app/native/faceclaw-communicator.ts @@ -550,6 +550,16 @@ export class FaceclawCommunicatorBridge { }); } + /** + * Stereo depth for a surface, applied while it is the topmost visible + * surface and opaquely covers the screen; takes effect at its next frame. + */ + async setSurfaceDepth(id: string, depth: number): Promise { + await this.enqueueJavaCall(() => { + this.communicator.setSurfaceDepth(id, Math.round(depth)); + }); + } + /** * Blank (screen off) or unblank the composited output; retained surface * state survives, so unblanking restores the screen without repaints. diff --git a/app/native/preview-display.ios.ts b/app/native/preview-display.ios.ts index 250b6f07..2a70a769 100644 --- a/app/native/preview-display.ios.ts +++ b/app/native/preview-display.ios.ts @@ -14,6 +14,7 @@ export type DisplayTarget = Pick< | "configureSurface" | "removeSurface" | "setSurfaceVisible" + | "setSurfaceDepth" | "setUnderlayDim" | "setScreenBlanked" | "submitSurfaceFrame" @@ -80,6 +81,10 @@ export class PreviewDisplayTarget implements DisplayTarget { this.composited(); } + async setSurfaceDepth(id: string, depth: number): Promise { + this.compositor.setSurfaceDepth(id, Math.round(depth)); + } + async setUnderlayDim(belowZOrder: number, factor: number): Promise { this.compositor.setUnderlayDim(Math.round(belowZOrder), Math.max(0, Math.min(1, factor))); this.composited(); diff --git a/app/native/preview-display.ts b/app/native/preview-display.ts index 729d66f5..33a226de 100644 --- a/app/native/preview-display.ts +++ b/app/native/preview-display.ts @@ -19,6 +19,7 @@ export type DisplayTarget = Pick< | "configureSurface" | "removeSurface" | "setSurfaceVisible" + | "setSurfaceDepth" | "setUnderlayDim" | "setScreenBlanked" | "submitSurfaceFrame" @@ -98,6 +99,10 @@ export class PreviewDisplayTarget implements DisplayTarget { this.compositor.setSurfaceVisible(id, Boolean(visible)); } + async setSurfaceDepth(id: string, depth: number): Promise { + this.compositor.setSurfaceDepth(id, Math.round(depth)); + } + async submitShellScene(bytes: Uint8Array, paintMs = 0, frameId = 0): Promise { this.compositor.submitShellScene(new Uint8Array(bytes).buffer, paintMs, frameId); } diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt index f8045e86..0c63cb8d 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawCallType.kt @@ -9,3 +9,4 @@ const val DRAW_OP_TEXT = 5 const val DRAW_OP_REMAP_COLORS = 6 const val DRAW_OP_DISPLAY_LIST = 7 const val DRAW_OP_ROUNDED_RECT = 8 +const val DRAW_OP_CLEAR = 9 diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt index 0883a49f..3d3e9537 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt @@ -1,6 +1,6 @@ package com.faceclaw.app -/** Revision 27 wire grammar, shared by scene planning and the local renderer. */ +/** Revision 28 wire grammar, shared by scene planning and the local renderer. */ object DrawProtocol { /** Mirrors g2flash/patches/zlib_glue.c. */ const val DRAW = CFW_MSG_DRAW_CALLS @@ -107,6 +107,20 @@ object DrawProtocol { writeS16(dy) } + /** Fill the whole target, ignoring depth. */ + fun clear(color: Int = 0, target: Int? = null): ByteArray { + require(color in 0..15) + return call(DRAW_OP_CLEAR, target) { writeU8(color) } + } + + /** + * The copy that starts every root list: firmware presents only what the root + * draws. A shifted copy clears first so its uncovered edge is not stale. + */ + fun screenCopy(width: Int, height: Int, depth: Int = 0): List = + if (depth == 0) listOf(rectCopy(SCREEN, 0, 0, width, height, 0, 0)) + else listOf(clear(), rectCopy(SCREEN, 0, 0, width, height, 0, 0, depth = depth)) + fun stockText(x: Int, y: Int, options: Int, text: ByteArray): ByteArray { require(text.size <= 255) return call(DRAW_OP_STOCK_FONT_STRING) { diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt index fb85df35..3d290298 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionCore.kt @@ -930,6 +930,9 @@ class GlassesSessionCore( * actually appear — otherwise a static window (e.g. the terminal hub) whose * frame landed while briefly hidden would stay blank until its next repaint. */ + /** Stereo depth for a full-screen surface; applies from its next frame. */ + fun setSurfaceDepth(id: String, depth: Int) = compositor.setSurfaceDepth(id, depth) + fun setSurfaceVisible(id: String, visible: Boolean) { // Its own frame: this recomposite is a real screen update with real // latency, and without one it would show up in other frames' logs only diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt index 5e386ee2..08a9c5bd 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt @@ -164,9 +164,11 @@ class DisplayListRenderer( val frame = DrawEvaluation(elapsedMs) val references = mutableSetOf() for (apply in listOf(false, true)) { - if (apply) copyScreen(screen, composition) + // A root list composes the whole frame, including its screen copy. if (root != DrawProtocol.SCREEN) { executeList(root, composition, Walk(screen, apply, references, frame)) + } else if (apply) { + copyScreen(screen, composition) } } animationPending = frame.animationPending @@ -226,6 +228,7 @@ class DisplayListRenderer( DRAW_OP_TEXT -> drawText(reader, target, walk) DRAW_OP_REMAP_COLORS -> remapColors(reader, target, walk) DRAW_OP_ROUNDED_RECT -> drawRoundedRect(reader, target, walk) + DRAW_OP_CLEAR -> clear(reader, target, walk) DRAW_OP_DISPLAY_LIST -> { val id = reader.readU16() reader.requireDone() @@ -360,6 +363,13 @@ class DisplayListRenderer( } } + private fun clear(reader: DrawReader, target: Target, walk: Walk) { + val color = reader.readU8() + reader.requireDone() + require(color <= 15) + if (walk.apply) target.bytes.fill((color * 17).toByte(), target.offset, target.offset + target.stride * target.height) + } + private fun drawRoundedRect(reader: DrawReader, target: Target, walk: Walk) { val x = ExtendedVarint.evaluate(reader, walk.frame) val y = ExtendedVarint.evaluate(reader, walk.frame) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt index c48a81c2..304cb75d 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/ShellScene.kt @@ -1,15 +1,16 @@ package com.faceclaw.app /** Immutable shell snapshot. Keys identify writable surfaces across repaints, not their pixels. */ -class ShellScene(val layers: List, val selections: List = emptyList()) { +class ShellScene(val layers: List, val selections: List = emptyList(), val screenDepth: Int = 0) { class Layer(val key: Int, val x: Int, val y: Int, val width: Int, val height: Int, val dim: Int, val packed: ByteArray, val selections: List = emptyList(), val depth: Int = 0) val allSelections = selections + layers.flatMap { it.selections } val retainedResources = allSelections.flatMap { it.resources } - init { require(retainedResources.size + layers.size < 511) } - val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${it.depth},${CachedResource(it.packed).hash},${it.selections.joinToString { row -> row.fingerprint }}" } + selections.joinToString { it.fingerprint } + init { require(retainedResources.size + layers.size < 511 && screenDepth in -128..127) } + val fingerprint: String = layers.joinToString(";") { "${it.key},${it.x},${it.y},${it.width},${it.height},${it.dim},${it.depth},${CachedResource(it.packed).hash},${it.selections.joinToString { row -> row.fingerprint }}" } + selections.joinToString { it.fingerprint } + "|depth:$screenDepth" fun calls(width: Int, height: Int, surfaces: IntArray, selected: IntArray): List { val calls = ArrayList(); var rowId = 0 val now = drawAnimationTimeMs() + calls.addAll(DrawProtocol.screenCopy(width, height, screenDepth)) fun add(row: RetainedDrawing) { calls.addAll(row.calls(selected.copyOfRange(rowId, rowId + row.resources.size), now)) rowId += row.resources.size diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt index 0a52c70e..14e4e728 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/SurfaceCompositor.kt @@ -274,6 +274,9 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr @JvmField var visible: Boolean = true + /** Stereo depth; see setSurfaceDepth. */ + @JvmField var depth: Int = 0 + @JvmField var pixels: ByteArray = ByteArray(0) @JvmField var fingerprint: String = "" @@ -419,6 +422,27 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr } } + /** + * Stereo depth (DrawProtocol.depthOffset) for a surface. It applies while the surface is the + * topmost visible one and opaquely covers the screen: the glasses then copy the whole screen + * into the frame shifted per lens. Takes effect when the next frame composites. + */ + fun setSurfaceDepth(id: String, depth: Int): Unit { + require(depth in -128..127) { "bad depth $depth for $id" } + lock.withLock { + val surface = surfaces.get(id) ?: throw IllegalArgumentException(("unknown surface " + id)) + surface.depth = depth + } + } + + /** The screen's stereo depth: see setSurfaceDepth. */ + private fun screenDepthLocked(ordered: List): Int { + val top = ordered.lastOrNull { it.visible } ?: return 0 + val covers = top.transparency == TRANSPARENCY_OPAQUE && top.x <= 0 && top.y <= 0 && + top.x + top.width >= screenWidth && top.y + top.height >= screenHeight + return if (covers) top.depth else 0 + } + /** * While blanked (screen off), composites are all-zero regardless of surface content; retained * state is untouched, so unblanking restores the screen without asking sources to repaint. @@ -681,7 +705,9 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr fingerprint.append(":dim").append(dim) } } - val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene.EMPTY else ShellScene(shellScene?.layers ?: emptyList(), selections) + val screenDepth = screenDepthLocked(ordered) + val scene = if (surfaces.values.any { it.visible && it.zOrder > 1 }) ShellScene(emptyList(), screenDepth = screenDepth) + else ShellScene(shellScene?.layers ?: emptyList(), selections, screenDepth) val sceneKey = fingerprint.append("|shell:").append(scene.fingerprint).toString() val preview = if (includePreview && (shellScene != null || selections.isNotEmpty())) { previewScene(scene, gray, sceneKey) diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt index c2a9b2ea..e9f6be48 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/IosNativeApi.kt @@ -223,6 +223,8 @@ class IosSurfaceCompositor(width: Int, height: Int) { fun visible(id: String, visible: Boolean) = compositor.setSurfaceVisible(id, visible) + fun depth(id: String, depth: Int) = compositor.setSurfaceDepth(id, depth) + fun dim(below: Int, factor: Double) { require(factor.isFinite()) compositor.setUnderlayDim(below, (factor.coerceIn(0.0, 1.0) * 256).toInt()) diff --git a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt index f4fe2b3d..37b5fcf8 100644 --- a/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt +++ b/native/kotlin/shared/src/iosMain/kotlin/com/faceclaw/app/ble/IosGlassesSession.kt @@ -207,6 +207,8 @@ class IosGlassesSession internal constructor( fun setSurfaceVisible(id: String, visible: Boolean) = core.setSurfaceVisible(id, visible) + fun setSurfaceDepth(id: String, depth: Int) = core.setSurfaceDepth(id, depth) + fun setScreenBlanked(blanked: Boolean) = core.setScreenBlanked(blanked) fun configureSurface(id: String, x: Int, y: Int, width: Int, height: Int, zOrder: Int, transparency: Int) = diff --git a/tests/ios-glanceboard.test.cjs b/tests/ios-glanceboard.test.cjs index 35f5808e..aac52891 100644 --- a/tests/ios-glanceboard.test.cjs +++ b/tests/ios-glanceboard.test.cjs @@ -27,7 +27,7 @@ function fixture() { let now = 1000, nextTask = 0, screenOn = true, shellOptions; const tasks = new Map(), sent = [], previews = [], received = [], errors = []; const boardStats = { starts: 0, stops: 0, paints: 0 }; - const settings = { lock: true, enabled: true, tap: true, hold: true, tilt: true, duration: 3000 }; + const settings = { lock: true, enabled: true, tap: true, hold: true, tilt: true, duration: 3000, depth: 0 }; const clock = { Date: class extends Date { static now() { return now; } }, setTimeout: (fn, ms) => { tasks.set(++nextTask, { fn, at: now + ms }); return nextTask; }, clearTimeout: id => tasks.delete(id), setInterval: () => ++nextTask, clearInterval() {} }; @@ -63,6 +63,8 @@ function fixture() { async configureSurface(id, options) { this.compositor.configureSurface(id, options); } async removeSurface(id) { this.compositor.removeSurface(id); this.changed(); } async setSurfaceVisible(id, visible) { this.compositor.setSurfaceVisible(id, visible); this.changed(); } + depths = []; + async setSurfaceDepth(id, depth) { this.depths.push([id, depth]); this.compositor.setSurfaceDepth(id, depth); } async setUnderlayDim(below, factor) { this.compositor.setUnderlayDim(below, factor); this.changed(); } async setScreenBlanked(blanked) { this.compositor.setScreenBlanked(blanked); this.changed(); } async submitSurfaceFrame(id, pixels, rect, _fingerprint, _paintMs, _frameId, draws = null) { this.compositor.submitSurfaceFrame(id, pixels, rect, draws); this.changed(); } @@ -96,7 +98,7 @@ function fixture() { const provider = { isEnabled: () => settings.enabled, showOnTap: () => settings.tap, showOnLongPress: () => settings.hold, showOnHeadTilt: () => settings.tilt, - tapTimeoutMs: () => settings.duration, + tapTimeoutMs: () => settings.duration, depth: () => settings.depth, createBoard: () => ({ start: () => boardStats.starts++, stop: () => boardStats.stops++, paint: () => { boardStats.paints++; return new images.GrayImage(100, 80, 200); } }), }; @@ -194,6 +196,16 @@ test('iOS sleep tap shows the shared board; repeated tap renews timeout and hide assert.equal(f.boardStats.starts, 1); assert.equal(f.boardStats.stops, 1); }); +test('Glanceboard applies its depth setting to its surface only when it changes', async () => { + const f = fixture(); await f.connect(); f.shell.sleep(); await f.render(); + f.settings.depth = 32; await f.hardware(0); assertBoard(f.sent.at(-1)); + await f.advance(3100); await f.render(); assert.equal(f.controller.glance.isVisible(), false); + await f.hardware(0); assert.equal(f.controller.glance.isVisible(), true); + await f.advance(3100); await f.render(); + f.settings.depth = 0; await f.hardware(0); + assert.deepEqual(f.controller.display.depths, [['glance', 32], ['glance', 0]]); +}); + test('iOS holds and tap-then-holds last until release, including with phone backgrounded', async () => { const f = fixture(); await f.connect(); f.shell.sleep(); f.controller.pause(); const previews = f.previews.length; diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt index 802d54fa..a3fb26d9 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt @@ -51,15 +51,43 @@ class DisplayListTest { val calls = listOf(DrawProtocol.call(DRAW_OP_DISPLAY_LIST,DrawProtocol.word(20)), DrawProtocol.image(10,3,1), DrawProtocol.call(DRAW_OP_TEXT,hex("0c00070003000f0141")), DrawProtocol.lut(8,4,128)) resources[21]=DrawProtocol.displayList(calls) - val screen=hex("123456789abcdef0123456789abcdef0"); val output=ByteArray(16) + // Like the C harness, seed composition with the screen: this list has no screen copy. + val screen=hex("123456789abcdef0123456789abcdef0"); val output=screen.copyOf() val renderer=DisplayListRenderer(resources) assertEquals(setOf(10,11,12,20,21),renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4))) // Shared with the C sanitizer harness: signed clipping, resource target override, font and LUT. assertContentEquals(hex("71122334755061700112233445534477"),output) - val first=output.copyOf(); renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4)) + val first=output.copyOf(); screen.copyInto(output); renderer.render(21,DisplayListRenderer.Target(screen,8,4),DisplayListRenderer.Target(output,8,4)) assertContentEquals(first,output) assertContentEquals(hex("123456789abcdef0123456789abcdef0"),screen) } + @Test fun rootListsComposeTheScreenCopyAndClearBeforeDepthShifts() { + val screen = ByteArray(640 * 480 / 2) { (0x12 + it * 0x22).toByte() } + val sourceTarget = DisplayListRenderer.Target(screen, 640, 480) + // Without a copy, a root presents only what it draws. + val empty = mapOf(1 to DrawProtocol.displayList(emptyList())) + val composition = ByteArray(screen.size) { 0x55 } + DisplayListRenderer(empty).render(1, sourceTarget, DisplayListRenderer.Target(composition, 640, 480)) + assertTrue(composition.all { it == 0x55.toByte() }) + for (depth in listOf(-64, -17, 0, 1, 32)) for (right in listOf(false, true)) { + val resources = mapOf(1 to DrawProtocol.displayList(DrawProtocol.screenCopy(640, 480, depth))) + val output = ByteArray(screen.size) { -1 } + val target = DisplayListRenderer.Target(output, 640, 480) + DisplayListRenderer(resources, rightLens = right).render(1, sourceTarget, target) + val shift = DrawProtocol.depthOffset(depth, right) + for (y in listOf(0, 479)) for (x in 0 until 640) { + val sx = x - shift + assertEquals(if (sx in 0 until 640) sourceTarget.get(sx, y) else 0, target.get(x, y), "depth=$depth right=$right x=$x") + } + } + // Clear fills the whole resource target, padding included, and ignores depth. + val raw = DrawProtocol.rawImage(3, 2, hex("1234ab12")) + DisplayListRenderer(mapOf(5 to raw)).execute(DrawProtocol.sequence(listOf(DrawProtocol.clear(7, target = 5))), + DisplayListRenderer.Target(ByteArray(1), 1, 1)) + assertContentEquals(DrawProtocol.rawImage(3, 2, hex("77777777")), raw) + val rejected = DrawProtocol.call(DRAW_OP_CLEAR, hex("10")) + assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(rejected)), DisplayListRenderer.Target(ByteArray(1), 1, 1)) } + } @Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() { val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1) val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff000000000600010002000000")) @@ -80,7 +108,7 @@ class DisplayListTest { val screen = hex("012345601234560112345601234560122345601234560123345601234560123445601234560123455601234f60123456601234560123456001234560123456011234560123456012234560123456012334560123456012344560123456012345") val expected = listOf("01234560123456011aaaaaaaaaa56012aa45644444aa0123a4564444456a1234a564f44f564a2345a6444fff644a3456a4444456444a4560aa44456444aa56011aaaaaaaaaa56012234560123456012334560123456012344560123456012345", "012345601234560112aaaaaaaaaa60122aa56444445aa1233a5644444564a2344a644f44f644a3455a4444ff6444a4566a4444564444a5600aa44564444aa60112aaaaaaaaaa6012234560123456012334560123456012344560123456012345") for (right in listOf(false, true)) { - val output = ByteArray(screen.size) + val output = screen.copyOf() // the shared vector's list has no screen copy DisplayListRenderer(resources, rightLens = right).render(42, DisplayListRenderer.Target(screen,16,12), DisplayListRenderer.Target(output,16,12)) assertContentEquals(hex(expected[if(right) 1 else 0]), output) } @@ -189,6 +217,36 @@ class DisplayListTest { assertTrue(reconnect.commands.any { it[0].toInt()==29 });glasses.apply(reconnect.commands) assertContentEquals(newer,glasses.screen) } + @Test fun fullScreenSurfaceDepthShiftsThePresentedScreenPerLens() { + val c = SurfaceCompositor() + c.configureScreen(640, 480) + c.configureSurface("app", 0, 0, 640, 480, 0, 0) + c.configureSurface("glance", 0, 0, 640, 480, 900, 0) + val board = ByteArray(640 * 480) { if (it % 640 in 100 until 110) 255.toByte() else 0 } + c.submitSurface("glance", ArrayByteReader(board), 0, 0, 640, 480, "board") + c.setSurfaceDepth("glance", 32) + assertEquals(32, c.composite().shellScene.screenDepth) + // Only the topmost visible surface counts, and only when it opaquely covers the screen. + c.configureSurface("partial", 0, 0, 10, 10, 950, 0) + assertEquals(0, c.composite().shellScene.screenDepth) + c.setSurfaceVisible("partial", false) + c.setSurfaceVisible("glance", false) + assertEquals(0, c.composite().shellScene.screenDepth) + c.setSurfaceVisible("glance", true) + val composite = c.composite() + val screen = BmpUtil.pack4bppFromGray8(composite.screenGray, 640, 480) + for (right in listOf(false, true)) { + val glasses = Glasses(right) + glasses.composition.fill(-1) // stale pixels from an earlier frame + glasses.apply(ScenePlanner(ResourceCacheState()).plan(screen, 640, 480, null, composite.shellScene, 1).commands) + assertContentEquals(screen, glasses.screen) + val output = DisplayListRenderer.Target(glasses.composition, 640, 480) + val shift = if (right) -16 else 16 + assertEquals(15, output.get(100 + shift, 0)); assertEquals(0, output.get(99 + shift, 0)) + assertEquals(15, output.get(109 + shift, 479)); assertEquals(0, output.get(110 + shift, 479)) + assertEquals(0, output.get(if (right) 639 else 0, 240)) // cleared, not stale + } + } @Test fun noisyFramesRemainBoundedAndResourceBudgetIs192KiB() { val cache=ResourceCacheState();val planner=ScenePlanner(cache);val glasses=Glasses() val app=ByteArray(640*480/2){(it*37).toByte()} diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt index 11fd7001..d42f3ff5 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawExpressionTest.kt @@ -74,7 +74,7 @@ class DrawExpressionTest { @Test fun playerSchedulesOnlyUnfinishedFramesAndCancelsStaleCallbacks() { val call = DrawProtocol.roundedRect(DrawValue.Integer(0), DrawValue.animate(0, 4, 300), 2, 2, 0, 15) - val renderer = DisplayListRenderer(mapOf(1 to DrawProtocol.displayList(listOf(call)))) + val renderer = DisplayListRenderer(mapOf(1 to DrawProtocol.displayList(DrawProtocol.screenCopy(4, 8) + call))) val screen = DisplayListRenderer.Target(ByteArray(16), 4, 8) val output = DisplayListRenderer.Target(ByteArray(16), 4, 8) var now = 1000L diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt index 90e0cff8..52db8cf2 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt @@ -5,7 +5,7 @@ import kotlin.test.* class DrawWireTest { private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray() - @Test fun encodersUseRevision27CoordinatesAndPreserveOtherWireBytes() { + @Test fun encodersUseRevision28CoordinatesAndPreserveOtherWireBytes() { // Literal vectors pin the firmware grammar independently of the reader. val calls = listOf( DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to @@ -20,12 +20,20 @@ class DrawWireTest { DrawProtocol.lut(640, 480, 256) to "0600000000008002e0010123456789abcdef", DrawProtocol.bbox(hex("ffffffffffffffff"), 4, 0, 0, 8, 2) to "010000000002010f10", DrawProtocol.bbox(hex("0f"), 1, 1, 0, 1, 1) to "01000101000000010001001f", + DrawProtocol.clear(15, target = 511) to "0901ff010f", ) for ((call, expected) in calls) assertContentEquals(hex(expected), call) assertContentEquals(hex("0100050007027fff01"), DrawProtocol.sequence(listOf(calls[4].first))) assertContentEquals(hex("1a0100050007027fff01"), DrawProtocol.message(listOf(calls[4].first))) assertContentEquals(hex("020100050007027fff01"), DrawProtocol.displayList(listOf(calls[4].first))) assertContentEquals(hex("1bffff"), DrawProtocol.root(DrawProtocol.SCREEN)) + val flat = DrawProtocol.screenCopy(640, 352) + assertEquals(1, flat.size) + assertContentEquals(hex("0200ffff000000008002600100000000"), flat[0]) + val shifted = DrawProtocol.screenCopy(640, 352, -32) + assertEquals(2, shifted.size) + assertContentEquals(hex("090000"), shifted[0]) + assertContentEquals(hex("0202e0ffff000000008002600100000000"), shifted[1]) } @Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() { From c801bd5185503e39f13699e204d0a13d2eba5530 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Thu, 24 Sep 2026 11:04:10 -0700 Subject: [PATCH 21/27] Animate scrolling in menus --- CHANGELOG | 8 +- app/g2/firmware-compat.ts | 2 +- app/g2/firmware/cfw-patches.ts | 16 +- app/graphics/display-list.md | 21 ++- app/graphics/display-list.ts | 14 +- app/graphics/draw-expression.ts | 15 +- app/graphics/menu-scroll-list.ts | 46 ++++++ app/ui/menu-core.ts | 134 ++++++++++++++-- app/ui/menu-highlight-motion.ts | 12 +- app/ui/menu-scroll-motion.ts | 53 +++++++ .../faceclaw/app/g2protocol/DrawProtocol.kt | 17 +- .../app/graphics/DisplayListRenderer.kt | 12 +- .../faceclaw/app/graphics/FrameDisplayList.kt | 18 ++- tests/brightness-picker.test.cjs | 4 +- tests/display-list-authoring.test.cjs | 2 +- .../com/faceclaw/app/DisplayListTest.kt | 13 +- .../kotlin/com/faceclaw/app/DrawWireTest.kt | 10 +- .../com/faceclaw/app/FrameDisplayListTest.kt | 22 ++- tests/menu-core.test.cjs | 32 ++-- tests/menu-display-list.test.cjs | 4 +- tests/menu-scroll-animation.test.cjs | 146 ++++++++++++++++++ tests/music-settings.test.cjs | 2 +- tests/notification-filter.test.cjs | 2 +- 23 files changed, 514 insertions(+), 91 deletions(-) create mode 100644 app/graphics/menu-scroll-list.ts create mode 100644 app/ui/menu-scroll-motion.ts create mode 100644 tests/menu-scroll-animation.test.cjs diff --git a/CHANGELOG b/CHANGELOG index 1cf5da58..52e40066 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,12 +2,18 @@ ## 0.7.3 - Future +### Depth and Animation + +* A new display-list system for glasses-side drawing, unlocking z-effects and animation +* Menus animate when changing selection and scrolling +* Depth effects for the window switcher, top bar, and modals +* Glanceboard has configurable distance + ### Other Features * Add tokens and faceclaw-input script, which allows using a CLI utility as an input device for the glasses * Navigate app: Add map-without-destination mode * Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space -* Glanceboard: Add distance setting ### iOS port: diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index 943d7166..894d8c80 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -26,7 +26,7 @@ export type FirmwareInfo = { }; /** The Faceclaw firmware revision this build of the app needs. */ -export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 28; +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 29; const FACECLAW_PREFIX = "Faceclaw/"; const LEGACY_PREFIX = "EVENCFW"; diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index f5af85fd..f5041484 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,7 +19,7 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "8dbb39ad4acaf430e889ff98fe698ccb54d55c19d90a4d7053ce0fb804adb11b", + "outputSha256": "0275d20b0e50cd8fccc2eb4209384cac93ff3ae22149ddcc70da4a375440c818", "patches": [ { "offset": 1045797, @@ -210,43 +210,43 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f05df8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef715fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef7cbfd0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f012fb0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf069fd48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf0e3fc414602e0022084f8200350460c22fdf7d2ff94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7a2ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf771ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf71bff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf05ffcd8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf025fe0bf0f9fd294630b9ffe50bf0f4fd002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7bdfd0fe04eea062141ea0b4141ea05633946624665460bf0f3fb00281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af019fcd4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f213040af0c9f84ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b700af0b6f8e05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f0e2ff059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f014ff28461a21224609f091fd00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f003fd854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f0fffc706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f0ecfb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f092fc606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf751f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009508f03cfb606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7a3fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009708f04df8002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009508f02ff8606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009508f002f8606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f0d7ff606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf7dbf904f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf797f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf741f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f0f4fd019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f65c01c0f20001033079440b22f9f710fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f7d8fb0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f729fb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f77ffa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f68600c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f7ddfb4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f7f1fb4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f70afbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f729fb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009503f093fc3eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb00446002047f64c68a4f88003c2f20708d8f80000002a8b461abfc4f874030146d4f87413401ac4f87c03fdf762f8002800f0f980d4f86803002800f0f48004f0f8f9002800f0ef800646b4f86c03002848d0a0f10108d4f87c0300254ff4a0714ff4f0774ff48059cde90d050df1180acde901152046414632464ff42073cde906950c95cde9035a009703f03cfc002840f0c980d4f87c034146cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906950c95cdf810a0009703f020fc002840f0ad809df8380094f8801347f64c68084384f88003c2f2070806e0d4f8681330464ff41632f7f712f94ef66c694ff29c57ccf2ff09c2f229074ff6ff76002506e048f2a351c0f24501bff32f8f8847d7f800a0bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168494548d04ff46d70fdf781fe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d10121c0f8009081728683c683068446848684c684068546858685c685068646868686c6860687468757e8001f5145aad1bff35f8f00bf47e8000121b157e8001f5145f8d09fe7054604f031f9002d18bf002803d101208bf8050022e0c5f860014ff001094ff4f07085f8649101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718bf8059004e09bf805008bf8049030b14ff0ff300fb0bde8f08f0025cbe794f8800384f8810348b3d4f8700342f66535c0f2440528b1d8f800102d31c4f8781311e044f21740c0f200007844002122460023a847c4f87003d8f8001001f12d01c4f8781320b105f1e8022d21904728b1002084f881030fb0bde8f08f00200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2045d279008784f7801eb020c50ea072001f10204239002f0a3820df5a567e0cf42a8063000211690cde9203c644502f09182601c604502f08d82269120786178a21c40ea0121aceb020081422892299102f28082ddf83c2530a8e8c01068ddf8341500283491a0f10101116002f072822998002802f06e822998871c032f02f06982e678032e02f26582289890f80090f00703d104f1040828e000bf299820f00100022802f0568294f804a0657927984aea052b594630aa02f05cfa002842f04982ddf8340504f10608012d34900dd8ddf83c05806948b14feadb020af00701835c012505fa01f119438154022e04eb070503d2ddf834052b9026e0a8452f4603d0444614f9015b01e000253c4645f64d5ac0f2460ad047012808bf0135681e81b26e0800ebd130002d48bf4610d0470128ddf8340508bf76423118b845a0463d462b91349102f00582b9f1040f29ddb9f1060f40f35081b9f1070f00f0ad83b9f1080f00f0be81b9f1090f42f0f281a84502f0ef8118f8011ba84542f0ea810f2902f2e781ddf83805002801f01081dde93223309801eb01115a43f7f73af801f006b9b9f1020f00f39680b9f1010f00f08082b9f1020f42f0cc81a84502f0c98108f10100a84202f0c48108f10200a84202f0bf8108f10300a84202f0ba8108f10400a84202f0b58108f10500a84202f0b08108f10600a84202f0ab8108f10700a84202f0a68108f10800a84202f0a18108f10900a84202f09c8108f10a00a84202f0978108f10b00a84202f0928108f10c00a84202f08d8108f10d00a84202f0888108f10e00a84242f0838198f8020098f800a02e9098f8030098f801b02d9098f80500309c2c9098f8080098f804e02f9098f80a0098f80630249098f80b0098f8072098f80990229098f80cc098f80d60dde93181339f4aea0b254ff6fe70854242942591cde94381459700f05b864ff6ff70854240f02c862798d0f868134ff4207043904ff4f07044904ff4a070459000f049beb9f1030f00f03e82b9f1040f42f03681b5eb080402f0328108f10100a84202f02d812798002802f02981a01e0528c2f0258108f10700a84242f020812798d0f86c01002802f01a8198f80110012902f2158198f8003043ea012250f82210002902f00c810f1ab90742f008816ff4403140f60f063944cff6fd76b142c2f0fe80384450f8081c914242f0f88050f80c1ca1f1011616f5803fc2f0f080002802f0ed8050f8046c8e4242f0e880c7f54037b94202f2e380ddf83c75bf6947b1d20803f00703be5c012505fa03f33343bb540df1c00a9ae84006339d00223aab02f029f900284ff0000708bf4ff0ff3702f05280ddf83805ddf884c02699002802f04d80072c4ff0ff3742f04880002e02f04580fcf72dfd002840f0998302f039b8b9f1050f00f08382b9f1060f42f0a680a84502f0a38008f10100a84202f09e8008f10200a84202f0998008f10300a84202f0948008f10400a84202f08f8008f10500a84202f08a8008f10600a84202f0858008f10700a84202f0808008f1080ca5eb0c000828c2f0798008f11000a84242f0748098f8040098f8051050ea01261ebf98f8060098f8071050ea012502f0658098f8000098f80120319940ea0224081bc2f05b80864202f2588098f8020098f80330329a40ea0327d01bc2f04e80854202f24b80ddf83805002800f074873098339bcde901472b9fcdf814c0cde90365009702f0a6ff00f066bfddf83c05cde94285c069002142af3aaddde9304bdde932964491cde93a013846294603f04ff982463846294603f04af94499002941f0a787dde942218a4201f0a287531c8b4201f09e87931c8b4201f09a87d31c8b4201f09687131d8b4201f09287531d8b4201f08e87931d8b4201f08a87d31d8b4201f0868702f108038b4241f08187117853784ff0ff3c51ea032101f08e879378d77853ea072301f08887b1f5207f01f28487b3f5f07f01f2808797790f2f259701f27b87d5796746102d2f9501f262872493ddf83c352c903b981f6a92f804c03843ddf838755279002f1c962a94186201f032872b980023084440428245c1f25e872b98abeb0000824581f25887249847422c98b842c1f252872c98ddf870e0249c81451f4641f335874cea0222b2eb510f28bf4a08b2eb540f28bf62081d92013a4ff0000738bf3a461292424202eae078a9eb0002a242a8bf22469045229281f218872b9a1d9b92445a001f9203fb03f292001b9201eb0a0203294ff000012d9238bf01210022032c38bf012211431a91611e1891a11e159112994ff000094a00494389000f910af1010113912f9914920a0141ea011110916ff00801119201eb43012a9a179120eae0710efb01250026cdf864a001f03dbba84501f04d87414611f8010b012801f24787309addf8cce02d92319a00282f92329a2e9200f0df81a94201f0398708f10201a94201f0348708f10301a94201f02f8708f10401a94201f02a8708f10501a94201f0258708f10601a94201f0208708f10701a94201f01b8708f10801a94201f0168798f8011098f8022098f8043041ea022198f80320474698f8056098f8064042ea0328fa793b7a093746ea04261a9742ea0322bee1a5eb080bbbf1050fc1f0f68608f10509a94501f0f18608f1060698f80570a81bb842c1f0e986f019a84241f0e58630981b90dde93150249033981a90b7b1002403e000bf0134bc4210d2305d01381e28f8d93019391b42aa3aab02f093f9002801f0ca8642980444bc42eed3ddf83805002800f0ef85bbf1050f2c9501f0bc861b98002801f0b886fcf730fb002801f0b38699f800a00af10600834541f0ac8647f65420c2f20700d0f800b0bbf1000f01f0a2869bf80c009bf80d109bf80e209bf80f3040ea012040ea024040ea0365a5f1810010f1800fc1f08e869bf810009bf811109bf8132040ea01209bf8121040ea014040ea02600c90813810f5817f41f27a86baf1000f4ff000002e9000f04a844ff0000900270be000bf00f1004042a941f824000137574504f1010980f0ea83f05d4c46411e1e29efd9f019aaeb07013aaa36ab02f01df9002801f0df853a99369842aa0f4442f82400e4e7a84501f04a8608f10100a84201f0458608f10200a84241f0408698f8000098f8011030af40ea0121ddf83c058ccf0490ddf83805339e03902b98019602902798009702f0aefe074601f0b4bdb5eb080a01f0238608f10100a84201f01e86aaf102000528c1f0198608f10700a84201f014862798002801f0108608f1080998f80740a5eb0900a042c1f0078609eb0400a84241f002862798d0f86c31002b01f0fc8598f80100012801f2f78598f8001041ea002053f82020002a01f0ee85d21a970741f0ea856ff4403740f60f061744cff6fd76b742c1f0e0859e1856f8083c834241f0da8556f80cbcabf1011313f5803fc1f0d285002e01f0cf8556f8043c5b4541f0ca85c2f54032934501f2c585ddf83c25926942b1c00801f00701135c012707fa01f119431154bbf1c10fc1f0b4853078012841f0b08530982f9031982e9032982d9033982c9014b3a6f13f074d4602e000bf013c1bd015f8010b411e1f29f8d341b22029c1f2978507eb400117f81000497840ea0122c12ac1f08d853046594642ab01f0e4fd0028e3d101f084bdddf83805002800f0ad840020baf1080f4ff0ff374290c1f004852f98002801f00085fcf7ebf9002801f0f98498f8074004f10800824541f0f28498f8000098f8017098f806a040ea072600f097bca94201f05a8508f10201a94201f0558508f10301a94201f0508508f10401a94201f04b8598f80220474698f801104fea4208fa783b7996007a1d89001a925a00002e1b9201f039851b9a002a01f035852f9a521ac1f03185964201f22e852e9ab2eb0802c1f029851b9b934201f22585002878d02b98002301eb000a82e048f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f0da824ff46d70fdf71cf8002801f082844ff64c41cff6ff71002342180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa14297d1bff35f8f42e80001002900f08b8252e8001fa142f6d08be72b98002301eb000ac00708d1baf1000f05d42f9906eb0a008842d8bf01231a991b9a681a1890ddf8380502fb06fcb0fa80f040091843c00700241e900a46002019932c90cde91c5c0fe000bf2c982a9918442c90249881424ff0000088bf01200443259ae00708bf0a44e00704d02c98844508d801f06ebcaa4200f078832c98844540f27483af1a01f064841078030902d0012112e000bf012f01f05b8453780bb102210ae0042fc1f054849178d37851ea032301f04e84042100bf2a912c99aceb01018b4201f245841e99cde924720029bbd1591e00f00f0903294fea001b1f94229380f080800021229bdde91c5c1f9c13f00300a9d02c9a1144b1fbf6f202fb161702eb080307eb0a0453ea040215d42f9a944212d22e9a93420fd22d9a03fb0e226308d75ce40707f00f0507f0f0074f4408bf45ea0b071c9dd754ddf874c01f9c229b01283ff480af4a1cb2fbf6f303fb1622434402eb0a0453ea040217d42f9a944214d22e9a934211d22d9a03fb0e226308d75ce40707f00f0507f0f0074f4408bf45ea0b071c9dddf874c0d7541f9c229b02283ff458af881cb0fbf6f101fb16004144504451ea00023ff54daf2f9a9042bff449af2e9a9142bff445af2d9a01fb0e2142088b5cc00703f00f0703f0f0034b4408bf47ea0b03ddf874c08b54229b31e723f0030000212b9005e000bf2b98043188423ff476af2c980844b0fbf6f303fb160503eb080405eb0a0c54ea0c0318d42f9a944515d22e9a944212d22d9a5feacc7704fb0e234fea5c041d5d724605f00f0e05f0f0054d4408bf4eea0b0596461d55431cb3fbf6f707fb163507eb080305eb0a0453ea040714d42f9a944211d22e9a93420ed22d9a670803fb0e23e407dd5d05f00f0205f0f0054d4408bf42ea0b05dd55821cb2fbf6f303fb1622434402eb0a0453ea040214d42f9a944211d22e9a93420ed22d9a03fb0e226308d75ce40707f00f0507f0f0074f4408bf45ea0b07d7540330b0fbf6f202fb160002eb0803504453ea00023ff588af2f9a9042bff484af2e9a9342bff480af2d9a03fb0e224308d75cc00707f00f0507f0f0074f4408bf45ea0b07d7546fe72798cde91e26294642aacdf8a8c0cde91ce301f025fb002841f09d82ddf83c05dde91ce38069ddf8a8c0dde91e2688b1bbf1010f0ed8ea080af0070110f802c0012505fa01f141ea0c011f9eddf8a8c081541e9a4299002901f07d822a9753ea02204ff0ff371fbfcde91d321f912f9951ea092501f07182dde92d31439a41ea03218a42c1f06982521a904201f265822c9a449be2464eea022cb34663454ff00006a3eb0c0338bf01269d424ff0000388bf01233343c3f1000741f04e82ddf83835002b01f04982229a2b9e1306249a002743ea02431b149a19424581f23d824fea0b6343ea0a43259e1b14b34281f234824642b24241f330826e42b34241f32c82cdf870e002eae27e0eeb000622eae270a8eb0007a1eb0e09be4228bf3e46259903eae37b23eae3725d448b1a9d4238bf2b46ddf87ca01794a245aceb0b042b9300f04f860021154601f070b8b9f1000f2d9500f01f825d46a9f1010b4ff0000a42af08e0d3450af1010aa4f1010407f1040700f00c8242a850f82a100029f1d40020534684421dd007eb80067268b2f1ff3f18dc5a1c934514d0b268b2f1ff3f11dc9a1c93450dd0f268b2f1ff3f0adcda1c934506d032690433002a00f10400e0d400e0002228463aab36ae009601f088fd002801f0be8136980028c2d04af20d313aa8c0f24e018847bbe72d9501204ff00009d1e1d0f86c014ff0ff37002801f0aa8198f80110012901f2a58198f8002042ea012150f82120002a01f09c81121a930741f098816ff440333c4640f60f071344cff6fd77bb422746c1f08c81104450f8083c8b4241f0848150f80c1c0027a1f10113cff6ff77bb42c1f07a8100284ff0ff3701f0778150f8043c8b4241f07281c2f54032914201f26d81002242ab01f038fa002801f0648198f8031098f80200090698f8053041ea00402b9998f8042001eb2040190641ea024198f806200f24970602f00f0304eae7775f4389246743ff0a8df8d8700e2712f0200f08bf012703fb07f704fb07f74fead7278df8d9704ff00d0708bf022703fb07f704fb07f74fead7278df8da704ff00c0708bf032703fb07f704fb07f74fead7278df8db704ff00b0708bf042703fb07f704fb07f74fead7278df8dc704ff00a0708bf052703fb07f704fb07f74fead7278df8dd704ff0090708bf062703fb07f704fb07f74fead7278df8de704ff0080708bf072703fb07f704fb07f74fead7278df8df704ff0070708bf082703fb07f704fb07f74fead7278df8e0704ff0060708bf092703fb07f704fb07f74fead7278df8e1704ff0050708bf0a2703fb07f704fb07f74fead7278df8e2704ff0040708bf0b2703fb07f704fb07f74fead7278df8e3704ff0030708bf0c2703fb07f704fb07f74fead7278df8e4704ff0020708bf0d2703fb07f704fb07f74fead7278df8e5704ff0010708bf0e2703fb07f704fb07f74fead7278df8e6704ff0000708bf0f277b436343c2f300120914db0a049236aa4ff0000c8df8e7300392cde90001304629464a46534642af0297674601f0e9fc01f080b8aa4241f0f0802c98844541f0ec80ddf83805002818bf012019990840012810d12d98189908fb0e00770800eb5a021b98734601901a98009701f0a5f9002801f0d280ddf884c0269901f05fb848f2a351c0f24501bff32f8f88474ff29c50c2f229000568bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f059834ff46d70fcf7cbfb002801f031804ff64c41cff6ff71002300bf42180c3182f8b43382f8b53382f8b63382f8b73382f8b83382f8b93382f8ba3382f8bb3382f8bc3382f8bd3382f8be3382f8bf33e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa94296d1bff35f8f42e80001002900f0098352e8001fa942f6d08ae70020ab4602e04ff00009012098f804100f258c0601f00f0605eae474744389256c43e40a98f800e08df8d8400e2498f8012098f8023098f803702f9111f0200f08bf012406fb04f405fb04f44fead4248df8d9404ff00d0408bf022406fb04f405fb04f44fead4248df8da404ff00c0408bf032406fb04f405fb04f44fead4248df8db404ff00b0408bf042406fb04f405fb04f44fead4248df8dc404ff00a0408bf052406fb04f405fb04f44fead4248df8dd404ff0090408bf062406fb04f405fb04f44fead4248df8de404ff0080408bf072406fb04f405fb04f44fead4248df8df404ff0070408bf082406fb04f405fb04f44fead4248df8e0404ff0060408bf092406fb04f405fb04f44fead4248df8e1404ff0050408bf0a2406fb04f405fb04f44fead4248df8e2404ff0040408bf0b2406fb04f405fb04f44fead4248df8e3404ff0030408bf0c2406fb04f405fb04f44fead4248df8e4404ff0020408bf0d2406fb04f405fb04f44fead4248df8e5404ff0010408bf0e2406fb04f405fb04f44fead4248df8e6404ff0000408bf0f2466436e43ddf8b0a0f60a00288df8e76040f02a82120642ea0e412b9a380602eb21442d9940ea0340a9f1010501eb204000260b90cdf84090cde90d5b07e001f01f000b3801364e45044400f0088242a850f82610b1f1ff3ff1dd33469d421cd042a800eb83004268b2f1ff3f16dc0133ab4212d08268b2f1ff3f0fdc0133ab420bd0c268b2f1ff3f08dc0133ab4204d002690133002ae1d400e0002258463aab35af009701f08cfa002800f0da8135990029179100f0ca819df8f0009df8f110129650ea012e149400f0af819df8f4709df8f5603f049df8ef009df8ee1047ea06670c9e4fea002c41ea00229df8f20076449df8f33006eb27470b9e0004149d40ea0360f41b0126031405eb204706eb520015900ceb01001d92421e19927a1c1392ba1c0f92179a01f00301cdf870e005eb030ceb1a02f1010e06eb5002401a2e90d807ddf870b00df1d809229100212d904feacc702b90cde91e2406e000bf2a9996440131594500f05f8108192a91f6d424998842f3d21d990029f0d0dde91a214ff0000800fb021c1998cdf894e0032880f0b7802298ddf870b0dde91e24ddf894e00028dbd0179815992a9a5feac87602fb01032f984fea5801595c00f010004ff0010282ea101501f00f00cab208bf10090146002818bf01212943012918951ed118eb070e1bd4d64519d24fea5e011cf8012019f8000002f00f0402f0f00202431d4633465feace7608bf44ea0012ddf870b00df1d8091e462b460cf801202298dde91e24ddf894e0012897d008f101004008195c002ec8b24fea101008bf01f00f00c1b2002918bf0121189d294301291cd1139911eb080118d4514516d24fea510e11961cf80e6036ad285c06f00f0506f0f0060643c90708bf45ea00160cf80e60ddf894e0119e0df1d809229802283ff464af08f102004008185c002ec1b200f00f0008bf08090146002818bf0121189b194301297ff451af0f9911eb08013ff54caf5145bff449af4d081cf8053019f8000003f00f0603f0f00303430df1d809c90708bf46ea00130cf8053035e72e9808f1040840450ef1020e3ff449af2f981ef8013c00f01000012181ea1011d8b200230f2888bf01230b43012b07eb080318d1002b16d4534514d25c0800091cf804a019f800000af00f050af0f002ddf8b0a002430df1d809fe0708bf45ea00120cf804201ef8010c10f00f00024618bf01220a43012a17d15c1c15d4544513d262081cf8024019f8000004f00f05ddf8b4b045ea001504f0f004bbf1000f08bf44ea00050cf802509ef800000022c0b20f2888bf01220a43012a17d19c1c15d4544513d2620800091cf8024019f800003e462b9f04f00f0504f0f0040443002f374608bf45ea00140cf802409ef8000010f00f00024618bf0122114301297ff47eafd91c3ff57baf5145bff478af49081cf8012019f8000002f00f032d9c43ea001302f0f002002c08bf42ea00030cf8013064e74af20d313aa8c0f24e0188479df8ec009df8ed10ddf84090149cdde90d5b129e05e09df8ec009df8ed10ddf8409040ea0120f2e5002001e04ff0ff302e90ddf884c026992e9f00f0e4bcd0f86c114ff0ff3000293ef423af012f074600f2d68451f82600002800f0cf84401a82074ff0ff3740f0cb846ff4403240f60f030244cff6fd739a42c0f0c1840b1853f8081cb14240f0bb8453f80c6c0022a6f10111cff6ff729142c0f0b18453f8041cb14240f0ac84c0f5403086422a9600f2a6849b46002b00f0a2842a98c128c0f09e849bf80000012840f099844fea8a660f250af00f0705eae6767e4389256e43f60a8df8d8600e2698f8021098f8033098f804c098f805201af0200f08bf012607fb06f605fb06f64fead6268df8d9604ff00d0608bf022607fb06f605fb06f64fead6268df8da604ff00c0608bf032607fb06f605fb06f64fead6268df8db604ff00b0608bf042607fb06f605fb06f64fead6268df8dc604ff00a0608bf052607fb06f605fb06f64fead6268df8dd604ff0090608bf062607fb06f605fb06f64fead6268df8de604ff0080608bf072607fb06f605fb06f64fead6268df8df604ff0070608bf082607fb06f605fb06f64fead6268df8e0604ff0060608bf092607fb06f605fb06f64fead6268df8e1604ff0050608bf0a2607fb06f605fb06f64fead6268df8e2604ff0040608bf0b2607fb06f605fb06f64fead6268df8e3604ff0030608bf0c2607fb06f605fb06f64fead6268df8e4604ff0020608bf0d2607fb06f605fb06f64fead6268df8e5604ff0010608bf0e2607fb06f605fb06f64fead6268df8e6604ff0000608bf0f2677436f430020ff0a002c8df8e7703ef417ae1b0643ea01412b9b4d4603eb2146110641ea0c4000142490caf30010abf13f0a27462290a0e3a242154640f2168201211ee20120019018463b46259f59460097774601f054fe2c98be46229908f10108754488454ff0000780f2a0836fea080121448845b8bf41461f9a6fea4101114401295cdb1b9a4ff0ff3301fb11211d9a921b012a03eb420231db02fb02f38b422ddd179aa2eb460303f10807032f03f106021edb02fb02f48c421add052f03f1040218db02fb02f48c4214dd072f03f1020212db02fb02f48c420edd0436092fa3f1080203db5b438b421346dcdc083204e0013602e0023600e00336249c012e1edb0832931f5b438b4219dc022e16db131f5b438b4200f3b380022e0fd0931e5b438b4200f3ae80042e08db02fb02f38b4200f3a980043e02f10802e2d100262a9b08eb000101fb0e332f9906eb0a0210292d99a1eb06073ff473af2e93b8fa88f11a9b490919434cd11899884549d01599a8f10100a1eb08012b971e958842b8bf01466fea4100149908440128c0f2aa800f9900fb10101299a1eb09034ff0ff31012b01eb430178db01fb01f7874274dd5900a1f1090303f10807032f03f1060163db01fb01f484425fdd052f03f104015edb01fb01f484425add072f03f1020159db01fb01f4844255dd09f10409092fa3f1080103db5b4383420b46dbdc08314be022eae27c5f45a8bf5f46bc452b97bff622af5feacc701e950ad02e9b4fea5c00195c2f9a01f0f00111430cf1010c19542b984fea5c02b2eb500f1bd22e982b991e9f109d00eb5103b9180c4604f8015b9c4280f08380881c9842257080f08380cc1c9c4205707dd20437b81898422570ead378e02e9800eb5c0074e0013e5de7023e5be7033e59e709f1010904e009f1020901e009f10309b9f1010f23db08318b1f5b4383421edcb9f1020f19db0b1f5b43834200f3ce80b9f1020f11d08b1e5b43834200f3c980b9f1040f09db01fb01f3834200f3c480b9f1040901f10801ded14ff00009139822eae27e00eb090cdc45da46b8bfe246d6454dda5feace700ad02e9b4fea5e00195c2f9a01f0f00111430ef1010e19544fea5e07b7eb5a0f18d22e981e9b109d00eb5a04d919084600f8015ba04213d28a1ca242057020d2c81ca04215701bd20433da19a2420570ecd316e02e9800eb5e0212e0481c02e04a1c0ee020462b99c9076bd02b998c4568d20178119a01f00f011143017061e002465feaca7007d0d64505d21078119900f00f00084310702d996fea090001eb000a012001902e98259f594662465346009701f0a2fc2b982aeaea7c5845a8bf584684453eda86465feacc700ad02e9b4fea5c00195c2f9a01f0f00111430cf1010c19544fea5c02b2eb5e0f18d22e981e9f109d00eb5e03b818044604f8015b9c4211d2811c9942257010d2c41c9c420d700bd20437b91899422570ecd306e02e9800eb5c0102e0411c00e021465feace7007d0f44505d20878119a00f00f00104308702c98ddf870e0249cddf864a01e9d00e6a9f1010945e7a9f1020942e7a9f103093fe72a1bb2fa82f200235209484588bf012302ea03012b9b002b00f07581cde918142c9922954fea012c1e992d9a0b021d9d73444fea022832182b444fea590500f0010402f001011595bb4238bf1f463b1803f00103651823442f91711b09eb0605a7eb030a0427013d27ea890327ea850711971c9f6e086744a7eb0b070c9709eb04077f08129626181d9789ea0007400814932e9b109050080f904fea5a0b01204344dde9185cbbf1010f88bf4fea5a00234400f0030220f003081f98a3eb0e03ddf85ce00d9200eb530270081c900eeb5600461c03380a90f8071b9045982b9b2c9048080e904ff0ff3000eb5a0025906ff0010000eb5a002490901e09906ff00200cdf82ca000eb5a004ff0000a0796139108921a901e9406e00af1010a9a454ff0000700f00d8152466fea0a00002d18bf1a181f992c9b02eb0c0000fb03110cb9002005e01598149b085cd84000f00f002e902f982a9f08b9002004e01298119b085cd84000012d9022981b9c131803fb07e91c98002c1d9c484421441fd10e9af4f729ffddf864c0dde917e51e9c44b110992e9a19f8010000f0f000104409f801002f982b9b0028b6d00f992d9a19f8010000f00f00104309f80100ace7002d03fb07f642d013980228dfd30c982c991044099a01fb00200a990022314400eb0b039e785c78259fc6f3031646ea041401eb0b069742b470c8d05c7810f80b70c4f3031444ea0717249c77709442bdd010f80b7013f8014cc7f3031747ea04171a9c01f80b709442b0d013f8017c13f8023cc7f30317043247ea031304389345a1f1040106f8013cc9d19fe7139b022b9cd30b9b082b01d200222ce00c9b2c9f1a44089b07fb023c079a164400220ceb02077c781cf80250c4f3031444ea0515b41804f8015cbd787b78c5f3031545ea0313b354fb78bd78c3f3031343ea051363703b79ff780432c3f3031343ea07139045a370dbd10d9bdde9185c002b3ff465af531ccf5c8e5c0d9cc7f3031747ea0617012c87543ff459af961c8f5dcc5cc7f3031747ea04170d9cc754022c3ff44daf0a44d278895dc2f3031242ea0111815543e700271be0013f30d015f8010b411e1f29f8d341b220290fdb0aeb40011af81000497840ea0122c12a06d32a9958463aab00f0d3f80028e5d14ff0ff37ddf884c02699002f6dd1239801318142dde928020df5a567209be0cf00eb02047df4cdad65e06746eae71f46e8e742982b90249820eae070259004e030440b38013c06464cd019f8010b1f28f6d90aeb40011af81000497840ea0122c12acdd32a9958463aab00f09af80028c6d02298ddf8b480049036a803903aa80290dde92e70249d2c993a4643460195009600f01efcdde93c013b4630444a19b84226eae671b8bf03464245a8bf42468b42c7dd259fba42c4dd2b9f0f2fc1d8ddf894c0169e2b9da2eb0c025b1a06ebc50726f835100135a7f802c0bb80fa802b95afe70020fef7d6b94ff0ff300df2045dbde8f08fb4eb0c0018bf4ff0ff300df2045dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f91b00df1700b9be8400a10913169ddf868a0002900f05c813768bbf1000f40f05181874200f04e8199f80f100f2940f0498199f80e100e2940f0448199f80d100d2940f03f8199f80c100c2940f03a8199f80b100b2940f0358199f80a100a2940f0308199f80910092940f02b8199f80810082940f0268199f80710072940f0218199f80610062940f01c8199f80510052940f0178199f80410042940f0128199f80310032940f00d8199f80210022940f0088199f80110012940f0038199f80010002940f0fe80ddf86cc0caf10001d6f808e001eaea75ccf10001f76801eaec740895aeeb05062aeaea75391b2ceaec77521b9642a3eb07030d97b8bf32469942b8bf0b46012a0e930992c0f2ea820e990129c0f2e6820ef10101a4464c08089900eb55000c9048100b90042020ea81000790099801310138cde905014810049004fb0cf000f102094ff0000a0a94cde901c507e000bf0e980af1010a8245a14400f0bf821c98109bd0f800e00aeb0c0000fb04e20d980c9e504400fb0360eb0703d10b9edde9083810e00b9b2f46d35c079d0678eb4006f0f00603f00f03334400f8013b069bdde904683d469119da074fea58070f9208d13a468b466446f4f7b4f8a4460a9c68e000bf8b46b8f1020f63d37a1e032a04d2002117f0030237d15be06ff0030202ea58034e44c3f1000c0eeb0601461c039700bf8d18ef78ac78c7f3031747ea0417b418e7702f79eb78c7f3031747ea031323716b792f79c3f3031343ea07136371ab796f79c3f30313043243ea07130ceb02070437a371dcd1dde901c50a9c039f111d17f0030224d04b1cbe461bf803701bf80160c7f3031747ea0617012a4754774616d08e1c1bf806701bf80350c7f3031747ea0517029d022ac754774608d05944c9781bf80620c1f3031141ea021181555feac8713ff45aaf0f9a1bf80710002a4ff0000208bf0422c35dd14003f00f0242ea0111c15549e7874200f09f815c460021aae17568002d00f0068200214ff0000e09e0dde90e71d8f804503944dde91d9ba94280f0f881ddf870800f91d8f80060775c3c0901d0012117e06d1a012d00f0ea8106eb010c9cf8016016b1344602210be0042dc0f0df819cf802509cf8036055ea062400f0d781042117f00f07bbfa8bf60e914fea561619f807b018bf012746ea07091b9f4fea0b1c14f00301754600f09980d8f808504ff00008befbf5f60d9106fb15e55544b5f1ff3fc8bf4ff0010809ea080101291ad1f61918d4954216d29e4214d210990b9406fb01046e08a15ded070c916ff00f05594604bf0f256146ddf8308005ea08052943a1550b9c0d99ddf8708001290ef1010563d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080b91895ded070c916ff00f05594604bf0f256146ddf8308005ea080529430b9dddf87080a9550d990ef10205022930d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080c91895ded070d916ff00f05594604bf0f256146ddf8348005ea080529430c9dddf87080a9550ef1030500bf611e0329a64405d220e700bf0435ae453ff41cafd8f808100024b5fbf1f606fb11515144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f808106c1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ac1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ec1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c7ff46aaff6193ff567af9142bff464af9e42bff461af109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa1554be71b995c46002901dd012108e0b1fa81f149090027baf1000fc8bf01273940d6f808e0f76807fb0ef8b8f1000f56d0b4fa84f4bb4600274ff0ff3c6409c9070e940f9106e001370bfb0ef84745acf1010c44d20f990ef101050029394618bf08eb0c01b1fbfef46d0804fb1e161c99096804fb05117508495d042525ea8605e94011f00f08454618bf01250e990d43012dd8d116eb0a065cbf1b9d14eb0504d1d49642cfd29c42cdd2109d19f8081004fb050e74081ef80450f60705f00f0805f0f00545ea010508bf48ea01151c990ef80450d1f808e0d1f80cb0b3e711b0bde8f08f00bf2de9f04fc8b0dde95162549f1644ba1926eae6778a42b8bf11468f42039080f203815698cde90071a0f1030a6ff007076ff004044ff0000b0df1200e4ff000090293cdf810a000bf56984fea5903c05c4ff0100c00f0f0080590cde9064700bf1af8041f0eeb07001af8012c9af8013048ea121602f00f0242ea0802427248ea111201f00f01827241ea08010eeb0402117248ea13119af802500672517203f00f0141ea0801917248ea1511817305f00f0141ea08010837bcf1080c04f10804c173cdd10598ddf810a00401102753465d4600bf13f8040f0eeb050213f8011c5e7844ea111801f00f012143517444ea101100f00f002043d07444ea161093f802c0107506f00f002043507544ea1c1090750cf00f002043083f05f1080582f810809174d075d5d1079f069c09f1020920372034b9f1100f0bf1200b84d15598029bdde90086539900286dd00844079008f10100069003984fea580a03fb01074fea660c4feac87b06e000bf079809f1010181421f4457d20398894601fb0301bbf1000f45460bd011f80a00069d1ef8002000f0f00002f00f02104401f80a00bceb550f28dd680801eb0c033e4600bf315c06eb00081ef80120414601f8012b99421ed20a7808f102041ef802209c420a7018d221781ef80110217008f103049c4210d2217804361ef80110217034189c42ddd307e000bf01eb5504f00707d1b4e708f10104029bdde90086f007add0b542abda20781ef8001000f00f0001f0f00108442070a1e748b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf752fc69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae72de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041b1e022eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70f9f7d8fc002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f769fc00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f8f710fde0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f77cf902a9284600224ff0000afbf72dfc81464046f7f741fab9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f7fdfb06f1210506f1280029460722f2f7f5fb284621460722f2f7f0fb20465146032207f10905f2f7e9fb06f11d0049460422f2f7e3fbf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f7b7fba81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f77dfb012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f764fb572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f74dfb312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f737fb462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f720fb362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f7b5facde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f796fa8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f797f9284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f743f9002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f711f904a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f7fdf80020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f7e6f8352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f7c2f804a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f7aff8002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f79bf804a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f777f804f14f0051460722f2f771f884f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f1f7e3ff84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f1f7f9fe284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f7f735fe0028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3238000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f05df8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef715fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef7cbfd0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f012fb0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf057fd48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf0d1fc414602e0022084f8200350460c22fdf7d2ff94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7a2ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf771ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf71bff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf04dfcd8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf013fe0bf0e7fd294630b9ffe50bf0e2fd002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7bdfd0fe04eea062141ea0b4141ea05633946624665460bf0e1fb00281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af007fcd4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f213040af0b7f84ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b700af0a4f8e05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f0d0ff059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f002ff28461a21224609f07ffd00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f0f1fc854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f0edfc706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f0dafb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f080fc606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf751f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009508f02afb606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7a3fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009708f03bf8002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009508f01df8606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009507f0f0ff606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f0c5ff606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf7dbf904f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf797f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf741f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f0e2fd019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f63801c0f20001033079440b22f9f710fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f7d8fb0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f729fb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f77ffa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f66200c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f7ddfb4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f7f1fb4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f70afbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f729fb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009504f0bff83eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb00446002047f64c68a4f88003c2f20708d8f80000002a8b461abfc4f874030146d4f87413401ac4f87c03fdf762f8002800f0f980d4f86803002800f0f48004f0e6f9002800f0ef800646b4f86c03002848d0a0f10108d4f87c0300254ff4a0714ff4f0774ff48059cde90d050df1180acde901152046414632464ff42073cde906950c95cde9035a009704f068f8002840f0c980d4f87c034146cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906950c95cdf810a0009704f04cf8002840f0ad809df8380094f8801347f64c68084384f88003c2f2070806e0d4f8681330464ff41632f7f712f94ef66c694ff29c57ccf2ff09c2f229074ff6ff76002506e048f2a351c0f24501bff32f8f8847d7f800a0bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168494548d04ff46d70fdf781fe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d10121c0f8009081728683c683068446848684c684068546858685c685068646868686c6860687468757e8001f5145aad1bff35f8f00bf47e8000121b157e8001f5145f8d09fe7054604f01ff9002d18bf002803d101208bf8050022e0c5f860014ff001094ff4f07085f8649101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718bf8059004e09bf805008bf8049030b14ff0ff300fb0bde8f08f0025cbe794f8800384f8810348b3d4f8700342f66535c0f2440528b1d8f800102d31c4f8781311e044f2f330c0f200007844002122460023a847c4f87003d8f8001001f12d01c4f8781320b105f1e8022d21904728b1002084f881030fb0bde8f08f00200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2f44d0e784f780a4456ea072701f102041d9702f094821c903ea8063000261f9314901a92944202f08482601c904202f0808220786178a31c40ea0121d01a81422593269102f275821f98ddf82c252c90ddf81805ddf824152d90ddf81c0530912e90ddf8200521962f901068411e0028116002f05e822698002802f05a822698871c032f02f05582e678032e02f25182259890f80080f00702d104f1040927e0269820f00100022802f0438294f804a065791c984aea052b59462caa02f048fa002842f03682ddf8240504f10609012d30900dd8ddf82c05806948b14feadb020af00701835c012505fa01f119438154022e04eb070a03d2ddf82405279024e0d14503d04c4614f9015b01e00025544645f64d57c0f24607b847012808bf0135681e81b26e0800ebd130002d48bf4610b8470128ddf8240508bf76423118d145a1462791309102f0f481b8f1040f29ddb8f1060f40f3ec80b8f1070f00f04583b8f1080f00f05a81b8f1090f42f0e181d14502f0de8119f8011bd14542f0d9810f2902f2d681ddf82805002801f08680dde92e232c9801eb01115a43f7f73af801f07cb8b8f1020f2edcb8f1010f00f02282b8f1020f42f0bc812c984ff000082b902d98d14528902e98cde9369a29902f98cdf8e0802a90ddf82c05cdf8cc80c069329000f0ea8309f10100369099f80080504532af00f0e28309f10200369099f801000002dde3b8f1030f00f04982b8f1040f42f08d81baeb090402f0898109f10100504502f084811c98002802f08081a01e0528c2f07c8109f10700504542f077811c98d0f86c01002802f0718199f80110012902f26c8199f8003043ea012250f82210002902f063810f1ab90742f05f816ff4403140f60f063944cff6fd76b142c2f05581384450f8081c914242f04f8150f80c1ca1f1011616f5803fc2f04781002802f0448150f8046c8e4242f03f81c7f54037b94202f23a81ddf82c75bf6947b1d20803f00703be5c012505fa03f33343bb54dde92c5bdde92e6a002236ab02f080f900284ff0000708bf4ff0ff3700f08b83ddf828052b961a9a219e00280df1c80800f08383072c4ff0ff3740f07e83002d00f07b830027fcf793fd002840f01a841a9a4ff0ff3770e3b8f1050f00f07e82b8f1060f42f0f980d14502f0f68009f10100504502f0f18009f10200504502f0ec8009f10300504502f0e78009f10400504502f0e28009f10500504502f0dd8009f10600504502f0d88009f10700504502f0d38009f1080caaeb0c000828c2f0cc8009f11000504542f0c78099f8040099f8051050ea01261ebf99f8060099f8071050ea012502f0b88099f8000099f801202d9940ea0224081bc2f0ae80864202f2ab8099f8020099f803302e9a40ea0327d01bc2f0a180854202f29e80ddf82805002800f04e872c982f9bcde90147279fcdf814c0cde90365009703f036fc00f040bf5046cde93e90ddf82c050021c0693eaf36addde92c48dde92ea64091cde936013846294602f03cfb81463846294602f037fb4099002940f0da82dde93e218a4200f0d582531c8b4200f0d182931c8b4200f0cd82d31c8b4200f0c982131d8b4200f0c582531d8b4200f0c182931d8b4200f0bd82d31d8b4200f0b98202f108038b4240f0b482117853784ff0ff3551ea032101f04f869378d77853ea072301f04986b1f5207f01f24586b3f5f07f01f2418697792b960f2f229701f23b86d6792f46102e299600f294822093ddf82c35239037981f6a92f804c03843ddf8287552794ff0000b002f2494186201f0b98727980023084440428145c1f224862798a8eb0000814581f21e86209847422398b842c1f21886ddf88ce02498209ef2451f4640f366824cea0222b2eb510f28bf4a08b2eb560f28bf72081792013a4ff0000738bf3a460d92cef1000202eaee75aaeb0e02b242a8bf324695421e9280f24882279a179b91445a001b9203fb03f29200169201eb090203294ff00001279238bf01210022032e38bf012211431591711e1291b11e10910d9900244a00494389000a9109f101010e9129990f920a0141ea01110b916ff008010c9201eb43012b9a11912eeaee7102fb0101cdf84c902a910021189101f085bbd14501f09b87494611f8010b012801f295872c9a002828922d9a2b922e9a2a922f9a299200f05682514501f0878709f10201514501f0828709f10301514501f07d8709f10401514501f0788709f10501514501f0738709f10601514501f06e8709f10701514501f0698709f10801514501f0648799f8011099f8022099f8043041ea022c99f8032099f8056099f8061042ea032746ea012699f8071099f8082009f10903169341ea022135e2aaeb0905052dc1f0438709f10508d04501f03e8709f1060699f80570aaeb0600b842c1f03587f019504541f031872c981890dde92da01e902f981790afb1002402e00134bc4210d2305d01381e28f8d93019391b3eaa36ab02f01dfe002801f017873e980444bc42eed3ddf82805002800f0c385052d01f00b871898002801f00787fcf790fb002801f0028798f8008008f10600854241f0fb8647f65420c2f207000768002f01f0f386387b797bba7bfb7b40ea012040ea024040ea0365a5f1810010f1800fc1f0e386387c797cfa7c40ea0120b97c40ea014040ea02600b90813810f5817f41f2d386b8f1000f4ff0000012972a9000f027844ff0000c00270df1c80b0ae000f100403ea941f824000137474504f1010c80f0c583f05d6446411e1e29efd9f019a8eb070136aa5b4602f0b1fd002800f01781369932983eaa0f4442f82400e4e7d14501f0a18609f10100504501f09c8609f10200504541f0978699f8000099f801102caf40ea0121ddf82c058ccf0490ddf828052f9e03902798019602901c98009703f042fb0746ece0baeb090801f07b8609f10100504501f07686a8f102000528c1f0718609f10700504501f06c861c98002801f0688609f1080b99f80740aaeb0b00a042c1f05f860beb0400504541f05a861c98d0f86c31002b01f0548699f80100012801f24f8699f8001041ea002053f82020002a01f04686d21a970741f042866ff4403740f60f061744cff6fd76b742c1f038869e1856f8083c834241f0328656f80cacaaf1011313f5803fc1f02a86002e01f0278656f8043c534541f02286c2f54032924501f21d86ddf82c25926942b1c00801f00701135c012707fa01f119431154baf1c10fc1f00c863078012841f008862c982b902d982a902e9829902f9828900cb3a6f13f075d4601e0013c1bd015f8010b411e1f29f8d341b22029c1f2f08507eb400117f81000497840ea0122c12ac1f0e685304651463eab01f03cfe0028e3d101f0ddbdddf82805002800f08d840020b8f1080f4ff0ff373e903ed32b98e0b30025fcf757fab0b399f807a00af10800804530d199f8000099f8017099f8068040ea072400f085bc32af01203890002036ae24903046394602f076f881463046394602f071f838990746e9b1002400260120389000200df1d80a0df1c80b23905046594602f060f805465046594602f05bf8389919b34ff0ff371a9a219e002f00f0448401f08bbddde936018842ddd0024612f8014b8a423692d8d0821c369243788a4244ea0324d1d0c21c369286788a42cdd0011d3691c0780002cbe78646dde9360122961a9a219ebb4688424ff0ff37d4d1b9f1000fd1d4bbf1000fced4ddf82c353398196aaa460843249d18622b9845ea08053e904ff6fe7085422a98289e299f41901c98cc463f96409700f09c844ff6ff718d4240f07884d0f868834ff420703f904ff4f07040904ff4a070419000f08cbc514501f0318509f10201514501f02c8509f10301514501f0278509f10401514501f0228599f8022099f80110570099f8032099f804304fea810c09f10501960016915900002e179101f00e851799002901f00a852b99b1eb0c02c1f00585964201f202852a99ca1bc1f0fe841799914201f2fa84002878d0279800250ceb000280e048f2a351c0f245010027bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f035824ff46d70fdf701f800283ff4c6ab4ff64c41cff6ff7142180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa14297d1bff35f8f42e80001002900f0e78152e8001fa142f6d08be7279800250ceb0002c00706d1002a04d42b99b0188842d8bf01251699179baaeb01001390ddf8280503fb06fbb0fa80f040092843c00715954ff0000e1b900d4600202790cdf878a0cdf860b014e000bf27982499084427902098239981424ff0000088bf01204eea000e229d5feace7008bf0d44ddf878a05feace7004d02798834508d801f03bbc554500f0cc822798834540f2c882baeb050401f0308495f800805fea181001d0012111e0012c01f02684687808b102210ae0042cc1f01f8495f802c0eb785cea032001f01884042123912799abeb0103984201f210841b992490002920942295b2d1249808f00f09431e032b4fea081ccdf864e076d24ff0000a2498dde918be10f00308a0d027988244bafbf6f000fb16a1c319881853ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd54b8f1010f3ff47caf0af10100b0fbf6f101fb1600cb19104453ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd54b8f1020f3ff457af0af10200b0fbf6f101fb1600cb19104453ea00013ff54baf2b998842bff447af2a998b42bff443afdde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd5431e720f003084ff0000a05e000bf0af1040ad0453ff480af279800eb0a0bbbfbf6f000fb16b300eb070e98185eea000315d42b99884212d22a998e450fd2dde928310efb013341085c5cc00704f00f0504f0f0044c4408bf45ea0c045c540bf10100b0fbf6f101fb1600cb19104453ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd540bf10200b0fbf6f101fb1600cb19104453ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd540bf10300b0fbf6f101fb1600cb19104453ea00018ad42b998842bff487af2a998b42bff483afdde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd5471e7bcf1000f299500f0ac82acf101054ff000083eaf09e0b446454508f10108a4f1010407f1040700f09a823ea850f828100029f1d40020434684421dd007eb80067268b2f1ff3f18dc5a1c954214d0b268b2f1ff3f11dc9a1c95420dd0f268b2f1ff3f0adcda1c954206d032690433002a00f10400e0d400e00022129836ab6646cdf800b002f040fa00283ff41aad32980028c0d04af20d3136a8c0f24e018847b9e7299501204ff0000c0df1c80b5be2d0f86c014ff0ff37002800f0278199f80110012900f2228199f8002042ea012150f82120002a00f01981121a930740f015816ff440333c4640f60f071344cff6fd77bb422746c0f00981104450f8083c8b427ff46da950f80c1c0027a1f10113cff6ff77bb42fff463a900284ff0ff3700f0f48050f8043c8b4240f0ef80c2f54032914200f2ea8000223eab01f0b0fa00283ff44da999f8031099f80200090699f8053041ea0040279999f8042001eb2040190641ea024199f806200f24970602f00f0304eae7775f4389246743ff0a8df8c8700e2712f0200f08bf012703fb07f704fb07f74fead7278df8c9704ff00d0708bf022703fb07f704fb07f74fead7278df8ca704ff00c0708bf032703fb07f704fb07f74fead7278df8cb704ff00b0708bf042703fb07f704fb07f74fead7278df8cc704ff00a0708bf052703fb07f704fb07f74fead7278df8cd704ff0090708bf062703fb07f704fb07f74fead7278df8ce704ff0080708bf072703fb07f704fb07f74fead7278df8cf704ff0070708bf082703fb07f704fb07f74fead7278df8d0704ff0060708bf092703fb07f704fb07f74fead7278df8d1704ff0050708bf0a2703fb07f704fb07f74fead7278df8d2704ff0040708bf0b2703fb07f704fb07f74fead7278df8d3704ff0030708bf0c2703fb07f704fb07f74fead7278df8d4704ff0020708bf0d2703fb07f704fb07f74fead7278df8d5704ff0010708bf0e2703fb07f704fb07f74fead7278df8d6704ff0000708bf0f277b436343db0a09148df8d730c2f300122b9b4ff0000ccde90382cde90001284651465a463eaf0297674602f0a0f91a9afff7dcbb554541f069812798834541f06581ddf82805002818bf012015990840012810d1dde92803139907fb0300770800eb5202179800970190169801f01dfa002801f04b811a9a219e1d9801368642dde9250100eb01047ef4b9ae01f044b948f2a351c0f245010025bff32f8f88474ff29c50c2f229000668bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f0c3834ff46d70fcf74cfc00283ff482ab4ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fb14296d1bff35f8f42e80001002900f0748352e8001fb142f6d08ae729463eaa774601f0d3f800287ff42dabddf82c051a9a8069be46299f4ff00001cc4660b1b1eb552f09d1ea0808f00701835c012505fa01f1194381541a9addf8f880b8f1000f00f03e833d46002c4ff0ff371cbfdde9220151ea00033ff408ab3f986045fff404aba0eb0c0084423ff6ffaa40985845fff4fbaaa0eb0b0083423ff6f6aaddf82805002700283ff4f0aaaaf1011010f1021f7ff6eaaa27980aeb0001b142b8bfae45bff6e2aa604281427ff7deaa584286457ff7daaa21eae17001eae171aceb01020f190eeaee79714609eb030e21eae171331a9f42a5eb010538bf3b462091ae45249528bfae462b9fcdf84ce0b845abeb09071e9700f05b86002700f071be002002e04ff0000c012099f804100f248d0601f00f0604eae575754389246543ed0a99f800e08df8c8500e2599f8012099f8023099f803702b9111f0200f08bf012506fb05f504fb05f54fead5258df8c9504ff00d0508bf022506fb05f504fb05f54fead5258df8ca504ff00c0508bf032506fb05f504fb05f54fead5258df8cb504ff00b0508bf042506fb05f504fb05f54fead5258df8cc504ff00a0508bf052506fb05f504fb05f54fead5258df8cd504ff0090508bf062506fb05f504fb05f54fead5258df8ce504ff0080508bf072506fb05f504fb05f54fead5258df8cf504ff0070508bf082506fb05f504fb05f54fead5258df8d0504ff0060508bf092506fb05f504fb05f54fead5258df8d1504ff0050508bf0a2506fb05f504fb05f54fead5258df8d2504ff0040508bf0b2506fb05f504fb05f54fead5258df8d3504ff0030508bf0c2506fb05f504fb05f54fead5258df8d4504ff0020508bf0d2506fb05f504fb05f54fead5258df8d5504ff0010508bf0e2506fb05f504fb05f54fead5258df8d6504ff0000508bf0f256e436643f60a00288df8d76040f01682120642ea0e41279a380602eb2145299940ea0340ddf84880acf1010601eb204000240a90cdf838c00c9607e001f01f000b3801346445054400f0ef813ea850f82410b1f1ff3ff1dd23469e421cd03ea800eb83004268b2f1ff3f16dc0133b34212d08268b2f1ff3f0fdc0133b3420bd0c268b2f1ff3f08dc0133b34204d002690133002ae1d400e00022404636ab31af009701f0b9fe002800f0c58131990029159100f0b1819df8e0009df8e1100f9450ea01201195279000f096819df8e4709df8e5603f0447ea06670b9e279d9df8df009df8de102e4406eb27470a9e020241ea00249df8e2009df8e330f71b00042497119d012740ea036007eb54060a44031405eb20401396561e19941696ee1801f00304e91a431c1093831c0d93159bc9075d1c07eb52031b94121b00242991f10723932a92289107e000bf279901348c4223990d4400f04f8124990919f5d41e9a9142f2d2199a002aefd0dde917324ff0000901fb032e169922940329209580f099801b99209d229c0029ded01599139a012704fb02132b994fea59029a5c01f0100187ea111c02f00f01d5b25feac97808bf29090a46002918bf012242ea0c02012a14d119eb000611d456450fd272081ef802501bf8011005f00f0705f0f0050d43f60708bf47ea01150ef802501b99209d229c0129a8d009f101014908595cb8f1000fcab24fea121208bf01f00f02d1b2002918bf012141ea0c01012917d1109911eb090113d4514511d24d081ef805601bf8022006f00f0706f0f0061643c90708bf47ea02160ef80560229c209d1b9902293ff479af09f102014908595cb8f1000fcab201f00f0108bf11090a46002918bf012242ea0c02012a7ff465af0d9a19eb02033ff560af5345bff45daf5a081ef802701bf8011007f00f0607f0f0070f43db0708bf46ea0117229c0ef802704ae7ac4608e000bf2a9909f1040949450cf1020c3ff45caf2b991cf8013c01f010010122deb2002382ea11110f2e88bf01230b43012b00eb090319d1002b17d4534515d235095e081ef806201bf80550574602f00f0a02f0f0022a435feac07b0df1c80b08bf4aea0512ba460ef806201cf8012c12f00f06324618bf01220a43012a19d15d1c17d4554515d26a081ef802501bf80660d846ddf8a4b005f00f0747ea0617bbf1000fc34605f0f00508bf45ea06070ef802709cf80020d6b200220f2e88bf01220a43012a17d19d1c15d4554513d26d0832091ef805601bf802200446289806f00f0706f0f00616430028204608bf47ea02160ef805609cf8002012f00f06324618bf0122114301297ff47bafd91c3ff578af5145bff475af49081ef801201bf8063002f00f05299e45ea031502f0f002002e08bf42ea03050ef8015061e74af20d3136a8c0f24e0188479df8dc009df8dd10dde911580c9edde90ec405e09df8dc009df8dd10ddf838c040ea01200be6002005e04ff0ff37fef7d1bf4ff0ff302a901a9a219e2a9ffef7cabfd0f86c114ff0ff30002900f02281012f07463ef6bdaf51f8240000283ef4b6af401a82074ff0ff377ef4b2af6ff4403240f60f030244cff6fd739a42fef4a8af0b1853f8081ca1427ef4a2af53f80c6c0022a6f10111cff6ff729142fef498af53f8041c2493b1427ef492afc0f54030864223963ef68caf249800283ef488af2398c128fef484af2498007801287ef47faf4fea88660f2508f00f0705eae6767e4389256e43f60a8df8c8600e2699f8021099f8033099f8040099f8052018f0200f08bf012607fb06f605fb06f64fead6268df8c9604ff00d0608bf022607fb06f605fb06f64fead6268df8ca604ff00c0608bf032607fb06f605fb06f64fead6268df8cb604ff00b0608bf042607fb06f605fb06f64fead6268df8cc604ff00a0608bf052607fb06f605fb06f64fead6268df8cd604ff0090608bf062607fb06f605fb06f64fead6268df8ce604ff0080608bf072607fb06f605fb06f64fead6268df8cf604ff0070608bf082607fb06f605fb06f64fead6268df8d0604ff0060608bf092607fb06f605fb06f64fead6268df8d1604ff0050608bf0a2607fb06f605fb06f64fead6268df8d2604ff0040608bf0b2607fb06f605fb06f64fead6268df8d3604ff0030608bf0c2607fb06f605fb06f64fead6268df8d4604ff0020608bf0d2607fb06f605fb06f64fead6268df8d5604ff0010608bf0e2607fb06f605fb06f64fead6268df8d6604ff0000608bf0f2677436f430024ff0abaf1000f8df8d77000f051821b0643ea0141279b5f4603eb2144110641ea004000142290c8f30010209024985646a0f13f0822e20746fef79cbe0120229f0190184641465346009702f08cf9dde923e0dde92a2101350a441e9900278d422a92bef687aee94331448d42b8bf29461b9a6fea41011144012938db169a4ff0ff3301fb1121179a4ff0000c121b012a03eb420233db02fb02f38b422fdd119aa2eb440303f10807032f03f1060220db02fb02f68e421cdd052f03f104021adb02fb02f68e4216dd072f03f1020214db02fb02f68e4210dd0434092fa3f1080203db5b438b421346dcdc083206e0002427e0013402e0023400e00334209e012c1edb0832931f5b438b4219dc022c16db131f5b438b4200f3b280022c0fd0931e5b438b4200f3af80042c08db02fb02f38b4200f3aa80043c02f10802e2d10024e3462b9b05eb0e0101fb0303299804eb090210282798a0eb040a3ff46fafb5fa85f1159849090143289349d11298854246d01099681e491b19958842b8bf01466fea41000f9908440128c0f2ad800a99189b00fb10100d99cb1a4ff0ff31012b01eb430179db01fb01f7874275dd5900189da1f1090303f10807032f03f1060165db01fb01f6864261dd052f03f104015fdb01fb01f686425bdd072f03f1020159db01fb01f6864255dd0435092fa3f1080103db5b4383420b46dcdc08314be022eae27cc245a8bfc246d44531da4ff0000b5feacc7019950ad0289b4fea5c00195c299a01f0f00111430cf1010c19544fea5c02b2eb5a0f1dd228982a9f0b9d00eb5a03b9180e4606f8015b9e4280f08880881c9842357080f08880ce1c9e42057080f082800437b81898423570e9d37ce02498ede6289800eb5c0076e0013c4ff0000b5de7023c5ae7033c58e7013502e0023500e003351895ddf860b0bbf1010f23db08318b1f5b4383421edcbbf1020f19db0b1f5b43834200f3d380bbf1020f11d08b1e5b43834200f3ce80bbf1040f09db01fb01f3834200f3c980bbf1040b01f10801ded14ff0000b0e9822eae27e00eb0b0cc445c146b8bfe146ce4551da5feace700ad0289b4fea5e00195c299a01f0f00111430ef1010e19544fea5e07b7eb590f18d228982a9b0b9d00eb5906d919084600f8015bb04213d28a1cb242057024d2c81cb04215701fd20433da19b2420570ecd31ae0289800eb5e0216e0481c02e04a1c12e030465feaca710ad0d44508d201780c9a01f00f011143ddf88ce0017067e0ddf88ce064e002465feac97007d0ce4505d210780c9900f00f000843107027996fea0b000e18012001902898229f414662463346cdf860b0009701f0d0ff26eae67cc245a8bfc246d4453dda5feacc700ad0289b4fea5c00195c299a01f0f00111430cf1010c19544fea5c02b2eb5a0f18d228982a9f0b9d00eb5a03b818064606f8015b9e4211d2811c9942357010d2c61c9e420d700bd20437b91899423570ecd306e0289800eb5c0102e0411c00e031465feaca7007d0d44505d208780c9a00f00f0010430870ddf88ce04ff0000b2498209eddf84c90199df6e5abf1010b40e7abf1020b3de7abf1030b3ae7013e00f0b78117f8010b411e1f29f7d341b220290fdb08eb400118f81000497840ea0122c12a06d3dde9231036ab00f053fa0028e4d14ff0ff342746fef75fbc2f46fef75cbc209f1e9eb74204dd012710e01f46fef753bc209f1e9e9042a7eb0607b7fa87f74fea57174ff00006c8bf01263740ddf84ce0bef1000f169700f0768154084ff0040c12942cea82041194d41803eb000a013c00f001050af00106670810972cea8407ac190f971f1bdde9223405eb000c1c445319424040080e904fea5a000d9004eb0900ddf890907908484538bf81460120cdf890901791012988bf780800f0030120f0030b58081b9008eb530009904fea5c0019902b984ff0000900eb5c0001300890d00718904198ddf858c029904ff0ff3000eb57000b90c7f341000a906ff0010000eb570007906ff0020000eb57000c9115970690cde9226507e0249809f1010981454ff000073ef4d6ab6fea09014846bcf1000f18bf0eeb01001e9900eb0102299902fb01810db9002305e0129b119ccb5ce34003f00f0328930eb9002304e0109b0f9ccb5ce3401b012793209b189c0344dde92a70002c03fb070a19981b9c504421441fd1179af4f71fffddf858c0ddf84ce0239d45b10e99289a1af8010000f0f00010440af80100229e1a9a002eb3d00d99279b1af8010000f00f0018430af80100a9e7299cbcf1000f04fb02f25bd0159b022bddd30a9b002b179b23d0179b0b9dcb5c4c5dc3f3031343ea041343550a9b012b2b4616d00b9b079dcb5c4c5dc3f3031343ea041343550a9b022b2b4609d0079b069ccb5c095dc3f3031343ea0111234601550b990329b2d309991144ca18cc5c12f8016cc4f3031444ea0616c41804f8016c12f8016c12f8025cc6f3031646ea051604f8026c12f8026c12f8035cc6f3031646ea051604f8036c12f8036c12f8042cc6f30316043b46ea021204f8042cd4d184e7159c022cfff481af159f082f01d200222ce02a9f03fb07f4099b03eb020c089a144400220ceb020675781cf80270c5f3031545ea0717a51805f8017cb7787378c7f3031747ea0313a354f378b778c3f3031343ea07136b703379f7780432c3f3031343ea07139345ab70dbd10c9bddf858c0002b3ff449af531ccf5c8e5c0c9cc7f3031747ea0617012c87543ff43daf941c0f5dce5c0c9dc7f3031747ea0617022dc7543ff431af0a44d278095dc2f3031242ea0111015527e70027fef7c5ba22983e9f20eae070279005e020440b38baf1010a044648d01bf8010b1f28f5d908eb400118f81000497840ea0122c12afff447aedde9231036ab00f093f800283ff43fae2098ddf8a490049032a8039036a80290dde92a60229d289932464b460195009401f054f8dde93801334620444a19b04224eae471b8bf03464a45a8bf4a468b42c4dd279eb242c1dd0f2fbfd8279d149c521b5b1a04ebc70624f8371001377580b380f280b2e700240be64ff0ff300df2f44dbde8f08fa01a18bf4ff0ff300df2f44dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf2de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041ffe78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f91b00df1700b9be8400a10913169ddf868a0002900f05c813768bbf1000f40f05181874200f04e8199f80f100f2940f0498199f80e100e2940f0448199f80d100d2940f03f8199f80c100c2940f03a8199f80b100b2940f0358199f80a100a2940f0308199f80910092940f02b8199f80810082940f0268199f80710072940f0218199f80610062940f01c8199f80510052940f0178199f80410042940f0128199f80310032940f00d8199f80210022940f0088199f80110012940f0038199f80010002940f0fe80ddf86cc0caf10001d6f808e001eaea75ccf10001f76801eaec740895aeeb05062aeaea75391b2ceaec77521b9642a3eb07030d97b8bf32469942b8bf0b46012a0e930992c0f2ea820e990129c0f2e6820ef10101a4464c08089900eb55000c9048100b90042020ea81000790099801310138cde905014810049004fb0cf000f102094ff0000a0a94cde901c507e000bf0e980af1010a8245a14400f0bf821c98109bd0f800e00aeb0c0000fb04e20d980c9e504400fb0360eb0703d10b9edde9083810e00b9b2f46d35c079d0678eb4006f0f00603f00f03334400f8013b069bdde904683d469119da074fea58070f9208d13a468b466446f3f788fca4460a9c68e000bf8b46b8f1020f63d37a1e032a04d2002117f0030237d15be06ff0030202ea58034e44c3f1000c0eeb0601461c039700bf8d18ef78ac78c7f3031747ea0417b418e7702f79eb78c7f3031747ea031323716b792f79c3f3031343ea07136371ab796f79c3f30313043243ea07130ceb02070437a371dcd1dde901c50a9c039f111d17f0030224d04b1cbe461bf803701bf80160c7f3031747ea0617012a4754774616d08e1c1bf806701bf80350c7f3031747ea0517029d022ac754774608d05944c9781bf80620c1f3031141ea021181555feac8713ff45aaf0f9a1bf80710002a4ff0000208bf0422c35dd14003f00f0242ea0111c15549e7874200f09f815c460021aae17568002d00f0068200214ff0000e09e0dde90e71d8f804503944dde91d9ba94280f0f881ddf870800f91d8f80060775c3c0901d0012117e06d1a012d00f0ea8106eb010c9cf8016016b1344602210be0042dc0f0df819cf802509cf8036055ea062400f0d781042117f00f07bbfa8bf60e914fea561619f807b018bf012746ea07091b9f4fea0b1c14f00301754600f09980d8f808504ff00008befbf5f60d9106fb15e55544b5f1ff3fc8bf4ff0010809ea080101291ad1f61918d4954216d29e4214d210990b9406fb01046e08a15ded070c916ff00f05594604bf0f256146ddf8308005ea08052943a1550b9c0d99ddf8708001290ef1010563d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080b91895ded070c916ff00f05594604bf0f256146ddf8308005ea080529430b9dddf87080a9550d990ef10205022930d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080c91895ded070d916ff00f05594604bf0f256146ddf8348005ea080529430c9dddf87080a9550ef1030500bf611e0329a64405d220e700bf0435ae453ff41cafd8f808100024b5fbf1f606fb11515144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f808106c1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ac1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ec1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c7ff46aaff6193ff567af9142bff464af9e42bff461af109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa1554be71b995c46002901dd012108e0b1fa81f149090027baf1000fc8bf01273940d6f808e0f76807fb0ef8b8f1000f56d0b4fa84f4bb4600274ff0ff3c6409c9070e940f9106e001370bfb0ef84745acf1010c44d20f990ef101050029394618bf08eb0c01b1fbfef46d0804fb1e161c99096804fb05117508495d042525ea8605e94011f00f08454618bf01250e990d43012dd8d116eb0a065cbf1b9d14eb0504d1d49642cfd29c42cdd2109d19f8081004fb050e74081ef80450f60705f00f0805f0f00545ea010508bf48ea01151c990ef80450d1f808e0d1f80cb0b3e711b0bde8f08f00bf2de9f04fc8b0dde95162549f1644ba1926eae6778a42b8bf11468f42039080f203815698cde90071a0f1030a6ff007076ff004044ff0000b0df1200e4ff000090293cdf810a000bf56984fea5903c05c4ff0100c00f0f0080590cde9064700bf1af8041f0eeb07001af8012c9af8013048ea121602f00f0242ea0802427248ea111201f00f01827241ea08010eeb0402117248ea13119af802500672517203f00f0141ea0801917248ea1511817305f00f0141ea08010837bcf1080c04f10804c173cdd10598ddf810a00401102753465d4600bf13f8040f0eeb050213f8011c5e7844ea111801f00f012143517444ea101100f00f002043d07444ea161093f802c0107506f00f002043507544ea1c1090750cf00f002043083f05f1080582f810809174d075d5d1079f069c09f1020920372034b9f1100f0bf1200b84d15598029bdde90086539900286dd00844079008f10100069003984fea580a03fb01074fea660c4feac87b06e000bf079809f1010181421f4457d20398894601fb0301bbf1000f45460bd011f80a00069d1ef8002000f0f00002f00f02104401f80a00bceb550f28dd680801eb0c033e4600bf315c06eb00081ef80120414601f8012b99421ed20a7808f102041ef802209c420a7018d221781ef80110217008f103049c4210d2217804361ef80110217034189c42ddd307e000bf01eb5504f00707d1b4e708f10104029bdde90086f007add0b542abda20781ef8001000f00f0001f0f00108442070a1e748b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf726f869680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae722eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae72de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70f9f7eafc002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f77bfc00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f8f722fde0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f78ef902a9284600224ff0000afbf73ffc81464046f7f753fab9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f70ffc06f1210506f1280029460722f2f707fc284621460722f2f702fc20465146032207f10905f2f7fbfb06f11d0049460422f2f7f5fbf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f7c9fba81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f78ffb012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f776fb572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f75ffb312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f749fb462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f732fb362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f7c7facde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f7a8fa8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f7a9f9284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f755f9002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f723f904a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f70ff90020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f7f8f8352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f7d4f804a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f7c1f8002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f7adf804a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f789f804f14f0051460722f2f783f884f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f1f7f5ff84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f1f70bff284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f7f747fe0028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3239000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "5c4f3a00", + "new": "384f3a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "dc4f3a00", + "new": "b84f3a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "5c4f3a04", + "new": "384f3a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "56bcf2ba", + "new": "9218d6af", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "8dff7648", + "new": "3ef62aed", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "8dff7648", + "new": "3ef62aed", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/graphics/display-list.md b/app/graphics/display-list.md index 38462c02..4445bd89 100644 --- a/app/graphics/display-list.md +++ b/app/graphics/display-list.md @@ -32,10 +32,12 @@ Supported calls in this first pass: - `IMAGE`: a local resource index, integer `x`/`y`, and `transparent`. Transparent images skip pixels quantized to zero. Resources have `width`, `height`, and gray8 `pixels`; a baked `GrayImage` can be used directly. -- `RECT_COPY`: a local resource index, integer source rectangle and destination - `dx`/`dy`. `SCREEN` reads the uncomposed frame; its source coordinates are also - relative to this list's placement. Each call may add its own `depth` to the - list's depth. A screen restore normally uses the negative of the list depth. +- `RECT_COPY`: a local resource index, source rectangle and destination + `dx`/`dy`. Source x/y and `dx`/`dy` accept expressions (revision 29); the + source rectangle must stay inside the source at every time, or firmware + rejects the list. `SCREEN` reads the uncomposed frame; its source coordinates + are also relative to this list's placement. Each call may add its own `depth` + to the list's depth. A screen restore normally uses the negative of the list depth. Kotlin allocates/cache-pins all image resources, resolves the local indices, applies surface placement, and includes the calls in the root firmware display list. The @@ -48,7 +50,9 @@ the current firmware protocol; no firmware update is needed for this bridge chan integer remainder, negation, explicit conversions, lerp, and the easing functions in `ExprOp`. `ease()` defaults to smoothstep. Integers wrap at 32 bits; float operations round to f32. The firmware's existing stack/error semantics apply. -Only rounded-rectangle x/y accept expressions in this first pass. +Rounded-rectangle x/y and rect-copy source/destination coordinates accept +expressions. `E.progress(duration, delay)` stays 0 for the first `delay` ms of +the timeline, so one list can run motions that started at different times. `maximum.time()` returns `min(milliseconds since PRESENT, maximum)`. The existing 45 ms repaint timer remains active while this is below maximum. `E.elapsed()` is @@ -64,7 +68,8 @@ exclude the changing elapsed duration. Without a timeline, raw `time()` expressi start at each PRESENT. Native compilation strips the bridge-only elapsed opcode. `menu-selection-list.ts` authors both the rounded highlight and the transparent row -image using this API. Navigation eligibility, duration, and easing remain in +image using this API. `menu-scroll-list.ts` authors a menu scroll: a viewport-sized +copy from a strip resource whose source y animates, then the highlight. Navigation eligibility, duration, and easing remain in TypeScript. There is no animated-menu tag or menu animation policy in Kotlin. ## Bridge framing @@ -73,8 +78,8 @@ Tag 7 is followed by a little-endian u32 byte length and a bounded body: placement (i16 x/y, u16 width/height, i8 depth), timeline (u32 token/elapsed), u16 resource count, gray8 images (u16 width/height followed by pixels), u16 call count, then calls. Calls start with the firmware opcode and an i16 relative depth; -operands otherwise use their fixed-width fields, except rounded x/y which use -extended varints. Expressions use the firmware bytecode plus bridge-only +operands otherwise use their fixed-width fields, except rounded x/y and rect-copy +x/y/dx/dy which use extended varints. Expressions use the firmware bytecode plus bridge-only `ELAPSED = 128`. Resource indices are local to this record, never firmware IDs. Rect-copy source x/y are signed here to permit relative SCREEN coordinates. diff --git a/app/graphics/display-list.ts b/app/graphics/display-list.ts index a7eb5c36..9f5491a1 100644 --- a/app/graphics/display-list.ts +++ b/app/graphics/display-list.ts @@ -8,7 +8,7 @@ export type ListImage = { readonly width: number; readonly height: number; reado export type ListCall = ( | { op: typeof DrawOp.ROUNDED_RECT; x: DrawValue; y: DrawValue; width: number; height: number; radius: number; background: number; border: number } | { op: typeof DrawOp.IMAGE; resource: number; x: number; y: number; transparent: boolean } - | { op: typeof DrawOp.RECT_COPY; resource: number; x: number; y: number; width: number; height: number; dx: number; dy: number } + | { op: typeof DrawOp.RECT_COPY; resource: number; x: DrawValue; y: DrawValue; width: number; height: number; dx: DrawValue; dy: DrawValue } ) & { depth?: number }; export type DisplayList = { readonly resources: readonly ListImage[]; @@ -53,12 +53,13 @@ export function encodeDisplayList(placed: PlacedDisplayList, now = Date.now()): out.u8(integer(call.background, 0, 15)); out.u8(integer(call.border, 0, 16)); } else { if (call.resource !== SCREEN) integer(call.resource, 0, list.resources.length - 1); - if (call.op === DrawOp.RECT_COPY && call.resource !== SCREEN && (call.x < 0 || call.y < 0)) throw new Error('Negative image source coordinate'); + if (call.op === DrawOp.RECT_COPY && call.resource !== SCREEN && [call.x, call.y].some(v => typeof v === 'number' && v < 0)) throw new Error('Negative image source coordinate'); if (call.op === DrawOp.IMAGE && call.resource === SCREEN) throw new Error('Use rectCopy to read SCREEN'); out.u16(call.resource); if (call.op === DrawOp.IMAGE) { out.i16(call.x); out.i16(call.y); out.u8(call.transparent ? 31 : 15); } else { - out.i16(call.x); out.i16(call.y); out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480)); out.i16(call.dx); out.i16(call.dy); + out.raw(encodeValue(call.x)); out.raw(encodeValue(call.y)); out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480)); + out.raw(encodeValue(call.dx)); out.raw(encodeValue(call.dy)); } } } @@ -81,7 +82,7 @@ export function readDisplayList(bytes: Uint8Array, offset: number, now = Date.no const op = r.u8(), depth = r.i16(); if (op === DrawOp.ROUNDED_RECT) calls.push({ op, depth, x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), radius: r.u16(), background: r.u8(), border: r.u8() }); else if (op === DrawOp.IMAGE) calls.push({ op, depth, resource: r.u16(), x: r.i16(), y: r.i16(), transparent: (r.u8() & 16) !== 0 }); - else if (op === DrawOp.RECT_COPY) calls.push({ op, depth, resource: r.u16(), x: r.i16(), y: r.i16(), width: r.u16(), height: r.u16(), dx: r.i16(), dy: r.i16() }); + else if (op === DrawOp.RECT_COPY) calls.push({ op, depth, resource: r.u16(), x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), dx: readValue(r), dy: readValue(r) }); else throw new Error('Unsupported display-list call'); } if (r.offset !== length) throw new Error('Trailing display-list bytes'); @@ -121,8 +122,9 @@ export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width: } else { const source = c.resource === SCREEN ? { width, height, pixels: screen } : placed.displayList.resources[c.resource]; const w = c.op === DrawOp.IMAGE ? source.width : c.width, h = c.op === DrawOp.IMAGE ? source.height : c.height; - const sx = c.op === DrawOp.IMAGE ? 0 : c.x + (c.resource === SCREEN ? placed.x : 0), sy = c.op === DrawOp.IMAGE ? 0 : c.y + (c.resource === SCREEN ? placed.y : 0); - const x = placed.x + (c.op === DrawOp.IMAGE ? c.x : c.dx) + shift, y = placed.y + (c.op === DrawOp.IMAGE ? c.y : c.dy); + const at = (v: DrawValue) => evaluate(v, elapsed, presentTime).value; + const sx = c.op === DrawOp.IMAGE ? 0 : at(c.x) + (c.resource === SCREEN ? placed.x : 0), sy = c.op === DrawOp.IMAGE ? 0 : at(c.y) + (c.resource === SCREEN ? placed.y : 0); + const x = placed.x + (c.op === DrawOp.IMAGE ? c.x : at(c.dx)) + shift, y = placed.y + (c.op === DrawOp.IMAGE ? c.y : at(c.dy)); for (let yy = 0; yy < h; yy++) for (let xx = 0; xx < w; xx++) { if (x + xx < 0 || y + yy < 0 || x + xx >= width || y + yy >= height || sx + xx < 0 || sy + yy < 0 || sx + xx >= source.width || sy + yy >= source.height) continue; const v = q(source.pixels[(sy + yy) * source.width + sx + xx]); diff --git a/app/graphics/draw-expression.ts b/app/graphics/draw-expression.ts index 869ea641..f122d679 100644 --- a/app/graphics/draw-expression.ts +++ b/app/graphics/draw-expression.ts @@ -59,12 +59,17 @@ export class DrawExpression { } /** Time already elapsed on this list's timeline when the next PRESENT happens. */ static elapsed(): DrawExpression<'i32'> { return new DrawExpression('i32', [ExprOp.ELAPSED]); } - /** A 0..1 timeline fraction that survives subsequent PRESENT clock resets. */ - static progress(durationMs: number): DrawExpression<'f32'> { + /** + * A 0..1 timeline fraction that survives subsequent PRESENT clock resets. + * With a delay, it stays 0 for the first delayMs of the timeline. + */ + static progress(durationMs: number, delayMs = 0): DrawExpression<'f32'> { const duration = DrawExpression.i32(integer(durationMs, 1, 2147483647)); - const elapsed = DrawExpression.elapsed().min(duration); - return duration.sub(elapsed).max(DrawExpression.i32(0)).time() - .add(elapsed).toFloat().div(duration.toFloat()); + const end = DrawExpression.i32(integer(delayMs + durationMs, 1, 2147483647)); + const elapsed = DrawExpression.elapsed().min(end); + let total = end.sub(elapsed).max(DrawExpression.i32(0)).time().add(elapsed); + if (delayMs) total = total.sub(DrawExpression.i32(delayMs)).max(DrawExpression.i32(0)); + return total.toFloat().div(duration.toFloat()); } static decode(code: Uint8Array): DrawExpression<'i32'> { return new DrawExpression('i32', Array.from(code)); } private binary(other: DrawExpression, i: number, f: number): DrawExpression { diff --git a/app/graphics/menu-scroll-list.ts b/app/graphics/menu-scroll-list.ts new file mode 100644 index 00000000..7517d8e3 --- /dev/null +++ b/app/graphics/menu-scroll-list.ts @@ -0,0 +1,46 @@ +import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion'; +import type { MenuScrollAnimation } from '../ui/menu-scroll-motion'; +import { DrawExpression as E, type DrawValue } from './draw-expression'; +import { DrawOp, type DisplayList, type ListCall, type ListImage } from './display-list'; + +export type MenuScrollHighlight = { + /** Final row top within the viewport. */ + y: number; + width: number; + height: number; + radius: number; + /** Gray8, like drawMenuSelection. */ + background: number; + border: number; + animation?: MenuHighlightAnimation; +}; + +/** + * A menu viewport scrolling over a pre-rendered strip. `strip` holds every + * row that is visible at any point of the scroll, starting at content offset + * `stripTop` and `stripX` pixels into the viewport. The copy's source row is + * the animated value; the highlight is max-blended over the copied rows, + * sliding on the same timeline and clamped inside the viewport. + */ +export function menuScrollList(strip: ListImage, stripX: number, stripTop: number, viewportHeight: number, + scroll: MenuScrollAnimation, highlight?: MenuScrollHighlight): DisplayList { + const eased = (durationMs: number, delayMs = 0) => E.progress(durationMs, delayMs).ease(); + const sourceY: DrawValue = eased(scroll.durationMs) + .lerp(E.i32(scroll.from - stripTop).toFloat(), E.i32(scroll.to - stripTop).toFloat()).toInt(); + const calls: ListCall[] = [ + { op: DrawOp.RECT_COPY, resource: 0, x: 0, y: sourceY, width: strip.width, height: viewportHeight, dx: stripX, dy: 0 }, + ]; + if (highlight) { + const q = (n: number) => Math.min(15, (n + 8) >> 4); + const motion = highlight.animation; + let y: DrawValue = highlight.y; + if (motion?.dy) { + const delay = Math.max(0, motion.startedAt - scroll.startedAt); + y = eased(motion.durationMs, delay).lerp(E.i32(highlight.y + motion.dy).toFloat(), E.i32(highlight.y).toFloat()).toInt() + .max(E.i32(0)).min(E.i32(viewportHeight - highlight.height)); + } + calls.push({ op: DrawOp.ROUNDED_RECT, x: 0, y, width: highlight.width, height: highlight.height, radius: highlight.radius, + background: q(highlight.background), border: q(highlight.border) }); + } + return { resources: [strip], timeline: scroll, calls }; +} diff --git a/app/ui/menu-core.ts b/app/ui/menu-core.ts index 108e07b3..97f84479 100644 --- a/app/ui/menu-core.ts +++ b/app/ui/menu-core.ts @@ -1,6 +1,8 @@ import { GrayImage } from "../graphics/image"; +import { menuScrollList, type MenuScrollHighlight } from "../graphics/menu-scroll-list"; import type { InputEvent } from "./gestures"; import { MenuHighlightMotion } from "./menu-highlight-motion"; +import { MenuScrollMotion, type MenuScrollAnimation } from "./menu-scroll-motion"; /** Selected-row fill while the menu owns input; the outline alone marks an unfocused menu's selection. */ export const MENU_HIGHLIGHT_FILL = 15; @@ -9,6 +11,8 @@ const SCROLLBAR_TRACK_VALUE = 30; const SCROLLBAR_THUMB_VALUE = 120; const SCROLLBAR_WIDTH = 3; const SCROLLBAR_MIN_THUMB = 8; +/** Largest packed scroll strip, in bytes: the firmware's per-resource limit. */ +const MAX_SCROLL_STRIP_BYTES = 65536; /** A rectangle in image coordinates. */ export type MenuBox = { x: number; y: number; width: number; height: number }; @@ -17,8 +21,9 @@ export type MenuDrawArgs = { /** * Draw into this image, inside the (x, y, width, height) rect. For the * selected row this is a scratch image exactly the rect's size (so x and y - * are 0), replayed over the highlight. Never draw relative to image.width - * or image.height, and never outside the rect. + * are 0), replayed over the highlight. While a scroll animates, rows are + * also drawn into a strip image covering both viewports. Never draw + * relative to image.width or image.height, and never outside the rect. */ image: GrayImage; item: T; @@ -73,9 +78,16 @@ type MenuLayout = { tops: number[]; heights: number[]; total: number }; * * Rows may vary in height and some may be unselectable; navigation skips * those. Scrolling is pixel-based: the viewport moves the minimum needed to - * keep the selection fully visible, then aligns to a row top so the list - * never starts with a partially visible row. Rows that don't fully fit at - * the bottom are not drawn. + * keep the selection and its neighbors fully visible (just the selection + * when they don't all fit), then aligns to a row top so the list never + * starts with a partially visible row. Rows that don't fully fit at the + * bottom are not drawn. + * + * Navigation that scrolls (without wrapping) animates on the glasses: the + * rows visible before and after are drawn into one strip, and a display list + * slides a viewport-sized copy of it while the highlight moves on the same + * timeline. When the strip would be too large or the menu doesn't fit the + * assumptions below (see scrollStrip), the scroll snaps instead. */ export class Menu { private itemList: readonly T[]; @@ -89,6 +101,7 @@ export class Menu { private scrollY = 0; private lastBox: MenuBox | null = null; private readonly motion = new MenuHighlightMotion(); + private readonly scrollMotion = new MenuScrollMotion(); constructor(private readonly options: MenuOptions) { this.itemList = options.items ?? []; @@ -162,6 +175,7 @@ export class Menu { const next = this.nextSelectable(from, delta); if (next !== null) { if (from !== null) this.motion.navigate(from, false); + this.scrollMotion.navigate(false); this.selected = next; this.deselected = false; return; @@ -171,6 +185,7 @@ export class Menu { const wrapped = this.nextSelectable(null, delta); if (wrapped !== null && wrapped !== from) { if (from !== null) this.motion.navigate(from, true); + this.scrollMotion.navigate(true); this.selected = wrapped; this.deselected = false; } else if (from === null && this.lastBox) { @@ -225,8 +240,13 @@ export class Menu { this.reconcile(); const layout = this.layout(box.width); this.ensureVisible(layout, box.height); + const now = Date.now(); + const scroll = this.scrollMotion.paint(this.scrollY, box, now); + const strip = scroll ? this.scrollStrip(image, layout, box, focused, scroll) : null; + if (scroll && !strip) this.scrollMotion.cancel(); const gap = this.options.rowGap ?? 0; const highlight = this.options.highlight; + let scrollHighlight: MenuScrollHighlight | undefined; for (let index = 0; index < this.itemList.length; index++) { const top = layout.tops[index]! - this.scrollY; const height = layout.heights[index]! - gap; @@ -238,15 +258,28 @@ export class Menu { const rowY = box.y + top; const item = this.itemList[index]!; if (selected && highlight !== false) { + const animation = this.motion.paint(index, this.scrollY, box.x, rowY, box.width, height, now, !!strip); + const background = focused ? MENU_HIGHLIGHT_FILL : 0; + if (strip) { + // The strip already holds this row's content; only the box is drawn over it. + scrollHighlight = { y: top, width: box.width, height, radius: highlight?.radius ?? 8, + background, border: MENU_HIGHLIGHT_STROKE, animation }; + continue; + } const row = new GrayImage(box.width, height, 0); this.options.draw({ image: row, item, index, x: 0, y: 0, width: box.width, height, selected, focused }); - const animation = this.motion.paint(index, this.scrollY, box.x, rowY, box.width, height, Date.now()); - image.drawMenuSelection(row, box.x, rowY, focused ? MENU_HIGHLIGHT_FILL : 0, MENU_HIGHLIGHT_STROKE, + image.drawMenuSelection(row, box.x, rowY, background, MENU_HIGHLIGHT_STROKE, highlight?.radius ?? 8, highlight?.depth ?? 0, animation); } else { this.options.draw({ image, item, index, x: box.x, y: rowY, width: box.width, height, selected, focused }); } } + // The rows painted above stay underneath: once the animation ends, the + // strip's final frame and the static paint are pixel-identical. + if (strip && scroll) { + image.drawDisplayList(menuScrollList(strip.image, strip.x, strip.top, box.height, scroll, scrollHighlight), + box.x, box.y, box.width, box.height, 0); + } } /** Draw a vertical scrollbar for the last painted box (no-op unless the content overflows it). */ @@ -262,6 +295,65 @@ export class Menu { image.fillRect(x, y + (((height - thumbHeight) * fraction) | 0), SCROLLBAR_WIDTH, thumbHeight, SCROLLBAR_THUMB_VALUE); } + /** + * Render every row visible at either end of the scroll into one strip, or + * return null to snap. Its final frame must match the static paint, so + * rows the static paint hides (partial ones at the bottom) are left out of + * the part the new viewport shows. The strip copy is opaque, so this also + * requires a black background under the menu, a selected row that fits, + * and a highlight at the menu's own depth. + */ + private scrollStrip(image: GrayImage, layout: MenuLayout, box: MenuBox, focused: boolean, + scroll: MenuScrollAnimation): { image: GrayImage; x: number; top: number } | null { + const highlight = this.options.highlight; + if (highlight !== false && (highlight?.depth ?? 0) !== 0) return null; + const gap = this.options.rowGap ?? 0; + const selected = this.selected; + if (selected !== null && layout.tops[selected]! + layout.heights[selected]! - gap - scroll.to > box.height) return null; + const top = Math.min(scroll.from, scroll.to); + const bottom = Math.max(scroll.from, scroll.to) + box.height; + const strip = new GrayImage(box.width, bottom - top, 0); + for (let index = 0; index < this.itemList.length; index++) { + const rowTop = layout.tops[index]!; + const height = layout.heights[index]! - gap; + const rowBottom = rowTop + height; + const shownAfter = rowTop >= scroll.to && rowBottom <= scroll.to + box.height; + const outsideAfter = rowBottom <= scroll.to || rowTop >= scroll.to + box.height; + if (!shownAfter && !(outsideAfter && rowTop >= top && rowBottom <= bottom)) continue; + const item = this.itemList[index]!; + const y = rowTop - top; + const isSelected = index === selected; + if (isSelected && highlight !== false) { + // Clip like the static selected row, which is drawn in a scratch image. + const row = new GrayImage(box.width, height, 0); + this.options.draw({ image: row, item, index, x: 0, y: 0, width: box.width, height, selected: true, focused }); + strip.bitBlt(row.withDrawsBaked(), 0, y, { transparentZero: true }); + } else { + this.options.draw({ image: strip, item, index, x: 0, y, width: box.width, height, selected: isSelected, focused }); + } + } + // Crop to the columns with ink; the static paint shows the rest unchanged. + const baked = strip.withDrawsBaked(); + let left = baked.width, right = -1; + for (let y = 0; y < baked.height; y++) { + const row = y * baked.width; + for (let x = 0; x < left; x++) if (baked.pixels[row + x]! >= 8) { left = x; break; } + for (let x = baked.width - 1; x > right; x--) if (baked.pixels[row + x]! >= 8) { right = x; break; } + } + if (right < left) return null; + const width = right - left + 1; + if (5 + Math.ceil(width / 2) * baked.height > MAX_SCROLL_STRIP_BYTES) return null; + // Whatever the host drew under the copied columns would be covered. + for (let y = box.y; y < box.y + box.height; y++) { + for (let x = box.x + left; x <= box.x + right; x++) { + if (x >= 0 && y >= 0 && x < image.width && y < image.height && image.pixels[y * image.width + x]! >= 8) return null; + } + } + const cropped = new GrayImage(width, baked.height, 0); + cropped.bitBlt(baked, -left, 0); + return { image: cropped, x: left, top }; + } + private isSelectable(index: number): boolean { return this.options.isSelectable?.(this.itemList[index]!) ?? true; } @@ -319,17 +411,27 @@ export class Menu { this.scrollY = Math.max(0, Math.min(this.maxScroll(layout, viewportHeight), this.scrollY)); return; } - const top = layout.tops[this.selected]!; - const bottom = top + layout.heights[this.selected]! - (this.options.rowGap ?? 0); + const gap = this.options.rowGap ?? 0; + const selected = this.selected; + const top = layout.tops[selected]!; + const bottom = top + layout.heights[selected]! - gap; + // Keep the neighbors in view too when all three fit, so the user sees + // what the next step will reach. + const contextTop = selected > 0 ? layout.tops[selected - 1]! : top; + const contextBottom = selected + 1 < this.itemList.length + ? layout.tops[selected + 1]! + layout.heights[selected + 1]! - gap : bottom; + const fits = contextBottom - contextTop <= viewportHeight; + const wantTop = fits ? contextTop : top; + const wantBottom = fits ? contextBottom : bottom; let target = this.scrollY; - if (top < target) { - target = top; - } else if (bottom > target + viewportHeight) { + if (wantTop < target) { + target = wantTop; + } else if (wantBottom > target + viewportHeight) { // A row taller than the viewport shows from its top. - target = Math.min(top, bottom - viewportHeight); - // Snap to the first row that starts inside the viewport: the selected - // row still fits (its bottom is within viewportHeight of that top). - for (let index = 0; index <= this.selected; index++) { + target = Math.min(top, wantBottom - viewportHeight); + // Snap to the first row that starts inside the viewport: the wanted + // rows still fit (their bottom is within viewportHeight of that top). + for (let index = 0; index <= selected; index++) { if (layout.tops[index]! >= target) { target = layout.tops[index]!; break; diff --git a/app/ui/menu-highlight-motion.ts b/app/ui/menu-highlight-motion.ts index e7c09121..74116a5a 100644 --- a/app/ui/menu-highlight-motion.ts +++ b/app/ui/menu-highlight-motion.ts @@ -3,6 +3,11 @@ export type MenuHighlightAnimation = { dx: number; dy: number; startedAt: number let nextToken = 1; +/** A fresh display-list timeline token, shared by all menu animations. */ +export function nextAnimationToken(): number { + return nextToken++; +} + /** Eligibility is decided by menu navigation, before the display-list bridge. */ export class MenuHighlightMotion { private previous?: { index: number; scroll: number; x: number; y: number; width: number; height: number }; @@ -13,7 +18,8 @@ export class MenuHighlightMotion { this.fromIndex = wrapped ? null : from; } - paint(index: number, scroll: number, x: number, y: number, width: number, height: number, now: number): MenuHighlightAnimation | undefined { + /** `scrolling`: the scroll change since the last paint is itself animated, so the highlight may slide across it. */ + paint(index: number, scroll: number, x: number, y: number, width: number, height: number, now: number, scrolling = false): MenuHighlightAnimation | undefined { const previous = this.previous; if (!previous || previous.index !== index || previous.scroll !== scroll || previous.x !== x || previous.y !== y || previous.width !== width || previous.height !== height) { @@ -25,8 +31,8 @@ export class MenuHighlightMotion { fromY += this.animation.dy * remaining; } const eligible = previous && previous.index !== index && this.fromIndex === previous.index && - previous.scroll === scroll && previous.width === width && previous.height === height; - this.animation = eligible ? { dx: Math.round(fromX - x), dy: Math.round(fromY - y), startedAt: now, token: nextToken++, durationMs: MENU_HIGHLIGHT_DURATION_MS } : undefined; + (previous.scroll === scroll || scrolling) && previous.width === width && previous.height === height; + this.animation = eligible ? { dx: Math.round(fromX - x), dy: Math.round(fromY - y), startedAt: now, token: nextAnimationToken(), durationMs: MENU_HIGHLIGHT_DURATION_MS } : undefined; this.fromIndex = null; this.previous = { index, scroll, x, y, width, height }; } diff --git a/app/ui/menu-scroll-motion.ts b/app/ui/menu-scroll-motion.ts new file mode 100644 index 00000000..676944fb --- /dev/null +++ b/app/ui/menu-scroll-motion.ts @@ -0,0 +1,53 @@ +import { MENU_HIGHLIGHT_DURATION_MS, nextAnimationToken } from "./menu-highlight-motion"; + +/** Longest scroll, in pixels, that animates; longer jumps snap. */ +export const MAX_ANIMATED_SCROLL = 96; + +/** A viewport moving from content offset `from` to `to`, on the same clock as the highlight. */ +export type MenuScrollAnimation = { from: number; to: number; startedAt: number; token: number; durationMs: number }; + +type Box = { x: number; y: number; width: number; height: number }; + +/** + * Tracks the painted scroll offset. Only a change caused by non-wrapping + * navigation animates; programmatic scrolls, item edits and geometry changes + * snap. A scroll during an animation starts from the offset on screen now. + */ +export class MenuScrollMotion { + private previous?: { scroll: number; box: Box }; + private navigated = false; + private animation?: MenuScrollAnimation; + + navigate(wrapped: boolean): void { + this.navigated = !wrapped; + } + + /** Record this paint's settled offset; returns the animation in flight, if any. */ + paint(scroll: number, box: Box, now: number): MenuScrollAnimation | undefined { + const previous = this.previous; + const sameBox = !!previous && previous.box.x === box.x && previous.box.y === box.y && + previous.box.width === box.width && previous.box.height === box.height; + if (!previous || !sameBox || previous.scroll !== scroll) { + const from = previous ? this.offsetAt(previous.scroll, now) : scroll; + const eligible = sameBox && this.navigated && from !== scroll && Math.abs(scroll - from) <= MAX_ANIMATED_SCROLL; + this.animation = eligible + ? { from, to: scroll, startedAt: now, token: nextAnimationToken(), durationMs: MENU_HIGHLIGHT_DURATION_MS } + : undefined; + this.previous = { scroll, box: { ...box } }; + } + this.navigated = false; + return this.animation && now - this.animation.startedAt < this.animation.durationMs ? this.animation : undefined; + } + + /** Cancel an animation in flight, e.g. when it cannot be drawn; the next change snaps from `settled`. */ + cancel(): void { + this.animation = undefined; + } + + private offsetAt(settled: number, now: number): number { + const animation = this.animation; + if (!animation) return settled; + const t = Math.max(0, Math.min(1, (now - animation.startedAt) / animation.durationMs)); + return Math.round(animation.from + (animation.to - animation.from) * t * t * (3 - 2 * t)); + } +} diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt index 3d3e9537..95b1fb25 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/DrawProtocol.kt @@ -1,6 +1,6 @@ package com.faceclaw.app -/** Revision 28 wire grammar, shared by scene planning and the local renderer. */ +/** Revision 29 wire grammar, shared by scene planning and the local renderer. */ object DrawProtocol { /** Mirrors g2flash/patches/zlib_glue.c. */ const val DRAW = CFW_MSG_DRAW_CALLS @@ -97,14 +97,21 @@ object DrawProtocol { fun rectCopy( source: Int, x: Int, y: Int, width: Int, height: Int, dx: Int, dy: Int, target: Int? = null, depth: Int? = null, + ): ByteArray = rectCopy(source, DrawValue.Integer(x), DrawValue.Integer(y), width, height, + DrawValue.Integer(dx), DrawValue.Integer(dy), target, depth) + + /** Revision 29: source and destination coordinates may be expressions; the source rect must stay in bounds. */ + fun rectCopy( + source: Int, x: DrawValue, y: DrawValue, width: Int, height: Int, dx: DrawValue, dy: DrawValue, + target: Int? = null, depth: Int? = null, ): ByteArray = call(DRAW_OP_RECT_COPY, target, depth) { writeU16(source) - writeU16(x) - writeU16(y) + writeExtended(x) + writeExtended(y) writeU16(width) writeU16(height) - writeS16(dx) - writeS16(dy) + writeExtended(dx) + writeExtended(dy) } /** Fill the whole target, ignoring depth. */ diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt index 08a9c5bd..a6907908 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/DisplayListRenderer.kt @@ -256,13 +256,14 @@ class DisplayListRenderer( private fun drawRectCopy(reader: DrawReader, target: Target, walk: Walk) { val id = reader.readU16() - val x = reader.readU16() - val y = reader.readU16() + val x = ExtendedVarint.evaluate(reader, walk.frame) + val y = ExtendedVarint.evaluate(reader, walk.frame) val width = reader.readU16() val height = reader.readU16() - val dx = reader.readS16() - val dy = reader.readS16() + val dx = ExtendedVarint.evaluate(reader, walk.frame) + val dy = ExtendedVarint.evaluate(reader, walk.frame) reader.requireDone() + require(x >= 0 && y >= 0) val source = when (id) { DrawProtocol.SCREEN -> walk.screen DrawProtocol.CURRENT -> target @@ -272,7 +273,8 @@ class DisplayListRenderer( } } require(width > 0 && height > 0 && x + width <= source.width && y + height <= source.height) - if (walk.apply) { + // Mirrors the firmware's overflow guard before the depth shift. + if (walk.apply && dx in -65536..65536) { // Snapshot the rectangle so overlapping copies have memmove semantics. val copy = IntArray(width * height) { source.get(x + it % width, y + it / width) } for (i in copy.indices) target.put(dx + i % width, dy + i / width, copy[i]) diff --git a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt index 0d7c467f..18e9f44d 100644 --- a/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt +++ b/native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/graphics/FrameDisplayList.kt @@ -21,7 +21,8 @@ class FrameDisplayList private constructor( override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity) private class Command(val op: Int, val depth: Int, val values: IntArray, - val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0)) + val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0), + val dx: DrawValue = DrawValue.Integer(0), val dy: DrawValue = DrawValue.Integer(0)) override fun calls(ids: IntArray, nowMs: Long): List { require(ids.size == resources.size) @@ -34,9 +35,9 @@ class FrameDisplayList private constructor( v[0], v[1], v[2], v[3], v[4], depth + c.depth) DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), x + v[1], y + v[2], v[3], depth = depth + c.depth) DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]), - v[1] + if (v[0] == DrawProtocol.SCREEN) x else 0, - v[2] + if (v[0] == DrawProtocol.SCREEN) y else 0, - v[3], v[4], x + v[5], y + v[6], depth = depth + c.depth) + bind(c.x, elapsed, if (v[0] == DrawProtocol.SCREEN) x else 0), + bind(c.y, elapsed, if (v[0] == DrawProtocol.SCREEN) y else 0), + v[1], v[2], bind(c.dx, elapsed, x), bind(c.dy, elapsed, y), depth = depth + c.depth) else -> error("Unsupported frame display-list opcode") } } @@ -115,11 +116,12 @@ class FrameDisplayList private constructor( Command(op, d, intArrayOf(id, xx, yy, options)) } DRAW_OP_RECT_COPY -> { - val id = resource(); val sx = r.readS16(); val sy = r.readS16() - val w = r.readU16(); val h = r.readU16(); val dx = r.readS16(); val dy = r.readS16() + val id = resource(); val sx = value(); val sy = value() + val w = r.readU16(); val h = r.readU16(); val dx = value(); val dy = value() require(w in 1..640 && h in 1..480) - require(id == DrawProtocol.SCREEN || sx >= 0 && sy >= 0) - Command(op, d, intArrayOf(id, sx, sy, w, h, dx, dy)) + // Relative SCREEN sources may be negative until placement is added. + require(id == DrawProtocol.SCREEN || listOf(sx, sy).all { it !is DrawValue.Integer || it.value >= 0 }) + Command(op, d, intArrayOf(id, w, h), sx, sy, dx, dy) } else -> error("Unsupported frame display-list opcode") } diff --git a/tests/brightness-picker.test.cjs b/tests/brightness-picker.test.cjs index 4163c5ba..997b131c 100644 --- a/tests/brightness-picker.test.cjs +++ b/tests/brightness-picker.test.cjs @@ -27,11 +27,11 @@ const layers = load('app/ui/layers.ts', { '../native/frame-timings': { spanCurrent: (_name, paint) => paint() }, }); const menu = load('app/ui/menu.ts', { - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap, '../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'), './menu-core': load('app/ui/menu-core.ts', { - '../graphics/image': graphics, './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), + '../graphics/image': graphics, './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), }), }); diff --git a/tests/display-list-authoring.test.cjs b/tests/display-list-authoring.test.cjs index d3f7cc61..490941e2 100644 --- a/tests/display-list-authoring.test.cjs +++ b/tests/display-list-authoring.test.cjs @@ -6,7 +6,7 @@ const { GrayImage } = require('../.test-build/app/graphics/image.js'); const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js'); // Also consumed by FrameDisplayListTest.kt: bridge bytes, not independently rebuilt native calls. const MENU = '077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f'; -const MULTI = '074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000'; +const MULTI = '0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00'; test('extended integers agree with firmware widths and sign extension', () => { const vectors = [[63,'3f'],[-64,'40'],[64,'8040'],[-65,'bfbf'],[8191,'9fff'],[-8192,'a000'],[8192,'c02000'],[-8193,'dfdfff'],[1048575,'cfffff'],[-1048576,'d00000'],[1048576,'e0100000'],[-1048577,'efefffff'],[134217727,'e7ffffff'],[-134217728,'e8000000'],[134217728,'f008000000'],[2147483647,'f07fffffff'],[-2147483648,'f080000000']]; diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt index a3fb26d9..a13d5cb9 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DisplayListTest.kt @@ -90,9 +90,20 @@ class DisplayListTest { } @Test fun graphValidationPrecedesMutationAndCopyPreservesOverlap() { val screen=hex("12345678"); val target=DisplayListRenderer.Target(screen,8,1) - val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff000000000600010002000000")) + val copy=DrawProtocol.call(DRAW_OP_RECT_COPY,hex("feff0000060001000200")) DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(copy)),target) assertContentEquals(hex("12123456"),screen) + // Revision 29: an animated source row scrolls a raw strip; source bounds are checked each frame. + val strip=mapOf(9 to DrawProtocol.rawImage(2,4,hex("11223344"))) + val scroll=DrawProtocol.rectCopy(9,DrawValue.Integer(0),DrawValue.animate(0,2,100),2,2,DrawValue.Integer(0),DrawValue.Integer(0)) + for ((elapsed,rows) in listOf(0L to "1122",100L to "3344",500L to "3344")) { + val window=DisplayListRenderer.Target(ByteArray(2),2,2) + val renderer=DisplayListRenderer(strip) + renderer.execute(DrawProtocol.sequence(listOf(scroll)),window,elapsedMs=elapsed) + assertContentEquals(hex(rows),window.bytes); assertEquals(elapsed<100,renderer.animationPending) + } + val past=DrawProtocol.rectCopy(9,0,3,2,2,0,0) + assertFails { DisplayListRenderer(strip).execute(DrawProtocol.sequence(listOf(past)),DisplayListRenderer.Target(ByteArray(2),2,2)) } val valid=DrawProtocol.bbox(hex("ffffffff"),4,0,0,8,1) assertFails { DisplayListRenderer(emptyMap()).execute(DrawProtocol.sequence(listOf(valid,byteArrayOf(99,0))),target) } assertContentEquals(hex("12123456"),screen) diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt index 52db8cf2..91622969 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/DrawWireTest.kt @@ -5,13 +5,13 @@ import kotlin.test.* class DrawWireTest { private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray() - @Test fun encodersUseRevision28CoordinatesAndPreserveOtherWireBytes() { + @Test fun encodersUseRevision29CoordinatesAndPreserveOtherWireBytes() { // Literal vectors pin the firmware grammar independently of the reader. val calls = listOf( DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to "0403ff018034120080ff7f1f", DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to - "0200feff0100020003000400fbfffaff", + "0200feff0102030004007b7a", DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9", DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f", DrawProtocol.playList(511, depth = 127) to "07027fff01", @@ -29,11 +29,11 @@ class DrawWireTest { assertContentEquals(hex("1bffff"), DrawProtocol.root(DrawProtocol.SCREEN)) val flat = DrawProtocol.screenCopy(640, 352) assertEquals(1, flat.size) - assertContentEquals(hex("0200ffff000000008002600100000000"), flat[0]) + assertContentEquals(hex("0200ffff0000800260010000"), flat[0]) val shifted = DrawProtocol.screenCopy(640, 352, -32) assertEquals(2, shifted.size) assertContentEquals(hex("090000"), shifted[0]) - assertContentEquals(hex("0202e0ffff000000008002600100000000"), shifted[1]) + assertContentEquals(hex("0202e0ffff0000800260010000"), shifted[1]) } @Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() { @@ -43,7 +43,7 @@ class DrawWireTest { "0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9", "030001020134120f10" to "010000000102010f10", "060f10" to "01000100000000080002000f10", - "090100020003000400fbfffaff" to "0200feff0100020003000400fbfffaff", + "090100020003000400fbfffaff" to "0200feff0102030004007b7a", ) for ((record, expected) in records) { val calls = DrawProtocol.fromOptimized(hex(record), 8, 2) diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt index 29975bc8..0c4a677a 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt @@ -5,7 +5,8 @@ import kotlin.test.* class FrameDisplayListTest { // Golden records emitted by display-list-authoring.test.cjs. private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f" - private val multi = "074c000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f020000010000000000010001000200000002feffffffffff000001000100ffff0000" + private val multi = "0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00" + private val scroll = "0787000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff220100300102300180f0800180f0161101001732800180f01610300180f0302341403102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103" private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray() private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList { val reader = ArrayByteReader(bytes) @@ -36,6 +37,25 @@ class FrameDisplayListTest { assertNotEquals(read(hex(menu)).fingerprint, read(other).fingerprint) } + @Test fun animatedCopySourcesRebindOnPresentAndDestinationsTranslate() { + // Emitted by menu-scroll-animation.test.cjs: a menu strip scrolling from row 0 to row 2. + val list = read(hex(scroll)).translated(10, 10) + fun copy(elapsed: Long): List { + val call = DrawReader(list.calls(intArrayOf(5), 1150).first()) + assertEquals(DRAW_OP_RECT_COPY, call.readU8()) + assertEquals(DRAW_FLAG_DEPTH, call.readU8()) + assertEquals(0, call.readS8()) + val frame = DrawEvaluation(elapsed) + val values = listOf(call.readU16(), ExtendedVarint.evaluate(call, frame), ExtendedVarint.evaluate(call, frame), + call.readU16(), call.readU16(), ExtendedVarint.evaluate(call, frame), ExtendedVarint.evaluate(call, frame)) + call.requireDone() + return values + if (frame.animationPending) 1 else 0 + } + // 150 of 240 ms elapsed before this PRESENT; the source row is not translated with the surface. + assertEquals(listOf(5, 0, 1, 2, 2, 14, 12, 1), copy(0)) + assertEquals(listOf(5, 0, 2, 2, 2, 14, 12, 0), copy(90)) + } + @Test fun localResourceIdsAreResolvedAndScreenCopiesStayAtScreenDepth() { val list = read(hex(multi)).translated(10, 10) val calls = list.calls(intArrayOf(41, 42), 1150) diff --git a/tests/menu-core.test.cjs b/tests/menu-core.test.cjs index ce64f813..2b16b034 100644 --- a/tests/menu-core.test.cjs +++ b/tests/menu-core.test.cjs @@ -11,8 +11,15 @@ function stringMenu(overrides = {}) { const menu = new Menu({ items: ['a', 'b', 'c', 'd', 'e'], getHeight: () => 20, - draw: (args) => drawn.push({ item: args.item, x: args.x, y: args.y, width: args.width, height: args.height, - selected: args.selected, focused: args.focused, scratch: args.image !== drawn.image }), + draw: (args) => { + // A scroll animation also draws rows into a strip taller than one row; only + // the frame's rows are recorded. A strip's selected row uses a row scratch + // like the static one, and an empty strip falls back to the static paint, + // so paint() keeps one draw per row. + if (args.image !== drawn.image && args.image.height !== args.height) return; + drawn.push({ item: args.item, index: args.index, x: args.x, y: args.y, width: args.width, height: args.height, + selected: args.selected, focused: args.focused, scratch: args.image !== drawn.image }); + }, onSelect: (item, index) => selected.push({ item, index }), onExitTop: () => exits.top++, onExitBottom: () => exits.bottom++, @@ -23,7 +30,8 @@ function stringMenu(overrides = {}) { const paint = (focused = true, box = { x: 10, y: 5, width: 80, height: 60 }) => { drawn.length = 0; menu.paint(image, box, focused); - return drawn.slice(); + const rows = new Map(drawn.map((row) => [row.index, row])); + return [...rows.values()].sort((a, b) => a.index - b.index); }; return { menu, paint, drawn, exits, selected, image }; } @@ -49,14 +57,16 @@ test('rowGap shrinks the drawable box without changing the pitch', () => { assert.deepEqual(rows.map((r) => r.y), [0, 25, 45]); }); -test('scrolling keeps the selection visible and aligns the viewport to a row top', async () => { +test('scrolling keeps the selection and its neighbors visible and aligns the viewport to a row top', async () => { const { menu, paint } = stringMenu(); await menu.handleInput({ type: 'scroll-down' }); + assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c'], 'b and both neighbors already fit'); await menu.handleInput({ type: 'scroll-down' }); + assert.deepEqual(paint().map((r) => r.item), ['b', 'c', 'd'], 'c reveals d below it'); await menu.handleInput({ type: 'scroll-down' }); assert.equal(menu.selectedIndex, 3); - assert.deepEqual(paint().map((r) => r.item), ['b', 'c', 'd']); - assert.equal(menu.scrollTop, 20); + assert.deepEqual(paint().map((r) => r.item), ['c', 'd', 'e']); + assert.equal(menu.scrollTop, 40); await menu.handleInput({ type: 'scroll-up' }); await menu.handleInput({ type: 'scroll-up' }); await menu.handleInput({ type: 'scroll-up' }); @@ -144,14 +154,14 @@ test('setItems keeps the index by default, takes an explicit one, and holds the const { menu, paint } = stringMenu(); menu.select(3); paint(); - assert.equal(menu.scrollTop, 20, 'row d sits at the bottom of the viewport'); + assert.equal(menu.scrollTop, 40, 'row d sits above its neighbor e at the bottom of the viewport'); menu.setItems(['x', 'y', 'z', 'd2', 'e2', 'f2', 'g2']); assert.equal(menu.selectedIndex, 3); - assert.equal(menu.scrollTop, 20); + assert.equal(menu.scrollTop, 40); menu.setItems(['x', 'y', 'z', 'w', 'v', 'u', 'd3'], 6); assert.equal(menu.selectedIndex, 6); paint(); - assert.equal(menu.scrollTop, 80, 'row d3 (top 120) stays 40 px below the viewport top'); + assert.equal(menu.scrollTop, 80, 'row d3 (top 120) stays at the bottom, 40 px below the viewport top'); menu.setItems(['only'], null); assert.equal(menu.selectedIndex, null); menu.setItems(['p', 'q'], 9); @@ -274,14 +284,14 @@ test('setItems never leaves the viewport scrolled past the end of the list', () menu.setItems(['a', 'b', 'c'], 2); assert.deepEqual(paint().map((r) => r.item), ['a', 'b', 'c'], 'a row sorted in above stays visible'); assert.equal(menu.scrollTop, 0); - // The selected row at the top of a scrolled viewport loses the rows below it: + // The selected row near the top of a scrolled viewport loses the rows below it: // keeping its on-screen position would leave a gap, so pull back to show the end. const long = stringMenu({ items: ['a', 'b', 'c', 'd', 'e', 'f', 'g'] }); long.menu.select(6); long.paint(); long.menu.select(4); long.paint(); - assert.equal(long.menu.scrollTop, 80, 'e is the top row'); + assert.equal(long.menu.scrollTop, 60, 'd, above e, is the top row'); long.menu.setItems(['a', 'b', 'c', 'd', 'e'], 4); assert.deepEqual(long.paint().map((r) => r.item), ['c', 'd', 'e']); assert.equal(long.menu.scrollTop, 40); diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs index fc541512..89d8bee8 100644 --- a/tests/menu-display-list.test.cjs +++ b/tests/menu-display-list.test.cjs @@ -16,12 +16,12 @@ function load(file,modules) { const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4, drawText:(image,x,y,text,value)=>{for(let i=0;ifont}, '../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{}, - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), './metrics':require('../.test-build/app/ui/metrics.js'),'./menu-core':menuCore, }); const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}}); diff --git a/tests/menu-scroll-animation.test.cjs b/tests/menu-scroll-animation.test.cjs new file mode 100644 index 00000000..42531672 --- /dev/null +++ b/tests/menu-scroll-animation.test.cjs @@ -0,0 +1,146 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { Menu } = require('../.test-build/app/ui/menu-core.js'); +const { MENU_HIGHLIGHT_DURATION_MS } = require('../.test-build/app/ui/menu-highlight-motion.js'); +const { GrayImage } = require('../.test-build/app/graphics/image.js'); +const { DrawOp, encodeDisplayList, readDisplayList } = require('../.test-build/app/graphics/display-list.js'); +const { evaluate } = require('../.test-build/app/graphics/draw-expression.js'); +const { menuScrollList } = require('../.test-build/app/graphics/menu-scroll-list.js'); +const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js'); +// Also consumed by FrameDisplayListTest.kt. +const SCROLL = '0787000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff220100300102300180f0800180f0161101001732800180f01610300180f0302341403102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103'; + +const BOX = { x: 10, y: 5, width: 40, height: 60 }; +const ITEMS = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; + +function withClock(now, fn) { + const original = Date.now; + Date.now = () => now; + try { return fn(); } finally { Date.now = original; } +} + +/** 20px rows whose ink ignores selection, so frames compare across selection changes. */ +function inkMenu(overrides = {}) { + return new Menu({ + items: ITEMS, + getHeight: () => 20, + draw: ({ image, index, x, y }) => image.fillRect(x + 2 + index, y + 4, 6, 8, 200), + ...overrides, + }); +} + +function paint(menu, now, { box = BOX, background = 0, size = [64, 72] } = {}) { + return withClock(now, () => { + const image = new GrayImage(size[0], size[1], background); + menu.paint(image, box, true); + return image; + }); +} + +const scrollLists = (image) => image.draws + .map((draw) => draw.presentation?.displayList) + .filter((list) => list?.calls.some((call) => call.op === DrawOp.RECT_COPY)); + +/** What the glasses show at `at`, as 4-bit values. */ +function shown(image, at) { + return withClock(at, () => Array.from(image.withDrawsBaked().pixels, (v) => Math.min(15, (v + 8) >> 4))); +} + +test('navigation that scrolls animates a strip covering both viewports', () => { + const menu = inkMenu(); + menu.select(1); + const before = paint(menu, 1000); + assert.equal(menu.scrollTop, 0); + menu.moveSelection(1); + const moving = paint(menu, 2000); + assert.equal(menu.scrollTop, 20, 'c scrolls d into view'); + const [list] = scrollLists(moving); + assert.ok(list, 'a scroll display list is retained'); + const [strip] = list.resources; + assert.equal(strip.height, 80, 'the strip spans the old and new viewports'); + assert.ok(strip.width < BOX.width, 'the strip is cropped to the ink columns'); + const copy = list.calls[0]; + assert.equal(copy.op, DrawOp.RECT_COPY); + assert.equal(copy.height, BOX.height); + assert.deepEqual(evaluate(copy.y, 0, 0), { value: 0, pending: true }); + assert.equal(evaluate(copy.y, MENU_HIGHLIGHT_DURATION_MS / 2, 0).value, 10); + assert.deepEqual(evaluate(copy.y, MENU_HIGHLIGHT_DURATION_MS, 0), { value: 20, pending: false }); + assert.equal(list.calls[1].op, DrawOp.ROUNDED_RECT, 'the highlight is drawn over the copied rows'); + assert.equal(moving.draws.filter((draw) => draw.presentation && !draw.presentation.displayList?.calls.some((c) => c.op === DrawOp.RECT_COPY)).length, 0, + 'the selected row is in the strip, not a separate selection'); + + // First and last frames match the static paints on either side. + assert.deepEqual(shown(moving, 2000), shown(before, 1000)); + const end = 2000 + MENU_HIGHLIGHT_DURATION_MS; + const settled = paint(menu, end); + assert.equal(scrollLists(settled).length, 0, 'the static paint takes over once the animation ends'); + assert.deepEqual(shown(moving, end), shown(settled, end)); +}); + +test('a second move during the scroll starts from the offset on screen', () => { + const menu = inkMenu(); + menu.select(1); + paint(menu, 1000); + menu.moveSelection(1); + paint(menu, 2000); + menu.moveSelection(1); + const image = paint(menu, 2000 + MENU_HIGHLIGHT_DURATION_MS / 2); + assert.equal(menu.scrollTop, 40); + const [list] = scrollLists(image); + assert.equal(list.resources[0].height, 90, 'the strip starts at the current offset, 10'); + assert.equal(evaluate(list.calls[0].y, 0, 0).value, 0); + assert.equal(evaluate(list.calls[0].y, MENU_HIGHLIGHT_DURATION_MS, 0).value, 30); +}); + +test('wraps, programmatic moves, busy backgrounds and oversized strips snap', () => { + const wrapping = inkMenu({ wrap: true }); + wrapping.select(6); + paint(wrapping, 1000); + wrapping.moveSelection(1); + assert.equal(scrollLists(paint(wrapping, 2000)).length, 0, 'wrap'); + + const jumped = inkMenu(); + paint(jumped, 1000); + jumped.select(5); + assert.equal(scrollLists(paint(jumped, 2000)).length, 0, 'select()'); + + const busy = inkMenu(); + busy.select(1); + paint(busy, 1000, { background: 100 }); + busy.moveSelection(1); + const covered = paint(busy, 2000, { background: 100 }); + assert.equal(scrollLists(covered).length, 0, 'the opaque copy would hide the host background'); + assert.equal(covered.draws.filter((draw) => draw.presentation).length, 1, 'the selection is still drawn'); + + // 600px-wide rows: a 600x220 strip exceeds the 64 KiB resource limit unless cropped. + const wide = (inkWidth) => { + const menu = new Menu({ items: Array.from({ length: 20 }, (_, i) => i), getHeight: () => 20, + draw: ({ image, x, y }) => image.fillRect(x, y + 4, inkWidth, 8, 200) }); + const options = { box: { x: 0, y: 0, width: 600, height: 200 }, size: [640, 240] }; + menu.select(8); + paint(menu, 1000, options); + menu.moveSelection(1); + return scrollLists(paint(menu, 2000, options)); + }; + assert.equal(wide(600).length, 0, 'too large'); + assert.equal(wide(40).length, 1, 'narrow ink crops under the limit'); + assert.equal(wide(40)[0].resources[0].width, 40); +}); + +test('scroll lists survive the bridge with animated copy coordinates', () => { + const strip = { width: 2, height: 4, pixels: Uint8Array.of(17, 34, 51, 68, 85, 102, 119, 136) }; + const list = menuScrollList(strip, 1, 0, 2, { from: 0, to: 2, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS }, + { y: 0, width: 4, height: 2, radius: 0, background: 15, border: 45, animation: { dx: 0, dy: 1, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS } }); + const bytes = encodeDisplayList({ displayList: list, x: 3, y: 2, width: 4, height: 2, depth: 0 }, 1150); + assert.equal(Buffer.from(bytes).toString('hex'), SCROLL); + const { placed } = readDisplayList(bytes, 0, 1150); + const [copy, box] = placed.displayList.calls; + assert.equal(evaluate(copy.y, 150, 0).value, 1); + assert.deepEqual(evaluate(copy.y, 150, 90), { value: 2, pending: false }); + assert.equal(copy.dx, 1); + assert.equal(evaluate(box.y, 0, 0).value, 0, 'the highlight is clamped inside the viewport'); + + const image = new GrayImage(8, 8); + image.drawDisplayList(list, 3, 2, 4, 2); + assert.ok(encodePresentation(image.draws[0]).length > 0); +}); diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index 32d693f2..b98e3b54 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -153,7 +153,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp '../graphics/textwrap': textwrap, '../graphics/ui-fonts': { getDefaultSmallFont: () => font }, '../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), './metrics': load('app/ui/metrics.ts'), './gestures': {}, }; deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]); diff --git a/tests/notification-filter.test.cjs b/tests/notification-filter.test.cjs index 669675bb..95cc86a2 100644 --- a/tests/notification-filter.test.cjs +++ b/tests/notification-filter.test.cjs @@ -84,7 +84,7 @@ function ui(fontSize = 12) { '../native/notification-sources': prefs, '../native/notification-access': { isNotificationListenerEnabled: () => true }, '../util/render-freshness': { renderPassAllowsStaleData: () => false }, - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), './metrics': load('app/ui/metrics.ts'), './gestures': {}, }; From f66e0b025fd4e6f7c9ef11022fcdbd82bdfcc5f8 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Thu, 24 Sep 2026 12:23:20 -0700 Subject: [PATCH 22/27] Add partial rows and a bounce effect to menus --- CHANGELOG | 1 + app/graphics/display-list.md | 7 +- app/graphics/draw-expression.ts | 5 +- app/graphics/menu-scroll-list.ts | 43 ++++--- app/ui/menu-core.ts | 112 +++++++++++------- app/ui/menu-scroll-motion.ts | 63 +++++++++- tests/brightness-picker.test.cjs | 4 +- tests/display-list-authoring.test.cjs | 4 + .../com/faceclaw/app/FrameDisplayListTest.kt | 2 +- tests/menu-core.test.cjs | 16 ++- tests/menu-display-list.test.cjs | 4 +- tests/menu-scroll-animation.test.cjs | 79 +++++++++++- tests/music-settings.test.cjs | 2 +- tests/notification-filter.test.cjs | 2 +- 14 files changed, 259 insertions(+), 85 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 52e40066..ebdd0757 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ * A new display-list system for glasses-side drawing, unlocking z-effects and animation * Menus animate when changing selection and scrolling +* Menus bounce at the ends, and show part of the next row when there is more below * Depth effects for the window switcher, top bar, and modals * Glanceboard has configurable distance diff --git a/app/graphics/display-list.md b/app/graphics/display-list.md index 4445bd89..8f6562fb 100644 --- a/app/graphics/display-list.md +++ b/app/graphics/display-list.md @@ -68,8 +68,11 @@ exclude the changing elapsed duration. Without a timeline, raw `time()` expressi start at each PRESENT. Native compilation strips the bridge-only elapsed opcode. `menu-selection-list.ts` authors both the rounded highlight and the transparent row -image using this API. `menu-scroll-list.ts` authors a menu scroll: a viewport-sized -copy from a strip resource whose source y animates, then the highlight. Navigation eligibility, duration, and easing remain in +image using this API. `menu-scroll-list.ts` authors a menu scroll or bounce: a +viewport-sized copy from a strip resource whose source y animates, then the +highlight. The bounce curve (`app/ui/menu-scroll-motion.ts`) needs no branches: +the easing ops clamp their input to 0..1, so `ease(t / p)` holds at 1 after the +peak and `ease((t - p) / (1 - p))` holds at 0 before it. Navigation eligibility, duration, and easing remain in TypeScript. There is no animated-menu tag or menu animation policy in Kotlin. ## Bridge framing diff --git a/app/graphics/draw-expression.ts b/app/graphics/draw-expression.ts index f122d679..dab4604e 100644 --- a/app/graphics/draw-expression.ts +++ b/app/graphics/draw-expression.ts @@ -61,9 +61,12 @@ export class DrawExpression { static elapsed(): DrawExpression<'i32'> { return new DrawExpression('i32', [ExprOp.ELAPSED]); } /** * A 0..1 timeline fraction that survives subsequent PRESENT clock resets. - * With a delay, it stays 0 for the first delayMs of the timeline. + * With a delay, it stays 0 for the first delayMs of the timeline; a + * negative delay continues a motion that started before the timeline. */ static progress(durationMs: number, delayMs = 0): DrawExpression<'f32'> { + integer(delayMs, -2147483647, 2147483647); + if (delayMs + durationMs <= 0) return DrawExpression.f32(1); const duration = DrawExpression.i32(integer(durationMs, 1, 2147483647)); const end = DrawExpression.i32(integer(delayMs + durationMs, 1, 2147483647)); const elapsed = DrawExpression.elapsed().min(end); diff --git a/app/graphics/menu-scroll-list.ts b/app/graphics/menu-scroll-list.ts index 7517d8e3..0f6cc839 100644 --- a/app/graphics/menu-scroll-list.ts +++ b/app/graphics/menu-scroll-list.ts @@ -1,46 +1,45 @@ import type { MenuHighlightAnimation } from '../ui/menu-highlight-motion'; -import type { MenuScrollAnimation } from '../ui/menu-scroll-motion'; import { DrawExpression as E, type DrawValue } from './draw-expression'; import { DrawOp, type DisplayList, type ListCall, type ListImage } from './display-list'; export type MenuScrollHighlight = { - /** Final row top within the viewport. */ - y: number; + /** Row top within the viewport; clamped inside it. */ + y: DrawValue; width: number; height: number; radius: number; /** Gray8, like drawMenuSelection. */ background: number; border: number; - animation?: MenuHighlightAnimation; }; /** - * A menu viewport scrolling over a pre-rendered strip. `strip` holds every - * row that is visible at any point of the scroll, starting at content offset - * `stripTop` and `stripX` pixels into the viewport. The copy's source row is - * the animated value; the highlight is max-blended over the copied rows, - * sliding on the same timeline and clamped inside the viewport. + * A highlight sliding by (0, dy) to rest at `y`, on a list timeline that + * started at `timelineStart` (the slide may have started before or after it). */ -export function menuScrollList(strip: ListImage, stripX: number, stripTop: number, viewportHeight: number, - scroll: MenuScrollAnimation, highlight?: MenuScrollHighlight): DisplayList { - const eased = (durationMs: number, delayMs = 0) => E.progress(durationMs, delayMs).ease(); - const sourceY: DrawValue = eased(scroll.durationMs) - .lerp(E.i32(scroll.from - stripTop).toFloat(), E.i32(scroll.to - stripTop).toFloat()).toInt(); +export function slidingHighlightY(y: number, motion: MenuHighlightAnimation | undefined, timelineStart: number): E<'i32'> { + if (!motion?.dy) return E.i32(y); + return E.progress(motion.durationMs, motion.startedAt - timelineStart).ease() + .lerp(E.i32(y + motion.dy).toFloat(), E.i32(y).toFloat()).toInt(); +} + +/** + * A menu viewport moving over a pre-rendered strip. `strip` holds every row + * visible at any point of the motion, and sits `stripX` pixels into the + * viewport; `sourceY` is the strip row at the viewport's top, animated on + * `timeline`. The highlight is max-blended over the copied rows. + */ +export function menuScrollList(strip: ListImage, stripX: number, viewportHeight: number, + timeline: { token: number; startedAt: number }, sourceY: DrawValue, highlight?: MenuScrollHighlight): DisplayList { const calls: ListCall[] = [ { op: DrawOp.RECT_COPY, resource: 0, x: 0, y: sourceY, width: strip.width, height: viewportHeight, dx: stripX, dy: 0 }, ]; if (highlight) { const q = (n: number) => Math.min(15, (n + 8) >> 4); - const motion = highlight.animation; - let y: DrawValue = highlight.y; - if (motion?.dy) { - const delay = Math.max(0, motion.startedAt - scroll.startedAt); - y = eased(motion.durationMs, delay).lerp(E.i32(highlight.y + motion.dy).toFloat(), E.i32(highlight.y).toFloat()).toInt() - .max(E.i32(0)).min(E.i32(viewportHeight - highlight.height)); - } + const y = typeof highlight.y === 'number' ? highlight.y + : highlight.y.max(E.i32(0)).min(E.i32(viewportHeight - highlight.height)); calls.push({ op: DrawOp.ROUNDED_RECT, x: 0, y, width: highlight.width, height: highlight.height, radius: highlight.radius, background: q(highlight.background), border: q(highlight.border) }); } - return { resources: [strip], timeline: scroll, calls }; + return { resources: [strip], timeline: { token: timeline.token, startedAt: timeline.startedAt }, calls }; } diff --git a/app/ui/menu-core.ts b/app/ui/menu-core.ts index 97f84479..145998b3 100644 --- a/app/ui/menu-core.ts +++ b/app/ui/menu-core.ts @@ -1,8 +1,9 @@ +import { DrawExpression as E } from "../graphics/draw-expression"; import { GrayImage } from "../graphics/image"; -import { menuScrollList, type MenuScrollHighlight } from "../graphics/menu-scroll-list"; +import { menuScrollList, slidingHighlightY, type MenuScrollHighlight } from "../graphics/menu-scroll-list"; import type { InputEvent } from "./gestures"; import { MenuHighlightMotion } from "./menu-highlight-motion"; -import { MenuScrollMotion, type MenuScrollAnimation } from "./menu-scroll-motion"; +import { MenuScrollMotion, scrollOffsetExpression, type MenuScrollAnimation } from "./menu-scroll-motion"; /** Selected-row fill while the menu owns input; the outline alone marks an unfocused menu's selection. */ export const MENU_HIGHLIGHT_FILL = 15; @@ -13,6 +14,9 @@ const SCROLLBAR_WIDTH = 3; const SCROLLBAR_MIN_THUMB = 8; /** Largest packed scroll strip, in bytes: the firmware's per-resource limit. */ const MAX_SCROLL_STRIP_BYTES = 65536; +/** A bounce overshoots by this fraction of the end row's pitch, as if starting to reveal another row. */ +const BOUNCE_FRACTION = 0.4; +const MAX_BOUNCE = 24; /** A rectangle in image coordinates. */ export type MenuBox = { x: number; y: number; width: number; height: number }; @@ -57,7 +61,8 @@ export type MenuOptions = { onSelect?: (item: T, index: number) => void | Promise; /** * Whether scrolling past either end wraps to the other. When false the - * selection stays put and onExitTop / onExitBottom is called instead. + * selection stays put and onExitTop / onExitBottom is called instead; with + * no callback for that end, the list bounces. */ wrap?: boolean; onExitTop?: () => void; @@ -80,14 +85,17 @@ type MenuLayout = { tops: number[]; heights: number[]; total: number }; * those. Scrolling is pixel-based: the viewport moves the minimum needed to * keep the selection and its neighbors fully visible (just the selection * when they don't all fit), then aligns to a row top so the list never - * starts with a partially visible row. Rows that don't fully fit at the - * bottom are not drawn. + * starts with a partially visible row. A row cut off by the viewport's edge + * is drawn clipped, so a box that isn't a whole number of rows tall shows + * part of the next row as a hint that there is more. * * Navigation that scrolls (without wrapping) animates on the glasses: the * rows visible before and after are drawn into one strip, and a display list * slides a viewport-sized copy of it while the highlight moves on the same - * timeline. When the strip would be too large or the menu doesn't fit the - * assumptions below (see scrollStrip), the scroll snaps instead. + * timeline. Scrolling past an end without wrap or an exit callback bounces + * the same way, with the highlight carried along by its row. When the strip + * would be too large or the menu doesn't fit the assumptions in scrollStrip, + * the motion snaps instead. */ export class Menu { private itemList: readonly T[]; @@ -193,8 +201,9 @@ export class Menu { } return; } - if (delta > 0) this.options.onExitBottom?.(); - else this.options.onExitTop?.(); + const exit = delta > 0 ? this.options.onExitBottom : this.options.onExitTop; + if (exit) exit(); + else this.bounce(delta); } /** Invoke onSelect for the selected item. Returns false when nothing is selected. */ @@ -251,33 +260,35 @@ export class Menu { const top = layout.tops[index]! - this.scrollY; const height = layout.heights[index]! - gap; const selected = index === this.selected; - if (top < 0 || top >= box.height) continue; - // Rows cut off by the bottom edge are not drawn, except a selected row - // taller than the box, which has nowhere better to be. - if (top + height > box.height && !selected) continue; + if (top + height <= 0 || top >= box.height) continue; const rowY = box.y + top; const item = this.itemList[index]!; if (selected && highlight !== false) { const animation = this.motion.paint(index, this.scrollY, box.x, rowY, box.width, height, now, !!strip); const background = focused ? MENU_HIGHLIGHT_FILL : 0; - if (strip) { + if (strip && scroll) { // The strip already holds this row's content; only the box is drawn over it. - scrollHighlight = { y: top, width: box.width, height, radius: highlight?.radius ?? 8, - background, border: MENU_HIGHLIGHT_STROKE, animation }; + let y = slidingHighlightY(top, animation, scroll.startedAt); + // A bounce carries the highlight with its row. + if (scroll.peak !== undefined) y = y.add(E.i32(scroll.to)).sub(scrollOffsetExpression(scroll)); + scrollHighlight = { y, width: box.width, height, radius: highlight?.radius ?? 8, + background, border: MENU_HIGHLIGHT_STROKE }; continue; } + // A selected row taller than the box is drawn whole, from its top. const row = new GrayImage(box.width, height, 0); this.options.draw({ image: row, item, index, x: 0, y: 0, width: box.width, height, selected, focused }); image.drawMenuSelection(row, box.x, rowY, background, MENU_HIGHLIGHT_STROKE, highlight?.radius ?? 8, highlight?.depth ?? 0, animation); } else { - this.options.draw({ image, item, index, x: box.x, y: rowY, width: box.width, height, selected, focused }); + this.drawRow(image, index, box.x, rowY, box.width, height, focused, box.y, box.y + box.height); } } // The rows painted above stay underneath: once the animation ends, the // strip's final frame and the static paint are pixel-identical. if (strip && scroll) { - image.drawDisplayList(menuScrollList(strip.image, strip.x, strip.top, box.height, scroll, scrollHighlight), + const sourceY = scrollOffsetExpression(scroll).sub(E.i32(strip.top)); + image.drawDisplayList(menuScrollList(strip.image, strip.x, box.height, scroll, sourceY, scrollHighlight), box.x, box.y, box.width, box.height, 0); } } @@ -296,12 +307,33 @@ export class Menu { } /** - * Render every row visible at either end of the scroll into one strip, or - * return null to snap. Its final frame must match the static paint, so - * rows the static paint hides (partial ones at the bottom) are left out of - * the part the new viewport shows. The strip copy is opaque, so this also - * requires a black background under the menu, a selected row that fits, - * and a highlight at the menu's own depth. + * Draw one row at (x, y), clipped to target rows [clipTop, clipBottom). + * Selected rows with a highlight are drawn in a scratch image the row's + * size, like the static selection, which clips their ink to the row. + */ + private drawRow(target: GrayImage, index: number, x: number, y: number, width: number, height: number, + focused: boolean, clipTop: number, clipBottom: number): void { + const item = this.itemList[index]!; + const selected = index === this.selected; + const scratch = selected && this.options.highlight !== false; + if (!scratch && y >= clipTop && y + height <= clipBottom) { + this.options.draw({ image: target, item, index, x, y, width, height, selected, focused }); + return; + } + const row = new GrayImage(width, height, 0); + this.options.draw({ image: row, item, index, x: 0, y: 0, width, height, selected, focused }); + const skip = Math.max(0, clipTop - y); + target.bitBlt(row.withDrawsBaked(), x, y + skip, + { sy: skip, height: Math.min(height, clipBottom - y) - skip, transparentZero: true }); + } + + /** + * Render every row visible at any point of the motion into one strip, or + * return null to snap. Its first and last frames must match the static + * paints on either side, which clip rows at the viewport's edges the same + * way. The strip copy is opaque, so this also requires a black background + * under the menu, a selected row that fits, and a highlight at the menu's + * own depth. */ private scrollStrip(image: GrayImage, layout: MenuLayout, box: MenuBox, focused: boolean, scroll: MenuScrollAnimation): { image: GrayImage; x: number; top: number } | null { @@ -310,27 +342,15 @@ export class Menu { const gap = this.options.rowGap ?? 0; const selected = this.selected; if (selected !== null && layout.tops[selected]! + layout.heights[selected]! - gap - scroll.to > box.height) return null; - const top = Math.min(scroll.from, scroll.to); - const bottom = Math.max(scroll.from, scroll.to) + box.height; + const offsets = [scroll.from, scroll.to, scroll.peak ?? scroll.to]; + const top = Math.min(...offsets); + const bottom = Math.max(...offsets) + box.height; const strip = new GrayImage(box.width, bottom - top, 0); for (let index = 0; index < this.itemList.length; index++) { const rowTop = layout.tops[index]!; const height = layout.heights[index]! - gap; - const rowBottom = rowTop + height; - const shownAfter = rowTop >= scroll.to && rowBottom <= scroll.to + box.height; - const outsideAfter = rowBottom <= scroll.to || rowTop >= scroll.to + box.height; - if (!shownAfter && !(outsideAfter && rowTop >= top && rowBottom <= bottom)) continue; - const item = this.itemList[index]!; - const y = rowTop - top; - const isSelected = index === selected; - if (isSelected && highlight !== false) { - // Clip like the static selected row, which is drawn in a scratch image. - const row = new GrayImage(box.width, height, 0); - this.options.draw({ image: row, item, index, x: 0, y: 0, width: box.width, height, selected: true, focused }); - strip.bitBlt(row.withDrawsBaked(), 0, y, { transparentZero: true }); - } else { - this.options.draw({ image: strip, item, index, x: 0, y, width: box.width, height, selected: isSelected, focused }); - } + if (rowTop + height <= top || rowTop >= bottom) continue; + this.drawRow(strip, index, 0, rowTop - top, box.width, height, focused, 0, strip.height); } // Crop to the columns with ink; the static paint shows the rest unchanged. const baked = strip.withDrawsBaked(); @@ -354,6 +374,16 @@ export class Menu { return { image: cropped, x: left, top }; } + /** At an end with nowhere to go, overshoot a little past it and come back. */ + private bounce(delta: -1 | 1): void { + const count = this.itemList.length; + if (!this.lastBox || !count) return; + const layout = this.layout(this.lastBox.width); + const pitch = layout.heights[delta > 0 ? count - 1 : 0]!; + const amount = Math.min(MAX_BOUNCE, Math.round(pitch * BOUNCE_FRACTION)); + if (amount > 0) this.scrollMotion.bounce(delta * amount); + } + private isSelectable(index: number): boolean { return this.options.isSelectable?.(this.itemList[index]!) ?? true; } diff --git a/app/ui/menu-scroll-motion.ts b/app/ui/menu-scroll-motion.ts index 676944fb..81e80bdd 100644 --- a/app/ui/menu-scroll-motion.ts +++ b/app/ui/menu-scroll-motion.ts @@ -1,27 +1,73 @@ +import { DrawExpression as E, ExprOp } from "../graphics/draw-expression"; import { MENU_HIGHLIGHT_DURATION_MS, nextAnimationToken } from "./menu-highlight-motion"; /** Longest scroll, in pixels, that animates; longer jumps snap. */ export const MAX_ANIMATED_SCROLL = 96; +export const MENU_BOUNCE_DURATION_MS = 320; +/** Fraction of a bounce spent moving out to the peak; the rest settles back. */ +const BOUNCE_PEAK = 0.35; -/** A viewport moving from content offset `from` to `to`, on the same clock as the highlight. */ -export type MenuScrollAnimation = { from: number; to: number; startedAt: number; token: number; durationMs: number }; +/** + * The viewport's content offset moving from `from` to `to`, on the same clock + * as the highlight. A bounce passes through `peak` on the way (usually past + * the end of the list, with `to` where it started). + */ +export type MenuScrollAnimation = { + from: number; to: number; peak?: number; + startedAt: number; token: number; durationMs: number; +}; type Box = { x: number; y: number; width: number; height: number }; +const clamp01 = (t: number) => Math.max(0, Math.min(1, t)); +const smoothstep = (t: number) => t * t * (3 - 2 * t); + +/** The offset at timeline fraction t (0..1). Keep in sync with scrollOffsetExpression. */ +export function scrollOffsetAt(animation: MenuScrollAnimation, t: number): number { + const { from, to, peak } = animation; + if (peak === undefined) return from + (to - from) * smoothstep(clamp01(t)); + const out = 1 - (1 - clamp01(t / BOUNCE_PEAK)) ** 2; + const back = smoothstep(clamp01((t - BOUNCE_PEAK) / (1 - BOUNCE_PEAK))); + return from + (peak - from) * out + (to - peak) * back; +} + /** - * Tracks the painted scroll offset. Only a change caused by non-wrapping + * The offset as a draw expression on the animation's own timeline. The easing + * ops clamp their input, which splits a bounce into its two phases without + * comparisons: the return term stays 0 until the peak, the outward one stays 1 after. + */ +export function scrollOffsetExpression(animation: MenuScrollAnimation) { + const { from, to, peak } = animation; + const t = () => E.progress(animation.durationMs); + if (peak === undefined) return t().ease().lerp(E.i32(from).toFloat(), E.i32(to).toFloat()).toInt(); + const out = t().mul(E.f32(1 / BOUNCE_PEAK)).ease(ExprOp.EASE_OUT_QUAD); + const back = t().sub(E.f32(BOUNCE_PEAK)).div(E.f32(1 - BOUNCE_PEAK)).ease(); + return E.i32(from).toFloat() + .add(E.i32(peak - from).toFloat().mul(out)) + .add(E.i32(to - peak).toFloat().mul(back)).toInt(); +} + +/** + * Tracks the painted scroll offset. A change caused by non-wrapping * navigation animates; programmatic scrolls, item edits and geometry changes - * snap. A scroll during an animation starts from the offset on screen now. + * snap. A bounce is requested explicitly, at an end of the list. Either starts + * from the offset on screen now, so it can interrupt one in flight. */ export class MenuScrollMotion { private previous?: { scroll: number; box: Box }; private navigated = false; + private bounceBy = 0; private animation?: MenuScrollAnimation; navigate(wrapped: boolean): void { this.navigated = !wrapped; } + /** Overshoot by `offset` pixels (negative past the top) and come back, at the next paint. */ + bounce(offset: number): void { + this.bounceBy = offset; + } + /** Record this paint's settled offset; returns the animation in flight, if any. */ paint(scroll: number, box: Box, now: number): MenuScrollAnimation | undefined { const previous = this.previous; @@ -34,8 +80,14 @@ export class MenuScrollMotion { ? { from, to: scroll, startedAt: now, token: nextAnimationToken(), durationMs: MENU_HIGHLIGHT_DURATION_MS } : undefined; this.previous = { scroll, box: { ...box } }; + } else if (this.bounceBy) { + const from = this.offsetAt(scroll, now); + this.animation = Math.abs(scroll - from) <= MAX_ANIMATED_SCROLL + ? { from, peak: scroll + this.bounceBy, to: scroll, startedAt: now, token: nextAnimationToken(), durationMs: MENU_BOUNCE_DURATION_MS } + : undefined; } this.navigated = false; + this.bounceBy = 0; return this.animation && now - this.animation.startedAt < this.animation.durationMs ? this.animation : undefined; } @@ -47,7 +99,6 @@ export class MenuScrollMotion { private offsetAt(settled: number, now: number): number { const animation = this.animation; if (!animation) return settled; - const t = Math.max(0, Math.min(1, (now - animation.startedAt) / animation.durationMs)); - return Math.round(animation.from + (animation.to - animation.from) * t * t * (3 - 2 * t)); + return Math.round(scrollOffsetAt(animation, (now - animation.startedAt) / animation.durationMs)); } } diff --git a/tests/brightness-picker.test.cjs b/tests/brightness-picker.test.cjs index 997b131c..ff2faa03 100644 --- a/tests/brightness-picker.test.cjs +++ b/tests/brightness-picker.test.cjs @@ -27,11 +27,11 @@ const layers = load('app/ui/layers.ts', { '../native/frame-timings': { spanCurrent: (_name, paint) => paint() }, }); const menu = load('app/ui/menu.ts', { - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'), '../graphics/image': graphics, '../graphics/ui-fonts': fonts, '../graphics/textwrap': textwrap, '../util/numeric-util': numeric, './gestures': gestures, './metrics': load('app/ui/metrics.ts'), './menu-core': load('app/ui/menu-core.ts', { - '../graphics/image': graphics, './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), + '../graphics/image': graphics, './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'), }), }); diff --git a/tests/display-list-authoring.test.cjs b/tests/display-list-authoring.test.cjs index 490941e2..3c84e937 100644 --- a/tests/display-list-authoring.test.cjs +++ b/tests/display-list-authoring.test.cjs @@ -32,6 +32,10 @@ test('typed expressions follow i32/f32 arithmetic, easing, time and error semant assert.deepEqual(evaluate(E.i32(300).time(),0,300), {value:300,pending:false}); assert.deepEqual(evaluate(E.i32(300).time().div(E.i32(0)),0,150), {value:0,pending:false}); assert.deepEqual(evaluate(E.decode(Uint8Array.of(ExprOp.IADD)),0), {value:0,pending:false}); + // Delayed timelines: a later start holds at 0, an earlier one continues, a finished one is constant. + const pct = (d, delay, elapsed) => evaluate(E.progress(d, delay).mul(E.f32(100)).toInt(), elapsed).value; + assert.deepEqual([pct(200, 100, 50), pct(200, 100, 200), pct(200, -50, 0), pct(200, -50, 150), pct(200, -300, 0)], [0, 50, 25, 100, 100]); + assert.equal(Buffer.from(E.progress(300, 0).code).toString('hex'), Buffer.from(E.progress(300).code).toString('hex')); }); test('menu authors the golden generic list and stable timeline identity', () => { diff --git a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt index 0c4a677a..69efbfa9 100644 --- a/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt +++ b/tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/FrameDisplayListTest.kt @@ -6,7 +6,7 @@ class FrameDisplayListTest { // Golden records emitted by display-list-authoring.test.cjs. private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f" private val multi = "0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00" - private val scroll = "0787000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff220100300102300180f0800180f0161101001732800180f01610300180f0302341403102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103" + private val scroll = "078a000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff250100300102300180f0800180f0161101001732800180f01610300180f0302341403101001102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103" private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray() private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList { val reader = ArrayByteReader(bytes) diff --git a/tests/menu-core.test.cjs b/tests/menu-core.test.cjs index 2b16b034..633ad57c 100644 --- a/tests/menu-core.test.cjs +++ b/tests/menu-core.test.cjs @@ -168,11 +168,13 @@ test('setItems keeps the index by default, takes an explicit one, and holds the assert.equal(menu.selectedIndex, 1, 'an out-of-range index clamps'); }); -test('variable heights: the layout follows getHeight and partial rows are hidden', () => { +test('variable heights: the layout follows getHeight and partial rows are clipped', () => { const heights = { a: 10, b: 30, c: 15, d: 40, e: 5 }; const { menu, paint } = stringMenu({ getHeight: (item) => heights[item] }); let rows = paint(); - assert.deepEqual(rows.map((r) => [r.item, r.y, r.height]), [['a', 0, 10], ['b', 15, 30], ['c', 45, 15]]); + assert.deepEqual(rows.map((r) => [r.item, r.y, r.height, r.scratch]), + [['a', 0, 10, true], ['b', 15, 30, false], ['c', 45, 15, false], ['d', 0, 40, true]], + 'd is drawn in a scratch image and clipped to the viewport'); menu.select(3); rows = paint(); assert.equal(menu.scrollTop, 40, 'aligned to the top of row c'); @@ -180,6 +182,16 @@ test('variable heights: the layout follows getHeight and partial rows are hidden assert.equal(menu.overflows, true); }); +test('a partially visible row shows only its top, hinting at more rows', () => { + const menu = new Menu({ items: ['a', 'b', 'c', 'd'], getHeight: () => 20, + draw: ({ image, x, y, width, height }) => image.fillRect(x, y, width, height, 200) }); + const image = new GrayImage(20, 60); + menu.paint(image, { x: 0, y: 5, width: 20, height: 50 }, true); + const column = Array.from({ length: 60 }, (_, y) => image.pixels[y * 20]); + assert.deepEqual(column.slice(25, 55), new Array(30).fill(200), 'rows b and the top half of c'); + assert.deepEqual(column.slice(55), new Array(5).fill(0), 'nothing below the box'); +}); + test('a selected row taller than the box is drawn from its top', () => { const { menu, paint } = stringMenu({ getHeight: (item) => (item === 'c' ? 90 : 20) }); menu.select(2); diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs index 89d8bee8..2a176bea 100644 --- a/tests/menu-display-list.test.cjs +++ b/tests/menu-display-list.test.cjs @@ -16,12 +16,12 @@ function load(file,modules) { const font={lineHeight:12,ascent:10,descent:2,measureText:text=>text.length*4, drawText:(image,x,y,text,value)=>{for(let i=0;ifont}, '../util/numeric-util':{clamp:(n,a,b)=>Math.max(a,Math.min(b,n))},'./gestures':{}, - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'), './metrics':require('../.test-build/app/ui/metrics.js'),'./menu-core':menuCore, }); const {prepareFrameDraws}=load('app/graphics/glyph-wire.ts',{'./presentation-wire':wire,'../native/texture-atlas':{textureAtlasAvailable:()=>false}}); diff --git a/tests/menu-scroll-animation.test.cjs b/tests/menu-scroll-animation.test.cjs index 42531672..cf7047c8 100644 --- a/tests/menu-scroll-animation.test.cjs +++ b/tests/menu-scroll-animation.test.cjs @@ -5,10 +5,12 @@ const { MENU_HIGHLIGHT_DURATION_MS } = require('../.test-build/app/ui/menu-highl const { GrayImage } = require('../.test-build/app/graphics/image.js'); const { DrawOp, encodeDisplayList, readDisplayList } = require('../.test-build/app/graphics/display-list.js'); const { evaluate } = require('../.test-build/app/graphics/draw-expression.js'); -const { menuScrollList } = require('../.test-build/app/graphics/menu-scroll-list.js'); +const { DrawExpression: E } = require('../.test-build/app/graphics/draw-expression.js'); +const { menuScrollList, slidingHighlightY } = require('../.test-build/app/graphics/menu-scroll-list.js'); +const { MENU_BOUNCE_DURATION_MS, scrollOffsetExpression } = require('../.test-build/app/ui/menu-scroll-motion.js'); const { encodePresentation } = require('../.test-build/app/graphics/presentation-wire.js'); // Also consumed by FrameDisplayListTest.kt. -const SCROLL = '0787000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff220100300102300180f0800180f0161101001732800180f01610300180f0302341403102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103'; +const SCROLL = '078a000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff250100300102300180f0800180f0161101001732800180f01610300180f0302341403101001102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103'; const BOX = { x: 10, y: 5, width: 40, height: 60 }; const ITEMS = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; @@ -127,10 +129,79 @@ test('wraps, programmatic moves, busy backgrounds and oversized strips snap', () assert.equal(wide(40)[0].resources[0].width, 40); }); +test('rows cut off by the viewport edge scroll without popping in either direction', () => { + // 70px box, 20px rows: at rest the fourth visible row shows its top half. + const box = { x: 10, y: 5, width: 40, height: 70 }; + const menu = inkMenu(); + menu.select(1); + let before = paint(menu, 1000, { box }); + for (const [delta, at] of [[1, 2000], [1, 3000], [-1, 4000], [-1, 5000]]) { + const scrollTop = menu.scrollTop; + menu.moveSelection(delta); + const moving = paint(menu, at, { box }); + assert.notEqual(menu.scrollTop, scrollTop, `step at ${at} scrolls`); + assert.equal(scrollLists(moving).length, 1); + assert.deepEqual(shown(moving, at), shown(before, at - 1000), `first frame at ${at}`); + const end = at + MENU_HIGHLIGHT_DURATION_MS; + before = paint(menu, end, { box }); + assert.deepEqual(shown(moving, end), shown(before, end), `last frame at ${at}`); + } +}); + +test('an end without wrap or exit callback bounces, carrying the highlight with its row', () => { + for (const [start, delta] of [[6, 1], [0, -1]]) { + const menu = inkMenu(); + menu.select(start); + const rest = paint(menu, 1000); + const scrollTop = menu.scrollTop; + menu.moveSelection(delta); + assert.equal(menu.selectedIndex, start); + const bouncing = paint(menu, 2000); + assert.equal(menu.scrollTop, scrollTop); + const [list] = scrollLists(bouncing); + assert.ok(list, `bounce ${delta}`); + const [copy, box] = list.calls; + const at = (value, ms) => evaluate(value, ms, 0).value; + const peak = Math.round(MENU_BOUNCE_DURATION_MS * 0.35); + // Offsets relative to rest: 8px (0.4 of a 20px row) past the end at the peak. + assert.equal(at(copy.y, peak) - at(copy.y, 0), 8 * delta); + assert.equal(at(copy.y, MENU_BOUNCE_DURATION_MS), at(copy.y, 0)); + assert.equal(at(box.y, peak) - at(box.y, 0), -8 * delta, 'the highlight moves with its row'); + assert.ok(evaluate(copy.y, MENU_BOUNCE_DURATION_MS - 1, 0).pending); + assert.deepEqual(shown(bouncing, 2000), shown(rest, 1000)); + const end = 2000 + MENU_BOUNCE_DURATION_MS; + assert.deepEqual(shown(bouncing, end), shown(paint(menu, end), end)); + } + const exits = []; + const exiting = inkMenu({ onExitBottom: () => exits.push('bottom') }); + exiting.select(6); + paint(exiting, 1000); + exiting.moveSelection(1); + assert.deepEqual(exits, ['bottom']); + assert.equal(scrollLists(paint(exiting, 2000)).length, 0, 'an exit callback replaces the bounce'); +}); + +test('a bounce during a scroll starts from the offset on screen', () => { + const menu = inkMenu(); + menu.select(4); + paint(menu, 1000); + menu.moveSelection(1); + paint(menu, 2000); // 60 -> 80, the end + menu.moveSelection(1); + paint(menu, 2060); // the highlight moves to the last row; no further scroll + assert.equal(menu.selectedIndex, 6); + menu.moveSelection(1); + const [list] = scrollLists(paint(menu, 2120)); + const offsets = [0, MENU_BOUNCE_DURATION_MS].map((ms) => evaluate(list.calls[0].y, ms, 0).value); + assert.ok(offsets[0] < offsets[1], 'it starts where the scroll had got to, above its settled offset'); +}); + test('scroll lists survive the bridge with animated copy coordinates', () => { const strip = { width: 2, height: 4, pixels: Uint8Array.of(17, 34, 51, 68, 85, 102, 119, 136) }; - const list = menuScrollList(strip, 1, 0, 2, { from: 0, to: 2, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS }, - { y: 0, width: 4, height: 2, radius: 0, background: 15, border: 45, animation: { dx: 0, dy: 1, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS } }); + const timeline = { from: 0, to: 2, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS }; + const y = slidingHighlightY(0, { dx: 0, dy: 1, startedAt: 1000, token: 7, durationMs: MENU_HIGHLIGHT_DURATION_MS }, 1000); + const list = menuScrollList(strip, 1, 2, timeline, scrollOffsetExpression(timeline).sub(E.i32(0)), + { y, width: 4, height: 2, radius: 0, background: 15, border: 45 }); const bytes = encodeDisplayList({ displayList: list, x: 3, y: 2, width: 4, height: 2, depth: 0 }, 1150); assert.equal(Buffer.from(bytes).toString('hex'), SCROLL); const { placed } = readDisplayList(bytes, 0, 1150); diff --git a/tests/music-settings.test.cjs b/tests/music-settings.test.cjs index b98e3b54..97da8432 100644 --- a/tests/music-settings.test.cjs +++ b/tests/music-settings.test.cjs @@ -153,7 +153,7 @@ test('Music settings keeps toggles and selection when a new app arrives and supp '../graphics/textwrap': textwrap, '../graphics/ui-fonts': { getDefaultSmallFont: () => font }, '../util/numeric-util': { clamp: (n, lo, hi) => Math.max(lo, Math.min(hi, n)) }, - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'), './metrics': load('app/ui/metrics.ts'), './gestures': {}, }; deps['./menu-core'] = load('app/ui/menu-core.ts', (name) => deps[name]); diff --git a/tests/notification-filter.test.cjs b/tests/notification-filter.test.cjs index 95cc86a2..90e57a9c 100644 --- a/tests/notification-filter.test.cjs +++ b/tests/notification-filter.test.cjs @@ -84,7 +84,7 @@ function ui(fontSize = 12) { '../native/notification-sources': prefs, '../native/notification-access': { isNotificationListenerEnabled: () => true }, '../util/render-freshness': { renderPassAllowsStaleData: () => false }, - './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), + './menu-highlight-motion': require('../.test-build/app/ui/menu-highlight-motion.js'), '../graphics/menu-scroll-list': require('../.test-build/app/graphics/menu-scroll-list.js'), './menu-scroll-motion': require('../.test-build/app/ui/menu-scroll-motion.js'), '../graphics/draw-expression': require('../.test-build/app/graphics/draw-expression.js'), './metrics': load('app/ui/metrics.ts'), './gestures': {}, }; From 4f3ad37c20801f757ac2c52e26edd3d2774da857 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Fri, 25 Sep 2026 00:54:36 -0700 Subject: [PATCH 23/27] Custom auto-brightness, and fade in/out effects --- .../faceclaw/app/FaceclawBleCommunicator.kt | 2 + app/g2/brightness-curve.ts | 26 +++++ app/g2/cfw-message-type.ts | 1 + app/g2/dashboard-controller.ts | 19 ++- app/g2/firmware-compat.ts | 2 +- app/g2/firmware/cfw-patches.ts | 68 +++++------ app/g2/ios-preview-controller.ts | 27 +++-- app/native/faceclaw-communicator.ios.ts | 6 +- app/native/faceclaw-communicator.ts | 6 +- app/phone-ui/remote-controls-view-model.ts | 2 +- app/phone-ui/remote-controls.xml | 2 +- app/ui/dashboard-settings.ts | 56 ++++++++- app/ui/dashboard/settings-menus.ts | 18 +++ app/ui/shell/brightness-picker-layer.ts | 2 +- .../faceclaw/app/g2protocol/BleProtocol.kt | 15 ++- .../app/g2protocol/BrightnessPolicy.kt | 102 +++++++++++++++++ .../faceclaw/app/g2protocol/CfwMessageType.kt | 1 + .../session/GlassesSessionBrightness.kt | 42 +++++++ .../g2protocol/session/GlassesSessionCore.kt | 36 +++--- .../g2protocol/session/GlassesSessionSend.kt | 16 ++- .../com/faceclaw/app/ble/IosGlassesSession.kt | 2 + tests/brightness-curve.test.cjs | 53 +++++++++ tests/brightness-picker.test.cjs | 4 +- tests/ios-app-host.test.cjs | 19 ++- tests/ios-glanceboard.test.cjs | 4 +- .../com/faceclaw/app/BrightnessPolicyTest.kt | 108 ++++++++++++++++++ .../faceclaw/app/GlassesSessionCoreTest.kt | 36 ++++++ tests/remote-controls.test.cjs | 4 +- tests/tsconfig.json | 3 +- 29 files changed, 589 insertions(+), 93 deletions(-) create mode 100644 app/g2/brightness-curve.ts create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/BrightnessPolicy.kt create mode 100644 native/kotlin/shared/src/commonMain/kotlin/com/faceclaw/app/g2protocol/session/GlassesSessionBrightness.kt create mode 100644 tests/brightness-curve.test.cjs create mode 100644 tests/kotlin/src/commonTest/kotlin/com/faceclaw/app/BrightnessPolicyTest.kt diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt index 97d98665..65d9c9c8 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.kt @@ -169,6 +169,8 @@ class FaceclawBleCommunicator(context: Context, rightAddress: String?, leftAddre fun setCompassEnabled(owner: String?, enable: Boolean) = core.setCompassEnabled(owner, enable) fun setBrightness(autoAdjust: Boolean, brightnessLevel: Int) = core.setBrightness(autoAdjust, brightnessLevel) + fun configureBrightness(auto: Boolean, level: Int, minimum: Int, maximum: Int, curve: String, fadeMs: Int) = + core.configureBrightness(auto, level, minimum, maximum, curve, fadeMs) fun enableWearDetectionAndRequestState() = core.enableWearDetectionAndRequestState() diff --git a/app/g2/brightness-curve.ts b/app/g2/brightness-curve.ts new file mode 100644 index 00000000..1695ae8d --- /dev/null +++ b/app/g2/brightness-curve.ts @@ -0,0 +1,26 @@ +export const DEFAULT_BRIGHTNESS_CURVE = "0:0,0.2:7,1.5:33,5:100"; +const PREVIOUS_DEFAULT_CURVE = "0:0,1:10,10:30,100:65,1000:100"; + +/** Percent of the configured range; defaults (20–100) give 20/26/46/100. */ +export function brightnessCurveError(value: string): string | null { + const pairs = value.split(",").map(part => part.trim().split(":")); + if (pairs.length < 2 || pairs.length > 16 || pairs.some(p => p.length !== 2 || p.some(s => !s.trim()))) + return "Use 2–16 lux:percent pairs separated by commas."; + const points = pairs.map(pair => pair.map(Number)); + if (points.some(([lux, percent]) => !Number.isFinite(lux) || !Number.isFinite(percent) + || lux < 0 || lux > 1_000_000 || percent < 0 || percent > 100)) + return "Lux must be 0–1000000 and percent must be 0–100."; + if (points[0][0] !== 0 || points[0][1] !== 0 || points[points.length - 1][1] !== 100) + return "Start at 0:0 and end at 100%. Set dark-room brightness with Auto minimum."; + if (points.some(([lux, percent], i) => i > 0 && (lux <= points[i-1][0] || percent < points[i-1][1]))) + return "Lux must increase and brightness must not decrease."; + return null; +} + +/** Keep incomplete drafts intact. Validation must never replace typed input. */ +export function normalizeBrightnessCurve(value: string | null | undefined): string { + if (value == null) return DEFAULT_BRIGHTNESS_CURVE; + if (brightnessCurveError(value)) return value; + const canonical = value.split(",").map(pair => pair.split(":").map(Number).join(":")).join(","); + return canonical === PREVIOUS_DEFAULT_CURVE ? DEFAULT_BRIGHTNESS_CURVE : canonical; +} diff --git a/app/g2/cfw-message-type.ts b/app/g2/cfw-message-type.ts index 550fd658..5dd24a61 100644 --- a/app/g2/cfw-message-type.ts +++ b/app/g2/cfw-message-type.ts @@ -32,5 +32,6 @@ export const CFW_MSG_DRAW_CALLS = 26 export const CFW_MSG_SET_ROOT_DISPLAY_LIST = 27 export const CFW_MSG_PRESENT = 28 export const CFW_MSG_CREATE_SURFACE = 29 +export const CFW_MSG_BRIGHTNESS = 30 export const CFW_MSG_TYPE_MASK = 127 export const CFW_MSG_FLAG_LENSES_DIFFER = 128 diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 894a6c65..d0643fb1 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -1,6 +1,6 @@ import { startRemoteInput } from "../remote/service"; import { acceptInput, resetRingInputFilter } from "../ui/input-monitor"; -import { Application, ImageSource } from "@nativescript/core"; +import { Application, Dialogs, ImageSource } from "@nativescript/core"; import { EvenAIStatus, EvenAIStatusName, EventSourceType, EventSourceTypeName, OsEventTypeList, OsEventTypeName, WatchGestureType, WatchGestureTypeName } from "./events"; import { isValidMacAddress, loadDeviceAddresses } from "./device-addresses"; import { @@ -71,7 +71,7 @@ import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-a import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible, type WindowHeightMode } from "../ui/shell/geometry"; import { type LayerActions, type TextSettingsEditToggle } from "../ui/layers"; import { type KeyboardInputSession } from "../ui/shell/keyboard-input"; -import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, displayModeSetting, navigateDisplayModeSetting, navigateVerticalPositionSetting, terminalDisplayModeSetting, terminalVerticalPositionSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings"; +import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayModeSetting, navigateDisplayModeSetting, navigateVerticalPositionSetting, terminalDisplayModeSetting, terminalVerticalPositionSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings"; import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization"; import { getInstalledEvenHubAppById, @@ -908,11 +908,14 @@ class DashboardController { */ private pushBrightness(force = false): void { if (!this.communicator) return; - const value = brightnessSetting.get(); + const preferences = getBrightnessPreferences(); + const value = JSON.stringify(preferences); if (!force && value === this.lastPushedBrightness) return; this.lastPushedBrightness = value; - const level = brightnessSettingToLevel(value); - void this.communicator.setBrightness(level === null, level ?? 0).catch(() => {}); + void this.communicator.configureBrightness(preferences).catch((error) => { + this.lastPushedBrightness = null; + this.appendLog(`brightness configuration failed: ${this.formatError(error)}`); + }); } /** Save the occupied part of the composited screen as a 4-bit grayscale PNG. */ @@ -1341,6 +1344,7 @@ class DashboardController { // queue is FIFO, so enqueuing the screen size first guarantees it lands // ahead of them. Mirrors ensurePreviewDisplay. await communicator.configureCompositorScreen(G2_LENS_WIDTH, G2_LENS_HEIGHT); + await communicator.configureBrightness(getBrightnessPreferences()); this.offState = communicator.onStateChange((state) => { if (state.phase !== "connected") resetRingInputFilter(); if (state.phase === "unpaired") { @@ -2035,6 +2039,11 @@ class DashboardController { */ finishActiveTextSettingEdit(): void { if (!this.activeTextSettings.length) return; + const invalid = this.activeTextSettings.find(setting => setting.validationError()); + if (invalid) { + void Dialogs.alert({ title: invalid.editorTitle, message: invalid.validationError()!, okButtonText: "OK" }); + return; + } const onFinish = this.activeTextEditorOnFinish; // Completing is not cancelling: drop the cancel callback before // endTextSettingEdit, which fires whatever is still set. diff --git a/app/g2/firmware-compat.ts b/app/g2/firmware-compat.ts index 894d8c80..09d48327 100644 --- a/app/g2/firmware-compat.ts +++ b/app/g2/firmware-compat.ts @@ -26,7 +26,7 @@ export type FirmwareInfo = { }; /** The Faceclaw firmware revision this build of the app needs. */ -export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 29; +export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 32; const FACECLAW_PREFIX = "Faceclaw/"; const LEGACY_PREFIX = "EVENCFW"; diff --git a/app/g2/firmware/cfw-patches.ts b/app/g2/firmware/cfw-patches.ts index f5041484..5bafedb7 100644 --- a/app/g2/firmware/cfw-patches.ts +++ b/app/g2/firmware/cfw-patches.ts @@ -19,12 +19,12 @@ export type FirmwarePatchSet = { export const CFW_PATCH_SET: FirmwarePatchSet = { "base": "g2_2.3.0.24.bin", "baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979", - "outputSha256": "0275d20b0e50cd8fccc2eb4209384cac93ff3ae22149ddcc70da4a375440c818", + "outputSha256": "61f732b4a6ba10c26b1eb4f93253d990380b5a7cff4fdd18482626a883c457e6", "patches": [ { "offset": 1045797, "old": "38b584b0", - "new": "5cf35fb9", + "new": "5df3bbb8", "desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease" }, { @@ -36,49 +36,49 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1437923, "old": "fef788ff", - "new": "fcf26efe", + "new": "fdf2cafd", "desc": "cfw_ancs_event" }, { "offset": 1437951, "old": "fef7e8fb", - "new": "fcf2a8fb", + "new": "fdf204fb", "desc": "cfw_ancs_open" }, { "offset": 1437969, "old": "fef7e7fb", - "new": "fcf2bffb", + "new": "fdf21bfb", "desc": "cfw_ancs_close" }, { "offset": 1388387, "old": "39694d00", - "new": "c5547d00", + "new": "7d637d00", "desc": "connection-bound ANCS EUS write callback" }, { "offset": 971497, "old": "fff717f8", - "new": "6ef38ffa", + "new": "6ff3ebf9", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 971845, "old": "fef769ff", - "new": "6ef3e1f9", + "new": "6ff33df9", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 979579, "old": "fdf74ef8", - "new": "6cf3c6fa", + "new": "6df322fa", "desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)" }, { "offset": 1428895, "old": "f8f76cfd", - "new": "fbf206fe", + "new": "fcf23afa", "desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)" }, { @@ -108,145 +108,145 @@ export const CFW_PATCH_SET: FirmwarePatchSet = { { "offset": 1248487, "old": "d4f712fb", - "new": "29f396fc", + "new": "2af304fb", "desc": "bl settings_send_wrapper (append caps field 100)" }, { "offset": 1246183, "old": "f5f7e2f8", - "new": "29f372fe", + "new": "2af388fc", "desc": "bl settings_decode_wrapper (Faceclaw lease field 101)" }, { "offset": 975219, "old": "02f083fc", - "new": "6bf3defe", + "new": "6cf3f4fc", "desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)" }, { "offset": 975411, "old": "02f023fc", - "new": "6bf342ff", + "new": "6cf358fd", "desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)" }, { "offset": 975103, "old": "07f085fb", - "new": "6df398fa", + "new": "6ef3f4f9", "desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)" }, { "offset": 830549, "old": "19f03efb", - "new": "90f347fc", + "new": "91f3a3fb", "desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)" }, { "offset": 830795, "old": "1ff071ff", - "new": "90f300fc", + "new": "91f35cfb", "desc": "bl gesture_press (owned event 9 before stock menu gate)" }, { "offset": 830887, "old": "1ff043ff", - "new": "90f3fafb", + "new": "91f356fb", "desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)" }, { "offset": 831763, "old": "1ff08dfd", - "new": "90f330fa", + "new": "91f38cf9", "desc": "bl gesture_release (owned event 10 before stock menu gate)" }, { "offset": 1570209, "old": "7fb50600", - "new": "dbf227b8", + "new": "dbf295be", "desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline" }, { "offset": 1051545, "old": "f6f787f9", - "new": "55f30ff8", + "new": "55f311f9", "desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)" }, { "offset": 1051861, "old": "f6f7e9f8", - "new": "54f371ff", + "new": "55f373f8", "desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)" }, { "offset": 1262237, "old": "d9f7d0fd", - "new": "25f3a7fd", + "new": "26f345fb", "desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)" }, { "offset": 1262337, "old": "d9f79efd", - "new": "25f375fd", + "new": "26f313fb", "desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)" }, { "offset": 1309405, "old": "67f02dff", - "new": "19f37ffe", + "new": "1af31dfc", "desc": "bl compass_decode_capture (sample-matched GAF diagnostics)" }, { "offset": 1307865, "old": "fff7c9fb", - "new": "1af3fdf9", + "new": "1af39bff", "desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)" }, { "offset": 1300937, "old": "00210170", - "new": "1bf3e3fe", + "new": "1cf381fc", "desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)" }, { "offset": 4537963, "old": "", - "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff64c484ef66c6b4ff29c591446cff6ff78ccf2ff0bc2f229094ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847d9f800a0bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f04bfc002800f01a81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001f5145abd1bff35f8f49e8000121b159e8001f5145f8d0a1e70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847d9f80070bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7006f0e5fb002800f0b480414600bf42180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb942abd1bff35f8f49e8000121b159e8001fb942f8d0a1e7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f023810f9800285fd00e980778a7f11700022859d80f980c2840f00c810e9e7078b178084300f00681f0780138022800f20181b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f06f83172f40f08483002a40f0e880fe2800f07485812800f06685002840f07b8551ea030040f0db8000f0fabe04460020b047d8b104f51d7151e800afbaf1000f0bd1bff35f8f00bf41e80002002a7bd051e800afbaf1000ff6d00021bff32f8f0029bff35f8f6bd0824694e74ff0ff37bfe047f6df40c0f24f008047002701261197adf8487006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594549d04ff46d7006f003fb002842d0414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142add1bff35f8f49e8000159b159e8001fa142f8d0a3e706f5a971884726e7012189e700200e9999b10f9a8ab1097801f07f02b2f10b0418bf0124b2f11c0618bf01268a2924dc0b2926d01c2924d03fe00d9010a804f0c7f84ff0ff3701269df84900002810a818bf4ff0ff3704f08bf9054646b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010746884797f8641119b997f80413384669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a8264004f086f80e98007800f07f041d2c00f07e0018bf1a2811d1d9f800100322cff680720a40b2f1005fbff35f8f0ad10a685a4504bf002281f8812303e0a4f115010129e9d90f2c0adc092c00f3cc80052c00f07882072c40f0f282002769e0142c00f37781102c00f07582112c40f0e7820f98022840f00b840e990878112840f006844878002840f0028445f64d50c0f24600804701284ff000077ff475af40f20830c0f210003590ff208df8d00044f25220c0f20100339040f2c960c0f248003446cde93677804798b148f27e30c2f2070000880122c1b264298df8cf2008d80721b0f5807f38bf03218df8cf108df8d00040f2d260adf8d800052035ae8df8da00f01d33a90522fff748fc4ff22507c0f247070120092132460c23b8470746264631e748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f04e844ff46d7006f0b4f9002800f04684414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d10121c0f800b081728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142aad1bff35f8f49e80001002900f00c8459e8001fa142f6d09ee70a2c00f0b9810b2c40f02682d9f800500320cff680702840b0f1005fbff35f8f41f059802868002758457ff4baaed5f870030c9642f68d46c0f244060028a5f8807318bfb0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f02df90024c5f87842d5f8680320b148f2a351c0f245018847c5f86843a5f86c43286ca5f8444040b1b047286c06f166018847002804bf002028644bf63940c0f251008047d9f800400320cff680702040b0f1005fbff35f8f2ad12068584527d194f877010027c4f8807188b149f25962c0f25902002044f2436184f8777190474ef6e378c0f25a08c04708f1bc008047d4f8840184f8707150b1b047d4f8840106f166018847002804bf0020c4f88401d9f800000321cff680710140b1f1005fbff35f8f40f00a860168594540f0068690f8a811002900f0fb8506f0c9fb00f0fdbd152c00f06b81162c40f070810f9801380228c0f093820e994ff0ff374878897840ea0120b0f5007f3ff605ae03210f9a01eb400191427ff4fead002700288df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803718df804718df805718df806718df807718df808718df809718df80a718df80b718df80c718df80d718df80e718df80f718df810718df811718df812718df813713ff47aad0e9935aa03314ff0010c4b78012b00f2f4810f7847ea0323db08d45c07f007070cfa07f7274240f0e881d45c013847ea040701f10201d754e7d105f053f9002800f0db810c96002701262ee300294ff0ff3708bf002b7ff47aad1328bff477ad102a4ff0000138bf01211228b2fa82f218bf510901297ff46aad87e3182f4ff0ff3708bf00297ff462ad002b7ff45fad352800f3c081002800f06083012800f06c83312840f05e83082abff450ad6de30f980c960228c0f09c800e98407899e0dde90e0106f0d4fb6de00f980228c0f094810c960027012606e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f06a814ff46d7005f08fff002800f05e81414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0298159e8001fa142f6d09fe70e980f990130013907f081fa0746a4e41d2c40f0c7800f9801380228c0f020810e994878897840ea0124b4f5007f00f2178104eb4400032101eb40000f99884240f00e8105f081f8002800f009810c96002601270f94fbe1ff20002701260b9006e048f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594544d04ff46d7005f0fffe002800f08c81414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e8000121b159e8001fa142f8d0a1e790f84410dde90b5661b1016c39b142f68d42c0f244020446084690472046002180f8441001210f9a032a0ed36db90e988078082800f29c854bf63941c0f25101963188470027fff7f9bb0f9a052a7cd3012d7ad10e9a00279078411e06293ff6edabd17803293ff6e9ab1279002a3ff4e5ab4bf63943c0f2510303f59a7398470027fff7dbbb1a2818bf1c2c59d104f0cdff002855d000f0adfe814607f02cfeb9f1000f4ff0ff373ff4c8ab034600283ff4c4ab47f63400c2f20700d0f81806d9f874131b2ca0eb0100c9f87c0300f03c831a2c40f05b830e9900254f1c0f994ff4f072a1f1010b4ff4a071cde93b5035a80c964ff420744ff480560590cde90121484639465a46cde935653d95cde903559846009408f05df8002800f02b850c9e4ff0ff37fff789bb0e990c9e4c7814b3022c05d840f0ff830f99062980f0d9824ff0ff37fff779bb022d6dd14bf63940c0f2510080470027fff76fbb362800f0b881462800f0b281572840f09e81002e7ff490abade1002780f8437145f64d50c0f24600804701287ff457ab43f2a310c0f256008047a9e60c294ff0ff377ff479abb3f5005fc0f09481fff773bb481e1f284ff0ff373ff66dabc1f51630834240f28781fff766bb002b7ff461ab421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012900f06c81b0f1370218bf0122b0f1c10318bf01231a4208bf022900f05f819f284ff0ff377ff43bab042900f05781fff736bb0f9a072ac0f01c82032d40f019820e9bb0469878da78197940ea02205c799d7901284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0358244ea0521012988bf0e4642f68d41c0f24401a1f14002314626e2dde90b5600210020bfe600200f99022902d30e99497800e0ff21002800f05a8402294ff000072cd0012926d000297ff4b7aa4cf67e21caf2101187760783c9f80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff793ba01218172fff78fba8772fff78cba48f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0de814ff46d7005f00efd00283ff4ddae414642180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800b087728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f09d8159e8001fa142f6d09fe748f2a351c0f24501bff32f8f8847d9f80040bff35f8fd9f800000321cff680710140b1f1005fbff35f8f03d10168594500f0c6814ff46d7005f0aefc00283ff47dae414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b086728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fa142abd1bff35f8f49e80001002900f0858159e8001fa142f6d09fe7022abff4f6a913e0002a7ff4f2a9a0f1fd0102290cd397287ff4eba908e06ff0780002427ff4e5a902e0402abff4e1a945f64d50c0f2460080470e990128c9784ff001004ff0010408bf022008424ff0000708d1fff7cdb948f2a351c0f24501bff32f8f8847d9f80060bff35f8fd9f800000321cff680710140b1f1005fbff35f8f02d10168594543d04ff46d7005f023fc00283ff4aba9414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b084728583c583058445848584c584058545858585c585058645868586c5860587458759e8001fb142acd1bff35f8f49e8000121b159e8001fb142f8d0a2e74af21f36c0f247060546b04795f8640100287ff463a995f80403294600287ff45da90e98007817281bd0d1f8640342f68d44c0f2440468b946f6cb50c0f20000a4f594777844012100220023b847c5f8640340b3a4f140024ff47a719047294608bb01f206300c460e990c22fef715fe0d98002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff41fa985f8047306f14c0080474ff0ff37fff716b90f9a0027032afff4e4a82a1fb2fa82f25209b046114000f0b5800f994cf6cd420339ccf6cc42a1fb02120e9900f146038d780331b5eb920f88bf95082e46302d28bf302606eb860204461846fef7cbfd0027002d84f8446084f8457000f09280206c30b9204600f058fc0028206400f0808342f68d41c0f24401a1f140020121904700274646fff7a4b80e9fb978fa783b797f7941ea022143ea072232293591369280f00e81322110e10a90d0f86c01002800f03b8100214ff4006205e01b681a44b2f5403f80f09f8083189f680137f5d05f68033727f0030739441031eee70f983446032840f01e810e994ff4f077487889781a4640ea01260020cde902004ff4a0700190484631464ff42073009707f0adfb002800f01a824ff0ff372646fff757b80f9801287ff453a811a94846012207f0cafbfff7a5bbd0f86c110027002900f013834ff400624ff0ff3c0df1d40e04e02b681a44b2f5403f5dd28d18ac68b7eb542ff5d1e3081ef8033004f00706f340db071ebf41f82470c5f808c0ef60e7e74646fff724b890f8a911002918bf05f0cafd95f84301002785f8437158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84241c5f8387185f84271a5f8407150b1b047d5f83c0106f166018847002804bf0020c5f83c010120002ca87200f08a814af27366c0f246060021002200230027b0470c9efef7e5bf0f9a002a40f09380b1f53e3f3ff64fac74e14ff0000c4ff400634ff0000ec0f800c30ee0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe4680f05d81cf18ba68ce58013201d07746f2e7f418220c022ae5d80a1995680135e1d115682e443e6012681444220c022ad9d80a1995680135d5d115682e443e6012681444220c022acdd80a1995680135c9d115682e443e6012681444220c022ac1d80a1995680135bdd115682e443e6012681444b4f5403fcfd3b4e7b1f5fa6f02d94ff4fa6135910121054680f8431145f64d50c0f246008047012840f0108143f2a316c0f25606a6f188008047022c074608bf002f01d067b900e14bf2110235a9c0f24b0202209047002800f0f7800746b047002085f843010c9efef756bf2646fef753bf0f99002900f0e88000210e9a4ff0000b02f1030c16324ff0ff390e92cdf82cc00beb4b020ceb42056c784ff0ff37012c00f20682ae78eb7856ea032e00f000822b796d7953ea052800f0fa81bef5207f00f2f681b8f5f07f00f2f2810ef101035b0803fb08f54ff6fb739d4200f2e8811cf81220bbf1000f42ea04270e9c4a462cd014f8133c14f8126c43ea0623bb423ff47bab12b314f80d3c14f80c6c43ea0623bb423ff471ab012a17d014f8073c14f8066c43ea0623bb423ff466ab022a0cd014f8013c267843ea0623bb423ff45cab043a531c04f11804d2d100283ed06b1d4ff4006200eb020cdcf80840bc423fd0dcf8006032444ff6ff76c0f20206b2422cd800eb020cdcf80840bc4230d0dcf8006032444ff6ff76c0f20206b2421dd800eb020cdcf80840bc4221d0dcf8006032444ff6ff76c0f20206b2420ed800eb020cdcf80840bc4212d0dcf8006032444ff6ff76c0f20206b242c3d94ff6fc7305f10802c0f201031a401144103120e0dcf804209a427ff407abdcf80c209a427ff402ab9cf81020042a7ff4fdaa9cf811209cf8123042ea032272457ff4f4aa9cf813209cf8143042ea032242457ff4ebaa0f9a0bf1010bddf82cc0934509f101097ff42cafb1f53e3f3ff6ddaa002500210e9143e00c9e0027fef763be4ff48050cde93505d9f87c033946cde93c0535a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773b95009707f012fb0c9e0746fef742be701ca9f86c0300272646fef73bbe0a98d0f86c014a688b6890454ff00002c1f80c8008bf01f1100240f823200e9a0f9901328a424ff000070e9200f0f0800e990b9b01eb410103eb410213f811c0937856780893d3780793137952794cea06290993069298b3012e31d84ff4006283189f684f45dad01b681a444ff6ff73c0f202039a4223d883189f684f45ced01b681a444ff6ff73c0f202039a4217d883189f684f45c2d01b681a444ff6ff73c0f202039a420bd883189f684f45b6d01b681a444ff6ff73c0f202039a42cfd9dde90773099c43ea07200699013044ea0122400800fb02fb0bf1050801208df8d4004fea18208df8d9004fea18408df8da0005208df8de0004208df8e0008df8e41035a811218df8d5508df8d6c08df8d7608df8d8808df8db508df8dd508df8dc508df8df508df8e1308df8e2708df8e34006f07afb00287ff40faa0a980021d0f86c01a0b3012e32d84ff4006281188b684b452cd009680a444ff6ff71c0f202018a4223d881188b684b4520d009680a444ff6ff71c0f202018a4217d881188b684b4514d009680a444ff6ff71c0f202018a420bd881188b684b4508d009680a444ff6ff71c0f202018a42cfd90021bbf1000f3ff427af0798089b0002069a40f001001844099b120240081a434243501e032801d200200ae022f0030300200f18043083427d75bd75fd753d76f7d112f003023ff404af01f11503012a1d543ff4feae1844022a457018bf8570f7e60c9efef730bd4bf639400027c0f2510084f8447080474646fef725bd00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594546d04ff46d7004f094ff00283fd0414600bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000129b155e8001fa142f8d0a7e7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcdb04ff29c55c2f229052c68032720464ef66c666ff39600cff68077ccf2ff06b0f1005fbff35f8f40f0ee812068b04240f0ea8194f8510347f64c69c2f2070904f5417850b34ff61c20cff6ff7059f800004bf67c51c0f2720188421ed14ff61020cff6ff7059f80000b8b1d4f85c03d9f80010401a012802db04f005f868b940460bf057fd48b142f69570c0f25b008047002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db03f0eaff20b9002084f8500384f8660198f80000bff35f8f60b194f84fa3baf1000f1cd094f8050394f81e13091a18bf012115e094f85103002840f08d8194f85003002840f08881d4f86403002800f0838142f68d41c0f2440188477ce1012194f8070394f81133049094f8080394f81d23059094f8067394f80a0394f80bc394f80ce394f80d6394f80eb394f80f539342cdf8008035d194f8102394f81c339a422fd194f81b2395422bd194f81a23934527d194f81923964223d194f8182396451fd194f8172394451bd194f81623904217d194f8092394f815339a4211d194f81423059b93420cd194f81323049b934207d194f81223974203d111b994f80583afe0002184f8201384f8231384f8241384f8251384f8261384f8271384f8281384f8291384f82a1384f82b1384f82c1384f82d1384f82e1384f82f1384f8301384f8311384f8321384f8331384f8341384f8351384f8361384f8371384f8381384f8391384f83a1384f83b1384f83c1384f83d1384f83e1384f83f1384f8401384f8411384f8421384f8431384f8441384f8451384f8461384f8471384f8481384f8491384f84a1384f84b1384f84c1384f84d1384f84e13012184f81f1384f8217384f82203d9f8002004f20631130a84f8232384f82433130c120e84f82623082284f8253384f84f234ff61c22cff6ff7259f802204bf67c53c0f272039a4204f2123a20d14ff61022cff6ff7259f80220cab140f6b803c2f200031a689ab1182f00f0f381172f40f0fe81fe2804f22737884600f01782002840f0228200980bf0d1fc414602e0022084f8200350460c22fdf7d2ff94f8058394f84fa384f81e8345f64d50c0f246008047811eb1fa81f14fea511b012808bf4ff0020bbaf1000f58d004f21f3003900df11f00063002900aa8023000254ff003090024019018e001980df11f011a468df828908df82980fdf7a2ff47f008024af66107f0200aa90023c0f24607b8470334e0b25045b14630d2aaeb0400c7b20420032f28bf4f468df81f0004983a468df8200005988df822b08df8210003988df8234050fa84f102988df824a08df825508df826508df82750fdf771ffb81dc345c3b24ff00306bed14ef60b670120f0210df11f02c0f24707c8e7bff35f8f00994ff29c5503274ef66c660020c2f22905cff68077ccf2ff060870d5f800b0bff35f8f0bea0700b0f1005f47d1dbf80000b04243d19bf8500338b100208bf86401cbf860014db0bde8f08f9bf8640118b3dbf8604104b340f6b800c2f20000d0f8008006a802f0e5fab8f1000f00f01f81404621464ff41632b246b9464ff6ff75cdf81480fdf71bff4ff29c5600274ff00108c2f2290620e09bf8660170b1dbf8680140b147f64c61c2f207010968401a002802f3b58200208bf8660140f6a120c0f2470080474db0bde8f08f48f2a351c0f24501bff32f8f88473468bff35f8f3068bff35f8f00ea0901b1f1005f02d10168514549d04ff46d7004f076fc002802f076824ff64c41cff6ff7100bf42180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800a080f80a808583c583058445848584c584058545858585c585058645868586c5860587458756e8001fa142abd1bff35f8f00bf46e8000121b156e8001fa142f8d0a0e7817a002942f02f82027e0021002a8df8281000f04e810aaa535c002b00f0218153185f78002f00f0df809f78002f00f0dd80df78002f00f0db801f79002f00f0d9805f79002f00f0d7809f79002f00f0d580df79002f00f0d3801f7a002f00f0d1805f7a002f00f0cf809f7a002f00f0cd80df7a002f00f0cb801f7b002f00f0c9805f7b002f00f0c7809f7b002f00f0c580df7b002f00f0c3801f7c002f00f0c1805f7c002f00f0bf809f7c002f00f0bd80df7c002f00f0bb801f7d002f00f0b9805f7d002f00f0b7809f7d002f00f0b580df7d002f00f0b3801f7e002f00f0b1805f7e002f00f0af809f7e002f00f0ad80df7e002f00f0ab801f7f002f00f0a9805f7f002f00f0a7809f7f002f00f0a580db7f002b00f0a380203160297ff47bafc2e000208bf86401cbf860018bf8660101208bf8650140f6a120c0f24700804702f0a3b940460d460bf04dfcd8b102304ff0030008bf022084f82003294612e684f85003d9f800204ef660231a44c4f8602380b140460d460bf013fe0bf0e7fd294630b9ffe50bf0e2fd002829463ff4faad0320f5e5002084f86601f3e51868624600eb0620704400eb0b4000eb056138466546fdf7bdfd0fe04eea062141ea0b4141ea05633946624665460bf0e1fb00281cbf032084f8200305f1080084f84f034146cfe501313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f00d8600218df887100121427e002a00f0cd8000220aab9f5c002f00f0a6809f187e78002e62d0be78002e61d0fe78002e60d03e79002e5fd07e79002e5ed0be79002e5dd0fe79002e5cd03e7a002e5bd07e7a002e5ad0be7a002e59d0fe7a002e58d03e7b002e57d07e7b002e56d0be7b002e55d0fe7b002e54d03e7c002e53d07e7c002e52d0be7c002e51d0fe7c002e50d03e7d002e4fd07e7d002e4ed0be7d002e4dd0fe7d002e4cd03e7e002e4bd07e7e002e4ad0be7e002e49d0fe7e002e48d03e7f002e47d07e7f002e46d0be7f002e45d0ff7f4ff29c56002fc2f229065dd02032602a7ff496af5be0013238e0023236e0033234e0043232e0053230e006322ee007322ce008322ae0093228e00a3226e00b3224e00c3222e00d3220e00e321ee00f321ce010321ae0113218e0123216e0133214e0143212e0153210e016320ee017320ce018320ae0193208e01a3206e01b3204e01c3202e01d3200e01e324ff29c56c2f229065f2a1ad84ff053079f5416d013444b275e2a5f7011d049275d2a9f700dd050275c2adf7009d020275b2a1f7105d000225a7105e01f325f2ae4d900228df887200131827e002a00f0be8000210aaa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df887100121726846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210aaa535c002b00f0828153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0f9805f7a002f00f0f9809f7a002f00f0f980df7a002f00f0f9801f7b002f00f0f9805f7b002f00f0f9809f7b002f00f0f980df7b002f00f0f9801f7c002f00f0f9805f7c002f00f0f9809f7c002f00f0f980df7c002f00f0f9801f7d002f00f0f9805f7d002f00f0f9809f7d002f00f0f980df7d002f00f0f9801f7e002f00f0f9805f7e002f00f0f9809f7e002f00f0f980df7e002f00f0f9801f7f002f00f00a815f7f002f00f008819f7f002f00f00681db7f002b00f00481203160297ff47baf1ae14cf67e22caf210127260002940f0168100210aaa535c002b00f0d98053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f65d01f7b002f66d05f7b002f67d09f7b002f68d0df7b002f69d01f7c002f6ad05f7c002f6bd09f7c002f6cd0df7c002f6dd01f7d002f6ed05f7d002f6fd09f7d002f70d0df7d002f71d01f7e002f72d05f7e002f73d09f7e002f74d0df7e002f75d01f7f002f76d05f7f002f77d09f7f002f78d0db7f002b79d0203160297ff49aafa9e000211171f6e6013170e002316ee003316ce004316ae0013181e0053166e002317de0063162e0033179e007315ee0043175e008315ae0053171e0093156e006316de00a3152e0073169e00b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df8871000210aaf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df8871002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f146bef15f0f98bf4ff05f09c9f1000a0aad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f805eb0e0208f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd008fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330aada9d20ce0ce460ae00ef1010e07e00ef1020e04e00ef1030e00e0ce460aad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df8871002694ff0000915f80910002900f0c78005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d009f12009b9f1600f7ff496af4ff060095ee009f101095be009f1020958e009f1030955e009f1040952e009f105094fe009f106094ce009f1070949e009f1080946e009f1090943e009f10a0940e009f10b093de009f10c093ae009f10d0937e009f10e0934e000220a7162e709f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88710d0f8ac234ff0000915f80910002900f0c48005eb09035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d009f12009b9f1600f7ff496af4ff060095be009f1010958e009f1020955e009f1030952e009f104094fe009f105094ce009f1060949e009f1070946e009f1080943e009f1090940e009f10a093de009f10b093ae009f10c0937e009f10d0934e009f10e0931e009f10f092ee009f110092be009f1110928e009f1120925e009f1130922e009f114091fe009f115091ce009f1160919e009f1170916e009f1180913e009f1190910e009f11a090de009f11b090ae009f11c0907e009f11d0904e009f11e0901e009f11f0901230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46ce46b9f15f0f98bf4ff05f0ecef1000842f2107c0aad18eb090a51d0b2fbf3f40a2b04f1300105f809104cf6cd41ccf6cc41a3fb011747d31af1010140d004fb1326ff08b6fbf7f405eb090204f13001517048f21f51c5f2eb11642ba3fb015135d31af102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31af1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb114209f1040963454fea57330aadabd20ce0f1460ae0f14607e009f1010905e009f1020901e009f103090aad059f002205f80920a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88700384602212a460af007fcd4f870c272208df8280078208df8290020204ff0000a1ffa8cf28df82a008df82ba015f80a00002800f0c88005eb0a035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00af1200abaf1600f7ff496af4ff0600a5fe004460020887078e70af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d046baf15f0f98bf4ff05f08c8f1000942f2107e19eb0a004fd0b2fbf3f50aa905f1300401f80a404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70aa901eb0a0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020af1040a73454fea5633add209e0c24607e00af1010a04e00af1020a01e00af1030a00220aac04f80a20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06f8100208df8870037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df81f1000f137010a2838bf00f13001ccf303508df8201000f137010a2838bf00f13001ccf303408df8211000f137010a2838bf00f1300100208df823001f208df82210211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf61e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2822d8c0f15d0ec0f15e02c0f15f03c0f1600c204400250df11f04675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88700059842f2941845f29c140aaa0e21c2f22008c2f213040af0b7f84ff6a42040f6b801cff6ff70c2f200010858a0426bd14ff6b020cff6ff700858b0f54d2f63d14ff6b420cff6ff700858a0425cd145f610634ff0000ec2f213034cf6394508f1040c00274ff0ff3263454dd8186830f003041bd0984528bf0c2847d3a8eb03018c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e1d130e00021417190e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7f2b9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f6d060c2f20700006808f1080342f6941c9842c2f2270c4dd142f610674ff0000ac2f2200746f6b9700cf1040e00244ff0ff384ff0ff3977453cd83e6836f0030515d0bc4528bf0c2e36d3aceb07039d4234d82346a54288bf2b46f6071cbf1c46aa447b19013803f10407e4d122e00420b4f5807f17d34ff000082546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b8eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea0008d14603e04ff0ff384ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834268d14ff69423cff6ff73fb58b3f5333f60d14ff69823cff6ff73fb58834259d14ff29c5043f21063c2f229004ff0000cc2f2270342f6f935071fa0f1080e002404970498834245d8d3f800a03af003071cd09e454ff0ff3028bfbaf10c0f3bd3aeeb0306b7424ff0ff3637d8a742264688bf3e465feaca7003eb07001cbf3446bc44013d00f10403dbd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff000498834204d17b4204ea0300664603e04ff0ff304ff0ff36824666208df8280072208df8290065208df82a008df82b002f208df82c006d204b238df82d0061208df8313069238df82e0078208df83230422356278df82f0020208df833303a238df8377047270aac8df830008df834308df835004c238df838708df83a00002720468df836308df839308df83b700af0a4f8e05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f98000208df8870020464946424609f0d0ff059d0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df887000aac20463146524609f002ff28461a21224609f07ffd00208bf86401cbf8600105984ef217310a904ff416300b900aa8c0f24701884701208bf8660106a800f0dbf8cbf810004db0bde8f08f0020c871d6e70021417206e72de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff64c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168b14242d04ff46d7002f093f9002879d0514642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945b3d1bff35f8f47e8000121b157e8001f4945f8d0a9e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f83b041f20401cef200014ef66c674ff29c56096800684ff64c4b48f2a359ccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108c0f245090291019003e000bfbff32f8fc847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168b94244d04ff46d7002f0d3f8002800f09b80594600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f5145b1d1bff35f8f46e8000121b156e8001f5145f8d0a7e74169dde9014561b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ee047f64c6245f6e466c2f20702cff6f8761368314600bf17689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f4230d041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94218d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2002e0dde90145fa20291bb1fbf0f003b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204608f0f1fc854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f0c780207887f00301084200f0c380012039464246334600f0a4f90446002898f8080018bf0624b6e04ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f099804ef66c6a4ff29c574ff64c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168514545d04ff46d7001f054ff002867d0414600bf42180c3182f8b46382f8b56382f8b66382f8b76382f8b86382f8b96382f8ba6382f8bb6382f8bc6382f8bd6382f8be6382f8bf63e4d1c0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f4945add1bff35f8f00bf47e8000121b157e8001f4945f8d0a2e705eb450100eb011090f85d1201b300f513760024304629462a460323009408f0edfc706840b14bf69b71c0f25d0188477068fff7f9fe74603068b475002818bffff7f2fe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f000f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104608f0dafb201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009508f080fc606840b14bf69b71c0f25d0188476068fff78cfe65602068a575002818bffff785fe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff64c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450b009002e0bff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a94243d04ff46d7001f049fe00283cd0494642180c3182f8b44382f8b54382f8b64382f8b74382f8b84382f8b94382f8ba4382f8bb4382f8bc4382f8bd4382f8be4382f8bf43e4d1056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b3d1bff35f8f46e8000129b156e8001f4145f8d0a9e700200099002801eb410100eb011118bf01f5137001b0bde8f08f00bfb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46fbf751f8a81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c644ff29c564ff64c4948f2a35bccf2ff04c2f229064ff6ff77cff6ff7900254ff0010ac0f2450bcde90813cde9062003e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168a14244d04ff46d7001f0a5fd002800f0de83494600bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1046080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f4145b1d1bff35f8f46e8000121b156e8001f4145f8d0a7e70999ddf81c8001eb410100eb011098f9081000f51374b1f1ff3f01f0030609dd274617f8110fd8bb2068002818bffff74dfd2be3207cf0b1607ce0b10699099a002520460323009508f02afb606840b14bf69b71c0f25d0188476068fff736fd65602068a575002818bffff72ffd00202060a06020822068002818bffff726fd00204ff480712060a060218298f80210a081092004f11107e174a17426756076a07c98f80210884240f0d582217db14240f0d182089b411ca3f10b00627e03971e2828bf1e209042a17488bf6076981e86b20a2e4ff00005c0f0e182092241f221090920049619e02068002818bffff7edfca089c4f8009084f81090c4f808900130002d059d41f22109a08118bf06250898584482b2b24280f0c182217c80b24ff0000a0429074600f2808018f80220471c4b1c0129237405dd022906d0032967d1e28106e021b9627503e0238943ea02222281b74280f0a282042966d018f80720831c8f1c0129277405ddff290ad003290ad11f464ce000291cbf278947ea0222228102e0627500e0e281b34280f08682022936d818f80320c71ccb1c0129237407dd022934d0fe2907d16275b7420cd374e231b9238943ea02222281b74204d36ce2e281b74280f0698202292dd018f80720031d41f00407fc29277408ddfd290ad0fe291cbf278947ea0222228104e00029bed1e28100e06275b34280f04e8209b11f4611e018f80320471d05202074e189208941ea0221e18130b1fff731fc0028206000f06b8200bf238960890897191a1ffa81fbb9b2721a5a45b8bf93465fea0b420bd02268414410441ffa8bf2faf7a3fe6089b4f808a0002701e057469a46584481b2514560817ff450af0026d4f800808df82b60607db8f1000f0df12b0108bf88460f2806d8217d00f00302511ab1fa81f14e09000706d4217e607e814238bf20760fe000bf606840b14bf69b71c0f25d0188476068fff706fc6760607e20760120e0820595a6b1607da67d400715d4002e049e4ff0000500f08b811ffa8af100294ff6ff7300f0108101295fd10020d5e0607d400752d4002579e14ff48030fff7bdfb002e804600f07181a07d049e00284ad0b8f1000f47d06668002e00f0028120890428c0f0628121680a1812f8043c002b40f05b8112f8033c002b40f0568112f8023cff2b40f0518112f8012cff2a40f04c814ff4803531607060c6f80c8035610028029000f067814bf69b70c0f25d0000f58572304600219047002840f035813169002900f0318170688d420d46e7d1029a0d468242e3d127e14ff48030fff76cfb054622e1454621e14ff6fe7000ea0a00ae464ff0000c42426ff0010008eb0006b578f67883ea05231db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead7375d0087ea43032db25f003fb209ead53585ea430309ead73787ea430383ea06231fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead73787ea430309ead6365f0086ea43033fb25e0036b209ead737023087ea430309ead6371618023687ea430395d1049e0230674675465feaca7232d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003e0899ab282426fd1099b4046faf754fe002869d14ff00009012374e03820fff7a9fa00285ed00646077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2ad40cff6ff70784430624ff2f940cff6ff70784470624bf69b70c0f25d0045f6e46200f13c0c30460f21c0f27c023823e04730b33046fff76cfa4546049e606840b14bf69b71c0f25d0188476068fff760fa67604ff000090323a7750699099addf81c801ffa8af72046009708f03bf8002d294605463ff45aad0846fff749fa55e5666073e63760f760049ec5f5803ab5f5803f45467ff647aed0e70699099a002520460323009508f01df8606840b14bf69b71c0f25d0188476068fff729fa65602068a575002818bffff722fa0020387000202060a06020820a2528460bb0bde8f08f98f808004006f7d5207c00b303980078e0b10699099a002520460323009507f0f0ff606840b14bf69b71c0f25d0188476068fff7fcf965602068a575002818bffff7f5f900202060a06020820b252068002818bffff7ebf900202060a0602082cae703980078e0b10699099a002520460323009507f0c5ff606840b14bf69b71c0f25d0188476068fff7d1f965602068a575002818bffff7caf900202060a06020820625a8e72de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7a9fa002869d006462846fff7fffa21462a46fff7d3fa3046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff72ebb0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22faf7dbf904f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522faf797f90834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522faf741f94ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff64c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f02d10168494544d04ff46d7000f0a3fd00286ad0414642180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d1c0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5945aed1bff35f8f00bf46e8000121b156e8001f5945f8d0a3e7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff73afe2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff780fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f85b04468002c00f082828368002b00f07e824ff29c5c04eb03094ff0000bc2f2290c0025002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310eeb0a0300254b451c464ff0000680f05e82a04618f9013b03f07f07af40002b46ea070610d406f00703012b16dc0bb3012b40f04c82a9eb0803082bc0f0478204f10903dee700bfc84580f04082182d05f107054446dcd939e200bf022b3ad0052b40f03482a9eb0803042bc0f02f82631dc7e7c84580f02a8294f90130002b04f10203bed54b4580f0218294f90230b3f1ff3f04f10303b4dc4b4580f0178294f90330b3f1ff3f04f10403aadc4b4580f00d8294f90430b3f1ff3f04f10503a0dc4b4580f0038294f90530002b00f1fe81a31d96e7c84580f0f98194f9013004f1020e002b03f07f0a1ed5ce4580f0ee8194f90250e31c05f07f07b5f1ff3f4aeac71a02ddf0469e460ee04b4580f0de8194f9037004f1040e07f07f05b7f1ff3f4aea853a31dd9846a9eb0e039a4500f2cd81f308672b19d0652b7ff460afbaf1060ffff45caf9ef80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf0490cde9021e39e0804670460d46514616466746744600f0dcfba646bc4629463246404639e7ce4580f09e8194f90470631d07f07f05b7f1ff3f4aea455aafdc4b4580f0918194f90550002d00f18c8104f1060e4aea057ab3e748f2a3513046c0f24501bff32f8f8847ddf80ce04ff29c5c02990498c2f2290c2246dcf80050bff35f8fdcf80060bff35f8f33466ff39603b3f1005f06d133684ef66c67ccf2ff07bb4257d04ff46d70144600f037fbddf80ce04ff29c5c029906460498c2f2290c2246002e3ff4e8ae4ff64c43cff6ff73f7180c3387f8b4b387f8b5b387f8b6b387f8b7b387f8b8b387f8b9b387f8bab387f8bbb387f8bcb387f8bdb387f8beb387f8bfb3e4d14ef66c63ccf2ff0333600123b3724ff6ff73b383f38333847384b384f38433857385b385f38533867386b386f386338773875ce8003fab428bd1bff35f8f4ce8006323b15ce8003fab42f8d081e798f8043098f8057098f80650032b47ea052839dd052b61dc042b00f08380052b7ff490aed6f868313bb147f64c67c2f207073f68db1b002b19dcd6f86c3186f866b1c6f86cb1c6f800b3a6f86cb373b10c4648f2a3511846c0f2450115466746f04688470498c646bc4621462a4647f64c63c2f207031b6845f69077c0f201073b44c6f868315de6012b3ff44fae022b00f09880032b7ff455ae01920c4667467546fff7c5fb019a03460498ae46bc462146002b3ff446ae96f84231002b3ff441ae304641f28831a6f8408107f0e2fd019a0498ae46bc46214633e6062b52d0072b7ff42fae4df6db50c0f24a0015460e466446f0468047034604985f1ec646a44631462a46012f3ff61cae981eb0fa80f04009fff784fcc646a446314604982a460fe615460c467746fff781fb4ff29c5c03460498be46c2f2290c21462a46002b3ff4ffad96f84231002b3ff4faadb6f8403143457ff4f5add6f83c3186f842b1002ba6f840b13ff4ecad42f68d411846c0f2440188474ff29c5cbe46c2f2290c2146cbe7d6f86c31c6f868b1002b86f866b1c6f86cb1c6f800b3a6f86cb33ff4d0ad0e4648f2a35180461846c0f245011546674674468847a646bc4631462a4683e696f84231c6f838b1002b3ff4b9ad0446d6f83c0167468846154686f842b1a6f840b120b142f68d41c0f2440188474af273660120002100220023c0f24606b047ddf80ce020462a464146bc4698e54ff2a513c0f2490305b0bde8f04f184700bf7fb50646002806d1fff700fb002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817048f63801c0f20001033079440b22f9f710fc0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f9f7d8fb0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f9f729fb1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f9f77ffa4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f093800c46014600784d2840f08d804878432840f089808878012840f085804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f02d10268424548d04ff46d70fff767ff002857d04ff64c425146cff6ff7283180c3283f8b45383f8b55383f8b65383f8b75383f8b85383f8b95383f8ba5383f8bb5383f8bc5383f8bd5383f8be5383f8bf53e4d1c0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a45a9d1bff35f8f00bf47e8000222b157e8002f4a45f8d09ee7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff66932cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6c140cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff359ae0cde901100120cff680704ef66c644ff29c564ff64c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f02d10168a14243d04ff46d70fff7a6fb0028c6d0594600bf42180c3182f8b48382f8b58382f8b68382f8b78382f8b88382f8b98382f8ba8382f8bb8382f8bc8382f8bd8382f8be8382f8bf83e4d1046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f5145afd1bff35f8f46e8000121b156e8001f5145f8d0a5e7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff477af00210025fff7d0fe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff74cfe0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff782fe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff66d22cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff7a8fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef7c6fb014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7a6fb0146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7a3fb204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd47f66200c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef7e3fa0028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f8f7ddfb4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf7e1be00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1faf711f8c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd02293cbf4ff0ff3070472de9f04f99b00278437842ea0322b2f5007f089204d94ff0ff3019b0bde8f08f4ef66c694ff29c564ff64c48ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a0391069008e000bf48f2a3512046c0f24501bff32f8f8847d6f800b0bff35f8f3468bff35f8f20466ff39600b0f1005f02d12068484546d04ff46d70fef780fc00283fd00446404621180c3081f8b45381f8b55381f8b65381f8b75381f8b85381f8b95381f8ba5381f8bb5381f8bc5381f8bd5381f8be5381f8bf53e4d1c4f8009084f80aa0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f5845acd1bff35f8f00bf46e8004028b156e8000f5845f8d0a1e700240898ddf80cb058b1fdf78ffd0146002c4ff0ff3018bf002902d119b0bde8f08f08980021b0fa80f040098df824108df825108df826108df827108df828108df829108df82a108df82b108df82c108df82d108df82e108df82f108df830108df831108df832108df833108df834108df835108df836108df837108df838108df839108df83a108df83b108df83c108df83d108df83e108df83f108df840108df841108df842108df843108df844108df845108df846108df847108df848108df849108df84a108df84b108df84c108df84d108df84e108df84f108df850108df851108df852108df853108df854108df855108df856108df857108df858108df859108df85a108df85b108df85c108df85d108df85e108df85f108df860108df861108df862108df86310b4b1d4f86c219ab14ff4006305e000bf3f683b44b3f5403f0ad2d718be680136f6d07e68033626f0030631441031efe7089a4ff0020a002a00f0f780abf102020a2ac0f0f28000260df1240e069800eb0a0c9cf801704ff0ff30012f3ff648af9cf802209cf803309cf8045042ea03229cf8053042ea054949ea0368a8f1011212f5803ffff434af9cf808209cf80930029242ea03250af10a020592abeb02020795013d9542bff423af9cf806509cf80720019545ea022bb8eb0b050496fff417af079eae423ff613af069810f80a5045ea072a4feada001ef8006005f007050127af40374240f0eb821ef8005047ea05074ff6ff75c0f202050ef800703cb3d4f86c0120b316021a0200924ff4006283189f6857453ed01b681a44aa4217d883189f68574536d01b681a44aa420fd883189f6857452ed01b681a44aa4207d883189f68574526d01b681a44aa42dfd9bbf1000f40f0b4824ff6fc7209f10300c0f203021040084400f11001ddf80cb00798059a049e00eb020a0898013686424ff0000028bf01204fd2abeb0a02092a3ff65caf49e05868404540f09182d8685845c0f08d82e1d9079aa0eb0b00824200f286821046aab30298009addf80cb002eb00090198c9f1000e304403eb0008a9f10106002308eb03020ceb0307107cbd7aa84240f06c829e4218d0507cfd7aa84240f065820eeb0300851c0fd092f812a03d7baa4540f05b82033007d0d07c7a7b904240f0548204339945dbd10df1240ea5e7ddf80cb0a3e7002800f04882baeb0b0018bf0120b1f53e3f4ff0000188bf0121014308980028c1f100003ff44fae00297ff44caed4f86cb1bbf1000f40f08b804ff44030fef772fa002800f02782834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760221c0f202064ff0000a09e008980af1010a09eb080182454ff000003ff4a9ad069807914518405ca9782a7a6f78039195f803e095f8049095f805c0a979eb7905926a7a40ea072804925cb3012f29d84ff400670beb0705a868404500f0a38028680744b7421dd80beb0705a868404500f0998028680744b74213d80beb0705a868404500f08f8028680744b74209d80beb0705a868404500f0858028680744b742d7d90398cdf808a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a0020cde900310397b9f1000f26d00beb09035bf809105a68514580f09a80eab10beb02005bf80210d0f80490514580f08b80b9f1000f11d00beb09035bf809105a68514580f0858042b10beb02005bf80210d0f804905145d6d375e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f7f7f1fb4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f800230fd90beb09004bf809104ff0ff3142608160c260c4f8009309e0e868079a059f5fe010b10268114401604ff000090020b9f1000f76d00beb09035bf809105a68514522d2002a6dd00beb02005bf80210d0f80490514513d2b9f1000f62d00beb09035bf809105a6851450ed2002a59d00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf808a0079adde90031059f00280cbfc4f800c3c0f804c003984ff6ff7668600020c0f20206c5f80880e86041ea0321049b814247ea032902f10a087ff4c5ae05f11007781806994a464144f7f70afbe9686868aa68d4f86cb14944e96081424ff0000018bf07464bf82270ade600204ff400684ff4006704e000bf2f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f7f729fb4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f8008319b0bde8f08f00281ebf0168114401604ff0ff3019b0bde8f08f00bf2de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70fef712f8002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8680310b101b0bde8f08f4ff41630fdf7c5ff00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8680301b0bde8f08f002001b0bde8f08f84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009504f0bff83eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb00446002047f64c68a4f88003c2f20708d8f80000002a8b461abfc4f874030146d4f87413401ac4f87c03fdf762f8002800f0f980d4f86803002800f0f48004f0e6f9002800f0ef800646b4f86c03002848d0a0f10108d4f87c0300254ff4a0714ff4f0774ff48059cde90d050df1180acde901152046414632464ff42073cde906950c95cde9035a009704f068f8002840f0c980d4f87c034146cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906950c95cdf810a0009704f04cf8002840f0ad809df8380094f8801347f64c68084384f88003c2f2070806e0d4f8681330464ff41632f7f712f94ef66c694ff29c57ccf2ff09c2f229074ff6ff76002506e048f2a351c0f24501bff32f8f8847d7f800a0bff35f8f3868bff35f8f01466ff39601b1f1005f02d10168494548d04ff46d70fdf781fe002875d04ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d10121c0f8009081728683c683068446848684c684068546858685c685068646868686c6860687468757e8001f5145aad1bff35f8f00bf47e8000121b157e8001f5145f8d09fe7054604f01ff9002d18bf002803d101208bf8050022e0c5f860014ff001094ff4f07085f8649101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718bf8059004e09bf805008bf8049030b14ff0ff300fb0bde8f08f0025cbe794f8800384f8810348b3d4f8700342f66535c0f2440528b1d8f800102d31c4f8781311e044f2f330c0f200007844002122460023a847c4f87003d8f8001001f12d01c4f8781320b105f1e8022d21904728b1002084f881030fb0bde8f08f00200fb0bde8f08f022a3cbf4ff0ff3070472de9f04fadf2f44d0e784f780a4456ea072701f102041d9702f094821c903ea8063000261f9314901a92944202f08482601c904202f0808220786178a31c40ea0121d01a81422593269102f275821f98ddf82c252c90ddf81805ddf824152d90ddf81c0530912e90ddf8200521962f901068411e0028116002f05e822698002802f05a822698871c032f02f05582e678032e02f25182259890f80080f00702d104f1040927e0269820f00100022802f0438294f804a065791c984aea052b59462caa02f048fa002842f03682ddf8240504f10609012d30900dd8ddf82c05806948b14feadb020af00701835c012505fa01f119438154022e04eb070a03d2ddf82405279024e0d14503d04c4614f9015b01e00025544645f64d57c0f24607b847012808bf0135681e81b26e0800ebd130002d48bf4610b8470128ddf8240508bf76423118d145a1462791309102f0f481b8f1040f29ddb8f1060f40f3ec80b8f1070f00f04583b8f1080f00f05a81b8f1090f42f0e181d14502f0de8119f8011bd14542f0d9810f2902f2d681ddf82805002801f08680dde92e232c9801eb01115a43f7f73af801f07cb8b8f1020f2edcb8f1010f00f02282b8f1020f42f0bc812c984ff000082b902d98d14528902e98cde9369a29902f98cdf8e0802a90ddf82c05cdf8cc80c069329000f0ea8309f10100369099f80080504532af00f0e28309f10200369099f801000002dde3b8f1030f00f04982b8f1040f42f08d81baeb090402f0898109f10100504502f084811c98002802f08081a01e0528c2f07c8109f10700504542f077811c98d0f86c01002802f0718199f80110012902f26c8199f8003043ea012250f82210002902f063810f1ab90742f05f816ff4403140f60f063944cff6fd76b142c2f05581384450f8081c914242f04f8150f80c1ca1f1011616f5803fc2f04781002802f0448150f8046c8e4242f03f81c7f54037b94202f23a81ddf82c75bf6947b1d20803f00703be5c012505fa03f33343bb54dde92c5bdde92e6a002236ab02f080f900284ff0000708bf4ff0ff3700f08b83ddf828052b961a9a219e00280df1c80800f08383072c4ff0ff3740f07e83002d00f07b830027fcf793fd002840f01a841a9a4ff0ff3770e3b8f1050f00f07e82b8f1060f42f0f980d14502f0f68009f10100504502f0f18009f10200504502f0ec8009f10300504502f0e78009f10400504502f0e28009f10500504502f0dd8009f10600504502f0d88009f10700504502f0d38009f1080caaeb0c000828c2f0cc8009f11000504542f0c78099f8040099f8051050ea01261ebf99f8060099f8071050ea012502f0b88099f8000099f801202d9940ea0224081bc2f0ae80864202f2ab8099f8020099f803302e9a40ea0327d01bc2f0a180854202f29e80ddf82805002800f04e872c982f9bcde90147279fcdf814c0cde90365009703f036fc00f040bf5046cde93e90ddf82c050021c0693eaf36addde92c48dde92ea64091cde936013846294602f03cfb81463846294602f037fb4099002940f0da82dde93e218a4200f0d582531c8b4200f0d182931c8b4200f0cd82d31c8b4200f0c982131d8b4200f0c582531d8b4200f0c182931d8b4200f0bd82d31d8b4200f0b98202f108038b4240f0b482117853784ff0ff3551ea032101f04f869378d77853ea072301f04986b1f5207f01f24586b3f5f07f01f2418697792b960f2f229701f23b86d6792f46102e299600f294822093ddf82c35239037981f6a92f804c03843ddf8287552794ff0000b002f2494186201f0b98727980023084440428145c1f224862798a8eb0000814581f21e86209847422398b842c1f21886ddf88ce02498209ef2451f4640f366824cea0222b2eb510f28bf4a08b2eb560f28bf72081792013a4ff0000738bf3a460d92cef1000202eaee75aaeb0e02b242a8bf324695421e9280f24882279a179b91445a001b9203fb03f29200169201eb090203294ff00001279238bf01210022032e38bf012211431591711e1291b11e10910d9900244a00494389000a9109f101010e9129990f920a0141ea01110b916ff008010c9201eb43012b9a11912eeaee7102fb0101cdf84c902a910021189101f085bbd14501f09b87494611f8010b012801f295872c9a002828922d9a2b922e9a2a922f9a299200f05682514501f0878709f10201514501f0828709f10301514501f07d8709f10401514501f0788709f10501514501f0738709f10601514501f06e8709f10701514501f0698709f10801514501f0648799f8011099f8022099f8043041ea022c99f8032099f8056099f8061042ea032746ea012699f8071099f8082009f10903169341ea022135e2aaeb0905052dc1f0438709f10508d04501f03e8709f1060699f80570aaeb0600b842c1f03587f019504541f031872c981890dde92da01e902f981790afb1002402e00134bc4210d2305d01381e28f8d93019391b3eaa36ab02f01dfe002801f017873e980444bc42eed3ddf82805002800f0c385052d01f00b871898002801f00787fcf790fb002801f0028798f8008008f10600854241f0fb8647f65420c2f207000768002f01f0f386387b797bba7bfb7b40ea012040ea024040ea0365a5f1810010f1800fc1f0e386387c797cfa7c40ea0120b97c40ea014040ea02600b90813810f5817f41f2d386b8f1000f4ff0000012972a9000f027844ff0000c00270df1c80b0ae000f100403ea941f824000137474504f1010c80f0c583f05d6446411e1e29efd9f019a8eb070136aa5b4602f0b1fd002800f01781369932983eaa0f4442f82400e4e7d14501f0a18609f10100504501f09c8609f10200504541f0978699f8000099f801102caf40ea0121ddf82c058ccf0490ddf828052f9e03902798019602901c98009703f042fb0746ece0baeb090801f07b8609f10100504501f07686a8f102000528c1f0718609f10700504501f06c861c98002801f0688609f1080b99f80740aaeb0b00a042c1f05f860beb0400504541f05a861c98d0f86c31002b01f0548699f80100012801f24f8699f8001041ea002053f82020002a01f04686d21a970741f042866ff4403740f60f061744cff6fd76b742c1f038869e1856f8083c834241f0328656f80cacaaf1011313f5803fc1f02a86002e01f0278656f8043c534541f02286c2f54032924501f21d86ddf82c25926942b1c00801f00701135c012707fa01f119431154baf1c10fc1f00c863078012841f008862c982b902d982a902e9829902f9828900cb3a6f13f075d4601e0013c1bd015f8010b411e1f29f8d341b22029c1f2f08507eb400117f81000497840ea0122c12ac1f0e685304651463eab01f03cfe0028e3d101f0ddbdddf82805002800f08d840020b8f1080f4ff0ff373e903ed32b98e0b30025fcf757fab0b399f807a00af10800804530d199f8000099f8017099f8068040ea072400f085bc32af01203890002036ae24903046394602f076f881463046394602f071f838990746e9b1002400260120389000200df1d80a0df1c80b23905046594602f060f805465046594602f05bf8389919b34ff0ff371a9a219e002f00f0448401f08bbddde936018842ddd0024612f8014b8a423692d8d0821c369243788a4244ea0324d1d0c21c369286788a42cdd0011d3691c0780002cbe78646dde9360122961a9a219ebb4688424ff0ff37d4d1b9f1000fd1d4bbf1000fced4ddf82c353398196aaa460843249d18622b9845ea08053e904ff6fe7085422a98289e299f41901c98cc463f96409700f09c844ff6ff718d4240f07884d0f868834ff420703f904ff4f07040904ff4a070419000f08cbc514501f0318509f10201514501f02c8509f10301514501f0278509f10401514501f0228599f8022099f80110570099f8032099f804304fea810c09f10501960016915900002e179101f00e851799002901f00a852b99b1eb0c02c1f00585964201f202852a99ca1bc1f0fe841799914201f2fa84002878d0279800250ceb000280e048f2a351c0f245010027bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f035824ff46d70fdf701f800283ff4c6ab4ff64c41cff6ff7142180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa14297d1bff35f8f42e80001002900f0e78152e8001fa142f6d08be7279800250ceb0002c00706d1002a04d42b99b0188842d8bf01251699179baaeb01001390ddf8280503fb06fbb0fa80f040092843c00715954ff0000e1b900d4600202790cdf878a0cdf860b014e000bf27982499084427902098239981424ff0000088bf01204eea000e229d5feace7008bf0d44ddf878a05feace7004d02798834508d801f03bbc554500f0cc822798834540f2c882baeb050401f0308495f800805fea181001d0012111e0012c01f02684687808b102210ae0042cc1f01f8495f802c0eb785cea032001f01884042123912799abeb0103984201f210841b992490002920942295b2d1249808f00f09431e032b4fea081ccdf864e076d24ff0000a2498dde918be10f00308a0d027988244bafbf6f000fb16a1c319881853ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd54b8f1010f3ff47caf0af10100b0fbf6f101fb1600cb19104453ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd54b8f1020f3ff457af0af10200b0fbf6f101fb1600cb19104453ea00013ff54baf2b998842bff447af2a998b42bff443afdde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd5431e720f003084ff0000a05e000bf0af1040ad0453ff480af279800eb0a0bbbfbf6f000fb16b300eb070e98185eea000315d42b99884212d22a998e450fd2dde928310efb013341085c5cc00704f00f0504f0f0044c4408bf45ea0c045c540bf10100b0fbf6f101fb1600cb19104453ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd540bf10200b0fbf6f101fb1600cb19104453ea000115d42b99884212d22a998b420fd2dde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd540bf10300b0fbf6f101fb1600cb19104453ea00018ad42b998842bff487af2a998b42bff483afdde9285103fb01514308cd5cc00705f00f0405f0f0054d4408bf44ea0c05cd5471e7bcf1000f299500f0ac82acf101054ff000083eaf09e0b446454508f10108a4f1010407f1040700f09a823ea850f828100029f1d40020434684421dd007eb80067268b2f1ff3f18dc5a1c954214d0b268b2f1ff3f11dc9a1c95420dd0f268b2f1ff3f0adcda1c954206d032690433002a00f10400e0d400e00022129836ab6646cdf800b002f040fa00283ff41aad32980028c0d04af20d3136a8c0f24e018847b9e7299501204ff0000c0df1c80b5be2d0f86c014ff0ff37002800f0278199f80110012900f2228199f8002042ea012150f82120002a00f01981121a930740f015816ff440333c4640f60f071344cff6fd77bb422746c0f00981104450f8083c8b427ff46da950f80c1c0027a1f10113cff6ff77bb42fff463a900284ff0ff3700f0f48050f8043c8b4240f0ef80c2f54032914200f2ea8000223eab01f0b0fa00283ff44da999f8031099f80200090699f8053041ea0040279999f8042001eb2040190641ea024199f806200f24970602f00f0304eae7775f4389246743ff0a8df8c8700e2712f0200f08bf012703fb07f704fb07f74fead7278df8c9704ff00d0708bf022703fb07f704fb07f74fead7278df8ca704ff00c0708bf032703fb07f704fb07f74fead7278df8cb704ff00b0708bf042703fb07f704fb07f74fead7278df8cc704ff00a0708bf052703fb07f704fb07f74fead7278df8cd704ff0090708bf062703fb07f704fb07f74fead7278df8ce704ff0080708bf072703fb07f704fb07f74fead7278df8cf704ff0070708bf082703fb07f704fb07f74fead7278df8d0704ff0060708bf092703fb07f704fb07f74fead7278df8d1704ff0050708bf0a2703fb07f704fb07f74fead7278df8d2704ff0040708bf0b2703fb07f704fb07f74fead7278df8d3704ff0030708bf0c2703fb07f704fb07f74fead7278df8d4704ff0020708bf0d2703fb07f704fb07f74fead7278df8d5704ff0010708bf0e2703fb07f704fb07f74fead7278df8d6704ff0000708bf0f277b436343db0a09148df8d730c2f300122b9b4ff0000ccde90382cde90001284651465a463eaf0297674602f0a0f91a9afff7dcbb554541f069812798834541f06581ddf82805002818bf012015990840012810d1dde92803139907fb0300770800eb5202179800970190169801f01dfa002801f04b811a9a219e1d9801368642dde9250100eb01047ef4b9ae01f044b948f2a351c0f245010025bff32f8f88474ff29c50c2f229000668bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f0c3834ff46d70fcf74cfc00283ff482ab4ff64c41cff6ff7100bf42180c3182f8b45382f8b55382f8b65382f8b75382f8b85382f8b95382f8ba5382f8bb5382f8bc5382f8bd5382f8be5382f8bf53e4d14ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fb14296d1bff35f8f42e80001002900f0748352e8001fb142f6d08ae729463eaa774601f0d3f800287ff42dabddf82c051a9a8069be46299f4ff00001cc4660b1b1eb552f09d1ea0808f00701835c012505fa01f1194381541a9addf8f880b8f1000f00f03e833d46002c4ff0ff371cbfdde9220151ea00033ff408ab3f986045fff404aba0eb0c0084423ff6ffaa40985845fff4fbaaa0eb0b0083423ff6f6aaddf82805002700283ff4f0aaaaf1011010f1021f7ff6eaaa27980aeb0001b142b8bfae45bff6e2aa604281427ff7deaa584286457ff7daaa21eae17001eae171aceb01020f190eeaee79714609eb030e21eae171331a9f42a5eb010538bf3b462091ae45249528bfae462b9fcdf84ce0b845abeb09071e9700f05b86002700f071be002002e04ff0000c012099f804100f248d0601f00f0604eae575754389246543ed0a99f800e08df8c8500e2599f8012099f8023099f803702b9111f0200f08bf012506fb05f504fb05f54fead5258df8c9504ff00d0508bf022506fb05f504fb05f54fead5258df8ca504ff00c0508bf032506fb05f504fb05f54fead5258df8cb504ff00b0508bf042506fb05f504fb05f54fead5258df8cc504ff00a0508bf052506fb05f504fb05f54fead5258df8cd504ff0090508bf062506fb05f504fb05f54fead5258df8ce504ff0080508bf072506fb05f504fb05f54fead5258df8cf504ff0070508bf082506fb05f504fb05f54fead5258df8d0504ff0060508bf092506fb05f504fb05f54fead5258df8d1504ff0050508bf0a2506fb05f504fb05f54fead5258df8d2504ff0040508bf0b2506fb05f504fb05f54fead5258df8d3504ff0030508bf0c2506fb05f504fb05f54fead5258df8d4504ff0020508bf0d2506fb05f504fb05f54fead5258df8d5504ff0010508bf0e2506fb05f504fb05f54fead5258df8d6504ff0000508bf0f256e436643f60a00288df8d76040f01682120642ea0e41279a380602eb2145299940ea0340ddf84880acf1010601eb204000240a90cdf838c00c9607e001f01f000b3801346445054400f0ef813ea850f82410b1f1ff3ff1dd23469e421cd03ea800eb83004268b2f1ff3f16dc0133b34212d08268b2f1ff3f0fdc0133b3420bd0c268b2f1ff3f08dc0133b34204d002690133002ae1d400e00022404636ab31af009701f0b9fe002800f0c58131990029159100f0b1819df8e0009df8e1100f9450ea01201195279000f096819df8e4709df8e5603f0447ea06670b9e279d9df8df009df8de102e4406eb27470a9e020241ea00249df8e2009df8e330f71b00042497119d012740ea036007eb54060a44031405eb20401396561e19941696ee1801f00304e91a431c1093831c0d93159bc9075d1c07eb52031b94121b00242991f10723932a92289107e000bf279901348c4223990d4400f04f8124990919f5d41e9a9142f2d2199a002aefd0dde917324ff0000901fb032e169922940329209580f099801b99209d229c0029ded01599139a012704fb02132b994fea59029a5c01f0100187ea111c02f00f01d5b25feac97808bf29090a46002918bf012242ea0c02012a14d119eb000611d456450fd272081ef802501bf8011005f00f0705f0f0050d43f60708bf47ea01150ef802501b99209d229c0129a8d009f101014908595cb8f1000fcab24fea121208bf01f00f02d1b2002918bf012141ea0c01012917d1109911eb090113d4514511d24d081ef805601bf8022006f00f0706f0f0061643c90708bf47ea02160ef80560229c209d1b9902293ff479af09f102014908595cb8f1000fcab201f00f0108bf11090a46002918bf012242ea0c02012a7ff465af0d9a19eb02033ff560af5345bff45daf5a081ef802701bf8011007f00f0607f0f0070f43db0708bf46ea0117229c0ef802704ae7ac4608e000bf2a9909f1040949450cf1020c3ff45caf2b991cf8013c01f010010122deb2002382ea11110f2e88bf01230b43012b00eb090319d1002b17d4534515d235095e081ef806201bf80550574602f00f0a02f0f0022a435feac07b0df1c80b08bf4aea0512ba460ef806201cf8012c12f00f06324618bf01220a43012a19d15d1c17d4554515d26a081ef802501bf80660d846ddf8a4b005f00f0747ea0617bbf1000fc34605f0f00508bf45ea06070ef802709cf80020d6b200220f2e88bf01220a43012a17d19d1c15d4554513d26d0832091ef805601bf802200446289806f00f0706f0f00616430028204608bf47ea02160ef805609cf8002012f00f06324618bf0122114301297ff47bafd91c3ff578af5145bff475af49081ef801201bf8063002f00f05299e45ea031502f0f002002e08bf42ea03050ef8015061e74af20d3136a8c0f24e0188479df8dc009df8dd10dde911580c9edde90ec405e09df8dc009df8dd10ddf838c040ea01200be6002005e04ff0ff37fef7d1bf4ff0ff302a901a9a219e2a9ffef7cabfd0f86c114ff0ff30002900f02281012f07463ef6bdaf51f8240000283ef4b6af401a82074ff0ff377ef4b2af6ff4403240f60f030244cff6fd739a42fef4a8af0b1853f8081ca1427ef4a2af53f80c6c0022a6f10111cff6ff729142fef498af53f8041c2493b1427ef492afc0f54030864223963ef68caf249800283ef488af2398c128fef484af2498007801287ef47faf4fea88660f2508f00f0705eae6767e4389256e43f60a8df8c8600e2699f8021099f8033099f8040099f8052018f0200f08bf012607fb06f605fb06f64fead6268df8c9604ff00d0608bf022607fb06f605fb06f64fead6268df8ca604ff00c0608bf032607fb06f605fb06f64fead6268df8cb604ff00b0608bf042607fb06f605fb06f64fead6268df8cc604ff00a0608bf052607fb06f605fb06f64fead6268df8cd604ff0090608bf062607fb06f605fb06f64fead6268df8ce604ff0080608bf072607fb06f605fb06f64fead6268df8cf604ff0070608bf082607fb06f605fb06f64fead6268df8d0604ff0060608bf092607fb06f605fb06f64fead6268df8d1604ff0050608bf0a2607fb06f605fb06f64fead6268df8d2604ff0040608bf0b2607fb06f605fb06f64fead6268df8d3604ff0030608bf0c2607fb06f605fb06f64fead6268df8d4604ff0020608bf0d2607fb06f605fb06f64fead6268df8d5604ff0010608bf0e2607fb06f605fb06f64fead6268df8d6604ff0000608bf0f2677436f430024ff0abaf1000f8df8d77000f051821b0643ea0141279b5f4603eb2144110641ea004000142290c8f30010209024985646a0f13f0822e20746fef79cbe0120229f0190184641465346009702f08cf9dde923e0dde92a2101350a441e9900278d422a92bef687aee94331448d42b8bf29461b9a6fea41011144012938db169a4ff0ff3301fb1121179a4ff0000c121b012a03eb420233db02fb02f38b422fdd119aa2eb440303f10807032f03f1060220db02fb02f68e421cdd052f03f104021adb02fb02f68e4216dd072f03f1020214db02fb02f68e4210dd0434092fa3f1080203db5b438b421346dcdc083206e0002427e0013402e0023400e00334209e012c1edb0832931f5b438b4219dc022c16db131f5b438b4200f3b280022c0fd0931e5b438b4200f3af80042c08db02fb02f38b4200f3aa80043c02f10802e2d10024e3462b9b05eb0e0101fb0303299804eb090210282798a0eb040a3ff46fafb5fa85f1159849090143289349d11298854246d01099681e491b19958842b8bf01466fea41000f9908440128c0f2ad800a99189b00fb10100d99cb1a4ff0ff31012b01eb430179db01fb01f7874275dd5900189da1f1090303f10807032f03f1060165db01fb01f6864261dd052f03f104015fdb01fb01f686425bdd072f03f1020159db01fb01f6864255dd0435092fa3f1080103db5b4383420b46dcdc08314be022eae27cc245a8bfc246d44531da4ff0000b5feacc7019950ad0289b4fea5c00195c299a01f0f00111430cf1010c19544fea5c02b2eb5a0f1dd228982a9f0b9d00eb5a03b9180e4606f8015b9e4280f08880881c9842357080f08880ce1c9e42057080f082800437b81898423570e9d37ce02498ede6289800eb5c0076e0013c4ff0000b5de7023c5ae7033c58e7013502e0023500e003351895ddf860b0bbf1010f23db08318b1f5b4383421edcbbf1020f19db0b1f5b43834200f3d380bbf1020f11d08b1e5b43834200f3ce80bbf1040f09db01fb01f3834200f3c980bbf1040b01f10801ded14ff0000b0e9822eae27e00eb0b0cc445c146b8bfe146ce4551da5feace700ad0289b4fea5e00195c299a01f0f00111430ef1010e19544fea5e07b7eb590f18d228982a9b0b9d00eb5906d919084600f8015bb04213d28a1cb242057024d2c81cb04215701fd20433da19b2420570ecd31ae0289800eb5e0216e0481c02e04a1c12e030465feaca710ad0d44508d201780c9a01f00f011143ddf88ce0017067e0ddf88ce064e002465feac97007d0ce4505d210780c9900f00f000843107027996fea0b000e18012001902898229f414662463346cdf860b0009701f0d0ff26eae67cc245a8bfc246d4453dda5feacc700ad0289b4fea5c00195c299a01f0f00111430cf1010c19544fea5c02b2eb5a0f18d228982a9f0b9d00eb5a03b818064606f8015b9e4211d2811c9942357010d2c61c9e420d700bd20437b91899423570ecd306e0289800eb5c0102e0411c00e031465feaca7007d0d44505d208780c9a00f00f0010430870ddf88ce04ff0000b2498209eddf84c90199df6e5abf1010b40e7abf1020b3de7abf1030b3ae7013e00f0b78117f8010b411e1f29f7d341b220290fdb08eb400118f81000497840ea0122c12a06d3dde9231036ab00f053fa0028e4d14ff0ff342746fef75fbc2f46fef75cbc209f1e9eb74204dd012710e01f46fef753bc209f1e9e9042a7eb0607b7fa87f74fea57174ff00006c8bf01263740ddf84ce0bef1000f169700f0768154084ff0040c12942cea82041194d41803eb000a013c00f001050af00106670810972cea8407ac190f971f1bdde9223405eb000c1c445319424040080e904fea5a000d9004eb0900ddf890907908484538bf81460120cdf890901791012988bf780800f0030120f0030b58081b9008eb530009904fea5c0019902b984ff0000900eb5c0001300890d00718904198ddf858c029904ff0ff3000eb57000b90c7f341000a906ff0010000eb570007906ff0020000eb57000c9115970690cde9226507e0249809f1010981454ff000073ef4d6ab6fea09014846bcf1000f18bf0eeb01001e9900eb0102299902fb01810db9002305e0129b119ccb5ce34003f00f0328930eb9002304e0109b0f9ccb5ce3401b012793209b189c0344dde92a70002c03fb070a19981b9c504421441fd1179af4f71fffddf858c0ddf84ce0239d45b10e99289a1af8010000f0f00010440af80100229e1a9a002eb3d00d99279b1af8010000f00f0018430af80100a9e7299cbcf1000f04fb02f25bd0159b022bddd30a9b002b179b23d0179b0b9dcb5c4c5dc3f3031343ea041343550a9b012b2b4616d00b9b079dcb5c4c5dc3f3031343ea041343550a9b022b2b4609d0079b069ccb5c095dc3f3031343ea0111234601550b990329b2d309991144ca18cc5c12f8016cc4f3031444ea0616c41804f8016c12f8016c12f8025cc6f3031646ea051604f8026c12f8026c12f8035cc6f3031646ea051604f8036c12f8036c12f8042cc6f30316043b46ea021204f8042cd4d184e7159c022cfff481af159f082f01d200222ce02a9f03fb07f4099b03eb020c089a144400220ceb020675781cf80270c5f3031545ea0717a51805f8017cb7787378c7f3031747ea0313a354f378b778c3f3031343ea07136b703379f7780432c3f3031343ea07139345ab70dbd10c9bddf858c0002b3ff449af531ccf5c8e5c0c9cc7f3031747ea0617012c87543ff43daf941c0f5dce5c0c9dc7f3031747ea0617022dc7543ff431af0a44d278095dc2f3031242ea0111015527e70027fef7c5ba22983e9f20eae070279005e020440b38baf1010a044648d01bf8010b1f28f5d908eb400118f81000497840ea0122c12afff447aedde9231036ab00f093f800283ff43fae2098ddf8a490049032a8039036a80290dde92a60229d289932464b460195009401f054f8dde93801334620444a19b04224eae471b8bf03464a45a8bf4a468b42c4dd279eb242c1dd0f2fbfd8279d149c521b5b1a04ebc70624f8371001377580b380f280b2e700240be64ff0ff300df2f44dbde8f08fa01a18bf4ff0ff300df2f44dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf2de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041ffe78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f91b00df1700b9be8400a10913169ddf868a0002900f05c813768bbf1000f40f05181874200f04e8199f80f100f2940f0498199f80e100e2940f0448199f80d100d2940f03f8199f80c100c2940f03a8199f80b100b2940f0358199f80a100a2940f0308199f80910092940f02b8199f80810082940f0268199f80710072940f0218199f80610062940f01c8199f80510052940f0178199f80410042940f0128199f80310032940f00d8199f80210022940f0088199f80110012940f0038199f80010002940f0fe80ddf86cc0caf10001d6f808e001eaea75ccf10001f76801eaec740895aeeb05062aeaea75391b2ceaec77521b9642a3eb07030d97b8bf32469942b8bf0b46012a0e930992c0f2ea820e990129c0f2e6820ef10101a4464c08089900eb55000c9048100b90042020ea81000790099801310138cde905014810049004fb0cf000f102094ff0000a0a94cde901c507e000bf0e980af1010a8245a14400f0bf821c98109bd0f800e00aeb0c0000fb04e20d980c9e504400fb0360eb0703d10b9edde9083810e00b9b2f46d35c079d0678eb4006f0f00603f00f03334400f8013b069bdde904683d469119da074fea58070f9208d13a468b466446f3f788fca4460a9c68e000bf8b46b8f1020f63d37a1e032a04d2002117f0030237d15be06ff0030202ea58034e44c3f1000c0eeb0601461c039700bf8d18ef78ac78c7f3031747ea0417b418e7702f79eb78c7f3031747ea031323716b792f79c3f3031343ea07136371ab796f79c3f30313043243ea07130ceb02070437a371dcd1dde901c50a9c039f111d17f0030224d04b1cbe461bf803701bf80160c7f3031747ea0617012a4754774616d08e1c1bf806701bf80350c7f3031747ea0517029d022ac754774608d05944c9781bf80620c1f3031141ea021181555feac8713ff45aaf0f9a1bf80710002a4ff0000208bf0422c35dd14003f00f0242ea0111c15549e7874200f09f815c460021aae17568002d00f0068200214ff0000e09e0dde90e71d8f804503944dde91d9ba94280f0f881ddf870800f91d8f80060775c3c0901d0012117e06d1a012d00f0ea8106eb010c9cf8016016b1344602210be0042dc0f0df819cf802509cf8036055ea062400f0d781042117f00f07bbfa8bf60e914fea561619f807b018bf012746ea07091b9f4fea0b1c14f00301754600f09980d8f808504ff00008befbf5f60d9106fb15e55544b5f1ff3fc8bf4ff0010809ea080101291ad1f61918d4954216d29e4214d210990b9406fb01046e08a15ded070c916ff00f05594604bf0f256146ddf8308005ea08052943a1550b9c0d99ddf8708001290ef1010563d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080b91895ded070c916ff00f05594604bf0f256146ddf8308005ea080529430b9dddf87080a9550d990ef10205022930d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080c91895ded070d916ff00f05594604bf0f256146ddf8348005ea080529430c9dddf87080a9550ef1030500bf611e0329a64405d220e700bf0435ae453ff41cafd8f808100024b5fbf1f606fb11515144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f808106c1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ac1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ec1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c7ff46aaff6193ff567af9142bff464af9e42bff461af109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa1554be71b995c46002901dd012108e0b1fa81f149090027baf1000fc8bf01273940d6f808e0f76807fb0ef8b8f1000f56d0b4fa84f4bb4600274ff0ff3c6409c9070e940f9106e001370bfb0ef84745acf1010c44d20f990ef101050029394618bf08eb0c01b1fbfef46d0804fb1e161c99096804fb05117508495d042525ea8605e94011f00f08454618bf01250e990d43012dd8d116eb0a065cbf1b9d14eb0504d1d49642cfd29c42cdd2109d19f8081004fb050e74081ef80450f60705f00f0805f0f00545ea010508bf48ea01151c990ef80450d1f808e0d1f80cb0b3e711b0bde8f08f00bf2de9f04fc8b0dde95162549f1644ba1926eae6778a42b8bf11468f42039080f203815698cde90071a0f1030a6ff007076ff004044ff0000b0df1200e4ff000090293cdf810a000bf56984fea5903c05c4ff0100c00f0f0080590cde9064700bf1af8041f0eeb07001af8012c9af8013048ea121602f00f0242ea0802427248ea111201f00f01827241ea08010eeb0402117248ea13119af802500672517203f00f0141ea0801917248ea1511817305f00f0141ea08010837bcf1080c04f10804c173cdd10598ddf810a00401102753465d4600bf13f8040f0eeb050213f8011c5e7844ea111801f00f012143517444ea101100f00f002043d07444ea161093f802c0107506f00f002043507544ea1c1090750cf00f002043083f05f1080582f810809174d075d5d1079f069c09f1020920372034b9f1100f0bf1200b84d15598029bdde90086539900286dd00844079008f10100069003984fea580a03fb01074fea660c4feac87b06e000bf079809f1010181421f4457d20398894601fb0301bbf1000f45460bd011f80a00069d1ef8002000f0f00002f00f02104401f80a00bceb550f28dd680801eb0c033e4600bf315c06eb00081ef80120414601f8012b99421ed20a7808f102041ef802209c420a7018d221781ef80110217008f103049c4210d2217804361ef80110217034189c42ddd307e000bf01eb5504f00707d1b4e708f10104029bdde90086f007add0b542abda20781ef8001000f00f0001f0f00108442070a1e748b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fcf726f869680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae722eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae72de9f04f81b04ef66c6b4ff29c554ff64c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f02d10168594545d04ff46d70f9f7eafc002800f0b980414642180c3182f8b47382f8b57382f8b67382f8b77382f8b87382f8b97382f8ba7382f8bb7382f8bc7382f8bd7382f8be7382f8bf73e4d1c0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa142b2d1bff35f8f00bf45e8000121b155e8001fa142f8d0a7e70446d0f8780210b101b0bde8f08f4ff41630f7f77bfc00284ff000016ad00022831881544032b2f5163f59709970d970197159719971d971197259729972d972197359739973d973197459749974d974197559759975d975197659769976d976197759779977d97783f8201083f8211083f8221083f8231083f8241083f8251083f8261083f8271083f8281083f8291083f82a1083f82b1083f82c1083f82d1083f82e1083f82f1083f8301083f8311083f8321083f8331083f8341083f8351083f8361083f8371083f8381083f8391083f83a1083f83b1083f83c1083f83d1083f83e1083f83f109ad1c4f8780201b0bde8f08f002001b0bde8f08f70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f8f722fde0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f7f78ef902a9284600224ff0000afbf73ffc81464046f7f753fab9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f2f70ffc06f1210506f1280029460722f2f707fc284621460722f2f702fc20465146032207f10905f2f7fbfb06f11d0049460422f2f7f5fbf07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f2f7c9fba81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f2f78ffb012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f2f776fb572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f2f75ffb312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f2f749fb462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f2f732fb362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f2f7c7facde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f2f7a8fa8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f2f7a9f9284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f2f755f9002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f2f723f904a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f2f70ff90020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f2f7f8f8352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f2f7d4f804a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f2f7c1f8002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f2f7adf804a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f2f789f804f14f0051460722f2f783f884f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f1f7f5ff84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f1f70bff284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f7f747fe0028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3239000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", + "new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc1b04ff62c484ef66c694ff29c5b1446cff6ff78ccf2ff09c2f2290b4ff6ff75002701260993cde90a0106e048f2a351c0f24501bff32f8f8847dbf800a0bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0b8fa002800f0078241464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001f51457ff436afbff35f8f4be8000121b15be8001f5145f8d02be70b99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847dbf80070bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0dcf9002800f02b8141464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb9427ff436afbff35f8f4be8000121b15be8001fb942f8d02be7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f09d810b98002861d00a980778a7f1170002285bd80b980c2840f086810a9e7078b178084300f08081f0780138022800f27b81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f01082172f40f02682002a40f06281fe2800f06d86812800f06086002840f0738651ea030040f0558100f0bdbe04460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0f58051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0e480824692e74ff0ff3737e147f6df40c0f24f008047002701240d97adf8387006e048f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0c1804ff4757007f082f8002800f0b98041464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009084728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff436afbff35f8f4be8000159b15be8001fb142f8d02be706f5a9718847ace6012110e700200a9999b10b9a8ab1097801f07f02b2f10b0618bf0126b2f11c0718bf01278a2924dc0b2926d01c2924d03fe009900ca804f0a9fa4ff0ff3701249df8390000280ca818bf4ff0ff3704f0e5fb054644b99df8380028b94af21f30c0f247004c3080470998002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010446884794f8641119b994f80413204669b14ff0ff3742f6f760c0f2440000f5807150468847384641b0bde8f08f09900ca806ea070404f067fa0a98017801f07f061e2e04d10b9908f088fb0746b5e71d2e01f07e0018bf1a2811d1dbf800100322cff680720a40b2f1005fbff35f8f0ad10a684a4504bf002281f8812303e0a6f115010129e9d90f2e0adc092e00f37381052e00f0ef82072e40f01c8300279ae0142e00f32182102e00f0eb82112e40f011830b98022841f0c6800a990878112841f0c1804878002841f0bd8045f64d50c0f24600804701284ff000077ff46daf40f20830c0f210003190ff208df8c00044f25220c0f201002f9040f2c960c0f24800cde93277804798b148f27e30c2f2070000880122c1b264298df8bf2008d80721b0f5807f38bf03218df8bf108df8c00040f2d260adf8c800052031ae8df8ca00f01d2fa90522fff7dbfa4ff22507c0f247070120092132460c23b84774e700294ff0ff3708bf002b7ff453af1328bff450af102a4ff0000138bf01211228b2fa82f218bf510901297ff443af00f0a9bc182f4ff0ff3708bf00297ff43aaf002b7ff437af352800f32c84002800f08184012800f08d84312840f07f84082abff428af00f08ebc48f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f00f864ff4757006f083fe002800f0078641464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470af0121c0f8009081728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff435afbff35f8f4be80001002900f057855be8001fb142f6d028e70a2e00f088810b2e40f0a981dbf800500320cff680702840b0f1005fbff35f8f40f0f9872868002748457ff40baed5f8700342f68d48c0f244080028a5f8807318bfc0470021a5f8b013c5f8ac13c5f8681185f8661185f86411d5f86c01c5f8601185f86511c5f86c11c5f80013a5f86c1320b148f2a351c0f245018847d5f87802002818bf04f04dfb0026c5f87862d5f8680320b148f2a351c0f245018847c5f86863a5f86c63286ca5f8446040b1c047286c08f166018847002804bf002028644bf63940c0f251008047dbf800700320cff680703840b0f1005fbff35f8f2ed1386848452bd197f877010026c7f8806188b149f25962c0f25902002044f2436187f8776190474ef6e378c0f25a08c04708f1bc008047d7f8840142f68d48c0f2440887f8706150b1c047d7f8840108f166018847002804bf0020c7f88401dbf800000321cff680710140b1f1005fbff35f8f40f040860168494540f03c8690f8a811002900f0318607f097f800f033be152e00f0ec80162e40f0f0800b9801380228c0f0a4860a9a4ff0ff375078917840ea0120b0f5007f3ff653ad03210b9b01eb400199427ff44cad002700288df8c4708df8c5708df8c6708df8c7708df8c8708df8c9708df8ca708df8cb708df8cc708df8cd708df8ce708df8cf708df8d0708df8d1708df8d2708df8d3708df8d4708df8d5708df8d6708df8d7708df8d8708df8d9708df8da708df8db708df8dc708df8dd708df8de708df8df708df8e0708df8e1708df8e2708df8e3708df8e4708df8e5708df8e6708df8e7708df8e8708df8e9708df8ea708df8eb708df8ec708df8ed708df8ee708df8ef708df8f0708df8f1708df8f2708df8f3708df8f4708df8f5708df8f6708df8f7708df8f8708df8f9708df8fa708df8fb708df8fc708df8fd708df8fe708df8ff708df800718df801718df802718df803713ff4c8acd11c31ae012208944b78012b00f206860f7847ea0323db08f45c07f0070702fa07f7274240f0f784f45c013847ea0407f754089c01f10201e6d105f0d9fc002800f0e984002700f017bc0b980894022835d30a98407833e0dde90a0107f0d6f8dee40b980228c0f0d98500f091fe002800f0d4850a994d78002d00f09f83022d00f2cc8540f0458601460b982646062880f032854ff0ff37344679e40a980b990130013908f09af8bae41d2e40f029810a980b990130013908f0a4fdb0e4ff2000270124079006e048f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757006f0eefb002800f06b8341464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009084728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff436afbff35f8f4be8000121b15be8001fb142f8d02be790f84410ddf82880dde9076461b1016c39b142f68d42c0f244020546084690472846002180f8441001210b9a032a0ed36eb998f80200082800f25b854bf63941c0f25101963188470027fff769bb0b9a052ac0f0d780012e40f0d48098f802000027411e06293ff65bab98f8031003293ff656ab98f80420002a3ff451ab4bf63943c0f2510303f59a7398470027fff747bb1a2818bf1c2e40f0888405f070fb002800f0838400f03bfd814608f08cffb9f1000f4ff0ff3718bf00283ff430ab804647f63400c2f20700d0f81806d9f874131b2ea0eb0100c9f87c0300f04a841a2e40f067840a9900254f1c0b994ff4f072a1f1010b4ff4a0714ff48053cde9375031a84ff42076cde931350590cde90121484639465a4643463995cde90355009609f0c3fa002840f040844ff48050cde93105d9f87c033946cde9380531a805900120cde903504ff4a07002904ff4f070019048465a4643464ff420773795009709f0a3fafff723bb36286dd0462868d0572855d1002e7ff4ffaa65e00c294ff0ff377ff4f9aab3f5005f5dd3fff7f4ba481e1f284ff0ff373ff6eeaac1f51630834251d9fff7e8ba002b7ff4e3aa421f18bf0122b0f1350318bf01231a40b0f1590318bf01231a40b0f1470318bf0123134208bf012937d0b0f1370218bf0122b0f1c10318bf01231a4208bf02292bd09f284ff0ff377ff4bfaa042924d0fff7bbba022e40f062814bf63940c0f2510080470027fff783ba022abff4adaa13e0002a7ff4a9aaa0f1fd0102290cd397287ff4a2aa08e06ff0780002427ff49caa02e0402abff498aa45f64d50c0f2460080470a990128c9784ff001004ff0010408bf022008424ff0000708d1fff784ba48f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757006f0e1f900283ff461aa41464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009084728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff436afbff35f8f4be8000121b15be8001fb142f8d02be74af21f36c0f247060546b04795f8640100287ff4a3a995f80403294600287ff49da90a98007817281bd0d1f8640342f68d47c0f2440768b947f63720c0f20000a7f594747844012100220023a047c5f8640340b3a7f140024ff47a719047294608bb01f206300c460a990c22fef7effc0998002184f805030120bff35f8f84f804034ff4f07001904ff4207006f5106400900020002200230027a04700283ff45fa985f8047306f14c0080474ff0ff37fff756b90b9a072ac0f06d81032e40f06a8198f8020098f8032098f8041040ea022098f8055098f8067001284ff0010698bf304644f62062904228bf10464bf63942c0f2510202f5e272642928bf6421904747f63400c2f207000068002800f0e38245ea0721012988bf0e4642f68d41c0f24401a1f14002314690470027fff7eab8002780f8437145f64d50c0f24600804701287ff4dfa843f2a310c0f256008047fff720b9ddf82880dde907640021002055e500200b9902290a992cbf4978ff21002800f0b08202294ff000072cd0012926d000297ff4bea84cf67e21caf2101187760783cbf80410078147608583c583058445848584c584058545858585c585058645868586c5860587458780f83c7080f8b17380f8b073c0f8ac73fff79ab801218172fff796b88772fff793b848f2a351c0f24501bff32f8f8847dbf80040bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f007814ff4757006f01df8002800f0b58041464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470af0121c0f8009081728583c583058445848584c584058545858585c585058645868586c586058745875be8001fa1427ff435afbff35f8f4be8000100294fd05be8001fa142f7d029e7089c4ff0ff37fef7b8bf80460b98a14603284ff000073bd3301fb0fa80f04009084035d00b980a9a4cf6cd410338ccf6cc419478a0fb0101b4eb910f88bf8c082646302c28bf302608f14600d11c06eb8602fef736fb002788f8446088f84570b4b1d8f8400038b9404600f0c6fa0028c8f8400000f0768142f68d41c0f24401a1f140020121904700274c46fef775bf4c46fef772bfd0f86c110027002900f058814ff400624ff0ff3cb64605e02b681a44b2f5403f80f0c0808d18ab68b7eb532ff4d1dc081ef8044003f0070624fa06f6f6071ebf41f82370c5f808c0ef60e5e70a9fb878fa783b797f7940ea022043ea072232283190329280f0f5803220f9e090f8a911002918bf06f062fadbf800000321cff680710140b1f1005fbff35f8f1cd10168494519d1d0f8b813b1b14ff00041bff35f8fc0f8b4134af21f30c0f2470000f510674ff4f07001904ff4207600200021002200230096b84795f84301002685f8436158b145f64d50c0f246008047012804d143f2a310c0f256008047d5f83c0195f84271c5f8386185f84261a5f8406150b1c047d5f83c0108f166018847002804bf0020c5f83c010120002fa87200f0ca804af27366c0f246060021002200230027b047fef7d6be0b9803287ef4d2ae0a994ff4f07748788978424640ea01260020cde902004ff4a0700190484631464ff42073009708f079fc002800f0a9804ff0ff37fef7b6be0b9801287ef4b2ae09f57170bff35f8f50e8001f013140e80012002af8d10da94846012208f08cfcfef7e8be4ff0000c4ff400634ff0000ec0f800c30de0bef1000fc7f804c00cbfc0f80033cef804303344b3f5403fbe463bd2cf18ba68ce58013201d07746f3e7f218140c022ce6d88d18ac680134e2d12c6826443e602c682244140c022cdad88d18ac680134d6d12c6826443e602c682244140c022cced88d18ac680134cad12c6826443e602c682244140c022cc2d88d18ac680134bed12c6826443e602c682244b2f5403fcfd3b5e7089c0027fef749beb0f5fa6f0846344604d94ff4fa603190084634460121064680f8431145f64d50c0f24600804701281cd143f2a318c0f25608a8f188008047022d074608bf002f01d057b90ee04bf2110231a9c0f24b020220904730b10746c047002086f84301fef717be0027fef714be089cfef711be701ca9f86c030027fef70bbe4bf639400027c0f2510088f8447080474c46fef700be2de9f04f81b04ef66c6b4ff29c554ff62c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0be804ff4757005f077fd002800f0b680414600bf4218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff43bafbff35f8f00bf45e8000129b155e8001fa142f8d02fe7002001b0bde8f08f70b500284dd001684ef66c62ccf2ff02914218bf70bd90f8441090f845504bf6394c8d42c0f2510c2ad205eb8501014491f8492091f84a4091f846e091f8473091f8481042ea0424012c4ff0010298bf14466e1c054680f84560b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f84410bde870406047e047286c38b142f64d42c0f244022146bde87040104770bd02464ff64b70cff6ff7042f6653c7844c0f2440c00210023604700bf2de9f04fcfb04ff29c57c2f229073c68032620464ef66c6b6ff39600cff68076ccf2ff0bb0f1005fbff35f8f40f0e5812068584540f0e18194f8510347f64c69c2f2070904f5417530b347f61800c2f20700016d4bf67c52c0f2720291421bd1406cc8b1d4f85c03d9f80010401a012802db04f0a7fc78b92846b8460df022fa50b142f69570c0f25b0080474746002084f8520384f8510394f8500370b1d4f86003d9f80010401a012802db04f08afc20b9002084f8500384f866012878bff35f8f70b194f84f83cc46b8f1000f01951cd094f8050394f81e13091a18bf012115e094f85103002840f0878194f85003002840f08281d4f86403002800f07d8142f68d41c0f24401884776e1012194f8070394f81133069094f8080394f81d23079094f8065394f80a0394f80b9394f80ce394f80db394f80ea394f80f63934235d194f8102394f81c339a422fd194f81b2396422bd194f81a23924527d194f81923934523d194f8182396451fd194f8172391451bd194f81623904217d194f8092394f815339a4211d194f81423079b93420cd194f81323069b934207d194f81223954203d111b994f805b3a9e00023012284f8203384f8233384f8243384f8253384f8263384f8273384f8283384f8293384f82a3384f82b3384f82c3384f82d3384f82e3384f82f3384f8303384f8313384f8323384f8333384f8343384f8353384f8363384f8373384f8383384f8393384f83a3384f83b3384f83c3384f83d3384f83e3384f83f3384f8403384f8413384f8423384f8433384f8443384f8453384f8463384f8473384f8483384f8493384f84a3384f84b3384f84c3384f84d3384f84e3384f81f2384f8215384f82203dcf8002047f61803170a84f8232384f82473170c120e84f826230822c2f2070384f8257384f84f231a6d4bf67c57c0f2720704f20631ba4204f212381bd15a6ccab140f6b803c2f200031a689ab1182d00f04884172d40f05484fe2804f2273c0d4600f07584002840f07f8401980df0a2f9294602e0022084f8200340460c22fdf7dbfe94f805b394f84f8384f81eb345f64d50c0f246008047811eb1fa81f14fea511a012808bf4ff0020ab8f1000f5ad004f21f3009a9059040f261400631c0f2470004910ca9023100254ff00309a0f5b84000240391029015e000bf039809a91a468df830908df831b0fdf7a5fe47f00802029ff0200ca90023b8470334e0b24045b1462fd2a8eb0400c7b20420032f28bf4f468df8240006983a468df8250007988df827a08df8260005988df8284050fa84f104988df829808df82a508df82b508df82c50fdf777feb81dda45c3b24ff00306c2d14ef60b670120f02109aac0f24707c9e7bff35f8f01994ff29c574ef66c6b03260020c2f22907ccf2ff0bcff6807608703d68bff35f8f05ea0600b0f1005f57d12868584554d105f56d700021bff35f8f00bf50e8004f40e80012002af9d147f64c60bff35f8fc2f20700d0f800a0b4f1004f0fd0b84604f0c0fa58b1002c00f0668195f8cc03220a002800f0fc8195f8cd1305e295f8cc03e8b147f61800c2f207000068b8b145f60960c2f207000478002040f261430c9009900ca909aac0f247032046984709990c9a43f69b53c0f24e0320469847002085f8ce0385f8cc03d5f8b80320b142f68d41c0f244018847d7f80080bff35f8f08ea0600b0f1005f44d1d8f80000584540d198f8500338b1002088f86401c8f860014fb0bde8f08f98f8640100b3d8f86041ecb140f6b800c2f20000056808a802f0d5fc002d00f014834ff62c49284621464ff41632b2465e46cff6ff794ff6ff770795fdf7c1fd00244ff0010b20e098f8660170b1d8f8680140b147f64c61c2f207010968401a002802f3a684002088f8660140f6a120c0f2470080474fb0bde8f08f48f2a351c0f24501bff32f8f88474ff29c50c2f229000568bff35f8f0068bff35f8f00ea0a01b1f1005f03d10168b14200f0c5804ff4757005f089f9002802f06284494600bf4218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470af4ff29c52066080f80ab08783c783078447848784c784078547858785c785078647868786c78607874787c2f2290252e8001fa9427ff431afbff35f8f42e8000151b152e8001fa942f8d026e795f8cc03002840f0db80cae6817a002942f0a083027e0021002a8df8301000f031824ff29c550caac2f22905535c002b00f09b8253185f78002f00f059829f78002f00f05782df78002f00f055821f79002f00f053825f79002f00f051829f79002f00f04f82df79002f00f04d821f7a002f00f04b825f7a002f00f049829f7a002f00f04782df7a002f00f045821f7b002f00f043825f7b002f00f041829f7b002f00f03f82df7b002f00f03d821f7c002f00f03b825f7c002f00f039829f7c002f00f03782df7c002f00f035821f7d002f00f033825f7d002f00f031829f7d002f00f02f82df7d002f00f02d821f7e002f00f02b825f7e002f00f029829f7e002f00f02782df7e002f00f025821f7f002f00f023825f7f002f00f021829f7f002f00f01f82db7f002b00f01d82203160297ff47baf3ce20120a5f8cc0340f20220a5f8d0030220002185f8cf03c5f8c01302f00103c4f300208b42c4f34b2206d123b395f8d233e7b2bb421fd00ce05bb995f8cf13a5f8ca2385f8d013022185f8d113c5f8bca311e095f8cf3385f8d03385f8d143a5f8ca23c5f8bca331b9012185f8ce13c4f34951a5f8c813002804bf002185f8ce1385f8cd0385f8d24395f8ce13b9b195f8640160b1d5f8c403bff35f8fb5f8c8136ff39f20884205d195f8ce1339b195f8cf9331e0002085f8ce03c5f8bca3d5f8bc13b5f8ca0395f8d193aaeb0101814221d28902b1fbf0f04ff4406395f8d01300fb00f2a3eb40005043000da9eb010200fb02f34ff62c47002b4ff40073cff6ff7748bf07f5ea7310fb0230c21700eb925001eb9029002147f61800c2f20700006848b395f8cf035ffa89f4844207d1d5f8c00320b1aaeb0000b0f57a7f1bd3002040f261430c9009900ca909aac0f247032046984709990c9a43f69b53c0f24e0320469847baf1010f98bf4ff0010ac5f8c0a395f8ce13d5f8b80385f8cf9311b14ff47a7109e095f8d1135ffa89f28a424ff0280108bf4ff47a7142f68d42c0f24402403a904795f8ce034746a0b13868bff35f8f00ea0601b1f1005f42f045820168594542f04182002180f86411c0f860114fb0bde8f08f95f8cd0300287ff443ad5ffa89f00228e1d140f6b800c2f2000001680029dad001684ff416322139002301f8403f403a01f81f3c01f81e3c01f81d3c01f81c3c01f81b3c01f81a3c01f8193c01f8183c01f8173c01f8163c01f8153c01f8143c01f8133c01f8123c01f8113c01f8103c01f80f3c01f80e3c01f80d3c01f80c3c01f80b3c01f80a3c01f8093c01f8083c01f8073c01f8063c01f8053c01f8043c01f8033c01f8023c01f8013c4b708b70cb700b714b718b71cb710b724b728b72cb720b734b738b73cb730b744b748b74cb740b754b758b75cb750b764b768b76cb760b774b778b77cb7781f820309cd100684ef217310c904ff416300d900ca8c0f247018847474665e7002088f86401c8f8600188f86601012088f8650140f6a120c0f24700804702f09eb901980d460cf0c9fe10b302304ff0030008bf022084f820032946fff7bdbb84f85003dcf800204ef660231a44c4f86023b8b101980d460df08ef80df062f8294660b9fff7a9bb4ff29c55c2f2290595e00df057f8002829463ff49eab0320fff799bb002084f86601fff796bb18684a4600eb0b20704400eb0a4000eb06616046fdf769fa0ee04eea0b2141ea0a4141ea066361464a460cf056fe00281cbf032084f8200309f1080084f84f032946fff773bb01313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2921d84ff0520353541dd00a4445235e29537018d04f235d29937014d052235c29d37010d044235b2913710cd045235a29537108d052235929937104d020235829d37141f0058600218df88f100121427e002a00f0c28000220cab9f5c002f00f0a0809f187e78002e5ed0be78002e5dd0fe78002e5cd03e79002e5bd07e79002e5ad0be79002e59d0fe79002e58d03e7a002e57d07e7a002e56d0be7a002e55d0fe7a002e54d03e7b002e53d07e7b002e52d0be7b002e51d0fe7b002e50d03e7c002e4fd07e7c002e4ed0be7c002e4dd0fe7c002e4cd03e7d002e4bd07e7d002e4ad0be7d002e49d0fe7d002e48d03e7e002e47d07e7e002e46d0be7e002e45d0fe7e002e44d03e7f002e43d07e7f002e42d0be7f002e41d0ff7f002f40d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff053079f5411d013444b275e2a5f700cd049275d2a9f7008d050275c2adf7004d020275b2a1f7140f0f08100228df88f200131827e002a00f0be8000210caa535c002b00f0a08053185f78002f5ed09f78002f5dd0df78002f5cd01f79002f5bd05f79002f5ad09f79002f59d0df79002f58d01f7a002f57d05f7a002f56d09f7a002f55d0df7a002f54d01f7b002f53d05f7b002f52d09f7b002f51d0df7b002f50d01f7c002f4fd05f7c002f4ed09f7c002f4dd0df7c002f4cd01f7d002f4bd05f7d002f4ad09f7d002f49d0df7d002f48d01f7e002f47d05f7e002f46d09f7e002f45d0df7e002f44d01f7f002f43d05f7f002f42d09f7f002f41d0db7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f0098100218df88f1001216a6846f23f53c5f28803b3eb520f40f08b80d20700f08d8000210caa535c002b00f0858153185f78002f00f0f9809f78002f00f0f980df78002f00f0f9801f79002f00f0f9805f79002f00f0f9809f79002f00f0f980df79002f00f0f9801f7a002f00f0fc805f7a002f00f0fc809f7a002f00f0fc80df7a002f00f0fc801f7b002f00f0fc805f7b002f00f0fc809f7b002f00f0fc80df7b002f00f0fc801f7c002f00f0fc805f7c002f00f0fc809f7c002f00f0fc80df7c002f00f0fc801f7d002f00f0fc805f7d002f00f0fc809f7d002f00f0fc80df7d002f00f0fc801f7e002f00f0fc805f7e002f00f0fc809f7e002f00f0fc80df7e002f00f0fc801f7f002f00f00d815f7f002f00f00b819f7f002f00f00981db7f002b00f00781203160297ff47baf1de14cf67e22caf210126a60002940f0198100210caa535c002b00f0dc8053185f78002f61d09f78002f60d0df78002f5fd01f79002f5ed05f79002f5fd09f79002f60d0df79002f61d01f7a002f62d05f7a002f63d09f7a002f64d0df7a002f68d01f7b002f69d05f7b002f6ad09f7b002f6bd0df7b002f6cd01f7c002f6dd05f7c002f6ed09f7c002f6fd0df7c002f70d01f7d002f71d05f7d002f72d09f7d002f73d0df7d002f74d01f7e002f75d05f7e002f76d09f7e002f77d0df7e002f78d01f7f002f79d05f7f002f7ad09f7f002f7bd0db7f002b7cd0203160297ff49aaface000211171f6e6013173e0023171e003316fe004316de0013184e0053169e0023180e0063165e003317ce0073161e0043178e008315de0053174e0093159e0063170e00a3155e007316ce000225a710fe60b314ee0083165e00c314ae0093161e00d3146e00a315de00e3142e00b3159e00f313ee00c3155e010313ae00d3151e0113136e00e314de0123132e00f3149e013312ee0103145e014312ae0113141e0153126e012313de0163122e0133139e017311ee0143135e018311ae0153131e0193116e016312de01a3112e0173129e01b310ee0183125e01c310ae0193121e01d3106e01a311de01e3102e01b3119e01f315f2931d84ff04f0353542dd00a444b235e29537028d020235d29937024d00021d17024e01c3104e01d3102e01e3100e01f315f2918d84ff04103535414d00a444c235e2953700fd05d2993700cd04f235c29d37008d043235b29137104d020235a29537141f0c38200218df88f1000210caf7a5c002a00f0a0807a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b59d0d379002b58d0137a002b57d0537a002b56d0937a002b55d0d37a002b54d0137b002b53d0537b002b52d0937b002b51d0d37b002b50d0137c002b4fd0537c002b4ed0937c002b4dd0d37c002b4cd0137d002b4bd0537d002b4ad0937d002b49d0d37d002b48d0137e002b47d0537e002b46d0937e002b45d0d37e002b44d0137f002b43d0537f002b42d0937f002b41d0d27f002a40d0203160297ff49aaf42e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2903d84ff077027a5403d100218df88f1002e0394400224a70c2684ff0000e17f80e10002900f0c48007eb0e035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00ef1200ebef1600f7ff496af4ff0600e5be00ef1010e58e00ef1020e55e00ef1030e52e00ef1040e4fe00ef1050e4ce00ef1060e49e00ef1070e46e00ef1080e43e00ef1090e40e00ef10a0e3de00ef10b0e3ae00ef10c0e37e00ef10d0e34e00ef10e0e31e00ef10f0e2ee00ef1100e2be00ef1110e28e00ef1120e25e00ef1130e22e00ef1140e1fe00ef1150e1ce00ef1160e19e00ef1170e16e00ef1180e13e00ef1190e10e00ef11a0e0de00ef11b0e0ae00ef11c0e07e00ef11d0e04e00ef11e0e01e00ef11f0e01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46f346bef15f0f98bf4ff05f0bcbf1000a0cad1aeb0e0c53d0b2fbf3f60a2b06f1300105f80e104cf6cd41ccf6cc41a3fb011447d31cf1010142d006fb1326e708b6fbf7f905eb0e0209f13001517048f21f51c5f2eb11642ba3fb011435d31cf102012dd009fb17666709b6fbf7f4b3f57a7f04f13001917044f6d351c1f26201a3fb015124d31cf1030524d004fb1767890941f25975b7fbf1f6cdf2b715a3fb055406f13005d57006fb117242f210710ef1040e8b424fea54330cada9d20ce0de460ae00ef1010e07e00ef1020e04e00ef1030e00e0de460cad002205f80e20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf50e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a11d84ff07501a9540dd0a91873235e2a4b7008d020235d2a8b7004d070235c2acb7040f09d8000218df88f1002694ff0000a15f80a10002900f0c78005eb0a035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002965d0197c002965d0597c002965d0997c002965d0d97c002965d0197d002965d0597d002965d0997d002965d0d97d002965d0197e002965d0597e002965d0997e002965d0d97e002965d0197f002965d0597f002965d0997f002965d0d97f002965d00af1200abaf1600f7ff496af4ff0600a5ee00af1010a5be00af1020a58e00af1030a55e00af1040a52e00af1050a4fe00af1060a4ce00af1070a49e00af1080a46e00af1090a43e00af10a0a40e00af10b0a3de00af10c0a3ae00af10d0a37e00af10e0a34e000220a7162e70af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46d646baf15f0f98bf4ff05f0ecef1000942f2107c0cad19eb0a0b51d0b2fbf3f40a2b04f1300105f80a104cf6cd41ccf6cc41a3fb011747d31bf1010140d004fb1326ff08b6fbf7f405eb0a0204f13001517048f21f51c5f2eb11642ba3fb015135d31bf102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31bf1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb11420af1040a63454fea57330cadabd20ce0f2460ae0f24607e00af1010a05e00af1020a01e00af1030a0cad002205f80a20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf5ce001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a1dd84ff07501a95419d0a91873235e2a4b7014d020235d2a8b7010d074235c2acb700cd031235b2a0b7108d030235a2a4b7104d02023592a8b7140f0cb8500218df88f10d0f8ac234ff0000a15f80a10002900f0c48005eb0a035978002962d09978002962d0d978002962d01979002962d05979002962d09979002962d0d979002962d0197a002962d0597a002962d0997a002962d0d97a002962d0197b002962d0597b002962d0997b002962d0d97b002962d0197c002962d0597c002962d0997c002962d0d97c002962d0197d002962d0597d002962d0997d002962d0d97d002962d0197e002962d0597e002962d0997e002962d0d97e002962d0197f002962d0597f002962d0997f002962d0d97f002962d00af1200abaf1600f7ff496af4ff0600a5be00af1010a58e00af1020a55e00af1030a52e00af1040a4fe00af1050a4ce00af1060a49e00af1070a46e00af1080a43e00af1090a40e00af10a0a3de00af10b0a3ae00af10c0a37e00af10d0a34e00af10e0a31e00af10f0a2ee00af1100a2be00af1110a28e00af1120a25e00af1130a22e00af1140a1fe00af1150a1ce00af1160a19e00af1170a16e00af1180a13e00af1190a10e00af11a0a0de00af11b0a0ae00af11c0a07e00af11d0a04e00af11e0a01e00af11f0a01230a2a1ed364274ff47a7542f2107403eb83014900b2fbf1f60a2e11d303fb07f1b2fbf1f60a2e0bd303fb05f1b2fbf1f60a2e05d36343b2fbf3f10929e7d800e00b46d646baf15f0f98bf4ff05f0ecef1000942f2107c0cad19eb0a0b51d0b2fbf3f40a2b04f1300105f80a104cf6cd41ccf6cc41a3fb011747d31bf1010140d004fb1326ff08b6fbf7f405eb0a0204f13001517048f21f51c5f2eb11642ba3fb015135d31bf102052dd004fb17664c09b6fbf4f7b3f57a7f07f13001917044f6d351c1f26201a3fb015124d31bf1030519d007fb1464890941f25976b4fbf1f5cdf2b716a3fb066705f13006d67005fb11420af1040a63454fea57330cadabd20ce0f2460ae0f24607e00af1010a05e00af1020a01e00af1030a0cad079f002205f80a20a95c002900f0a080a9184b78002b5ed08b78002b5dd0cb78002b5cd00b79002b5bd04b79002b5ad08b79002b59d0cb79002b58d00b7a002b57d04b7a002b56d08b7a002b55d0cb7a002b54d00b7b002b53d04b7b002b52d08b7b002b51d0cb7b002b50d00b7c002b4fd04b7c002b4ed08b7c002b4dd0cb7c002b4cd00b7d002b4bd04b7d002b4ad08b7d002b49d0cb7d002b48d00b7e002b47d04b7e002b46d08b7e002b45d0cb7e002b44d00b7f002b43d04b7f002b42d08b7f002b41d0c97f002940d02032602a7ff49aaf48e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a09d84ff07501a95405d0a91873235e2a4b7040f08780044600208df88f00384602212a460bf083fed4f870c272208df8300078208df8310020204ff0000b1ffa8cf28df832008df833b015f80b00002800f0c88005eb0b035878002866d09878002866d0d878002866d01879002866d05879002866d09879002866d0d879002866d0187a002866d0587a002866d0987a002866d0d87a002866d0187b002866d0587b002866d0987b002866d0d87b002866d0187c002866d0587c002866d0987c002866d0d87c002866d0187d002866d0587d002866d0987d002866d0d87d002866d0187e002866d0587e002866d0987e002866d0d87e002866d0187f002866d0587f002866d0987f002866d0d87f002866d00bf1200bbbf1600f7ff496af4ff0600b5fe004460020887078e70bf1010b58e00bf1020b55e00bf1030b52e00bf1040b4fe00bf1050b4ce00bf1060b49e00bf1070b46e00bf1080b43e00bf1090b40e00bf10a0b3de00bf10b0b3ae00bf10c0b37e00bf10d0b34e00bf10e0b31e00bf10f0b2ee00bf1100b2be00bf1110b28e00bf1120b25e00bf1130b22e00bf1140b1fe00bf1150b1ce00bf1160b19e00bf1170b16e00bf1180b13e00bf1190b10e00bf11a0b0de00bf11b0b0ae00bf11c0b07e00bf11d0b04e00bf11e0b01e00bf11f0b01230a2a1ed364204ff47a7742f2107503eb83067600b2fbf6f40a2c11d303fb00f6b2fbf6f40a2c0bd303fb07f6b2fbf6f40a2c05d36b43b2fbf3f6092ee7d800e03346d946bbf15f0f98bf4ff05f09c9f1000a42f2107e1aeb0b004fd0b2fbf3f50ca905f1300401f80b404cf6cd41ccf6cc410a2ba3fb014742d3441c3ed005fb1326fd08b6fbf5f70ca901eb0b0248f21f5107f13004c5f2eb115470642ba3fb011430d3811c29d007fb15656609b5fbf6f7b3f57a7f07f13001917044f6d351c1f26201a3fb011420d3033016d007fb1650a10941f25975b0fbf1f4cdf2b715a3fb055604f13005d57004fb11020bf1040b73454fea5633add209e0cb4607e00bf1010b04e00bf1020b01e00bf1030bddf81c9000220cac04f80b20a05c002800f0a080a118487800285ed0887800285dd0c87800285cd0087900285bd0487900285ad08879002859d0c879002858d0087a002857d0487a002856d0887a002855d0c87a002854d0087b002853d0487b002852d0887b002851d0c87b002850d0087c00284fd0487c00284ed0887c00284dd0c87c00284cd0087d00284bd0487d00284ad0887d002849d0c87d002848d0087e002847d0487e002846d0887e002845d0c87e002844d0087f002843d0487f002842d0887f002841d0c87f002840d02032602a7ff49aaf54e001323ae0023238e0033236e0043234e0053232e0063230e007322ee008322ce009322ae00a3228e00b3226e00c3224e00d3222e00e3220e00f321ee010321ce011321ae0123218e0133216e0143214e0153212e0163210e017320ee018320ce019320ae01a3208e01b3206e01c3204e01d3202e01e3200e01f325f2a15d84ff02000a05411d0a01863215e2a41700cd072215d2a817008d063215c2ac17004d020215b2a017140f06d8100208df88f0037214fea1c7001eb1c71bcf1204f38bf00f13001ccf303608df8241000f137010a2838bf00f13001ccf303508df8251000f137010a2838bf00f13001ccf303408df8261000f137010a2838bf00f1300100208df828001f208df82710211811f81f2c002a00f0808011f81e2c002a7dd011f81d2c002a7bd011f81c2c002a79d011f81b2c002a77d011f81a2c002a75d011f8192c002a73d011f8182c002a71d011f8172c002a6fd011f8162c002a6dd011f8152c002a6bd011f8142c002a69d011f8132c002a67d011f8122c002a65d011f8112c002a63d011f8102c002a61d011f80f2c002a5fd011f80e2c002a5dd011f80d2c002a5bd011f80c2c002a59d011f80b2c002a57d011f80a2c002a55d011f8092c002a53d011f8082c002a51d011f8072c002a4fd011f8062c002a4dd011f8052c002a4bd011f8042c002a49d011f8032c002a47d011f8022c002a45d011f8011c002943d0215c002941d020307f287ff47baf60e01f383ae01e3838e01d3836e01c3834e01b3832e01a3830e019382ee018382ce017382ae0163828e0153826e0143824e0133822e0123820e011381ee010381ce00f381ae00e3818e00d3816e00c3814e00b3812e00a3810e009380ee008380ce007380ae0063808e0053806e0043804e0033802e0023800e001385f2821d8c0f15d0ec0f15e02c0f15f03c0f1600c2044002509ac675d4755b7b1ab4211d0661971784719797079b1aa420ad0b178b97051b1ae4505d0f178f97029b10435ac45e8d100208df88f0042f2941645f29c140caa48460e21c2f22006c2f213040bf032fb4ff6a42040f6b801cff6ff70c2f200010858a0426ad14ff6b020cff6ff700858b0f54d2f62d14ff6b420cff6ff700858a0425bd145f610634ff0000ec2f213034cf6394506f1040c00274ff0ff3263454cd8186830f003041ad09e4228bf0c2846d3f11a8c424ff0ff3143d8bc42394688bf2146c00703eb04001cbf0f46a644013d00f10403e2d130e00021417192e60421b7f5807f22d300223d46b5f5007f18d3b5f5806f17d3b5f5006f16d30901b2eb153f4fea1515f0d110e00022ca71fff734ba00219171fef73cbd00211172fef7fab9490002e0890000e0c900634504d1484207ea0002714603e04ff0ff324ff0ff3147f64c60c2f20700d0f8840006f1080342f6941c9842c2f2270c4cd142f610674ff0000bc2f2200746f6b9700cf1040e00244ff0ff3a4ff0ff3977453bd83e6836f0030515d0bc4528bf0c2e35d3aceb07039d4233d82346a54288bf2b46f6071cbf1c46ab447b19013803f10407e4d121e00420b4f5807f16d300262546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad30001b6eb153f4fea1515f0d104e0400002e0800000e0c000774504d1404204ea000ad94603e04ff0ff3a4ff0ff394ff6882040f6b807cff6ff70c2f200073b580cf10800834264d14ff69423cff6ff73fb58b3f5333f5cd14ff69823cff6ff73fb58834255d14ff29c5043f21063c2f229004ff0000bc2f2270342f6f935a0f1040ca0f1080e0024634542d81e6836f003071ad09e454ff0ff30069028bf0c2e3ad3aeeb030087424ff0ff3034d82046a74288bf3846f6071cbf0446bb44d819013d00f10403dfd123e00427b4f5807f17d34ff0000e2546b5f5007f0cd3b5f5806f0bd3b5f5006f0ad33f01beeb153f4fea1515f0d104e07f0002e0bf0000e0ff00634505d17b4204ea03000690584602e04ff0ff300690064666208df8300072208df8310065208df832008df833002f208df834006d204b238df8350061208df8393069238df8360078208df83a30422356278df8370020208df83b303a238df83f7047270cac8df838008df83c308df83d004c238df840708df84200002720468df83e308df841308df843700bf025fb079de05d002800f0a080e019417800295ed0817800295dd0c17800295cd0017900295bd0417900295ad08179002959d0c179002958d0017a002957d0417a002956d0817a002955d0c17a002954d0017b002953d0417b002952d0817b002951d0c17b002950d0017c00294fd0417c00294ed0817c00294dd0c17c00294cd0017d00294bd0417d00294ad0817d002949d0c17d002948d0017e002947d0417e002946d0817e002945d0c17e002944d0017f002943d0417f002942d0817f002941d0c07f002840d02037602f7ff49aaf64e001373ae0023738e0033736e0043734e0053732e0063730e007372ee008372ce009372ae00a3728e00b3726e00c3724e00d3722e00e3720e00f371ee010371ce011371ae0123718e0133716e0143714e0153712e0163710e017370ee018370ce019370ae01a3708e01b3706e01c3704e01d3702e01e3700e01f375f2f25d84ff02000e05521d0e01945215e2f41701cd076215d2f817018d065215c2fc17014d06e215b2f017110d048215a2f41710cd07521592f817108d06221582fc17104d02021572f017240f0f88000208df88f002046494652460bf050fa0020215c002900f0a08021184a78002a5ed08a78002a5dd0ca78002a5cd00a79002a5bd04a79002a5ad08a79002a59d0ca79002a58d00a7a002a57d04a7a002a56d08a7a002a55d0ca7a002a54d00a7b002a53d04a7b002a52d08a7b002a51d0ca7b002a50d00a7c002a4fd04a7c002a4ed08a7c002a4dd0ca7c002a4cd00a7d002a4bd04a7d002a4ad08a7d002a49d0ca7d002a48d00a7e002a47d04a7e002a46d08a7e002a45d0ca7e002a44d00a7f002a43d04a7f002a42d08a7f002a41d0c97f002940d0203060287ff49aaf5be001303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f281cd84ff02001215418d021184f225e284a7013d074225d288a700fd068225c28ca700bd065225b280a7107d072225a284a7103d0202259288a7128d100208df88f000cac069a204631460bf083f928461a2122460bf000f8002088f86401c8f8600107984ef217310c904ff416300d900ca8c0f247018847012088f8660108a800f054f9c8f810004fb0bde8f08f0020c871d6e70021417207e700bf2de9f04f81b0009041f204024cf65560cef20002ccf2ac50c2f8ac0f4ef6fc50cef2000001684ef66c6641f08071016052f8040c4ff29c574ff62c4a48f2a358ccf2ff06c2f229074ff6ff7440f00100cff6ff7a00254ff0010bc0f2450842f8040c02e0bff32f8fc047d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168b14200f0ba804ff4757002f0b8fc002800f0f08051464218463182f8d45382f8d55382f8d65382f8d75382f8d85382f8d95382f8da5382f8db5382f8dc5382f8dd5382f8de5382f8df5382f8e05382f8e15382f8e25382f8e35382f8e45382f8e55382f8e65382f8e75382f8e85382f8e95382f8ea5382f8eb5382f8ec5382f8ed5382f8ee5382f8ef5382f8f05382f8f15382f8f25382f8f35382f8f45382f8f55382f8f65382f8f75382f8f85382f8f95382f8fa5382f8fb5382f8fc5382f8fd5382f8fe5382f8ff5382f8005482f8015482f8025482f8035482f8045482f8055482f8065482f8075482f8085482f8095482f80a5482f80b5482f80c5482f80d5482f80e5482f80f5482f8105482f8115482f8125482f8135482f8145482f8155482f8165482f8175482f8185482f819547ff470af066080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff43cafbff35f8f47e8000121b157e8001f4945f8d031e74169d1bb47f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f421ed041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94206d041f20401cef200010968c91a416141f20400cef2000000680099086001b0bde8f08f00bf2de9f04f81b041f20401cef200014ef66c674ff29c56d1f8009000684ff62c4bccf2ff07c2f229064ff6ff74cff6ff7b00254ff00108009007e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168b94200f0ba804ff4757002f080fb002800f00e8159464218463182f8d45382f8d55382f8d65382f8d75382f8d85382f8d95382f8da5382f8db5382f8dc5382f8dd5382f8de5382f8df5382f8e05382f8e15382f8e25382f8e35382f8e45382f8e55382f8e65382f8e75382f8e85382f8e95382f8ea5382f8eb5382f8ec5382f8ed5382f8ee5382f8ef5382f8f05382f8f15382f8f25382f8f35382f8f45382f8f55382f8f65382f8f75382f8f85382f8f95382f8fa5382f8fb5382f8fc5382f8fd5382f8fe5382f8ff5382f8005482f8015482f8025482f8035482f8045482f8055482f8065482f8075482f8085482f8095482f80a5482f80b5482f80c5482f80d5482f80e5482f80f5482f8105482f8115482f8125482f8135482f8145482f8155482f8165482f8175482f8185482f819547ff470af076080f80a808483c483048444848484c484048544858485c485048644868486c4860487448756e8001f51457ff438afbff35f8f46e8000121b156e8001f5145f8d02de74169009d61b144f6d350c1f26200a1fb0001880901284ff0010088bf88094ce047f64c6245f6e466c2f20702cff6f8761368314617689f420ed117689f420bd117689f4208d117689f4203d1002901f10401efd19f422fd041f20401cef200010b6817681168b9420ed11168b9420bd11168b94208d11168b94203d1002e06f10406efd1b94217d041f20401cef20001096844f6d357ca1ac1f26207a2fb07764261b00901284ff0010088bfb009994208bffa2001e0009dfa20a9eb0501b1fbf0f001b0bde8f08f2ab1a2fb0103002b1cbf0020704702fb01f0ffe7b0b54ff2a054c2f229040146206846f23f52c5f28802b2eb500f40f258304df681124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304df69f22c2f20000c0f248021047002858d1002956d0082a54d30b78aa2b51d18b79f02b4ed12de9f04f83b00b2a4ed3c878a2f10803834249d14878212848d10879012845d14879012842d1c87900283fd10c4614f8080f10f03c0f39d18818884610f8021c10f8010c164641ea0025a2f10a0081b2204609f085fe854228d145f64d50c0f246008047811eb1fa81f14f09012808bf0227002f00f03f81207887f00301084200f03b81012039464246334600f092fa0446002898f8080018bf06242ee14ff27143c0f24c0318470b2400e00a2445f64d50c0f246008047811eb1fa81f14d09012808bf0225002d00f011814ef66c6a4ff29c574ff62c480294ccf2ff0ac2f229074ff6ff74cff6ff7800264ff0010b06e048f2a351c0f24501bff32f8f8847d7f80090bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168514500f0bd804ff4757002f08df9002800f0de80414600bf4218463182f8d46382f8d56382f8d66382f8d76382f8d86382f8d96382f8da6382f8db6382f8dc6382f8dd6382f8de6382f8df6382f8e06382f8e16382f8e26382f8e36382f8e46382f8e56382f8e66382f8e76382f8e86382f8e96382f8ea6382f8eb6382f8ec6382f8ed6382f8ee6382f8ef6382f8f06382f8f16382f8f26382f8f36382f8f46382f8f56382f8f66382f8f76382f8f86382f8f96382f8fa6382f8fb6382f8fc6382f8fd6382f8fe6382f8ff6382f8006482f8016482f8026482f8036482f8046482f8056482f8066482f8076482f8086482f8096482f80a6482f80b6482f80c6482f80d6482f80e6482f80f6482f8106482f8116482f8126482f8136482f8146482f8156482f8166482f8176482f8186482f819647ff470afc0f800a080f80ab08483c483048444848484c484048544858485c485048644868486c4860487448757e8001f49457ff436afbff35f8f00bf47e8000121b157e8001f4945f8d02ae705eb450100eb011090f85d1201b300f513760024304629462a460323009409f009fe706840b14bf69b71c0f25d0188477068fff781fe74603068b475002818bffff77afe0020029c3060b060308200e0029c204603b0bde8f08f0624f9e700243842f6d0404631463a463b4600f076f9002818bf0446ece70b291dd3c278a1f10803934218d10278aa2a13d14278212a10d10279012a0dd14279012a0ad18279f02a07d1c2792ab9024612f8083f13f03c0f03d00a2070470b20704710b5084410f8023c10f8010c43ea0024a1f10a0081b2104609f0f6fc201a18bf0a2010bd002808bf7047b0b582b00446407cd0b1002520460323009509f09cfd606840b14bf69b71c0f25d0188476068fff714fe65602068a575002818bffff70dfe00202060a060208202b0bde8b040704700bf2de9f04f81b04ef66c654ff29c564ff62c498046ccf2ff05c2f229064ff6ff77cff6ff7900244ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0bb804ff4757002f00af8002800f0b38049464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470af056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff438afbff35f8f46e8000129b156e8001f5945f8d02de7002008eb480100eb0111002818bf01f5137001b0bde8f08fb0b5c4b0dc08202c03d94ff0ff3044b0b0bd0df107048df807008df80810a01c11461a461d46faf72ffba81c4af6610582b2c0f24605f02021460023a84744b0b0bd00bf2de9f04f8bb04ef66c654ff29c564ff62c4948f2a35bccf2ff05c2f229064ff6ff77cff6ff7900244ff0010ac0f2450bcde90612cde9080303e000bfbff32f8fd847d6f80080bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168a94200f0ba804ff4757001f0f0fe002800f0578449464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470af056080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f41457ff43cafbff35f8f46e8000121b156e8001f4145f8d031e70999089d01eb410100eb011095f9081000f51376b1f1ff3f01f0030409dd374617f8110fd0bb3068002818bffff7eafb2fe3307cf0b1707ce0b10799099a002730460323009709f05bfb706840b14bf69b71c0f25d0188477068fff7d3fb77603068b775002818bffff7ccfb00203060b06030823068002818bffff7c3fb00204ff480713060b0603182a978b081092006f11107f174b17434757076b07ca978884240f0db82317da14240f0d782069b411ca3f10b00727e02971e2828bf1e209042b17488bf7076981e84b200270a2c4ff00008c0f0e782092241f221090920039419e030684f46002818bffff78afbb089376001303774b760b081002c18bf4ff00608039cd146ddf814a00aeb0b0082b2a24280f0c782317c80b20429824600f28880aa5c00f1010a4b1c0129337405dd022906d0032970d1f28106e021b9727503e0338943ea02223281a24580f0aa8204296ed015f80a204ff0000c831c8f1c0129377406ddff290bd0032967460dd19a4652e000291cbf378947ea0222328100e072756746a34204d38be2f281a34280f08882022936d8ea5c00f1030acb1c0129337407dd022937d0fe2907d17275a2450cd376e231b9338943ea02223281a24504d36ee2f281a24580f06b8202292fd015f80a20031d41f00407fc29377408ddfd2909d0fe291cbf378947ea0222328103e079b9f28100e072756746a34280f0508209b19a4613e0ea5c00f1050a0520307401e09a466746f189308941ea0221f18128b1fff7c8fa0028306000f06a8233897089191a1ffa81fb1ffa8af1621a5a45b8bf93465fea0b4208d03268294410441ffa8bf2faf707f970893389584481b2994270817ff44faf0025cdf81080d6f800808df82b50707db8f1000f06930df12b0108bf88460f2806d8317d00f00302511ab1fa81f14d09000706d4317e707e814238bf30760fe000bf706840b14bf69b71c0f25d0188477068fff7a0fa7760707e30760120f082cdf814a09db1707db57d400714d4002d4ff0000400f0898106984ff6ff7381b2002900f00d8101295ed10020d2e0707d400753d4002478e14ff48030fff757fa002d804600f07081b07d002800f06c81b8f1000f00f068817568002d00f0008130890428c0f0608131680a1812f8043c002b40f0598112f8033c002b40f0548112f8023cff2b40f04f8112f8012cff2a40f04a814ff4803429606860c5f80c802c610028019000f067814bf69b70c0f25d0000f58572284600219047002840f033812969002900f02f8168688c420c46e7d1019a0c468242e3d125e14ff48030fff705fa044620e1069a4ff6fe701040a44642426ff0010000bf08eb0005ac78ed7883ea04231cb25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead7375c0087ea430324b25f003fb209ead43484ea430309ead73787ea430383ea05231fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead73787ea430309ead5355f0085ea43033fb25d002db209ead737023087ea430309ead5371518023587ea430395d1023000276446069ad20732d018f8000083ea002002b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead333420083ea400012b243001bb209ead23282ea400009ead33282ea4003f0899ab2824270d1099b4046faf7bdf800286ad141f2210a4ff00009012375e03820fff744f900285ed00546077047708770c770077147718771c771077247728772c772077347738773c773077447748774c774077547758775c775077647768776c776077747778777c77780f8287080f8297080f82a7080f82b7080f82c7080f82d7080f82e7080f82f7080f8307080f8317080f8327080f8337080f8347080f8357080f8367080f837704ff2e310cff6ff70784428624ff22f20cff6ff70784468624bf69b70c0f25d0045f6e46200f13c0c28460f21c0f27c023823e04740b32846fff707f94446706841f2210a40b14bf69b71c0f25d0188477068fff7faf877604ff000090323b77506980799099a089dddf8108087b23046009709f068f8002c214604463ff455ad0846fff7e2f850e5756073e6c4f58030b4f5803f444606902f60ef607ff646aecde70799099a002430460323009409f04af8706840b14bf69b71c0f25d0188477068fff7c2f874603068b475002818bffff7bbf80020387000203060b06030824ff00a0840460bb0bde8f08f287a4006f8d5307c08b302980078e0b10799099a002430460323009409f01df8706840b14bf69b71c0f25d0188477068fff795f874603068b475002818bffff78ef800203060b06030824ff00b083068002818bffff783f800203060b0603082cae702980078e0b10799099a002430460323009408f0f1ff706840b14bf69b71c0f25d0188477068fff769f874603068b475002818bffff762f800203060b06030824ff00608a7e700bf2de9f041f0284bd100294ff00b0000f07f80022a7cd345f64d50c0f246000e4617468047811eb1fa81f14c09012808bf0224002c4ff00a006ad07578e91ec9b2fe2938bfbde8f081307833463946032860d002282dd001281cbf0a20bde8f081ac4204bf0020bde8f0814808842884bf0b20bde8f081881e03f1020887b240463946fff7b7f9002869d006462846fff70dfa21462a46fff7e1f93046bde8f08145f64d57c0f2460707f5e27cbde8f0416047ac421cbf0020bde8f081a1f1210010f1160f48d36ff0480048432330c0b2242841d81a4612f8020f40f00207032f4bd19b796340032b47d10b2904d0032804bf0b20bde8f081881e4ef60b6783b2c0f247070120f021b847002818bf0620bde8f081ac422dd1a1f10c0010f1030f1ad31a4612f8020f042815d158796040032811d1d879a0f1310717f1300f0bd39b79984208d9a1f10807c01a874284bf0b20bde8f081cfe70b20bde8f081b07a204207d04046394622462b46bde8f041fff7b2ba0020bde8f0810a20bde8f0814ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f15d10a684ef66c63ccf2ff039a420ed1d1f8681159b147f64c62c2f207021268891a012903db0178042938bf7047002101707047b0b541f23154c0f252041d46a0474ff29c51c2f229010968bff35f8f0a466ff39602b2f1005f08d10a684ef66c63ccf2ff039a4218bf002100e00021421c18bf002900d1b0bd95f84d20002afad091f84321002a08bfb0bd46f25863c2f206031a68132aeed8c2ebc20403eb04135b6801ebc2014ff40042c1f8c031a1f8c6212a7a01f5e071002a0fbf802248f20112ca808122ab7c33b1ab7d23b1022342f002028b71ca7195f820303bb195f8243023b1032342f004028b71ca7195f846304bb195f8443042f008020b7195f84530ca714b71b0bd48f27342c2f207021378002b14bf9378ff230b711378002b14bf5278ff224a71b0bdf0b589b048f66502c0f24b020c46054690474ff29c51c2f229010e68bff35f8f31466ff39601b1f1005f08d131684ef66c62ccf2ff02914208bf092d01d009b0f0bde1082c29fad896f843110029f6d045f64d51c0f2460107468847014638460129ecd1ff22079244f6435246f258610020cff60172c2f20601089006920b685a1e132a4fd8c3ebc30501eb05111a1fa1f5de7191f85451ad0618d4d51c42d091f8e450ad0616d4951c3cd091f87450ad0613d4551c36d00d79ad0610d4043aa1f5e071151da3f10403e3d12be05a1e01f5a87104e09a1ee03101e0da1e703106ebc203096893f9c721b2f1ff3f1adc03f5e0731e688e4215d11e798df81b605e798df81c609b798df81e200a0a8df820108df821200a0c090e8df81d308df822208df823100f228df8012010228df80220522208218df80420b4f5804f4ff080028df800108df8061038bf4ff48042b4f5001f6ff07f0604f07f0138bf0026802c28bf80318df807109df809509df80a108df8030004d29df808200223002415e0c4f3c610b4f5804f024403d20323012400200be0b4f5001f03d204230224012003e0052303240120002135468df8053004f108038df808208df809508df80a1070b96846a222c118c254062048700c208870c81c06a90c22f9f73dfc04f117034ff225066a46c0f2470601200821b047384609b0f0bd70b582b00546ff208df8040044f25220c0f20100009040f2c960c0f2480016460c46804798b148f27e30c2f2070000880122c1b264298df8032008d80721b0f5807f38bf03218df803108df80400301b28bf08280cd3d221281929550621417005218170033069460522f9f7f9fb0834204602b070bd00bf024600284ff0ff3009d0022918bf70471078112801d1507810b14ff0ff30704710b586b045f64d50c0f24600804701284ff000003ed1cde9020040f20830c0f210000190ff208df8140044f25220c0f20100049040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8132008d80721b0f5807f38bf03218df813108df8140040f2d260adf80800052001ac8df80a00e01d04a90522f9f7a3fb4ff2250cc0f2470c0120092122460c23e04706b010bd4ff29c50c2f22900016808466ff39600b0f1005f16d108684ef66c62ccf2ff0290420fd1d1f8380160b147f64c62c2f207021268801a0028cebf01200020c1f838017047002070474ff29c50c2f22900026810466ff39600b0f1005f2ed110684ef66c61ccf2ff01884227d1d2f8680120b347f64c61c2f207010968401a0028c4bf01207047d2f86c1100200029c2f8680182f86601c2f86c01c2f80003a2f86c0308bf704780b548f2a352c0f24502084690470020bde88040704700207047f0b101684ef66c62ccf2ff02914218bf704790f8421199b110b54af273644ff0000cc0f24604864680f842c10120002100220023aef840c1a446bde810406047704700bf02464ff6ab70cff6ff7042f6653c7844c0f2440c00210023604700bf70b5002862d0044600796179a279e37940ea012040ea024050ea036007d00e2803d0032852d1032502e0042500e00225fff756ff002849d04ff29c50c2f22900066830466ff39600b0f1005f3ed130684ef66c61ccf2ff01884218bf70bd45f64d50a478c0f24600804701282ed1082086f86002032086f86102102086f86202b22086f86402062086f8650286f86602462086f8670243204ff0000e86f8680201204ef6057c06f5187286f863e286f8690286f86a5286f86b42c0f2470c09210d2386f86ce2bde87040604770bd00bf2de9f04f81b04ef66c694ff29c564ff62c480446ccf2ff09c2f229064ff6ff77cff6ff7800254ff0010a06e048f2a351c0f24501bff32f8f8847d6f800b0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f0bc804ff4757000f072fe002800f0e18041464218463182f8d45382f8d55382f8d65382f8d75382f8d85382f8d95382f8da5382f8db5382f8dc5382f8dd5382f8de5382f8df5382f8e05382f8e15382f8e25382f8e35382f8e45382f8e55382f8e65382f8e75382f8e85382f8e95382f8ea5382f8eb5382f8ec5382f8ed5382f8ee5382f8ef5382f8f05382f8f15382f8f25382f8f35382f8f45382f8f55382f8f65382f8f75382f8f85382f8f95382f8fa5382f8fb5382f8fc5382f8fd5382f8fe5382f8ff5382f8005482f8015482f8025482f8035482f8045482f8055482f8065482f8075482f8085482f8095482f80a5482f80b5482f80c5482f80d5482f80e5482f80f5482f8105482f8115482f8125482f8135482f8145482f8155482f8165482f8175482f8185482f819547ff470afc0f8009080f80aa08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f59457ff437afbff35f8f00bf46e8000121b156e8001f5945f8d02be7002780f857712a270821032380f85871042780f8541180f85531102380f8597180f85a1101214ff2250c074600f5aa7280f8563180f85b1180f85c31002c18bf0124c0f2470c012010210a2387f85d4101b0bde8f04f604701b0bde8f08f00bf80b582b04ff0010ccdf800c000f002f802b080bd2de9f04381b04ff29c57c2f229073f684ff000093e466ff39606b6f1005f07d13e684ef66c65ccf2ff05ae4208bfb946012811d1ddf820801c4615460e460746fff7c2fd2346044631462a463846002c18bfb9f1000f07d14af2736cc0f2460c01b0bde8f043604799f8420180b1b8f1010f7cd1d9f83c01002189f84211a9f84011a0b342f68d41c0f2440188472ee0b9f840010121013080b2012898bf0846a9f84001d9f83c0142f68d44c0f2440489f8421128b94846fff708fec9f83c0140b1a047d9f83c01a4f140024ff4c8719047a8b199f84201002848d0d9f83c01002189f84211a9f8401100b1a0474af2736cc0f2460c0120002100220023afe745f64d50c0f24600804701282fd1082089f84401032089f84501102089f84601002089f84701b22089f84801062089f8490189f84a01462089f84b01432089f84c01012089f84d01b9f840014ef6057c070a09f5a27289f84e8189f84f01c0f2470c012009210d2389f8507178e701b0bde8f08380b582b04ff0050ccdf800c0fff73eff02b080bd2de9f04f83b04468002c00f0db828368002b00f0d78204eb030b4ff000090027002614e047f64c63c2f207031b6845f69077c0f201073b44c6f838310ceb0a0300275b451c464ff0000680f0bb82a04618f9013b03f07f05bd40002b46ea050610d406f00703012b16dc0bb3012b40f0a982abeb0803082bc0f0a48204f10903dee700bfd84580f09d82182f07f107074446dcd996e200bf022b3ad0052b40f09182abeb0803042bc0f08c82631dc7e7d84580f0878294f90130002b04f10203bed55b4580f07e8294f90230b3f1ff3f04f10303b4dc5b4580f0748294f90330b3f1ff3f04f10403aadc5b4580f06a8294f90430b3f1ff3f04f10503a0dc5b4580f0608294f90530002b00f15b82a31d96e7d84580f0568294f9013004f1020c002b03f07f0a1ed5dc4580f04b8294f90270e31c07f07f05b7f1ff3f4aeac51a02dde0469c460ee05b4580f03b8294f9037004f1040c07f07f05b7f1ff3f4aea853a33dd9846abeb0c039a4500f22a82f308672b1dd0652b7ff460afbaf1060ffff45caf9cf80030462b7ff457af98f80230432b7ff452af98f80330012b7ff44daf4ff29c54c2f229040290cde9002132e0044660460e4651461746654600f035fcac4631463a46204637e7dc4580f0f98194f90470631d07f07f05b7f1ff3f4aea455aaddc5b4580f0ec8194f90570002f00f1e78104f1060c4aea077ab1e748f2a3513046c0f24501bff32f8f8847dde900210298ac462768bff35f8f2668bff35f8f33466ff39603b3f1005f07d133684ef66c65ccf2ff05ab4200f0ce804ff47570654600f097fbdde9002106460298ac46002e3ff4f1ae4ff62c43cff6ff7300bff418463384f8d49384f8d59384f8d69384f8d79384f8d89384f8d99384f8da9384f8db9384f8dc9384f8dd9384f8de9384f8df9384f8e09384f8e19384f8e29384f8e39384f8e49384f8e59384f8e69384f8e79384f8e89384f8e99384f8ea9384f8eb9384f8ec9384f8ed9384f8ee9384f8ef9384f8f09384f8f19384f8f29384f8f39384f8f49384f8f59384f8f69384f8f79384f8f89384f8f99384f8fa9384f8fb9384f8fc9384f8fd9384f8fe9384f8ff9384f8009484f8019484f8029484f8039484f8049484f8059484f8069484f8079484f8089484f8099484f80a9484f80b9484f80c9484f80d9484f80e9484f80f9484f8109484f8119484f8129484f8139484f8149484f8159484f8169484f8179484f8189484f819947ff470af4ef66c63ccf2ff0333600123b3724ff6ff734ff29c54b383f38333847384b384f38433857385b385f38533867386b386f38633877387c2f2290454e8003fbb427ff41cafbff35f8f44e8006323b154e8003fbb42f8d011e798f8043098f8057098f80650032b47ea052437dd052b58dc042b78d0052b7ff41faed6f868313bb147f64c67c2f207073f68db1b002b18dcd6f86c3186f86691c6f86c91c6f80093a6f86c936bb10c4648f2a35180461846c0f24501174665468847ac4621463a46404647f64c63c2f207031b6845f69077c0f201073b44c6f86831ede5012b3ff4dfad022b00f08780032b7ff4e5ad174688466546fff7e2fa03460298ac4641463a46002b3ff4d8ad96f84231002b3ff4d3ad304641f28831a6f8404108f02afd47e0062b4ad0072b7ff4c6ad80464df6db50c0f24a0016460f466446804703465d1ea446394632464046012d3ff6b4ad981eb0fa80f04009fff7a8fba446394632464046a8e5174688466546fff7a6fa03460298ac4641463a46002b3ff49cad96f84231002b3ff497adb6f84031a3427ff492add6f83c3186f84291002ba6f840913ff489ad42f68d411846c0f2440188470298ac4641463a467de5d6f86c31c6f86891002b86f86691c6f86c91c6f80093a6f86c933ff46fad0f4648f2a35104461846c0f24501164665468847ac463946324626e696f84231c6f83891002b3ff45aad0446d6f83c0165468846174686f84291a6f8409120b142f68d41c0f2440188474af273660120002100220023c0f24606b04720463a464146ac463be54ff2a513c0f2490303b0bde8f04f18477fb50646002806d1fff730fa002807d19de80f00064649f29b1cc0f24f0c60477fbd00bff0b583b01d46144609294ed106460f46f22d10d8a22160196155062141700b21817049f2ec61c0f20001033079440b22f8f7a2fd0e35204629464ff4807200f03df80546ff208df8080044f25220c0f20100019040f2c960c0f24800804798b148f27e30c2f2070000880122c1b264298df8072008d80721b0f5807f38bf03218df807108df80800f82d0cd8d221601961550621417005218170033001a90522f8f76afd0835394630464ef60577c0f2470722462b46b84703b0f0bdf0b587b00c464ff29c51c2f229010d68bff35f8f29466ff39601b1f1005f52d129684ef66c63ccf2ff0399424bd14d218df8041043218df8051001218df8061095f8701195f871318df807108df8083095f87511b5f878318df80b108df80c30190ab5f87a318df80d10190a8df80f1095f8761195f8737195f874618df80e3095f877318df8101045f64d51c0f246018df809708df80a608df81130064617468847d5f87c3101468df81210190a8df81410190c3a4630468df813308df81510190ea02328e04d218df8041043218df8051001218df80610002100238df807108df808108df809108df80a108df80b108df80c108df80d108df80e108df80f108df810108df811108df812108df813108df814108df815108df816108df817300023111b8df8183028bf18290cd3c222011902550620487015208870c81c01a91522f8f7bbfc1834204607b0f0bd00bf2de9f04f81b04ff29c50c2f229000468bff35f8f20466ff39600b0f1005f0dd120684ef66c63ccf2ff03984206d194f8700118b1002a18bf002902d101b0bde8f08f94f877010028f8d0d4f880010028f4d047f64c69c2f20709d9f80030c01a0128ebdb94f87101012802d14ff0010b06e094f873b1bbf1010f18bf4ff0020b94f876510020eb078846adf80200adf8000013d0bbf1020f10d194f8750168b96b4641f281570df10201c0f25b07404615461a46b8472a4694f876511646b2f5c86f28bf4ff4c86606f1150a5046174600f050f80028b1d0b7f5c86f88bf45f08005d9f80010d4f87c2153230271120a42710a0a8171c2710a0c090e03704d234172a02143700123c17200218370c570027280f80ab0017394f87511bdf802204173bdf800108373c173090a0174110a8174310a017500f115014274c6740746084641463246f8f711fc4ff27d12c0f24702384651469047d4f87c0148f2a3510130c4f87c01c0f245013846884701b0bde8f08fb0b54ff2a054c2f22904216846f23f52c5f28802b2eb510f48f25f514cf67e25c0f24501caf2101518bf25608847002804bf691c2160b0bd10b301684ef66c62ccf2ff0291421bd190f87711c1b1d0f88011b1b147f64c62c2f207021368cb1a012b0edb1268d0f88401002808bf7047891a42f64d42c0f2440208bf01211047704710b5002149f25962c0f8801180f87711c0f25902002044f2436190474ef6e374c0f25a04a04704f1bc00bde81040004700bf2de9f04f81b00429c0f00b810c46014600784d2840f005814878432840f001818878012840f0fd804ef66c684ff29c57ccf2ff08c2f229074ff6ff7600254ff0010b8a4607e048f2a351c0f24501bff32f8f88475146d7f80090bff35f8f3868bff35f8f02466ff39602b2f1005f03d10268424500f0c0804ff47570fff766ff002800f0ce804ff62c425146cff6ff728318463283f8d45383f8d55383f8d65383f8d75383f8d85383f8d95383f8da5383f8db5383f8dc5383f8dd5383f8de5383f8df5383f8e05383f8e15383f8e25383f8e35383f8e45383f8e55383f8e65383f8e75383f8e85383f8e95383f8ea5383f8eb5383f8ec5383f8ed5383f8ee5383f8ef5383f8f05383f8f15383f8f25383f8f35383f8f45383f8f55383f8f65383f8f75383f8f85383f8f95383f8fa5383f8fb5383f8fc5383f8fd5383f8fe5383f8ff5383f8005483f8015483f8025483f8035483f8045483f8055483f8065483f8075483f8085483f8095483f80a5483f80b5483f80c5483f80d5483f80e5483f80f5483f8105483f8115483f8125483f8135483f8145483f8155483f8165483f8175483f8185483f819547ff470afc0f8008080f80ab08683c683068446848684c684068546858685c685068646868686c6860687468757e8002f4a457ff432afbff35f8f00bf47e8000222b157e8002f4a45f8d026e7ca78022a04dc012a0dd0022a79d00ce0032a0dd0042a08d190f8701129b101b0bde8f04faae00d2c06d201b0bde8f08f044600f045f963e090f87721aab1002149f2596280f87711c0f259020446002044f2436190474ef6e375c0f25a05a84705f1bc008047204651460a790446012a88bf002280f871214a7902f00303012b4ff0010298bf134680f873318f79012f88bf002780f87471cf79022f88bf002780f875710f7a4e7a47ea0627502f98bf5027b7f5f07f28bf4ff4f077a0f878718f7ace7a47ea062741f28836b74238bf3e46a0f87a61097b80f8702101f0030180f8761103f0010101eb530180f872110021c0f87c1100f009f8204600f03ef8204601b0bde8f04f6ae000bfb0b5044690f87601800758bfb0bd94f871014ef633750128c0f25a0507d105f1b000804705f58b71002088470ee005f5b670804794f87101012801d1002004e094f87301013818bf0120a8474ff67922cff6ff7249f201537a44c0f25903002044f243619847012084f87701b0bd00bf70b5044647f64c60c2f20700006894f8771145f69075c0f2010500292844c4f8800108bf70bdd4f8840142f66536c0f2440658b94ff6d130cff6ff707844002122460023b047c4f8840150b106f594718847d4f8840106f1e8022946bde87040104770bd70b5044600f5c475082084f88801032084f88901102084f88a01c22084f88c01062084f88d014d2084f88f01432084f89001012084f8910194f8700194f8711184f8920184f8931194f87501b4f8781184f8960184f89711080ab4f87a1184f89801080a84f89a0194f8760194f8732194f8743184f8991194f8771184f89b0145f64d500026c0f2460084f88b6184f8942184f8953184f89c118047d4f87c1184f89d01080a84f89f01080c84f8a001080e84f8a101a02084f8a36115264ef6057c84f89e1184f8a201c0f2470c012009212a461c2384f88e61bde87040604770b54ff29c50c2f229000468bff35f8f20466ff39600b0f1005f33d120684ef66c61ccf2ff01884218bf70bd94f877010025c4f8805188b149f25962c0f25902002044f2436184f8775190474ef6e376c0f25a06b04706f1bc008047d4f8840184f8705170b142f68d45c0f24405a847d4f8840105f166018847002804bf0020c4f8840170bd00bf2de9f04182b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f75d121684ef66c62ccf2ff0291426ed194f8a81179b394f8aa01c0070ad0d4f8680178b347f64c61c2f207010968401a002827dd47f24c45c2f2070555f8040c002854d042f29707c0f24c074af6e908002607f5437101a8c0f24b0801968847a8b1032084f8ab612860b4f8ac01c04702b0bde8f081d4f8b411c1b302b0bde8f0410847204602b0bde8f04133e0019841f60d56c0f24c06a861b04706f5af708047e861b847012084f8ab0103202860b4f8ac01c047d4f8bc01a0b10199d4f8b821b4f8ae71531a38bf8b1abb420ad2b4f8b01159b147f64c62c2f207021268101a884203d32046022100f078f802b0bde8f08100bfb0b590f8a841002c4cd044f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114614d14a68b2f5870f10d36ff35602012a0cd14a684ff65b63cff6ff737b449a4204d1d0f8b421002a18bf4a60002180f8a81190f8a911b1b1002180f8a91145f60a61c2f20701097869b947f24841c2f20701096839b14af68171c0f24b010546042088472846002c08bfb0bd0321bde8b04000e000bfb0b588b0044645f64d50c0f246000d468047012840f08f8008208df8010003208df8020010208df8030000208df80400ca208df8050006208df8060018208df8070047f26440c2f2070050f81c2c94f8a811002a18bf0122002945f60961c2f207014b7818bf0232002b94f8ab3118bf0432002b4ff0410318bf08328df808304c238df8093001238df80a308df80b508df80c2050f8182c4ef605758df80d200268c0f24705130a8df80e208df80f30130c120e8df810308df811204268130a8df812208df81330130c120e8df814308df8152002698df81620120a8df8172009788df8181081688df819106821c2f2000109688df81a10090a8df81b1047f64c61c2f207010a68130a8df81c208df81d30130c120e8df81e308df81f2000680df10102c4f8b80108680921c4f8bc0101201f23a84708b0b0bd00bf2de9f04f83b0022902d24ff0ff3510e1cde901100120cff680704ef66c644ff29c564ff62c4bccf2ff04c2f229064ff6ff77851ccff6ff7b4ff000084ff0010907e000bf48f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f00ea0501b1f1005f03d10168a14200f0b9804ff47570fff72dfb0028c5d059464218463182f8d48382f8d58382f8d68382f8d78382f8d88382f8d98382f8da8382f8db8382f8dc8382f8dd8382f8de8382f8df8382f8e08382f8e18382f8e28382f8e38382f8e48382f8e58382f8e68382f8e78382f8e88382f8e98382f8ea8382f8eb8382f8ec8382f8ed8382f8ee8382f8ef8382f8f08382f8f18382f8f28382f8f38382f8f48382f8f58382f8f68382f8f78382f8f88382f8f98382f8fa8382f8fb8382f8fc8382f8fd8382f8fe8382f8ff8382f8008482f8018482f8028482f8038482f8048482f8058482f8068482f8078482f8088482f8098482f80a8482f80b8482f80c8482f80d8482f80e8482f80f8482f8108482f8118482f8128482f8138482f8148482f8158482f8168482f8178482f8188482f819847ff470af046080f80a908783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff43aafbff35f8f46e8000121b156e8001f5145f8d02fe7044645f64d50c0f24600804701281dd1029d6978022916d00129204607d000297ff401af00210025fff75afe0fe0019f41f28831022f0ed14ff4fa730022012741f2883624e02046fff7d6fd0025284603b0bde8f08faa78052f11d3eb782e79072f43ea062310d395f805c0ae79092f4cea0627e4d3ee792d7a46ea052607e041f288364ff4fa7301e041f288360127642b98bf64238b4228bf0b4690f8a81180f8aa21a0f8ac31a0f8ae71a0f8b06171b147f24841c2f20701096800295ed001210446fff70cfe0025c4f8bc51bee744f28442c2f200021188082911462cd0114631f8083f082b27d0114631f8103f082b22d0114631f8183f082b1dd0114631f8203f082b18d0114631f8283f082b13d0114631f8303f082b0ed0114631f8383f082b09d0114631f8403f082b04d032f8481f0829114632d14a686ff00105b2f5870ffff483af0123cff680731a40012a7ff47caf4b684ff68112cff6ff727a44934214bfc0f8b431d0f8b431002b3ff46daf4a60012180f8a81199e74af60771c0f24b010420884720b105462046fff732fd5be70121204684f8a9118fe76ff0010553e700bf10b582b00c464df6cb61c0f24501884724b12178042901d1617809b102b010bda1780d29fad1e1780029f7d121790029f4d161790029f1d10028efd00168e029ecd10446fef708fa014620460029e5d004204ff6591e01904ff0000cc0f24e0e0020002100220e23cdf800c0f047204602b010bd3146fff7c3bf00bfb0b582b00c460546fef7e8f90146002d4ff0000018bf002901d102b0b0bd47f2fc70c2f2070000684df6cb61c0f24501884790b10068e0284ff00000edd129784ff6591c0191c0f24e0c0021002223460090e047012002b0b0bd002002b0b0bd08b530460921fff7cbff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460a21fff7b7ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf08b530460b21fff7a3ff002805d002b045f28310c0f24400004744f62703c0f24603984708bd00bf10b589b38968012805d104460846fef7e5f9204628e039b30a794b798c79c97942ea032242ea044242ea016106291bd147f29121c0f24601044688470146204691b144f2e970c0f24400804701462046002918bf10bd48f23a50c0f2000078440c21fff761ffd4e710bd00bf10b5059c4ff20340c0f2460080472146fff7c0ff10bd00bfb0b5c4b0044600284ff0000000f0c38089b20b2940f0bf80207838b96078092804d1a078612801d1e07810b1002044b0b0bdfef725f90028f8d045f64d50c0f24600804701281cd00228efd103208df8070001200df107058df80800a81c21460b22f7f781fc4af66104c0f24604f02029460d220023a047b0fa80f0400944b0b0bd4ff29c50c2f22900006801466ff39601b1f1005fc9d101684ef66c62ccf2ff029142c2d122797f21042a06dc012a0cdcbab1012a08bf00211ae0082a0bdc052a11d0082a08bf0a2112e0022a0dd0042a08bf01210ce0092a09d00a2a08bf0e2106e0092104e0022102e0032100e00b2180f8eb1210216a2580f8ec12a22180f8e652152580f8ee12062180f8e7521a2580f8ef120c2180f8e852132580f8f01252210822022380f8e95280f8f1124921012580f8e42280f8e53280f8ea2280f8ed3280f8f21280f8f35280f8f452217900f5397280f8f5126179192380f8f612a17980f8f712002180f8f812e17980f8f912217a80f8fa12617a80f8fb12a17a4ff2250480f8fc12c0f247040120e021a047284644b0b0bd00bf1fb5fff72fff002803d0bde81f4000207047bde81f4038b584b049f21f13c0f24703184710b5f0281bd1d1b1cab10c78032c16d10d2a1cbf0b2010bd487801281cbf0a2010bd45f64d50c0f246000c468047012803d1a01c0b21fff703ff002010bdbde81040fdf723bd00bf4ff29c52c2f229021268bff35f8f13466ff39603b3f1005f0cd1d2f800c04ef66c63ccf2ff039c4502bf0023c2f8dc32c2f8e03247f2c942c0f24d02104700bf4ff29c50c2f229000068bff35f8f01466ff39601b1f1005f0bd101684ef66c62ccf2ff02914202bf0021c0f8dc12c0f8e01247f2d940c0f24d0000472de9f04184b0dde90a76022f16d340f64705a94212d08eb13578412d0ed175784e2d0bd1014602f0bf0012284ff00d0008bf002b0ed004b0bde8f0810c9d0097cde9016546f63916c0f24d06b04704b0bde8f081082feed3b078012802d1f078022803d90d2004b0bde8f08100294ed045f6f444c2f2060414f8040c814246d12068002843d048f22732c0f254020d46084602219047d0b324682088b8b36088a8b3a08898b3e08888b330797179b279f37940ea012040ea024050ea0368d1d04ff29c50c2f229000068bff35f8f01466ff39601b1f1005f17d101684ef66c62ccf2ff02914210d1f178a1b190f8dc22aa420cd1d0f8e022424508d101295bd1082fafd100f09cf875e0f07818b1082004b0bde8f081082fa4d1f9f73ff9c8b10646d0f868010028f1d047f64c61c2f207010968401a0128e9db96f8dc0268b196f8dd02032809d00628e0d1304600f077f8dce7112004b0bde8f08146f63917c0f24d0707f53a60804707f539622846214690470120002786f8dd020df10f02304600210123a6f8de7286f8dc52c6f8e0828df80f70adf80c7000f07ff861884af2bd6603abc0f24c0628460222b047384604b0bde8f081a7f1510189b24ff6b87291424ff00d0119d390f8dd02032808467ff430af334613f8080fa7f108018ab280b9052a0ed9a1884af2bd67c0f24c072846b847002004b0bde8f081084604b0bde8f08101280dd1042a0bd3981810f8021c00297ff425af10f8010c00287ff420afe0e702284ff00d0008bf062a7ff401af707b01283ff614afd4e700bf90f8dd120a1f022a38bf7047022905d0012907d1042180f8dd127047052180f8dd12704780b582b0052180f8dd120121adf8061045f6f441c2f2060190f8dc0209684af2bd6c49880df10603c0f24c0c0222e04702b0bde8804070472de9f04fc7b0054690f8dc0203920591d8b145f6f041c2f206010978884214d148f22732c0f2540202211c46904760b195f8dc0240f66502c0f255020021904718b100690088172802d247b0bde8f08f033880b2f42828bff42007af0b3807f101084ff000094ff0000a01900495029414e000bf0699cde94509adf810112121adf8121143f23d5144a8c0f255018847049d029c1ffa8af0a042d6d2a4eb0a01019a1ffa81fbb5f8de1241235a45b8bf93468df81c304e234a1c8df81d300123a5f8de22d5f8e0228df81e30059b1ffa8af08df81f30130a8df82410090a8df820208df82130130c120e8df82510b0fa80f18df823204a091ffa8bf111fa8afaa2458df8223008bf0232bbf1000f8df826202fd001390329039901eb000c01d2002115e04ff6fc700bea00020cf10103002100bf5e1816f8014c7d187078ec725c5cb67804318a422c736873ae73f1d1049d1bf003020dd01cf80160cb19012ade7207d00ceb01004178022a19731cbf8078587395f8dc020bf10b0406900b2010fa84f649f6cd713046c0f24c01884700283ff47eaf26f003031ffa84fc06f003025e426ff00303c1180433f518043581f8049081f8059081f8069081f80790f2d152b10344012a83f8049005d0022a83f8059018bf83f806900bf10e0202701b22442108230272220480f801908170c370417283723ff43dafbcf1040f01d2002214e047f6fc710cea0103002200bfb95c8618f17218f8021008eb020531736978ad78043293427173b573f0d11cf003033ff41fafbe5c00f10b01012b8e543ff418af561cbd5d022b8d553ff412af0232bb5c8b540de7f0b583b04ff29c51c2f229010c68bff35f8f21466ff39601b1f1005f47d121684ef66c62ccf2ff02914240d194f8dc12e9b3002840d002888a423dd145f6f446c2f2060616f8041c8a4235d1316899b3356894f8dd12032919d8d4f8681139b147f64c62c2f207021268891a00290edc02218df80b100df10b020746204600210123fff791fe2046fff760fe38468278092a1bd141896b8894f8dd72994217d1032f3adc012f6ad0022f3dd004e018b181780939022901d203b0f0bd47f6ed31c0f24d0103b0bde8f040084794f8dd72032ff1d8a2f10d0102290cd2c178d1b302208df8040001aa204600210123fff75bfe03b0f0bd092a08bf032fdcd14189aa889142d8d1c078002800f0818002200df105028df80500e6e7052f04d0042fcad1c07805262fe0c078002848d0062084f8dd0202208df807000df10702204600210123fff730fe052fb5d02046fff7fdfd03b0f0bd4268002aadd00389a3f2012189b2b1f57e4fa6d34089082b48d12988884245d12046012108234ce0c0780526002808bf022650b102208df80a000df10a02204600210123fff705fe6988012294f8dc024af2bd67adf8082002abc0f24c07022284f8dd62b84703b0f0bd052f15d1002094f8dc523668c4f8dc02c4f8e00247f2c944c0f24d0404f11000804728463146224603b0bde8f0401047032084f8dd0201208df806000df1060272e7e98888427ff457af2046022103e0204603210022002303b0bde8f040c3e580b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd06290ad14178012907d18178653911f1630f02d3c178012902d94ff0ff307047f0b581b00179427941ea022540f6b8318d421fd80646fdf743fcd8b1f8f710fec0b10446d0f8b80342f66537c0f2440758b941f26770c0f200007844012100220023b847c4f8b80320b107f1e8022821904718b14ff0ff3001b0f0bdb078f178d4f8c4230023c7f6e07340ea452003ea425240ea0120bff35f8f1043bff35f8fc4f8b403002001b0f0bd00bf02293cbf4ff0ff3070472de9f04f9bb00278437842ea0325b5f5007f04d94ff0ff301bb0bde8f08f4ef66c6a4ff29c56ccf2ff0ac2f229064ff6ff774ff000084ff0010b0791099008e000bf48f2a3512046c0f24501bff32f8f8847d6f80090bff35f8f3468bff35f8f20466ff39600b0f1005f03d12068504500f0c2804ff47570fef73ffb002800f0ba8004464ff62c40cff6ff7000bf2118463081f8d48381f8d58381f8d68381f8d78381f8d88381f8d98381f8da8381f8db8381f8dc8381f8dd8381f8de8381f8df8381f8e08381f8e18381f8e28381f8e38381f8e48381f8e58381f8e68381f8e78381f8e88381f8e98381f8ea8381f8eb8381f8ec8381f8ed8381f8ee8381f8ef8381f8f08381f8f18381f8f28381f8f38381f8f48381f8f58381f8f68381f8f78381f8f88381f8f98381f8fa8381f8fb8381f8fc8381f8fd8381f8fe8381f8ff8381f8008481f8018481f8028481f8038481f8048481f8058481f8068481f8078481f8088481f8098481f80a8481f80b8481f80c8481f80d8481f80e8481f80f8481f8108481f8118481f8128481f8138481f8148481f8158481f8168481f8178481f8188481f819847ff470afc4f800a084f80ab0a783e78327846784a784e78427856785a785e78527866786a786e7862787678756e8000f48457ff431afbff35f8f00bf46e8004028b156e8000f4845f8d025e70024ddf824805db1fdf704fb0146002c4ff0ff3018bf002902d11bb0bde8f08fb5fa85f040094ff000098df82c908df82d908df82e908df82f908df830908df831908df832908df833908df834908df835908df836908df837908df838908df839908df83a908df83b908df83c908df83d908df83e908df83f908df840908df841908df842908df843908df844908df845908df846908df847908df848908df849908df84a908df84b908df84c908df84d908df84e908df84f908df850908df851908df852908df853908df854908df855908df856908df857908df858908df859908df85a908df85b908df85c908df85d908df85e908df85f908df860908df861908df862908df863908df864908df865908df866908df867908df868908df869908df86a908df86b90bcb1d4f86c21a2b14ff4006304e03f683b44b3f5403f0cd2d718be680136f6d07e68033626f0030609eb060101f11009ede7002d4ff0020a039500f00581ddf81cc0acf102020a2ac0f00081002608eb0a0b9bf801504ff0ff30012d3ff648af9bf802209bf803309bf8047042ea03229bf8053042ea074747ea0361a1f1011212f5803f0a91fff433af9bf808109bf809e0029141ea0e210af10a020497aceb02034f1e9f42bff423afcde905269bf806209bf807300a9e42ea032cb6eb0c07fff416afb9423ff613af18f80a70089147ea052a4feada000ba90e5c07f00705012707fa05f5354240f003830e5c45ea06050d5407994ff6ff75c0f20205b4b3d4f86c0198b317461a0201924fea0e264ff4006200eb0208d8f8083053454bd0d8f800301a44aa4221d800eb0208d8f80830534540d0d8f800301a44aa4216d800eb0208d8f80830534535d0d8f800301a44aa420bd800eb0208d8f8083053452ad0d8f800301a44aa42d3d900bfbcf1000f40f0be8204980a464ff6fc710330c0f2030108404844944600f1100908980599069e00eb010a0398013686424ff0000028bf0120ddf824804fd2aceb0a02092a3ff64caf49e0d8f804000a9a904240f09782d8f80c006045c0f0928236d9089aa0eb0c00824200f28b827ab3029831180198c1f1000cc2199044a1f1010e002208eb02050beb0203287c9e7ab04240f0778296451cd06e7cdf7abe4240f070820ceb0207be1c13d0ae7c187b864240f06782079ef81c07d0e87c5b7b984240f05f8204329142dbd1b446a7e78c46a5e7ddf81cc0a2e7ddf81cc0002800f05082baeb0c004ff0000118bf0120b9f53e3f88bf0121014303980028c1f100003ff43eae00297ff43baed4f86cb1bbf1000f40f08b804ff44030fef7a6f8002800f02f82834600206ff0200100220beb02030bf8020040320beb0107b2f5006f01f1400158709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d87618775877987787f8400087f8410087f8420083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f0093d14ff43e30cbf800080020cbf804084ff0ff31cbf80c084ff40060c4f86cb1cbf80818c4f800034ff6ff760222c0f2020600210ae00aeb080209f10101ddf8248071454ff000003ff498ad08eb02050a9218f80200aa786f7805922a7a95f803e095f8049095f805c095f806a0eb7908926a7a40ea0728cde906215cb3012f29d84ff400670beb0705a868404500f0a28028680744b7421dd80beb0705a868404500f0988028680744b74213d80beb0705a868404500f08e8028680744b74209d80beb0705a868404500f0848028680744b742d7d90598cdf810a040ea0e2040ea094040ea0c67f81c20f00300d4f8009300f1100a002002930597b9f1000f26d00beb09035bf809105a68514580f09c80eab10beb02005bf80210d0f80490514580f08d80b9f1000f11d00beb09035bf809105a68514580f0878042b10beb02005bf80210d0f804905145d6d377e000204ff400694ff4006504e000bf3d44b5f5403f23d20beb05018a685bf805700132f4d04868ca68033020f0030000f110060beb09001032f6f7b5fb4168c2684bf809608368d4f86cb18a424ff00001b14408bf00f110014bf82310d7e7c9f540310f294ff00002c4f8002311d90beb09004bf809104ff0ff3142608160c260c4f800930be0e868ddf80ce00a9a089f60e010b10268114401604ff000090020b9f1000f7bd00beb09035bf809105a68514522d2002a72d00beb02005bf80210d0f80490514513d2b9f1000f67d00beb09035bf809105a6851450ed2002a5ed00beb02005bf80210d0f804905145d7d30546cc469146184601e01d469446a1eb0a0110290fd309eb0a020beb02034bf802104ff0ff31c3f804c0996000219446d960c5f800a0ddf80ce00a9addf810a0029b089f00280cbfc4f800c3c0f804c005984ff6ff7668600020c0f20206c5f80880e8604aea0321069bddf81c9047ea032a814202f10a087ff4bdae05f110077818099952464144f346f6f7c8fae968de466868aa68d4f86cb15144e96081424ff0000018bf07464bf82270a3e600204ff400684ff4006703e02f44b7f5403f23d20beb07018a685bf807500132f4d04868ca68033020f0030000f110060beb08001032f6f7e7fa4168c2684bf808608368d4f86cb18a424ff00001b04408bf00f110014bf82310d7e7c8f5403200210f2ac4f800130dd90beb08034ff0ff304bf8082059609860d960c4f800831bb0bde8f08f00281ebf0168114401604ff0ff301bb0bde8f08f00bf02293cbf4ff0ff3070472de9f04f8bb00278437842ea0325b5f5007f00f2148105eb4502022303eb4202914240f00c810590fcf7dbfe002800f006814ef66c694ff29c564ff62c48ccf2ff09c2f229064ff6ff77cff6ff7800244ff0010b06e048f2a351c0f24501bff32f8f8847d6f800a0bff35f8f3068bff35f8f01466ff39601b1f1005f03d10168494500f0bc804ff47570fdf722fe002800f0d58041464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470afc0f8009080f80ab08783c783078447848784c784078547858785c785078647868786c7860787478756e8001f51457ff437afbff35f8f00bf46e8000121b156e8001f5145f8d02be7d0f86cc10495bcf1000f20d000234ff4006104e03f683944b1f5403f0bd20ceb0107be680136f5d07e68033626f0030633441033eee775b9b3f53e3f40f2e0804ff0ff310bb0bde8f04f08467047002d00f0d680002305994ff0000901f1020a153103914ff0ff31059109eb49060aeb46056c784ff0ff31012ce3d8af78ea7857ea022e1ebf2a796d7952ea0528d9d0bef5207fd6d8b8f5f07fd3d80ef10102520802fb08fb4ff6fb724ff6ff779345c0f20207c6d81af81610059e41ea0421039cb9f1000f28d014f8132c14f8125c42ea05228a42b3d0feb114f80d2c14f80c5c42ea05228a42aad0012e15d014f8072c14f8065c42ea05228a42a0d0022e0bd014f8012c257842ea05228a4297d0043e721c04f11804d6d15646bcf1000f2fd00bf105054ff400640ceb040adaf808208a4230d0daf800201444bc4220d80ceb040adaf808208a4225d0daf800201444bc4215d80ceb040adaf808208a421ad0daf800201444bc420ad80ceb040adaf808208a420fd0daf800201444bc42d3d94ff6fc720bf10801c0f201021140194401f1100320e0daf80410a9427ff44fafdaf80c10a9427ff44aaf9af8101004297ff445af9af811109af8122041ea022171457ff43caf9af813109af8142041ea022141457ff433af049909f1010989450599b24601f1010105917ff43dafb3f53e3f3ff624af00240025019019e000211fe7d0f86cc14a688b684ff6ff7793454ff00002c0f20207c1f80cb008bf01f110024cf82320013575454ff000013ff408af05eb45000aeb40011af8100091f8018091f802e091f803b091f804904979bcf1000f40ea082605912cd0b8f1010f29d84ff400610ceb01039a68b24200f0a8801a681144b9421dd80ceb01039a68b24200f09e801a681144b94213d80ceb01039a68b24200f094801a681144b94209d80ceb01039a68b24200f08a801a681144b942d7d94eea0b21059b013149ea0322490801fb02f75a4607f1050b8df81d004fea1b208df820004fea1b408df8210005208df82500042001218df8270048468df81b1003908df82a000df11b0011218df81c408df81e808df81fb08df822408df824408df823408df82640cdf808e08df828e091468df829208df82b30fff74df800287ff482ae01980021d0f86cc1bcf1000f3fd0ddf810e0b8f1010f3cd84ff400630ceb03018a68b24235d009680b444ff6ff71c0f202018b4226d80ceb03018a68b24228d009680b444ff6ff71c0f202018b4219d80ceb03018a68b2421bd009680b444ff6ff71c0f202018b420cd80ceb03018a68b2420ed009680b444ff6ff71c0f202018b42cbd9002104e0ddf810e02ee7ddf810e0002f3ff41aaf4fea0922029f059b42f001023a44039f1b0252083b4353435a1e032a01d200220ae023f0030700228e18043297427475b475f4753476f7d113f003033ff4f8ae01f11507012bbc543ff4f2ae3a44022b547018bf9470ebe62de9f04f81b04ef66c6b4ff29c554ff62c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0bd804ff47570fdf723fb002800f02e81414600bf4218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff43bafbff35f8f00bf45e8000121b155e8001fa142f8d02fe7d0f86813002974d104464ff41630fdf761fa014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8681300e00021084601b0bde8f08f00bf84464ff6ff7081424ff0000008bf7047f0b58fb04ff48057cde90670dcf87c73dde91646dde9145e0c90cde90d7006a8cde903606046cde901e46446009504f03bfa3eb130b99df8381094f88023114384f880130fb0bde8f04070472de9f04f8fb00446002047f64c68a4f88003c2f20708d8f80000002a8b461abfc4f874030146d4f87413401ac4f87c03fcf72cfa002800f07181d4f86803002800f06c8104f062fb002800f067810646b4f86c03002848d0a0f10108d4f87c0300254ff4a0714ff4f0774ff48059cde90d050df1180acde901152046414632464ff42073cde906950c95cde9035a009704f0e4f9002840f04181d4f87c034146cde90d050120cde902504ff4a0700190204632464ff420734ff4f077cde906950c95cdf810a0009704f0c8f9002840f025819df8380094f8801347f64c68084384f88003c2f2070806e0d4f8681330464ff41632f5f73efd4ef66c694ff29c57ccf2ff09c2f229074ff6ff76002506e048f2a351c0f24501bff32f8f8847d7f800a0bff35f8f3868bff35f8f01466ff39601b1f1005f03d10168494500f0c0804ff47570fdf71af9002800f0ec804ff62c41cff6ff7100bf4218463182f8d45382f8d55382f8d65382f8d75382f8d85382f8d95382f8da5382f8db5382f8dc5382f8dd5382f8de5382f8df5382f8e05382f8e15382f8e25382f8e35382f8e45382f8e55382f8e65382f8e75382f8e85382f8e95382f8ea5382f8eb5382f8ec5382f8ed5382f8ee5382f8ef5382f8f05382f8f15382f8f25382f8f35382f8f45382f8f55382f8f65382f8f75382f8f85382f8f95382f8fa5382f8fb5382f8fc5382f8fd5382f8fe5382f8ff5382f8005482f8015482f8025482f8035482f8045482f8055482f8065482f8075482f8085482f8095482f80a5482f80b5482f80c5482f80d5482f80e5482f80f5482f8105482f8115482f8125482f8135482f8145482f8155482f8165482f8175482f8185482f819547ff470af0121c0f8009081728683c683068446848684c684068546858685c685068646868686c6860687468757e8001f51457ff433afbff35f8f00bf47e8000121b157e8001f5145f8d027e7054604f023fa002d18bf002803d101208bf8050022e0c5f860014ff001094ff4f07085f8649101904ff420704af61f460090c0f2470600200021002200230027b04730b185f86471c5f860718bf8059004e09bf805008bf8049030b14ff0ff300fb0bde8f08f0025cbe794f8800384f8810348b3d4f8700342f66535c0f2440528b1d8f800102d31c4f8781311e044f2eb60c0f200007844002122460023a847c4f87003d8f8001001f12d01c4f8781320b105f1e8022d21904728b1002084f881030fb0bde8f08f00200fb0bde8f08f80b582b04ff4f0704af61f4e01904ff4207cc0f2470e0020002100220023cdf800c0f04702b080bd022a3cbf4ff0ff3070472de9f04fadf2fc4d1d460f784b780a4457ea032301f10204239302f08383229040a806300027169021951f92944202f07383601c904202f06f8320786178a31c40ea0121d01a81422793289102f26483ddf82005ddf834252f90ddf82405ddf82c153090ddf828054ff00008319010683291411e002825972e95116002f04c832898002802f048832898871c032f02f04383e678032e02f23f83279890f80090f00702d104f1040e27e0289820f00100022802f0318394f804a0657922984aea052b59462eaa02f036fb002842f02483ddf82c0504f1060e012d32900dd8ddf83405806948b14feadb020af00701835c012505fa01f119438154022e04eb070203d2ddf82cb528e000bf964503d0744614f9015b01e00025144645f64d57c0f24607f2469346b847012808bf0135681e81b26e0800ebd130002d48bf4610b8470128ddf82c0508bf76423044da45a6465a468346329002f0df82b9f1040fcdf8b0e02addb9f1060f40f3e480b9f1070f00f07782b9f1080f00f05081b9f1090f42f0ca82964502f0c7821ef8011b964542f0c2820f2902f2bf82ddf83005002800f0d787dde930232e9801eb01115a43f5f7d3fb00f0cdbf00bfb9f1020f2adcb9f1010f00f04d81b9f1020f42f0a4822e9800272c902f98964529903098cde938e22a9031983a972b90ddf834053597c069349000f0ff820ef1010038909ef80070904200f0f7820ef1020038909ef801000502f2e2b9f1030f00f07981b9f1040f42f07982b2eb0e0402f075820ef10100904202f070822298002802f06c82a01e0528c2f068820ef10700904242f063822298d0f86c01002802f05d829ef80110012902f258829ef8003043ea012250f82210002902f04f820f1ab90742f04b826ff4403140f60f063944cff6fd76b142c2f04182384450f8081c914242f03b8250f80c1ca1f1011616f5803fc2f03382002802f0308250f8046c8e4242f02b82c7f54037b94202f22682ddf83475bf6947b1d20803f00703be5c012505fa03f33343bb54dde92e69dde93075002238ab02f06cfa00284ff0000a08bf4ff0ff3a00f0d181ddf830052d971f9a259f002801f0ef87072c4ff0ff3a41f0ea87002e01f0e787fbf7d0fe002840f02a8400f091beb9f1050f00f0ba81b9f1060f42f0ea81964502f0e7810ef10100904202f0e2810ef10200904202f0dd810ef10300904202f0d8810ef10400904202f0d3810ef10500904202f0ce810ef10600904202f0c9810ef10700904202f0c4810ef1080ca2eb0c000828c2f0bd810ef11000904242f0b8819ef804009ef8051050ea01261ebf9ef806009ef8071050ea012502f0a9819ef800009ef801202f9940ea0224081bc2f09f81864202f29c819ef802009ef80330309a40ea0327d01bc2f09281854202f28f81ddf83005002800f0a7862e98319bcde9045ccde90276cde900b403f029fd00f09bbeddf8340540adc06938afdde92e49dde9306acde9380828463946cde940e2cdf8088102f030fc80462846394602f02bfc4299002900f07f82219d259f4ff0ff3a1f9a01f04abf964502f05881714611f8010b012802f252812e9b00282a932f9b1d922d93309b2c93319b2b9300f03583914202f043810ef10201914202f03e810ef10301914202f039810ef10401914202f034810ef10501914202f02f810ef10601914202f02a810ef10701914202f025810ef10801914202f020819ef801109ef802209ef8043041ea02219ef803209ef805709ef8064042ea03269ef807209ef8083047ea04240ef10907189742ea032213e3a2eb0e0abaf1050fc2f0fe800ef10505954202f0f9800ef106079ef80540d01ba042c2f0f1803819904242f0ed802e981b902f982d903098249031981a90b4b1002603e000bf0136a64210d2b85d01381e28f8d9b819a11b40aa38ab02f0d7ff002802f0d18040980644a642eed3ddf83005002800f0e585baf1050f02f0c4801b98002802f0c080fbf797fd002802f0bb802d78a81d824542f0b68047f65420c2f20700d0f80080b8f1000f02f0ac8098f80c0098f80d1098f80e2098f80f3040ea012040ea024040ea0369a9f1810010f1800fc2f0988098f8100098f8111098f8132040ea012098f8121040ea014040ea02600d90813810f5817f42f28480002d4ff0000a00f07185002200240be000bf00f1004040a941f826000134ac4206f1010280f01385385d1646411e1e29efd93819291b38aa34ab02f068ff002800f05a853899349840aa0c4442f82600e5e7964502f058800ef10100904202f053800ef10200904242f04e809ef800009ef801102eaf40ea0121ddf834058ccf0490ddf83005319e03902298cde9016b009703f0fafc82461f9a259f01f022beb2eb0e0902f030800ef10100904202f02b80a9f102000528c2f026800ef10700904202f021802298002802f01d800ef108009ef807702d90101ab842c2f014802d983844904242f00f802298d0f86c31002b02f009809ef80100012802f204809ef8001041ea002053f82020002a01f0fb87d21a960741f0f7876ff4403640f60f051644cff6fd75ae42c1f0ed879e1856f8083c834241f0e78756f80c5ca5f1011313f5803fc1f0df87002e01f0dc8756f8043cab4241f0d787c2f54032954201f2d287ddf83425926942b1c00801f00701135c012404fa01f119431154c12dc1f0c2873078012841f0be872e98002f2b902f982a90309829903198269055d0ddf8b4a0a6f13f0401e0013f4ed01af8010b411e1f29f8d341b22029c1f2a48704eb400114f81000497840ea0122c12ac1f09a873046294640ab01f0f0ff0028e3d101f091bf01203a90002538ae34ac3046214602f04dfa2d903046214602f048fa3a9906460029269545d04ff0000a002024900120d9463a9000200df1e00b34ac20905846214602f033fa05465846214602f02efa3a9900294ad01f9a4ff0ff31219d259f8a4601f04dbdddf83005002800f07684b9f1080f4ff0ff3acdf80081c1f03d852b98259f002801f03985fbf723fc002800f0e6832c99cd7905f10800814540f0df8308784f7891f8069040ea072600f061bcdde938018842b5d0024612f801ab8a423892b1d0821c389243788a424aea032aaad0c21c389283788a422493a6d0011d3891c078d9460002a4e78446dde938011f9a88424ff0ff31afd1ddf8b4e0bef1000faad4002ea8d4ddf834353598196aab460843269d186229983d4341904ff6fe7085422b982c9b2a9c439022984093429400f023854ff6ff718d4240f0fb84d0f868534ff4207041904ff4f07042904ff4a070439000f012bddde94021219d259f8a42cdf8b4903ff47aad531c8b423ff476ad931c8b423ff472add31c8b423ff46ead131d8b423ff46aad531d8b423ff466ad931d8b423ff462add31d8b423ff45ead02f108038b427ff459ad11785378b646d14651ea03264ff0ff3a01f0b7849378d77853ea07232b9301f0b084b6f5207f01f2ac842b9b259fb3f5f07f3ff640ad93790f2b1e933ff63badd17910292a913ff636adddf83435299039981f6a11793843ddf830755279002f2494186201f082840beb0600404280454ff0000ac1f285842d985b46a0eb0b00804581f27e842b9847422998b842c1f278842998dde924c786457ff70cad41ea0221b1eb560f28bf71082b98b1eb500f28bf41081891013938bf51460f9129994a4202eae174aeeb01018142a8bf01468c421d91bff6efacddf860e008eb03004fea4e010efb0ef21b9191001791311820910021032e38bf01212b9b0022032b38bf012211431591591e1491991e12910f991c904a00494389000c912a990130109008010e9041ea01106ff008010d9001eb4e00139029984ff0000b20eae07109fb01c011922c9000201a9001f0dab9914201f00e860ef10201914201f009860ef10301914201f004860ef10401914201f0ff859ef802209ef8011056009ef803209ef8043094000ef10502890018925a001d9b002c199201f0eb85199a002a01f0e7852d9a521ac1f0e385944201f2e0852c9a921bc1f0dc85199f974201f2d885002800f0f08001eb0b020025f9e048f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914201f045804ff47570fcf7fef9002800f049824ff62c41cff6ff7100bf4218463182f8d48382f8d58382f8d68382f8d78382f8d88382f8d98382f8da8382f8db8382f8dc8382f8dd8382f8de8382f8df8382f8e08382f8e18382f8e28382f8e38382f8e48382f8e58382f8e68382f8e78382f8e88382f8e98382f8ea8382f8eb8382f8ec8382f8ed8382f8ee8382f8ef8382f8f08382f8f18382f8f28382f8f38382f8f48382f8f58382f8f68382f8f78382f8f88382f8f98382f8fa8382f8fb8382f8fc8382f8fd8382f8fe8382f8ff8382f8008482f8018482f8028482f8038482f8048482f8058482f8068482f8078482f8088482f8098482f80a8482f80b8482f80c8482f80d8482f80e8482f80f8482f8108482f8118482f8128482f8138482f8148482f8158482f8168482f8178482f8188482f819847ff470af4ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001f2c9ba1427ff421afbff35f8f00bf42e80001002900f07f8752e8001fa142f6d013e701eb0b025feacb704ff0000506d1002a04d42d99a0188842d8bf01251899199f581a1590ddf8300507fb04feb0fa80f040092843c0074ff0000b1c900f46002017952990cdf868e013e000bf29982699084429901e98249981424ff0000088bf01204bea000b209f5feacb7008bf0f441d9b5feacb7005d02998864509d801f0a4bc00bf9f4200f09c812998864540f29881dd1b01f099843878030902d0012112e000bf012d01f090847b780bb102210ae0042dc1f08984b978fb7851ea032301f08384042100bf24912999aeeb01018b4201f27a841c99269300291e952097b4d1269900f00f084b1e032b4fea0019cdf86cb074d24ff0000c2698dde91aeb10f0030aa2d029986044b0fbf4f101fb14078b19174453ea070115d42d998f4212d22c998b420fd2dde92a5103fb01517b08cd5cff0705f00f0c05f0f005454408bf4cea0905cd54baf1010f3ff47eaf411cb1fbf4f303fb141133448f1853ea070115d42d998f4212d22c998b420fd2dde92a5103fb01517b08cd5cff0705f00f0c05f0f005454408bf4cea0905cd54baf1020f3ff45aaf0230b0fbf4f101fb14008b19104453ea00013ff54faf2d998842bff44baf2c998b42bff447afdde92a7103fb01714308cf5cc00707f00f0507f0f007474408bf45ea0907cf5435e721f0030b4ff0000c05e000bf0cf1040ce3453ff482af299800eb0c0abafbf4f303fb14a703eb060e17445eea070315d42d98874212d22c9886450fd2dde92a107d080efb0013ff07585d00f00f0100f0f000404408bf41ea090058550af10100b0fbf4f101fb14008b19871853ea070015d42d98874212d22c9883420fd2dde92a1003fb00107908435cff0703f00f0503f0f003434408bf45ea090343540af10200b0fbf4f101fb14008b19871853ea070015d42d98874212d22c9883420fd2dde92a1003fb00107908435cff0703f00f0503f0f003434408bf45ea090343540af10300b0fbf4f101fb14008b19871853ea07008ad42d988742bff487af2c988342bff483afdde92a1003fb00107908435cff0703f00f0503f0f003434408bf45ea0903435471e74ff0ff3a01f04ab9002acdf8ac9000f0ee812c9f9146a2f1010a002540ac09e02c9faa4505f10105a6f1010604f1040400f0d98140a850f825100029f1d400202b4686421dd004eb80077a68b2f1ff3f18dc5a1c924514d0ba68b2f1ff3f11dc9a1c92450dd0fa68b2f1ff3f0adcda1c924506d03a690433002a00f10400e0d400e00022404638ab34af009702f0a8fa78b134980028c3d04af20d3138a8c0f24e018847bce7cdf8ac9001204ff00009a0e14ff0ff3afff7ccba9f4241f001832998864541f0fd82ddf83005002818bf012017990840012810d1dde92a03159906fb0300670800eb5202199800970190189801f0b5fb002801f0e3821f9a259f219d01f0d1b848f2a351c0f24501bff32f8f88474ff29c50c2f229000468bff35f8f00680321cff680710140b1f1005fbff35f8f07d101684ef66c62ccf2ff02914200f030844ff47570fbf70bff002801f0a1804ff62c41cff6ff714218463182f8d48382f8d58382f8d68382f8d78382f8d88382f8d98382f8da8382f8db8382f8dc8382f8dd8382f8de8382f8df8382f8e08382f8e18382f8e28382f8e38382f8e48382f8e58382f8e68382f8e78382f8e88382f8e98382f8ea8382f8eb8382f8ec8382f8ed8382f8ee8382f8ef8382f8f08382f8f18382f8f28382f8f38382f8f48382f8f58382f8f68382f8f78382f8f88382f8f98382f8fa8382f8fb8382f8fc8382f8fd8382f8fe8382f8ff8382f8008482f8018482f8028482f8038482f8048482f8058482f8068482f8078482f8088482f8098482f80a8482f80b8482f80c8482f80d8482f80e8482f80f8482f8108482f8118482f8128482f8138482f8148482f8158482f8168482f8178482f8188482f819847ff470af4ef66c61ccf2ff010160012181724ff6ff714ff29c528183c183018441848184c184018541858185c185018641868186c18601874187c2f2290252e8001fa1427ff423afbff35f8f42e80001002900f06c8352e8001fa142f6d016e7294640aacdf89890e14601f0fdf900287ff485aaddf834051f9a8069ddf8b4e0cc462c9b2a9cddf8989060b1b8eb552f09d1ea0807f00701855c012707fa01f1294381541f9a409d5746002d3ff468aa002f4ff0ff313ff465aaca4699462498209b03433ff45eaa41987045fff45aaaa0eb0e0087423ff655aa4298b042fff451aa801b83423ff64daaddf83005002100283ff447aaabf1011010f1021f7ff641aa2998a0460beb0a048442b8bfc445bff638aa784284427ff734aa584284457ff730aa04eae471aeeb010a0f44299924eae4700ceaec7b0beb030e2ceaec720b1a9f4238bf3b46a8eb0207be451e92269728bfbe464d45a6eb0b071d970b95cdf854e000f07387002700f089bf00204ff0000a03e04ff0000901202c9f39790f248d0601f00f0604eae575754389246543ed0a97f800c08df8d0500e257a78bb78ff782c9111f0200f08bf012506fb05f504fb05f54fead5258df8d1504ff00d0508bf022506fb05f504fb05f54fead5258df8d2504ff00c0508bf032506fb05f504fb05f54fead5258df8d3504ff00b0508bf042506fb05f504fb05f54fead5258df8d4504ff00a0508bf052506fb05f504fb05f54fead5258df8d5504ff0090508bf062506fb05f504fb05f54fead5258df8d6504ff0080508bf072506fb05f504fb05f54fead5258df8d7504ff0070508bf082506fb05f504fb05f54fead5258df8d8504ff0060508bf092506fb05f504fb05f54fead5258df8d9504ff0050508bf0a2506fb05f504fb05f54fead5258df8da504ff0040508bf0b2506fb05f504fb05f54fead5258df8db504ff0030508bf0c2506fb05f504fb05f54fead5258df8dc504ff0020508bf0d2506fb05f504fb05f54fead5258df8dd504ff0010508bf0e2506fb05f504fb05f54fead5258df8de504ff0000508bf0f256e436643219df60a00288df8df6040f00b82120642ea0c4138060beb214a2b9940ea0340a9f1010601eb204000240c90cdf84080cde90e6907e001f01f000b3801344c45824400f0ea8140a850f82410b1f1ff3ff1dd23469e421cd040a800eb83004268b2f1ff3f16dc0133b34212d08268b2f1ff3f0fdc0133b3420bd0c268b2f1ff3f08dc0133b34204d002690133002ae1d400e00022404638ab33af009701f0e3ff002800f0bd8133990029189100f0ae819df8e8009df8e910129450ea012ecdf850a000f090819df8ec709df8ed603f049df8e7009df8e61047ea06670d9e4fea002c41ea00229df8ea0076449df8eb3006eb27470c9e0004149d40ea0360f41b0126031405eb204a06eb520015900ceb01001e92421e199201f003020af1010113910af1020111911899ef18eb1a01f1010906eb5001801a2b90d8074ff0000c2a90f807269120922990cde91c4e07e000bf26980cf1010cf445814400f043811ceb0400f5d424998842f2d21e990029efd0dde91a21002600fb02181998032880f097802098dde91c4e0028e1d01898159901220cfb01072c987108795c00f0100082ea101301f00f00cab25feac67b08bf10090146002818bf01211943012917d116eb0a0514d42d998d4211d2690818f80120179734af385c02f00f0702f0f0020243ed0708bf47ea0012179f08f8012020980128acd0701c4008385cbbf1000fc1b24fea111e08bf00f00f0e5ffa8ef0002818bf01201843012818d11398801915d42d99884212d2410818f8012034ac179714f80e7002f00f0502f0f0023a43c00708bf45ea0712179f08f801202098dde91c4e02283ff47bafb01c4008385cbbf1000fc1b200f00f0008bf08090146002818bf0121194301297ff469af119973183ff565af2d998b42bff461af590818f8012034af385c02f00f0702f0f0020243db0708bf47ea001208f801204fe7ce4606e02b980436b0420ef1020e3ff460af2c981ef8015c00f01000012181ea1013edb200200f2d88bf0120184301280aeb060016d1002814d42d99884211d247082d0918f8071034aa555d01f00f0401f0f00129435feaca7208bf44ea051108f807101ef8011c11f00f0b594618bf01211943012917d1451c15d42d998d4212d2690818f8012034ac14f80b4002f00f052a9f45ea041502f0f002002f08bf42ea040508f801509ef80010cdb200210f2d88bf01211943012916d1871c14d42d998f4211d27a08290918f8024034ad695c04f00f0504f0f004299f0c43002f08bf45ea011408f802409ef8001011f00f05294618bf0121194301297ff482af03303ff57faf2d998842bff47baf400818f8001034aa525d01f00f032a9c43ea021301f0f001002c08bf41ea020308f8003067e74af20d3138a8c0f24e0188479df8e4009df8e510219dddf84080ddf850a0dde90e69129c03e09df8e4009df8e51040ea012010e64ff0000a01e04ff0ff3a1f9a259f00f07dbcd0f86c114ff0ff3a002900f07384012f259f00f2708451f82600002800f06b84401a820740f067846ff4403240f60f030244cff6fd739a42c0f05d840b1853f8081cb14240f0578453f80c6c0022a6f10111cff6ff729142c0f04d8453f8041cb14240f04884c0f540308642249600f242849846002b00f03d842498259fc128c0f0398498f80000012840f033844fea89660f2409f00f0704eae6767e43892466432c9af60a8df8d0600e269178d3781079527919f0200f08bf012607fb06f604fb06f64fead6268df8d1604ff00d0608bf022607fb06f604fb06f64fead6268df8d2604ff00c0608bf032607fb06f604fb06f64fead6268df8d3604ff00b0608bf042607fb06f604fb06f64fead6268df8d4604ff00a0608bf052607fb06f604fb06f64fead6268df8d5604ff0090608bf062607fb06f604fb06f64fead6268df8d6604ff0080608bf072607fb06f604fb06f64fead6268df8d7604ff0070608bf082607fb06f604fb06f64fead6268df8d8604ff0060608bf092607fb06f604fb06f64fead6268df8d9604ff0050608bf0a2607fb06f604fb06f64fead6268df8da604ff0040608bf0b2607fb06f604fb06f64fead6268df8db604ff0030608bf0c2607fb06f604fb06f64fead6268df8dc604ff0020608bf0d2607fb06f604fb06f64fead6268df8dd604ff0010608bf0e2607fb06f604fb06f64fead6268df8de604ff0000608bf0f26774367434ff0000aff0a002d8df8df7000f06a831b0643ea01410beb2144110641ea004000142d9e2090c9f30010a8f13f0a2f461e903de32c9bd0f86c014ff0ff3a002800f051835978012900f24d831a7842ea012150f82120002a00f04583121a930740f041836ff4403340f60f071344cff6fd77bb42259fc0f03683104450f8083c8b4240f0308350f80c1c0027a1f10113cff6ff77bb42c0f02583259f002800f0228350f8043c8b4240f01d83c2f54032914200f21883002240ab00f082fd002800f00e832c9f0f24f978b8787b793a79090641ea0040190641ea0241ba790beb2040970602f00f0304eae7775f4389246743ff0a8df8d0700e2712f0200f08bf012703fb07f704fb07f74fead7278df8d1704ff00d0708bf022703fb07f704fb07f74fead7278df8d2704ff00c0708bf032703fb07f704fb07f74fead7278df8d3704ff00b0708bf042703fb07f704fb07f74fead7278df8d4704ff00a0708bf052703fb07f704fb07f74fead7278df8d5704ff0090708bf062703fb07f704fb07f74fead7278df8d6704ff0080708bf072703fb07f704fb07f74fead7278df8d7704ff0070708bf082703fb07f704fb07f74fead7278df8d8704ff0060708bf092703fb07f704fb07f74fead7278df8d9704ff0050708bf0a2703fb07f704fb07f74fead7278df8da704ff0040708bf0b2703fb07f704fb07f74fead7278df8db704ff0030708bf0c2703fb07f704fb07f74fead7278df8dc704ff0020708bf0d2703fb07f704fb07f74fead7278df8dd704ff0010708bf0e2703fb07f704fb07f74fead7278df8de704ff0000708bf0f277b436343db0ac2f3001209148df8df30049234aa2d9b0392cde90001304629464a4640af4ff0000a029701f077fc30e2dde924c7199cca462c98013450442c901d984ff0000a8442bef6d9aa2b9ae14311448c42b8bf21461b986fea41010144012966db1798189a01fb1101a2eb0b024ff0ff33012a03eb420235db02fb02f38b4231dd1398a0eb4b0303f10807032f03f106021fdb02fb02f68e421bdd052f03f104021adb02fb02f68e4216dd072f03f1020215db02fb02f68e4211dd0bf1040b092fa3f1080203db5b438b421346dbdc083207e00bf1010b04e00bf1020b01e00bf1030b259fbbf1010f23db0832931f5b438b421edcbbf1020f19db131f5b438b4200f3bd80bbf1020f11d0931e5b438b4200f3b880bbf1040f09db02fb02f38b4200f3b380bbf1040b02f10802ded14ff0000b1c98ca460beb0002299821182a9801fb09c310282098a0eb0b080bd101202d991e9e019018464346009602f012f9ddf890c066e7b4fa84f1159849090143269349d11498844246d01299601e091b19948842b8bf01466fea4100119908440128c0f2a4800c991a9b00fb10100f99cb1a4ff0ff31012b01eb430176db01fb01f7874272dd59001a9ca1f1090303f10807032f03f1060162db01fb01f686425edd052f03f104015cdb01fb01f6864258dd072f03f1020156db01fb01f6864252dd0434092fa3f1080103db5b4383420b46dcdc083148e02d9822eae27c8045a8bf8046c445a3da5feacc7019940ad026994fea5c000a5c2a9b02f0f0021a430cf1010c0a544fea5c02b2eb580f1ad226982c9f0d9900eb5803bc18264606f8011b9e4280f08180a01c9842317080f08180e61c9e4201707bd20437b81898423170ead376e0269800eb5c0072e0abf1010b56e7abf1020b53e7abf1030b50e7013402e0023400e003341a941a9c012c1edb08318b1f5b43834219dc022c16db0b1f5b43834200f3c780022c0fd08b1e5b43834200f3c280042c08db01fb01f3834200f3bd80043c01f10801e2d100241098ddf8b4a000eb040c22eae27ed445b8bfe246d6451a944fda5feace700ad026994fea5e000a5c2a9b02f0f0021a430ef1010e0a544fea5e07b7eb5a0f18d226982c9c0d9900eb5a06e019034603f8011bb34213d2821cb242197021d2c31cb34211701cd20434e219b2421970ecd317e0269800eb5e0213e0601c02e0421c0fe030465feac8723ff460aec445bff45dae01780e9a01f00f011143017055e61a461a9c5feaca7007d0d64505d210780e9900f00f00084310702099e0430e1801202d9c019026981e9f214662463346009701f0e7ff26eae67ca045a8bfa046c445bff633ae5feacc710ad026984fea5c01425c2a9b02f0f0021a430cf1010c42544fea5c02b2eb580f18d226982c9f00eb58030d98bc18264606f8010b9e4211d2a11c9942307010d2e61c9e4208700bd20437b91899423070ecd306e0269800eb5c0102e0611c00e031465feac8723ff4fcadc445bff4f9ad08780e9a00f00f0010430870f1e5013c49e7023c47e7033c45e7013f00f0d08116f8010b411e1f29f7d341b220290fdb0aeb40011af81000497840ea0122c12a06d32499404638ab00f073fa0028e4d14ff0ff3a259f1f9a219dbaf1000f40f00d82239801378742dde9270100eb01047df48eae08e2259f4ff0000afef7a0b8dde91d67b74204dd012710e0259ffef797b8dde91d675045a7eb0607b7fa87f74fea57174ff00006c8bf01263740ddf854e0bef1000f199700f07e814fea5a044ff0040c14942cea8a0413940aeb030403eb0009013c00f0010509f00106670812972cea8407ac1911971f1b249b209a05eb000cd4188aea0002400810904fea5900ddf898800f9004eb0b007908404538bf804601200aeb0503cdf898801a91012988bf7808ddf82cb000f0030120f0030a580820900beb53000a904fea5c001c902c984ff0000800eb5c0001300990d0071b904398ddf864c02d904ff0ff3000eb57000d90c7f341000c906ff0010000eb570008906ff0020000eb57000e91179707901895249607e0269808f1010880454ff000013ef40eaa6fea08014046bcf1000f18bf0eeb01001d9900eb01022d9902fb01b10db9002305e0149b139ccb5ce34003f00f032a930eb9002304e0129b119ccb5ce3401b0129931e9b0344dde92b0403fb00491b9c1c98002c209c484421441ed11a9af3f7d9f9dde9185cddf854e045b110992a9a19f8010000f0f000104409f80100249e1f9a002eb4d00f99299b19f8010000f00f00184309f80100aae72d9cbcf1000f04fb02f25bd0179b022bded30c9b002b1a9b23d01a9b0d9ccb5c0f5dc3f3031343ea071303550c9b012b234616d00d9b089ccb5c0f5dc3f3031343ea071303550c9b022b234609d0089b079ccb5c095dc3f3031343ea0111234601550d990329b3d30a991144ca18cf5c12f8016cc7f3031747ea0617c61806f8017c12f8017c12f8024cc7f3031747ea041706f8027c12f8027c12f8034cc7f3031747ea041706f8037c12f8037c12f8042cc7f30317043b47ea021206f8042cd4d185e7179c022cfff482af179f082f01d200222be02b9f5f430a9b03eb020c099a174400220ceb020674781cf80250c4f3031444ea0515bc1804f8015cb5787378c5f3031545ea0313bb54f378b578c3f3031343ea051363703379f6780432c3f3031343ea06139245a370dbd10e9bddf82cb0dde9185c002b3ff449af531ccf5c8e5c0e9cc7f3031747ea0617012c87543ff43daf971cce5dcc5cc6f3031646ea04160e9cddf82cb0022cc6543ff42faf0a44d278c95dc2f3031242ea0111c15525e71f9a0021fef7fbb82098ddf800b120eae0702c9004e020440b38013d04464ed02d9911f8010b1f282d91f4d90aeb40011af81000497840ea0122c12afff42cae2499404638ab00f098f800283ff424ae1e98299e049034a8039038a80290dde92a70ddf8809026993a463346cdf80490009401f058f8dde93a013b46204401eb0902b84224eae471b8bf0346b242a8bf32468b42c1dd2c9fba42beddbbf10f0fbbd82c9e169c921b5b1a04ebcb0724f83b100bf1010b7e80bb80fa80ade74ff0000aebe54ff0ff300df2fc4dbde8f08fa01a18bf4ff0ff300df2fc4dbde8f08f00bfb0b586b008b3d0f86c01f0b10023b3eb512f1ad150f82130bbb11b1a9d0714d16ff4403540f60f041d44cff6fd74a5420bd3184450f8085c8d4206d150f80c1ca1f1011515f5803f03d24ff0ff3006b0b0bd50f8045c8d42f7d1c3f540339942f3d80028f1d0037813f00b0fedd1144601ab0022002500f00ff80028e5d00198dde903122060481c40086160a260e0602846256106b0b0bd91429cbf002070472de9f041855c4ff0050c6e0758bf4ff0030c15f0f30f02d1891a614502d20020bde8f0818418627894f802e0002e05d5e078267942ea0e2240ea062e002a4ff0000018bfbef1000fead0b2f5207fe7d8bef5f07f88bfbde8f081082d38bf0120072d18610ad8501c400800fb0ef0a1eb0c018842d3d804eb0c0828e004eb0c080efb02f5002000bf00eb0c04a142c6d008eb00073e78360903d00127b54213d2bde70c1b012cbad07e781eb10227b5420ad2b4e7042cb2d3bc78fe7854ea0626add00427b542aad3ad1b3844dcd158600120c3f800809a60c3f80ce0bde8f0812de9f04f89b0dde91257069005fb07f000294fea4007029100f0d48100200390089002984ff0010e00264ff0000b4ff000084ff0000c4ff000090497079205930be000bf4ff0000c4ff00308cdf80ca009f10109814500f0ba81bcf1000f40f0b4810699b8f1020f11f809a0ead0b8f1010f15d0ddf81cc0b8f1000f40f086805fea1a100af00f01089100f092800499814280f09a804ff0010c4ff0000882e1079abaf1000f00f07f800499514576d3a1eb0a010491089901eb01100901019114e000bfa15d089f01f0f0013943a1550136aaf1010a4ff0010eae4224bf00260bf1010bbaf1000f00f0598113998b45d1d20bfb0324bef1000fe3d0a91bb1eb5a0f88bf4fea5a0141b38d0804eb060817d0002208f10107a2eb850c6ff003057b1904350ceb05020432d870187158719871f5d1059b079a2f1d11f0030504d10ce0002711f0030508d0012d08f8070004d04744022d787018bfb870aaeb410abaf1000f0e440dd0129dae42b5d2a15d019f01f00f013943aaf1010a4ff0000ea155afe7129d4ff0000aa6e7039a52ea0a2213d004990392914280f08f804ff0010c4ff0000853e74ff0000c4ff002084ee74ff0000c4ff00108f4e000214ff0010c4ff00008039142e7089a091a049102eb02111201cdf80090019214e000bf1af80670089a07f0f00717440af80670013601384ff0010eae4224bf00260bf1010b002800f0d680139a934580f0cd800bfb03cabef1000fe2d0ad1bb5eb500ff14688bf45087db3ac080aeb06081ed0002308f10107a3eb840c6ff0030400bf07eb040e04340ceb040304338ef803108ef804108ef805108ef80610f0d1059bddf81cc0271d15f0030404d10ce0002715f0030408d0012c08f8071004d04744022c797018bfb970a0eb45002e4488b1129dae4210d21af80620019f02f00f023a430af8062001384ff0000e0028abd180e000bf129d0020ce469de7891a0491089901eb011009010191114613e000bf1af80620089c02f0f00222430af80620013601394ff0010eae4224bf00260bf1010b002953d0139a9345bff4ccae0bfb03cabef1000fe3d0ad1bb5eb510f88bf4d085db3ac080aeb060819d0002208f10107a2eb840c6ff0030400bf3a1904340ceb04030433d070107150719071f5d1059bddf81cc0271d15f0030404d10de0002715f0030409d0012c08f8070005d04744022c787018bfb87000bfa1eb45012e4489b1129dae42b6d21af80620019f02f00f023a4301394ff0000e0af806200029b0d103e000bf129d0021a4e74ff000084ff0000c029852e64ff0010c4ff0000803e04ff000084ff0000c0298ddf8009045e60120012107e04ff0010cb8fa88f0049f8cf001014009b7fa87f252091140084009b0bde8f08f00bf2de9f041826882b10121816007220020511e20fa01f1c90708bfbde8f0814ff0ff3191400843bde8f0818c46056841688d42e9d06b1c03602c78ff2c11d18b4200f0dc80ac1c046095f90120b2f1ff3fd6b200f3d080bf2e22d806f03f0602238fe062b2b2f1ff3f02dd07222046cfe7bf2c09d804f03f070e224ff0010e4ff000084ff0000c2ee0df2c0fd804f01f0715224ff0000c4ff001084ff0010e22e0df2e0fd806f01f0603236ae0ef2c0fd804f00f071c224ff0010c4ff000084ff0010e10e0ef2e58d806f00f06042358e0f02c40f093804ff0000820224ff0000c4ff0000e00278b424fea072603d0af1c07606d7803e00125856000251f46c02c45ea06046cd35b1a7d1ab3fa83f3b5fa85f55b096d092b434fea042403d001258560002503e07e1c06603d783746b8f1000f44ea050453d17d1ab5fa85f56d092b434fea042403d001258560002503e07e1c06603d783746bcf1000f44ea05043ed1791ab1fa81f1490919434fea042131d001238360002030e0f02e3ed1002605234ff0010e00250127ea074fea062617d18c4215d0621c0260247801379f4246ea040623d000bf8a424fea062609d0541c0460127801371643bb422246f3d116e02246013701254ff0000e9f4214468560dad112e07b1c0360387840ea0104bef1000f20467ff413afbde8f08114465feace7202d0091b8e4204d9012181600020bde8f081a11907462046002263463960bde8f041ffe78446081ab0f5806f01d90020704761454ff00000fad0002a18bf70472de9f04fabb09fed251a9fed250a9fed253a9e4600264ff0ff380df12c090df10c0ab7ee002ab0ee084ab6ee005ab1ee006ab9ee007a00206746019009e000bf49f826500af8064001368f42bc4600f0cb8217f8012b501e01280fd8012a23d18f4274d09cf901000cf10207b0f1ff3fc5b240f38f8000220724f5e1052a37d0042a30d0032a49d1002e00f0d982701e59f820501af8004093e200bf0000004f000000cf000000008f4254d00cf102079cf801008f4247d09cf802200cf103078f4240ea02203fd09cf803200cf104078f4240ea024037d09cf804200cf10507130600223ae0002e00f0aa82013eace7022ec0f0a582b21e59f82230701e59f8205049f820301af802301af800400af8003049f822500af8024096e702f0f80010281fd1002e00f08b82701e1af80030002b40f0858259f82050152a6fd16d420022002406463de20023012206e001220724002588e101220020002343ea000501242fe2a2f12000062827d8002e00f06782731e1af80300002800f0618259f82300242a40f0858080f00045012400221e4617e2bf2d5ad801220292002205f03f000e244ff0000b00928f4200f019819cf802300cf10308002215e1322a51d002f0fe0030284dd0402a40f0a380032ec0f03682701e1af80020002a00f03082b21e1af80230002b00f02a82033e1af80630002b00f0248209eb8202d2ed000a09eb860209eb8000d2ed001ad0ed002a70eee10a62eea00a71eea00acee1002800f00e82023e1af80600002840f0088259f82600122a58dc102a00f03081112a00f03381122a40f02c81454354e1df2d44d8002205f01f00152400924ff0010b0122bae0002e00f0eb81a2f13100013eb0fa80f01af806304009834240f0e08159f82600302a7bd100ee900af8eee00a94e1002b00f0d481023e1af80630002b00f0ce8159f82630212a40f3ed80222a00f02581232a00f02981252a40f03a8100ee903a01ee900af4ee610af1ee10fa48bff0ee601a11ee905a71e1ef2d72d805f00f001c24012274e0a2f11303022b80f0c480002d00f0a381b0f1004f08bf15f1010300f0eb80132a40f0f18090fbf5f5f1e0a2f1480010f1070f4ff00000c0f05f81002e00f05c81013e1af80600002800f0858109eb8600d0ed000af4ee420af1ee10faf5ee400ac8bff0ee420af1ee10fa48bff0ee430a432a72ee601a00f3b480412a00f0f380422a00f00f81432a40f0008161eea10a72ee600a1de1312a40f0948000ee900a20f00040b0f1ff4f4ff00002f4ee410aa8bf0122f1ee10fa4ff0000080f21c81f4ee400af1ee10fa00f11681002a40f01381fdeee00a10ee905a98e0f02d4ff0000040f00981002220244ff0000b009202928f427ff4e7ae00230122b8460002c02d43ea000535d3781aa8eb0103b0fa80f0b3fa83f340095b0918434fea05270ebf18f8013b00230122bbf1000f43ea07051fd1a8eb0103b3fa83f35b0918430ebf18f8013b002301222f02009d002d43ea07050ed1a8eb0103b3fa83f35b0918434fea05230ebf18f8010b0020012240ea0305474602984ff0ff3838b1601e25fa00f0c0071cbf08fa04f005430024a3e0162a10d1a842b8bf054637e0202a4cd0212a51d100ee903a01ee900a70eee10a8ee005442ae0a842c8bf054626e0451b24e0002800f1c680def800200546824238bf15469042019888bf0120019015e0442a48d0452a5fd0462a4ed161eea10a61e00025132a4ff0000208bf4ff00045002469e090fbf5f202fb15050022002462e000ee903a01ee900a61eea00a57e000ee900af5ee400af1ee10fa00f0928001ee903ac1eea00a4ae000ee903a01ee900a71eea00a43e000ee903a01ee900af4ee610af1ee10fac8bff0ee601a11ee905a37e060eea01a70eea00a74ee600a61eea00a2ce0f4ee450af1ee10fa18d570eea01a60eea10a22e0f4ee450af1ee10fa15d560ee861a60eea11a60eea10a16e060eea00a13e060eea01a60eea10a0ee071eea10a61eea00a72ee600a07e061ee870a61eea00a61eea00a70ee820a10ee905a012400224ff000005ab9202e09d0002c3ff436ad25f00040b0f1ff4ffff630ad00202bb0bde8f08f56b3701e1af8001059f82000d9b102ee100a20f00040b0f1ff4f4ff00001b4ee412aa8bf0121f1ee10fa4ff00000e4dab4ee402af1ee10fadfd40029ddd1bdeec20a10ee100a019adef804101143cef804102bb0bde8f08f00202bb0bde8f08f80b5002970d090f900c0bcf1200f5ffa8cfc07db012010604ff0010ec3f800c0704680bdacf1c20ebef11d0f0fd801295ad090f9011011f1410f55dc02211160407800f03f006cf38a108446e4e70cf0f00ebef1e00f23d1032945d390f901e01ef1410f40dc90f9021011f1410f3bdcbcf1e00f5ffa8ef101d1a02934d3bcf1ed0f01d19f292fd80321116042784fea0c3189b2807802f03f0241ea821136e004294ff0000ebbd3acf1f50111f1050fb6d390f901e01ef1410f15dc90f9021011f1410f10dc90f9031011f1410f0bdcbcf1f00f5ffa8ef101d1902904d3bcf1f40f03d18f2901d9002080bd042111604ff4e011427801ea8c4c817802f03f02c0784cea023201f03f0142ea811100f03f0001eb000c7fe72de9f04188b04af2bb261c46c0f24e0613460a46ddf83880002706f1ae05214627706770a770e77027716771a771e77127726772a772e77227736773a773e77327746774a774e77427756775a775e77527766776a776e77627776777a777e777a8470028c8f800705cd020786178a278e3780843104318434ff0010008d0e179a27911431ebf617a227a51ea020102d108b0bde8f081a07b14284ff00000f7d1217d8df8040041f0010121758df805008df806008df807008df808008df809008df80a008df80b008df80c008df80d008df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f0001a92046b047c8f8000018b1012008b0bde8f08106f1520120468847d8f80000002818bf012008b0bde8f0812de9f04f91b00df1700b9be8400a10913169ddf868a0002900f05c813768bbf1000f40f05181874200f04e8199f80f100f2940f0498199f80e100e2940f0448199f80d100d2940f03f8199f80c100c2940f03a8199f80b100b2940f0358199f80a100a2940f0308199f80910092940f02b8199f80810082940f0268199f80710072940f0218199f80610062940f01c8199f80510052940f0178199f80410042940f0128199f80310032940f00d8199f80210022940f0088199f80110012940f0038199f80010002940f0fe80ddf86cc0caf10001d6f808e001eaea75ccf10001f76801eaec740895aeeb05062aeaea75391b2ceaec77521b9642a3eb07030d97b8bf32469942b8bf0b46012a0e930992c0f2ea820e990129c0f2e6820ef10101a4464c08089900eb55000c9048100b90042020ea81000790099801310138cde905014810049004fb0cf000f102094ff0000a0a94cde901c507e000bf0e980af1010a8245a14400f0bf821c98109bd0f800e00aeb0c0000fb04e20d980c9e504400fb0360eb0703d10b9edde9083810e00b9b2f46d35c079d0678eb4006f0f00603f00f03334400f8013b069bdde904683d469119da074fea58070f9208d13a468b466446f1f738ffa4460a9c68e000bf8b46b8f1020f63d37a1e032a04d2002117f0030237d15be06ff0030202ea58034e44c3f1000c0eeb0601461c039700bf8d18ef78ac78c7f3031747ea0417b418e7702f79eb78c7f3031747ea031323716b792f79c3f3031343ea07136371ab796f79c3f30313043243ea07130ceb02070437a371dcd1dde901c50a9c039f111d17f0030224d04b1cbe461bf803701bf80160c7f3031747ea0617012a4754774616d08e1c1bf806701bf80350c7f3031747ea0517029d022ac754774608d05944c9781bf80620c1f3031141ea021181555feac8713ff45aaf0f9a1bf80710002a4ff0000208bf0422c35dd14003f00f0242ea0111c15549e7874200f09f815c460021aae17568002d00f0068200214ff0000e09e0dde90e71d8f804503944dde91d9ba94280f0f881ddf870800f91d8f80060775c3c0901d0012117e06d1a012d00f0ea8106eb010c9cf8016016b1344602210be0042dc0f0df819cf802509cf8036055ea062400f0d781042117f00f07bbfa8bf60e914fea561619f807b018bf012746ea07091b9f4fea0b1c14f00301754600f09980d8f808504ff00008befbf5f60d9106fb15e55544b5f1ff3fc8bf4ff0010809ea080101291ad1f61918d4954216d29e4214d210990b9406fb01046e08a15ded070c916ff00f05594604bf0f256146ddf8308005ea08052943a1550b9c0d99ddf8708001290ef1010563d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080b91895ded070c916ff00f05594604bf0f256146ddf8308005ea080529430b9dddf87080a9550d990ef10205022930d0d8f80810b5fbf1f606fb115101eb0a050021b5f1ff3fc8bf012101ea090101291cd1f6191ad4954218d29e4216d2109906fb01016e080c91895ded070d916ff00f05594604bf0f256146ddf8348005ea080529430c9dddf87080a9550ef1030500bf611e0329a64405d220e700bf0435ae453ff41cafd8f808100024b5fbf1f606fb11515144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f808106c1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ac1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c19d1f61917d4914215d29e4213d2109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa155d8f80810ec1cb4fbf1f606fb114100245144b1f1ff3fc8bf012404ea0904012c7ff46aaff6193ff567af9142bff464af9e42bff461af109c5f4606fb04044e08c90714f806806ff00f0104bf0f21674601ea0801ddf8708039431b9fa1554be71b995c46002901dd012108e0b1fa81f149090027baf1000fc8bf01273940d6f808e0f76807fb0ef8b8f1000f56d0b4fa84f4bb4600274ff0ff3c6409c9070e940f9106e001370bfb0ef84745acf1010c44d20f990ef101050029394618bf08eb0c01b1fbfef46d0804fb1e161c99096804fb05117508495d042525ea8605e94011f00f08454618bf01250e990d43012dd8d116eb0a065cbf1b9d14eb0504d1d49642cfd29c42cdd2109d19f8081004fb050e74081ef80450f60705f00f0805f0f00545ea010508bf48ea01151c990ef80450d1f808e0d1f80cb0b3e711b0bde8f08f00bf2de9f04fc8b0dde95162549f1644ba1926eae6778a42b8bf11468f42039080f203815698cde90071a0f1030a6ff007076ff004044ff0000b0df1200e4ff000090293cdf810a000bf56984fea5903c05c4ff0100c00f0f0080590cde9064700bf1af8041f0eeb07001af8012c9af8013048ea121602f00f0242ea0802427248ea111201f00f01827241ea08010eeb0402117248ea13119af802500672517203f00f0141ea0801917248ea1511817305f00f0141ea08010837bcf1080c04f10804c173cdd10598ddf810a00401102753465d4600bf13f8040f0eeb050213f8011c5e7844ea111801f00f012143517444ea101100f00f002043d07444ea161093f802c0107506f00f002043507544ea1c1090750cf00f002043083f05f1080582f810809174d075d5d1079f069c09f1020920372034b9f1100f0bf1200b84d15598029bdde90086539900286dd00844079008f10100069003984fea580a03fb01074fea660c4feac87b06e000bf079809f1010181421f4457d20398894601fb0301bbf1000f45460bd011f80a00069d1ef8002000f0f00002f00f02104401f80a00bceb550f28dd680801eb0c033e4600bf315c06eb00081ef80120414601f8012b99421ed20a7808f102041ef802209c420a7018d221781ef80110217008f103049c4210d2217804361ef80110217034189c42ddd307e000bf01eb5504f00707d1b4e708f10104029bdde90086f007add0b542abda20781ef8001000f00f0001f0f00108442070a1e748b0bde8f08f00bf2de9f04f87b0149d6c68072c79d824b12f89b94275d0012c70d1002871d0d0f86c61002e6dd00027b7eb512f69d156f82170002f65d0a7eb060c5fea8c7760d16ff440370ceb070e40f60f07cff6fd77be4556d306eb0c0e5ef8086c8e4250d15ef80c6ca6f1011717f5803f49d35ef8047cb74245d1ccf54037be4241d8bef1000f3ed0032e3cd39ef80070022f38d19446aa69ddf84890dde91087ddf84cb09a469ab1c3464fead10801f0070401234f4612f80890a34043ea090302f80830b946d846ddf84cb0119f6c6805eb4402631c6b6011810ef10101721e63460595cde9039bcde90187cdf800a0fbf736ff69680139696007b0bde8f08f6f89b94204d14ff0ff3007b0bde8f08f022c3ff484afaf89b942f4d0032c3ff47eafef89b942eed0042c3ff478af2f8ab942e8d0052c3ff472af6f8ab942e2d0062c3ff46cafaf8ab9427ff468afdae722eae27c8b42b8bf19468c45a8bf704770b5dde904231ab913b1bde870407047b2f10f0e18bf9e465feacc730fd04fea5c03c45cbef1000f03d004f00f05aa4203d904f0f0041443c4540cf1010c4fea5c0400eb5c034d08bef1000f00eb510049d0ac425fd200bf1c78164604f00f05b2eb141f38bf2609954298bf154645ea06141d4605f8014b854267d25c78164604f00f05b2eb141f38bf2609954298bf15469c1c45ea061584425d7040d29c78164604f00f05b2eb141f38bf2609954298bf1546dc1c45ea061584429d702fd2dc78164604f00f05b2eb141f38bf2609954298bf154645ea06151c1ddd7084422346b9d31ce0ac4219d242ea021500bf1c4604f8015b844228d29c1c84425d700ed2dc1c84429d700ad21c1ddd7084422346edd304e01c46c80704d175e71c46c8073ff472af8c45bff46faf2078bef1000f03d0b2eb101f7ff667af00f00f0040ea02102070bde8704070475c1cc807e9d15ae72de9f04f81b04ef66c6b4ff29c554ff62c4848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0bd804ff47570f8f707fe002800f02e81414600bf4218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f800b080f80a908683c683068446848684c684068546858685c685068646868686c6860687468755e8001fa1427ff43bafbff35f8f00bf45e8000121b155e8001fa142f8d02fe7d0f87812002974d104464ff41630f6f7e9fa014600284ff0000069d0002200bf8b1888544032b2f5163f58709870d870187158719871d871187258729872d872187358739873d873187458749874d874187558759875d875187658769876d876187758779877d87783f8200083f8210083f8220083f8230083f8240083f8250083f8260083f8270083f8280083f8290083f82a0083f82b0083f82c0083f82d0083f82e0083f82f0083f8300083f8310083f8320083f8330083f8340083f8350083f8360083f8370083f8380083f8390083f83a0083f83b0083f83c0083f83d0083f83e0083f83f009ad1c4f8781200e00021084601b0bde8f08f00bf70b5044690f8800384f8810350b3d4f8700347f64c6642f66535c2f20706c0f2440520b131682d31c4f8781310e040f22f00c0f200007844002122460023a847c4f87003316801f12d01c4f8781330b105f1e8022d219047002808bf70bd002084f8810370bd00bf2de9f047a4b0d0f87442bff35f8fa4b142f691760546c0f2440620460021b04770b1d5f8700340b142f64d42c0f244022d2124b0bde8f047104724b0bde8f08747f64c69c2f20709d9f8007095f8810300283fd0f7f7f8fce0b3d5f87813781a17d495f8640110b995f80403e0b395f8800385f8810380b3d5f8700342f64d48c0f2440878b1d9f800102d31c5f878131de0d5f8700300b342f64d42c91bc0f24402904719e04ff64b70cff6ff70a8f1e807784400212a460023b847c5f87003d9f8001001f12d01c5f8781310b12d21c04710b1002085f8810306f16601204624b0bde8f04708474af21f37c0f2470700200290adf80c00b84795f8640110b995f8040318b12846fff746ffe5e70df104084046f5f70eff02a9284600224ff0000afbf74bfa81464046f6f74bf8b9f1000f02d085f881a303e00146284600f009f89df80c000028c7d107f14c008047c3e700bf2de9f04f90f8b13300f5617c4cf82310591c41f69a134b4390f8b0b31b0c03eb8303a1eb4301bbf1090f80f8b1139cbf0bf1010b80f8b0b3bbf1040f0bf0030e05d200244ff000094ff0000a2ee00bf0fc0800244ff000094ff0000a00eb8406d6f88473d6f88853b7fbfbf3d6f88c1303eb090203fb1b73b5fbfbf7d6f8906307fb1b5553443a44b1fbfbf72b44b6fbfbf53a4407fb1b1105eb020905fb1b6219440434a04502eb010ad7d1bef1000f1dd05cf82450bef1010fb5fbfbf606fb1b55b144aa4412d00ceb84056e68bef1020fb6fbfbf404fb1b66a144b24406d0ae68b6fbfbf505fb1b66a944b244bafbfbf202eb0901c0f8ac13bde8f08f00bff0b500294ff6ff7e00f0af80012903d10022c90775d1a8e021f00102c2f1000c6ff0010241f221038418a578e7788eea05252cb26e0036b203ead43484ea450503ead6366c0086ea450624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead53585ea460686ea07273eb27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead63686ea470703ead5357e0085ea470736b27d002db203ead636023286ea470703ead5360ceb0205023586ea470e95d10232c90733d0805c41f221038eea002001b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead232410082ea400009b2420012b203ead13181ea400003ead23181ea400e1ffa8ef0f0bd2de9f04fcbb00646c07c8b468df80600b08954998df80700000a8df808008df80a10080af1898df80b00080a17468df80d000020012b8df805308df809b08df80c108df80e008df80f008df810008df811008df812008df813008df814008df815008df816008df817008df818008df819008df81a008df81b008df81c008df81d008df81e008df81f008df820008df821008df822004cd1307e96f81780a0f1090144f62510c2f29240a1fb0002891a02eb510100970df10500b8eb910f88bf4fea9108c8ebc80706f11a0400f1010a00f10509093021463a46f0f747fe06f1210506f1280029460722f0f73ffe284621460722f0f73afe20465146032207f10905f0f733fe06f11d0049460422f0f72dfef07d02289cbf0130f075009fbb450cd0b8f1240f13d94ff0ff304bb0bde8f08fbb454ff00905f07509d14ef60b67abb20df10502c0f247070120f02115e002200df12304aab28df82300a01c0df105018df82470f0f701fea81c4af6610782b2c0f24607f02021460023b8474bb0bde8f08f2de9f04184b0044690f84d0000284ff0000000f09a8094f84f1042f28b0701f078018df8071094f85010c0f25b0701f007018df80610cde9020002a906200022b847054670b9002002adcde902000df1070128460122f0f7c7fd012029460122b847054694f84e00a8b1002602a906200022cde90266b84760b9cde9026602ae04f1540130460122f0f7aefd572031460122b8470543002602a906200022cde90266b84768b90df108080df1060140460122cde90266f0f797fd312041460122b847054302a906200022cde90266b84768b9002002ae04f15301cde9020030460122f0f781fd462031460122b8470543002602a906200022cde90266b84768b90df1080804f1510140460222cde90266f0f76afd362041460222b847054302a9a3200022cde90266b847054302a997200022cde90266b84742f62b310543c0f2440102208847284615b104b0bde8f081002184f84e1084f84d10a16504b0bde8f08100bf2de9f04f8bb00190233002254ff000080df10c0a4ff001094ff0000b002402900be000bf09fa0bf0002f0bf1010b08bf0443bbf1070f354426d041f66320c0f20000784410f80b0041f65d21c0f20001794411f80b6042f2fb0351463246c0f25b03cde90988cde90788cde90588cde90388984707460028d4d10298514628443246f0f7fffccde742f2fb00c0f25b004ff60073002600f1340703a9c0f21f0381200c22cde90966cde90766cde90566cde90366b84730b9029803a928440c22f0f7e0fc8026ddf804c040f6b80146ea0400220ac2f200018cf823008cf824200a68002a00f0ad8045f2fd774ff6ff766ff0020241f22103c0f202070d681544ed7886ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4342d7984ea460686ea052635b203ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea460624b275002db203ead43484ea460603ead535740085ea46060d6824b2154403ead4346d7984ea460686ea052635b2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead434750084ea46062db2740024b203ead53585ea460603ead4350332ba4285ea46067ff460afb1b2090a01e0ff26ff218cf83e109cf84c109cf84d208cf83f1026218cf83d608cf84020ff288cf84b101cbf04208cf81c000bb0bde8f08f70b588b042f2fb0514460e46c0f25b05002181280791cde90511cde90311cde90111009107d11b023435694681202246a84720b905e069462246a84708b108b070bd6946054630462246f0f7e1fb284608b070bd2de9f0478cb08579972d17d00446fe2d0fd0fd2d2ad142f69570c0f25b008047002084f84e0084f84d00a0650cb0bde8f08720460cb0bde8f047cbe50020cde9040042f2fb00c0f25b00a0f1700304a9972000229847044642f62b31c0f244010220884720460cb0bde8f08742f2fb08002094f80c90677bc0f25b08cde90a00cde90800cde90600cde9040004a99f200422c047064620b901a804a90422f0f78dfb002e6ff00100ddd19df80410bd29d9d19df805104029d5d19df806101029d1d194f84d00002852d047f64c60c2f20700006843f698210844a065002604a937200222cde90a66cde90866cde90666cde90466c047002840f0898002a804a90222f0f75bfb04a947200122cde90a66cde90866cde90666cde90466c047002875d10df1030004a90122f0f747fb0020cde90a00cde90800cde90600cde9040004a905200122c047002860d10df1020004a9012249ea0726f0f730fb352d5bdc002d00f08180012d70d19df8020082e0002604a9052001228df80e60adf80c600296cde90a66cde90866cde90666cde90466c047d8bb0df1080a04a950460122f0f70cfb04a935200122cde90a66cde90866cde90666cde90466c04738bb0af1010004a90122f0f7f9fa002604a937200222cde90a66cde90866cde90666cde90466c04798b90af1020004a90222f0f7e5fa04a947200122cde90a66cde90866cde90666cde904660126c04778b14ff0ff300cb0bde8f087362d6ed0572d15d194f84e00002800f08580572039e00af1040004a90122f0f7c1fa04f14f0051460722f0f7bbfa84f84d603ee700208df801006946284601228df8009000f04ef9312d044627d036e09df80200002e00f0380618bf4036704010f0380f10d09df808009df8091041f25a530e22c0f2000302ea96027b449a5a41ea0020904239d8012000218df80110694601228df8006000f024f904460df103014620012200f01df9054602a93620022200f017f945ea040141ea00040025a8f1700604a9a3200022cde90455b047044304a997200022cde90455b0470443aee69df802000e2101ea900041f2e241c0f200017944085a864204d96ff001000cb0bde8f0876946362002228df800708df8019000f0e6f80446d0e70020cde90a00cde90800cde90600cde9040004a9592001220125c04700287ff45caf04f1540004a90122f0f72dfa84f84e5060e740f6b800c2f200000168002904bf4ff0ff30704780b584b000684ef2173102904ff41630039002a8c0f2470188474ff4f07042f29f7e01904ff4207cc0f25b0e0020002100220023cdf800c0f04704b080bd00bf2de9f04340f6b801c2f2000109684ff0000e01f1020c4cf6cd4340f2762808e00ef1010ebef5f07f0cf5a07c08bfbde8f083aef1a0096ff00906644607e000bf07eb0711a170053445452e46e8d290f84c1006f10a054f1e112905fb03f208bf570d122908d1a6f1e6019f294ff000079cbfb9f19f0f077b07eb071104f8021c90f84c1006f10c024f1e112903fb02f208bf570d122908d1a6f1e4019f294ff000079cbfb9f19f0f077b07eb071104f8011c90f84c1006f10e024f1e112903fb02f208bf570d122908d1a6f1e2019f294ff000079cbfb9f19f0f077b07eb0711217090f84c1006f110024f1e112903fb02f208bf570d122908d1a6f1e0019f294ff000079cbfb9f19f0f077b07eb0711617090f84c1006f112024f1e112903fb02f208bf570d12298ad1a6f1de019f294ff000079cbfb9f19f0f077b80e700bf2de9f04383b042f28b0914460e460546c0f25b090027694606200022cde90077c84710b103b0bde8f083e846404631462246cde90077f0f743f9284641462246c84703b0bde8f08370b50446d0f83c010d4638b92046f6f71dfe0028c4f83c0108bf70bd42f64d46c0f2440606f140018847d4f83c0129463246bde8704010472de9f04f81b0934612788ab1022300bf0beb030717f8012c62b11bf8032062b17a784ab1ba780433002af1d1023b04e0002205e0013b00e0013303eb4302520042eae272931c02f1010c01eb810203f0030e23f0030a00eb8213a3f5a0784ff0ff3906e009f10109b9f10d0f08f5a0786bd009eb010202eb8202bcf1030f00eb821605d24ff0ff34bef1000f2ed1e9e70024474604e000bfa24507f1020721d0621cd209042a03d83a7802f0f0023a70a21cd209042a03d87a7802f00f027a70e21cd209042a03d87a7802f0f0027a700434e209042adfd86208b55c05f00f05b554d9e7013cbef1000fbbd0a21cd509042d08d85208b55ce7076ff00f0708bf0f273d40b554bef1010fabd0e21cd509042d09d85208b55ce7074ff00f0708bf6ff00f073d40b554bef1020f9ad0221dd509042d96d85208e407b55c6ff00f0408bf0f242c40b4548ce79bf80010cdf800b0002900f0ce80022041f2410a41f2420b41f2430808e0009a063012f8011f03330029009200f0bd80a1f17f0717f15f0ff1d340f65d42c0f2000201eb41017a4402eb81014ff20014a1f5c079cff6ff7402e014f52074ded0494619f9027bc509042d09d8b7f1ff3f06dc1a1992f8016f46f0f00682f8016f5ffa87fe5fea4e6208d5042d06d81a1992f8017f47f00f0782f8017f5fea8e620ad540f27d22904206d81a1992f8027f47f0f00782f8027f5feace6209d5b0f51f7f06d81a1992f8027f47f00f0782f8027f5fea0e724fea900c09d5bcf19e0f06d81a1992f8036f46f0f00682f8036f5fea4e720ad540f27a22904206d81a1992f8037f47f00f0782f8037f91f90110042d09d8b1f1ff3f06dc1a1912f80a7047f0f00702f80a70c9b24a0608d5042d06d81a1912f80a7047f00f0702f80a708a060ad540f27d22904206d81a1912f80b7047f0f00702f80b70ca0609d5b0f51f7f06d81a1912f80b7047f00f0702f80b700a0709d5bcf19e0f06d81a1912f8087047f0f00702f8087049077ff565af40f27a2188423ff660af191911f8082042f00f0201f8082057e701b0bde8f08f00bf2de9f04f81b0134681464a1c00f08f808e0a4ff0000b19f80b20002a00f0888109eb0b077a78002a00f00a81ba78002a00f00981fa78002a00f008813a79002a00f007817a79002a00f00681ba79002a00f00581fa79002a00f004813a7a002a00f003817a7a002a00f00281ba7a002a00f00181fa7a002a00f000813a7b002a00f0ff807a7b002a00f0fe80ba7b002a00f0fd80fa7b002a00f0fc803a7c002a00f0fb807a7c002a00f0fa80ba7c002a00f0fb80fa7c002a00f0fc803a7d002a00f0fd807a7d002a00f0fe80ba7d002a00f0ff80fa7d002a00f000813a7e002a00f001817a7e002a00f00281ba7e002a00f00381fa7e002a00f004813a7f002a00f005817a7f002a00f00681ba7f002a00f00781fa7f002a00f008810bf1200bbbf1600f7ff477af4ff0600b00e1002119f80120002a00f0af8109eb01056a78002a00f0b080aa78002a00f0b180ea78002a00f0b2802a79002a00f0b3806a79002a00f0b480aa79002a00f0b580ea79002a00f0b6802a7a002a00f0b7806a7a002a00f0b880aa7a002a00f0b980ea7a002a00f0ba802a7b002a00f0bb806a7b002a00f0bc80aa7b002a00f0bd80ea7b002a00f050812a7c002a00f04e816a7c002a00f04c81aa7c002a00f04a81ea7c002a00f048812a7d002a00f046816a7d002a00f04481aa7d002a00f04281ea7d002a00f040812a7e002a00f03e816a7e002a00f03c81aa7e002a00f03a81ea7e002a00f038812a7f002a00f036816a7f002a00f03481aa7f002a00f03281ea7f002a00f03081203160297ff479af32e10bf1010b74e00bf1020b71e00bf1030b6ee00bf1040b6be00bf1050b68e00bf1060b65e00bf1070b62e00bf1080b5fe00bf1090b5ce00bf10a0b59e00bf10b0b56e00bf10c0b53e00bf10d0b50e00bf10e0b4de00bf10f0b4ae00bf1100b47e00bf1110b44e00131f6e00bf1120b3fe00231f1e00bf1130b3ae00331ece00bf1140b35e00431e7e00bf1150b30e00531e2e00bf1160b2be00631dde00bf1170b26e00731d8e00bf1180b21e00831d3e00bf1190b1ce00931cee00bf11a0b17e00a31c9e00bf11b0b12e00b31c4e00bf11c0b0de00c31bfe00bf11d0b08e00d31bae00bf11e0b03e00e31b5e00bf11f0bb1f5205f4ff0010100931fd364234ff47a7442f2107700bf01eb81025200b6fbf2f50a2d11d301fb03f2b6fbf2f50a2d0bd301fb04f2b6fbf2f50a2d05d37943b6fbf1f2092ae7d800e011465846bbf15f0f98bf5f20c0f1000c1ceb0b0a53d0b6fbf1f74cf6cd4207f13003ccf6cc4209f80b300a29a1fb023547d31af1010342d007fb11674fead508b7fbf8fe48f21f520ef1300309eb0b06c5f2eb1273706429a1fb023434d31af102032cd00efb18776409b7fbf4f544f6d35205f13003c1f26202b370b1f57a7fa1fb022323d31af1030218d005fb14729b0941f25975b2fbf3f7cdf2b715a1fb055407f13005f57007fb132642f210720bf1040b91424fea5431a9d209e0834607e00bf1010b04e00bf1020b01e00bf1030b0020009b09f80b002de00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f020a7003d1002189f85f1001e000204870002119f80100002800f0a18009eb0105687800285ed0a87800285dd0e87800285cd0287900285bd0687900285ad0a879002859d0e879002858d0287a002857d0687a002856d0a87a002855d0e87a002854d0287b002853d0687b002852d0a87b002851d0e87b002850d0287c00284fd0687c00284ed0a87c00284dd0e87c00284cd0287d00284bd0687d00284ad0a87d002849d0e87d002848d0287e002847d0687e002846d0a87e002845d0e87e002844d0287f002843d0687f002842d0a87f002841d0e87f002840d0203160297ff498af44e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2905d849444ff02f00087040f09580002089f85f00581c00f094809d0a4ff0000e19f80e00002800f08d8109eb0e067078002800f00f81b078002800f00e81f078002800f00d813079002800f00c817079002800f00b81b079002800f00a81f079002800f00981307a002800f00881707a002800f00781b07a002800f00681f07a002800f00581307b002800f00481707b002800f00381b07b002800f00281f07b002800f00181307c002800f00081707c002800f0ff80b07c002800f00081f07c002800f00181307d002800f00281707d002800f00381b07d002800f00481f07d002800f00581307e002800f00681707e002800f00781b07e002800f00881f07e002800f00981307f002800f00a81707f002800f00b81b07f002800f00c81f07f002800f00d810ef1200ebef1600f7ff477af4ff0600e05e100204870581c7ff46caf002119f80100002800f0aa8109eb01025078002800f0b0809078002800f0b180d078002800f0b2801079002800f0b3805079002800f0b4809079002800f0b580d079002800f0b680107a002800f0b780507a002800f0b880907a002800f0b980d07a002800f0ba80107b002800f0bb80507b002800f0bc80907b002800f0bd80d07b002800f04b81107c002800f04981507c002800f04781907c002800f04581d07c002800f04381107d002800f04181507d002800f03f81907d002800f03d81d07d002800f03b81107e002800f03981507e002800f03781907e002800f03581d07e002800f03381107f002800f03181507f002800f02f81907f002800f02d81d07f002800f02b81203160297ff479af2de10ef1010e74e00ef1020e71e00ef1030e6ee00ef1040e6be00ef1050e68e00ef1060e65e00ef1070e62e00ef1080e5fe00ef1090e5ce00ef10a0e59e00ef10b0e56e00ef10c0e53e00ef10d0e50e00ef10e0e4de00ef10f0e4ae00ef1100e47e00ef1110e44e00131f1e00ef1120e3fe00231ece00ef1130e3ae00331e7e00ef1140e35e00431e2e00ef1150e30e00531dde00ef1160e2be00631d8e00ef1170e26e00731d3e00ef1180e21e00831cee00ef1190e1ce00931c9e00ef11a0e17e00a31c4e00ef11b0e12e00b31bfe00ef11c0e0de00c31bae00ef11d0e08e00d31b5e00ef11e0e03e00e31b0e00ef11f0e0122b3f5205f1ed364234ff47a7442f2107602eb82004100b5fbf1f00a2811d302fb03f1b5fbf1f00a280bd302fb04f1b5fbf1f00a2805d37243b5fbf2f00928e7d800e00a46f046bef15f0f98bf4ff05f08c8f1000c42f2107a1ceb0e074dd0b5fbf2f30a2a03f1300009f80e004cf6cd40ccf6cc40a2fb000641d3781c3dd003fb1253f608b3fbf6f409eb0e0504f13000687048f21f50c5f2eb10642aa2fb000130d3b81c29d004fb16334e09b3fbf6f4b2f57a7f04f13000a87044f6d350c1f26200a2fb000120d3f81c16d004fb1630890941f25974b0fbf1f3cdf2b714a2fb044603f13004ec7003fb11050ef1040e52454fea5632afd209e0c64607e00ef1010e04e00ef1020e01e00ef1030e002009f80e0001b0bde8f08f0f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2904d849444ff03f00087005d1002089f85f0001b0bde8f08f0020487001b0bde8f08f434d01ffff0000000000000052420100ff00000008031000000000000000000046616365636c61772f3332000000000000000000000000000000002020202020002020000000505050000000000000000000005050f85050f85050000000002070a8a07028a8702000000048a85010202854480000000020505020689090680000002020200000000000000000000010204040404020100000000040201010101020400000000000005020f82050000000000000002020f82020000000000000000000000020204000000000000000f800000000000000000000000000202000000000080810102020404000000000708898a8c88888700000000020602020202020700000000070888808102040f8000000007088083008088870000000000818284888f8080800000000f88080f00808887000000000708080f08888887000000000f808081010202020000000007088887088888870000000007088888878080870000000000000202000002020000000000000202000002020400000000008102040201008000000000000f80000f8000000000000004020100810204000000000708888102000202000000000708898a8a89880780000000070888888f888888800000000f08888f0888888f000000000708880808080887000000000e0908888888890e000000000f88080f0808080f800000000f88080f0808080800000000070888080b888887000000000888888f888888888000000007020202020202070000000003810101010909060000000008890a0c0c0a090880000000080808080808080f80000000088d8a8a888888888000000008888c8a89888888800000000708888888888887000000000f0888888f080808000000000708888888888a87008000000f0888888f0a0908800000000708880700808887000000000f8202020202020200000000088888888888888700000000088888850505020200000000088888888a8a8d88800000000888850202050888800000000888850502020202000000000f8081020408080f8000000007040404040404070000000004040202010100808000000007010101010101070000000205088000000000000000000000000000000000000f80040200000000000000000000000000000700878888878000000008080f088888888f00000000000007088808088700000000008087888888888780000000000007088f8808078000000001820702020202020000000000000788888888878087000008080f08888888888000000202000602020202070000000080800180808080808483000004040485060605048000000006020202020202070000000000000f0a8a8a8a8a8000000000000f08888888888000000000000708888888870000000000000f088888888f0808000000000788888888878080800000000b8c0808080800000000000007880700808f00000000020207020202020180000000000008888888888780000000000008888505020200000000000008888a8a8a870000000000000885020205088000000000000888888888878087000000000f810204080f800000000182020402020201800000000202020202020202000000000601010081010106000000048a89000000000000000009f0535593747c181040101010201020c005353a829c51bd314a810260d5b0bfe090000", "desc": "append injected blobs to main-app payload" }, { "offset": 779123, "old": "805a3900", - "new": "384f3a00", + "new": "c86a3a00", "desc": "main-app subheader payload size (ps)" }, { "offset": 152, "old": "005b3900", - "new": "b84f3a00", + "new": "486b3a00", "desc": "main-app TOC entry size (ps + 128)" }, { "offset": 779243, "old": "805a3904", - "new": "384f3a04", + "new": "c86a3a04", "desc": "main-app preamble length (low 24 bits)" }, { "offset": 779247, "old": "effdbcea", - "new": "9218d6af", + "new": "0d513b79", "desc": "[5] ota/s200_firmware_ota.bin preamble crc32" }, { "offset": 156, "old": "c0c6322a", - "new": "3ef62aed", + "new": "ca6f630a", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)" }, { "offset": 779127, "old": "c0c6322a", - "new": "3ef62aed", + "new": "ca6f630a", "desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)" } ] diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts index 568c3abf..7e8ec2dd 100644 --- a/app/g2/ios-preview-controller.ts +++ b/app/g2/ios-preview-controller.ts @@ -44,7 +44,7 @@ import { TextViewerLayer } from '../apps/files/text-viewer' import { shell, rawInputEventToInputEvent, type ShellWindow } from '../ui/shell/shell' import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible } from '../ui/shell/geometry' import { DISPLAY_MODE_VALUES, displayModeLabel, displayModeSetting, onAnySettingChanged, - previewColorSetting, lockScreenEnabledSetting, brightnessSetting, brightnessSettingToLevel } from '../ui/dashboard-settings' + previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences } from '../ui/dashboard-settings' import type { PhoneGesture } from '../phone-ui/phone-gestures' import { isWelcomeSoundPending, setWelcomeSoundPending } from '../phone-ui/onboarding-state' import { findSoundEffect, playSoundEffect } from '../ui/sound-effects' @@ -332,11 +332,11 @@ export class IosPreviewController { private pushBrightness(): void { const communicator = this.communicator if (!communicator || this.state.phase !== 'connected') { this.lastBrightness = null; return } - const value = brightnessSetting.get() + const preferences = getBrightnessPreferences() + const value = JSON.stringify(preferences) if (value === this.lastBrightness) return this.lastBrightness = value - const level = brightnessSettingToLevel(value) - void communicator.setBrightness(level === null, level ?? 0).catch(error => { + void communicator.configureBrightness(preferences).catch(error => { this.lastBrightness = null this.logBluetooth(`Brightness: ${String(error)}`) }) @@ -694,6 +694,7 @@ export class IosPreviewController { this.displayReady = this.registerSurfaces(communicator) await this.displayReady this.update('connecting', 'Connecting to the glasses…') + await communicator.configureBrightness(getBrightnessPreferences()) this.startedCommunicators.add(communicator) await communicator.start() for (const window of shell.getWindows()) window.requestRender() @@ -887,13 +888,21 @@ export class IosPreviewController { if (this.glassesLocked || !this.active) return shell.startKeyboardInput() } - private async editSetting(setting: { editorTitle: string; inputKind?: string; get(): string; set(value: string): void }): Promise { + private async editSetting(setting: { editorTitle: string; inputKind?: string; get(): string; set(value: string): void; validationError?(value?: string): string | null }): Promise { if (!this.active) { this.logBluetooth('Editing text settings requires opening Faceclaw on the phone'); return false } - const result = await Dialogs.prompt({ title: setting.editorTitle, defaultText: setting.get(), inputType: setting.inputKind, okButtonText: 'Save', cancelButtonText: 'Cancel' }) - if (result.result) { - setting.set(result.text) + let draft = setting.get() + while (true) { + const result = await Dialogs.prompt({ title: setting.editorTitle, defaultText: draft, inputType: setting.inputKind, okButtonText: 'Save', cancelButtonText: 'Cancel' }) + if (!result.result) return false + draft = result.text + const error = setting.validationError?.(draft) + if (error) { + await Dialogs.alert({ title: setting.editorTitle, message: error, okButtonText: 'OK' }) + continue + } + setting.set(draft) if (setting === nightscoutSiteUrlSetting || setting === nightscoutApiTokenSetting) await nightscoutBridge.refreshNow() + return true } - return result.result } } diff --git a/app/native/faceclaw-communicator.ios.ts b/app/native/faceclaw-communicator.ios.ts index 2a32aad8..47fe1231 100644 --- a/app/native/faceclaw-communicator.ios.ts +++ b/app/native/faceclaw-communicator.ios.ts @@ -443,11 +443,15 @@ export class FaceclawCommunicatorBridge { await this.enqueueNativeCall(() => this.communicator.setFirmwareDebugFlagsEnabled(Boolean(enabled))); } - /** Set lens brightness: auto (ambient sensor) or an explicit 0-100 level. */ + /** Set lens brightness: Faceclaw auto or a fixed level (clamped to 2–100). */ async setBrightness(autoAdjust: boolean, level: number): Promise { await this.enqueueNativeCall(() => this.communicator.setBrightnessAutoAdjustBrightnessLevel(Boolean(autoAdjust), Math.round(level))); } + async configureBrightness(p: { auto: boolean; level: number; minimum: number; maximum: number; curve: string; fadeMs: number }): Promise { + await this.enqueueNativeCall(() => this.communicator.configureBrightnessAutoLevelMinimumMaximumCurveFadeMs(p.auto, p.level, p.minimum, p.maximum, p.curve, p.fadeMs)); + } + async enableWearDetectionAndRequestState(): Promise { await this.enqueueNativeCall(() => this.communicator.enableWearDetectionAndRequestState()); } diff --git a/app/native/faceclaw-communicator.ts b/app/native/faceclaw-communicator.ts index 806cf7ad..2663195e 100644 --- a/app/native/faceclaw-communicator.ts +++ b/app/native/faceclaw-communicator.ts @@ -442,11 +442,15 @@ export class FaceclawCommunicatorBridge { await this.enqueueJavaCall(() => this.communicator.setFirmwareDebugFlags(Boolean(enabled))); } - /** Set lens brightness: auto (ambient sensor) or an explicit 0-100 level. */ + /** Set lens brightness: Faceclaw auto or a fixed level (clamped to 2–100). */ async setBrightness(autoAdjust: boolean, level: number): Promise { await this.enqueueJavaCall(() => this.communicator.setBrightness(Boolean(autoAdjust), Math.round(level))); } + async configureBrightness(p: { auto: boolean; level: number; minimum: number; maximum: number; curve: string; fadeMs: number }): Promise { + await this.enqueueJavaCall(() => this.communicator.configureBrightness(p.auto, p.level, p.minimum, p.maximum, p.curve, p.fadeMs)); + } + async enableWearDetectionAndRequestState(): Promise { await this.enqueueJavaCall(() => this.communicator.enableWearDetectionAndRequestState()); } diff --git a/app/phone-ui/remote-controls-view-model.ts b/app/phone-ui/remote-controls-view-model.ts index 5d2d96ff..b846cea9 100644 --- a/app/phone-ui/remote-controls-view-model.ts +++ b/app/phone-ui/remote-controls-view-model.ts @@ -102,7 +102,7 @@ export class RemoteControlsViewModel extends Observable { const raw = typeof args.value === "number" ? args.value : Number(args.object?.value ?? NaN); if (!Number.isFinite(raw)) return; // The setting only has every tenth level; snap to the nearest. - const level = Math.min(100, Math.max(0, Math.round(raw / 10) * 10)); + const level = Math.min(100, Math.max(2, Math.round(raw / 10) * 10)); this.lastManualBrightness = level; const value = String(level) as BrightnessSetting; if (brightnessSetting.get() !== value) brightnessSetting.set(value); diff --git a/app/phone-ui/remote-controls.xml b/app/phone-ui/remote-controls.xml index 4d4c4a70..4790537f 100644 --- a/app/phone-ui/remote-controls.xml +++ b/app/phone-ui/remote-controls.xml @@ -43,7 +43,7 @@