package com.ea.nimble; import com.ea.nimble.Log; import java.util.List; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ class SynergyNetworkConnection implements SynergyNetworkConnectionHandle { private SynergyNetworkConnectionCallback m_completionCallback; private SynergyRequest m_request; private NetworkConnectionHandle m_networkHandle = null; private SynergyResponse m_response = new SynergyResponse(); private SynergyOperationalTelemetryDispatch m_otDispatch = new SynergyOperationalTelemetryDispatch(); private SynergyNetworkConnectionCallback m_headerCallback = null; private SynergyNetworkConnectionCallback m_progressCallback = null; public SynergyNetworkConnection(SynergyRequest synergyRequest, SynergyNetworkConnectionCallback synergyNetworkConnectionCallback) { this.m_request = synergyRequest; this.m_completionCallback = synergyNetworkConnectionCallback; } public void start() { this.m_request.prepare(this); } public void send() { Log.Helper.LOGFUNC(this); try { this.m_request.build(); NetworkConnectionHandle sendRequest = Network.getComponent().sendRequest(this.m_request.httpRequest, new NetworkConnectionCallback() { // from class: com.ea.nimble.SynergyNetworkConnection.1 @Override // com.ea.nimble.NetworkConnectionCallback public void callback(NetworkConnectionHandle networkConnectionHandle) { if (SynergyNetworkConnection.this.m_networkHandle == null) { SynergyNetworkConnection.this.m_networkHandle = networkConnectionHandle; } SynergyNetworkConnection.this.parseDataFromNetworkHandle(); networkConnectionHandle.setHeaderCallback(null); networkConnectionHandle.setProgressCallback(null); networkConnectionHandle.setCompletionCallback(null); if (SynergyNetworkConnection.this.m_completionCallback != null) { SynergyNetworkConnection.this.m_completionCallback.callback(SynergyNetworkConnection.this); } } }, this.m_otDispatch); this.m_networkHandle = sendRequest; this.m_response.httpResponse = sendRequest.getResponse(); updateNetworkHeaderHandler(); updateNetworkProgressHandler(); } catch (Exception e) { errorPriorToSend(e); } } public void errorPriorToSend(Exception exc) { Log.Helper.LOGPUBLICFUNC(this); HttpResponse httpResponse = new HttpResponse(); httpResponse.error = exc; httpResponse.isCompleted = true; this.m_response.httpResponse = httpResponse; SynergyNetworkConnectionCallback synergyNetworkConnectionCallback = this.m_completionCallback; if (synergyNetworkConnectionCallback != null) { synergyNetworkConnectionCallback.callback(this); } } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public ISynergyRequest getRequest() { Log.Helper.LOGPUBLICFUNC(this); return this.m_request; } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public ISynergyResponse getResponse() { Log.Helper.LOGPUBLICFUNC(this); return this.m_response; } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public SynergyNetworkConnectionCallback getHeaderCallback() { Log.Helper.LOGPUBLICFUNC(this); return this.m_headerCallback; } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public void setHeaderCallback(SynergyNetworkConnectionCallback synergyNetworkConnectionCallback) { Log.Helper.LOGPUBLICFUNC(this); this.m_headerCallback = synergyNetworkConnectionCallback; if (this.m_networkHandle != null) { updateNetworkHeaderHandler(); } } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public SynergyNetworkConnectionCallback getProgressCallback() { Log.Helper.LOGPUBLICFUNC(this); return this.m_progressCallback; } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public void setProgressCallback(SynergyNetworkConnectionCallback synergyNetworkConnectionCallback) { Log.Helper.LOGPUBLICFUNC(this); this.m_progressCallback = synergyNetworkConnectionCallback; if (this.m_networkHandle != null) { updateNetworkProgressHandler(); } } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public SynergyNetworkConnectionCallback getCompletionCallback() { Log.Helper.LOGPUBLICFUNC(this); return this.m_completionCallback; } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public void setCompletionCallback(SynergyNetworkConnectionCallback synergyNetworkConnectionCallback) { Log.Helper.LOGPUBLICFUNC(this); this.m_completionCallback = synergyNetworkConnectionCallback; } public NetworkConnectionHandle getNetworkConnectionHandle() { Log.Helper.LOGPUBLICFUNC(this); return this.m_networkHandle; } public void setNetworkConnectionHandle(NetworkConnectionHandle networkConnectionHandle) { Log.Helper.LOGPUBLICFUNC(this); this.m_networkHandle = networkConnectionHandle; } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public void waitOn() { Log.Helper.LOGPUBLICFUNC(this); NetworkConnectionHandle networkConnectionHandle = this.m_networkHandle; if (networkConnectionHandle != null) { networkConnectionHandle.waitOn(); } } @Override // com.ea.nimble.SynergyNetworkConnectionHandle public void cancel() { Log.Helper.LOGPUBLICFUNC(this); NetworkConnectionHandle networkConnectionHandle = this.m_networkHandle; if (networkConnectionHandle != null) { networkConnectionHandle.cancel(); } } private void updateNetworkHeaderHandler() { Log.Helper.LOGFUNC(this); if (this.m_headerCallback == null) { this.m_networkHandle.setHeaderCallback(null); } else { this.m_networkHandle.setHeaderCallback(new NetworkConnectionCallback() { // from class: com.ea.nimble.SynergyNetworkConnection.2 @Override // com.ea.nimble.NetworkConnectionCallback public void callback(NetworkConnectionHandle networkConnectionHandle) { SynergyNetworkConnection.this.m_headerCallback.callback(SynergyNetworkConnection.this); } }); } } private void updateNetworkProgressHandler() { Log.Helper.LOGFUNC(this); if (this.m_progressCallback == null) { this.m_networkHandle.setProgressCallback(null); } else { this.m_networkHandle.setProgressCallback(new NetworkConnectionCallback() { // from class: com.ea.nimble.SynergyNetworkConnection.3 @Override // com.ea.nimble.NetworkConnectionCallback public void callback(NetworkConnectionHandle networkConnectionHandle) { SynergyNetworkConnection.this.m_progressCallback.callback(SynergyNetworkConnection.this); } }); } } /* JADX INFO: Access modifiers changed from: private */ public void parseDataFromNetworkHandle() { Log.Helper.LOGFUNC(this); NetworkConnectionHandle networkConnectionHandle = this.m_networkHandle; if (networkConnectionHandle != null) { this.m_response.httpResponse = networkConnectionHandle.getResponse(); this.m_response.parseData(); } } public class SynergyOperationalTelemetryDispatch implements IOperationalTelemetryDispatch { private SynergyOperationalTelemetryDispatch() { } @Override // com.ea.nimble.IOperationalTelemetryDispatch public void logEvent(String str, String str2) { Log.Helper.LOGFUNC(this); if (!BaseCore.getInstance().isActive()) { Log.Helper.LOGV(this, "BaseCore not active for operational telemetry logging.", new Object[0]); return; } try { JSONObject jSONObject = new JSONObject(str2); IOperationalTelemetryDispatch component = OperationalTelemetryDispatch.getComponent(); if (component != null) { SynergyNetworkConnection.this.parseDataFromNetworkHandle(); Map jsonData = SynergyNetworkConnection.this.m_response.getJsonData(); if (jsonData != null && jsonData.containsKey("resultCode")) { try { jSONObject.put("SYNERGY_RESULT_CODE", ((Integer) jsonData.get("resultCode")).intValue()); } catch (JSONException unused) { Log.Helper.LOGE(this, "Failed to add SYNERGY_RESULT_CODE to eventDict.", new Object[0]); } } component.logEvent(str, jSONObject.toString()); } } catch (Exception unused2) { Log.Helper.LOGE(this, "SynergyOperationalTelemetryDispatch.logEvent(): Failed to build JSONObject from payload: " + str2, new Object[0]); } } @Override // com.ea.nimble.IOperationalTelemetryDispatch public List getEvents(String str) { Log.Helper.LOGFUNC(this); if (!BaseCore.getInstance().isActive()) { Log.Helper.LOGV(this, "BaseCore not active for operational telemetry logging.", new Object[0]); return null; } IOperationalTelemetryDispatch component = OperationalTelemetryDispatch.getComponent(); if (component == null) { return null; } return component.getEvents(str); } @Override // com.ea.nimble.IOperationalTelemetryDispatch public void setMaxEventCount(String str, int i) { Log.Helper.LOGFUNC(this); if (!BaseCore.getInstance().isActive()) { Log.Helper.LOGV(this, "BaseCore not active for operational telemetry logging.", new Object[0]); return; } IOperationalTelemetryDispatch component = OperationalTelemetryDispatch.getComponent(); if (component == null) { return; } component.setMaxEventCount(str, i); } @Override // com.ea.nimble.IOperationalTelemetryDispatch public int getMaxEventCount(String str) { Log.Helper.LOGFUNC(this); if (!BaseCore.getInstance().isActive()) { Log.Helper.LOGV(this, "BaseCore not active for operational telemetry logging.", new Object[0]); return -1; } IOperationalTelemetryDispatch component = OperationalTelemetryDispatch.getComponent(); if (component == null) { return -1; } return component.getMaxEventCount(str); } } }