jimu-decompiled/sources/com/ubtrobot/analytics/HttpReport.java
2025-05-13 19:24:51 +02:00

165 lines
6.1 KiB
Java

package com.ubtrobot.analytics;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import com.google.gson.Gson;
import com.ubtrobot.analytics.ReportException;
import com.ubtrobot.analytics.device.DeviceInfo;
import com.ubtrobot.analytics.device.DeviceInfoReporter;
import com.ubtrobot.analytics.device.MobileDeviceInfo;
import com.ubtrobot.analytics.device.RobotDeviceInfo;
import com.ubtrobot.http.rest.URestException;
import com.ubtrobot.okhttp.interceptor.sign.AuthorizationInterceptor;
import com.ubtrobot.okhttp.interceptor.sign.HttpSignInterceptor;
import com.ubtrobot.retrofit.adapter.urest.URestCall;
import com.ubtrobot.retrofit.adapter.urest.URestCallAdapterFactory;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
/* loaded from: classes2.dex */
public class HttpReport implements EventReporter, DeviceInfoReporter {
private final Context a;
private final String b;
private final String c;
private final String d;
private ReportService e;
public interface ReportService {
@GET("configuration/realtime/eventIds")
URestCall<RealtimeEvent> getForthwithEventIdList(@Query("eventCode") String str);
@POST("collected/device")
URestCall<Void> reportDeviceInfo(@Body MobileDeviceInfo mobileDeviceInfo);
@POST("collected/device")
URestCall<Void> reportDeviceInfo(@Body RobotDeviceInfo robotDeviceInfo);
@POST("collected/events")
URestCall<Void> reportEvent(@Body List<Event> list);
}
public HttpReport(Context context, String str, String str2, String str3) {
this.a = context;
this.b = str;
this.c = str2;
if (str3 == null || str3.length() == 0) {
throw new IllegalArgumentException("deviceId is not null.");
}
this.d = str3;
b();
}
private void b() {
this.e = b("https://apis.ubtrobot.com/v1/collect-rest/");
}
private void a() {
this.e = b("https://test79.ubtrobot.com/v1/collect-rest/");
}
private ReportService b(String str) {
Log.i("Analytics", "Url:" + str);
return (ReportService) new Retrofit.Builder().client(new OkHttpClient.Builder().addInterceptor(new HttpSignInterceptor(this.b, this.c, new HttpSignInterceptor.DeviceInfoSource() { // from class: com.ubtrobot.analytics.HttpReport.2
@Override // com.ubtrobot.okhttp.interceptor.sign.HttpSignInterceptor.DeviceInfoSource
public String a(Request request) {
return HttpReport.this.d;
}
})).addInterceptor(new AuthorizationInterceptor(new AuthorizationInterceptor.AuthenticationInfoSource() { // from class: com.ubtrobot.analytics.HttpReport.1
@Override // com.ubtrobot.okhttp.interceptor.sign.AuthorizationInterceptor.AuthenticationInfoSource
public String a(Request request) {
return HttpReport.this.d;
}
@Override // com.ubtrobot.okhttp.interceptor.sign.AuthorizationInterceptor.AuthenticationInfoSource
public String b(Request request) {
return null;
}
})).build()).addConverterFactory(GsonConverterFactory.create(new Gson())).addCallAdapterFactory(URestCallAdapterFactory.create()).baseUrl(str).build().create(ReportService.class);
}
public void a(boolean z) {
if (z) {
Log.i("Analytics", "Change debug environment.");
a();
} else {
Log.i("Analytics", "Change release environment.");
b();
}
}
public RealtimeEvent a(String str) throws ReportException {
try {
return this.e.getForthwithEventIdList(str).a();
} catch (URestException e) {
Log.e("Analytics", "Get forthwith event id list fail.", e);
a(e);
throw null;
} catch (IllegalStateException e2) {
Log.e("Analytics", "Method getRealtimeEventIdList fail.", e2);
return null;
}
}
public void a(List<Event> list) throws ReportException {
try {
Log.i("Analytics", "Start report event:" + list.size());
this.e.reportEvent(list).a();
} catch (URestException e) {
a(e);
throw null;
}
}
private void a(URestException uRestException) throws ReportException {
int code = uRestException.getCode();
if (code == -3) {
throw ReportException.Factory.c(uRestException);
}
if (code == -2) {
if (a(this.a)) {
throw ReportException.Factory.b(uRestException);
}
throw ReportException.Factory.a(uRestException);
}
if (code == -1) {
throw new IllegalStateException("Should add permission(android.permission.INTERNET).", uRestException);
}
if (code != 1001) {
throw ReportException.Factory.a(uRestException);
}
throw ReportException.Factory.d(uRestException);
}
private boolean a(Context context) {
NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo == null) {
return false;
}
return activeNetworkInfo.isConnected();
}
public void a(DeviceInfo deviceInfo) throws ReportException {
try {
if (deviceInfo instanceof MobileDeviceInfo) {
this.e.reportDeviceInfo((MobileDeviceInfo) deviceInfo).a();
} else if (deviceInfo instanceof RobotDeviceInfo) {
this.e.reportDeviceInfo((RobotDeviceInfo) deviceInfo).a();
}
} catch (URestException e) {
a(e);
throw null;
} catch (IncompatibleClassChangeError e2) {
Log.e("Analytics", "Method reportDeviceInfo fail", e2);
}
}
}