package com.pichillilorenzo.flutter_inappwebview_android.print_job;

import android.print.PrintJob;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.pichillilorenzo.flutter_inappwebview_android.InAppWebViewFlutterPlugin;
import com.pichillilorenzo.flutter_inappwebview_android.types.Disposable;
import com.pichillilorenzo.flutter_inappwebview_android.types.PrintJobInfoExt;
import defpackage.e;
import ed.u;

/* JADX INFO: loaded from: classes.dex */
@RequiresApi(api = 19)
public class PrintJobController implements Disposable {
    protected static final String LOG_TAG = "PrintJob";
    public static final String METHOD_CHANNEL_NAME_PREFIX = "com.pichillilorenzo/flutter_inappwebview_printjobcontroller_";

    @Nullable
    public PrintJobChannelDelegate channelDelegate;

    /* JADX INFO: renamed from: id, reason: collision with root package name */
    @NonNull
    public String f24814id;

    @Nullable
    public PrintJob job;

    @Nullable
    public InAppWebViewFlutterPlugin plugin;

    @Nullable
    public PrintJobSettings settings;

    public PrintJobController(@NonNull String str, @NonNull PrintJob printJob, @Nullable PrintJobSettings printJobSettings, @NonNull InAppWebViewFlutterPlugin inAppWebViewFlutterPlugin) {
        this.f24814id = str;
        this.plugin = inAppWebViewFlutterPlugin;
        this.job = printJob;
        this.settings = printJobSettings;
        this.channelDelegate = new PrintJobChannelDelegate(this, new u(inAppWebViewFlutterPlugin.messenger, e.i(METHOD_CHANNEL_NAME_PREFIX, str)));
    }

    public void cancel() {
        PrintJob printJob = this.job;
        if (printJob != null) {
            printJob.cancel();
        }
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.Disposable
    public void dispose() {
        PrintJobManager printJobManager;
        PrintJobChannelDelegate printJobChannelDelegate = this.channelDelegate;
        if (printJobChannelDelegate != null) {
            printJobChannelDelegate.dispose();
            this.channelDelegate = null;
        }
        InAppWebViewFlutterPlugin inAppWebViewFlutterPlugin = this.plugin;
        if (inAppWebViewFlutterPlugin != null && (printJobManager = inAppWebViewFlutterPlugin.printJobManager) != null && printJobManager.jobs.containsKey(this.f24814id)) {
            printJobManager.jobs.put(this.f24814id, null);
        }
        PrintJob printJob = this.job;
        if (printJob != null) {
            printJob.cancel();
            this.job = null;
        }
        this.plugin = null;
    }

    public void disposeNoCancel() {
        PrintJobManager printJobManager;
        PrintJobChannelDelegate printJobChannelDelegate = this.channelDelegate;
        if (printJobChannelDelegate != null) {
            printJobChannelDelegate.dispose();
            this.channelDelegate = null;
        }
        InAppWebViewFlutterPlugin inAppWebViewFlutterPlugin = this.plugin;
        if (inAppWebViewFlutterPlugin != null && (printJobManager = inAppWebViewFlutterPlugin.printJobManager) != null && printJobManager.jobs.containsKey(this.f24814id)) {
            printJobManager.jobs.put(this.f24814id, null);
        }
        if (this.job != null) {
            this.job = null;
        }
        this.plugin = null;
    }

    @Nullable
    public PrintJobInfoExt getInfo() {
        PrintJob printJob = this.job;
        if (printJob != null) {
            return PrintJobInfoExt.fromPrintJobInfo(printJob.getInfo());
        }
        return null;
    }

    public void restart() {
        PrintJob printJob = this.job;
        if (printJob != null) {
            printJob.restart();
        }
    }
}
