Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit a5d0417e authored by Simon Chan's avatar Simon Chan
Browse files

feat(adb): let subprocess API escape each argument

parent f3f5be0b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ import {
    AdbSubprocessService,
    AdbSync,
    AdbTcpIpService,
    escapeArg,
    framebuffer,
} from "./commands/index.js";
import type { AdbFeature } from "./features.js";
@@ -147,11 +146,11 @@ export class Adb implements Closeable {
        if (Array.isArray(filenames)) {
            for (const filename of filenames) {
                // https://github.com/microsoft/typescript/issues/17002
                args.push(escapeArg(filename as string));
                args.push(filename as string);
            }
        } else {
            // https://github.com/microsoft/typescript/issues/17002
            args.push(escapeArg(filenames as string));
            args.push(filenames as string);
        }
        // https://android.googlesource.com/platform/packages/modules/adb/+/1a0fb8846d4e6b671c8aa7f137a8c21d7b248716/client/adb_install.cpp#984
        args.push("</dev/null");
+2 −1
Original line number Diff line number Diff line
import type { Adb } from "../../../adb.js";
import { escapeArg } from "../utils.js";

import { AdbNoneProtocolProcessImpl } from "./process.js";
import { AdbNoneProtocolPtyProcess } from "./pty.js";
@@ -18,7 +19,7 @@ export class AdbNoneProtocolSubprocessService {
        // `shell,raw:${command}` also triggers raw mode,
        // But is not supported on Android version <7.
        const socket = await this.#adb.createSocket(
            `exec:${command.join(" ")}`,
            `exec:${command.map(escapeArg).join(" ")}`,
        );

        if (signal?.aborted) {
+2 −1
Original line number Diff line number Diff line
import type { Adb } from "../../../adb.js";
import { AdbFeature } from "../../../features.js";
import { escapeArg } from "../utils.js";

import { AdbShellProtocolProcessImpl } from "./process.js";
import { AdbShellProtocolPtyProcess } from "./pty.js";
@@ -21,7 +22,7 @@ export class AdbShellProtocolSubprocessService {

    spawn = adbShellProtocolSpawner(async (command, signal) => {
        const socket = await this.#adb.createSocket(
            `shell,v2,raw:${command.join(" ")}`,
            `shell,v2,raw:${command.map(escapeArg).join(" ")}`,
        );

        if (signal?.aborted) {
+1 −2
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ import type { MaybeConsumable, ReadableStream } from "@yume-chan/stream-extra";

import type { Adb, AdbSocket } from "../../adb.js";
import { AdbFeature } from "../../features.js";
import { escapeArg } from "../subprocess/index.js";

import type { AdbSyncEntry } from "./list.js";
import { adbSyncOpenDir } from "./list.js";
@@ -152,7 +151,7 @@ export class AdbSync {
            // Ignore the result.
            // TODO: sync: test push mkdir workaround (need an Android 8 device)
            await this._adb.subprocess.noneProtocol
                .spawn(["mkdir", "-p", escapeArg(dirname(options.filename))])
                .spawn(["mkdir", "-p", dirname(options.filename)])
                .wait();
        }

+5 −3
Original line number Diff line number Diff line
import type { Adb, AdbNoneProtocolProcess } from "@yume-chan/adb";
import { AdbServiceBase, escapeArg } from "@yume-chan/adb";
import { AdbServiceBase } from "@yume-chan/adb";
import { SplitStringStream, TextDecoderStream } from "@yume-chan/stream-extra";

import { Cmd } from "./cmd/index.js";
@@ -43,13 +43,15 @@ export class ActivityManager extends AdbServiceBase {
    ): Promise<void> {
        // `am start` and `am start-activity` are the same,
        // but `am start-activity` was added in Android 8.
        let args = buildArguments(
        const args = buildArguments(
            [ActivityManager.ServiceName, "start", "-W"],
            options,
            START_ACTIVITY_OPTIONS_MAP,
        );

        args = args.concat(options.intent.build().map(escapeArg));
        for (const arg of options.intent.build()) {
            args.push(arg);
        }

        // `cmd activity` doesn't support `start` command on Android 7.
        let process: AdbNoneProtocolProcess;
Loading