Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Phone type_text: send ADBKeyBoard text to ADBKeyBoard only

Xiaolei Shi0058ee92135f
diff --git a/server/drivers/phone-proxy.test.ts b/server/drivers/phone-proxy.test.ts
index 900692037a..71cb6f6884 100644
--- a/server/drivers/phone-proxy.test.ts
+++ b/server/drivers/phone-proxy.test.ts
@@ -35,6 +35,10 @@ emulator-5554 device product:sdk model:Emulator transport_id:6
expect(launchTarget("com.taobao.idlefish", packages)).toBe("com.taobao.idlefish");
});
+ it("keeps naming the candidates when an app name is ambiguous", () => {
+ expect(() => launchTarget("taobao", ["com.taobao.idlefish", "com.taobao.taobao"])).toThrow("App name is ambiguous: com.taobao.idlefish, com.taobao.taobao");
+ });
+
it("offers keys that turn the screen on and off", () => {
const press = TOOLS.find((tool) => tool.name === "press") as { inputSchema: { properties: { key: { enum: string[] } } } } | undefined;
expect(press?.inputSchema.properties.key.enum).toEqual(expect.arrayContaining(["wakeup", "sleep"]));
@@ -70,10 +74,24 @@ describe("phone MCP text input", () => {
await expect(typePhoneText(phone.shell, "二手 iPad +86 😀")).resolves.toBe("Typed text into the focused Android field");
expect(phone.commands).toEqual([
["settings", "get", "secure", "default_input_method"],
- ["am", "broadcast", "-a", "ADB_INPUT_B64", "--es", "msg", "5LqM5omLIGlQYWQgKzg2IPCfmIA="],
+ ["am", "broadcast", "-a", "ADB_INPUT_B64", "-p", "com.android.adbkeyboard", "--es", "msg", "5LqM5omLIGlQYWQgKzg2IPCfmIA="],
]);
});
+ it("types up to 256 characters of other text", async () => {
+ const phone = device(ADB_KEYBOARD);
+ await expect(typePhoneText(phone.shell, "二".repeat(256))).resolves.toBe("Typed text into the focused Android field");
+ expect(phone.commands.map((command) => command[0])).toEqual(["settings", "am"]);
+ });
+
+ it.each(["iPad", "二手"])("reports a failed adb command instead of claiming it typed (%s)", async (text) => {
+ const shell = async (...command: string[]) => {
+ if (command[0] === "settings") return `${ADB_KEYBOARD}\n`;
+ throw new Error("error: closed");
+ };
+ await expect(typePhoneText(shell, text)).rejects.toThrow("error: closed");
+ });
+
it("asks for ADBKeyBoard and types nothing when another keyboard is chosen", async () => {
const phone = device(VENDOR_KEYBOARD);
await expect(typePhoneText(phone.shell, "二手 iPad")).rejects.toThrow("ADBKeyBoard (https://github.com/senzhk/ADBKeyBoard) is installed and chosen as the phone's keyboard");
diff --git a/server/drivers/phone-proxy.ts b/server/drivers/phone-proxy.ts
index 821c23607a..a1c04891c3 100644
--- a/server/drivers/phone-proxy.ts
+++ b/server/drivers/phone-proxy.ts
@@ -153,7 +153,8 @@ export async function typePhoneText(shell: Shell, text: string): Promise<string>
throw new Error("Only letters, digits, spaces and _.,@- can be typed until ADBKeyBoard (https://github.com/senzhk/ADBKeyBoard) is installed and chosen as the phone's keyboard. Ask the person to set it up, or type only those characters.");
}
// ADBKeyBoard reads msg as Base64 UTF-8; Base64 also keeps the text out of the device shell's syntax.
- await shell("am", "broadcast", "-a", "ADB_INPUT_B64", "--es", "msg", Buffer.from(text, "utf8").toString("base64"));
+ // -p delivers it to ADBKeyBoard alone, not to any other app listening for the action.
+ await shell("am", "broadcast", "-a", "ADB_INPUT_B64", "-p", "com.android.adbkeyboard", "--es", "msg", Buffer.from(text, "utf8").toString("base64"));
}
return "Typed text into the focused Android field";
}