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

Unverified Commit 74bb3666 authored by Danny Lin's avatar Danny Lin
Browse files

src: Fix code formatting

parent c281a69f
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ export async function runWithTimedProgress<T>(
    action: string,
    item: string,
    duration: number,
    workPromise: Promise<T>,
    workPromise: Promise<T>
) {
    let startTime = new Date().getTime();
    let stop = false;
@@ -100,7 +100,10 @@ export class TimeoutError extends Error {
    }
}

export function runWithTimeout<T>(promise: Promise<T>, timeout: number): Promise<T> {
export function runWithTimeout<T>(
    promise: Promise<T>,
    timeout: number
): Promise<T> {
    return new Promise((resolve, reject) => {
        // Set up timeout
        let timedOut = false;
+47 −8
Original line number Diff line number Diff line
import * as common from "./common";
import { ZipReader, BlobReader, BlobWriter, TextWriter, Entry, Writer, GetDataOptions, ZipReaderOptions } from "@zip.js/zip.js";
import {
    ZipReader,
    BlobReader,
    BlobWriter,
    TextWriter,
    Entry,
    Writer,
    GetDataOptions,
    ZipReaderOptions,
} from "@zip.js/zip.js";
import { FastbootDevice, FastbootError, ReconnectCallback } from "./fastboot";

/**
@@ -10,7 +19,11 @@ import { FastbootDevice, FastbootError, ReconnectCallback } from "./fastboot";
 * @param {string} item - Item processed by the action, e.g. partition being flashed.
 * @param {number} progress - Progress within the current action between 0 and 1.
 */
export type FactoryProgressCallback = (action: string, item: string, progress: number) => void;
export type FactoryProgressCallback = (
    action: string,
    item: string,
    progress: number
) => void;

// Images needed for fastbootd
const BOOT_CRITICAL_IMAGES = [
@@ -42,11 +55,19 @@ const FASTBOOTD_REBOOT_TIME = 16000; // ms
const USERDATA_ERASE_TIME = 1000; // ms

// Wrapper for Entry#getData() that unwraps ProgressEvent errors
async function zipGetData(entry: Entry, writer: Writer, options?: GetDataOptions | ZipReaderOptions) {
async function zipGetData(
    entry: Entry,
    writer: Writer,
    options?: GetDataOptions | ZipReaderOptions
) {
    try {
        return await entry.getData!(writer, options);
    } catch (e) {
        if (e instanceof ProgressEvent && e.type === "error" && e.target !== null) {
        if (
            e instanceof ProgressEvent &&
            e.type === "error" &&
            e.target !== null
        ) {
            throw (e.target as any).error;
        } else {
            throw e;
@@ -54,7 +75,12 @@ async function zipGetData(entry: Entry, writer: Writer, options?: GetDataOptions
    }
}

async function flashEntryBlob(device: FastbootDevice, entry: Entry, onProgress: FactoryProgressCallback, partition: string) {
async function flashEntryBlob(
    device: FastbootDevice,
    entry: Entry,
    onProgress: FactoryProgressCallback,
    partition: string
) {
    common.logDebug(`Unpacking ${partition}`);
    onProgress("unpack", partition, 0.0);
    let blob = await zipGetData(
@@ -74,7 +100,12 @@ async function flashEntryBlob(device: FastbootDevice, entry: Entry, onProgress:
    });
}

async function tryFlashImages(device: FastbootDevice, entries: Array<Entry>, onProgress: FactoryProgressCallback, imageNames: Array<string>) {
async function tryFlashImages(
    device: FastbootDevice,
    entries: Array<Entry>,
    onProgress: FactoryProgressCallback,
    imageNames: Array<string>
) {
    for (let imageName of imageNames) {
        let pattern = new RegExp(`${imageName}(?:-.+)?\\.img$`);
        let entry = entries.find((entry) => entry.filename.match(pattern));
@@ -140,7 +171,11 @@ async function checkRequirements(device: FastbootDevice, androidInfo: string) {
    }
}

async function tryReboot(device: FastbootDevice, target: string, onReconnect: ReconnectCallback) {
async function tryReboot(
    device: FastbootDevice,
    target: string,
    onReconnect: ReconnectCallback
) {
    try {
        await device.reboot(target, false);
    } catch (e) {
@@ -155,7 +190,11 @@ export async function flashZip(
    blob: Blob,
    wipe: boolean,
    onReconnect: ReconnectCallback,
    onProgress: FactoryProgressCallback = (_action: string, _item: string, _progress: number) => {}
    onProgress: FactoryProgressCallback = (
        _action: string,
        _item: string,
        _progress: number
    ) => {}
) {
    onProgress("load", "package", 0.0);
    let reader = new ZipReader(new BlobReader(blob));
+33 −10
Original line number Diff line number Diff line
import * as Sparse from "./sparse";
import * as common from "./common";
import { FactoryProgressCallback, flashZip as flashFactoryZip } from "./factory";
import {
    FactoryProgressCallback,
    flashZip as flashFactoryZip,
} from "./factory";

const FASTBOOT_USB_CLASS = 0xff;
const FASTBOOT_USB_SUBCLASS = 0x42;
@@ -374,9 +377,9 @@ export class FastbootDevice {
     */
    private async getDownloadSize(): Promise<number> {
        try {
            let resp = (
                await this.getVariable("max-download-size")
            )!.toLowerCase();
            let resp = (await this.getVariable(
                "max-download-size"
            ))!.toLowerCase();
            if (resp) {
                // AOSP fastboot requires hex
                return Math.min(parseInt(resp, 16), MAX_DOWNLOAD_SIZE);
@@ -394,7 +397,10 @@ export class FastbootDevice {
     *
     * @private
     */
    private async sendRawPayload(buffer: ArrayBuffer, onProgress: FlashProgressCallback) {
    private async sendRawPayload(
        buffer: ArrayBuffer,
        onProgress: FlashProgressCallback
    ) {
        let i = 0;
        let remainingBytes = buffer.byteLength;
        while (remainingBytes > 0) {
@@ -431,7 +437,11 @@ export class FastbootDevice {
     * @param {FlashProgressCallback} onProgress - Callback for upload progress updates.
     * @throws {FastbootError}
     */
    async upload(partition: string, buffer: ArrayBuffer, onProgress: FlashProgressCallback = (_progress) => {}) {
    async upload(
        partition: string,
        buffer: ArrayBuffer,
        onProgress: FlashProgressCallback = (_progress) => {}
    ) {
        common.logDebug(
            `Uploading single sparse to ${partition}: ${buffer.byteLength} bytes`
        );
@@ -476,7 +486,11 @@ export class FastbootDevice {
     * @param {boolean} wait - Whether to wait for the device to reconnect.
     * @param {ReconnectCallback} onReconnect - Callback to request device reconnection, if wait is enabled.
     */
    async reboot(target: string = "", wait: boolean = false, onReconnect: ReconnectCallback = () => {}) {
    async reboot(
        target: string = "",
        wait: boolean = false,
        onReconnect: ReconnectCallback = () => {}
    ) {
        if (target.length > 0) {
            await this.runCommand(`reboot-${target}`);
        } else {
@@ -500,7 +514,11 @@ export class FastbootDevice {
     * @param {FlashProgressCallback} onProgress - Callback for flashing progress updates.
     * @throws {FastbootError}
     */
    async flashBlob(partition: string, blob: Blob, onProgress: FlashProgressCallback = (_progress) => {}) {
    async flashBlob(
        partition: string,
        blob: Blob,
        onProgress: FlashProgressCallback = (_progress) => {}
    ) {
        // Use current slot if partition is A/B
        if ((await this.getVariable(`has-slot:${partition}`)) === "yes") {
            partition += "_" + (await this.getVariable("current-slot"));
@@ -577,7 +595,12 @@ export class FastbootDevice {
     * @param {ReconnectCallback} onReconnect - Callback to request device reconnection.
     * @param {FactoryProgressCallback} onProgress - Progress callback for image flashing.
     */
    async flashFactoryZip(blob: Blob, wipe: boolean, onReconnect: ReconnectCallback, onProgress: FactoryProgressCallback = (_progress) => {}) {
    async flashFactoryZip(
        blob: Blob,
        wipe: boolean,
        onReconnect: ReconnectCallback,
        onProgress: FactoryProgressCallback = (_progress) => {}
    ) {
        return await flashFactoryZip(this, blob, wipe, onReconnect, onProgress);
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -23,10 +23,10 @@ export interface SparseSplit {
}

export enum ChunkType {
    Raw = 0xCAC1,
    Fill = 0xCAC2,
    Skip = 0xCAC3,
    Crc32 = 0xCAC4,
    Raw = 0xcac1,
    Fill = 0xcac2,
    Skip = 0xcac3,
    Crc32 = 0xcac4,
}

export interface SparseHeader {
@@ -42,7 +42,7 @@ export interface SparseChunk {
    blocks: number;
    dataBytes: number;
    data: ArrayBuffer | null; // to be populated by consumer
};
}

/**
 * Returns a parsed version of the sparse image file header from the given buffer.