package com.unity3d.services.core.webview.bridge; import com.unity3d.services.core.log.DeviceLog; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; /* loaded from: classes2.dex */ public class Invocation { private static AtomicInteger _idCount = new AtomicInteger(0); private static Map _invocationSets; private IInvocationCallbackInvoker _invocationCallbackInvoker; private int _invocationId; private ArrayList> _invocations; private ArrayList> _responses; public Invocation() { this(SharedInstances.INSTANCE.getWebViewAppInvocationCallbackInvoker()); } public static synchronized Invocation getInvocationById(int i10) { synchronized (Invocation.class) { Map map = _invocationSets; if (map == null || !map.containsKey(Integer.valueOf(i10))) { return null; } return _invocationSets.get(Integer.valueOf(i10)); } } public void addInvocation(String str, String str2, Object[] objArr, WebViewCallback webViewCallback) { if (this._invocations == null) { this._invocations = new ArrayList<>(); } ArrayList arrayList = new ArrayList<>(); arrayList.add(str); arrayList.add(str2); arrayList.add(objArr); arrayList.add(webViewCallback); this._invocations.add(arrayList); } public int getId() { return this._invocationId; } public ArrayList> getResponses() { return this._responses; } public boolean nextInvocation() { ArrayList> arrayList = this._invocations; if (arrayList == null || arrayList.size() <= 0) { return false; } ArrayList remove = this._invocations.remove(0); String str = (String) remove.get(0); String str2 = (String) remove.get(1); Object[] objArr = (Object[]) remove.get(2); try { WebViewBridge.handleInvocation(str, str2, objArr, (WebViewCallback) remove.get(3)); } catch (Exception e10) { DeviceLog.exception(String.format("Error handling invocation %s.%s(%s)", str, str2, Arrays.toString(objArr)), e10); } return true; } public void sendInvocationCallback() { _invocationSets.remove(Integer.valueOf(getId())); this._invocationCallbackInvoker.invokeCallback(this); } public void setInvocationResponse(CallbackStatus callbackStatus, Enum r32, Object... objArr) { if (this._responses == null) { this._responses = new ArrayList<>(); } ArrayList arrayList = new ArrayList<>(); arrayList.add(callbackStatus); arrayList.add(r32); arrayList.add(objArr); this._responses.add(arrayList); } public Invocation(IInvocationCallbackInvoker iInvocationCallbackInvoker) { this._invocationCallbackInvoker = iInvocationCallbackInvoker; this._invocationId = _idCount.getAndIncrement(); if (_invocationSets == null) { _invocationSets = new HashMap(); } _invocationSets.put(Integer.valueOf(this._invocationId), this); } }