Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
package com.baidu.uaq.agent.android.harvest.multiharvest;
import android.app.Application;
import android.content.Context;
import com.baidu.uaq.agent.android.customtransmission.APMUploadConfigure;
import java.util.ArrayList;
import java.util.Iterator;
/* compiled from: MultiHarvest.java */
/* loaded from: classes.dex */
public class a {
private static final com.baidu.uaq.agent.android.logging.a e = com.baidu.uaq.agent.android.logging.b.a();
private static a f = new a();
private Context a;
private c b;
private final ArrayList<c> c = new ArrayList<>();
private int d = 0;
public static a c() {
return f;
}
private void d() {
if (this.b == null) {
APMUploadConfigure aPMUploadConfigure = new APMUploadConfigure(APMUploadConfigure.APMUPLOADNAME, "", null);
com.baidu.uaq.agent.android.customtransmission.b.a(aPMUploadConfigure);
this.b = new c(this.a, aPMUploadConfigure);
}
}
public synchronized void a(Context context) {
this.a = b(context);
this.d++;
if (this.d == 1) {
d();
this.b.c();
}
e.d("MultiHarvest start one time, instanceNumber now is " + this.d);
}
public synchronized void b() {
this.d--;
if (this.d == 0) {
synchronized (this.c) {
Iterator<c> it = this.c.iterator();
while (it.hasNext()) {
c next = it.next();
next.d();
next.a().a();
next.a().b();
}
this.c.clear();
}
com.baidu.uaq.agent.android.a.h();
com.baidu.uaq.agent.android.customtransmission.b.a().clear();
com.baidu.uaq.agent.android.customtransmission.b.b().clear();
if (this.b != null) {
this.b.d();
this.b.a().a();
this.b.a().b();
this.b = null;
}
}
e.d("MultiHarvest stop one time, instanceNumber now is " + this.d);
}
public void a(APMUploadConfigure aPMUploadConfigure) {
if (com.baidu.uaq.agent.android.customtransmission.b.a().containsKey(aPMUploadConfigure.getUploadName())) {
e.d("addUploadCofigure already exists:" + aPMUploadConfigure.getUploadName() + " size:" + com.baidu.uaq.agent.android.customtransmission.b.a().size());
com.baidu.uaq.agent.android.customtransmission.b.a(aPMUploadConfigure);
return;
}
com.baidu.uaq.agent.android.customtransmission.b.a(aPMUploadConfigure);
e.d("addUploadCofigure:" + aPMUploadConfigure.getUploadName());
f.b(aPMUploadConfigure);
}
public int a() {
return this.d;
}
private void b(APMUploadConfigure aPMUploadConfigure) {
c cVar = new c(this.a, aPMUploadConfigure);
cVar.c();
synchronized (this.c) {
this.c.add(cVar);
}
}
private static Context b(Context context) {
return !(context instanceof Application) ? context.getApplicationContext() : context;
}
}

View File

@@ -0,0 +1,229 @@
package com.baidu.uaq.agent.android.harvest.multiharvest;
import com.baidu.uaq.agent.android.UAQ;
import com.baidu.uaq.agent.android.customtransmission.APMUploadConfigure;
import com.baidu.uaq.agent.android.util.e;
import com.baidu.uaq.agent.android.util.h;
import com.baidu.uaq.agent.android.util.l;
import com.ubt.jimu.unity.bluetooth.UnityActivity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
/* compiled from: MultiHarvestConnection.java */
/* loaded from: classes.dex */
public class b {
private static final com.baidu.uaq.agent.android.logging.a b = com.baidu.uaq.agent.android.logging.b.a();
private static final UAQ c = UAQ.getInstance();
private HttpClient a;
private void a() {
int convert = (int) TimeUnit.MILLISECONDS.convert(20L, TimeUnit.SECONDS);
BasicHttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicHttpParams, convert);
HttpConnectionParams.setSoTimeout(basicHttpParams, convert);
HttpConnectionParams.setTcpNoDelay(basicHttpParams, true);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, UnityActivity.BLOCKLY_TYPE_NONE);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
this.a = new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
}
private HttpPost b(String str, APMUploadConfigure aPMUploadConfigure) {
return a(str, "deflate", aPMUploadConfigure);
}
private String c(String str) {
return (c.getConfig().isUseSsl() ? "https://" : "http://") + c.getConfig().getCollectorHost() + (":" + c.getConfig().getCollectorPort()) + str;
}
private HttpPost b(String str) {
return a(b(), str, "gzip");
}
private String b() {
return c("/sdk_push_stat");
}
public com.baidu.uaq.agent.android.harvest.b a(String str, APMUploadConfigure aPMUploadConfigure) {
if (str != null) {
l.a("MultiHarvest sendData = " + str);
HttpPost b2 = b(str.replace("\\/", "/"), aPMUploadConfigure);
if (b2 != null) {
long contentLength = b2.getEntity().getContentLength();
b.d("HarvestSize = " + contentLength + "bytes");
com.baidu.uaq.agent.android.stats.a.b().b("Supportability/AgentHealth/Collector/HarvestSize", contentLength);
}
return a(b2);
}
throw new IllegalArgumentException();
}
public com.baidu.uaq.agent.android.harvest.b a(String str) {
if (str != null) {
l.a("MultiHarvest sendData = " + str);
HttpPost b2 = b(str.replace("\\/", "/") + "\n");
if (b2 != null) {
long contentLength = b2.getEntity().getContentLength();
b.d("HarvestSize = " + contentLength + "bytes");
com.baidu.uaq.agent.android.stats.a.b().b("Supportability/AgentHealth/Collector/HarvestSize", contentLength);
}
return a(b2);
}
throw new IllegalArgumentException();
}
private HttpPost a(String str, String str2, APMUploadConfigure aPMUploadConfigure) {
String url = aPMUploadConfigure.getUrl();
b.d("MultiHarvest POST <uri> = " + url);
HttpPost httpPost = new HttpPost(url);
HashMap<String, String> headerMap = aPMUploadConfigure.getHeaderMap();
if (headerMap.size() <= 0) {
b.a("Http header is null");
}
for (Map.Entry<String, String> entry : headerMap.entrySet()) {
httpPost.addHeader(entry.getKey(), entry.getValue());
}
if (c.getConfig().getAPIKey() == null) {
b.a("Cannot create POST without an Application Token.");
return null;
}
if ("deflate".equals(str2)) {
httpPost.setEntity(new ByteArrayEntity(com.baidu.uaq.agent.android.util.b.a(str)));
} else {
try {
httpPost.setEntity(new StringEntity(str, "utf-8"));
} catch (UnsupportedEncodingException e) {
b.a("UTF-8 is unsupported");
throw new IllegalArgumentException(e);
}
}
return httpPost;
}
private HttpPost a(String str, String str2, String str3) {
String a;
b.d("MultiHarvest POST <uri> = " + str);
HttpPost httpPost = new HttpPost(str);
httpPost.addHeader("Content-Type", "application/json");
httpPost.addHeader("Content-Encoding", str3);
if (System.getProperty("http.agent") != null) {
httpPost.addHeader("User-Agent", System.getProperty("http.agent").trim());
}
httpPost.addHeader("X-UAQ-WanType", com.baidu.uaq.agent.android.a.c());
try {
String cuid = c.getConfig().getCuid();
if (cuid.equals("null")) {
com.baidu.uaq.agent.android.harvest.bean.c a2 = com.baidu.uaq.agent.android.a.a().a();
if (a2.j()) {
a = a2.l();
} else {
a = e.a(a2.l());
}
httpPost.addHeader("X-UAQ-UUID", a);
} else {
httpPost.addHeader("X-UAQ-UUID", e.a(cuid));
}
httpPost.addHeader("X-UAQ-Channel", e.a(c.getConfig().getChannel()));
} catch (Exception e) {
b.a("Caught error while createPost AES: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
}
if (c.getConfig().getAPIKey() == null) {
b.a("Cannot create POST without an Application Token.");
return null;
}
httpPost.addHeader("X-App-License-Key", c.getConfig().getAPIKey());
if ("deflate".equals(str3)) {
httpPost.setEntity(new ByteArrayEntity(com.baidu.uaq.agent.android.util.b.a(str2)));
} else if ("gzip".equals(str3)) {
httpPost.setEntity(new ByteArrayEntity(com.baidu.uaq.agent.android.util.b.a(str2, "utf-8")));
} else {
try {
httpPost.setEntity(new StringEntity(str2, "utf-8"));
} catch (UnsupportedEncodingException e2) {
b.a("UTF-8 is unsupported");
throw new IllegalArgumentException(e2);
}
}
return httpPost;
}
private com.baidu.uaq.agent.android.harvest.b a(HttpPost httpPost) {
if (httpPost == null) {
b.a("Failed to send POST to collector");
return null;
}
com.baidu.uaq.agent.android.harvest.b bVar = new com.baidu.uaq.agent.android.harvest.b();
try {
com.baidu.uaq.agent.android.stats.b bVar2 = new com.baidu.uaq.agent.android.stats.b();
bVar2.a();
if (this.a == null) {
a();
}
HttpResponse execute = this.a.execute(httpPost);
bVar.a(bVar2.b());
bVar.a(execute.getStatusLine().getStatusCode());
try {
bVar.a(a(execute));
} catch (IOException e) {
b.a("Failed to retrieve collector response: ", e);
}
return bVar;
} catch (Exception e2) {
b.a("Failed to send POST to collector: ", e2);
a(e2);
return null;
}
}
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Type inference failed for: r5v4, types: [java.io.InputStream] */
/* JADX WARN: Type inference failed for: r5v5, types: [java.io.InputStream] */
/* JADX WARN: Type inference failed for: r5v7, types: [java.lang.String] */
private static String a(HttpResponse httpResponse) throws IOException {
char[] cArr = new char[UnityActivity.BLOCKLY_TYPE_NONE];
StringBuilder sb = new StringBuilder();
if (httpResponse == null || httpResponse.getEntity() == null) {
return null;
}
?? content = httpResponse.getEntity().getContent();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(content));
while (true) {
try {
int read = bufferedReader.read(cArr);
if (read < 0) {
content.close();
content = sb.toString();
return content;
}
sb.append(cArr, 0, read);
} catch (Exception unused) {
content.close();
return sb.toString();
}
}
}
private void a(Exception exc) {
com.baidu.uaq.agent.android.stats.a.b().a("Supportability/AgentHealth/Collector/ResponseErrorCodes/" + h.a(exc));
}
}

View File

@@ -0,0 +1,159 @@
package com.baidu.uaq.agent.android.harvest.multiharvest;
import android.content.Context;
import com.baidu.uaq.agent.android.UAQ;
import com.baidu.uaq.agent.android.customtransmission.APMUploadConfigure;
import com.baidu.uaq.agent.android.util.g;
import com.baidu.uaq.agent.android.util.i;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/* compiled from: MultiHarvestTimer.java */
/* loaded from: classes.dex */
public class c implements Runnable {
private static final UAQ i = UAQ.getInstance();
private static final com.baidu.uaq.agent.android.logging.a j = com.baidu.uaq.agent.android.logging.b.a();
private final d a;
private ScheduledExecutorService b = Executors.newSingleThreadScheduledExecutor(new g("HarvestTimer"));
private ScheduledFuture c;
private long d;
private long e;
private Context f;
private String g;
private APMUploadConfigure h;
public c(Context context, APMUploadConfigure aPMUploadConfigure) {
this.f = context;
this.g = aPMUploadConfigure.getUploadName();
this.h = aPMUploadConfigure;
this.a = new d(context, aPMUploadConfigure);
}
private void e() {
long j2 = j();
if (1000 + j2 < this.e && j2 != -1) {
j.d("HarvestTimer: Tick is too soon (" + j2 + " delta) Last tick time: " + this.d + " . Skipping.");
return;
}
j.d("================= Tick Begin for " + this.h.getUploadName() + " =====================");
j.d("HarvestTimer: time since last tick: " + j2);
long m = m();
try {
f();
} catch (Exception e) {
j.a("HarvestTimer: Exception in timer tick: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
}
this.d = m;
j.d("================= Tick End for " + this.h.getUploadName() + " =====================");
}
private void f() {
com.baidu.uaq.agent.android.stats.b bVar = new com.baidu.uaq.agent.android.stats.b();
bVar.a();
try {
this.a.a(this.h);
} catch (Exception e) {
j.a("HarvestTimer: Exception in harvest execute: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
}
long b = bVar.b();
j.d("HarvestTimer tick took " + b + "ms");
}
private long j() {
if (this.d == 0) {
return -1L;
}
return m() - this.d;
}
private void k() {
if (this.h == null) {
this.e = -1L;
return;
}
if (!i.d(this.f)) {
if (i.c(this.f)) {
this.e = this.h.getInterval4g();
return;
} else {
this.e = i.getConfig().getDataReportPeriod();
return;
}
}
j.d("getPeriod for name:" + this.h.getUploadName());
this.e = this.h.getIntervalWifi();
}
private void l() {
if (com.baidu.uaq.agent.android.customtransmission.b.a() != null) {
this.h = com.baidu.uaq.agent.android.customtransmission.b.a().get(this.g);
} else {
this.h = null;
}
}
private long m() {
return System.currentTimeMillis();
}
public d a() {
return this.a;
}
public boolean b() {
return this.c != null;
}
public void c() {
j.d("HarvestTimer: Start a harvestTimer, uploadName:" + this.h.getUploadName());
if (b()) {
j.b("HarvestTimer: Attempting to start while already running");
return;
}
k();
if (this.e <= 0) {
j.a("HarvestTimer: Refusing to start with a period <= 0 ms");
return;
}
j.d("HarvestTimer: Starting with a period of " + this.e + "ms");
System.currentTimeMillis();
this.c = this.b.scheduleAtFixedRate(this, 0L, this.e, TimeUnit.MILLISECONDS);
if (this.h.getUploadName().equals(APMUploadConfigure.APMUPLOADNAME)) {
com.baidu.uaq.agent.android.g.a();
}
}
public void d() {
if (b()) {
j.d("HarvestTimer: Stop a harvestTimer when period is " + this.e + "ms");
this.c.cancel(true);
this.c = null;
}
}
@Override // java.lang.Runnable
public void run() {
synchronized (this) {
try {
e();
l();
long j2 = this.e;
k();
j.d("period lasPeriod:" + j2 + " now:" + this.e);
if (this.e <= 0) {
d();
} else if (j2 != this.e) {
this.c.cancel(true);
this.c = this.b.scheduleAtFixedRate(this, this.e, this.e, TimeUnit.MILLISECONDS);
}
} catch (Exception e) {
j.a("HarvestTimer: Exception in timer tick: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
}
}
}
}

View File

@@ -0,0 +1,542 @@
package com.baidu.uaq.agent.android.harvest.multiharvest;
import android.content.Context;
import android.content.SharedPreferences;
import com.baidu.uaq.agent.android.AgentConfig;
import com.baidu.uaq.agent.android.UAQ;
import com.baidu.uaq.agent.android.customtransmission.APMUploadConfigure;
import com.baidu.uaq.agent.android.g;
import com.baidu.uaq.agent.android.harvest.bean.h;
import com.baidu.uaq.agent.android.util.e;
import com.baidu.uaq.agent.android.util.f;
import com.baidu.uaq.agent.android.util.i;
import com.tencent.open.SocialConstants;
import java.util.ArrayList;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
/* compiled from: MultiHarvester.java */
/* loaded from: classes.dex */
public class d {
private static final com.baidu.uaq.agent.android.logging.a k = com.baidu.uaq.agent.android.logging.b.a();
private static final UAQ l = UAQ.getInstance();
private static com.baidu.uaq.agent.android.harvest.a m;
private APMUploadConfigure a;
private b b;
private final f c;
private long d;
private long e;
private SharedPreferences f;
private SharedPreferences.Editor g;
private Context h;
private ArrayList<String> i = new ArrayList<>();
private a j;
/* compiled from: MultiHarvester.java */
/* renamed from: com.baidu.uaq.agent.android.harvest.multiharvest.d$1, reason: invalid class name */
static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] a = new int[a.values().length];
static {
try {
a[a.CONNECTEDWIFI.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
a[a.CONNECTEDNOTWIFI.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
/* compiled from: MultiHarvester.java */
private enum a {
CONNECTEDWIFI,
CONNECTEDNOTWIFI,
DISCONNECTED
}
public d(Context context, APMUploadConfigure aPMUploadConfigure) {
this.h = context;
this.a = aPMUploadConfigure;
this.c = new f(context, aPMUploadConfigure.getUploadName());
this.f = context.getSharedPreferences("com.baidu.uaq.android.agent.v2_customer_", 0);
}
public static void a(com.baidu.uaq.agent.android.harvest.health.b bVar) {
m.e().a(bVar);
}
public static com.baidu.uaq.agent.android.harvest.a c() {
return m;
}
private void d() {
if (this.a.getUploadName().equals(APMUploadConfigure.APMUPLOADNAME) && m == null) {
m = new com.baidu.uaq.agent.android.harvest.a();
}
if (this.b == null) {
this.b = new b();
}
}
private void e() {
if (this.j != a.CONNECTEDWIFI) {
return;
}
ArrayList<String> a2 = this.c.a();
if (a2.size() <= 0) {
return;
}
if (this.a.getUploadName().equals(APMUploadConfigure.APMUPLOADNAME)) {
a(a2, this.c);
} else {
b(a2, this.c);
}
}
private a f() {
return i.d(this.h) ? a.CONNECTEDWIFI : i.c(this.h) ? a.CONNECTEDNOTWIFI : a.DISCONNECTED;
}
private long g() {
int i = AnonymousClass1.a[this.j.ordinal()];
if (i == 1) {
return this.a.getMaxBytesPeriodWifi();
}
if (i != 2) {
return 0L;
}
return this.a.getMaxBytesPeriod4g();
}
private long h() {
int i = AnonymousClass1.a[this.j.ordinal()];
if (i == 1) {
return this.a.getMaxBytesWifi();
}
if (i != 2) {
return 0L;
}
return this.a.getMaxBytes4g();
}
private String i() {
int i = AnonymousClass1.a[this.j.ordinal()];
if (i == 1) {
return this.a.getUploadName() + "_dataReportLimitWIFI";
}
if (i != 2) {
return null;
}
return this.a.getUploadName() + "_dataReportLimitNOTWIFI";
}
private void j() {
this.g = this.f.edit();
String i = i();
if (i == null) {
return;
}
k.d("saveMaxBytesState uploaded bytes:" + this.e + " key:" + i + " uploadStartTime:" + this.d);
this.g.putLong(i, this.e);
this.g.apply();
}
private void k() {
this.g = this.f.edit();
String i = i();
if (i == null) {
return;
}
String l2 = l();
k.d("saveIntervalState uploaded bytes:" + this.e + " key:" + i + " uploadStartTime:" + this.d + " dateKey:" + l2);
this.g.putLong(i, this.e);
this.g.putLong(l2, this.d);
this.g.apply();
}
private String l() {
return this.a.getUploadName() + "apmUploadStartDate";
}
private long m() {
Context context = this.h;
if (context == null) {
k.a("getUploadedBytes failed, context is null");
return -1L;
}
SharedPreferences sharedPreferences = context.getSharedPreferences("com.baidu.uaq.android.agent.v2_customer_", 0);
String i = i();
if (sharedPreferences == null || i == null) {
this.e = 0L;
return 0L;
}
long j = sharedPreferences.getLong(i, 0L);
this.e = j;
return j;
}
private long n() {
Context context = this.h;
if (context == null) {
k.a("getUploadStartTime failed, context is null");
return -1L;
}
SharedPreferences sharedPreferences = context.getSharedPreferences("com.baidu.uaq.android.agent.v2_customer_", 0);
String l2 = l();
if (sharedPreferences == null || l2 == null) {
this.d = 0L;
return 0L;
}
long j = sharedPreferences.getLong(l2, 0L);
this.d = j;
return j;
}
private void o() {
long currentTimeMillis = System.currentTimeMillis();
long j = this.d;
Boolean bool = true;
if (j != 0 && currentTimeMillis - j < g()) {
bool = false;
}
if (bool.booleanValue()) {
this.d = currentTimeMillis;
this.e = 0L;
k();
}
}
public void b() {
if (this.a.getUploadName().equals(APMUploadConfigure.APMUPLOADNAME)) {
m.k();
} else {
this.i.clear();
}
}
public static void a(h hVar) {
m.f().a(hVar);
}
private void c(String str) {
com.baidu.uaq.agent.android.harvest.b a2 = this.b.a(a(str));
if (com.baidu.uaq.agent.android.harvest.multiharvest.a.c().a() < 1) {
k.a("Agent has shutdown during startUpload");
} else {
if (a(a2)) {
return;
}
k.d("upload APM data failed!");
}
}
public static void a(com.baidu.uaq.agent.android.harvest.bean.f fVar) {
m.g().a(fVar);
}
private void b(Long l2) {
ArrayList<String> a2 = com.baidu.uaq.agent.android.customtransmission.b.a(this.a.getUploadName(), Boolean.valueOf(this.a.isEnableRetransmission()));
if (!this.i.isEmpty()) {
k.a("blockArray is not empty!");
}
if (a2 == null || a2.isEmpty()) {
return;
}
this.i.addAll(a2);
String executeMerge = this.a.getMergeBlockCallBack().executeMerge(this.i);
k.d("config name:" + this.a.getUploadName() + ", upload limit:" + l2 + ", curr uploads:" + this.e + ", length:" + executeMerge.length());
if (l2.longValue() != 0 && this.e + executeMerge.length() > l2.longValue()) {
if (this.j != a.CONNECTEDWIFI) {
b(this.a.getUploadName());
com.baidu.uaq.agent.android.customtransmission.b.b(this.a.getUploadName(), Boolean.valueOf(this.a.isEnableRetransmission()));
return;
} else {
com.baidu.uaq.agent.android.customtransmission.b.b(this.a.getUploadName(), Boolean.valueOf(this.a.isEnableRetransmission()));
return;
}
}
a(executeMerge, this.a);
this.e += executeMerge.length();
j();
}
public void a(APMUploadConfigure aPMUploadConfigure) {
this.a = aPMUploadConfigure;
d();
this.j = f();
if (this.j != a.DISCONNECTED) {
this.d = n();
this.e = m();
o();
k.d("harvester exec for :" + aPMUploadConfigure.getUploadName() + ", uploadStartTime:" + this.d + ", intervalUploadedBytes:" + this.e);
long h = h();
if (aPMUploadConfigure.getUploadName().equals(APMUploadConfigure.APMUPLOADNAME)) {
a(Long.valueOf(h));
} else {
b(Long.valueOf(h));
}
if (h == 0 || this.e <= h) {
e();
}
} else {
a();
}
b();
}
public void a() {
if (this.a.getUploadName().equals(APMUploadConfigure.APMUPLOADNAME)) {
com.baidu.uaq.agent.android.harvest.a aVar = m;
a(aVar);
String c = aVar.c();
if (c != null) {
k.d("harvester exec for :" + this.a.getUploadName() + ", network is not connected, choose to localize data");
a(c, this.a.getUploadName());
return;
}
return;
}
ArrayList<String> a2 = com.baidu.uaq.agent.android.customtransmission.b.a(this.a.getUploadName(), Boolean.valueOf(this.a.isEnableRetransmission()));
if (a2 != null) {
this.i.addAll(a2);
k.d("harvester exec for :" + this.a.getUploadName() + ", network is not connected, choose to localize data");
b(this.a.getUploadName());
com.baidu.uaq.agent.android.customtransmission.b.b(this.a.getUploadName(), Boolean.valueOf(this.a.isEnableRetransmission()));
}
}
private void b(ArrayList<String> arrayList, f fVar) {
long h = h();
int size = arrayList.size();
k.d("handle localized data for " + this.a.getUploadName() + ", Local fileLen: " + size);
for (int i = 0; i < size; i++) {
String str = arrayList.get((size - i) - 1);
ArrayList<String> c = fVar.c(str);
if (c != null && c.size() != 0) {
k.d("handle localized file :" + str);
String executeMerge = this.a.getMergeBlockCallBack().executeMerge(c);
if (h != 0 && this.e + executeMerge.length() > h) {
k.d("upload data will exceeds upload limit");
return;
}
com.baidu.uaq.agent.android.harvest.b a2 = this.b.a(executeMerge.substring(0, executeMerge.length()), this.a);
if (a2 != null && a2.b()) {
fVar.a(str);
this.e += executeMerge.length();
j();
k.d("upload success, delete " + str + "; curr uploads:" + this.e + " length:" + executeMerge.length());
} else {
k.d("upload localized data for customer failed!");
}
}
}
}
private void a(Long l2) {
com.baidu.uaq.agent.android.harvest.a aVar = m;
a(aVar);
String c = aVar.c();
if (c.isEmpty()) {
return;
}
k.d("config name:" + this.a.getUploadName() + ", upload limit:" + l2 + ", curr uploads:" + this.e + ", length:" + c.length());
if (l2.longValue() != 0 && this.e + c.length() > l2.longValue()) {
if (this.j != a.CONNECTEDWIFI) {
a(c, this.a.getUploadName());
}
} else {
c(c);
this.e += c.length();
j();
}
}
private void a(ArrayList<String> arrayList, f fVar) {
long h = h();
int size = arrayList.size();
k.d("handle localized data for: " + this.a.getUploadName() + ", Local fileLen: " + size);
for (int i = 0; i < size; i++) {
String str = arrayList.get((size - i) - 1);
String b = fVar.b(str);
if (b != null && !b.isEmpty()) {
k.d("handle localized file :" + str);
if (h != 0 && this.e + b.length() > h) {
k.d("upload data will exceeds upload limit");
return;
}
com.baidu.uaq.agent.android.harvest.b a2 = this.b.a(a(b.substring(0, b.length() - 1)));
if (a2 != null && a2.a()) {
fVar.a(str);
this.e += b.length();
j();
k.d("upload success, delete " + str + "; curr uploads:" + this.e + " length:" + b.length());
}
if (com.baidu.uaq.agent.android.harvest.multiharvest.a.c().a() < 1) {
k.a("Agent has shutdown when handleLocalizedFile4APM");
} else if (!a(a2)) {
k.d("upload localized data failed");
}
}
}
}
private void b(String str) {
Iterator<String> it = this.i.iterator();
while (it.hasNext()) {
this.c.a(str, it.next());
k.d("Log Persist, fileList: " + this.c.a().size());
}
}
private static void b(com.baidu.uaq.agent.android.harvest.b bVar) {
com.baidu.uaq.agent.android.stats.a.b().a("Supportability/AgentHealth/Collector/HarvestTime", bVar.d());
k.d("HarvestTime = " + bVar.d() + "ms");
String c = bVar.c();
if (c != null && !c.isEmpty() && !"".equals(c)) {
try {
JSONObject jSONObject = new JSONObject(c);
if (!jSONObject.optString(SocialConstants.PARAM_SEND_MSG).isEmpty()) {
k.a("Err msg from server: " + jSONObject.getString(SocialConstants.PARAM_SEND_MSG));
return;
}
if (jSONObject.getBoolean("disableCollect")) {
if (l.isDisableCollect()) {
return;
}
k.c("disableCollect turn to true");
l.setSavedConfig(l.getConfig().newBuilder().build());
l.disableCollect();
g.b();
l.setDisableCollect(true);
return;
}
if (!jSONObject.getBoolean("disableCollect") && l.isDisableCollect()) {
k.c("disableCollect turn to false");
l.enableCollect(l.getSavedConfig());
g.a();
l.setDisableCollect(false);
}
com.baidu.uaq.agent.android.harvest.bean.b bVar2 = new com.baidu.uaq.agent.android.harvest.bean.b(jSONObject.getLong("accountId"), jSONObject.getLong("agentId"));
if (!bVar2.equals(m.j())) {
m.a(bVar2);
}
if (jSONObject.length() > 4) {
a(jSONObject);
}
l.setNeedBasicInfo(jSONObject.getBoolean("needBasicInfo"));
return;
} catch (JSONException e) {
k.a("Caught error while parse responseBody: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
return;
}
}
k.d("responseBody is Empty");
}
private void a(String str, String str2) {
this.c.a(str2, str);
k.d("localizeData4APM, localized file size: " + this.c.a().size());
}
private void a(String str, APMUploadConfigure aPMUploadConfigure) {
com.baidu.uaq.agent.android.harvest.b a2 = this.b.a(str, aPMUploadConfigure);
if (a2 != null && a2.b()) {
k.d("upload success");
com.baidu.uaq.agent.android.customtransmission.b.b(aPMUploadConfigure.getUploadName(), Boolean.valueOf(aPMUploadConfigure.isEnableRetransmission()));
} else {
k.d("upload customer data failed!");
}
}
private com.baidu.uaq.agent.android.harvest.a a(com.baidu.uaq.agent.android.harvest.a aVar) {
if (aVar.h().j()) {
return aVar;
}
try {
String a2 = e.a(aVar.h().e());
String a3 = e.a(aVar.h().n());
String a4 = e.a(aVar.h().l());
String a5 = e.a(aVar.h().m());
String a6 = e.a(aVar.h().k());
aVar.h().c(a2);
aVar.h().e(a3);
aVar.h().h(a4);
aVar.h().d(a5);
aVar.h().m(a6);
aVar.h().a(true);
return aVar;
} catch (Exception e) {
k.a("Caught error while data2AES: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
return aVar;
}
}
private boolean a(com.baidu.uaq.agent.android.harvest.b bVar) {
if (bVar == null) {
return false;
}
k.d("Harvest response status code: " + bVar.e());
if (bVar.f()) {
k.a("Harvest response error body: " + bVar.c());
m.k();
return false;
}
k.d("Harvest response body: " + bVar.c());
b(bVar);
return true;
}
private String a(String str) {
return "{\"version\":1,\"value\":[" + str + "]}";
}
private static void a(JSONObject jSONObject) {
boolean z;
AgentConfig.Builder newBuilder = l.getConfig().newBuilder();
try {
if (l.getConfig().isNativeControlDRP() || !jSONObject.has("dataReportPeriod") || l.getConfig().getDataReportPeriod() == jSONObject.getLong("dataReportPeriod")) {
z = false;
} else {
newBuilder.dataReportPeriod(jSONObject.getLong("dataReportPeriod"));
k.d("Update dataReportPeriod: " + jSONObject.getLong("dataReportPeriod"));
z = true;
}
if (jSONObject.has("dataReportLimit") && l.getConfig().getDataReportLimit() != jSONObject.getLong("dataReportLimit")) {
newBuilder.dataReportLimit(jSONObject.getLong("dataReportLimit"));
k.d("Update dataReportLimit: " + jSONObject.getLong("dataReportLimit"));
z = true;
}
if (jSONObject.has("responseBodyLimit") && l.getConfig().getResponseBodyLimit() != jSONObject.getLong("responseBodyLimit")) {
newBuilder.responseBodyLimit(jSONObject.getLong("responseBodyLimit"));
k.d("Update responseBodyLimit: " + jSONObject.getLong("responseBodyLimit"));
z = true;
}
if (jSONObject.has("sampleRate") && l.getConfig().getSampleRate() != jSONObject.getDouble("sampleRate")) {
newBuilder.sampleRate(jSONObject.getDouble("sampleRate"));
k.d("Update sampleRate: " + jSONObject.getDouble("sampleRate"));
z = true;
}
if (jSONObject.has("harvestableCacheLimit") && l.getConfig().getHarvestableCacheLimit() != jSONObject.getInt("harvestableCacheLimit")) {
newBuilder.harvestableCacheLimit(jSONObject.getInt("harvestableCacheLimit"));
k.d("Update harvestableCacheLimit: " + jSONObject.getInt("harvestableCacheLimit"));
z = true;
}
if (jSONObject.has("samplerFreq") && l.getConfig().getSamplerFreq() != jSONObject.getLong("samplerFreq")) {
newBuilder.samplerFreq(jSONObject.getLong("samplerFreq"));
k.d("Update samplerFreq: " + jSONObject.getLong("samplerFreq"));
z = true;
}
if (z) {
l.reconfig(newBuilder.build());
}
} catch (JSONException e) {
k.a("Caught error while updateAgentConfig: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
}
}
}