package com.unity3d.ads.webview.bridge; import com.unity3d.ads.log.DeviceLog; import com.unity3d.ads.webview.WebViewApp; import java.util.ArrayList; 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 int _invocationId = _idCount.getAndIncrement(); private ArrayList> _invocations; private ArrayList> _responses; public Invocation() { if (_invocationSets == null) { _invocationSets = new HashMap(); } _invocationSets.put(Integer.valueOf(this._invocationId), this); } public static synchronized Invocation getInvocationById(int i) { synchronized (Invocation.class) { if (_invocationSets == null || !_invocationSets.containsKey(Integer.valueOf(i))) { return null; } return _invocationSets.get(Integer.valueOf(i)); } } 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); try { WebViewBridge.handleInvocation((String) remove.get(0), (String) remove.get(1), (Object[]) remove.get(2), (WebViewCallback) remove.get(3)); } catch (Exception e) { DeviceLog.exception("Error handling invocation", e); } return true; } public void sendInvocationCallback() { _invocationSets.remove(Integer.valueOf(getId())); WebViewApp.getCurrentApp().invokeCallback(this); } public void setInvocationResponse(CallbackStatus callbackStatus, Enum r3, Object... objArr) { if (this._responses == null) { this._responses = new ArrayList<>(); } ArrayList arrayList = new ArrayList<>(); arrayList.add(callbackStatus); arrayList.add(r3); arrayList.add(objArr); this._responses.add(arrayList); } }