正在查看: CallApp v2.226 应用的 EventPublisher.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: CallApp v2.226 应用的 EventPublisher.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.twilio.voice;
import android.content.Context;
import android.os.Handler;
import androidx.annotation.Nullable;
import com.twilio.voice.Constants;
import com.twilio.voice.Event;
import com.twilio.voice.MetricEvent;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONArray;
import org.json.JSONObject;
class EventPublisher {
private String accessToken;
private Context context;
List<Integer> errorCodeList;
private EventPublisherStatus eventPublisherStatus;
private String homeRegion;
private Map<EventPublisherListener, Handler> listenerMap;
private String publisherName;
private EventPublisherEventListener publisherPublishEventListener;
int result;
String twilioProdSdkEventGatewayURL;
String twilioProdSdkMetricsGatewayURL;
private static final Logger logger = Logger.getLogger(EventPublisher.class);
private static final String TAG = "EventPublisher";
public interface EventPublisherEventListener {
void onEventPublished(Constants.SeverityLevel severityLevel, String str, String str2);
void onMetricEventPublished(MetricEvent metricEvent);
}
public interface EventPublisherListener {
void onError(VoiceException voiceException);
}
public class EventPublisherStatus {
private String explanation;
private volatile boolean invalidatePublishing = false;
private int errorCode = 0;
private String responseMessage = "";
public EventPublisherStatus() {
}
public int getErrorCode() {
return this.errorCode;
}
public String getExplanation() {
return this.explanation;
}
public String getResponseMessage() {
return this.responseMessage;
}
public void invalidatePublishing(boolean z) {
this.invalidatePublishing = z;
}
public boolean isPublishingInvalidated() {
return this.invalidatePublishing;
}
public void setErrorDetails(int i, String str, String str2) {
this.errorCode = i;
this.responseMessage = str;
this.explanation = str2;
}
}
public EventPublisher(String str, String str2) {
this(null, str, str2);
}
public Object lambda$publish$0(String str, String str2) throws Exception {
HttpsURLConnection httpsURLConnection;
?? r2 = 0;
if (this.eventPublisherStatus.isPublishingInvalidated()) {
notifyListeners(this.result, this.eventPublisherStatus.getResponseMessage(), this.eventPublisherStatus.getExplanation());
} else {
Logger logger2 = logger;
logger2.d("Start publishing events to : " + str + "\n" + str2);
try {
try {
httpsURLConnection = VoiceURLConnection.create(this.accessToken, str, VoiceURLConnection.METHOD_TYPE_POST);
try {
httpsURLConnection.setRequestProperty("Content-Encoding", "gzip");
httpsURLConnection.setRequestProperty("Accept-Encoding", "gzip");
GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(httpsURLConnection.getOutputStream());
gZIPOutputStream.write(str2.getBytes());
gZIPOutputStream.close();
this.result = httpsURLConnection.getResponseCode();
String responseMessage = httpsURLConnection.getResponseMessage();
int i = this.result;
if (i == 200) {
logger2.d("Response: " + this.result + " - " + responseMessage);
} else {
if (this.errorCodeList.contains(Integer.valueOf(i))) {
logger2.e(String.format(Locale.getDefault(), "Invalidating further publishing : %d - %s", Integer.valueOf(this.result), responseMessage));
this.eventPublisherStatus.invalidatePublishing(true);
}
char[] cArr = new char[1024];
StringBuilder sb = new StringBuilder();
InputStreamReader inputStreamReader = new InputStreamReader(new GZIPInputStream(httpsURLConnection.getErrorStream()), StandardCharsets.UTF_8);
while (true) {
int read = inputStreamReader.read(cArr);
if (read <= 0) {
break;
}
sb.append(cArr, 0, read);
}
String format = String.format(Locale.getDefault(), "%d-%s-%s", Integer.valueOf(this.result), responseMessage, sb.toString());
logger.d("Response: " + format);
this.eventPublisherStatus.setErrorDetails(this.result, responseMessage, format);
notifyListeners(this.result, responseMessage, format);
}
} catch (Exception e) {
e = e;
logger.e(e.toString());
VoiceURLConnection.release(httpsURLConnection);
return null;
}
} catch (Throwable th) {
th = th;
r2 = str;
VoiceURLConnection.release(r2);
throw th;
}
} catch (Exception e2) {
e = e2;
httpsURLConnection = null;
} catch (Throwable th2) {
th = th2;
VoiceURLConnection.release(r2);
throw th;
}
VoiceURLConnection.release(httpsURLConnection);
}
return null;
}
private void notifyListeners(int i, String str, String str2) {
final int i2;
final String str3;
final String str4;
for (Map.Entry<EventPublisherListener, Handler> entry : this.listenerMap.entrySet()) {
final EventPublisherListener key = entry.getKey();
Handler value = entry.getValue();
if (value != null) {
i2 = i;
str3 = str;
str4 = str2;
value.post(new Runnable() {
@Override
public void run() {
EventPublisherListener eventPublisherListener = key;
if (eventPublisherListener != null) {
eventPublisherListener.onError(new VoiceException(i2, str3, str4) {
});
}
}
});
} else {
i2 = i;
str3 = str;
str4 = str2;
}
i = i2;
str = str3;
str2 = str4;
}
}
private void updateServiceHostUrlsWithHomeRegion(String str) {
this.twilioProdSdkMetricsGatewayURL = com.mobilefuse.sdk.assetsmanager.a.m("https://eventgw.", str, ".twilio.com/v4/EndpointMetrics");
this.twilioProdSdkEventGatewayURL = com.mobilefuse.sdk.assetsmanager.a.m("https://eventgw.", str, ".twilio.com/v4/EndpointEvents");
}
public void addEventPublisherEventListener(EventPublisherEventListener eventPublisherEventListener) {
this.publisherPublishEventListener = eventPublisherEventListener;
}
public void addListener(EventPublisherListener eventPublisherListener) {
this.listenerMap.put(eventPublisherListener, Utils.createHandler());
}
public Event createEvent(Constants.SeverityLevel severityLevel, String str, String str2, JSONObject jSONObject) {
return new Event.Builder().productName(this.publisherName).eventName(str2).groupName(str).level(severityLevel).payLoadType(Constants.APP_JSON_PAYLOAD_TYPE).payLoad(jSONObject).build();
}
public MetricEvent createMetricEvent(String str, String str2, JSONArray jSONArray) {
return new MetricEvent.Builder().productName(this.publisherName).eventName(str2).groupName(str).level(Constants.SeverityLevel.INFO).payLoadType(Constants.APP_JSON_PAYLOAD_TYPE).payLoad(jSONArray).build();
}
public void publish(Constants.SeverityLevel severityLevel, String str, String str2, Event event) throws Exception {
if (this.publisherPublishEventListener != null && !this.eventPublisherStatus.isPublishingInvalidated()) {
this.publisherPublishEventListener.onEventPublished(severityLevel, str, str2);
}
publish(event.toJSONObject(this.context).toString(), this.twilioProdSdkEventGatewayURL);
}
public void publishMetrics(MetricEvent metricEvent) throws Exception {
if (metricEvent != null) {
publish(metricEvent.toJSONObject(this.context).toString(), this.twilioProdSdkMetricsGatewayURL);
EventPublisherEventListener eventPublisherEventListener = this.publisherPublishEventListener;
if (eventPublisherEventListener != null) {
eventPublisherEventListener.onMetricEventPublished(metricEvent);
}
}
}
public void removeListener(EventPublisherListener eventPublisherListener) {
this.listenerMap.remove(eventPublisherListener);
}
public EventPublisher(@Nullable Context context, String str, String str2) {
this.listenerMap = new HashMap();
this.result = 0;
this.eventPublisherStatus = new EventPublisherStatus();
this.errorCodeList = Arrays.asList(403);
if (str2 == null) {
throw new NullPointerException("accessToken must not be null.");
}
if (str == null) {
throw new NullPointerException("publisherName must not be null.");
}
this.context = context;
this.accessToken = str2;
this.publisherName = str;
this.twilioProdSdkMetricsGatewayURL = Constants.getKeyKibanaMetricsHostUrl();
this.twilioProdSdkEventGatewayURL = Constants.getKeyKibanaEventGatewayHostUrl();
try {
this.homeRegion = new AccessTokenParser(str2).getHomeRegion();
} catch (AccessTokenParseException e) {
e.printStackTrace();
}
String str3 = this.homeRegion;
if (str3 != null) {
updateServiceHostUrlsWithHomeRegion(str3);
}
}
private void publish(final String str, final String str2) {
ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
newCachedThreadPool.submit(new Callable() {
@Override
public final Object call() {
Object lambda$publish$0;
lambda$publish$0 = EventPublisher.this.lambda$publish$0(str2, str);
return lambda$publish$0;
}
});
newCachedThreadPool.shutdown();
}
}