diff --git a/App_Resources/Android/src/main/AndroidManifest.xml b/App_Resources/Android/src/main/AndroidManifest.xml index 4b6764f3..04244efc 100644 --- a/App_Resources/Android/src/main/AndroidManifest.xml +++ b/App_Resources/Android/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ + updateG2ScreenWakeLock(screenOn)); + } + public boolean startG2AudioCapture(FaceclawAudioPacketListener listener) { if (listener == null) { throw new IllegalArgumentException("listener is required"); @@ -1526,6 +1537,28 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { }); } + private void updateG2ScreenWakeLock(boolean screenOn) { + if (screenOn) { + if (g2ScreenWakeLock == null) { + g2ScreenWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, G2_SCREEN_WAKE_LOCK_TAG); + g2ScreenWakeLock.setReferenceCounted(false); + } + if (!g2ScreenWakeLock.isHeld()) { + g2ScreenWakeLock.acquire(); + logLine("G2 screen wake lock acquired"); + } + return; + } + releaseG2ScreenWakeLock(); + } + + private void releaseG2ScreenWakeLock() { + if (g2ScreenWakeLock != null && g2ScreenWakeLock.isHeld()) { + g2ScreenWakeLock.release(); + logLine("G2 screen wake lock released"); + } + } + private void logLine(String line) { Log.i(TAG, line); final FaceclawBleCommunicatorListener current = listener; diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 970b3d59..5ed662f2 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -13,6 +13,7 @@ import { voiceControlBridge } from "../native/voice-control"; import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image"; import { applyDashboardScreenTimeout, + dashboardState, drawDashboard, noteDashboardPhoneTextInput, openAndroidNotificationFromSleep, @@ -561,9 +562,15 @@ class DashboardController { this.updateDisplayPreviewFromImage(image); } if (this.communicator) { + if (dashboardState.screenOn) { + await this.communicator.setG2ScreenOn(true); + } console.log("submitDashboardImage"); await this.communicator.submitDashboardImage(image.to8bppBuffer(), image.width, image.height, fingerprint, paintMs); await this.communicator.waitForNextFrameMetrics(FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS); + if (!dashboardState.screenOn) { + await this.communicator.setG2ScreenOn(false); + } if (updatePreviewAfterTransmit) { await this.updateConnectedDisplayPreviewFromImage(image); } diff --git a/app/native/faceclaw-communicator.ts b/app/native/faceclaw-communicator.ts index 1546225d..4f14e0b3 100644 --- a/app/native/faceclaw-communicator.ts +++ b/app/native/faceclaw-communicator.ts @@ -225,6 +225,10 @@ export class FaceclawCommunicatorBridge { await this.enqueueJavaCall(() => this.communicator.start()); } + async setG2ScreenOn(screenOn: boolean): Promise { + await this.enqueueJavaCall(() => this.communicator.setG2ScreenOn(Boolean(screenOn))); + } + async submitDashboardImage(image8bpp: Uint8Array, width: number, height: number, fingerprint: string, paintMs = -1): Promise { const snapshot = new Uint8Array(image8bpp); await this.enqueueJavaCall(() => {