forked from Blendman974/faceclaw
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user