@mentra/engine 3.4.0-dev.990 → 3.4.0-dev.992
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/generated/releaseMetadata.js +5 -5
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/react/MentraLiveOtaFlow.d.ts.map +1 -1
- package/build/react/MentraLiveOtaFlow.js +1 -4
- package/build/react/MentraLiveOtaFlow.js.map +1 -1
- package/build/react/useMentraLiveOta.js +2 -2
- package/build/react/useMentraLiveOta.js.map +1 -1
- package/build/services/OtaArtifactDownloader.d.ts +3 -1
- package/build/services/OtaArtifactDownloader.d.ts.map +1 -1
- package/build/services/OtaArtifactDownloader.js +57 -13
- package/build/services/OtaArtifactDownloader.js.map +1 -1
- package/build/services/OtaArtifactFailure.d.ts +18 -0
- package/build/services/OtaArtifactFailure.d.ts.map +1 -0
- package/build/services/OtaArtifactFailure.js +72 -0
- package/build/services/OtaArtifactFailure.js.map +1 -0
- package/build/services/OtaErrorMapping.d.ts +4 -2
- package/build/services/OtaErrorMapping.d.ts.map +1 -1
- package/build/services/OtaErrorMapping.js +57 -6
- package/build/services/OtaErrorMapping.js.map +1 -1
- package/build/services/OtaFailureReportService.d.ts +2 -0
- package/build/services/OtaFailureReportService.d.ts.map +1 -1
- package/build/services/OtaFailureReportService.js.map +1 -1
- package/build/services/OtaInstallCoordinator.d.ts +3 -1
- package/build/services/OtaInstallCoordinator.d.ts.map +1 -1
- package/build/services/OtaInstallCoordinator.js +15 -26
- package/build/services/OtaInstallCoordinator.js.map +1 -1
- package/build/services/otaInstallPolicy.d.ts +2 -2
- package/build/services/otaInstallPolicy.js +2 -2
- package/build/services/otaInstallPolicy.js.map +1 -1
- package/package.json +8 -8
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/react/MentraLiveOtaFlow.tsx +1 -6
- package/src/react/useMentraLiveOta.ts +2 -2
- package/src/services/OtaArtifactDownloader.ts +62 -15
- package/src/services/OtaArtifactFailure.ts +102 -0
- package/src/services/OtaErrorMapping.ts +60 -6
- package/src/services/OtaFailureReportService.ts +2 -0
- package/src/services/OtaInstallCoordinator.ts +17 -28
- package/src/services/otaInstallPolicy.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMentraLiveOta.js","sourceRoot":"","sources":["../../src/react/useMentraLiveOta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAEvE,OAAO,EAAC,GAAG,EAAC,MAAM,gBAAgB,CAAA;AAClC,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,oBAAoB,EACpB,mCAAmC,EACnC,uBAAuB,EACvB,wBAAwB,EACxB,kCAAkC,EAClC,gBAAgB,EAChB,sBAAsB,GAEvB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,2BAA2B,EAC3B,uCAAuC,EACvC,kBAAkB,EAClB,eAAe,EACf,uCAAuC,EACvC,yCAAyC,GAC1C,MAAM,6BAA6B,CAAA;AAGpC,OAAO,EAAC,wBAAwB,EAAE,yBAAyB,EAAC,MAAM,8BAA8B,CAAA;AAEhG,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAA;AAkIrD,MAAM,iCAAiC,GAAG,IAAI,CAAA;AAC9C,MAAM,4BAA4B,GAAG,GAAG,CAAA;AACxC,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAA;AAE3C,SAAS,yBAAyB,CAAC,MAAoC;IACrE,OAAO,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,UAAU,EAAE,WAAW,IAAI,MAAM,CAAC,iBAAiB,EAAE,WAAW,IAAI,IAAI,CAAA;AACjH,CAAC;AAED,SAAS,qBAAqB,CAAC,UAAyB;IACtD,MAAM,OAAO,GAAG,UAAU,EAAE,IAAI,EAAE,CAAA;IAClC,OAAO,OAAO,IAAI,IAAI,CAAA;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,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,CAAC,CACtE,CAAA;AACH,CAAC","sourcesContent":["import {useCallback, useEffect, useMemo, useRef, useState} from \"react\"\n\nimport {ota} from \"../facades/ota\"\nimport {\n beginOtaAutoChain,\n clearOtaAutoChainReconnectWait,\n isOtaAutoChainActive,\n OTA_AUTO_CHAIN_RECONNECT_TIMEOUT_MS,\n otaAutoChainFingerprint,\n otaAutoChainReleaseRange,\n otaAutoChainReconnectWaitRemaining,\n stopOtaAutoChain,\n tryAdvanceOtaAutoChain,\n type OtaAutoChainReleaseRange,\n} from \"../services/OtaAutoChain\"\nimport {\n BES_INSTALL_RESTART_MESSAGE,\n OTA_ERROR_BES_RESTART_REQUIRED_COPY_KEY,\n getOtaErrorMessage,\n otaErrorCopyKey,\n shouldRequireGlassesRebootForBesFailure,\n shouldShowChangeWifiForOtaDownloadFailure,\n} from \"../services/OtaErrorMapping\"\nimport type {OtaInstallSnapshot} from \"../services/OtaInstallCoordinator\"\nimport type {OtaCheckCurrentGlassesResult} from \"../services/OtaUpdateCheckService\"\nimport {otaDeviceSessionRevision, subscribeOtaDeviceSession} from \"../services/OtaDeviceSession\"\nimport type {ReleaseChangelog} from \"../facades/ota\"\nimport {useEngineSnapshot} from \"./useEngineSnapshot\"\n\nexport type MentraLiveOtaFlowPage = \"check\" | \"progress\"\n\nexport type MentraLiveOtaScreen =\n | \"initializing\"\n | \"checking\"\n | \"finishing\"\n | \"update_available\"\n | \"battery_required\"\n | \"wifi_required\"\n | \"up_to_date\"\n | \"dev_build\"\n | \"unofficial_client\"\n | \"check_failed\"\n | \"update_info_unavailable\"\n | \"starting\"\n | \"preparing_hotspot\"\n | \"updating\"\n | \"restarting\"\n | \"verifying\"\n | \"complete\"\n | \"failed\"\n | \"disconnected\"\n\nexport type MentraLiveOtaErrorCode =\n | \"check_failed\"\n | \"update_info_unavailable\"\n | \"install_failed\"\n | \"bes_restart_required\"\n\nexport type MentraLiveOtaError = {\n code: MentraLiveOtaErrorCode\n /** English copy for hosts without localization. */\n message: string\n /**\n * Copy key for `message` when the failure maps to known copy, so localized hosts can\n * translate it. Null for phone-side watchdog and preflight messages, which are English-only.\n * Optional so host code that builds this type by hand keeps compiling; the hook always sets it.\n */\n copyKey?: string | null\n /**\n * Raw failure code reported by the glasses (`ota_status.error`), for support. Null when the\n * failure originated on the phone. Optional for the same source-compatibility reason.\n */\n glassesCode?: string | null\n}\n\nexport type MentraLiveOtaTransport = \"wifi\" | \"hotspot\"\nexport type MentraLiveOtaHotspotPhase = \"idle\" | \"downloading\" | \"starting_hotspot\" | \"joining_hotspot\" | \"serving\"\nexport type MentraLiveOtaInstallPhase = \"download\" | \"install\"\nexport type MentraLiveOtaStep = \"apk\" | \"mtk\" | \"bes\"\n\nexport type MentraLiveOtaReleaseTransition = {\n /** Current glasses software label. Temporarily backed by the reported ASG app version. */\n fromVersion: string | null\n /** Exact coordinated release identity for the selected OTA pin. */\n toVersion: string\n}\n\nexport type MentraLiveOtaState = {\n screen: MentraLiveOtaScreen\n connected: boolean\n batteryLevel: number | null\n transport: MentraLiveOtaTransport | null\n updateRequired: boolean\n versionChange: boolean\n versionChangeConverged: boolean\n versionChangePhase: \"installing\" | \"restarting\" | \"verifying\" | null\n wifiConnected: boolean\n wifiStatusKnown: boolean\n hotspotSupported: boolean\n hotspotPhase: MentraLiveOtaHotspotPhase\n hotspotArtifactPercent: number | null\n /**\n * Current phone download context. Index is zero-based; percent applies to this file only.\n * Optional for source compatibility; this hook returns null when no file is active.\n */\n hotspotArtifact?: {kind: MentraLiveOtaStep; index: number; totalCount: number} | null\n phase: MentraLiveOtaInstallPhase | null\n step: MentraLiveOtaStep | null\n currentStep: number | null\n totalSteps: number | null\n progress: number | null\n installingApkOnly: boolean\n firmwareRestarting: boolean\n error: MentraLiveOtaError | null\n canInstall: boolean\n canRetry: boolean\n canFinish: boolean\n canDismiss: boolean\n canDiscard: boolean\n canOpenWifiSetup: boolean\n continueDisabled: boolean\n /** True only after an approved update session reaches a final no-update check. */\n completedUpdate: boolean\n /** Release labels for the offered or just-completed coordinated update. */\n releaseTransition: MentraLiveOtaReleaseTransition | null\n /** Release notes crossed by this update, newest first. Populated on completion. */\n changelogs: ReleaseChangelog[]\n /** Sideloaded glasses client package, set only on the `unofficial_client` screen. */\n glassesPackageName: string | null\n}\n\nexport type UseMentraLiveOtaOptions = {\n /** Entry page. `progress` exists for interrupted-session recovery. */\n initialPage?: MentraLiveOtaFlowPage\n /** Start Engine's OTA-only projections. Full Engine hosts should pass false. */\n initializeRuntime?: boolean\n /** Called after the final check or when an optional update is dismissed. */\n onFinished?: () => void\n /** Host-owned Wi-Fi setup for glasses without hotspot OTA support. */\n onOpenWifiSetup?: () => void\n /** Lets a host coordinate its connection overlay with OTA firmware restarts. */\n onFirmwareRestartingChange?: (restarting: boolean, progressActive: boolean) => void\n}\n\nexport type MentraLiveOtaController = {\n state: MentraLiveOtaState\n check: () => void\n retryCheck: () => void\n install: () => void\n retryInstall: () => void\n finish: () => void\n discard: () => void\n openWifiSetup: () => void\n}\n\ntype CheckState = \"checking\" | \"update_available\" | \"no_update\" | \"dev_build\" | \"unofficial_client\" | \"error\"\n\nconst AUTO_CHAIN_NETWORK_RETRY_DELAY_MS = 5000\nconst AUTO_CHAIN_COMPLETE_DELAY_MS = 750\nexport const MINIMUM_OTA_BATTERY_LEVEL = 25\n\nfunction releaseRangeTargetVersion(result: OtaCheckCurrentGlassesResult): string | null {\n return result.releaseVersion ?? result.updateInfo?.versionName ?? result.latestVersionInfo?.versionName ?? null\n}\n\nfunction currentReleaseVersion(appVersion: string | null): string | null {\n const version = appVersion?.trim()\n return version || null\n}\n\nfunction releaseTransitionFromRange(range: OtaAutoChainReleaseRange | null): MentraLiveOtaReleaseTransition | null {\n if (!range?.releaseVersion) return null\n return {fromVersion: range.fromVersion, toVersion: range.releaseVersion}\n}\n\nfunction releaseChangelogsForActiveChain(): ReleaseChangelog[] {\n const range = otaAutoChainReleaseRange()\n if (!range?.toVersion) return []\n try {\n return ota.getReleaseChangelogs(range.fromVersion, range.toVersion)\n } catch {\n try {\n return ota.getReleaseChangelogs(null, range.toVersion)\n } catch {\n return []\n }\n }\n}\n\nfunction installProgress(snapshot: OtaInstallSnapshot): number | null {\n if (snapshot.displayState !== \"updating\") return null\n const {otaStatus} = snapshot\n const isDownload = otaStatus?.phase === \"download\"\n const totalSteps = otaStatus?.totalSteps ?? 1\n const rawPercent = isDownload\n ? (otaStatus?.stepPercent ?? 0)\n : totalSteps >= 2\n ? (otaStatus?.overallPercent ?? 0)\n : (otaStatus?.stepPercent ?? 0)\n return Math.min(Math.max(rawPercent, snapshot.mtkInstallStallSimulatedPercent ?? 0, 0), 100)\n}\n\nfunction progressScreen(snapshot: OtaInstallSnapshot): MentraLiveOtaScreen {\n if (snapshot.versionChangePhase === \"restarting\") return \"restarting\"\n if (snapshot.versionChangePhase === \"verifying\") return \"verifying\"\n switch (snapshot.displayState) {\n case \"starting\":\n return snapshot.hotspotPhase === \"idle\" || snapshot.hotspotPhase === \"serving\" ? \"starting\" : \"preparing_hotspot\"\n case \"updating\":\n return \"updating\"\n case \"restarting\":\n return \"restarting\"\n case \"complete\":\n return \"complete\"\n case \"failed\":\n return \"failed\"\n default:\n return \"disconnected\"\n }\n}\n\n/**\n * Headless Mentra Live OTA flow. Engine owns checking, hotspot staging,\n * APK/MTK/BES sequencing, restart recovery, retries, and verification; the host\n * renders semantic state and invokes these idempotent actions.\n */\nexport function useMentraLiveOta(options: UseMentraLiveOtaOptions = {}): MentraLiveOtaController {\n const {\n initialPage = \"check\",\n initializeRuntime = true,\n onFinished,\n onFirmwareRestartingChange,\n onOpenWifiSetup,\n } = options\n const otaSnapshot = useEngineSnapshot(ota.snapshot, ota.onSnapshot)\n const deviceRevision = useEngineSnapshot(otaDeviceSessionRevision, subscribeOtaDeviceSession)\n const installSnapshot = useEngineSnapshot(ota.installSession.snapshot, ota.installSession.onSnapshot)\n const [page, setPage] = useState<MentraLiveOtaFlowPage>(initialPage)\n const [runtimeReady, setRuntimeReady] = useState(!initializeRuntime)\n const [checkState, setCheckState] = useState<CheckState>(\"checking\")\n const [isUpdateRequired, setIsUpdateRequired] = useState(true)\n const [isVersionChange, setIsVersionChange] = useState(false)\n const [errorKind, setErrorKind] = useState<\"network\" | \"pin_unavailable\" | \"version_info\">(\"network\")\n const [unofficialClientPackage, setUnofficialClientPackage] = useState<string | null>(null)\n const [updateFingerprint, setUpdateFingerprint] = useState<string | null>(null)\n const [offeredReleaseTransition, setOfferedReleaseTransition] = useState<MentraLiveOtaReleaseTransition | null>(null)\n const [completedReleaseTransition, setCompletedReleaseTransition] = useState<MentraLiveOtaReleaseTransition | null>(\n null,\n )\n const [completedUpdate, setCompletedUpdate] = useState(false)\n const [completedChangelogs, setCompletedChangelogs] = useState<ReleaseChangelog[]>([])\n const [batteryBlocked, setBatteryBlocked] = useState(false)\n const [checkGeneration, setCheckGeneration] = useState(0)\n const mountedRef = useRef(false)\n const performCheckGenerationRef = useRef(0)\n const activeCheckKeyRef = useRef<string | null>(null)\n const checkStartedRef = useRef(false)\n const checkCompletedRef = useRef(false)\n const selectedCheckResultRef = useRef<OtaCheckCurrentGlassesResult | null>(null)\n const selectedCheckDeviceRef = useRef(deviceRevision)\n const previousDeviceRef = useRef(deviceRevision)\n const autoChainAdvancedRef = useRef(false)\n const installActionPendingRef = useRef(false)\n const onFinishedRef = useRef(onFinished)\n const onOpenWifiSetupRef = useRef(onOpenWifiSetup)\n const onFirmwareRestartingChangeRef = useRef(onFirmwareRestartingChange)\n onFinishedRef.current = onFinished\n onOpenWifiSetupRef.current = onOpenWifiSetup\n onFirmwareRestartingChangeRef.current = onFirmwareRestartingChange\n\n useEffect(() => {\n mountedRef.current = true\n return () => {\n mountedRef.current = false\n }\n }, [])\n\n useEffect(() => {\n if (!initializeRuntime) {\n setRuntimeReady(true)\n return\n }\n let cancelled = false\n setRuntimeReady(false)\n void ota.initialize().finally(() => {\n if (!cancelled) setRuntimeReady(true)\n })\n return () => {\n cancelled = true\n }\n }, [initializeRuntime])\n\n const returnToCheck = useCallback(() => {\n installActionPendingRef.current = false\n autoChainAdvancedRef.current = false\n setCheckState(\"checking\")\n setPage(\"check\")\n setCheckGeneration((generation) => generation + 1)\n }, [])\n\n useEffect(() => {\n if (previousDeviceRef.current === deviceRevision) return\n previousDeviceRef.current = deviceRevision\n performCheckGenerationRef.current += 1\n selectedCheckResultRef.current = null\n setUpdateFingerprint(null)\n setOfferedReleaseTransition(null)\n setCompletedReleaseTransition(null)\n setCompletedUpdate(false)\n setCompletedChangelogs([])\n setBatteryBlocked(false)\n setIsVersionChange(false)\n returnToCheck()\n }, [deviceRevision, returnToCheck])\n\n const navigateToProgress = useCallback(() => {\n installActionPendingRef.current = true\n ota.clearProgress()\n setPage(\"progress\")\n }, [])\n\n const continueApprovedChain = useCallback(\n (result: OtaCheckCurrentGlassesResult): boolean => {\n if (deviceRevision !== otaDeviceSessionRevision() || selectedCheckDeviceRef.current !== deviceRevision)\n return false\n if (installActionPendingRef.current || !isOtaAutoChainActive() || !result.updateInfo) return false\n const snapshot = ota.snapshot()\n if (snapshot.hotspotOtaVersion !== 1 && (!snapshot.wifiStatusKnown || !snapshot.wifiConnected)) return false\n\n const admission = tryAdvanceOtaAutoChain(\n otaAutoChainFingerprint(result),\n result.updateInfo.isDowngrade === true,\n releaseRangeTargetVersion(result),\n result.releaseVersion,\n )\n if (!admission.advance) return false\n\n checkCompletedRef.current = true\n ota.installSession.prepare(result)\n navigateToProgress()\n return true\n },\n [deviceRevision, navigateToProgress],\n )\n\n useEffect(() => {\n if (!runtimeReady || page !== \"check\") {\n if (checkStartedRef.current && !checkCompletedRef.current) {\n performCheckGenerationRef.current += 1\n checkStartedRef.current = false\n }\n return\n }\n const MIN_DISPLAY_TIME_MS = 1100\n const MAX_WAIT_FOR_VERSION_INFO_MS = 10_000\n const checkKey = `${deviceRevision}:${checkGeneration}`\n if (activeCheckKeyRef.current !== checkKey) {\n performCheckGenerationRef.current += 1\n activeCheckKeyRef.current = checkKey\n checkStartedRef.current = false\n checkCompletedRef.current = false\n selectedCheckResultRef.current = null\n installActionPendingRef.current = false\n setCheckState(\"checking\")\n }\n\n let reconnectTimeout: ReturnType<typeof setTimeout> | null = null\n\n const performCheck = async () => {\n if (checkCompletedRef.current) return\n if (isOtaAutoChainActive() && !otaSnapshot.ready) {\n if (checkStartedRef.current) {\n performCheckGenerationRef.current += 1\n checkStartedRef.current = false\n }\n const remainingMs = otaAutoChainReconnectWaitRemaining()\n if (remainingMs === null) return\n const reconnectGeneration = performCheckGenerationRef.current\n reconnectTimeout = setTimeout(() => {\n if (\n !mountedRef.current ||\n deviceRevision !== otaDeviceSessionRevision() ||\n reconnectGeneration !== performCheckGenerationRef.current ||\n ota.snapshot().ready\n )\n return\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setCheckState(\"error\")\n }, remainingMs)\n return\n }\n if (!otaSnapshot.connected) {\n if (checkStartedRef.current) {\n performCheckGenerationRef.current += 1\n checkStartedRef.current = false\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setCheckState(\"error\")\n return\n }\n checkCompletedRef.current = true\n onFinishedRef.current?.()\n return\n }\n if (checkStartedRef.current) return\n\n clearOtaAutoChainReconnectWait()\n checkStartedRef.current = true\n const myGeneration = ++performCheckGenerationRef.current\n const isCurrentCheck = () =>\n mountedRef.current &&\n myGeneration === performCheckGenerationRef.current &&\n deviceRevision === otaDeviceSessionRevision()\n const startTime = Date.now()\n try {\n const checkOptions = {\n waitForBuildNumberMs: MAX_WAIT_FOR_VERSION_INFO_MS,\n waitForBesVersionMs: 5000,\n waitForMtkVersionMs: 2000,\n waitForLegacyMigrationMs: isOtaAutoChainActive() ? OTA_AUTO_CHAIN_RECONNECT_TIMEOUT_MS : 0,\n refreshVersionInfo: true,\n fixClockBeforeCheck: false,\n }\n let result = await ota.checkForUpdates(checkOptions)\n if (!isCurrentCheck()) return\n if (!result.hasCheckCompleted && result.checkFailureReason === \"network\" && isOtaAutoChainActive()) {\n await new Promise((resolve) => setTimeout(resolve, AUTO_CHAIN_NETWORK_RETRY_DELAY_MS))\n if (!isCurrentCheck()) return\n result = await ota.checkForUpdates(checkOptions)\n }\n if (!isCurrentCheck()) return\n selectedCheckResultRef.current = result\n selectedCheckDeviceRef.current = deviceRevision\n await new Promise((resolve) => setTimeout(resolve, Math.max(0, MIN_DISPLAY_TIME_MS - (Date.now() - startTime))))\n if (!isCurrentCheck()) return\n\n if (result.skippedReason === \"disconnected\") {\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setCheckState(\"error\")\n return\n }\n if (result.skippedReason === \"missing_build\") {\n checkCompletedRef.current = true\n if (isOtaAutoChainActive()) {\n stopOtaAutoChain()\n setCheckState(\"error\")\n } else {\n onFinishedRef.current?.()\n }\n return\n }\n if (result.skippedReason === \"dev_build\") {\n stopOtaAutoChain()\n checkCompletedRef.current = true\n ota.clearUpdateAvailable()\n setCheckState(\"dev_build\")\n return\n }\n if (result.skippedReason === \"unofficial_client\") {\n stopOtaAutoChain()\n checkCompletedRef.current = true\n ota.clearUpdateAvailable()\n setUnofficialClientPackage(result.packageName ?? null)\n setCheckState(\"unofficial_client\")\n return\n }\n if (!result.hasCheckCompleted) {\n // A failed device verification is not a completed chain. Retain its\n // approval so Retry still verifies the release pin after legacy rescue.\n if (result.checkFailureReason !== \"version_info\") stopOtaAutoChain()\n checkCompletedRef.current = true\n setErrorKind(result.checkFailureReason ?? \"network\")\n setCheckState(\"error\")\n return\n }\n if (result.updateAvailable && result.updateInfo) {\n setIsUpdateRequired(result.isRequired)\n setIsVersionChange(result.updateInfo.isDowngrade === true)\n const fingerprint = otaAutoChainFingerprint(result)\n setUpdateFingerprint(fingerprint)\n if (!isOtaAutoChainActive()) {\n const fromVersion = currentReleaseVersion(ota.snapshot().appVersion)\n setOfferedReleaseTransition(result.releaseVersion ? {fromVersion, toVersion: result.releaseVersion} : null)\n }\n if (isOtaAutoChainActive() && !ota.snapshot().wifiStatusKnown && ota.snapshot().hotspotOtaVersion !== 1) {\n checkCompletedRef.current = true\n return\n }\n if (continueApprovedChain(result)) return\n checkCompletedRef.current = true\n setCheckState(\"update_available\")\n return\n }\n const completedApprovedSession = isOtaAutoChainActive()\n if (completedApprovedSession) {\n setCompletedChangelogs(releaseChangelogsForActiveChain())\n setCompletedReleaseTransition(releaseTransitionFromRange(otaAutoChainReleaseRange()))\n }\n setCompletedUpdate(completedApprovedSession)\n stopOtaAutoChain()\n checkCompletedRef.current = true\n ota.clearUpdateAvailable()\n setCheckState(\"no_update\")\n } catch (error) {\n console.error(\"OTA check failed:\", error)\n await new Promise((resolve) => setTimeout(resolve, Math.max(0, MIN_DISPLAY_TIME_MS - (Date.now() - startTime))))\n if (!isCurrentCheck()) return\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setErrorKind(\"network\")\n setCheckState(\"error\")\n }\n }\n\n void performCheck()\n return () => {\n if (reconnectTimeout) clearTimeout(reconnectTimeout)\n }\n }, [\n checkGeneration,\n deviceRevision,\n continueApprovedChain,\n otaSnapshot.connected,\n otaSnapshot.ready,\n otaSnapshot.wifiStatusKnown,\n page,\n runtimeReady,\n ])\n\n useEffect(() => {\n if (\n !runtimeReady ||\n page !== \"check\" ||\n (checkState !== \"checking\" && checkState !== \"update_available\") ||\n (!otaSnapshot.wifiStatusKnown && otaSnapshot.hotspotOtaVersion !== 1) ||\n !isOtaAutoChainActive()\n ) {\n return\n }\n const result = selectedCheckResultRef.current\n if (!result?.updateAvailable || !result.updateInfo) return\n if (!otaSnapshot.wifiConnected && otaSnapshot.hotspotOtaVersion !== 1) {\n setCheckState(\"update_available\")\n return\n }\n continueApprovedChain(result)\n }, [\n checkState,\n continueApprovedChain,\n otaSnapshot.hotspotOtaVersion,\n otaSnapshot.wifiConnected,\n otaSnapshot.wifiStatusKnown,\n page,\n runtimeReady,\n ])\n\n useEffect(() => {\n if (!runtimeReady || page !== \"progress\") return\n ota.installSession.attach()\n return () => ota.installSession.detach()\n }, [page, runtimeReady])\n\n const firmwareRestarting =\n page === \"progress\" &&\n ((!installSnapshot.connected && installSnapshot.displayState === \"restarting\") ||\n installSnapshot.versionChangePhase === \"restarting\")\n\n useEffect(() => {\n if (page !== \"progress\") return\n onFirmwareRestartingChangeRef.current?.(firmwareRestarting, true)\n }, [firmwareRestarting, page])\n\n useEffect(() => {\n if (page !== \"progress\") return\n return () => {\n onFirmwareRestartingChangeRef.current?.(false, false)\n }\n }, [page])\n\n useEffect(() => {\n if (\n page !== \"progress\" ||\n installSnapshot.displayState !== \"complete\" ||\n !installSnapshot.connected ||\n !isOtaAutoChainActive() ||\n autoChainAdvancedRef.current\n ) {\n return\n }\n const timeout = setTimeout(async () => {\n if (deviceRevision !== otaDeviceSessionRevision() || !isOtaAutoChainActive()) return\n autoChainAdvancedRef.current = true\n await ota.installSession.finish()\n if (deviceRevision !== otaDeviceSessionRevision()) return\n returnToCheck()\n }, AUTO_CHAIN_COMPLETE_DELAY_MS)\n return () => clearTimeout(timeout)\n }, [deviceRevision, installSnapshot.connected, installSnapshot.displayState, page, returnToCheck])\n\n const check = useCallback(() => {\n setBatteryBlocked(false)\n setOfferedReleaseTransition(null)\n setCompletedReleaseTransition(null)\n setCompletedUpdate(false)\n setCompletedChangelogs([])\n setPage(\"check\")\n setCheckState(\"checking\")\n setCheckGeneration((generation) => generation + 1)\n }, [])\n\n const install = useCallback(() => {\n if (installActionPendingRef.current || page !== \"check\") return\n if (deviceRevision !== otaDeviceSessionRevision() || selectedCheckDeviceRef.current !== deviceRevision) return\n const result = selectedCheckResultRef.current\n if (!result) {\n setErrorKind(\"network\")\n setCheckState(\"error\")\n return\n }\n const snapshot = ota.snapshot()\n if (snapshot.batteryLevel !== null && snapshot.batteryLevel < MINIMUM_OTA_BATTERY_LEVEL) {\n setBatteryBlocked(true)\n return\n }\n if (!snapshot.wifiStatusKnown && snapshot.hotspotOtaVersion !== 1) {\n check()\n return\n }\n if (!snapshot.wifiConnected && snapshot.hotspotOtaVersion !== 1) {\n onOpenWifiSetupRef.current?.()\n return\n }\n ota.installSession.prepare(result)\n setBatteryBlocked(false)\n setCompletedUpdate(false)\n setCompletedChangelogs([])\n if (updateFingerprint) {\n const fromVersion = offeredReleaseTransition\n ? offeredReleaseTransition.fromVersion\n : currentReleaseVersion(snapshot.appVersion)\n beginOtaAutoChain(updateFingerprint, isVersionChange, {\n fromVersion,\n toVersion: releaseRangeTargetVersion(result),\n releaseVersion: result.releaseVersion,\n })\n }\n navigateToProgress()\n }, [check, deviceRevision, isVersionChange, navigateToProgress, offeredReleaseTransition, page, updateFingerprint])\n\n useEffect(() => {\n if (\n batteryBlocked &&\n (otaSnapshot.batteryLevel === null || otaSnapshot.batteryLevel >= MINIMUM_OTA_BATTERY_LEVEL)\n ) {\n setBatteryBlocked(false)\n }\n }, [batteryBlocked, otaSnapshot.batteryLevel])\n\n const retryInstall = useCallback(() => {\n if (deviceRevision !== otaDeviceSessionRevision() || page !== \"progress\") return\n onFirmwareRestartingChangeRef.current?.(false, true)\n ota.installSession.retry()\n }, [deviceRevision, page])\n\n const finish = useCallback(async () => {\n if (deviceRevision !== otaDeviceSessionRevision()) return\n if (page === \"check\") {\n stopOtaAutoChain()\n onFinishedRef.current?.()\n return\n }\n const restartStillInProgress =\n installSnapshot.displayState === \"restarting\" ||\n installSnapshot.versionChangePhase === \"restarting\" ||\n installSnapshot.versionChangePhase === \"verifying\"\n if (restartStillInProgress) return\n const requiresGlassesReboot = shouldRequireGlassesRebootForBesFailure(\n installSnapshot.otaStatus,\n installSnapshot.otaProgress,\n installSnapshot.errorMsg,\n )\n if (requiresGlassesReboot) stopOtaAutoChain()\n await ota.installSession.finish()\n if (deviceRevision !== otaDeviceSessionRevision()) return\n returnToCheck()\n }, [deviceRevision, installSnapshot, page, returnToCheck])\n\n const discard = useCallback(async () => {\n if (deviceRevision !== otaDeviceSessionRevision()) return\n if (page !== \"progress\") return\n stopOtaAutoChain()\n await ota.installSession.discard()\n if (deviceRevision !== otaDeviceSessionRevision()) return\n returnToCheck()\n }, [deviceRevision, page, returnToCheck])\n\n const openWifiSetup = useCallback(() => {\n if (page === \"progress\") stopOtaAutoChain()\n onOpenWifiSetupRef.current?.()\n }, [page])\n\n const state = useMemo<MentraLiveOtaState>(() => {\n const hotspotSupported = otaSnapshot.hotspotOtaVersion === 1\n const canInstall = hotspotSupported || (otaSnapshot.wifiStatusKnown && otaSnapshot.wifiConnected)\n const autoChainActive = isOtaAutoChainActive()\n if (!runtimeReady) {\n return {\n screen: \"initializing\",\n connected: otaSnapshot.connected,\n batteryLevel: otaSnapshot.batteryLevel,\n transport: null,\n updateRequired: isUpdateRequired,\n versionChange: isVersionChange,\n versionChangeConverged: false,\n versionChangePhase: null,\n wifiConnected: otaSnapshot.wifiConnected,\n wifiStatusKnown: otaSnapshot.wifiStatusKnown,\n hotspotSupported,\n hotspotPhase: \"idle\",\n hotspotArtifactPercent: null,\n hotspotArtifact: null,\n phase: null,\n step: null,\n currentStep: null,\n totalSteps: null,\n progress: null,\n installingApkOnly: false,\n firmwareRestarting: false,\n error: null,\n canInstall: false,\n canRetry: false,\n canFinish: false,\n canDismiss: false,\n canDiscard: false,\n canOpenWifiSetup: false,\n continueDisabled: false,\n completedUpdate: false,\n releaseTransition: null,\n changelogs: [],\n glassesPackageName: null,\n }\n }\n\n if (page === \"check\") {\n const wifiRequired = otaSnapshot.wifiStatusKnown && !otaSnapshot.wifiConnected && !hotspotSupported\n let screen: MentraLiveOtaScreen\n if (checkState === \"checking\") screen = autoChainActive ? \"finishing\" : \"checking\"\n else if (checkState === \"update_available\") {\n screen = wifiRequired ? \"wifi_required\" : batteryBlocked ? \"battery_required\" : \"update_available\"\n } else if (checkState === \"no_update\") screen = \"up_to_date\"\n else if (checkState === \"dev_build\") screen = \"dev_build\"\n else if (checkState === \"unofficial_client\") screen = \"unofficial_client\"\n else screen = errorKind === \"pin_unavailable\" ? \"update_info_unavailable\" : \"check_failed\"\n\n let error: MentraLiveOtaError | null = null\n if (screen === \"check_failed\") {\n error = {\n code: \"check_failed\",\n message:\n errorKind === \"version_info\"\n ? \"Couldn't read the glasses software versions. Keep the glasses connected and try again.\"\n : \"Couldn't check for updates. Please check your connection and try again.\",\n copyKey: errorKind === \"version_info\" ? \"ota:versionInfoFailedMessage\" : \"ota:checkFailedMessage\",\n glassesCode: null,\n }\n } else if (screen === \"update_info_unavailable\") {\n error = {\n code: \"update_info_unavailable\",\n message: \"Update information for this app version is unavailable.\",\n copyKey: \"ota:updateInfoUnavailableMessage\",\n glassesCode: null,\n }\n }\n return {\n screen,\n connected: otaSnapshot.connected,\n batteryLevel: otaSnapshot.batteryLevel,\n transport: hotspotSupported ? \"hotspot\" : otaSnapshot.wifiConnected ? \"wifi\" : null,\n updateRequired: isUpdateRequired,\n versionChange: isVersionChange,\n versionChangeConverged: false,\n versionChangePhase: null,\n wifiConnected: otaSnapshot.wifiConnected,\n wifiStatusKnown: otaSnapshot.wifiStatusKnown,\n hotspotSupported,\n hotspotPhase: \"idle\",\n hotspotArtifactPercent: null,\n hotspotArtifact: null,\n phase: null,\n step: null,\n currentStep: null,\n totalSteps: null,\n progress: null,\n installingApkOnly: false,\n firmwareRestarting: false,\n error,\n canInstall: screen === \"update_available\" && canInstall,\n canRetry: screen === \"check_failed\",\n canFinish:\n screen === \"up_to_date\" ||\n screen === \"dev_build\" ||\n screen === \"unofficial_client\" ||\n screen === \"update_info_unavailable\",\n canDismiss:\n (screen === \"update_available\" || screen === \"wifi_required\" || screen === \"battery_required\") &&\n !isUpdateRequired &&\n !autoChainActive,\n canDiscard: false,\n canOpenWifiSetup: screen === \"wifi_required\",\n continueDisabled: false,\n completedUpdate: screen === \"up_to_date\" && completedUpdate,\n releaseTransition:\n screen === \"update_available\" || screen === \"wifi_required\"\n ? autoChainActive\n ? releaseTransitionFromRange(otaAutoChainReleaseRange())\n : offeredReleaseTransition\n : screen === \"up_to_date\"\n ? completedReleaseTransition\n : null,\n changelogs: screen === \"up_to_date\" ? completedChangelogs : [],\n glassesPackageName: screen === \"unofficial_client\" ? unofficialClientPackage : null,\n }\n }\n\n const requiresGlassesReboot = shouldRequireGlassesRebootForBesFailure(\n installSnapshot.otaStatus,\n installSnapshot.otaProgress,\n installSnapshot.errorMsg,\n )\n const showChangeWifi = shouldShowChangeWifiForOtaDownloadFailure(\n installSnapshot.otaStatus,\n installSnapshot.otaProgress,\n installSnapshot.errorMsg,\n )\n // The raw code the glasses attached to their failure report, kept for support even when\n // phone-side copy outranks it. Only a failed ota_status carries a current code.\n const glassesCode = installSnapshot.otaStatus?.status === \"failed\" ? installSnapshot.otaStatus.error || null : null\n // Precedence mirrors the legacy screen: the BES restart instruction, then a phone-side\n // watchdog/preflight message (English-only, no copy key), then the glasses code mapped to\n // copy (unknown codes get the generic glasses-error copy rather than the raw code).\n let displayedError: string\n let copyKey: string | null\n if (requiresGlassesReboot) {\n displayedError = BES_INSTALL_RESTART_MESSAGE\n copyKey = OTA_ERROR_BES_RESTART_REQUIRED_COPY_KEY\n } else if (installSnapshot.errorMsg) {\n displayedError = installSnapshot.errorMsg\n copyKey = null\n } else {\n displayedError = getOtaErrorMessage(glassesCode)\n copyKey = otaErrorCopyKey(glassesCode)\n }\n const progressState = progressScreen(installSnapshot)\n const screen = progressState === \"complete\" && autoChainActive ? \"finishing\" : progressState\n const error: MentraLiveOtaError | null =\n screen === \"failed\"\n ? {\n code: requiresGlassesReboot ? \"bes_restart_required\" : \"install_failed\",\n message: displayedError,\n copyKey,\n glassesCode,\n }\n : null\n const totalSteps = installSnapshot.otaStatus?.totalSteps ?? null\n const artifact = installSnapshot.hotspotArtifact\n const changelogs = screen === \"complete\" ? releaseChangelogsForActiveChain() : []\n return {\n screen,\n connected: installSnapshot.connected,\n batteryLevel: otaSnapshot.batteryLevel,\n transport: installSnapshot.transport,\n updateRequired: isUpdateRequired,\n versionChange: installSnapshot.isVersionChange,\n versionChangeConverged: installSnapshot.versionChangeConverged,\n versionChangePhase: installSnapshot.versionChangePhase,\n wifiConnected: otaSnapshot.wifiConnected,\n wifiStatusKnown: otaSnapshot.wifiStatusKnown,\n hotspotSupported,\n hotspotPhase: installSnapshot.hotspotPhase,\n hotspotArtifactPercent: installSnapshot.hotspotArtifactPercent,\n hotspotArtifact: artifact ? {kind: artifact.kind, index: artifact.index, totalCount: artifact.totalCount} : null,\n phase: installSnapshot.otaStatus?.phase ?? installSnapshot.otaProgress?.stage ?? null,\n step: installSnapshot.otaStatus?.stepType ?? null,\n currentStep: installSnapshot.otaStatus?.currentStep ?? null,\n totalSteps,\n progress: installProgress(installSnapshot),\n installingApkOnly:\n installSnapshot.otaStatus?.stepType === \"apk\" &&\n installSnapshot.otaStatus.phase === \"install\" &&\n totalSteps === 1,\n firmwareRestarting,\n error,\n canInstall: false,\n canRetry: screen === \"failed\" && !requiresGlassesReboot,\n canFinish: screen === \"complete\" || (screen === \"failed\" && requiresGlassesReboot),\n canDismiss: false,\n canDiscard: screen === \"disconnected\",\n canOpenWifiSetup: screen === \"failed\" && !hotspotSupported && showChangeWifi,\n continueDisabled: installSnapshot.continueButtonDisabled,\n completedUpdate: false,\n releaseTransition: releaseTransitionFromRange(otaAutoChainReleaseRange()),\n changelogs,\n glassesPackageName: null,\n }\n }, [\n unofficialClientPackage,\n checkState,\n batteryBlocked,\n completedChangelogs,\n completedReleaseTransition,\n completedUpdate,\n errorKind,\n firmwareRestarting,\n installSnapshot,\n isUpdateRequired,\n isVersionChange,\n otaSnapshot,\n offeredReleaseTransition,\n page,\n runtimeReady,\n deviceRevision,\n ])\n\n return useMemo(\n () => ({state, check, retryCheck: check, install, retryInstall, finish, discard, openWifiSetup}),\n [check, discard, finish, install, openWifiSetup, retryInstall, state],\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useMentraLiveOta.js","sourceRoot":"","sources":["../../src/react/useMentraLiveOta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA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AAkB;YAClB,KAAK;YACL,UAAU,EAAE,KAAK;YACjB,QAAQ,EAAE,MAAM,KAAK,QAAQ,IAAI,CAAC,qBAAqB;YACvD,SAAS,EAAE,MAAM,KAAK,UAAU,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,qBAAqB,CAAC;YAClF,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,MAAM,KAAK,cAAc;YACrC,gBAAgB,EAAE,MAAM,KAAK,QAAQ,IAAI,CAAC,gBAAgB,IAAI,cAAc;YAC5E,gBAAgB,EAAE,eAAe,CAAC,sBAAsB;YACxD,eAAe,EAAE,KAAK;YACtB,iBAAiB,EAAE,0BAA0B,CAAC,wBAAwB,EAAE,CAAC;YACzE,UAAU;YACV,kBAAkB,EAAE,IAAI;SACzB,CAAA;IACH,CAAC,EAAE;QACD,uBAAuB;QACvB,UAAU;QACV,cAAc;QACd,mBAAmB;QACnB,0BAA0B;QAC1B,eAAe;QACf,SAAS;QACT,kBAAkB;QAClB,eAAe;QACf,gBAAgB;QAChB,eAAe;QACf,WAAW;QACX,wBAAwB;QACxB,IAAI;QACJ,YAAY;QACZ,cAAc;KACf,CAAC,CAAA;IAEF,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,EAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAC,CAAC,EAChG,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,CAAC,CACtE,CAAA;AACH,CAAC","sourcesContent":["import {useCallback, useEffect, useMemo, useRef, useState} from \"react\"\n\nimport {ota} from \"../facades/ota\"\nimport {\n beginOtaAutoChain,\n clearOtaAutoChainReconnectWait,\n isOtaAutoChainActive,\n OTA_AUTO_CHAIN_RECONNECT_TIMEOUT_MS,\n otaAutoChainFingerprint,\n otaAutoChainReleaseRange,\n otaAutoChainReconnectWaitRemaining,\n stopOtaAutoChain,\n tryAdvanceOtaAutoChain,\n type OtaAutoChainReleaseRange,\n} from \"../services/OtaAutoChain\"\nimport {\n BES_INSTALL_RESTART_MESSAGE,\n OTA_ERROR_BES_RESTART_REQUIRED_COPY_KEY,\n getOtaErrorMessage,\n otaErrorCopyKey,\n shouldRequireGlassesRebootForBesFailure,\n shouldShowChangeWifiForOtaDownloadFailure,\n} from \"../services/OtaErrorMapping\"\nimport type {OtaInstallSnapshot} from \"../services/OtaInstallCoordinator\"\nimport type {OtaCheckCurrentGlassesResult} from \"../services/OtaUpdateCheckService\"\nimport {otaDeviceSessionRevision, subscribeOtaDeviceSession} from \"../services/OtaDeviceSession\"\nimport type {ReleaseChangelog} from \"../facades/ota\"\nimport {useEngineSnapshot} from \"./useEngineSnapshot\"\n\nexport type MentraLiveOtaFlowPage = \"check\" | \"progress\"\n\nexport type MentraLiveOtaScreen =\n | \"initializing\"\n | \"checking\"\n | \"finishing\"\n | \"update_available\"\n | \"battery_required\"\n | \"wifi_required\"\n | \"up_to_date\"\n | \"dev_build\"\n | \"unofficial_client\"\n | \"check_failed\"\n | \"update_info_unavailable\"\n | \"starting\"\n | \"preparing_hotspot\"\n | \"updating\"\n | \"restarting\"\n | \"verifying\"\n | \"complete\"\n | \"failed\"\n | \"disconnected\"\n\nexport type MentraLiveOtaErrorCode =\n | \"check_failed\"\n | \"update_info_unavailable\"\n | \"install_failed\"\n | \"bes_restart_required\"\n\nexport type MentraLiveOtaError = {\n code: MentraLiveOtaErrorCode\n /** English copy for hosts without localization. */\n message: string\n /**\n * Copy key for `message` when the failure maps to known copy, so localized hosts can\n * translate it. Null for phone-side watchdog and preflight messages, which are English-only.\n * Optional so host code that builds this type by hand keeps compiling; the hook always sets it.\n */\n copyKey?: string | null\n /**\n * Raw failure code reported by the glasses (`ota_status.error`), for support. Null when the\n * failure originated on the phone. Optional for the same source-compatibility reason.\n */\n glassesCode?: string | null\n}\n\nexport type MentraLiveOtaTransport = \"wifi\" | \"hotspot\"\nexport type MentraLiveOtaHotspotPhase = \"idle\" | \"downloading\" | \"starting_hotspot\" | \"joining_hotspot\" | \"serving\"\nexport type MentraLiveOtaInstallPhase = \"download\" | \"install\"\nexport type MentraLiveOtaStep = \"apk\" | \"mtk\" | \"bes\"\n\nexport type MentraLiveOtaReleaseTransition = {\n /** Current glasses software label. Temporarily backed by the reported ASG app version. */\n fromVersion: string | null\n /** Exact coordinated release identity for the selected OTA pin. */\n toVersion: string\n}\n\nexport type MentraLiveOtaState = {\n screen: MentraLiveOtaScreen\n connected: boolean\n batteryLevel: number | null\n transport: MentraLiveOtaTransport | null\n updateRequired: boolean\n versionChange: boolean\n versionChangeConverged: boolean\n versionChangePhase: \"installing\" | \"restarting\" | \"verifying\" | null\n wifiConnected: boolean\n wifiStatusKnown: boolean\n hotspotSupported: boolean\n hotspotPhase: MentraLiveOtaHotspotPhase\n hotspotArtifactPercent: number | null\n /**\n * Current phone download context. Index is zero-based; percent applies to this file only.\n * Optional for source compatibility; this hook returns null when no file is active.\n */\n hotspotArtifact?: {kind: MentraLiveOtaStep; index: number; totalCount: number} | null\n phase: MentraLiveOtaInstallPhase | null\n step: MentraLiveOtaStep | null\n currentStep: number | null\n totalSteps: number | null\n progress: number | null\n installingApkOnly: boolean\n firmwareRestarting: boolean\n error: MentraLiveOtaError | null\n canInstall: boolean\n canRetry: boolean\n canFinish: boolean\n canDismiss: boolean\n canDiscard: boolean\n canOpenWifiSetup: boolean\n continueDisabled: boolean\n /** True only after an approved update session reaches a final no-update check. */\n completedUpdate: boolean\n /** Release labels for the offered or just-completed coordinated update. */\n releaseTransition: MentraLiveOtaReleaseTransition | null\n /** Release notes crossed by this update, newest first. Populated on completion. */\n changelogs: ReleaseChangelog[]\n /** Sideloaded glasses client package, set only on the `unofficial_client` screen. */\n glassesPackageName: string | null\n}\n\nexport type UseMentraLiveOtaOptions = {\n /** Entry page. `progress` exists for interrupted-session recovery. */\n initialPage?: MentraLiveOtaFlowPage\n /** Start Engine's OTA-only projections. Full Engine hosts should pass false. */\n initializeRuntime?: boolean\n /** Called after the final check or when an optional update is dismissed. */\n onFinished?: () => void\n /** Host-owned Wi-Fi setup for glasses without hotspot OTA support. */\n onOpenWifiSetup?: () => void\n /** Lets a host coordinate its connection overlay with OTA firmware restarts. */\n onFirmwareRestartingChange?: (restarting: boolean, progressActive: boolean) => void\n}\n\nexport type MentraLiveOtaController = {\n state: MentraLiveOtaState\n check: () => void\n retryCheck: () => void\n install: () => void\n retryInstall: () => void\n finish: () => void\n discard: () => void\n openWifiSetup: () => void\n}\n\ntype CheckState = \"checking\" | \"update_available\" | \"no_update\" | \"dev_build\" | \"unofficial_client\" | \"error\"\n\nconst AUTO_CHAIN_NETWORK_RETRY_DELAY_MS = 5000\nconst AUTO_CHAIN_COMPLETE_DELAY_MS = 750\nexport const MINIMUM_OTA_BATTERY_LEVEL = 25\n\nfunction releaseRangeTargetVersion(result: OtaCheckCurrentGlassesResult): string | null {\n return result.releaseVersion ?? result.updateInfo?.versionName ?? result.latestVersionInfo?.versionName ?? null\n}\n\nfunction currentReleaseVersion(appVersion: string | null): string | null {\n const version = appVersion?.trim()\n return version || null\n}\n\nfunction releaseTransitionFromRange(range: OtaAutoChainReleaseRange | null): MentraLiveOtaReleaseTransition | null {\n if (!range?.releaseVersion) return null\n return {fromVersion: range.fromVersion, toVersion: range.releaseVersion}\n}\n\nfunction releaseChangelogsForActiveChain(): ReleaseChangelog[] {\n const range = otaAutoChainReleaseRange()\n if (!range?.toVersion) return []\n try {\n return ota.getReleaseChangelogs(range.fromVersion, range.toVersion)\n } catch {\n try {\n return ota.getReleaseChangelogs(null, range.toVersion)\n } catch {\n return []\n }\n }\n}\n\nfunction installProgress(snapshot: OtaInstallSnapshot): number | null {\n if (snapshot.displayState !== \"updating\") return null\n const {otaStatus} = snapshot\n const isDownload = otaStatus?.phase === \"download\"\n const totalSteps = otaStatus?.totalSteps ?? 1\n const rawPercent = isDownload\n ? (otaStatus?.stepPercent ?? 0)\n : totalSteps >= 2\n ? (otaStatus?.overallPercent ?? 0)\n : (otaStatus?.stepPercent ?? 0)\n return Math.min(Math.max(rawPercent, snapshot.mtkInstallStallSimulatedPercent ?? 0, 0), 100)\n}\n\nfunction progressScreen(snapshot: OtaInstallSnapshot): MentraLiveOtaScreen {\n if (snapshot.versionChangePhase === \"restarting\") return \"restarting\"\n if (snapshot.versionChangePhase === \"verifying\") return \"verifying\"\n switch (snapshot.displayState) {\n case \"starting\":\n return snapshot.hotspotPhase === \"idle\" || snapshot.hotspotPhase === \"serving\" ? \"starting\" : \"preparing_hotspot\"\n case \"updating\":\n return \"updating\"\n case \"restarting\":\n return \"restarting\"\n case \"complete\":\n return \"complete\"\n case \"failed\":\n return \"failed\"\n default:\n return \"disconnected\"\n }\n}\n\n/**\n * Headless Mentra Live OTA flow. Engine owns checking, hotspot staging,\n * APK/MTK/BES sequencing, restart recovery, retries, and verification; the host\n * renders semantic state and invokes these idempotent actions.\n */\nexport function useMentraLiveOta(options: UseMentraLiveOtaOptions = {}): MentraLiveOtaController {\n const {\n initialPage = \"check\",\n initializeRuntime = true,\n onFinished,\n onFirmwareRestartingChange,\n onOpenWifiSetup,\n } = options\n const otaSnapshot = useEngineSnapshot(ota.snapshot, ota.onSnapshot)\n const deviceRevision = useEngineSnapshot(otaDeviceSessionRevision, subscribeOtaDeviceSession)\n const installSnapshot = useEngineSnapshot(ota.installSession.snapshot, ota.installSession.onSnapshot)\n const [page, setPage] = useState<MentraLiveOtaFlowPage>(initialPage)\n const [runtimeReady, setRuntimeReady] = useState(!initializeRuntime)\n const [checkState, setCheckState] = useState<CheckState>(\"checking\")\n const [isUpdateRequired, setIsUpdateRequired] = useState(true)\n const [isVersionChange, setIsVersionChange] = useState(false)\n const [errorKind, setErrorKind] = useState<\"network\" | \"pin_unavailable\" | \"version_info\">(\"network\")\n const [unofficialClientPackage, setUnofficialClientPackage] = useState<string | null>(null)\n const [updateFingerprint, setUpdateFingerprint] = useState<string | null>(null)\n const [offeredReleaseTransition, setOfferedReleaseTransition] = useState<MentraLiveOtaReleaseTransition | null>(null)\n const [completedReleaseTransition, setCompletedReleaseTransition] = useState<MentraLiveOtaReleaseTransition | null>(\n null,\n )\n const [completedUpdate, setCompletedUpdate] = useState(false)\n const [completedChangelogs, setCompletedChangelogs] = useState<ReleaseChangelog[]>([])\n const [batteryBlocked, setBatteryBlocked] = useState(false)\n const [checkGeneration, setCheckGeneration] = useState(0)\n const mountedRef = useRef(false)\n const performCheckGenerationRef = useRef(0)\n const activeCheckKeyRef = useRef<string | null>(null)\n const checkStartedRef = useRef(false)\n const checkCompletedRef = useRef(false)\n const selectedCheckResultRef = useRef<OtaCheckCurrentGlassesResult | null>(null)\n const selectedCheckDeviceRef = useRef(deviceRevision)\n const previousDeviceRef = useRef(deviceRevision)\n const autoChainAdvancedRef = useRef(false)\n const installActionPendingRef = useRef(false)\n const onFinishedRef = useRef(onFinished)\n const onOpenWifiSetupRef = useRef(onOpenWifiSetup)\n const onFirmwareRestartingChangeRef = useRef(onFirmwareRestartingChange)\n onFinishedRef.current = onFinished\n onOpenWifiSetupRef.current = onOpenWifiSetup\n onFirmwareRestartingChangeRef.current = onFirmwareRestartingChange\n\n useEffect(() => {\n mountedRef.current = true\n return () => {\n mountedRef.current = false\n }\n }, [])\n\n useEffect(() => {\n if (!initializeRuntime) {\n setRuntimeReady(true)\n return\n }\n let cancelled = false\n setRuntimeReady(false)\n void ota.initialize().finally(() => {\n if (!cancelled) setRuntimeReady(true)\n })\n return () => {\n cancelled = true\n }\n }, [initializeRuntime])\n\n const returnToCheck = useCallback(() => {\n installActionPendingRef.current = false\n autoChainAdvancedRef.current = false\n setCheckState(\"checking\")\n setPage(\"check\")\n setCheckGeneration((generation) => generation + 1)\n }, [])\n\n useEffect(() => {\n if (previousDeviceRef.current === deviceRevision) return\n previousDeviceRef.current = deviceRevision\n performCheckGenerationRef.current += 1\n selectedCheckResultRef.current = null\n setUpdateFingerprint(null)\n setOfferedReleaseTransition(null)\n setCompletedReleaseTransition(null)\n setCompletedUpdate(false)\n setCompletedChangelogs([])\n setBatteryBlocked(false)\n setIsVersionChange(false)\n returnToCheck()\n }, [deviceRevision, returnToCheck])\n\n const navigateToProgress = useCallback(() => {\n installActionPendingRef.current = true\n ota.clearProgress()\n setPage(\"progress\")\n }, [])\n\n const continueApprovedChain = useCallback(\n (result: OtaCheckCurrentGlassesResult): boolean => {\n if (deviceRevision !== otaDeviceSessionRevision() || selectedCheckDeviceRef.current !== deviceRevision)\n return false\n if (installActionPendingRef.current || !isOtaAutoChainActive() || !result.updateInfo) return false\n const snapshot = ota.snapshot()\n if (snapshot.hotspotOtaVersion !== 1 && (!snapshot.wifiStatusKnown || !snapshot.wifiConnected)) return false\n\n const admission = tryAdvanceOtaAutoChain(\n otaAutoChainFingerprint(result),\n result.updateInfo.isDowngrade === true,\n releaseRangeTargetVersion(result),\n result.releaseVersion,\n )\n if (!admission.advance) return false\n\n checkCompletedRef.current = true\n ota.installSession.prepare(result)\n navigateToProgress()\n return true\n },\n [deviceRevision, navigateToProgress],\n )\n\n useEffect(() => {\n if (!runtimeReady || page !== \"check\") {\n if (checkStartedRef.current && !checkCompletedRef.current) {\n performCheckGenerationRef.current += 1\n checkStartedRef.current = false\n }\n return\n }\n const MIN_DISPLAY_TIME_MS = 1100\n const MAX_WAIT_FOR_VERSION_INFO_MS = 10_000\n const checkKey = `${deviceRevision}:${checkGeneration}`\n if (activeCheckKeyRef.current !== checkKey) {\n performCheckGenerationRef.current += 1\n activeCheckKeyRef.current = checkKey\n checkStartedRef.current = false\n checkCompletedRef.current = false\n selectedCheckResultRef.current = null\n installActionPendingRef.current = false\n setCheckState(\"checking\")\n }\n\n let reconnectTimeout: ReturnType<typeof setTimeout> | null = null\n\n const performCheck = async () => {\n if (checkCompletedRef.current) return\n if (isOtaAutoChainActive() && !otaSnapshot.ready) {\n if (checkStartedRef.current) {\n performCheckGenerationRef.current += 1\n checkStartedRef.current = false\n }\n const remainingMs = otaAutoChainReconnectWaitRemaining()\n if (remainingMs === null) return\n const reconnectGeneration = performCheckGenerationRef.current\n reconnectTimeout = setTimeout(() => {\n if (\n !mountedRef.current ||\n deviceRevision !== otaDeviceSessionRevision() ||\n reconnectGeneration !== performCheckGenerationRef.current ||\n ota.snapshot().ready\n )\n return\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setCheckState(\"error\")\n }, remainingMs)\n return\n }\n if (!otaSnapshot.connected) {\n if (checkStartedRef.current) {\n performCheckGenerationRef.current += 1\n checkStartedRef.current = false\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setCheckState(\"error\")\n return\n }\n checkCompletedRef.current = true\n onFinishedRef.current?.()\n return\n }\n if (checkStartedRef.current) return\n\n clearOtaAutoChainReconnectWait()\n checkStartedRef.current = true\n const myGeneration = ++performCheckGenerationRef.current\n const isCurrentCheck = () =>\n mountedRef.current &&\n myGeneration === performCheckGenerationRef.current &&\n deviceRevision === otaDeviceSessionRevision()\n const startTime = Date.now()\n try {\n const checkOptions = {\n waitForBuildNumberMs: MAX_WAIT_FOR_VERSION_INFO_MS,\n waitForBesVersionMs: 5000,\n waitForMtkVersionMs: 2000,\n waitForLegacyMigrationMs: isOtaAutoChainActive() ? OTA_AUTO_CHAIN_RECONNECT_TIMEOUT_MS : 0,\n refreshVersionInfo: true,\n fixClockBeforeCheck: false,\n }\n let result = await ota.checkForUpdates(checkOptions)\n if (!isCurrentCheck()) return\n if (!result.hasCheckCompleted && result.checkFailureReason === \"network\" && isOtaAutoChainActive()) {\n await new Promise((resolve) => setTimeout(resolve, AUTO_CHAIN_NETWORK_RETRY_DELAY_MS))\n if (!isCurrentCheck()) return\n result = await ota.checkForUpdates(checkOptions)\n }\n if (!isCurrentCheck()) return\n selectedCheckResultRef.current = result\n selectedCheckDeviceRef.current = deviceRevision\n await new Promise((resolve) => setTimeout(resolve, Math.max(0, MIN_DISPLAY_TIME_MS - (Date.now() - startTime))))\n if (!isCurrentCheck()) return\n\n if (result.skippedReason === \"disconnected\") {\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setCheckState(\"error\")\n return\n }\n if (result.skippedReason === \"missing_build\") {\n checkCompletedRef.current = true\n if (isOtaAutoChainActive()) {\n stopOtaAutoChain()\n setCheckState(\"error\")\n } else {\n onFinishedRef.current?.()\n }\n return\n }\n if (result.skippedReason === \"dev_build\") {\n stopOtaAutoChain()\n checkCompletedRef.current = true\n ota.clearUpdateAvailable()\n setCheckState(\"dev_build\")\n return\n }\n if (result.skippedReason === \"unofficial_client\") {\n stopOtaAutoChain()\n checkCompletedRef.current = true\n ota.clearUpdateAvailable()\n setUnofficialClientPackage(result.packageName ?? null)\n setCheckState(\"unofficial_client\")\n return\n }\n if (!result.hasCheckCompleted) {\n // A failed device verification is not a completed chain. Retain its\n // approval so Retry still verifies the release pin after legacy rescue.\n if (result.checkFailureReason !== \"version_info\") stopOtaAutoChain()\n checkCompletedRef.current = true\n setErrorKind(result.checkFailureReason ?? \"network\")\n setCheckState(\"error\")\n return\n }\n if (result.updateAvailable && result.updateInfo) {\n setIsUpdateRequired(result.isRequired)\n setIsVersionChange(result.updateInfo.isDowngrade === true)\n const fingerprint = otaAutoChainFingerprint(result)\n setUpdateFingerprint(fingerprint)\n if (!isOtaAutoChainActive()) {\n const fromVersion = currentReleaseVersion(ota.snapshot().appVersion)\n setOfferedReleaseTransition(result.releaseVersion ? {fromVersion, toVersion: result.releaseVersion} : null)\n }\n if (isOtaAutoChainActive() && !ota.snapshot().wifiStatusKnown && ota.snapshot().hotspotOtaVersion !== 1) {\n checkCompletedRef.current = true\n return\n }\n if (continueApprovedChain(result)) return\n checkCompletedRef.current = true\n setCheckState(\"update_available\")\n return\n }\n const completedApprovedSession = isOtaAutoChainActive()\n if (completedApprovedSession) {\n setCompletedChangelogs(releaseChangelogsForActiveChain())\n setCompletedReleaseTransition(releaseTransitionFromRange(otaAutoChainReleaseRange()))\n }\n setCompletedUpdate(completedApprovedSession)\n stopOtaAutoChain()\n checkCompletedRef.current = true\n ota.clearUpdateAvailable()\n setCheckState(\"no_update\")\n } catch (error) {\n console.error(\"OTA check failed:\", error)\n await new Promise((resolve) => setTimeout(resolve, Math.max(0, MIN_DISPLAY_TIME_MS - (Date.now() - startTime))))\n if (!isCurrentCheck()) return\n stopOtaAutoChain()\n checkCompletedRef.current = true\n setErrorKind(\"network\")\n setCheckState(\"error\")\n }\n }\n\n void performCheck()\n return () => {\n if (reconnectTimeout) clearTimeout(reconnectTimeout)\n }\n }, [\n checkGeneration,\n deviceRevision,\n continueApprovedChain,\n otaSnapshot.connected,\n otaSnapshot.ready,\n otaSnapshot.wifiStatusKnown,\n page,\n runtimeReady,\n ])\n\n useEffect(() => {\n if (\n !runtimeReady ||\n page !== \"check\" ||\n (checkState !== \"checking\" && checkState !== \"update_available\") ||\n (!otaSnapshot.wifiStatusKnown && otaSnapshot.hotspotOtaVersion !== 1) ||\n !isOtaAutoChainActive()\n ) {\n return\n }\n const result = selectedCheckResultRef.current\n if (!result?.updateAvailable || !result.updateInfo) return\n if (!otaSnapshot.wifiConnected && otaSnapshot.hotspotOtaVersion !== 1) {\n setCheckState(\"update_available\")\n return\n }\n continueApprovedChain(result)\n }, [\n checkState,\n continueApprovedChain,\n otaSnapshot.hotspotOtaVersion,\n otaSnapshot.wifiConnected,\n otaSnapshot.wifiStatusKnown,\n page,\n runtimeReady,\n ])\n\n useEffect(() => {\n if (!runtimeReady || page !== \"progress\") return\n ota.installSession.attach()\n return () => ota.installSession.detach()\n }, [page, runtimeReady])\n\n const firmwareRestarting =\n page === \"progress\" &&\n ((!installSnapshot.connected && installSnapshot.displayState === \"restarting\") ||\n installSnapshot.versionChangePhase === \"restarting\")\n\n useEffect(() => {\n if (page !== \"progress\") return\n onFirmwareRestartingChangeRef.current?.(firmwareRestarting, true)\n }, [firmwareRestarting, page])\n\n useEffect(() => {\n if (page !== \"progress\") return\n return () => {\n onFirmwareRestartingChangeRef.current?.(false, false)\n }\n }, [page])\n\n useEffect(() => {\n if (\n page !== \"progress\" ||\n installSnapshot.displayState !== \"complete\" ||\n !installSnapshot.connected ||\n !isOtaAutoChainActive() ||\n autoChainAdvancedRef.current\n ) {\n return\n }\n const timeout = setTimeout(async () => {\n if (deviceRevision !== otaDeviceSessionRevision() || !isOtaAutoChainActive()) return\n autoChainAdvancedRef.current = true\n await ota.installSession.finish()\n if (deviceRevision !== otaDeviceSessionRevision()) return\n returnToCheck()\n }, AUTO_CHAIN_COMPLETE_DELAY_MS)\n return () => clearTimeout(timeout)\n }, [deviceRevision, installSnapshot.connected, installSnapshot.displayState, page, returnToCheck])\n\n const check = useCallback(() => {\n setBatteryBlocked(false)\n setOfferedReleaseTransition(null)\n setCompletedReleaseTransition(null)\n setCompletedUpdate(false)\n setCompletedChangelogs([])\n setPage(\"check\")\n setCheckState(\"checking\")\n setCheckGeneration((generation) => generation + 1)\n }, [])\n\n const install = useCallback(() => {\n if (installActionPendingRef.current || page !== \"check\") return\n if (deviceRevision !== otaDeviceSessionRevision() || selectedCheckDeviceRef.current !== deviceRevision) return\n const result = selectedCheckResultRef.current\n if (!result) {\n setErrorKind(\"network\")\n setCheckState(\"error\")\n return\n }\n const snapshot = ota.snapshot()\n if (snapshot.batteryLevel !== null && snapshot.batteryLevel < MINIMUM_OTA_BATTERY_LEVEL) {\n setBatteryBlocked(true)\n return\n }\n if (!snapshot.wifiStatusKnown && snapshot.hotspotOtaVersion !== 1) {\n check()\n return\n }\n if (!snapshot.wifiConnected && snapshot.hotspotOtaVersion !== 1) {\n onOpenWifiSetupRef.current?.()\n return\n }\n ota.installSession.prepare(result)\n setBatteryBlocked(false)\n setCompletedUpdate(false)\n setCompletedChangelogs([])\n if (updateFingerprint) {\n const fromVersion = offeredReleaseTransition\n ? offeredReleaseTransition.fromVersion\n : currentReleaseVersion(snapshot.appVersion)\n beginOtaAutoChain(updateFingerprint, isVersionChange, {\n fromVersion,\n toVersion: releaseRangeTargetVersion(result),\n releaseVersion: result.releaseVersion,\n })\n }\n navigateToProgress()\n }, [check, deviceRevision, isVersionChange, navigateToProgress, offeredReleaseTransition, page, updateFingerprint])\n\n useEffect(() => {\n if (\n batteryBlocked &&\n (otaSnapshot.batteryLevel === null || otaSnapshot.batteryLevel >= MINIMUM_OTA_BATTERY_LEVEL)\n ) {\n setBatteryBlocked(false)\n }\n }, [batteryBlocked, otaSnapshot.batteryLevel])\n\n const retryInstall = useCallback(() => {\n if (deviceRevision !== otaDeviceSessionRevision() || page !== \"progress\") return\n onFirmwareRestartingChangeRef.current?.(false, true)\n ota.installSession.retry()\n }, [deviceRevision, page])\n\n const finish = useCallback(async () => {\n if (deviceRevision !== otaDeviceSessionRevision()) return\n if (page === \"check\") {\n stopOtaAutoChain()\n onFinishedRef.current?.()\n return\n }\n const restartStillInProgress =\n installSnapshot.displayState === \"restarting\" ||\n installSnapshot.versionChangePhase === \"restarting\" ||\n installSnapshot.versionChangePhase === \"verifying\"\n if (restartStillInProgress) return\n const requiresGlassesReboot = shouldRequireGlassesRebootForBesFailure(\n installSnapshot.otaStatus,\n installSnapshot.otaProgress,\n installSnapshot.errorMsg,\n )\n if (requiresGlassesReboot) stopOtaAutoChain()\n await ota.installSession.finish()\n if (deviceRevision !== otaDeviceSessionRevision()) return\n returnToCheck()\n }, [deviceRevision, installSnapshot, page, returnToCheck])\n\n const discard = useCallback(async () => {\n if (deviceRevision !== otaDeviceSessionRevision()) return\n if (page !== \"progress\") return\n stopOtaAutoChain()\n await ota.installSession.discard()\n if (deviceRevision !== otaDeviceSessionRevision()) return\n returnToCheck()\n }, [deviceRevision, page, returnToCheck])\n\n const openWifiSetup = useCallback(() => {\n if (page === \"progress\") stopOtaAutoChain()\n onOpenWifiSetupRef.current?.()\n }, [page])\n\n const state = useMemo<MentraLiveOtaState>(() => {\n const hotspotSupported = otaSnapshot.hotspotOtaVersion === 1\n const canInstall = hotspotSupported || (otaSnapshot.wifiStatusKnown && otaSnapshot.wifiConnected)\n const autoChainActive = isOtaAutoChainActive()\n if (!runtimeReady) {\n return {\n screen: \"initializing\",\n connected: otaSnapshot.connected,\n batteryLevel: otaSnapshot.batteryLevel,\n transport: null,\n updateRequired: isUpdateRequired,\n versionChange: isVersionChange,\n versionChangeConverged: false,\n versionChangePhase: null,\n wifiConnected: otaSnapshot.wifiConnected,\n wifiStatusKnown: otaSnapshot.wifiStatusKnown,\n hotspotSupported,\n hotspotPhase: \"idle\",\n hotspotArtifactPercent: null,\n hotspotArtifact: null,\n phase: null,\n step: null,\n currentStep: null,\n totalSteps: null,\n progress: null,\n installingApkOnly: false,\n firmwareRestarting: false,\n error: null,\n canInstall: false,\n canRetry: false,\n canFinish: false,\n canDismiss: false,\n canDiscard: false,\n canOpenWifiSetup: false,\n continueDisabled: false,\n completedUpdate: false,\n releaseTransition: null,\n changelogs: [],\n glassesPackageName: null,\n }\n }\n\n if (page === \"check\") {\n const wifiRequired = otaSnapshot.wifiStatusKnown && !otaSnapshot.wifiConnected && !hotspotSupported\n let screen: MentraLiveOtaScreen\n if (checkState === \"checking\") screen = autoChainActive ? \"finishing\" : \"checking\"\n else if (checkState === \"update_available\") {\n screen = wifiRequired ? \"wifi_required\" : batteryBlocked ? \"battery_required\" : \"update_available\"\n } else if (checkState === \"no_update\") screen = \"up_to_date\"\n else if (checkState === \"dev_build\") screen = \"dev_build\"\n else if (checkState === \"unofficial_client\") screen = \"unofficial_client\"\n else screen = errorKind === \"pin_unavailable\" ? \"update_info_unavailable\" : \"check_failed\"\n\n let error: MentraLiveOtaError | null = null\n if (screen === \"check_failed\") {\n error = {\n code: \"check_failed\",\n message:\n errorKind === \"version_info\"\n ? \"Couldn't read the glasses software versions. Keep the glasses connected and try again.\"\n : \"Couldn't check for updates. Please check your connection and try again.\",\n copyKey: errorKind === \"version_info\" ? \"ota:versionInfoFailedMessage\" : \"ota:checkFailedMessage\",\n glassesCode: null,\n }\n } else if (screen === \"update_info_unavailable\") {\n error = {\n code: \"update_info_unavailable\",\n message: \"Update information for this app version is unavailable.\",\n copyKey: \"ota:updateInfoUnavailableMessage\",\n glassesCode: null,\n }\n }\n return {\n screen,\n connected: otaSnapshot.connected,\n batteryLevel: otaSnapshot.batteryLevel,\n transport: hotspotSupported ? \"hotspot\" : otaSnapshot.wifiConnected ? \"wifi\" : null,\n updateRequired: isUpdateRequired,\n versionChange: isVersionChange,\n versionChangeConverged: false,\n versionChangePhase: null,\n wifiConnected: otaSnapshot.wifiConnected,\n wifiStatusKnown: otaSnapshot.wifiStatusKnown,\n hotspotSupported,\n hotspotPhase: \"idle\",\n hotspotArtifactPercent: null,\n hotspotArtifact: null,\n phase: null,\n step: null,\n currentStep: null,\n totalSteps: null,\n progress: null,\n installingApkOnly: false,\n firmwareRestarting: false,\n error,\n canInstall: screen === \"update_available\" && canInstall,\n canRetry: screen === \"check_failed\",\n canFinish:\n screen === \"up_to_date\" ||\n screen === \"dev_build\" ||\n screen === \"unofficial_client\" ||\n screen === \"update_info_unavailable\",\n canDismiss:\n (screen === \"update_available\" || screen === \"wifi_required\" || screen === \"battery_required\") &&\n !isUpdateRequired &&\n !autoChainActive,\n canDiscard: false,\n canOpenWifiSetup: screen === \"wifi_required\",\n continueDisabled: false,\n completedUpdate: screen === \"up_to_date\" && completedUpdate,\n releaseTransition:\n screen === \"update_available\" || screen === \"wifi_required\"\n ? autoChainActive\n ? releaseTransitionFromRange(otaAutoChainReleaseRange())\n : offeredReleaseTransition\n : screen === \"up_to_date\"\n ? completedReleaseTransition\n : null,\n changelogs: screen === \"up_to_date\" ? completedChangelogs : [],\n glassesPackageName: screen === \"unofficial_client\" ? unofficialClientPackage : null,\n }\n }\n\n const requiresGlassesReboot = shouldRequireGlassesRebootForBesFailure(\n installSnapshot.otaStatus,\n installSnapshot.otaProgress,\n installSnapshot.errorMsg,\n )\n const showChangeWifi = shouldShowChangeWifiForOtaDownloadFailure(\n installSnapshot.otaStatus,\n installSnapshot.otaProgress,\n installSnapshot.errorMsg,\n )\n // The raw code the glasses attached to their failure report, kept for support even when\n // phone-side copy outranks it. Only a failed ota_status carries a current code.\n const glassesCode = installSnapshot.otaStatus?.status === \"failed\" ? installSnapshot.otaStatus.error || null : null\n // Precedence mirrors the legacy screen: the BES restart instruction, then a phone-side\n // watchdog/preflight message (translated when a copy key is available), then the glasses code mapped to\n // copy (unknown codes get the generic glasses-error copy rather than the raw code).\n let displayedError: string\n let copyKey: string | null\n if (requiresGlassesReboot) {\n displayedError = BES_INSTALL_RESTART_MESSAGE\n copyKey = OTA_ERROR_BES_RESTART_REQUIRED_COPY_KEY\n } else if (installSnapshot.errorMsg) {\n displayedError = installSnapshot.errorMsg\n copyKey = installSnapshot.errorCopyKey ?? null\n } else {\n displayedError = getOtaErrorMessage(glassesCode)\n copyKey = otaErrorCopyKey(glassesCode)\n }\n const progressState = progressScreen(installSnapshot)\n const screen = progressState === \"complete\" && autoChainActive ? \"finishing\" : progressState\n const error: MentraLiveOtaError | null =\n screen === \"failed\"\n ? {\n code: requiresGlassesReboot ? \"bes_restart_required\" : \"install_failed\",\n message: displayedError,\n copyKey,\n glassesCode,\n }\n : null\n const totalSteps = installSnapshot.otaStatus?.totalSteps ?? null\n const artifact = installSnapshot.hotspotArtifact\n const changelogs = screen === \"complete\" ? releaseChangelogsForActiveChain() : []\n return {\n screen,\n connected: installSnapshot.connected,\n batteryLevel: otaSnapshot.batteryLevel,\n transport: installSnapshot.transport,\n updateRequired: isUpdateRequired,\n versionChange: installSnapshot.isVersionChange,\n versionChangeConverged: installSnapshot.versionChangeConverged,\n versionChangePhase: installSnapshot.versionChangePhase,\n wifiConnected: otaSnapshot.wifiConnected,\n wifiStatusKnown: otaSnapshot.wifiStatusKnown,\n hotspotSupported,\n hotspotPhase: installSnapshot.hotspotPhase,\n hotspotArtifactPercent: installSnapshot.hotspotArtifactPercent,\n hotspotArtifact: artifact ? {kind: artifact.kind, index: artifact.index, totalCount: artifact.totalCount} : null,\n phase: installSnapshot.otaStatus?.phase ?? installSnapshot.otaProgress?.stage ?? null,\n step: installSnapshot.otaStatus?.stepType ?? null,\n currentStep: installSnapshot.otaStatus?.currentStep ?? null,\n totalSteps,\n progress: installProgress(installSnapshot),\n installingApkOnly:\n installSnapshot.otaStatus?.stepType === \"apk\" &&\n installSnapshot.otaStatus.phase === \"install\" &&\n totalSteps === 1,\n firmwareRestarting,\n error,\n canInstall: false,\n canRetry: screen === \"failed\" && !requiresGlassesReboot,\n canFinish: screen === \"complete\" || (screen === \"failed\" && requiresGlassesReboot),\n canDismiss: false,\n canDiscard: screen === \"disconnected\",\n canOpenWifiSetup: screen === \"failed\" && !hotspotSupported && showChangeWifi,\n continueDisabled: installSnapshot.continueButtonDisabled,\n completedUpdate: false,\n releaseTransition: releaseTransitionFromRange(otaAutoChainReleaseRange()),\n changelogs,\n glassesPackageName: null,\n }\n }, [\n unofficialClientPackage,\n checkState,\n batteryBlocked,\n completedChangelogs,\n completedReleaseTransition,\n completedUpdate,\n errorKind,\n firmwareRestarting,\n installSnapshot,\n isUpdateRequired,\n isVersionChange,\n otaSnapshot,\n offeredReleaseTransition,\n page,\n runtimeReady,\n deviceRevision,\n ])\n\n return useMemo(\n () => ({state, check, retryCheck: check, install, retryInstall, finish, discard, openWifiSetup}),\n [check, discard, finish, install, openWifiSetup, retryInstall, state],\n )\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type OtaArtifactFailure } from "./OtaArtifactFailure";
|
|
1
2
|
import type { OtaCheckCurrentGlassesResult } from "./OtaUpdateCheckService";
|
|
2
3
|
/**
|
|
3
4
|
* Phone-side artifact staging for hotspot-served OTA (OS-1676).
|
|
@@ -36,7 +37,8 @@ export interface OtaArtifactDownloadProgress {
|
|
|
36
37
|
}
|
|
37
38
|
export declare class OtaArtifactError extends Error {
|
|
38
39
|
readonly code: "artifact_download_failed" | "artifact_verify_failed" | "manifest_invalid";
|
|
39
|
-
|
|
40
|
+
readonly failure?: OtaArtifactFailure | undefined;
|
|
41
|
+
constructor(code: "artifact_download_failed" | "artifact_verify_failed" | "manifest_invalid", message: string, failure?: OtaArtifactFailure | undefined, cause?: unknown);
|
|
40
42
|
}
|
|
41
43
|
export declare function otaArtifactsDirectory(): string;
|
|
42
44
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtaArtifactDownloader.d.ts","sourceRoot":"","sources":["../../src/services/OtaArtifactDownloader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,4BAA4B,EAAc,MAAM,yBAAyB,CAAA;AAEtF;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;AAEnD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,eAAe,CAAA;IACrB,oFAAoF;IACpF,GAAG,EAAE,MAAM,CAAA;IACX,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAC/D,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,eAAe,CAAA;IACrB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,iFAAiF;IACjF,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,IAAI,EAAE,0BAA0B,GAAG,wBAAwB,GAAG,kBAAkB;
|
|
1
|
+
{"version":3,"file":"OtaArtifactDownloader.d.ts","sourceRoot":"","sources":["../../src/services/OtaArtifactDownloader.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,kBAAkB,EAAC,MAAM,sBAAsB,CAAA;AAChF,OAAO,KAAK,EAAC,4BAA4B,EAAc,MAAM,yBAAyB,CAAA;AAEtF;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;AAEnD,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,GACjC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CA+GhC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,mBAAmB,EAAE,EAChC,OAAO,EAAE,MAAM,GACd,MAAM,CA6BR;AAED,gGAAgG;AAChG,wBAAsB,gBAAgB,CAAC,WAAW,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAYhF"}
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import * as RNFS from "@dr.pogodin/react-native-fs";
|
|
2
|
+
import { otaArtifactFailure } from "./OtaArtifactFailure";
|
|
2
3
|
export class OtaArtifactError extends Error {
|
|
3
4
|
code;
|
|
4
|
-
|
|
5
|
+
failure;
|
|
6
|
+
constructor(code, message, failure, cause) {
|
|
5
7
|
super(message);
|
|
6
8
|
this.code = code;
|
|
9
|
+
this.failure = failure;
|
|
7
10
|
this.name = "OtaArtifactError";
|
|
11
|
+
// Native Errors may contain URLs and paths. Keep the original available locally,
|
|
12
|
+
// but only the bounded, redacted failure snapshot can enter JSON/incident evidence.
|
|
13
|
+
if (cause !== undefined)
|
|
14
|
+
Object.defineProperty(this, "cause", { value: cause });
|
|
8
15
|
}
|
|
9
16
|
}
|
|
17
|
+
function artifactPreparationError(error, context) {
|
|
18
|
+
return new OtaArtifactError(error instanceof OtaArtifactError
|
|
19
|
+
? error.code
|
|
20
|
+
: context.stage === "verify"
|
|
21
|
+
? "artifact_verify_failed"
|
|
22
|
+
: "artifact_download_failed", error instanceof OtaArtifactError ? error.message : "Preparing the update artifact failed", otaArtifactFailure(error, context), error);
|
|
23
|
+
}
|
|
10
24
|
const ASG_PACKAGE = "com.mentra.asg_client";
|
|
11
25
|
export function otaArtifactsDirectory() {
|
|
12
26
|
return `${RNFS.DocumentDirectoryPath}/ota_artifacts`;
|
|
@@ -74,7 +88,17 @@ export function planArtifacts(result) {
|
|
|
74
88
|
*/
|
|
75
89
|
export async function prepareArtifacts(plan, onProgress, nativeDownload) {
|
|
76
90
|
const directory = otaArtifactsDirectory();
|
|
77
|
-
|
|
91
|
+
try {
|
|
92
|
+
await RNFS.mkdir(directory, { NSURLIsExcludedFromBackupKey: true });
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw artifactPreparationError(error, {
|
|
96
|
+
artifact: null,
|
|
97
|
+
stage: "save",
|
|
98
|
+
bytesWritten: 0,
|
|
99
|
+
contentLength: 0,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
78
102
|
const prepared = [];
|
|
79
103
|
for (let index = 0; index < plan.length; index++) {
|
|
80
104
|
const entry = plan[index];
|
|
@@ -89,18 +113,34 @@ export async function prepareArtifacts(plan, onProgress, nativeDownload) {
|
|
|
89
113
|
contentLength: 0,
|
|
90
114
|
});
|
|
91
115
|
const cachedPath = `${directory}/${entry.sha256}`;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
try {
|
|
117
|
+
if (await RNFS.exists(cachedPath)) {
|
|
118
|
+
const cachedHash = (await RNFS.hash(cachedPath, "sha256")).toLowerCase();
|
|
119
|
+
if (cachedHash === entry.sha256) {
|
|
120
|
+
prepared.push({ ...entry, filePath: cachedPath });
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
await safeUnlink(cachedPath);
|
|
97
124
|
}
|
|
98
|
-
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
throw artifactPreparationError(error, {
|
|
128
|
+
artifact: entry.kind,
|
|
129
|
+
stage: "verify",
|
|
130
|
+
bytesWritten: 0,
|
|
131
|
+
contentLength: 0,
|
|
132
|
+
});
|
|
99
133
|
}
|
|
100
134
|
const partPath = `${directory}/download-${index}.part`;
|
|
101
135
|
await safeUnlink(partPath);
|
|
136
|
+
let stage = "download";
|
|
137
|
+
let bytesWritten = 0;
|
|
138
|
+
let contentLength = 0;
|
|
139
|
+
let httpStatus;
|
|
102
140
|
try {
|
|
103
|
-
const reportProgress = (
|
|
141
|
+
const reportProgress = (written, length) => {
|
|
142
|
+
bytesWritten = written;
|
|
143
|
+
contentLength = length;
|
|
104
144
|
onProgress?.({
|
|
105
145
|
kind: entry.kind,
|
|
106
146
|
index,
|
|
@@ -118,19 +158,26 @@ export async function prepareArtifacts(plan, onProgress, nativeDownload) {
|
|
|
118
158
|
connectionTimeout: 30_000,
|
|
119
159
|
readTimeout: 30_000,
|
|
120
160
|
progressDivider: 5,
|
|
161
|
+
begin: (res) => {
|
|
162
|
+
httpStatus = res.statusCode;
|
|
163
|
+
contentLength = res.contentLength;
|
|
164
|
+
},
|
|
121
165
|
progress: (res) => {
|
|
122
166
|
reportProgress(res.bytesWritten, res.contentLength);
|
|
123
167
|
},
|
|
124
168
|
}).promise;
|
|
169
|
+
httpStatus = downloadResult.statusCode;
|
|
125
170
|
// A resumed native download can finish with 206. Accept it only through
|
|
126
171
|
// the same full-file manifest SHA256 verification below.
|
|
127
172
|
if (downloadResult.statusCode !== 200 && downloadResult.statusCode !== 206) {
|
|
128
173
|
throw new OtaArtifactError("artifact_download_failed", `Download of ${entry.kind} artifact failed with HTTP ${downloadResult.statusCode}`);
|
|
129
174
|
}
|
|
175
|
+
stage = "verify";
|
|
130
176
|
const actualSha256 = (await RNFS.hash(partPath, "sha256")).toLowerCase();
|
|
131
177
|
if (actualSha256 !== entry.sha256) {
|
|
132
178
|
throw new OtaArtifactError("artifact_verify_failed", `${entry.kind} artifact hash mismatch: expected ${entry.sha256}, got ${actualSha256}`);
|
|
133
179
|
}
|
|
180
|
+
stage = "save";
|
|
134
181
|
const finalPath = `${directory}/${entry.sha256}`;
|
|
135
182
|
await safeUnlink(finalPath);
|
|
136
183
|
await RNFS.moveFile(partPath, finalPath);
|
|
@@ -138,10 +185,7 @@ export async function prepareArtifacts(plan, onProgress, nativeDownload) {
|
|
|
138
185
|
}
|
|
139
186
|
catch (error) {
|
|
140
187
|
await safeUnlink(partPath);
|
|
141
|
-
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
|
-
throw new OtaArtifactError("artifact_download_failed", `Download of ${entry.kind} artifact failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
188
|
+
throw artifactPreparationError(error, { artifact: entry.kind, stage, httpStatus, bytesWritten, contentLength });
|
|
145
189
|
}
|
|
146
190
|
}
|
|
147
191
|
return prepared;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OtaArtifactDownloader.js","sourceRoot":"","sources":["../../src/services/OtaArtifactDownloader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,6BAA6B,CAAA;AA2CnD,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEvB;IADlB,YACkB,IAAgF,EAChG,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHE,SAAI,GAAJ,IAAI,CAA4E;QAIhG,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;CACF;AAED,MAAM,WAAW,GAAG,uBAAuB,CAAA;AAE3C,MAAM,UAAU,qBAAqB;IACnC,OAAO,GAAG,IAAI,CAAC,qBAAqB,gBAAgB,CAAA;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAoC;IAChE,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QACzB,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,uCAAuC,CAAC,CAAA;IACzF,CAAC;IACD,IAAI,QAAqB,CAAA;IACzB,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,iCAAiC,CAAC,CAAA;IACnF,CAAC;IAED,MAAM,OAAO,GAA2B,EAAE,CAAA;IAE1C,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,KAA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CAAC,MAAM,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,KAAK,wCAAwC,CAAC,CAAA;IAClG,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,6EAA6E;IAC/E,CAAC;AACH,CAAC","sourcesContent":["import * as RNFS from \"@dr.pogodin/react-native-fs\"\nimport type {OtaCheckCurrentGlassesResult, VersionJson} from \"./OtaUpdateCheckService\"\n\n/**\n * Phone-side artifact staging for hotspot-served OTA (OS-1676).\n *\n * When the glasses have no WiFi, the phone downloads the OTA artifacts itself (over\n * whatever network it is on — the user's tap on \"update\" is the consent) and serves them\n * to the glasses via the LocalOtaServer over the glasses' hotspot. This module owns:\n *\n * - planning which artifacts the pending update actually needs (from the raw manifest the\n * update check fetched, so the glasses re-parse byte-identical version data),\n * - downloading them with .part staging and sha256 verification, keyed on disk by hash so\n * retries and the post-APK continuation reuse verified files,\n * - rewriting the manifest's URL fields to point at the phone server, and\n * - cleanup once the update completes or the manifest moves on.\n */\n\nexport type OtaArtifactKind = \"apk\" | \"mtk\" | \"bes\"\n\nexport interface OtaArtifactPlanEntry {\n kind: OtaArtifactKind\n /** URL this artifact is fetched from, exactly as it appears in the raw manifest. */\n url: string\n /** Required content hash from the manifest. */\n sha256: string\n}\n\nexport interface PreparedOtaArtifact extends OtaArtifactPlanEntry {\n filePath: string\n}\n\nexport interface OtaArtifactDownloadProgress {\n kind: OtaArtifactKind\n /** 0-based index of the artifact being downloaded. */\n index: number\n totalCount: number\n /** Percent of the current artifact, 0-100 (0 when the server sent no length). */\n artifactPercent: number\n bytesWritten: number\n contentLength: number\n}\n\nexport class OtaArtifactError extends Error {\n constructor(\n public readonly code: \"artifact_download_failed\" | \"artifact_verify_failed\" | \"manifest_invalid\",\n message: string,\n ) {\n super(message)\n this.name = \"OtaArtifactError\"\n }\n}\n\nconst ASG_PACKAGE = \"com.mentra.asg_client\"\n\nexport function otaArtifactsDirectory(): string {\n return `${RNFS.DocumentDirectoryPath}/ota_artifacts`\n}\n\n/**\n * Derive the artifact list the pending update needs from a completed check.\n * Works off the raw manifest body (not the normalized check fields) so the URLs and\n * hashes match exactly what the glasses will re-parse.\n */\nexport function planArtifacts(result: OtaCheckCurrentGlassesResult): OtaArtifactPlanEntry[] {\n if (!result.manifestBody) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Check result carries no manifest body\")\n }\n let manifest: VersionJson\n try {\n manifest = JSON.parse(result.manifestBody)\n } catch {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest body is not valid JSON\")\n }\n\n const entries: OtaArtifactPlanEntry[] = []\n\n if (result.updates.includes(\"apk\")) {\n const app = manifest.apps?.[ASG_PACKAGE] as unknown as Record<string, unknown> | undefined\n const url = typeof app?.apkUrl === \"string\" ? app.apkUrl : null\n if (!url) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest has no apkUrl for the pending APK update\")\n }\n entries.push({\n kind: \"apk\",\n url,\n sha256: requireSha256(app, \"APK\"),\n })\n }\n\n if (result.updates.includes(\"mtk\") && result.mtkPatch) {\n const candidates = [...(manifest.mtk_patches ?? []), ...(manifest.mtk_full_ota ? [manifest.mtk_full_ota] : [])]\n const raw = candidates.find((entry) => firmwareUrl(entry) === firmwareUrl(result.mtkPatch!)) as unknown as\n | Record<string, unknown>\n | undefined\n const url = firmwareUrl(raw) ?? firmwareUrl(result.mtkPatch)\n if (!url) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest has no URL for the pending MTK patch\")\n }\n entries.push({\n kind: \"mtk\",\n url,\n sha256: requireSha256(raw, \"MTK\"),\n })\n }\n\n if (result.updates.includes(\"bes\") && manifest.bes_firmware) {\n const raw = manifest.bes_firmware as unknown as Record<string, unknown>\n const url = firmwareUrl(raw)\n if (!url) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest has no URL for the pending BES firmware\")\n }\n entries.push({\n kind: \"bes\",\n url,\n sha256: requireSha256(raw, \"BES\"),\n })\n }\n\n return entries\n}\n\n/**\n * Download every planned artifact into the on-disk hash-keyed store, reusing files that\n * already verify. Sequential on purpose: progress is legible and the hotspot window that\n * follows is the slow part, not phone-side parallelism.\n */\nexport async function prepareArtifacts(\n plan: OtaArtifactPlanEntry[],\n onProgress?: (progress: OtaArtifactDownloadProgress) => void,\n nativeDownload?: (\n entry: OtaArtifactPlanEntry,\n destination: string,\n onProgress?: (bytesWritten: number, contentLength: number) => void,\n ) => Promise<{statusCode: number}>,\n): Promise<PreparedOtaArtifact[]> {\n const directory = otaArtifactsDirectory()\n await RNFS.mkdir(directory, {NSURLIsExcludedFromBackupKey: true})\n\n const prepared: PreparedOtaArtifact[] = []\n for (let index = 0; index < plan.length; index++) {\n const entry = plan[index]\n // Announce each file before cache verification or native download callbacks,\n // so the previous file's 100% cannot linger under the next file's label.\n onProgress?.({\n kind: entry.kind,\n index,\n totalCount: plan.length,\n artifactPercent: 0,\n bytesWritten: 0,\n contentLength: 0,\n })\n\n const cachedPath = `${directory}/${entry.sha256}`\n if (await RNFS.exists(cachedPath)) {\n const cachedHash = (await RNFS.hash(cachedPath, \"sha256\")).toLowerCase()\n if (cachedHash === entry.sha256) {\n prepared.push({...entry, filePath: cachedPath})\n continue\n }\n await safeUnlink(cachedPath)\n }\n\n const partPath = `${directory}/download-${index}.part`\n await safeUnlink(partPath)\n try {\n const reportProgress = (bytesWritten: number, contentLength: number) => {\n onProgress?.({\n kind: entry.kind,\n index,\n totalCount: plan.length,\n artifactPercent: contentLength > 0 ? Math.round((bytesWritten / contentLength) * 100) : 0,\n bytesWritten,\n contentLength,\n })\n }\n const downloadResult = nativeDownload\n ? await nativeDownload(entry, partPath, reportProgress)\n : await RNFS.downloadFile({\n fromUrl: entry.url,\n toFile: partPath,\n connectionTimeout: 30_000,\n readTimeout: 30_000,\n progressDivider: 5,\n progress: (res: RNFS.DownloadProgressCallbackResultT) => {\n reportProgress(res.bytesWritten, res.contentLength)\n },\n }).promise\n // A resumed native download can finish with 206. Accept it only through\n // the same full-file manifest SHA256 verification below.\n if (downloadResult.statusCode !== 200 && downloadResult.statusCode !== 206) {\n throw new OtaArtifactError(\n \"artifact_download_failed\",\n `Download of ${entry.kind} artifact failed with HTTP ${downloadResult.statusCode}`,\n )\n }\n\n const actualSha256 = (await RNFS.hash(partPath, \"sha256\")).toLowerCase()\n if (actualSha256 !== entry.sha256) {\n throw new OtaArtifactError(\n \"artifact_verify_failed\",\n `${entry.kind} artifact hash mismatch: expected ${entry.sha256}, got ${actualSha256}`,\n )\n }\n\n const finalPath = `${directory}/${entry.sha256}`\n await safeUnlink(finalPath)\n await RNFS.moveFile(partPath, finalPath)\n prepared.push({...entry, filePath: finalPath})\n } catch (error) {\n await safeUnlink(partPath)\n if (error instanceof OtaArtifactError) {\n throw error\n }\n throw new OtaArtifactError(\n \"artifact_download_failed\",\n `Download of ${entry.kind} artifact failed: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n }\n return prepared\n}\n\n/**\n * Point the manifest's artifact URLs at the phone server, leaving every other field\n * semantically identical to what the update check saw. Entries we host get\n * `<baseUrl>/artifacts/<sha256>`; entries the update does not need keep their CDN URLs.\n * Only URL fields change: target versions, sizes, and manifest hashes remain untouched.\n */\nexport function rewriteManifestForLocalServer(\n manifestBody: string,\n artifacts: PreparedOtaArtifact[],\n baseUrl: string,\n): string {\n let manifest: VersionJson\n try {\n manifest = JSON.parse(manifestBody)\n } catch {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest body is not valid JSON\")\n }\n const byUrl = new Map(artifacts.map((artifact) => [artifact.url, artifact]))\n const localUrl = (artifact: PreparedOtaArtifact) => `${baseUrl}/artifacts/${artifact.sha256}`\n\n for (const app of Object.values(manifest.apps ?? {})) {\n const record = app as unknown as Record<string, unknown>\n const artifact = typeof record.apkUrl === \"string\" ? byUrl.get(record.apkUrl) : undefined\n if (artifact) {\n record.apkUrl = localUrl(artifact)\n }\n }\n\n for (const patch of manifest.mtk_patches ?? []) {\n rewriteFirmwareEntry(patch as unknown as Record<string, unknown>, byUrl, localUrl)\n }\n if (manifest.mtk_full_ota) {\n rewriteFirmwareEntry(manifest.mtk_full_ota as unknown as Record<string, unknown>, byUrl, localUrl)\n }\n if (manifest.bes_firmware) {\n rewriteFirmwareEntry(manifest.bes_firmware as unknown as Record<string, unknown>, byUrl, localUrl)\n }\n\n return JSON.stringify(manifest)\n}\n\n/** Delete every stored artifact whose hash is not in `keepSha256s` (plus stray .part files). */\nexport async function cleanupArtifacts(keepSha256s: string[] = []): Promise<void> {\n const directory = otaArtifactsDirectory()\n if (!(await RNFS.exists(directory))) {\n return\n }\n const keep = new Set(keepSha256s.map((sha) => sha.toLowerCase()))\n const items = await RNFS.readDir(directory)\n for (const item of items) {\n if (!item.isFile()) continue\n if (keep.has(item.name.toLowerCase())) continue\n await safeUnlink(item.path)\n }\n}\n\nfunction rewriteFirmwareEntry(\n entry: Record<string, unknown>,\n byUrl: Map<string, PreparedOtaArtifact>,\n localUrl: (artifact: PreparedOtaArtifact) => string,\n): void {\n const url = firmwareUrl(entry)\n const artifact = url ? byUrl.get(url) : undefined\n if (!artifact) {\n return\n }\n entry.url = localUrl(artifact)\n // Overwrite the legacy key too when present, so no glasses build can prefer a stale\n // CDN URL over the local one.\n if (typeof entry.firmwareUrl === \"string\") {\n entry.firmwareUrl = localUrl(artifact)\n }\n}\n\nfunction firmwareUrl(entry: unknown): string | null {\n if (!entry || typeof entry !== \"object\") {\n return null\n }\n const record = entry as Record<string, unknown>\n if (typeof record.url === \"string\" && record.url.length > 0) {\n return record.url\n }\n if (typeof record.firmwareUrl === \"string\" && record.firmwareUrl.length > 0) {\n return record.firmwareUrl\n }\n return null\n}\n\nfunction requireSha256(entry: Record<string, unknown> | undefined, label: string): string {\n const sha256 = typeof entry?.sha256 === \"string\" ? entry.sha256.trim().toLowerCase() : \"\"\n if (!/^[a-f0-9]{64}$/.test(sha256)) {\n throw new OtaArtifactError(\"manifest_invalid\", `${label} artifact has no valid manifest sha256`)\n }\n return sha256\n}\n\nasync function safeUnlink(path: string): Promise<void> {\n try {\n if (await RNFS.exists(path)) {\n await RNFS.unlink(path)\n }\n } catch {\n // Best-effort: a leftover file only wastes space and is cleaned up next run.\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OtaArtifactDownloader.js","sourceRoot":"","sources":["../../src/services/OtaArtifactDownloader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,6BAA6B,CAAA;AACnD,OAAO,EAAC,kBAAkB,EAA0B,MAAM,sBAAsB,CAAA;AA2ChF,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEvB;IAEA;IAHlB,YACkB,IAAgF,EAChG,OAAe,EACC,OAA4B,EAC5C,KAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QALE,SAAI,GAAJ,IAAI,CAA4E;QAEhF,YAAO,GAAP,OAAO,CAAqB;QAI5C,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;QAC9B,iFAAiF;QACjF,oFAAoF;QACpF,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC,CAAA;IAC/E,CAAC;CACF;AAED,SAAS,wBAAwB,CAC/B,KAAc,EACd,OAA8D;IAE9D,OAAO,IAAI,gBAAgB,CACzB,KAAK,YAAY,gBAAgB;QAC/B,CAAC,CAAC,KAAK,CAAC,IAAI;QACZ,CAAC,CAAC,OAAO,CAAC,KAAK,KAAK,QAAQ;YAC5B,CAAC,CAAC,wBAAwB;YAC1B,CAAC,CAAC,0BAA0B,EAC9B,KAAK,Y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AAM,CAAC,WAAW,CAAA;IAC3B,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,aAAa,CAAC,KAA0C,EAAE,KAAa;IAC9E,MAAM,MAAM,GAAG,OAAO,KAAK,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACzF,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,KAAK,wCAAwC,CAAC,CAAA;IAClG,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,6EAA6E;IAC/E,CAAC;AACH,CAAC","sourcesContent":["import * as RNFS from \"@dr.pogodin/react-native-fs\"\nimport {otaArtifactFailure, type OtaArtifactFailure} from \"./OtaArtifactFailure\"\nimport type {OtaCheckCurrentGlassesResult, VersionJson} from \"./OtaUpdateCheckService\"\n\n/**\n * Phone-side artifact staging for hotspot-served OTA (OS-1676).\n *\n * When the glasses have no WiFi, the phone downloads the OTA artifacts itself (over\n * whatever network it is on — the user's tap on \"update\" is the consent) and serves them\n * to the glasses via the LocalOtaServer over the glasses' hotspot. This module owns:\n *\n * - planning which artifacts the pending update actually needs (from the raw manifest the\n * update check fetched, so the glasses re-parse byte-identical version data),\n * - downloading them with .part staging and sha256 verification, keyed on disk by hash so\n * retries and the post-APK continuation reuse verified files,\n * - rewriting the manifest's URL fields to point at the phone server, and\n * - cleanup once the update completes or the manifest moves on.\n */\n\nexport type OtaArtifactKind = \"apk\" | \"mtk\" | \"bes\"\n\nexport interface OtaArtifactPlanEntry {\n kind: OtaArtifactKind\n /** URL this artifact is fetched from, exactly as it appears in the raw manifest. */\n url: string\n /** Required content hash from the manifest. */\n sha256: string\n}\n\nexport interface PreparedOtaArtifact extends OtaArtifactPlanEntry {\n filePath: string\n}\n\nexport interface OtaArtifactDownloadProgress {\n kind: OtaArtifactKind\n /** 0-based index of the artifact being downloaded. */\n index: number\n totalCount: number\n /** Percent of the current artifact, 0-100 (0 when the server sent no length). */\n artifactPercent: number\n bytesWritten: number\n contentLength: number\n}\n\nexport class OtaArtifactError extends Error {\n constructor(\n public readonly code: \"artifact_download_failed\" | \"artifact_verify_failed\" | \"manifest_invalid\",\n message: string,\n public readonly failure?: OtaArtifactFailure,\n cause?: unknown,\n ) {\n super(message)\n this.name = \"OtaArtifactError\"\n // Native Errors may contain URLs and paths. Keep the original available locally,\n // but only the bounded, redacted failure snapshot can enter JSON/incident evidence.\n if (cause !== undefined) Object.defineProperty(this, \"cause\", {value: cause})\n }\n}\n\nfunction artifactPreparationError(\n error: unknown,\n context: Omit<OtaArtifactFailure, \"category\" | \"nativeErrors\">,\n): OtaArtifactError {\n return new OtaArtifactError(\n error instanceof OtaArtifactError\n ? error.code\n : context.stage === \"verify\"\n ? \"artifact_verify_failed\"\n : \"artifact_download_failed\",\n error instanceof OtaArtifactError ? error.message : \"Preparing the update artifact failed\",\n otaArtifactFailure(error, context),\n error,\n )\n}\n\nconst ASG_PACKAGE = \"com.mentra.asg_client\"\n\nexport function otaArtifactsDirectory(): string {\n return `${RNFS.DocumentDirectoryPath}/ota_artifacts`\n}\n\n/**\n * Derive the artifact list the pending update needs from a completed check.\n * Works off the raw manifest body (not the normalized check fields) so the URLs and\n * hashes match exactly what the glasses will re-parse.\n */\nexport function planArtifacts(result: OtaCheckCurrentGlassesResult): OtaArtifactPlanEntry[] {\n if (!result.manifestBody) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Check result carries no manifest body\")\n }\n let manifest: VersionJson\n try {\n manifest = JSON.parse(result.manifestBody)\n } catch {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest body is not valid JSON\")\n }\n\n const entries: OtaArtifactPlanEntry[] = []\n\n if (result.updates.includes(\"apk\")) {\n const app = manifest.apps?.[ASG_PACKAGE] as unknown as Record<string, unknown> | undefined\n const url = typeof app?.apkUrl === \"string\" ? app.apkUrl : null\n if (!url) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest has no apkUrl for the pending APK update\")\n }\n entries.push({\n kind: \"apk\",\n url,\n sha256: requireSha256(app, \"APK\"),\n })\n }\n\n if (result.updates.includes(\"mtk\") && result.mtkPatch) {\n const candidates = [...(manifest.mtk_patches ?? []), ...(manifest.mtk_full_ota ? [manifest.mtk_full_ota] : [])]\n const raw = candidates.find((entry) => firmwareUrl(entry) === firmwareUrl(result.mtkPatch!)) as unknown as\n | Record<string, unknown>\n | undefined\n const url = firmwareUrl(raw) ?? firmwareUrl(result.mtkPatch)\n if (!url) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest has no URL for the pending MTK patch\")\n }\n entries.push({\n kind: \"mtk\",\n url,\n sha256: requireSha256(raw, \"MTK\"),\n })\n }\n\n if (result.updates.includes(\"bes\") && manifest.bes_firmware) {\n const raw = manifest.bes_firmware as unknown as Record<string, unknown>\n const url = firmwareUrl(raw)\n if (!url) {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest has no URL for the pending BES firmware\")\n }\n entries.push({\n kind: \"bes\",\n url,\n sha256: requireSha256(raw, \"BES\"),\n })\n }\n\n return entries\n}\n\n/**\n * Download every planned artifact into the on-disk hash-keyed store, reusing files that\n * already verify. Sequential on purpose: progress is legible and the hotspot window that\n * follows is the slow part, not phone-side parallelism.\n */\nexport async function prepareArtifacts(\n plan: OtaArtifactPlanEntry[],\n onProgress?: (progress: OtaArtifactDownloadProgress) => void,\n nativeDownload?: (\n entry: OtaArtifactPlanEntry,\n destination: string,\n onProgress?: (bytesWritten: number, contentLength: number) => void,\n ) => Promise<{statusCode: number}>,\n): Promise<PreparedOtaArtifact[]> {\n const directory = otaArtifactsDirectory()\n try {\n await RNFS.mkdir(directory, {NSURLIsExcludedFromBackupKey: true})\n } catch (error) {\n throw artifactPreparationError(error, {\n artifact: null,\n stage: \"save\",\n bytesWritten: 0,\n contentLength: 0,\n })\n }\n\n const prepared: PreparedOtaArtifact[] = []\n for (let index = 0; index < plan.length; index++) {\n const entry = plan[index]\n // Announce each file before cache verification or native download callbacks,\n // so the previous file's 100% cannot linger under the next file's label.\n onProgress?.({\n kind: entry.kind,\n index,\n totalCount: plan.length,\n artifactPercent: 0,\n bytesWritten: 0,\n contentLength: 0,\n })\n\n const cachedPath = `${directory}/${entry.sha256}`\n try {\n if (await RNFS.exists(cachedPath)) {\n const cachedHash = (await RNFS.hash(cachedPath, \"sha256\")).toLowerCase()\n if (cachedHash === entry.sha256) {\n prepared.push({...entry, filePath: cachedPath})\n continue\n }\n await safeUnlink(cachedPath)\n }\n } catch (error) {\n throw artifactPreparationError(error, {\n artifact: entry.kind,\n stage: \"verify\",\n bytesWritten: 0,\n contentLength: 0,\n })\n }\n\n const partPath = `${directory}/download-${index}.part`\n await safeUnlink(partPath)\n let stage: OtaArtifactFailure[\"stage\"] = \"download\"\n let bytesWritten = 0\n let contentLength = 0\n let httpStatus: number | undefined\n try {\n const reportProgress = (written: number, length: number) => {\n bytesWritten = written\n contentLength = length\n onProgress?.({\n kind: entry.kind,\n index,\n totalCount: plan.length,\n artifactPercent: contentLength > 0 ? Math.round((bytesWritten / contentLength) * 100) : 0,\n bytesWritten,\n contentLength,\n })\n }\n const downloadResult = nativeDownload\n ? await nativeDownload(entry, partPath, reportProgress)\n : await RNFS.downloadFile({\n fromUrl: entry.url,\n toFile: partPath,\n connectionTimeout: 30_000,\n readTimeout: 30_000,\n progressDivider: 5,\n begin: (res) => {\n httpStatus = res.statusCode\n contentLength = res.contentLength\n },\n progress: (res: RNFS.DownloadProgressCallbackResultT) => {\n reportProgress(res.bytesWritten, res.contentLength)\n },\n }).promise\n httpStatus = downloadResult.statusCode\n // A resumed native download can finish with 206. Accept it only through\n // the same full-file manifest SHA256 verification below.\n if (downloadResult.statusCode !== 200 && downloadResult.statusCode !== 206) {\n throw new OtaArtifactError(\n \"artifact_download_failed\",\n `Download of ${entry.kind} artifact failed with HTTP ${downloadResult.statusCode}`,\n )\n }\n\n stage = \"verify\"\n const actualSha256 = (await RNFS.hash(partPath, \"sha256\")).toLowerCase()\n if (actualSha256 !== entry.sha256) {\n throw new OtaArtifactError(\n \"artifact_verify_failed\",\n `${entry.kind} artifact hash mismatch: expected ${entry.sha256}, got ${actualSha256}`,\n )\n }\n\n stage = \"save\"\n const finalPath = `${directory}/${entry.sha256}`\n await safeUnlink(finalPath)\n await RNFS.moveFile(partPath, finalPath)\n prepared.push({...entry, filePath: finalPath})\n } catch (error) {\n await safeUnlink(partPath)\n throw artifactPreparationError(error, {artifact: entry.kind, stage, httpStatus, bytesWritten, contentLength})\n }\n }\n return prepared\n}\n\n/**\n * Point the manifest's artifact URLs at the phone server, leaving every other field\n * semantically identical to what the update check saw. Entries we host get\n * `<baseUrl>/artifacts/<sha256>`; entries the update does not need keep their CDN URLs.\n * Only URL fields change: target versions, sizes, and manifest hashes remain untouched.\n */\nexport function rewriteManifestForLocalServer(\n manifestBody: string,\n artifacts: PreparedOtaArtifact[],\n baseUrl: string,\n): string {\n let manifest: VersionJson\n try {\n manifest = JSON.parse(manifestBody)\n } catch {\n throw new OtaArtifactError(\"manifest_invalid\", \"Manifest body is not valid JSON\")\n }\n const byUrl = new Map(artifacts.map((artifact) => [artifact.url, artifact]))\n const localUrl = (artifact: PreparedOtaArtifact) => `${baseUrl}/artifacts/${artifact.sha256}`\n\n for (const app of Object.values(manifest.apps ?? {})) {\n const record = app as unknown as Record<string, unknown>\n const artifact = typeof record.apkUrl === \"string\" ? byUrl.get(record.apkUrl) : undefined\n if (artifact) {\n record.apkUrl = localUrl(artifact)\n }\n }\n\n for (const patch of manifest.mtk_patches ?? []) {\n rewriteFirmwareEntry(patch as unknown as Record<string, unknown>, byUrl, localUrl)\n }\n if (manifest.mtk_full_ota) {\n rewriteFirmwareEntry(manifest.mtk_full_ota as unknown as Record<string, unknown>, byUrl, localUrl)\n }\n if (manifest.bes_firmware) {\n rewriteFirmwareEntry(manifest.bes_firmware as unknown as Record<string, unknown>, byUrl, localUrl)\n }\n\n return JSON.stringify(manifest)\n}\n\n/** Delete every stored artifact whose hash is not in `keepSha256s` (plus stray .part files). */\nexport async function cleanupArtifacts(keepSha256s: string[] = []): Promise<void> {\n const directory = otaArtifactsDirectory()\n if (!(await RNFS.exists(directory))) {\n return\n }\n const keep = new Set(keepSha256s.map((sha) => sha.toLowerCase()))\n const items = await RNFS.readDir(directory)\n for (const item of items) {\n if (!item.isFile()) continue\n if (keep.has(item.name.toLowerCase())) continue\n await safeUnlink(item.path)\n }\n}\n\nfunction rewriteFirmwareEntry(\n entry: Record<string, unknown>,\n byUrl: Map<string, PreparedOtaArtifact>,\n localUrl: (artifact: PreparedOtaArtifact) => string,\n): void {\n const url = firmwareUrl(entry)\n const artifact = url ? byUrl.get(url) : undefined\n if (!artifact) {\n return\n }\n entry.url = localUrl(artifact)\n // Overwrite the legacy key too when present, so no glasses build can prefer a stale\n // CDN URL over the local one.\n if (typeof entry.firmwareUrl === \"string\") {\n entry.firmwareUrl = localUrl(artifact)\n }\n}\n\nfunction firmwareUrl(entry: unknown): string | null {\n if (!entry || typeof entry !== \"object\") {\n return null\n }\n const record = entry as Record<string, unknown>\n if (typeof record.url === \"string\" && record.url.length > 0) {\n return record.url\n }\n if (typeof record.firmwareUrl === \"string\" && record.firmwareUrl.length > 0) {\n return record.firmwareUrl\n }\n return null\n}\n\nfunction requireSha256(entry: Record<string, unknown> | undefined, label: string): string {\n const sha256 = typeof entry?.sha256 === \"string\" ? entry.sha256.trim().toLowerCase() : \"\"\n if (!/^[a-f0-9]{64}$/.test(sha256)) {\n throw new OtaArtifactError(\"manifest_invalid\", `${label} artifact has no valid manifest sha256`)\n }\n return sha256\n}\n\nasync function safeUnlink(path: string): Promise<void> {\n try {\n if (await RNFS.exists(path)) {\n await RNFS.unlink(path)\n }\n } catch {\n // Best-effort: a leftover file only wastes space and is cleaned up next run.\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type OtaArtifactFailureCategory = "internet" | "connection" | "server" | "timeout" | "storage" | "save" | "secure_connection" | "download" | "verify";
|
|
2
|
+
export interface OtaArtifactFailure {
|
|
3
|
+
artifact: "apk" | "mtk" | "bes" | null;
|
|
4
|
+
stage: "download" | "verify" | "save";
|
|
5
|
+
category: OtaArtifactFailureCategory;
|
|
6
|
+
httpStatus?: number;
|
|
7
|
+
bytesWritten: number;
|
|
8
|
+
contentLength: number;
|
|
9
|
+
nativeErrors: {
|
|
10
|
+
name?: string;
|
|
11
|
+
code?: string;
|
|
12
|
+
domain?: string;
|
|
13
|
+
message?: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
/** Preserve Error's non-enumerable fields before JSON serialization drops them. */
|
|
17
|
+
export declare function otaArtifactFailure(error: unknown, context: Omit<OtaArtifactFailure, "category" | "nativeErrors">): OtaArtifactFailure;
|
|
18
|
+
//# sourceMappingURL=OtaArtifactFailure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OtaArtifactFailure.d.ts","sourceRoot":"","sources":["../../src/services/OtaArtifactFailure.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAClC,UAAU,GACV,YAAY,GACZ,QAAQ,GACR,SAAS,GACT,SAAS,GACT,MAAM,GACN,mBAAmB,GACnB,UAAU,GACV,QAAQ,CAAA;AAEZ,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,CAAA;IACtC,KAAK,EAAE,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAA;IACrC,QAAQ,EAAE,0BAA0B,CAAA;IACpC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAC,EAAE,CAAA;CAClF;AAgBD,mFAAmF;AACnF,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,UAAU,GAAG,cAAc,CAAC,GAC7D,kBAAkB,CA8DpB"}
|