package com.pichillilorenzo.flutter_inappwebview_android.tracing;

import androidx.annotation.Nullable;
import com.pichillilorenzo.flutter_inappwebview_android.InAppWebViewFlutterPlugin;
import com.pichillilorenzo.flutter_inappwebview_android.types.Disposable;
import ed.u;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import l2.h;
import z3.c0;
import z3.m;
import z3.n;
import z3.o;

/* JADX INFO: loaded from: classes.dex */
public class TracingControllerManager implements Disposable {
    protected static final String LOG_TAG = "TracingControllerMan";
    public static final String METHOD_CHANNEL_NAME = "com.pichillilorenzo/flutter_inappwebview_tracingcontroller";

    @Nullable
    public static o tracingController;

    @Nullable
    public TracingControllerChannelDelegate channelDelegate;

    @Nullable
    public InAppWebViewFlutterPlugin plugin;

    public TracingControllerManager(InAppWebViewFlutterPlugin inAppWebViewFlutterPlugin) {
        this.plugin = inAppWebViewFlutterPlugin;
        this.channelDelegate = new TracingControllerChannelDelegate(this, new u(inAppWebViewFlutterPlugin.messenger, METHOD_CHANNEL_NAME));
    }

    public static m buildTracingConfig(TracingSettings tracingSettings) {
        Object obj;
        h hVar = new h();
        Iterator<Object> it = tracingSettings.categories.iterator();
        while (true) {
            boolean zHasNext = it.hasNext();
            obj = hVar.f29998d;
            if (!zHasNext) {
                break;
            }
            Object next = it.next();
            if (next instanceof String) {
                ((List) obj).addAll(Arrays.asList((String) next));
            }
            if (next instanceof Integer) {
                hVar.f29996b = new int[]{((Integer) next).intValue()}[0] | hVar.f29996b;
            }
        }
        Integer num = tracingSettings.tracingMode;
        if (num != null) {
            hVar.f29997c = num.intValue();
        }
        return new m(hVar.f29996b, hVar.f29997c, (List) obj);
    }

    public static void init() {
        if (tracingController == null && c0.a("TRACING_CONTROLLER_BASIC_USAGE")) {
            tracingController = n.f37044a;
        }
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.Disposable
    public void dispose() {
        TracingControllerChannelDelegate tracingControllerChannelDelegate = this.channelDelegate;
        if (tracingControllerChannelDelegate != null) {
            tracingControllerChannelDelegate.dispose();
            this.channelDelegate = null;
        }
        this.plugin = null;
    }
}
