chore: remove source comments and unused code, translate every missing string (#1965)

* chore(i18n): translate every missing string in all locales

Adds the 87 strings the bottom-screen Dashboard and in-game stats pages
introduced to all 32 locales, plus the 51 older settings strings Japanese
and the 50 Chinese locales were still missing. Every locale now has all
3456 translatable strings with the same placeholders as English.

Also translates 36 entries that were still English where the language
does not use the English word, and makes es-419 touch_app_id use the same
%1$s placeholder as English.

* chore(patches): drop comments from the lines downstream patches add

Removes comment lines and trailing comments from lines our patches add,
with hunk headers recounted. Lines that a later patch uses as context
and the upstream backport 0123 are left as they are.

The gamescope, FEX, proot and xodus series still apply to their pinned
sources, and the patched trees differ only in those comments.
test_hud_frames now finds the HUD writer by its first declaration.

* docs: credit Greenlight, Better xCloud, viture-v2, GameNative and DiRTTelemetryErrorFix

These were credited only in source headers and NOTICE files.

* chore: remove source comments and unused functions

Removes explanatory comments from first-party Kotlin, Java, C, C++,
Rust, TypeScript, Python, shell, Gradle, CMake and workflow files.
License and attribution headers stay, and vendored third-party trees,
generated files and license files are untouched. A shellcheck directive
is kept, and udevmon's fallthrough comments became fallthrough attributes.

Syntax trees and token streams match the previous sources apart from the
comments and Python docstrings. Module docstrings that argparse prints
are kept, and device-smoke.sh prints the same --help text from a heredoc.

Also removes 37 functions and 4 fields that nothing referenced.

* chore: remove comments from the Syncthing integration and the latest main sources

* docs: credit Syncthing and the syncthing-android fork

* chore(i18n): translate the Syncthing strings in all locales

The 107 strings the Syncthing integration added are now in all 32 locales.
sync_web_path_locked names the Syncthing tab by its label.

* docs: credit @xXJSONDeruloXx for the HUD metric readers

The CPU, GPU load, thermal and battery readers come from their
PerformanceHudView pull requests #777, #877, #991, #1406 and #1573.
The FusionHUD credit line is unchanged.

* docs: credit the HUD metric readers to @xXJSONDeruloXx's work
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-01 16:27:27 -05:00
1 parent d730f0fa8b
commit c5577478ca
511 files changed
+6813 -4068

No files matched your search

@@ -563,7 +563,6 @@ object Glasses {
val device = selected?.first
val m = selected?.second
val controllable = m?.let(::canOpenModel) == true
// XREAL uses Android's Ethernet sockets, without opening or claiming USB interfaces.
val permitted = controllable && device != null && (m === XrealModel || usb.hasPermission(device))
val identity = device?.let {
GlassesModeState.Device(it.productId, if (permitted) runCatching { it.serialNumber }.getOrNull() else null)
@@ -677,8 +676,6 @@ object Glasses {
internal fun selectGlassesDisplay(displays: List<Display>, usbPresent: Boolean): Display? {
val candidates = displays
.filter { it.displayId != Display.DEFAULT_DISPLAY && it.flags and Display.FLAG_PRESENTATION != 0 }
// Android can expose the glasses name on either the logical display or
// its product metadata. A generic label on one must not hide the other.
return candidates.firstOrNull { display ->
isGlassesDisplayName(display.name) ||
(Build.VERSION.SDK_INT >= 31 && display.deviceProductInfo?.let { product ->
@@ -728,7 +725,6 @@ object Glasses {
if (device.productId == VitureProtocol.PRO2_PRODUCT_ID) {
VitureV2Link.open(usb, device, v2Listener(generation))
} else if ((model as? VitureProtocol.Model)?.needsSdk == true) {
// Android can evict cacheDir while the SDK is running.
Log.i(TAG, "opening VITURE SDK pid=0x%04X spatial=%s".format(device.productId, spatial))
VitureSdkLink.open(usb, device, File(app.noBackupFilesDir, "viture"), sdkListener(generation),
(model as? VitureProtocol.Model)?.family, spatial)
@@ -854,7 +850,6 @@ object Glasses {
if (generation != linkGeneration) return@post
closeLink()
publish { it.copy(controlError = app.getString(R.string.glasses_connection_failed)) }
// Let a reconnect or explicit Allow retry restart the SDK, not an endless failure loop.
}
}
@@ -974,7 +969,6 @@ object Glasses {
}
if (!s.usable || s.sbs || modeState.pendingStereo) return
val hz = _settings.value.refreshHz
// Native 30 Hz is selected by the Android presentation, without a vendor mode command.
if (hz == 30 && GlassesRendering.native30HzAvailable(_settings.value, s)) return
if (glassesMode == m.mode(hz, false, outputResolution())) return
if (!force) {
@@ -1,6 +1,5 @@
package com.droiddeck.launcher.glasses
/** Hardware properties; display refresh is selected from Android's advertised modes. */
interface GlassesModel {
val name: String
val controllable: Boolean
@@ -18,9 +17,6 @@ interface GlassesModel {
fun modeForStep(step: Int): Int?
}
/** The command IDs here are the existing glasses controller's internal vocabulary.
* Each transport translates them to its own wire protocol; unsupported controls return false.
*/
internal interface GlassesLink {
val hasImu: Boolean
val badFrames: Long get() = 0L
@@ -63,7 +63,6 @@ class GlassesMenuSurface(
override fun onDetachedFromWindow() {
close()
super.onDetachedFromWindow()
// GLSurfaceView may exit its GL thread before queued cleanup is consumed.
releaseInput()
}
@@ -2,7 +2,6 @@ package com.droiddeck.launcher.glasses
import com.droiddeck.launcher.gpu.Cardboard
/** Share the actual picture mode with settings so controls match the rendered view. */
internal object GlassesRendering {
enum class Picture { FLAT, DUPLICATED, VIRTUAL_SCREEN, STEREO }
@@ -51,11 +50,7 @@ internal object GlassesRendering {
outputActive: Boolean,
steamVrRunning: Boolean,
): Cardboard {
// Mirror output still uses the glasses' picture and sensors during VR.
if (!usesGlasses(state, outputActive, steamVrRunning)) {
// SteamVR uses the renderer's enabled flag as headset proximity.
// A flat phone preview still needs an active HMD and one SBS eye;
// otherwise SteamVR enters standby and leaves a frozen frame.
return if (steamVrRunning && !base.enabled) base.copy(
enabled = true,
source = Cardboard.SOURCE_SBS,
@@ -36,7 +36,6 @@ class GlassesScreen(context: Context, display: Display, refreshHz: Int, private
fun prefer(hz: Int, resolution: GlassesResolution? = null) {
wantHz = hz
wantResolution = resolution
// A 2D/SBS transition can replace the active mode without changing Hz.
applyMode()
}
@@ -51,7 +51,6 @@ internal class HandImageBuffer {
pixels.clear()
pixels.put(rgb)
pixels.rewind()
// MediaPipe applies the model metadata's float normalization to these RGB bytes.
return ByteBufferImageBuilder(pixels, width, height, MPImage.IMAGE_FORMAT_RGB).build()
}
}
@@ -150,7 +150,6 @@ class LumaRgbCaptureService : Service() {
intent?.getIntExtra("durationMs",5000) ?: 5000) }
finally {
stopSelf()
// SDK 2.4.0 can crash while cancelling failed USB transfers; isolate each diagnostic.
android.os.Process.killProcess(android.os.Process.myPid())
}
}, "luma-rgb-diagnostic").start()
@@ -40,12 +40,9 @@ internal data class RayNeoCalibration(val gyroBiasDps: Vec3, val level: Quaterni
internal class RayNeoCalibrationStore(private val prefs: SharedPreferences) {
companion object {
// GT and GT Max can share USB identity fields. Keep the non-Max mounting
// correction separate from existing Max profiles and their legacy keys.
fun profileKey(base: String, gtUsb: Boolean, boardId: Int): String =
if (gtUsb && boardId == RayNeoProtocol.BOARD_GT) "$base:gt-standard-v1" else base
}
// A serial isolates physical units. Devices without one share their model profile.
fun key(vid: Int, pid: Int, serial: String?, modelName: String = ""): String =
"rayneo-cal-v1:$vid:$pid:${serial?.takeIf { it.isNotBlank() } ?: "model:$modelName"}"
fun load(key: String): RayNeoCalibration? = RayNeoCalibration.decode(prefs.getString(key, null))
@@ -55,7 +52,6 @@ internal class RayNeoCalibrationStore(private val prefs: SharedPreferences) {
}
}
/** One upside-down stationary pose estimates gyro bias and tilt, never yaw or accelerometer scale. */
internal class RayNeoCalibrationCollector(private val axes: RayNeoSensorAxes, private val beganMs: Long) {
var phase = CalibrationPhase.SETTLING; private set
var progress = 0; private set
@@ -6,7 +6,6 @@ import android.hardware.usb.UsbManager
import android.os.SystemClock
import android.util.Log
/** RayNeo command/response and IMU share one endpoint. Keep reads on a single worker. */
internal class RayNeoLink private constructor(
private val connection: UsbDeviceConnection,
private val endpoints: RayNeoEndpointSelection,
@@ -52,7 +51,6 @@ internal class RayNeoLink private constructor(
ready && (mode == RayNeoProtocol.CMD_SWITCH_TO_3D || mode == RayNeoProtocol.CMD_SWITCH_TO_2D) &&
command(mode)
}
// No VITURE brightness, volume, film, rate or raw command is sent to RayNeo.
else -> false
}
}
@@ -159,7 +157,6 @@ internal class RayNeoLink private constructor(
}
val wxyz = filter.update(packet.sample)
if (wantImu && collector == null && lastSensor >= warmupUntil) {
// Normalize basis and component order at the hardware boundary.
listener.onPose(raw, RayNeoOrientationFilter.glassesPose(wxyz),
SystemClock.elapsedRealtimeNanos())
}
@@ -176,7 +173,6 @@ internal class RayNeoLink private constructor(
override fun close() {
synchronized(writeLock) {
if (!running) return
// Best effort: stop the sensor before releasing the claimed interface.
if (ready) runCatching { command(RayNeoProtocol.CMD_CLOSE_IMU) }
running = false
}
@@ -8,8 +8,6 @@ object RayNeoModel {
fun model(vid: Int, pid: Int, name: String?): GlassesModel? {
if (!isVendor(vid)) return null
// GT's identity is confirmed by verncat's SDK; do not claim other products
// from that vendor just because their name resembles a supported model.
val gt = RayNeoProtocol.isGt(vid, pid)
if (vid == RayNeoProtocol.GT_VENDOR_ID && !gt) return null
if (!(vid == RayNeoProtocol.VENDOR_ID && pid == RayNeoProtocol.PRODUCT_ID) &&
@@ -23,8 +21,6 @@ object RayNeoModel {
name.contains("rayneo", ignoreCase = true) || name.contains("ray neo", ignoreCase = true) ||
modelName.containsMatchIn(name)
// Observed on GT Max: Android exposes an unbranded EDID monitor name.
// Match its product metadata, not every display called SmartGlasses/TCL.
fun isDisplayProduct(name: String?, manufacturer: String?, productId: String?): Boolean =
name?.trim().equals("SmartGlasses", ignoreCase = true) &&
manufacturer.equals("TCL", ignoreCase = true) && productId == "980"
@@ -33,7 +29,7 @@ object RayNeoModel {
override val controllable = true
override val brightnessMax = 0
override val volumeMax = 0
override val diagonalFovDeg = 46f // Conservative existing default, not a calibrated model profile.
override val diagonalFovDeg = 46f
override val sbs90 = false
override fun mode(hz: Int, sbs: Boolean) =
if (sbs) RayNeoProtocol.CMD_SWITCH_TO_3D else RayNeoProtocol.CMD_SWITCH_TO_2D
@@ -1,5 +1,4 @@
// Adapted from informalTechCode/RayNeo-Air-Series-3DoF-Scaffold (Apache-2.0).
// See docs/third-party/rayneo/. Returns scaffold quaternions in (w, x, y, z) order.
// Adapted from informalTechCode/RayNeo-Air-Series-3DoF-Scaffold (Apache-2.0); see docs/third-party/rayneo/ for license and attribution.
package com.droiddeck.launcher.glasses
import kotlin.math.cos
@@ -123,10 +122,6 @@ internal class RayNeoOrientationFilter(
private var lastRealtimeNs: Long = 0L
companion object {
/** Scaffold: right +X, up +Y, back +Z. VITURE: right -Y, up +Z, back -X.
* Conjugate by HeadPose.GLASSES_AXES before entering the unchanged VITURE pose path.
* This is a basis conversion, not a projection or seated-origin adjustment.
*/
fun glassesPose(wxyz: FloatArray): FloatArray =
floatArrayOf(-wxyz[3], -wxyz[1], wxyz[2], wxyz[0])
}
@@ -168,8 +163,6 @@ internal class RayNeoOrientationFilter(
if (accelNorm > 1e-3f) {
val measuredUp = accel.normalized()
if (!gravityInitialized) {
// Align gravity before publishing the first pose. Starting at
// identity and settling after recenter can rotate the horizon.
val axis = measuredUp.cross(worldUp)
q = if (measuredUp.y < -0.9999f) {
Quaternion.fromAxisAngle(Vec3(1f, 0f, 0f), Math.PI.toFloat())
@@ -179,7 +172,6 @@ internal class RayNeoOrientationFilter(
gravityInitialized = true
}
val predictedUp = q.conjugate().rotate(worldUp).normalized()
// q maps body to world: measured x predicted reduces gravity error.
val correction = measuredUp.cross(predictedUp)
gyro += correction * accelGain
}
@@ -40,14 +40,13 @@ data class RayNeoEndpointSelection(
object RayNeoProtocol {
const val VENDOR_ID = 0x1BBB
const val PRODUCT_ID = 0xAF50
// verncat/RayNeo-Air-3S-Pro-OpenVR PR #3 (MIT), tested on GT hardware.
const val GT_VENDOR_ID = 0x3941
private const val GT_CONTROL_INTERFACE = 5
fun isGt(vid: Int, pid: Int) = vid == GT_VENDOR_ID && pid == PRODUCT_ID
const val BOARD_AIR_4_PRO = 0x3A
const val BOARD_GT = 0x40 // Observed on the user's non-Max GT.
const val BOARD_GT = 0x40
const val PKT_MAGIC = 0x99
const val PKT_SENSOR = 0x65
@@ -131,7 +130,6 @@ object RayNeoProtocol {
endpoint.type != UsbConstants.USB_ENDPOINT_XFER_BULK) {
continue
}
// Exclude small button reports from GT's protocol transport.
if (gt && endpoint.maxPacketSize < 64) continue
if (endpoint.direction == UsbConstants.USB_DIR_IN && inEndpoint == null) {
@@ -159,8 +157,6 @@ object RayNeoProtocol {
}
}
// Interface numbers can change with firmware. Use a unique protocol-sized
// pair when interface 5 is absent, never an arbitrary composite interface.
return if (gt) gtCandidates.singleOrNull() else fallback
}
@@ -9,7 +9,6 @@ import android.hardware.usb.UsbManager
import android.os.SystemClock
import android.util.Log
/** Controls are vendor control transfers; the HID interrupt endpoint streams IMU reports unprompted. */
internal class RokidLink private constructor(
private val connection: UsbDeviceConnection,
private val usbInterface: UsbInterface,
@@ -44,7 +43,7 @@ internal class RokidLink private constructor(
?.let { listener.onValue(VitureProtocol.MSG_BRIGHTNESS, RokidModel.brightnessStep(it)) } != null
VitureProtocol.MSG_BRIGHTNESS -> value in 0..RokidModel.BRIGHTNESS_STEPS &&
control(RokidModel.REQUEST_SET_BRIGHTNESS, RokidModel.brightnessRaw(value), RokidModel.INDEX_BRIGHTNESS)
else -> false // Volume is the glasses' USB audio device; there is no film or IMU-rate control.
else -> false
}
}
@@ -54,7 +53,6 @@ internal class RokidLink private constructor(
if (!running) return null
val buffer = ByteArray(64)
val count = connection.controlTransfer(VENDOR_IN, request, 0, index, buffer, buffer.size, TIMEOUT_MS)
// Display mode is reported in the second byte, brightness in the first.
val offset = if (request == RokidModel.REQUEST_GET_DISPLAY) 1 else 0
if (count > offset) buffer[offset].toInt() and 0xff else null
}
@@ -90,7 +88,6 @@ internal class RokidLink private constructor(
if (enabled && !wasTracking) fusion = ImuFusion()
wasTracking = enabled
if (!enabled) continue
// Max captures: already right/up/back; level gravity +Y, turn left +gyroY, look up +gyroX, roll right -gyroZ.
fusion.update(sample.timeNs, sample.accel, sample.gyro)?.let {
if (running && tracking) listener.onPose(buffer.copyOf(count), it, SystemClock.elapsedRealtimeNanos())
}
@@ -3,7 +3,6 @@ package com.droiddeck.launcher.glasses
import java.nio.ByteBuffer
import java.nio.ByteOrder
/** Rokid Air/Max share one USB identity; Max 2 has a separate product ID. */
internal class RokidModel private constructor(override val name: String, private val max: Boolean) : GlassesModel {
override val controllable = true
override val brightnessMax = BRIGHTNESS_STEPS
@@ -36,7 +35,6 @@ internal class RokidModel private constructor(override val name: String, private
const val MAX2_PRODUCT_ID = 0x2002
const val BRIGHTNESS_STEPS = 10
// Vendor control requests, device recipient.
const val REQUEST_SET_DISPLAY = 0x01
const val REQUEST_GET_DISPLAY = 0x81
const val REQUEST_SET_BRIGHTNESS = 0x02
@@ -51,7 +49,6 @@ internal class RokidModel private constructor(override val name: String, private
const val MODE_SBS_1200_60 = 5
val MODES = setOf(MODE_2D_60, MODE_SBS_1080_60, MODE_2D_120, MODE_SBS_1200_90, MODE_SBS_1200_60)
// 0x04d2 is a shared vendor ID, so the Rokid product string is required too.
fun model(vid: Int, pid: Int, name: String?): GlassesModel? {
if (vid != VENDOR_ID || (pid != PRODUCT_ID && pid != MAX2_PRODUCT_ID)) return null
val product = name?.trim()?.takeIf { it.startsWith("Rokid", ignoreCase = true) } ?: return null
@@ -60,7 +57,6 @@ internal class RokidModel private constructor(override val name: String, private
fun isDisplay(name: String) = name.contains("Rokid", ignoreCase = true)
/** Device brightness is 0..100; the shared slider uses ten steps. */
fun brightnessStep(raw: Int): Int = ((raw.coerceIn(0, 100) + 5) / 10).coerceIn(0, BRIGHTNESS_STEPS)
fun brightnessRaw(step: Int): Int = step.coerceIn(0, BRIGHTNESS_STEPS) * 10
}
@@ -74,7 +70,6 @@ internal object RokidProtocol {
private const val SENSOR_ACCEL = 1
private const val SENSOR_GYRO = 2
/** Max sends one combined report; Air sends accel and gyro reports that share a timestamp. */
class Parser {
private var accel: Vec3? = null
private var accelTime = -1L
@@ -87,7 +82,7 @@ internal object RokidProtocol {
return when (packet[0].toInt() and 0xff) {
COMBINED -> Sample(b.getLong(1), vec(b, 9), vec(b, 21), packet[59].toInt() and 0xff)
SEPARATE -> {
val time = b.getLong(9) * 1000 // Air reports microseconds; Max reports nanoseconds.
val time = b.getLong(9) * 1000
when (packet[1].toInt() and 0xff) {
SENSOR_ACCEL -> { accel = vec(b, 21); accelTime = time }
SENSOR_GYRO -> { gyro = vec(b, 21); gyroTime = time }
@@ -26,7 +26,6 @@ internal class StereoCalibration(val identity: String, val width: Int, val heigh
val source get() = if (bundledBase && !verified) "luma-ultra-base" else "device"
private val p1 = Mat.zeros(3, 4, CvType.CV_64F)
private val p2 = Mat.zeros(3, 4, CvType.CV_64F)
private val undistortionMaps = Array(2) { arrayOf(Mat(),Mat()) }
init {
val a = Mat.eye(3, 4, CvType.CV_64F)
val b = Mat.zeros(3, 4, CvType.CV_64F)
@@ -35,18 +34,6 @@ internal class StereoCalibration(val identity: String, val width: Int, val heigh
Core.gemm(k1, a, 1.0, empty, 0.0, p1); Core.gemm(k2, b, 1.0, empty, 0.0, p2)
a.release(); b.release(); empty.release()
}
fun undistort(src: Mat, dst: Mat, right: Boolean) {
val k = if (right) k2 else k1; val d = if (right) d2 else d1
val maps=undistortionMaps[if(right) 1 else 0]
if(maps[0].empty()) {
val identity=Mat.eye(3,3,CvType.CV_64F)
try {
if(fisheye) Calib3d.fisheye_initUndistortRectifyMap(k,d,identity,k,src.size(),CvType.CV_16SC2,maps[0],maps[1])
else Calib3d.initUndistortRectifyMap(k,d,identity,k,src.size(),CvType.CV_16SC2,maps[0],maps[1])
} finally { identity.release() }
}
Imgproc.remap(src,dst,maps[0],maps[1],Imgproc.INTER_LINEAR)
}
fun triangulateRaw(left: List<Point>, right: List<Point>): List<SpatialVector>? {
val points = triangulateLandmarksRaw(left,right) ?: return null
return if(points.any { it == null }) null else points.filterNotNull()
@@ -74,10 +61,6 @@ internal class StereoCalibration(val identity: String, val width: Int, val heigh
return triangulatePoints(l.toList(),r.toList())
} finally { l.release(); r.release(); identity.release() }
}
fun triangulate(left: List<Point>, right: List<Point>): List<SpatialVector>? {
val points = triangulatePoints(left,right) ?: return null
return if(points.any { it == null }) null else points.filterNotNull()
}
private fun triangulatePoints(left: List<Point>, right: List<Point>): List<SpatialVector?>? {
if (left.size != right.size || left.isEmpty()) return null
val a = Mat(2, left.size, CvType.CV_64F); val b = Mat(2, right.size, CvType.CV_64F); val out = Mat()
@@ -105,7 +88,7 @@ internal class StereoCalibration(val identity: String, val width: Int, val heigh
val tmp = File(file.parentFile,file.name+".tmp"); tmp.writeText(j.toString())
java.nio.file.Files.move(tmp.toPath(),file.toPath(),java.nio.file.StandardCopyOption.REPLACE_EXISTING)
}
override fun close() { (listOf(k1,d1,k2,d2,r,t,p1,p2)+undistortionMaps.flatMap { it.toList() }).forEach { it.release() } }
override fun close() { listOf(k1,d1,k2,d2,r,t,p1,p2).forEach { it.release() } }
companion object {
fun load(file: File, identity: String, width: Int, height: Int): StereoCalibration? =
runCatching { StereoCalibrationProfile.parse(file.readText(), identity, width, height)?.let(::fromProfile) }.getOrNull()
@@ -286,7 +269,6 @@ internal class StereoCalibrator(private val context: Context) : AutoCloseable {
Mat().also { output -> corrected.add(output); Calib3d.fisheye_undistortPoints(pixels,output,k,d,identity,k) }
}
try {
// OpenCV 4.13 fisheye stereo fitting assumes equal corner counts in every view.
Calib3d.stereoCalibrate(objects,images(left,k1,d1),images(right,k2,d2),k1,if(fish)zero else d1,k2,if(fish)zero else d2,
size,r,t,e,f,Calib3d.CALIB_FIX_INTRINSIC)
} finally { (corrected+listOf(e,f,identity,zero)).forEach(Mat::release) }
@@ -383,7 +383,6 @@ internal class StereoHandEngine(private val context: Context, private val token:
message=context.getString(R.string.spatial_frame_changed)
calibrationProgress = calibrationProgress.copy(collecting = false, capturing = false, captureMessage = message)
}
// The callback pose's basis is undocumented; use canonical GL pose history.
val observation=HandObservation(time,generation,trackingFrame)
var captureHead=observation.headPose(SpatialTracking.session,metadata[6]>0)
val w=metadata[0].toInt();val h=metadata[1].toInt()
@@ -499,7 +498,6 @@ internal class StereoHandEngine(private val context: Context, private val token:
dl=pair.first.hands;dr=pair.second.hands
if(scheduled) inferenceSchedule.observe(stamp,dl.map { it.side },dr.map { it.side },pair.first.rawCount,pair.second.rawCount)
val inferenceMs=(System.nanoTime()-inferenceStart)/1e6f
// VIO callbacks can arrive during inference; verify this exact camera stamp before publishing.
captureHead=observation.headPose(SpatialTracking.session,
metadata[6]>0 || VitureSdk.nativeCameraSynchronized(token,metadata[2]))
val hands=Array(2) { SpatialHand() }
@@ -631,7 +629,7 @@ internal class StereoHandEngine(private val context: Context, private val token:
SpatialTracking.publish(System.nanoTime())
}
}
} catch(e: InterruptedException) { /* Shutdown interrupts the idle wait. */ }
} catch(e: InterruptedException) { }
catch(e: Throwable) {
message=context.getString(R.string.spatial_hand_error, e.message.orEmpty())
val unavailable=HandObservationDiagnostic(HandObservationOutcome.INFERENCE_UNAVAILABLE)
@@ -31,7 +31,6 @@ internal class StereoInferenceRunner : AutoCloseable {
catch (e: ExecutionException) { throw e.cause ?: e }
}
} finally {
// Native inference must finish before either camera's pixels or detector can be reused.
if (interrupted) Thread.currentThread().interrupt()
}
}
@@ -12,8 +12,6 @@ internal object UvcRgbDiagnostic {
internal data class UvcStreamHealth(val observationMs: Double, val observedFps: Double,
val maximumGapMs: Double, val healthy: Boolean) {
companion object {
// Health requires the full requested window, 80% of requested FPS, and no gap
// (including the final silent interval) above max(250 ms, three frame periods).
fun assess(metadata: LongArray, requestedFps: Int, durationMs: Int): UvcStreamHealth {
require(metadata.size == 14 && requestedFps > 0 && durationMs > 0)
val first = metadata[7]
@@ -81,7 +81,6 @@ object VitureProtocol {
}
}
/** SDK validates the PID before returning this market name. Never guess a new PID. */
fun sdkModel(marketName: String): Model? {
val family = when (marketName) {
"One", "Lite" -> Family.ONE
@@ -3,7 +3,6 @@ package com.droiddeck.launcher.glasses
import android.util.Log
import kotlin.math.sqrt
/** JNI adapter to VITURE's Android C SDK. The vendor binary is a local build input. */
internal object VitureSdk {
val available: Boolean by lazy {
runCatching {
@@ -27,7 +26,6 @@ internal object VitureSdk {
external fun nativeSpatialDiagnostics(token: Long): DoubleArray?
external fun nativeTracking(token: Long, enabled: Boolean): Int
external fun nativeCommand(token: Long, command: Int, value: Int): Int
/** Returns CLOCK_BOOTTIME receipt time, zero for no new pose, or a negative SDK error. */
external fun nativePose(token: Long, wxyz: FloatArray): Long
external fun nativeNextState(token: Long, event: IntArray): Int
external fun nativeClose(token: Long)
@@ -48,12 +46,9 @@ internal object VitureSpatialIdentity {
}
internal object VitureSdkPose {
// Pro 2 hardware captures use OpenGL axes despite the generic Gen2 callback's
// NWU documentation. Keep that model-specific exception out of other Gen2 devices.
fun usesOpenGlAxes(carina: Boolean, family: VitureProtocol.Family?) =
carina || family == VitureProtocol.Family.PRO2
/** SDK quaternions are wxyz; normalize their coordinate basis at the boundary. */
fun toGlasses(wxyz: FloatArray, openGlAxes: Boolean): FloatArray? {
if (wxyz.size != 4 || wxyz.any { !it.isFinite() }) return null
val length = sqrt(wxyz.sumOf { it.toDouble() * it }.toFloat())
@@ -7,7 +7,6 @@ import android.os.SystemClock
import android.util.Log
import java.io.File
/** SDK owns interface selection (including Ultra bulk endpoints) and all USB I/O. */
internal class VitureSdkLink private constructor(
private val connection: UsbDeviceConnection,
private val token: Long,
@@ -47,7 +46,6 @@ internal class VitureSdkLink private constructor(
if (rc == 0 || !wanted) tracking = wanted
return result("tracking", rc)
}
// Frequency is negotiated against SDK capabilities, including Pro 2's pose limit.
VitureProtocol.MSG_IMU_RATE -> return tracking
VitureProtocol.MSG_GET_IMU -> return true
}
@@ -89,7 +87,6 @@ internal class VitureSdkLink private constructor(
if (VitureSdk.nativeNextState(token, event) == 1) when (event[0]) {
0 -> listener.onValue(VitureProtocol.MSG_GET_BRIGHTNESS, event[1])
1 -> listener.onValue(VitureProtocol.MSG_GET_VOLUME, event[1])
// A device event can use a different display-mode namespace.
2 -> send(VitureProtocol.MSG_GET_DISPLAY)
3 -> listener.onValue(VitureProtocol.MSG_FILM, event[1])
}
@@ -122,7 +119,6 @@ internal class VitureSdkLink private constructor(
if (!running) return
running = false
VitureSdk.nativeClose(token)
// Keep Java's descriptor alive until the SDK and its worker threads have stopped.
connection.close()
}
if (Thread.currentThread() !== worker) worker.join(1000)
@@ -69,7 +69,6 @@ internal class VitureV2Link internal constructor(
return true
}
if (msgId == VitureProtocol.MSG_GET_IMU) return true
// Keep the measured 120 Hz mode; the generic controller requests 240 Hz.
if (msgId == VitureProtocol.MSG_IMU_RATE) return false
val query = when (msgId) {
VitureProtocol.MSG_GET_BRIGHTNESS -> VitureV2Protocol.MSG_GET_BRIGHTNESS
@@ -146,9 +145,7 @@ internal class VitureV2Link internal constructor(
tracking(true)
if (becameReady) listener.onReady()
val q = pose.quaternion
// Upstream right/up/back pose converted to the shared VITURE legacy basis.
val shared = floatArrayOf(-q[2], -q[0], q[1], q[3])
// Upstream does not establish device tick units; use host monotonic receipt time.
if (running && wanted && streamOn) listener.onPose(received.bytes, shared, received.timeNs)
return
}
@@ -1,5 +1,4 @@
// Adapted from elasticjava/viture-v2, MIT, Copyright (c) 2026 Holger Bartnick.
// Source: ece8c30485f7d357fefa362ae74f3eabac9b3899; see docs/third-party/viture-v2/.
// Adapted from elasticjava/viture-v2, MIT, Copyright (c) 2026 Holger Bartnick. Source: ece8c30485f7d357fefa362ae74f3eabac9b3899; see docs/third-party/viture-v2/.
package com.droiddeck.launcher.glasses
import kotlin.math.sqrt
@@ -37,7 +36,6 @@ object VitureV2Protocol {
val success: Boolean get() = status == 0
}
// Device ticks have no established time unit; quaternion is xyzw with no axis remapping.
class Pose internal constructor(
val deviceTick: Long,
val quaternion: FloatArray,
@@ -64,7 +62,6 @@ object VitureV2Protocol {
}
fun imuControl(streams: Int, rate: Rate = Rate.HZ_120): ByteArray {
// Upstream measured that stream mask 3 ACKs but produces no events on Pro 2.
require(streams == STREAM_OFF || streams == STREAM_POSE || streams == STREAM_RAW)
require(streams != STREAM_POSE || rate.hz <= 240)
val wireRate = if (streams == STREAM_OFF) 0 else rate.wireValue
@@ -24,7 +24,6 @@ internal interface XrealConnector : Closeable {
internal class XrealNetworkMissing : IOException("XREAL USB Ethernet network is not available")
/** Bind individual sockets, never the process: Steam must retain its Internet network. */
internal class AndroidXrealConnector(context: Context) : XrealConnector {
private val manager = context.getSystemService(ConnectivityManager::class.java)
private val address = InetAddress.getByName(XrealProtocol.HOST)
@@ -7,7 +7,6 @@ import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
/** One connection owns two TCP channels. All control requests are serialized off the UI thread. */
internal class XrealLink internal constructor(
private val connector: XrealConnector,
private val listener: Listener,
@@ -47,7 +46,7 @@ internal class XrealLink internal constructor(
VitureProtocol.MSG_DISPLAY -> value in 2..5 || value == XrealModel.NATIVE_60HZ
VitureProtocol.MSG_BRIGHTNESS -> value in 0..9
VitureProtocol.MSG_FILM -> value in 0..1
else -> false // No guessed volume, sensor-rate, or VITURE wire commands.
else -> false
}
return valid && commands.offer(Command(msgId, value))
}
@@ -88,7 +87,7 @@ internal class XrealLink internal constructor(
}
} catch (e: Exception) {
failure.set(e)
current.close() // Wake a control read immediately.
current.close()
}
}, "xreal-reports").apply { isDaemon = true; start() }
ready = true
@@ -145,12 +144,11 @@ internal class XrealLink internal constructor(
tracking = false
commands.clear()
connection.getAndSet(null)?.close()
connector.close() // Includes sockets still inside connect().
connector.close()
worker.interrupt()
}
}
/** Kept independent of Android so the real framing/acknowledgement path is testable. */
internal class XrealControl(private val channels: XrealChannels, private val settleDelayMs: Long = 150) {
private var transaction = 0
private fun exchange(command: Int, value: Int? = null): ByteArray {
@@ -158,7 +156,7 @@ internal class XrealControl(private val channels: XrealChannels, private val set
channels.controlOutput.write(XrealProtocol.request(command, transaction, value))
channels.controlOutput.flush()
val deadline = System.nanoTime() + 3_000_000_000L
repeat(32) { // Bound unsolicited button/status packets and stale responses.
repeat(32) {
if (System.nanoTime() > deadline) throw IOException("XREAL control timed out")
XrealProtocol.response(XrealProtocol.read(channels.controlInput), command, transaction)?.let { return it }
}
@@ -172,9 +170,6 @@ internal class XrealControl(private val channels: XrealChannels, private val set
fun changeDisplay(mode: Int): Int {
val stereo = mode == 5
set(XrealProtocol.SET_INPUT, if (stereo) 1 else 0)
// On 1S, SET_INPUT itself changes EDID. Sending SET_DISPLAY immediately
// receives error 5001 while that change is pending. GET_DISPLAY returns
// an empty property during the transition; wait for a real mode report.
val current = awaitDisplay { (it == 5) == stereo }
if (current == mode) return current
set(XrealProtocol.SET_DISPLAY, mode)
@@ -1,10 +1,9 @@
package com.droiddeck.launcher.glasses
/** First One-family target. Recovery and Air USB products must not use this transport. */
object XrealModel : GlassesModel {
const val VENDOR_ID = 0x3318
const val PRODUCT_1S = 0x043e
const val NATIVE_60HZ = 29 // Captured on 1S: 1920 x 1200 at 60 Hz.
const val NATIVE_60HZ = 29
override val name = "XREAL 1S"
override val controllable = true
override val brightnessMax = 9
@@ -16,7 +15,6 @@ object XrealModel : GlassesModel {
fun matches(vid: Int, pid: Int) = vid == VENDOR_ID && pid == PRODUCT_1S
fun isDisplay(name: String) = name.contains("XREAL", ignoreCase = true)
// One-family EDID configuration values, not VITURE's display mode IDs.
override fun mode(hz: Int, sbs: Boolean) = when {
sbs -> 5
hz >= 120 -> 4
@@ -2,19 +2,14 @@ package com.droiddeck.launcher.glasses
import kotlin.math.abs
/** 1S radians/sec and device nanoseconds, mapped using directed hardware captures. */
internal class XrealOrientationFilter {
private val fusion = ImuFusion()
// 1S reports right/down/forward. Rotate 180 degrees about X into the
// shared right/up/back basis before either gravity alignment or fusion.
// Captures: level gravity -Y; looking left -gyroY; up +gyroX; right tilt +gyroZ.
fun update(sample: XrealProtocol.Sample): FloatArray? = fusion.update(sample.timeNs,
Vec3(sample.accel.x, -sample.accel.y, -sample.accel.z),
Vec3(sample.gyro.x, -sample.gyro.y, -sample.gyro.z))
}
/** Gyro integration with gravity correction in the shared right/up/back basis, rad/s and device ns. */
internal class ImuFusion {
private var previous = 0L
private var rotation = Quaternion.IDENTITY
@@ -27,7 +22,7 @@ internal class ImuFusion {
previous = timeNs
val norm = accel.length()
val gravityValid = abs(norm - 9.81f) < 1.5f
if (dt > 0.25f) initialized = false // Never integrate a reconnect/stall as motion.
if (dt > 0.25f) initialized = false
if (!initialized) {
if (!gravityValid) return null
val up = accel.normalized()
@@ -47,7 +42,6 @@ internal class ImuFusion {
}
rotation = rotation.integrateBodyRate(rate, dt).normalized()
}
// Same right/up/back -> shared glasses basis used by the RayNeo adapter.
return RayNeoOrientationFilter.glassesPose(floatArrayOf(rotation.w, rotation.x, rotation.y, rotation.z))
}
}
@@ -6,7 +6,6 @@ import java.io.InputStream
import java.nio.ByteBuffer
import java.nio.ByteOrder
/** Independent implementation of the One-family wire format; see xreal-investigation.md. */
internal object XrealProtocol {
const val HOST = "169.254.2.1"
const val REPORT_PORT = 52998
@@ -46,7 +45,7 @@ internal object XrealProtocol {
fun sample(frame: Frame): Sample? {
if (frame.command != REPORT || frame.body.size != 128) return null
val b = ByteBuffer.wrap(frame.body).order(ByteOrder.LITTLE_ENDIAN)
if (b.getInt(24) != 11) return null // Magnetometer reports are a different type.
if (b.getInt(24) != 11) return null
val time = b.getLong(8)
val gyro = Vec3(b.getFloat(28), b.getFloat(32), b.getFloat(36))
val accel = Vec3(b.getFloat(40), b.getFloat(44), b.getFloat(48))
@@ -64,7 +63,6 @@ internal object XrealProtocol {
.putInt(4 + payload.size).putInt(transaction or Int.MIN_VALUE).put(payload).array()
}
/** No acknowledgement is inferred from a write; match both command and transaction. */
fun response(frame: Frame, command: Int, transaction: Int): ByteArray? {
if (frame.command != command || frame.body.size < 4 ||
ByteBuffer.wrap(frame.body).int != transaction) return null