jimu-decompiled/sources/com/baidu/uaq/agent/android/d.java
2025-05-13 19:24:51 +02:00

180 lines
6.8 KiB
Java

package com.baidu.uaq.agent.android;
import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.text.TextUtils;
import com.baidu.uaq.agent.android.util.i;
/* compiled from: AndroidAgentImpl.java */
/* loaded from: classes.dex */
public class d implements b {
private static final com.baidu.uaq.agent.android.logging.a f = com.baidu.uaq.agent.android.logging.b.a();
private static final UAQ g = UAQ.getInstance();
private final Context a;
private f b;
private com.baidu.uaq.agent.android.harvest.bean.c c;
private com.baidu.uaq.agent.android.harvest.bean.a d;
private com.baidu.uaq.agent.android.crashes.d e;
public d(Context context) throws c {
if (TextUtils.isEmpty(g.getConfig().getAPIKey())) {
f.d("License key invalid cannot start.");
throw new c("This license key is null");
}
this.a = b(context);
this.b = new f(this.a);
if (!g.getConfig().getAPIKey().equals(this.b.e())) {
f.d("License key has changed. Clearing saved state.");
this.b.a();
this.b.b(g.getConfig().getDataReportLimit());
this.b.c(System.currentTimeMillis());
}
if (g.getConfig().isNativeControlDRP() && g.getConfig().getDataReportPeriod() != this.b.b()) {
this.b.a(g.getConfig().getDataReportPeriod());
this.b.c();
}
this.b.a(g.getConfig().getAPIKey());
this.e = new com.baidu.uaq.agent.android.crashes.g(this.a);
}
public static void a(Context context) {
try {
a.a(new d(context));
a.i();
} catch (c e) {
f.a("Failed to initialize the agent: ", e);
}
}
@Override // com.baidu.uaq.agent.android.b
public com.baidu.uaq.agent.android.harvest.bean.a b() {
String str;
String str2 = "";
com.baidu.uaq.agent.android.harvest.bean.a aVar = this.d;
if (aVar != null) {
return aVar;
}
String packageName = this.a.getPackageName();
PackageManager packageManager = this.a.getPackageManager();
try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
str = (packageInfo == null || packageInfo.versionName == null || packageInfo.versionName.length() <= 0) ? "" : packageInfo.versionName;
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
str2 = applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo).toString() : packageName;
} catch (PackageManager.NameNotFoundException e) {
e = e;
f.a("Caught error while getApplicationInformation: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
this.d = new com.baidu.uaq.agent.android.harvest.bean.a(str2, str, packageName);
return this.d;
} catch (SecurityException e2) {
e = e2;
f.a("Caught error while getApplicationInformation: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
this.d = new com.baidu.uaq.agent.android.harvest.bean.a(str2, str, packageName);
return this.d;
}
} catch (PackageManager.NameNotFoundException | SecurityException e3) {
e = e3;
str = "";
}
this.d = new com.baidu.uaq.agent.android.harvest.bean.a(str2, str, packageName);
return this.d;
}
@Override // com.baidu.uaq.agent.android.b
public String c() {
return i.b(this.a);
}
@Override // com.baidu.uaq.agent.android.b
public String d() {
return i.a(this.a);
}
@Override // com.baidu.uaq.agent.android.b
public com.baidu.uaq.agent.android.harvest.bean.d e() {
com.baidu.uaq.agent.android.harvest.bean.d dVar = new com.baidu.uaq.agent.android.harvest.bean.d();
long[] jArr = new long[2];
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
StatFs statFs2 = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
try {
jArr[0] = statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
jArr[1] = statFs2.getAvailableBlocksLong() * statFs.getBlockSizeLong();
} catch (Exception e) {
f.a("Caught error while getEnvironmentInformation: ", e);
com.baidu.uaq.agent.android.harvest.health.a.a(e);
}
if (jArr[0] < 0) {
jArr[0] = 0;
}
if (jArr[1] < 0) {
jArr[1] = 0;
}
dVar.a(jArr);
dVar.a(0L);
dVar.a(this.a.getResources().getConfiguration().orientation);
dVar.a(i.a(this.a));
dVar.b(c());
return dVar;
}
@Override // com.baidu.uaq.agent.android.b
public void shutdown() {
com.baidu.uaq.agent.android.sample.a.d();
if (g.getConfig().isThingsMonitor()) {
com.baidu.uaq.agent.android.sample.b.k();
}
g.b();
}
@Override // com.baidu.uaq.agent.android.b
public void start() {
com.baidu.uaq.agent.android.sample.a.a(this.a);
if (g.getConfig().isThingsMonitor()) {
com.baidu.uaq.agent.android.sample.b.a(this.a);
}
if (g.getConfig().isReportCrashes()) {
com.baidu.uaq.agent.android.crashes.c.a(this.e);
}
}
@Override // com.baidu.uaq.agent.android.b
public com.baidu.uaq.agent.android.harvest.bean.c a() {
com.baidu.uaq.agent.android.harvest.bean.c cVar = this.c;
if (cVar != null) {
return cVar;
}
com.baidu.uaq.agent.android.harvest.bean.c cVar2 = new com.baidu.uaq.agent.android.harvest.bean.c();
cVar2.b("Android");
cVar2.c(Build.VERSION.RELEASE);
cVar2.i(Build.VERSION.INCREMENTAL);
cVar2.e(Build.MODEL);
cVar2.f("AndroidAgent");
cVar2.g(a.g() + "." + a.b());
cVar2.d(Build.MANUFACTURER);
if (g.getConfig().isUsePersistentUUID()) {
cVar2.h(com.baidu.uaq.agent.android.util.d.d(this.a));
} else {
cVar2.h(com.baidu.uaq.agent.android.util.d.b(this.a));
}
cVar2.j(System.getProperty("os.arch"));
cVar2.k(System.getProperty("java.vm.version"));
cVar2.l(com.baidu.uaq.agent.android.util.d.a(this.a).name().toLowerCase());
cVar2.m(g.getConfig().getCuid());
this.c = cVar2;
return this.c;
}
private static Context b(Context context) {
return !(context instanceof Application) ? context.getApplicationContext() : context;
}
}