diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java index 6aba3b3d..e7bce6ca 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawFlashPromptCommunicator.java @@ -26,6 +26,10 @@ import java.util.concurrent.TimeUnit; * protobuf helpers (BleProtocol), but owns its own GATT connection and runs its * whole lifecycle on a single worker thread. It expects the main app to be * disconnected while it runs (onboarding, before flashing). + * + * Only the right arm is used: the lenses relay messages to each other, so + * anything sent to the right arm reaches both, and acks/events only ever come + * from the right arm anyway. */ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { private static final String TAG = "FaceclawFlashPrompt"; @@ -43,7 +47,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { private final Context context; private final String rightAddress; - private final String leftAddress; private final String warningText; private final FaceclawBleManager bleManager; private final Handler mainHandler = new Handler(Looper.getMainLooper()); @@ -58,7 +61,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { private volatile boolean cancelled = false; private volatile boolean finished = false; private volatile boolean rightConnected = false; - private volatile boolean leftConnected = false; private volatile boolean rightLost = false; private volatile Boolean approved = null; private volatile ScheduledExecutorService heartbeatExecutor; @@ -66,10 +68,9 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { private int nextMagic = 100; private int nextSeq = 0x40; - public FaceclawFlashPromptCommunicator(Context context, String rightAddress, String leftAddress, String warningText) { + public FaceclawFlashPromptCommunicator(Context context, String rightAddress, String warningText) { this.context = context.getApplicationContext(); this.rightAddress = rightAddress == null ? "" : rightAddress; - this.leftAddress = leftAddress == null ? "" : leftAddress; this.warningText = warningText == null ? "" : warningText; this.bleManager = new FaceclawBleManager(this.context); this.bleManager.setListener(this); @@ -116,18 +117,8 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { } emitState("connecting", ""); - connectArm(rightAddress, "right"); + connectArm(rightAddress); rightConnected = true; - - boolean haveLeft = !leftAddress.trim().isEmpty() && !leftAddress.equalsIgnoreCase(rightAddress); - if (haveLeft) { - try { - connectArm(leftAddress, "left"); - leftConnected = true; - } catch (Exception e) { - emitLog("left arm connect failed (continuing on right only): " + e.getMessage()); - } - } if (cancelled) { teardown(); return; @@ -135,14 +126,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { emitState("connected", ""); bringUpArm(rightAddress); - if (leftConnected) { - try { - bringUpArm(leftAddress); - } catch (Exception e) { - emitLog("left arm prompt failed (continuing on right only): " + e.getMessage()); - leftConnected = false; - } - } startHeartbeat(); emitState("prompting", ""); @@ -158,7 +141,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { if (approved != null) { boolean result = Boolean.TRUE.equals(approved); try { - sendShutdownBoth(); + sendShutdown(); } catch (Exception ignored) { } emitResult(result); @@ -182,7 +165,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { } } - private void connectArm(String address, String labelForLog) { + private void connectArm(String address) { if (!bleManager.connect(address, ConnectionOptions.CONNECT_TIMEOUT_MS)) { throw new IllegalStateException("connect failed: " + address); } @@ -194,7 +177,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { if (!bleManager.enableNotifications(address, BleProtocol.NOTIFY_CHAR_UUID, true, ConnectionOptions.DESCRIPTOR_TIMEOUT_MS)) { throw new IllegalStateException("enableNotifications failed: " + address); } - emitLog("connected " + labelForLog + " arm"); + emitLog("connected right arm"); } private void bringUpArm(String address) throws InterruptedException { @@ -301,9 +284,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { if (rightConnected) { writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat); } - if (leftConnected) { - writeFrame(leftAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, heartbeat); - } } catch (Exception e) { Log.w(TAG, "heartbeat failed: " + e.getMessage()); } @@ -317,14 +297,11 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { } } - private void sendShutdownBoth() { + private void sendShutdown() { byte[] shutdown = BleProtocol.buildShutdown(allocMagic(), 0); if (rightConnected) { writeFrame(rightAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown); } - if (leftConnected) { - writeFrame(leftAddress, BleProtocol.SID_EVENHUB, BleProtocol.FLAG_REQUEST, shutdown); - } } private void teardown() { @@ -335,7 +312,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { } catch (Exception ignored) { } rightConnected = false; - leftConnected = false; } @Override @@ -355,10 +331,7 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { return; } if (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT) { - // Async events (taps/selections) only ever come from the right arm. - if (address.equalsIgnoreCase(rightAddress)) { - handleEvent(frame); - } + handleEvent(frame); return; } if (frame.msgSeq >= 0) { @@ -407,8 +380,6 @@ public class FaceclawFlashPromptCommunicator implements FaceclawBleListener { selectionLatch.countDown(); } } - } else if (address.equalsIgnoreCase(leftAddress)) { - leftConnected = false; } } diff --git a/app/app.css b/app/app.css index 673fc5bb..6e4dda3a 100644 --- a/app/app.css +++ b/app/app.css @@ -50,6 +50,31 @@ Button.-primary { tint-color: #e6e6e6; } +/* License / privacy-policy links in the onboarding disclaimer footer. The + * padding widens the tap target beyond the small text. */ +.footer-link { + color: #3b6fd6; + font-size: 15; + text-decoration: underline; + padding: 4 8; +} + +.ns-dark .footer-link { + color: #8ab0ff; +} + +.footer-link-separator { + color: #777777; + font-size: 15; + padding: 4 0; +} + +/* Bundled project docs (phone-ui/document-page). LICENSE and PRIVACY are + * hard-wrapped plain text, so keep the size modest to limit rewrapping. */ +.document-text { + font-size: 13; +} + /* * Stands in for the lens preview when showing it would be misleading (silent * mode, or a disconnect explained by a flat battery). Sized by the view model @@ -199,6 +224,29 @@ Button.pairing-link { border-width: 0; } +/* + * Permissions screen (phone-ui/permissions-page). Cards reuse the pairing-row + * / pairing-title / pairing-badge look above; these add the explanation body + * and the already-granted checkmark. + */ +.permissions-description { + font-size: 13; + color: #555555; + margin-top: 2; +} + +.permissions-check { + font-size: 24; + color: #2e7d32; + margin-left: 10; +} + +/* Continue with required permissions still missing: looks disabled but stays + * tappable (the tap raises an are-you-sure prompt instead of being ignored). */ +Button.permissions-primary-dimmed { + opacity: 0.45; +} + /* * Dark-mode pairing page. The cards keep their light-mode look above; here * they go dark-gray, and every text colour set above gets a light counterpart @@ -277,3 +325,11 @@ Button.pairing-link { .ns-dark Button.pairing-link { color: #7da7f5; } + +.ns-dark .permissions-description { + color: #b0b0b0; +} + +.ns-dark .permissions-check { + color: #7bc47f; +} diff --git a/app/g2/android-permissions.ts b/app/g2/android-permissions.ts index 648846ee..e3c4a949 100644 --- a/app/g2/android-permissions.ts +++ b/app/g2/android-permissions.ts @@ -5,6 +5,8 @@ const VOICE_PERMISSION_REQUEST_CODE = 4243; const CALENDAR_PERMISSION_REQUEST_CODE = 4244; const LOCATION_PERMISSION_REQUEST_CODE = 4245; const FINE_LOCATION_PERMISSION_REQUEST_CODE = 4246; +const BLE_ONLY_PERMISSION_REQUEST_CODE = 4247; +const POST_NOTIFICATIONS_PERMISSION_REQUEST_CODE = 4248; const POST_NOTIFICATIONS_PERMISSION = "android.permission.POST_NOTIFICATIONS"; const RECORD_AUDIO_PERMISSION = "android.permission.RECORD_AUDIO"; const READ_CALENDAR_PERMISSION = "android.permission.READ_CALENDAR"; @@ -31,23 +33,22 @@ function toJavaStringArray(values: string[]): string[] { return result; } -function getRequiredPermissions(): string[] { - const sdk = android.os.Build.VERSION.SDK_INT; - const permissions: string[] = []; - - if (sdk >= 31) { - permissions.push( +/** The runtime permissions this Android version needs for BLE scan + connect. */ +function getBlePermissions(): string[] { + if (android.os.Build.VERSION.SDK_INT >= 31) { + return [ android.Manifest.permission.BLUETOOTH_SCAN, android.Manifest.permission.BLUETOOTH_CONNECT, - ); - } else { - permissions.push(android.Manifest.permission.ACCESS_FINE_LOCATION); + ]; } + return [android.Manifest.permission.ACCESS_FINE_LOCATION]; +} - if (sdk >= 33) { +function getRequiredPermissions(): string[] { + const permissions = getBlePermissions(); + if (android.os.Build.VERSION.SDK_INT >= 33) { permissions.push(POST_NOTIFICATIONS_PERMISSION); } - return permissions; } @@ -107,6 +108,69 @@ export async function ensureVoicePermissions(): Promise { await ensurePermissions([RECORD_AUDIO_PERMISSION], VOICE_PERMISSION_REQUEST_CODE, "Voice control"); } +/** Whether the BLE scan/connect permissions have been granted (false off-Android). */ +export function hasBlePermissions(): boolean { + if (!global.isAndroid) return false; + return getBlePermissions().every((permission) => isPermissionGranted(permission)); +} + +/** + * Prompt for just the BLE permissions (without POST_NOTIFICATIONS, which the + * Permissions screen presents as its own card). Resolves true when granted. + */ +export async function requestBlePermissions(): Promise { + if (!global.isAndroid) return false; + try { + await ensurePermissions(getBlePermissions(), BLE_ONLY_PERMISSION_REQUEST_CODE, "Bluetooth"); + return true; + } catch { + return false; + } +} + +/** + * Whether posting notifications is allowed. Before Android 13 (sdk 33) there + * is no runtime permission for this, so it reports as granted. + */ +export function hasPostNotificationsPermission(): boolean { + if (!global.isAndroid) return false; + if (android.os.Build.VERSION.SDK_INT < 33) return true; + return isPermissionGranted(POST_NOTIFICATIONS_PERMISSION); +} + +/** Prompt for POST_NOTIFICATIONS. Resolves true when the permission is held afterward. */ +export async function requestPostNotificationsPermission(): Promise { + if (!global.isAndroid) return false; + if (android.os.Build.VERSION.SDK_INT < 33) return true; + try { + await ensurePermissions( + [POST_NOTIFICATIONS_PERMISSION], + POST_NOTIFICATIONS_PERMISSION_REQUEST_CODE, + "Notification", + ); + return true; + } catch { + return false; + } +} + +/** Whether RECORD_AUDIO has been granted (false off-Android). */ +export function hasMicrophonePermission(): boolean { + if (!global.isAndroid) return false; + return isPermissionGranted(RECORD_AUDIO_PERMISSION); +} + +/** Prompt for RECORD_AUDIO. Resolves true when granted, false on denial. */ +export async function requestMicrophonePermission(): Promise { + if (!global.isAndroid) return false; + try { + await ensureVoicePermissions(); + return true; + } catch { + return false; + } +} + /** Whether READ_CALENDAR has been granted (false off-Android). */ export function hasCalendarPermission(): boolean { if (!global.isAndroid) return false; diff --git a/app/native/flash-prompt-communicator.ts b/app/native/flash-prompt-communicator.ts index 19f08c47..a31cb420 100644 --- a/app/native/flash-prompt-communicator.ts +++ b/app/native/flash-prompt-communicator.ts @@ -17,6 +17,9 @@ export type FlashPromptState = * stock-firmware-compatible BLE path that shows the pre-flash confirmation on * the glasses and reports the user's Yes/No choice. Separate from * FaceclawCommunicatorBridge on purpose (different, minimal protocol subset). + * + * Talks to the right arm only: the lenses relay messages between themselves, + * and acks/events always come from the right arm. */ export class FlashPromptCommunicator { private readonly communicator: any; @@ -25,14 +28,13 @@ export class FlashPromptCommunicator { private readonly stateListeners = new Set<(state: FlashPromptState, detail: string) => void>(); private readonly resultListeners = new Set<(approved: boolean) => void>(); - constructor(addresses: { right: string; left: string }, warningText: string) { + constructor(rightAddress: string, warningText: string) { const context = Utils.android.getApplicationContext(); if (!context) throw new Error("Android application context unavailable"); this.communicator = new com.faceclaw.app.FaceclawFlashPromptCommunicator( context, - addresses.right, - addresses.left, + rightAddress, warningText, ); this.listenerProxy = new com.faceclaw.app.FaceclawFlashPromptListener({ diff --git a/app/phone-ui/config-page.ts b/app/phone-ui/config-page.ts index 9b9e3edc..301d0039 100644 --- a/app/phone-ui/config-page.ts +++ b/app/phone-ui/config-page.ts @@ -4,8 +4,8 @@ import { ConfigViewModel } from "./config-view-model"; export function navigatingTo(args: NavigatedData): void { const page = args.object as Page; - // Preserve the model across back-navigation (returning from the unpair page) - // so the onboarding "Continue" flow isn't lost. + // Preserve the model across back-navigation (returning from the firmware + // check page) so the onboarding "Continue" flow isn't lost. if (!page.bindingContext) { const context = (args.context as { onboarding?: boolean } | undefined) ?? undefined; page.bindingContext = new ConfigViewModel({ onboarding: context?.onboarding ?? false }); diff --git a/app/phone-ui/config-view-model.ts b/app/phone-ui/config-view-model.ts index 40a78dad..00f3a24b 100644 --- a/app/phone-ui/config-view-model.ts +++ b/app/phone-ui/config-view-model.ts @@ -232,8 +232,8 @@ export class ConfigViewModel extends Observable { return; } if (this.onboarding) { - // Continue the onboarding chain: unpair the official app next. - Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-unpair-page" }); + // Continue the onboarding chain: check the glasses' firmware next. + Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-firmware-check-page" }); } } diff --git a/app/phone-ui/document-page.ts b/app/phone-ui/document-page.ts new file mode 100644 index 00000000..a9e6ad0c --- /dev/null +++ b/app/phone-ui/document-page.ts @@ -0,0 +1,26 @@ +import { Frame, NavigatedData, Page, knownFolders } from "@nativescript/core"; + +/** Phone-side viewer for the project docs that webpack.config.js copies into + * the bundle under about/ (LICENSE, PRIVACY, ...). The glasses-side + * equivalent lives in ui/dashboard/settings-menus.ts. */ +type DocumentContext = { fileName?: string; title?: string } | undefined; + +export function navigatingTo(args: NavigatedData): void { + const page = args.object as Page; + const context = args.context as DocumentContext; + const fileName = context?.fileName ?? ""; + page.bindingContext = { + title: context?.title ?? fileName, + text: readBundledDoc(fileName), + onBackTap: () => Frame.topmost()?.goBack(), + }; +} + +function readBundledDoc(fileName: string): string { + try { + const text = knownFolders.currentApp().getFile(`about/${fileName}`).readTextSync(); + return text || `(${fileName} is missing from this build)`; + } catch { + return `(${fileName} is missing from this build)`; + } +} diff --git a/app/phone-ui/document-page.xml b/app/phone-ui/document-page.xml new file mode 100644 index 00000000..a0812b9a --- /dev/null +++ b/app/phone-ui/document-page.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index ec7ffe68..84d508c3 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -3,6 +3,7 @@ + diff --git a/app/phone-ui/main-view-model.ts b/app/phone-ui/main-view-model.ts index ad331513..ab31378d 100644 --- a/app/phone-ui/main-view-model.ts +++ b/app/phone-ui/main-view-model.ts @@ -484,6 +484,13 @@ export class MainViewModel extends Observable { Frame.topmost()?.navigate("phone-ui/config-page"); } + onPermissionsTap(): void { + Frame.topmost()?.navigate({ + moduleName: "phone-ui/permissions-page", + context: { onboarding: false }, + }); + } + /** * Live scan that names each nearby pair by model, colour, and serial and * checks both arms belong together. A connected arm stops advertising, so diff --git a/app/phone-ui/onboarding-firmware-check-view-model.ts b/app/phone-ui/onboarding-firmware-check-view-model.ts index c1fe5477..ff8ace3b 100644 --- a/app/phone-ui/onboarding-firmware-check-view-model.ts +++ b/app/phone-ui/onboarding-firmware-check-view-model.ts @@ -125,7 +125,11 @@ export class OnboardingFirmwareCheckViewModel extends Observable { frame.goBack(); return; } - frame?.navigate({ moduleName: "phone-ui/onboarding-unpair-page", clearHistory: true }); + frame?.navigate({ + moduleName: "phone-ui/pairing-page", + context: { onboarding: true }, + clearHistory: true, + }); } /** Escape hatch when the check itself fails: flash as if stock firmware had been detected. */ diff --git a/app/phone-ui/onboarding-flash-view-model.ts b/app/phone-ui/onboarding-flash-view-model.ts index 0a4e368f..7d29bdf1 100644 --- a/app/phone-ui/onboarding-flash-view-model.ts +++ b/app/phone-ui/onboarding-flash-view-model.ts @@ -253,7 +253,7 @@ export class OnboardingFlashViewModel extends Observable { private startCommunicator(addresses: { right: string; left: string }): void { this.disposePrompt(); - const prompt = new FlashPromptCommunicator(addresses, this.glassesWarning); + const prompt = new FlashPromptCommunicator(addresses.right, this.glassesWarning); this.prompt = prompt; this.promptUnsubscribers.push( diff --git a/app/phone-ui/onboarding-page.ts b/app/phone-ui/onboarding-page.ts index 69e00b33..ee47af0b 100644 --- a/app/phone-ui/onboarding-page.ts +++ b/app/phone-ui/onboarding-page.ts @@ -1,12 +1,16 @@ -import { EventData, Page } from "@nativescript/core"; +import { NavigatedData, Page } from "@nativescript/core"; import { OnboardingViewModel } from "./onboarding-view-model"; -export function navigatingTo(args: EventData): void { +type OnboardingContext = { step?: number } | undefined; + +export function navigatingTo(args: NavigatedData): void { const page = args.object as Page; // Preserve the step when returning from the flashing page (back navigation - // re-fires navigatingTo); only build a fresh model on first entry. + // re-fires navigatingTo); only build a fresh model on first entry. The + // permissions page navigates here with { step: 3 } to continue the flow. if (!page.bindingContext) { - page.bindingContext = new OnboardingViewModel(); + const context = args.context as OnboardingContext; + page.bindingContext = new OnboardingViewModel(context?.step); } } diff --git a/app/phone-ui/onboarding-page.xml b/app/phone-ui/onboarding-page.xml index 6608ce8f..00ef31c8 100644 --- a/app/phone-ui/onboarding-page.xml +++ b/app/phone-ui/onboarding-page.xml @@ -1,5 +1,5 @@ - + - + + + +