mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Compatibility check; notification icon fixes
* Display a warning if paired glasses do not have a compatible custo firmware * Fix certain notification icons being missing on system card * Rescale large notification icons with proper sampling; don't send unnecessary
This commit is contained in:
1 parent
c9fe92dc1c
commit
3532b1f437
13 files changed
+383
-18
No files matched your search
@@ -25,6 +25,10 @@
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<!-- Needed to resolve other apps' notification small icons (Icon TYPE_RESOURCE):
|
||||
package visibility filtering otherwise makes Icon.loadDrawable fail with
|
||||
NameNotFoundException for any package we cannot see. -->
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||
|
||||
<application
|
||||
android:name="com.tns.NativeScriptApplication"
|
||||
|
||||
@@ -89,6 +89,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
private int headsetBattery = -1;
|
||||
private int headsetCharging = -1;
|
||||
private boolean audioCaptureActive;
|
||||
private boolean firmwareInfoQueried;
|
||||
private volatile FaceclawAudioPacketListener audioPacketListener;
|
||||
private PowerManager.WakeLock g2ScreenWakeLock;
|
||||
|
||||
@@ -583,6 +584,18 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
setStateDisplay("connected", "Connected.");
|
||||
logLine("session ready");
|
||||
synchronized (lock) {
|
||||
// Query settings promptly on the first session so firmware
|
||||
// version/capabilities (and battery) arrive without waiting for
|
||||
// the input-quiet battery poll. The settings response doubles as
|
||||
// the firmware-compatibility check surfaced during onboarding.
|
||||
if (!firmwareInfoQueried) {
|
||||
firmwareInfoQueried = true;
|
||||
lastBatteryRefreshAtMs = SystemClock.elapsedRealtime();
|
||||
pendingMessages.addLast(createBatteryQueryMessageLocked());
|
||||
logLine("queue settings query for firmware info");
|
||||
}
|
||||
}
|
||||
tryConnectRing("initial");
|
||||
} catch (Throwable t) {
|
||||
logLine("connect failed: " + safeMessage(t));
|
||||
@@ -1198,6 +1211,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
// guarantee that the tile is now visible on-screen, so it must not
|
||||
// update the displayed-tile cache used by image dedupe.
|
||||
warmedUp = true;
|
||||
// Warmup fragments are image messages on the wire, so they reset
|
||||
// the firmware's heartbeat timer just like real image updates.
|
||||
lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime();
|
||||
};
|
||||
message.onTimeout = () -> {
|
||||
warmedUp = false;
|
||||
@@ -1262,6 +1278,11 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
message.setImageUpdatePosition(updateId, messageNumber, messageCount);
|
||||
message.onAck = () -> {
|
||||
imageRetryAfterMs = 0;
|
||||
// Firmware >= 2.2.4.34 resets its heartbeat timer when it receives
|
||||
// image messages (not just heartbeats), so an acked image fragment
|
||||
// satisfies the heartbeat deadline and heartbeats stop contending
|
||||
// with active rendering.
|
||||
lastHeartbeatAckedAtMs = SystemClock.elapsedRealtime();
|
||||
logImageUpdateAckLandmarkLocked(message);
|
||||
if (message.tileIndex >= 0 && !hasPendingOrInflightTileLocked(message.tileIndex)) {
|
||||
displayedBmp = BmpUtil.copyTileBmp(plan.bmp);
|
||||
@@ -1327,6 +1348,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
headsetCharging = snapshot.charging;
|
||||
emitBatteryState(headsetBattery, headsetCharging);
|
||||
}
|
||||
BleProtocol.FirmwareInfo firmwareInfo = BleProtocol.parseSettingsFirmwareInfo(message.ackPayload);
|
||||
if (firmwareInfo != null) {
|
||||
emitFirmwareInfo(firmwareInfo);
|
||||
}
|
||||
};
|
||||
message.onTimeout = () -> {
|
||||
logLine("Battery query timed out");
|
||||
@@ -1576,6 +1601,20 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
});
|
||||
}
|
||||
|
||||
private void emitFirmwareInfo(BleProtocol.FirmwareInfo info) {
|
||||
final FaceclawBleCommunicatorListener current = listener;
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
mainHandler.post(() -> {
|
||||
try {
|
||||
current.onFirmwareInfo(info.leftVersion, info.rightVersion, info.capabilities);
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "listener onFirmwareInfo failed", t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void emitFrameMetrics(int paintMs, int transmitMs, int tileCount) {
|
||||
final FaceclawBleCommunicatorListener current = listener;
|
||||
if (current == null) {
|
||||
|
||||
+1
@@ -8,4 +8,5 @@ public interface FaceclawBleCommunicatorListener {
|
||||
void onEvenAppConflict(String message);
|
||||
void onFrameMetrics(int paintMs, int transmitMs, int tileCount);
|
||||
void onFrameFinished(int frameId, String outcome);
|
||||
void onFirmwareInfo(String leftVersion, String rightVersion, String capabilities);
|
||||
}
|
||||
+70
-6
@@ -6,6 +6,7 @@ import android.app.PendingIntent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
@@ -164,9 +165,13 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
|
||||
}
|
||||
Drawable drawable = loadNotificationIcon(service, statusBarNotification.getNotification());
|
||||
if (drawable == null) {
|
||||
Log.i(TAG, "icon skipped (no drawable): " + statusBarNotification.getPackageName());
|
||||
continue;
|
||||
}
|
||||
appendIconGrayBytes(drawable, size, out);
|
||||
Log.i(TAG, "icon[" + emitted + "] pkg=" + statusBarNotification.getPackageName()
|
||||
+ " drawable=" + drawable.getClass().getSimpleName()
|
||||
+ " intrinsic=" + drawable.getIntrinsicWidth() + "x" + drawable.getIntrinsicHeight());
|
||||
appendIconGrayBytes(drawable, size, out, service, emitted, statusBarNotification.getPackageName());
|
||||
if (dedupeGroupKey != null) {
|
||||
emittedGroupKeys.add(dedupeGroupKey);
|
||||
}
|
||||
@@ -401,6 +406,16 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
|
||||
if (smallIcon != null) {
|
||||
Drawable drawable = smallIcon.loadDrawable(service);
|
||||
if (drawable != null) {
|
||||
// Status-bar small icons are alpha templates: the platform
|
||||
// draws them tinted and ignores their color channels, which
|
||||
// apps may fill with garbage (Discord ships noise there).
|
||||
// Tint white so the shape comes from alpha alone, matching
|
||||
// how the status bar renders them.
|
||||
drawable.mutate();
|
||||
drawable.setTint(Color.WHITE);
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
((BitmapDrawable) drawable).setFilterBitmap(true);
|
||||
}
|
||||
return drawable;
|
||||
}
|
||||
}
|
||||
@@ -408,6 +423,7 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
|
||||
Log.w(TAG, "failed to load small notification icon", t);
|
||||
}
|
||||
try {
|
||||
// Large icons are real color images (avatars, album art); keep color.
|
||||
Icon largeIcon = notification.getLargeIcon();
|
||||
if (largeIcon != null) {
|
||||
return largeIcon.loadDrawable(service);
|
||||
@@ -418,11 +434,10 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void appendIconGrayBytes(Drawable drawable, int size, ByteArrayOutputStream out) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, size, size);
|
||||
drawable.draw(canvas);
|
||||
private static void appendIconGrayBytes(Drawable drawable, int size, ByteArrayOutputStream out,
|
||||
FaceclawMediaNotificationListenerService service, int index, String packageName) {
|
||||
Bitmap bitmap = renderIconScaled(drawable, size);
|
||||
dumpIconDebugPng(service, index, packageName, bitmap);
|
||||
for (int y = 0; y < size; y++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
int color = bitmap.getPixel(x, y);
|
||||
@@ -435,6 +450,55 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
|
||||
bitmap.recycle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a drawable at the target size with proper downscaling. Detailed
|
||||
* sources (e.g. avatar bitmaps used as notification icons) are rendered at
|
||||
* native resolution and reduced by repeated halving: a single filtered pass
|
||||
* from, say, 126px to 24px samples too sparsely and turns fine detail into
|
||||
* speckle that reads as a garbled icon.
|
||||
*/
|
||||
private static Bitmap renderIconScaled(Drawable drawable, int size) {
|
||||
int renderW = Math.max(size, drawable.getIntrinsicWidth());
|
||||
int renderH = Math.max(size, drawable.getIntrinsicHeight());
|
||||
Bitmap bitmap = Bitmap.createBitmap(renderW, renderH, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, renderW, renderH);
|
||||
drawable.draw(canvas);
|
||||
while (bitmap.getWidth() >= size * 2 && bitmap.getHeight() >= size * 2) {
|
||||
Bitmap halved = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / 2, bitmap.getHeight() / 2, true);
|
||||
bitmap.recycle();
|
||||
bitmap = halved;
|
||||
}
|
||||
if (bitmap.getWidth() != size || bitmap.getHeight() != size) {
|
||||
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, size, size, true);
|
||||
bitmap.recycle();
|
||||
bitmap = scaled;
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug aid for garbled-icon reports: saves each rendered icon to
|
||||
* <externalFilesDir>/debug-icons/ (adb-pullable) so extraction problems can
|
||||
* be told apart from downstream compositing/transmission problems. Cheap:
|
||||
* runs at most once per icon-cache refresh on tiny bitmaps.
|
||||
*/
|
||||
private static void dumpIconDebugPng(FaceclawMediaNotificationListenerService service, int index, String packageName, Bitmap bitmap) {
|
||||
try {
|
||||
java.io.File dir = new java.io.File(service.getExternalFilesDir(null), "debug-icons");
|
||||
if (!dir.exists() && !dir.mkdirs()) {
|
||||
return;
|
||||
}
|
||||
String safeName = packageName == null ? "unknown" : packageName.replaceAll("[^A-Za-z0-9._-]", "_");
|
||||
java.io.File file = new java.io.File(dir, "icon-" + index + "-" + safeName + ".png");
|
||||
try (java.io.FileOutputStream stream = new java.io.FileOutputStream(file)) {
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "failed to dump debug icon", t);
|
||||
}
|
||||
}
|
||||
|
||||
private static StatusBarNotification findActiveNotificationByKey(FaceclawMediaNotificationListenerService service, String key) {
|
||||
if (service == null || key == null || key.isEmpty()) {
|
||||
return null;
|
||||
|
||||
@@ -181,6 +181,28 @@ public class BleProtocol {
|
||||
return new BatterySnapshot(battery, charging);
|
||||
}
|
||||
|
||||
/**
|
||||
* Firmware versions and the CFW capability advertisement from a settings
|
||||
* READ ack. Versions are fields 5/6 of the deviceReceiveRequestFromApp
|
||||
* submessage (field 4); the custom firmware additionally appends top-level
|
||||
* field 100, a string like "EVENCFW/1 img576 imgz xordelta stereo", which
|
||||
* stock firmware never sends. Returns null when the ack carries none of it.
|
||||
*/
|
||||
public static FirmwareInfo parseSettingsFirmwareInfo(byte[] pb) {
|
||||
byte[] root = stripTrailingCrc(pb);
|
||||
byte[] request = readFieldBytes(root, 4);
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
String leftVersion = readStringFieldValue(request, 5);
|
||||
String rightVersion = readStringFieldValue(request, 6);
|
||||
String capabilities = readStringFieldValue(root, 100);
|
||||
if (leftVersion.isEmpty() && rightVersion.isEmpty() && capabilities.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return new FirmwareInfo(leftVersion, rightVersion, capabilities);
|
||||
}
|
||||
|
||||
public static byte[] wrapEvenHub(int cmd, int magic, int innerFieldNumber, byte[] inner) {
|
||||
List<byte[]> parts = new ArrayList<>();
|
||||
parts.add(encodeVarintField(1, cmd));
|
||||
@@ -509,4 +531,16 @@ public class BleProtocol {
|
||||
this.charging = charging;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class FirmwareInfo {
|
||||
final String leftVersion;
|
||||
final String rightVersion;
|
||||
final String capabilities;
|
||||
|
||||
FirmwareInfo(String leftVersion, String rightVersion, String capabilities) {
|
||||
this.leftVersion = leftVersion;
|
||||
this.rightVersion = rightVersion;
|
||||
this.capabilities = capabilities;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import { nightscoutBridge } from "../native/nightscout-bridge";
|
||||
import { onAndroidNotificationPosted } from "../native/notification-icons";
|
||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||
import { grayImageToPreviewSource } from "../native/gray-image-preview";
|
||||
import { firmwareIncompatibilityMessage } from "./firmware-compat";
|
||||
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
|
||||
import { voiceControlBridge } from "../native/voice-control";
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||
import {
|
||||
@@ -44,6 +46,8 @@ export type DashboardSnapshot = {
|
||||
activeTextSettingValue: string;
|
||||
evenAppConflictMessage: string;
|
||||
evenAppConflictWarningVisible: boolean;
|
||||
firmwareWarningMessage: string;
|
||||
firmwareWarningVisible: boolean;
|
||||
};
|
||||
|
||||
type DashboardListener = (snapshot: DashboardSnapshot) => void;
|
||||
@@ -118,6 +122,7 @@ class DashboardController {
|
||||
private activeTextSetting: ConfigSettingString | null = null;
|
||||
private evenNotificationActive = false;
|
||||
private evenAppConflictMessage = "";
|
||||
private firmwareWarningMessage = "";
|
||||
private displayPreview: ImageSource | null = createInitialDisplayPreview();
|
||||
private readonly listeners = new Set<DashboardListener>();
|
||||
|
||||
@@ -132,6 +137,7 @@ class DashboardController {
|
||||
private offBattery: (() => void) | null = null;
|
||||
private offEvenAppConflict: (() => void) | null = null;
|
||||
private offFrameMetrics: (() => void) | null = null;
|
||||
private offFirmwareInfo: (() => void) | null = null;
|
||||
private offMedia: (() => void) | null = null;
|
||||
private offNightscout: (() => void) | null = null;
|
||||
private offVoiceStatus: (() => void) | null = null;
|
||||
@@ -145,6 +151,9 @@ class DashboardController {
|
||||
private queuedFrameId = 0;
|
||||
private lastForegroundNotificationUpdateAtMs = 0;
|
||||
private lastConnectedPreviewUpdateAtMs = 0;
|
||||
// Consumed by the next renderDashboard: repaint with data sources not
|
||||
// allowed to serve stale caches (set after a frame painted with stale data).
|
||||
private nextRenderWantsFreshData = false;
|
||||
|
||||
constructor() {
|
||||
setDashboardActions({
|
||||
@@ -184,6 +193,8 @@ class DashboardController {
|
||||
activeTextSettingValue: this.activeTextSetting?.get() ?? "",
|
||||
evenAppConflictMessage: this.evenAppConflictMessage,
|
||||
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
|
||||
firmwareWarningMessage: this.firmwareWarningMessage,
|
||||
firmwareWarningVisible: this.firmwareWarningMessage.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -232,6 +243,7 @@ class DashboardController {
|
||||
this.log = "";
|
||||
this.lastInput = "waiting...";
|
||||
this.lastSys = "none yet";
|
||||
this.firmwareWarningMessage = "";
|
||||
resetDashboardSleepTimerAndWake();
|
||||
this.refreshEvenAppStatus();
|
||||
this.setPhase("connecting");
|
||||
@@ -299,6 +311,20 @@ class DashboardController {
|
||||
this.setStatus(`Connected. Last frame: ${this.formatFrameMetrics(metrics)}.`);
|
||||
}
|
||||
});
|
||||
this.offFirmwareInfo = communicator.onFirmwareInfo((info) => {
|
||||
this.appendLog(
|
||||
`firmware: L=${info.leftVersion || "?"} R=${info.rightVersion || "?"}` +
|
||||
(info.capabilities ? ` caps="${info.capabilities}"` : " (no CFW capability string)"),
|
||||
);
|
||||
const warning = firmwareIncompatibilityMessage(info) ?? "";
|
||||
if (warning !== this.firmwareWarningMessage) {
|
||||
this.firmwareWarningMessage = warning;
|
||||
if (warning) {
|
||||
this.appendLog(`firmware compatibility warning: ${warning}`);
|
||||
}
|
||||
this.emit();
|
||||
}
|
||||
});
|
||||
this.offMedia = mediaControllerBridge.onStateChange(() => {
|
||||
if (this.phase === "connected" && this.communicator) {
|
||||
void this.requestRender("interval").catch((error) => {
|
||||
@@ -360,6 +386,8 @@ class DashboardController {
|
||||
this.offEvenAppConflict = null;
|
||||
this.offFrameMetrics?.();
|
||||
this.offFrameMetrics = null;
|
||||
this.offFirmwareInfo?.();
|
||||
this.offFirmwareInfo = null;
|
||||
this.offMedia?.();
|
||||
this.offMedia = null;
|
||||
this.offNightscout?.();
|
||||
@@ -406,6 +434,8 @@ class DashboardController {
|
||||
this.offEvenAppConflict = null;
|
||||
this.offFrameMetrics?.();
|
||||
this.offFrameMetrics = null;
|
||||
this.offFirmwareInfo?.();
|
||||
this.offFirmwareInfo = null;
|
||||
this.offMedia?.();
|
||||
this.offMedia = null;
|
||||
this.offNightscout?.();
|
||||
@@ -580,11 +610,18 @@ class DashboardController {
|
||||
private async renderDashboard(reason: "initial" | "interval", frameId: number): Promise<void> {
|
||||
console.log("renderDashboard", reason);
|
||||
frameTimings.logFrame(frameId, `renderDashboard start (${reason})`);
|
||||
const wantFreshData = this.nextRenderWantsFreshData;
|
||||
this.nextRenderWantsFreshData = false;
|
||||
beginRenderPass(!wantFreshData);
|
||||
const paintStartedAtMs = Date.now();
|
||||
const image = frameTimings.span(frameId, "paint", () =>
|
||||
frameTimings.runWithFrame(frameId, () => drawDashboard()),
|
||||
);
|
||||
const paintMs = Date.now() - paintStartedAtMs;
|
||||
const paintUsedStaleData = endRenderPass();
|
||||
if (paintUsedStaleData) {
|
||||
frameTimings.logFrame(frameId, "painted with stale data; will schedule a fresh-data repaint");
|
||||
}
|
||||
const fingerprint = frameTimings.span(frameId, "fingerprint", () => image.fingerprint());
|
||||
const updatePreviewAfterTransmit = this.phase === "connected";
|
||||
if (!updatePreviewAfterTransmit) {
|
||||
@@ -613,6 +650,13 @@ class DashboardController {
|
||||
frameTimings.finishFrame(frameId, "discarded: no communicator, preview only");
|
||||
}
|
||||
|
||||
if (paintUsedStaleData) {
|
||||
this.nextRenderWantsFreshData = true;
|
||||
void this.requestRender("interval").catch((error) => {
|
||||
this.appendLog(`fresh-data repaint failed: ${this.formatError(error)}`);
|
||||
});
|
||||
}
|
||||
|
||||
this.updateConnectedForegroundNotification();
|
||||
if (reason === "initial") {
|
||||
this.appendLog("initial dashboard image queued");
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Compatibility check for the glasses firmware. Faceclaw requires the custom
|
||||
* firmware: version >= 2.2.4.34 with the "imgz" extension token in the CFW
|
||||
* capability string ("EVENCFW/1 img576 imgz ..."). Stock firmware sends no
|
||||
* capability string at all.
|
||||
*/
|
||||
|
||||
import { type FirmwareInfo } from "../native/faceclaw-communicator";
|
||||
|
||||
const MIN_FIRMWARE_VERSION = [2, 2, 4, 34];
|
||||
const REQUIRED_FIRMWARE_EXTENSION = "imgz";
|
||||
|
||||
function parseDottedVersion(version: string): number[] {
|
||||
return version
|
||||
.trim()
|
||||
.split(".")
|
||||
.map((part) => {
|
||||
const value = parseInt(part, 10);
|
||||
return Number.isFinite(value) ? value : 0;
|
||||
});
|
||||
}
|
||||
|
||||
/** Standard component-wise compare; missing components count as 0. */
|
||||
function compareVersions(a: number[], b: number[]): number {
|
||||
const length = Math.max(a.length, b.length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
const delta = (a[i] ?? 0) - (b[i] ?? 0);
|
||||
if (delta !== 0) return delta;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Human-readable explanation of why this firmware cannot run Faceclaw, or
|
||||
* null if it is compatible. Returns null when no version was reported at all
|
||||
* (no data is not evidence of incompatibility).
|
||||
*/
|
||||
export function firmwareIncompatibilityMessage(info: FirmwareInfo): string | null {
|
||||
const reportedVersions = [info.leftVersion, info.rightVersion].filter((v) => v.trim().length > 0);
|
||||
if (reportedVersions.length === 0) return null;
|
||||
|
||||
const minVersionText = MIN_FIRMWARE_VERSION.join(".");
|
||||
const versionsText = `L=${info.leftVersion || "unknown"} R=${info.rightVersion || "unknown"}`;
|
||||
|
||||
if (reportedVersions.some((v) => compareVersions(parseDottedVersion(v), MIN_FIRMWARE_VERSION) < 0)) {
|
||||
return (
|
||||
`The glasses report firmware ${versionsText}, but Faceclaw requires the modified firmware, ` +
|
||||
`version ${minVersionText} or newer. Displaying images will not work until the glasses firmware is updated.`
|
||||
);
|
||||
}
|
||||
|
||||
const tokens = info.capabilities.trim().split(/\s+/);
|
||||
if (!tokens.includes(REQUIRED_FIRMWARE_EXTENSION)) {
|
||||
return (
|
||||
`The glasses firmware (${versionsText}) does not advertise the "${REQUIRED_FIRMWARE_EXTENSION}" extension` +
|
||||
`${info.capabilities.trim() ? ` (reported: ${info.capabilities.trim()})` : ", which suggests stock firmware"}. ` +
|
||||
`Faceclaw requires the modified firmware with compressed-image support.`
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -26,6 +26,12 @@ export type FrameMetrics = {
|
||||
tileCount: number;
|
||||
};
|
||||
|
||||
export type FirmwareInfo = {
|
||||
leftVersion: string;
|
||||
rightVersion: string;
|
||||
capabilities: string;
|
||||
};
|
||||
|
||||
export type RawInputEvent =
|
||||
| {
|
||||
kind: "list-click";
|
||||
@@ -72,6 +78,7 @@ export class FaceclawCommunicatorBridge {
|
||||
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
|
||||
private readonly evenAppConflictListeners = new Set<(message: string) => void>();
|
||||
private readonly frameMetricsListeners = new Set<(metrics: FrameMetrics) => void>();
|
||||
private readonly firmwareInfoListeners = new Set<(info: FirmwareInfo) => void>();
|
||||
|
||||
constructor(addresses: { right: string; left: string; ring?: string }) {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
@@ -139,6 +146,14 @@ export class FaceclawCommunicatorBridge {
|
||||
onFrameFinished: (frameId: number, outcome: string) => {
|
||||
this.recordFrameFinished(Number(frameId), String(outcome));
|
||||
},
|
||||
onFirmwareInfo: (leftVersion: string, rightVersion: string, capabilities: string) => {
|
||||
const info = {
|
||||
leftVersion: String(leftVersion),
|
||||
rightVersion: String(rightVersion),
|
||||
capabilities: String(capabilities),
|
||||
};
|
||||
this.emitAsync(this.firmwareInfoListeners, info);
|
||||
},
|
||||
});
|
||||
this.communicator.setListener(this.listenerProxy);
|
||||
}
|
||||
@@ -202,6 +217,11 @@ export class FaceclawCommunicatorBridge {
|
||||
return () => this.frameMetricsListeners.delete(listener);
|
||||
}
|
||||
|
||||
onFirmwareInfo(listener: (info: FirmwareInfo) => void): () => void {
|
||||
this.firmwareInfoListeners.add(listener);
|
||||
return () => this.firmwareInfoListeners.delete(listener);
|
||||
}
|
||||
|
||||
getNativeCommunicator(): any {
|
||||
return this.communicator;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,31 @@ export type AndroidNotification = {
|
||||
actions: AndroidNotificationAction[];
|
||||
};
|
||||
|
||||
export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
|
||||
if (!global.isAndroid || maxIcons <= 0) return [];
|
||||
export type NotificationIconsResult = {
|
||||
icons: GrayImage[];
|
||||
/** True when the icons came from an expired (or empty) cache under allowStale. */
|
||||
stale: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* With allowStale, this always returns immediately: expired cached icons (or
|
||||
* none at all, right after startup or a cache invalidation) come back with
|
||||
* stale=true, and the caller is expected to repaint with allowStale=false
|
||||
* once the current frame is done. Only an allowStale=false call actually
|
||||
* fetches from the notification listener service, which can be slow depending
|
||||
* on what is in the tray.
|
||||
*/
|
||||
export function readActiveNotificationIcons(maxIcons: number, allowStale: boolean): NotificationIconsResult {
|
||||
if (!global.isAndroid || maxIcons <= 0) return { icons: [], stale: false };
|
||||
|
||||
const now = Date.now();
|
||||
if (now - cachedAtMs < ICON_CACHE_MS) {
|
||||
if (cachedAtMs > 0 && now - cachedAtMs < ICON_CACHE_MS) {
|
||||
logCurrent("notification icons served from cache");
|
||||
return cachedIcons.map(icon => icon.clone());
|
||||
return { icons: cachedIcons.map(icon => icon.clone()), stale: false };
|
||||
}
|
||||
if (allowStale) {
|
||||
logCurrent("notification icons served stale");
|
||||
return { icons: cachedIcons.map(icon => icon.clone()), stale: true };
|
||||
}
|
||||
|
||||
const bytes = spanCurrent("fetch-notification-icons", () =>
|
||||
@@ -63,7 +81,7 @@ export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
|
||||
|
||||
cachedIcons = icons;
|
||||
cachedAtMs = now;
|
||||
return icons.map(icon => icon.clone());
|
||||
return { icons: icons.map(icon => icon.clone()), stale: false };
|
||||
}
|
||||
|
||||
export function readActiveNotifications(maxNotifications = 50): AndroidNotification[] {
|
||||
|
||||
@@ -11,9 +11,12 @@
|
||||
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}" />
|
||||
</StackLayout>
|
||||
<GridLayout row="1" rows="auto,auto,auto,*" class="p-20">
|
||||
<StackLayout row="0" class="m-b-8" visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
<StackLayout row="0" class="m-b-8">
|
||||
<StackLayout visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
</StackLayout>
|
||||
<Label text="{{ firmwareWarningMessage }}" textWrap="true" visibility="{{ firmwareWarningVisibility }}" />
|
||||
</StackLayout>
|
||||
<StackLayout row="1">
|
||||
<GridLayout rows="auto,auto,auto" columns="*,*,*" class="m-t-8">
|
||||
@@ -31,9 +34,12 @@
|
||||
</GridLayout>
|
||||
|
||||
<GridLayout rows="auto,*" class="p-20" visibility="{{ landscapeLayoutVisibility }}">
|
||||
<StackLayout row="0" class="m-b-8" visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
<StackLayout row="0" class="m-b-8">
|
||||
<StackLayout visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
</StackLayout>
|
||||
<Label text="{{ firmwareWarningMessage }}" textWrap="true" visibility="{{ firmwareWarningVisibility }}" />
|
||||
</StackLayout>
|
||||
<GridLayout row="1" rows="auto,auto,*" columns="*,260">
|
||||
<StackLayout row="0" col="0" visibility="{{ displayPreviewVisibility }}" horizontalAlignment="left">
|
||||
|
||||
@@ -13,6 +13,8 @@ export class MainViewModel extends Observable {
|
||||
private _activeTextSettingValue = "";
|
||||
private _evenAppConflictMessage = "";
|
||||
private _evenAppConflictWarningVisible = false;
|
||||
private _firmwareWarningMessage = "";
|
||||
private _firmwareWarningVisible = false;
|
||||
private _showLog = false;
|
||||
private _phase: "disconnected" | "connecting" | "connected" | "disconnecting" = "disconnected";
|
||||
|
||||
@@ -28,6 +30,8 @@ export class MainViewModel extends Observable {
|
||||
this.activeTextSettingValue = snapshot.activeTextSettingValue;
|
||||
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
||||
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
||||
this.firmwareWarningMessage = snapshot.firmwareWarningMessage;
|
||||
this.firmwareWarningVisible = snapshot.firmwareWarningVisible;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -199,6 +203,33 @@ export class MainViewModel extends Observable {
|
||||
return this._evenAppConflictWarningVisible ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get firmwareWarningMessage(): string {
|
||||
return this._firmwareWarningMessage;
|
||||
}
|
||||
|
||||
set firmwareWarningMessage(value: string) {
|
||||
if (this._firmwareWarningMessage !== value) {
|
||||
this._firmwareWarningMessage = value;
|
||||
this.notifyPropertyChange("firmwareWarningMessage", value);
|
||||
}
|
||||
}
|
||||
|
||||
get firmwareWarningVisible(): boolean {
|
||||
return this._firmwareWarningVisible;
|
||||
}
|
||||
|
||||
set firmwareWarningVisible(value: boolean) {
|
||||
if (this._firmwareWarningVisible !== value) {
|
||||
this._firmwareWarningVisible = value;
|
||||
this.notifyPropertyChange("firmwareWarningVisible", value);
|
||||
this.notifyPropertyChange("firmwareWarningVisibility", this.firmwareWarningVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
get firmwareWarningVisibility(): "visible" | "collapse" {
|
||||
return this._firmwareWarningVisible ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get phase(): "disconnected" | "connecting" | "connected" | "disconnecting" {
|
||||
return this._phase;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { spanCurrent } from "../../native/frame-timings";
|
||||
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
|
||||
import { BATTERY_ICON_WIDTH, drawBattery } from "../../graphics/battery";
|
||||
import { readActiveNotificationIcons } from "../../native/notification-icons";
|
||||
import { readPhoneBatteryState } from "../../native/phone-battery";
|
||||
@@ -32,7 +33,11 @@ function drawSystemCardFlowItems(image: GrayImage, bounds: DashboardPluginCardBo
|
||||
const items: SystemCardFlowItem[] = [];
|
||||
if (showAndroidNotificationsSetting.get()) {
|
||||
const maxNotificationIcons = Math.max(0, ((right - left) / Math.max(1, NOTIFICATION_ICON_SIZE + SYSTEM_CARD_ITEM_GAP)) | 0) * 2;
|
||||
for (const icon of readActiveNotificationIcons(maxNotificationIcons)) {
|
||||
const { icons, stale } = readActiveNotificationIcons(maxNotificationIcons, renderPassAllowsStaleData());
|
||||
if (stale) {
|
||||
noteStaleDataUsed();
|
||||
}
|
||||
for (const icon of icons) {
|
||||
items.push({ type: "notification", icon });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Per-render-pass channel for stale-data tracking. JS is single-threaded and
|
||||
* paints are synchronous, so module state set around a paint is visible to
|
||||
* every data source consulted during it, without threading flags through each
|
||||
* paint signature.
|
||||
*
|
||||
* Data sources with a cache (e.g. notification icons) consult
|
||||
* renderPassAllowsStaleData() to decide whether to return expired cached data
|
||||
* immediately instead of blocking the paint on a refetch, and report having
|
||||
* done so via noteStaleDataUsed(). The render loop reads the result from
|
||||
* endRenderPass() and schedules one follow-up repaint with fresh data, so the
|
||||
* first frame out of sleep is never blocked on slow data sources.
|
||||
*/
|
||||
|
||||
let allowStale = true;
|
||||
let staleDataUsed = false;
|
||||
|
||||
export function beginRenderPass(allowStaleData: boolean): void {
|
||||
allowStale = allowStaleData;
|
||||
staleDataUsed = false;
|
||||
}
|
||||
|
||||
export function renderPassAllowsStaleData(): boolean {
|
||||
return allowStale;
|
||||
}
|
||||
|
||||
export function noteStaleDataUsed(): void {
|
||||
staleDataUsed = true;
|
||||
}
|
||||
|
||||
/** End the pass, returning whether any source served stale data. */
|
||||
export function endRenderPass(): boolean {
|
||||
const usedStale = staleDataUsed;
|
||||
allowStale = true;
|
||||
staleDataUsed = false;
|
||||
return usedStale;
|
||||
}
|
||||
Reference in new issue
Block a user