package com.pichillilorenzo.flutter_inappwebview_android.service_worker;

import a4.a0;
import a4.b;
import a4.k0;
import a4.z;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.pichillilorenzo.flutter_inappwebview_android.Util;
import com.pichillilorenzo.flutter_inappwebview_android.types.BaseCallbackResultImpl;
import com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl;
import com.pichillilorenzo.flutter_inappwebview_android.types.SyncBaseCallbackResultImpl;
import com.pichillilorenzo.flutter_inappwebview_android.types.WebResourceRequestExt;
import com.pichillilorenzo.flutter_inappwebview_android.types.WebResourceResponseExt;
import ed.q;
import ed.t;
import ed.u;
import java.util.Map;
import z3.c0;
import z3.k;

/* JADX INFO: loaded from: classes.dex */
@RequiresApi(api = 24)
public class ServiceWorkerChannelDelegate extends ChannelDelegateImpl {

    @Nullable
    private ServiceWorkerManager serviceWorkerManager;

    public static class ShouldInterceptRequestCallback extends BaseCallbackResultImpl<WebResourceResponseExt> {
        @Override // com.pichillilorenzo.flutter_inappwebview_android.types.BaseCallbackResultImpl, com.pichillilorenzo.flutter_inappwebview_android.types.ICallbackResult
        @Nullable
        public WebResourceResponseExt decodeResult(@Nullable Object obj) {
            return WebResourceResponseExt.fromMap((Map) obj);
        }
    }

    public static class SyncShouldInterceptRequestCallback extends SyncBaseCallbackResultImpl<WebResourceResponseExt> {
        @Override // com.pichillilorenzo.flutter_inappwebview_android.types.BaseCallbackResultImpl, com.pichillilorenzo.flutter_inappwebview_android.types.ICallbackResult
        @Nullable
        public WebResourceResponseExt decodeResult(@Nullable Object obj) {
            return new ShouldInterceptRequestCallback().decodeResult(obj);
        }
    }

    public ServiceWorkerChannelDelegate(@NonNull ServiceWorkerManager serviceWorkerManager, @NonNull u uVar) {
        super(uVar);
        this.serviceWorkerManager = serviceWorkerManager;
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.Disposable
    public void dispose() {
        super.dispose();
        this.serviceWorkerManager = null;
    }

    @Override // com.pichillilorenzo.flutter_inappwebview_android.types.ChannelDelegateImpl, com.pichillilorenzo.flutter_inappwebview_android.types.IChannelDelegate, ed.s
    public void onMethodCall(@NonNull q qVar, @NonNull t tVar) {
        a0 a0Var;
        boolean allowContentAccess;
        int cacheMode;
        boolean allowFileAccess;
        boolean blockNetworkLoads;
        ServiceWorkerManager.init();
        k kVar = ServiceWorkerManager.serviceWorkerController;
        a0Var = kVar != null ? ((z) kVar).f373c : null;
        String str = qVar.f25842a;
        str.getClass();
        switch (str) {
            case "getAllowContentAccess":
                if (a0Var == null || !c0.a("SERVICE_WORKER_CONTENT_ACCESS")) {
                    tVar.success(Boolean.FALSE);
                    return;
                }
                b bVar = k0.f327j;
                if (bVar.a()) {
                    allowContentAccess = a0Var.b().getAllowContentAccess();
                } else {
                    if (!bVar.b()) {
                        throw k0.a();
                    }
                    allowContentAccess = a0Var.a().getAllowContentAccess();
                }
                tVar.success(Boolean.valueOf(allowContentAccess));
                return;
            case "setServiceWorkerClient":
                if (this.serviceWorkerManager == null) {
                    tVar.success(Boolean.FALSE);
                    return;
                } else {
                    this.serviceWorkerManager.setServiceWorkerClient((Boolean) qVar.argument("isNull"));
                    tVar.success(Boolean.TRUE);
                    return;
                }
            case "getCacheMode":
                if (a0Var == null || !c0.a("SERVICE_WORKER_CACHE_MODE")) {
                    tVar.success(null);
                    return;
                }
                b bVar2 = k0.f326i;
                if (bVar2.a()) {
                    cacheMode = a0Var.b().getCacheMode();
                } else {
                    if (!bVar2.b()) {
                        throw k0.a();
                    }
                    cacheMode = a0Var.a().getCacheMode();
                }
                tVar.success(Integer.valueOf(cacheMode));
                return;
            case "getAllowFileAccess":
                if (a0Var == null || !c0.a("SERVICE_WORKER_FILE_ACCESS")) {
                    tVar.success(Boolean.FALSE);
                    return;
                }
                b bVar3 = k0.f328k;
                if (bVar3.a()) {
                    allowFileAccess = a0Var.b().getAllowFileAccess();
                } else {
                    if (!bVar3.b()) {
                        throw k0.a();
                    }
                    allowFileAccess = a0Var.a().getAllowFileAccess();
                }
                tVar.success(Boolean.valueOf(allowFileAccess));
                return;
            case "setCacheMode":
                if (a0Var != null && c0.a("SERVICE_WORKER_CACHE_MODE")) {
                    int iIntValue = ((Integer) qVar.argument("mode")).intValue();
                    b bVar4 = k0.f326i;
                    if (bVar4.a()) {
                        a0Var.b().setCacheMode(iIntValue);
                    } else {
                        if (!bVar4.b()) {
                            throw k0.a();
                        }
                        a0Var.a().setCacheMode(iIntValue);
                    }
                }
                tVar.success(Boolean.TRUE);
                return;
            case "setBlockNetworkLoads":
                if (a0Var != null && c0.a("SERVICE_WORKER_BLOCK_NETWORK_LOADS")) {
                    boolean zBooleanValue = ((Boolean) qVar.argument("flag")).booleanValue();
                    b bVar5 = k0.f329l;
                    if (bVar5.a()) {
                        a0Var.b().setBlockNetworkLoads(zBooleanValue);
                    } else {
                        if (!bVar5.b()) {
                            throw k0.a();
                        }
                        a0Var.a().setBlockNetworkLoads(zBooleanValue);
                    }
                }
                tVar.success(Boolean.TRUE);
                return;
            case "setAllowContentAccess":
                if (a0Var != null && c0.a("SERVICE_WORKER_CONTENT_ACCESS")) {
                    boolean zBooleanValue2 = ((Boolean) qVar.argument("allow")).booleanValue();
                    b bVar6 = k0.f327j;
                    if (bVar6.a()) {
                        a0Var.b().setAllowContentAccess(zBooleanValue2);
                    } else {
                        if (!bVar6.b()) {
                            throw k0.a();
                        }
                        a0Var.a().setAllowContentAccess(zBooleanValue2);
                    }
                }
                tVar.success(Boolean.TRUE);
                return;
            case "setAllowFileAccess":
                if (a0Var != null && c0.a("SERVICE_WORKER_FILE_ACCESS")) {
                    boolean zBooleanValue3 = ((Boolean) qVar.argument("allow")).booleanValue();
                    b bVar7 = k0.f328k;
                    if (bVar7.a()) {
                        a0Var.b().setAllowFileAccess(zBooleanValue3);
                    } else {
                        if (!bVar7.b()) {
                            throw k0.a();
                        }
                        a0Var.a().setAllowFileAccess(zBooleanValue3);
                    }
                }
                tVar.success(Boolean.TRUE);
                return;
            case "getBlockNetworkLoads":
                if (a0Var == null || !c0.a("SERVICE_WORKER_BLOCK_NETWORK_LOADS")) {
                    tVar.success(Boolean.FALSE);
                    return;
                }
                b bVar8 = k0.f329l;
                if (bVar8.a()) {
                    blockNetworkLoads = a0Var.b().getBlockNetworkLoads();
                } else {
                    if (!bVar8.b()) {
                        throw k0.a();
                    }
                    blockNetworkLoads = a0Var.a().getBlockNetworkLoads();
                }
                tVar.success(Boolean.valueOf(blockNetworkLoads));
                return;
            default:
                tVar.notImplemented();
                return;
        }
    }

    public void shouldInterceptRequest(WebResourceRequestExt webResourceRequestExt, @NonNull ShouldInterceptRequestCallback shouldInterceptRequestCallback) {
        u channel = getChannel();
        if (channel == null) {
            return;
        }
        channel.invokeMethod("shouldInterceptRequest", webResourceRequestExt.toMap(), shouldInterceptRequestCallback);
    }

    @Nullable
    public WebResourceResponseExt shouldInterceptRequest(WebResourceRequestExt webResourceRequestExt) throws InterruptedException {
        u channel = getChannel();
        if (channel == null) {
            return null;
        }
        return (WebResourceResponseExt) Util.invokeMethodAndWaitResult(channel, "shouldInterceptRequest", webResourceRequestExt.toMap(), new SyncShouldInterceptRequestCallback());
    }
}
