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

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

refactor(bin): include nullable in pm install options

parent 0185333b
Loading
Loading
Loading
Loading
+9 −7
Original line number Original line Diff line number Diff line
@@ -108,7 +108,9 @@ export const PackageManagerInstallOptions = {
} as const;
} as const;


export type PackageManagerInstallOptions = {
export type PackageManagerInstallOptions = {
    [K in keyof typeof PackageManagerInstallOptions]: (typeof PackageManagerInstallOptions)[K]["type"];
    [K in keyof typeof PackageManagerInstallOptions]?:
        | (typeof PackageManagerInstallOptions)[K]["type"]
        | undefined;
};
};


export interface PackageManagerListPackagesOptions {
export interface PackageManagerListPackagesOptions {
@@ -187,7 +189,7 @@ const PACKAGE_MANAGER_RESOLVE_ACTIVITY_OPTIONS_MAP: Partial<


function buildInstallArguments(
function buildInstallArguments(
    command: string,
    command: string,
    options: Optional<PackageManagerInstallOptions> | undefined,
    options: PackageManagerInstallOptions | undefined,
    apiLevel: number | undefined,
    apiLevel: number | undefined,
): string[] {
): string[] {
    const args = [PackageManager.ServiceName, command];
    const args = [PackageManager.ServiceName, command];
@@ -283,7 +285,7 @@ export class PackageManager extends AdbServiceBase {
     */
     */
    async install(
    async install(
        apks: readonly string[],
        apks: readonly string[],
        options?: Optional<PackageManagerInstallOptions>,
        options?: PackageManagerInstallOptions,
    ): Promise<void> {
    ): Promise<void> {
        const args = buildInstallArguments("install", options, this.#apiLevel);
        const args = buildInstallArguments("install", options, this.#apiLevel);
        args[0] = PackageManager.CommandName;
        args[0] = PackageManager.CommandName;
@@ -312,7 +314,7 @@ export class PackageManager extends AdbServiceBase {


    async pushAndInstallStream(
    async pushAndInstallStream(
        stream: ReadableStream<MaybeConsumable<Uint8Array>>,
        stream: ReadableStream<MaybeConsumable<Uint8Array>>,
        options?: Optional<PackageManagerInstallOptions>,
        options?: PackageManagerInstallOptions,
    ): Promise<void> {
    ): Promise<void> {
        const fileName = Math.random().toString().substring(2);
        const fileName = Math.random().toString().substring(2);
        const filePath = `/data/local/tmp/${fileName}.apk`;
        const filePath = `/data/local/tmp/${fileName}.apk`;
@@ -338,7 +340,7 @@ export class PackageManager extends AdbServiceBase {
    async installStream(
    async installStream(
        size: number,
        size: number,
        stream: ReadableStream<MaybeConsumable<Uint8Array>>,
        stream: ReadableStream<MaybeConsumable<Uint8Array>>,
        options?: Optional<PackageManagerInstallOptions>,
        options?: PackageManagerInstallOptions,
    ): Promise<void> {
    ): Promise<void> {
        // Technically `cmd` support and streaming install support are unrelated,
        // Technically `cmd` support and streaming install support are unrelated,
        // but it's impossible to detect streaming install support without actually trying it.
        // but it's impossible to detect streaming install support without actually trying it.
@@ -563,7 +565,7 @@ export class PackageManager extends AdbServiceBase {
     * @returns ID of the new install session
     * @returns ID of the new install session
     */
     */
    async sessionCreate(
    async sessionCreate(
        options?: Optional<PackageManagerInstallOptions>,
        options?: PackageManagerInstallOptions,
    ): Promise<number> {
    ): Promise<number> {
        const args = buildInstallArguments(
        const args = buildInstallArguments(
            "install-create",
            "install-create",
@@ -679,7 +681,7 @@ export class PackageManager extends AdbServiceBase {
export class PackageManagerInstallSession {
export class PackageManagerInstallSession {
    static async create(
    static async create(
        packageManager: PackageManager,
        packageManager: PackageManager,
        options?: Optional<PackageManagerInstallOptions>,
        options?: PackageManagerInstallOptions,
    ): Promise<PackageManagerInstallSession> {
    ): Promise<PackageManagerInstallSession> {
        const id = await packageManager.sessionCreate(options);
        const id = await packageManager.sessionCreate(options);
        return new PackageManagerInstallSession(packageManager, id);
        return new PackageManagerInstallSession(packageManager, id);