Skip to content

Commit 799f229

Browse files
fix(mobile): live activity toggle no longer re-links saved environments
Turning Live Activity updates (Android ongoing activity) on or off re-linked every saved environment through the host's link-proof endpoint, which only accepts loopback hosts. A real phone reaches the host over LAN, Tailscale or the tunnel, so the toggle always failed with "Invalid managed endpoint origin." The relay already gates Live Activity delivery on each device's registration preference, and desktop, web and CLI links enable activities at the link level. The toggle now only updates this device's registration preference. The unused mobile environment-link module and its Clerk token plumbing are gone. Android registrations restore the stored native activity configuration when the permission lookup, preference update, or relay write fails, unless a newer registration has configured the device since. Fixes #27412 Rebased from #27432 onto current main.
1 parent 71c2d3a commit 799f229

8 files changed

Lines changed: 163 additions & 856 deletions

‎apps/mobile/src/features/agent-awareness/liveActivityPreferences.test.ts‎

Lines changed: 0 additions & 161 deletions
This file was deleted.

‎apps/mobile/src/features/agent-awareness/liveActivityPreferences.ts‎

Lines changed: 0 additions & 80 deletions
This file was deleted.

‎apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,128 @@ describe("makeRelayDeviceRegistrationRequest", () => {
665665
);
666666
},
667667
);
668+
it.effect("keeps Android activity off when the relay rejects turning it on", () => {
669+
vi.spyOn(Platform, "OS", "get").mockReturnValue("android");
670+
vi.spyOn(Platform, "Version", "get").mockReturnValue(36);
671+
vi.mocked(Notifications.getDevicePushTokenAsync).mockResolvedValue({
672+
type: "android",
673+
data: "fcm-token",
674+
});
675+
vi.stubGlobal("fetch", async (input: RequestInfo | URL, init?: RequestInit) => {
676+
const request = new Request(input, init);
677+
if (request.url.endsWith("/v1/client/dpop-token")) {
678+
return Response.json({
679+
access_token: "dpop",
680+
issued_token_type: "urn:ietf:params:oauth:token-type:access_token",
681+
token_type: "DPoP",
682+
expires_in: 300,
683+
scope: "mobile:registration",
684+
});
685+
}
686+
return new Response("Service unavailable", { status: 503 });
687+
});
688+
Constants.expoConfig!.extra = { relay: { url: "https://relay.example.test" } };
689+
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk"), "user-a");
690+
691+
return Effect.gen(function* () {
692+
const exit = yield* Effect.exit(
693+
updateAgentAwarenessRegistrationPreferences({ liveActivitiesEnabled: true }),
694+
);
695+
696+
expect(Exit.isFailure(exit)).toBe(true);
697+
expect(vi.mocked(configureAndroidAgentNotifications).mock.lastCall).toEqual([
698+
expect.any(String),
699+
"user-a",
700+
false,
701+
]);
702+
}).pipe(
703+
Effect.provideService(FetchHttpClient.Fetch, globalThis.fetch),
704+
Effect.provide(layerRelayTest),
705+
);
706+
});
707+
708+
it.effect("keeps Android activity off when reading notification permission fails", () => {
709+
vi.spyOn(Platform, "OS", "get").mockReturnValue("android");
710+
vi.spyOn(Platform, "Version", "get").mockReturnValue(36);
711+
vi.mocked(Notifications.getPermissionsAsync).mockRejectedValueOnce(
712+
new Error("permission lookup failed"),
713+
);
714+
Constants.expoConfig!.extra = { relay: { url: "https://relay.example.test" } };
715+
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk"), "user-a");
716+
717+
return Effect.gen(function* () {
718+
const exit = yield* Effect.exit(
719+
updateAgentAwarenessRegistrationPreferences({ liveActivitiesEnabled: true }),
720+
);
721+
722+
expect(Exit.isFailure(exit)).toBe(true);
723+
expect(vi.mocked(configureAndroidAgentNotifications).mock.lastCall).toEqual([
724+
expect.any(String),
725+
"user-a",
726+
false,
727+
]);
728+
}).pipe(Effect.provide(layerRelayTest));
729+
});
730+
731+
it.effect("keeps a newer Android activity toggle when an older registration fails", () => {
732+
vi.spyOn(Platform, "OS", "get").mockReturnValue("android");
733+
vi.spyOn(Platform, "Version", "get").mockReturnValue(36);
734+
vi.mocked(Notifications.getDevicePushTokenAsync).mockResolvedValue({
735+
type: "android",
736+
data: "fcm-token",
737+
});
738+
let olderRequestArrived!: () => void;
739+
const olderArrived = new Promise<void>((resolve) => {
740+
olderRequestArrived = resolve;
741+
});
742+
let failOlderRequest!: () => void;
743+
const olderFails = new Promise<void>((resolve) => {
744+
failOlderRequest = resolve;
745+
});
746+
let deviceRequests = 0;
747+
vi.stubGlobal("fetch", async (input: RequestInfo | URL, init?: RequestInit) => {
748+
const request = new Request(input, init);
749+
if (request.url.endsWith("/v1/client/dpop-token")) {
750+
return Response.json({
751+
access_token: "dpop",
752+
issued_token_type: "urn:ietf:params:oauth:token-type:access_token",
753+
token_type: "DPoP",
754+
expires_in: 300,
755+
scope: "mobile:registration",
756+
});
757+
}
758+
deviceRequests += 1;
759+
if (deviceRequests === 1) {
760+
olderRequestArrived();
761+
await olderFails;
762+
return new Response("Service unavailable", { status: 503 });
763+
}
764+
return Response.json({ ok: true });
765+
});
766+
Constants.expoConfig!.extra = { relay: { url: "https://relay.example.test" } };
767+
setAgentAwarenessRelayTokenProvider(() => Promise.resolve("clerk"), "user-a");
768+
769+
return Effect.gen(function* () {
770+
const older = yield* Effect.forkChild(
771+
Effect.exit(updateAgentAwarenessRegistrationPreferences({})),
772+
);
773+
yield* Effect.promise(() => olderArrived);
774+
775+
yield* updateAgentAwarenessRegistrationPreferences({ liveActivitiesEnabled: true });
776+
failOlderRequest();
777+
expect(Exit.isFailure(yield* Fiber.join(older))).toBe(true);
778+
779+
expect(vi.mocked(configureAndroidAgentNotifications).mock.lastCall).toEqual([
780+
expect.any(String),
781+
"user-a",
782+
true,
783+
]);
784+
}).pipe(
785+
Effect.provideService(FetchHttpClient.Fetch, globalThis.fetch),
786+
Effect.provide(layerRelayTest),
787+
);
788+
});
789+
668790
it.effect("preserves relay rejection errors with React Native response headers", () => {
669791
vi.spyOn(Platform, "OS", "get").mockReturnValue("android");
670792
vi.mocked(Notifications.getDevicePushTokenAsync).mockResolvedValue({

0 commit comments

Comments
 (0)