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

Unverified Commit 272c0895 authored by Danny Lin's avatar Danny Lin
Browse files

fastboot: Streamline response processing

parent d44342ce
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -232,30 +232,30 @@ export class FastbootDevice {
            text: "",
            dataSize: null,
        };
        let response;
        let respStatus;
        do {
            let respPacket = await this.device.transferIn(0x01, 64);
            response = new TextDecoder().decode(respPacket.data);
            common.logDebug("response: packet", respPacket, "string", response);
            let response = new TextDecoder().decode(respPacket.data);

            if (response.startsWith("OKAY")) {
            respStatus = response.substring(0, 4);
            let respMessage = response.substring(4);
            common.logDebug(`Response: ${respStatus} ${respMessage}`);

            if (respStatus === "OKAY") {
                // OKAY = end of response for this command
                returnData.text += response.substring(4);
            } else if (response.startsWith("INFO")) {
                returnData.text += respMessage;
            } else if (respStatus === "INFO") {
                // INFO = additional info line
                returnData.text += response.substring(4) + "\n";
            } else if (response.startsWith("DATA")) {
                returnData.text += respMessage + "\n";
            } else if (respStatus === "DATA") {
                // DATA = hex string, but it's returned separately for safety
                returnData.dataSize = response.substring(4);
                returnData.dataSize = respMessage;
            } else {
                // Assume FAIL or garbage data
                throw new FastbootError(
                    response.substring(0, 4),
                    response.substring(4)
                );
                throw new FastbootError(respStatus, respMessage);
            }
            // INFO means that more packets are coming
        } while (response.startsWith("INFO"));
        } while (respStatus === "INFO");

        return returnData;
    }