The best way to control Claude Code, Codex and more from any computer or phone
fix(device): report failed Android permission changes (#22358)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 29, 2026 at 12:53 UTC
1b3e330c98f8f063911b730b1befb77c13c7d791
2 files changed
+62
-3
apps/server/src/device/DeviceActions.test.ts
+54
@@ -98,6 +98,60 @@ describe("runDeviceAction", () => {
98
expect(calls.at(-1)?.args.at(-1)).toBe(expected);
99
}),
100
);
101
+
102
+ it.effect.each([
103
+ ["camera", "grant", "android.permission.CAMERA"],
104
+ ["photos", "revoke", "android.permission.READ_MEDIA_IMAGES"],
105
+ ] as const)(
106
+ "reports an Android %s %s that no pm command applied",
107
+ ([permission, decision, firstPermission]) =>
108
+ Effect.gen(function* () {
109
+ const { ready } = makeReady((call) => ({
110
+ code: 1,
111
+ stderr: `Unknown package: ${call.args.at(-1)}`,
112
+ }));
113
+ const error = yield* Effect.flip(
114
+ runDeviceAction(ready, "android", {
115
+ type: "setPermission",
116
+ deviceId: "emulator-5554",
117
+ appId: "com.example.missing",
118
+ permission,
119
+ decision,
120
+ }),
121
+ );
122
+ expect(error._tag).toBe("DeviceOperationError");
123
+ expect(error.operation).toBe("permission");
124
+ expect(error._tag === "DeviceOperationError" && error.cause).toMatchObject({
125
+ stderr: `Unknown package: ${firstPermission}`,
126
+ });
127
+ }),
128
+ );
129
+
130
+ it.effect.each([
131
+ [
132
+ "photos",
133
+ ["android.permission.READ_MEDIA_IMAGES", "android.permission.READ_EXTERNAL_STORAGE"],
134
+ 1,
135
+ ],
136
+ ["contacts", ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"], 0],
137
+ ] as const)(
138
+ "keeps a partially applied %s permission change",
139
+ ([permission, permissions, success]) =>
140
+ Effect.gen(function* () {
141
+ const { ready, calls } = makeReady((call) => ({
142
+ code: call.args.at(-1) === permissions[success] ? 0 : 1,
143
+ }));
144
+ const result = yield* runDeviceAction(ready, "android", {
145
+ type: "setPermission",
146
+ deviceId: "emulator-5554",
147
+ appId: "com.example.app",
148
+ permission,
149
+ decision: "grant",
150
+ });
151
+ expect(result).toBeUndefined();
152
+ expect(calls.map((call) => call.args.at(-1))).toEqual(permissions);
153
+ }),
154
+ );
155
});
156
157
describe("readDeviceDetail", () => {
apps/server/src/device/DeviceActions.ts
+8
-3
@@ -11,6 +11,7 @@ import {
11
type DeviceTextSize,
12
} from "@t3tools/contracts";
13
import * as Effect from "effect/Effect";
14
+import * as Result from "effect/Result";
15
import * as Schema from "effect/Schema";
16
17
import type { DeviceHostReady } from "./DeviceHost.ts";
@@ -432,9 +433,13 @@ const runAndroid = Effect.fn("DeviceActions.runAndroid")(function* (
433
});
434
}
435
const verb = input.decision === "grant" ? "grant" : "revoke";
435
- for (const permission of permissions) {
436
- yield* shell(["pm", verb, input.appId, permission], "permission").pipe(Effect.ignore);
437
- }
436
+ // `pm` rejects a permission the app or system image does not declare, and Photos lists both
437
+ // the Android 13 and the older storage permission, so fail only when none of them applied.
438
+ const results = yield* Effect.forEach(permissions, (permission) =>
439
+ shell(["pm", verb, input.appId, permission], "permission").pipe(Effect.result),
440
+ );
441
+ const failure = results.find(Result.isFailure);
442
+ if (failure && !results.some(Result.isSuccess)) return yield* failure.failure;
443
return;
444
}
445
case "openUrl":