Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calls): hide the Android lock-screen prompt once access is granted (#9995)

Peter Chinman84e3c6d3e022
diff --git a/apps/web/src/features/channel/Call/FullScreenCallPrompt.tsx b/apps/web/src/features/channel/Call/FullScreenCallPrompt.tsx
index 95f83a7ffd..8f03bb150c 100644
--- a/apps/web/src/features/channel/Call/FullScreenCallPrompt.tsx
+++ b/apps/web/src/features/channel/Call/FullScreenCallPrompt.tsx
@@ -18,8 +18,13 @@ const DISMISSED_KEY = 'full-screen-call-prompt-dismissed';
const dismissedValue = z.literal('true');
const fullScreenIntentState = z.object({ allowed: z.boolean() });
-async function canUseFullScreenIntent(): Promise<boolean> {
+type AccessCheckTrigger = 'mount' | 'resume';
+
+async function canUseFullScreenIntent(
+ trigger: AccessCheckTrigger
+): Promise<boolean> {
return Telemetry.span('call.full_screen_intent.check', async (span) => {
+ span.setAttr('call.full_screen_intent.trigger', trigger);
const result = await catchToResult(() =>
invoke<unknown>('plugin:call-kit|can_use_full_screen_intent')
);
@@ -83,9 +88,14 @@ export function FullScreenCallPrompt() {
},
});
- const checkBlocked = async () =>
- setBlocked(!(await canUseFullScreenIntent()));
- onMount(() => fireAndForget(checkBlocked(), 'channel-call'));
+ // Only the latest check decides: an earlier one that finishes late is stale.
+ let latestCheck = 0;
+ const checkBlocked = async (trigger: AccessCheckTrigger) => {
+ const check = ++latestCheck;
+ const allowed = await canUseFullScreenIntent(trigger);
+ if (check === latestCheck) setBlocked(!allowed);
+ };
+ onMount(() => fireAndForget(checkBlocked('mount'), 'channel-call'));
// Calls only ring once notifications are on; that prompt comes first.
const shouldShow = createMemo(
@@ -99,12 +109,16 @@ export function FullScreenCallPrompt() {
);
// The toast stays up while the user is in Settings; returning rechecks
- // access, and granting it unmounts the toast.
+ // access, and granting it unmounts the toast. The Android WebView shows the
+ // page again on return but never fires window focus.
const recheckOnReturn = () => {
- if (shouldShow()) fireAndForget(checkBlocked(), 'channel-call');
+ if (document.visibilityState === 'visible' && shouldShow())
+ fireAndForget(checkBlocked('resume'), 'channel-call');
};
- window.addEventListener('focus', recheckOnReturn);
- onCleanup(() => window.removeEventListener('focus', recheckOnReturn));
+ document.addEventListener('visibilitychange', recheckOnReturn);
+ onCleanup(() =>
+ document.removeEventListener('visibilitychange', recheckOnReturn)
+ );
return (
<Show when={shouldShow()}>
diff --git a/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx b/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx
index fc9ba4021c..d8e32c9865 100644
--- a/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx
+++ b/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx
@@ -71,6 +71,23 @@ function accessChecks() {
).length;
}
+let visibility: DocumentVisibilityState = 'visible';
+Object.defineProperty(document, 'visibilityState', {
+ configurable: true,
+ get: () => visibility,
+});
+
+function setVisibility(next: DocumentVisibilityState) {
+ visibility = next;
+ document.dispatchEvent(new Event('visibilitychange'));
+}
+
+/** Leaves for Settings and comes back, as the Android WebView reports it. */
+function returnFromSettings() {
+ setVisibility('hidden');
+ setVisibility('visible');
+}
+
/** Waits for the mount check to reach native and its result to land. */
async function settleAccessCheck() {
await waitFor(() => expect(accessChecks()).toBeGreaterThan(0));
@@ -80,6 +97,7 @@ async function settleAccessCheck() {
describe('full-screen call prompt', () => {
beforeEach(() => {
localStorage.clear();
+ visibility = 'visible';
native.allowed = false;
native.invoke.mockReset();
native.invoke.mockImplementation(async (command: string) => {
@@ -99,16 +117,56 @@ describe('full-screen call prompt', () => {
localStorage.getItem('full-screen-call-prompt-dismissed')
).toBeNull();
- // Back from Settings without allowing it.
+ // Leaving for Settings doesn't check; coming back without allowing it
+ // checks once and keeps the toast, with Allow still there.
const checks = accessChecks();
- fireEvent.focus(window);
+ setVisibility('hidden');
+ expect(accessChecks()).toBe(checks);
+ setVisibility('visible');
await waitFor(() => expect(accessChecks()).toBe(checks + 1));
await new Promise((resolve) => setTimeout(resolve, 0));
expect(screen.getByText(title)).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Allow' })).toBeTruthy();
native.allowed = true;
- fireEvent.focus(window);
+ returnFromSettings();
await waitFor(() => expect(screen.queryByText(title)).toBeNull());
+
+ // Granted: later returns don't bring it back.
+ returnFromSettings();
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(screen.queryByText(title)).toBeNull();
+ });
+
+ it('ignores an earlier check that finishes after a later one', async () => {
+ renderPrompt();
+ await screen.findByText(title);
+
+ const pending: ((state: { allowed: boolean }) => void)[] = [];
+ native.invoke.mockImplementation((command: string) =>
+ command === 'plugin:call-kit|can_use_full_screen_intent'
+ ? new Promise((resolve) => pending.push(resolve))
+ : Promise.resolve()
+ );
+ returnFromSettings();
+ returnFromSettings();
+ await waitFor(() => expect(pending).toHaveLength(2));
+
+ pending[1]({ allowed: true });
+ await waitFor(() => expect(screen.queryByText(title)).toBeNull());
+ pending[0]({ allowed: false });
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ expect(screen.queryByText(title)).toBeNull();
+ });
+
+ it('stays hidden on the next launch once access is granted', async () => {
+ native.allowed = true;
+ renderPrompt();
+ await settleAccessCheck();
+ expect(screen.queryByText(title)).toBeNull();
+ expect(
+ localStorage.getItem('full-screen-call-prompt-dismissed')
+ ).toBeNull();
});
it('stays hidden on this device once dismissed', async () => {
diff --git a/docs/agent-guide/calls.md b/docs/agent-guide/calls.md
index 97f13c7948..9ffb418670 100644
--- a/docs/agent-guide/calls.md
+++ b/docs/agent-guide/calls.md
@@ -466,7 +466,8 @@ remains usable; Answer opens the call screen directly for microphone permission
and retry errors. Verify allowed/denied full-screen access, missing microphone
permission, cancellation/expiry and stale notification actions after a replacement
call arrives. While Android 14+ blocks full-screen notifications, a toast
-offers **Allow** (system setting) or **Hide**. PiP is a native, device-dependent
+offers **Allow** (system setting) or **Dismiss**; returning to Macro with access
+granted removes it. PiP is a native, device-dependent
flow. Browser-only tests cannot validate Telecom, FCM wakeup or background media;
follow the hardware matrix in [Android development](../development/android.md#native-calling).
diff --git a/docs/development/android.md b/docs/development/android.md
index a6ca9ca548..493d2aef2d 100644
--- a/docs/development/android.md
+++ b/docs/development/android.md
@@ -1000,7 +1000,9 @@ as core functionality;
check with `adb shell appops get <package> USE_FULL_SCREEN_INTENT`. Once
notifications are on, Macro shows a toast while the setting is off; **Allow**
opens Android's per-app setting, and the toast stays until returning to Macro
-finds access granted; **Hide** stops the prompt on that device. The
+finds access granted; **Dismiss** stops the prompt on that device. The return
+check runs when the page becomes visible again: the Android WebView fires no
+window `focus` when the app comes back from Settings. The
call notification is public, so the lock screen shows the call and its actions.
Test both permission states. Microphone access is required to join;
camera access is requested when enabling video, and Bluetooth access when selecting