258 lines
8.0 KiB
Java
258 lines
8.0 KiB
Java
package com.baidu.uaq.agent.android.sample;
|
|
|
|
import android.content.Context;
|
|
import android.net.ConnectivityManager;
|
|
import android.net.NetworkInfo;
|
|
import android.net.wifi.WifiManager;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.telephony.PhoneStateListener;
|
|
import android.telephony.SignalStrength;
|
|
import android.telephony.TelephonyManager;
|
|
import com.baidu.uaq.agent.android.harvest.bean.f;
|
|
import com.baidu.uaq.agent.android.util.g;
|
|
import com.ijm.dataencryption.de.DataDecryptTool;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
/* compiled from: SamplerCommon.java */
|
|
/* loaded from: classes.dex */
|
|
public class b implements Runnable {
|
|
private static Context n;
|
|
private static b q;
|
|
private static TelephonyManager s;
|
|
public static a t;
|
|
private ScheduledFuture c;
|
|
private f d;
|
|
private float f;
|
|
private float g;
|
|
private float h;
|
|
private float i;
|
|
private float j;
|
|
private float k;
|
|
private float l;
|
|
private static final com.baidu.uaq.agent.android.logging.a m = com.baidu.uaq.agent.android.logging.b.a();
|
|
private static final Long o = 10000L;
|
|
private static final ReentrantLock p = new ReentrantLock();
|
|
private static double r = 0.0d;
|
|
private double e = 0.0d;
|
|
private final ScheduledExecutorService a = Executors.newSingleThreadScheduledExecutor(new g("SamplerCommon"));
|
|
private final AtomicBoolean b = new AtomicBoolean(false);
|
|
|
|
/* compiled from: SamplerCommon.java */
|
|
private static class a extends PhoneStateListener {
|
|
private static int a;
|
|
|
|
private a() {
|
|
}
|
|
|
|
public static int a() {
|
|
return a;
|
|
}
|
|
|
|
@Override // android.telephony.PhoneStateListener
|
|
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
|
super.onSignalStrengthsChanged(signalStrength);
|
|
try {
|
|
a = ((Integer) signalStrength.getClass().getMethod("getDbm", new Class[0]).invoke(signalStrength, new Object[0])).intValue();
|
|
} catch (IllegalAccessException e) {
|
|
b.m.a("Caught error while getDbm: ", e);
|
|
} catch (NoSuchMethodException e2) {
|
|
b.m.a("Caught error while getDbm: ", e2);
|
|
} catch (InvocationTargetException e3) {
|
|
b.m.a("Caught error while getDbm: ", e3);
|
|
}
|
|
}
|
|
}
|
|
|
|
private b() {
|
|
}
|
|
|
|
public static void a(Context context) {
|
|
p.lock();
|
|
try {
|
|
if (q == null) {
|
|
n = context;
|
|
q = new b();
|
|
l();
|
|
} else {
|
|
m.d("sampler not null when init samplerCommon!");
|
|
}
|
|
} finally {
|
|
p.unlock();
|
|
}
|
|
}
|
|
|
|
private void b() {
|
|
p.lock();
|
|
try {
|
|
this.d = new f();
|
|
this.d.a(System.currentTimeMillis());
|
|
a(0);
|
|
e();
|
|
c();
|
|
com.baidu.uaq.agent.android.harvest.bean.g.b(this.d);
|
|
} finally {
|
|
p.unlock();
|
|
}
|
|
}
|
|
|
|
private void c() {
|
|
NetworkInfo activeNetworkInfo = ((ConnectivityManager) n.getSystemService("connectivity")).getActiveNetworkInfo();
|
|
if (!a(activeNetworkInfo)) {
|
|
this.d.a("networkState", 0);
|
|
this.d.a("networkDbmStrength", 2);
|
|
} else if (b(activeNetworkInfo)) {
|
|
this.d.a("networkState", 1);
|
|
this.d.a("networkDbmStrength", Integer.valueOf(d()));
|
|
} else if (c(activeNetworkInfo)) {
|
|
this.d.a("networkState", 2);
|
|
this.d.a("networkDbmStrength", Integer.valueOf(a.a()));
|
|
}
|
|
}
|
|
|
|
private int d() {
|
|
return ((WifiManager) n.getSystemService("wifi")).getConnectionInfo().getRssi();
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:77:0x0177 A[EXC_TOP_SPLITTER, SYNTHETIC] */
|
|
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:64:0x0170 -> B:36:0x0173). Please report as a decompilation issue!!! */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
private void e() {
|
|
/*
|
|
Method dump skipped, instructions count: 384
|
|
To view this dump change 'Code comments level' option to 'DEBUG'
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.baidu.uaq.agent.android.sample.b.e():void");
|
|
}
|
|
|
|
private static void j() {
|
|
p.lock();
|
|
try {
|
|
if (q != null) {
|
|
q.a(true);
|
|
m.d("SamplerCommon hard stopped");
|
|
}
|
|
} finally {
|
|
p.unlock();
|
|
}
|
|
}
|
|
|
|
public static void k() {
|
|
p.lock();
|
|
try {
|
|
if (q != null) {
|
|
j();
|
|
q = null;
|
|
m.d("SamplerCommon shutdown");
|
|
} else {
|
|
m.d("SamplerCommon shutdown start, sampler null!");
|
|
}
|
|
} finally {
|
|
p.unlock();
|
|
}
|
|
}
|
|
|
|
public static void l() {
|
|
p.lock();
|
|
try {
|
|
m.d("SamplerCommon start!");
|
|
s = (TelephonyManager) n.getSystemService("phone");
|
|
if (t == null) {
|
|
new Handler(Looper.getMainLooper()).post(new Runnable() { // from class: com.baidu.uaq.agent.android.sample.b.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
b.t = new a();
|
|
}
|
|
});
|
|
}
|
|
s.listen(t, DataDecryptTool.DECRYPT_ALL_FILE);
|
|
q.a();
|
|
} finally {
|
|
p.unlock();
|
|
}
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
try {
|
|
if (this.b.get()) {
|
|
b();
|
|
}
|
|
} catch (Exception e) {
|
|
m.a("Caught error while Sampler run: ", e);
|
|
com.baidu.uaq.agent.android.harvest.health.a.a(e);
|
|
}
|
|
}
|
|
|
|
private void a(boolean z) {
|
|
p.lock();
|
|
try {
|
|
try {
|
|
if (this.b.get()) {
|
|
this.b.set(false);
|
|
if (this.c != null) {
|
|
this.c.cancel(z);
|
|
}
|
|
m.d("SamplerCommon canceled");
|
|
}
|
|
} catch (Exception e) {
|
|
m.a("Caught error while Sampler stop: ", e);
|
|
}
|
|
} finally {
|
|
p.unlock();
|
|
}
|
|
}
|
|
|
|
private boolean b(NetworkInfo networkInfo) {
|
|
return networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == 1;
|
|
}
|
|
|
|
private boolean c(NetworkInfo networkInfo) {
|
|
return networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == 0;
|
|
}
|
|
|
|
private void a() {
|
|
p.lock();
|
|
try {
|
|
if (!this.b.get()) {
|
|
this.c = this.a.scheduleWithFixedDelay(this, o.longValue(), o.longValue(), TimeUnit.MILLISECONDS);
|
|
this.b.set(true);
|
|
}
|
|
} finally {
|
|
p.unlock();
|
|
}
|
|
}
|
|
|
|
private void a(int i) {
|
|
if (i >= 2) {
|
|
this.d.a("appCpuUsagePercentage", Double.valueOf(r));
|
|
return;
|
|
}
|
|
int i2 = i + 1;
|
|
com.baidu.uaq.agent.android.tracing.a c = com.baidu.uaq.agent.android.sample.a.c();
|
|
if (c != null) {
|
|
this.e = ((Double) c.e().a()).doubleValue();
|
|
double d = this.e;
|
|
if (d <= 100.0d && d >= 0.0d) {
|
|
this.d.a("appCpuUsagePercentage", Double.valueOf(d));
|
|
r = this.e;
|
|
return;
|
|
}
|
|
}
|
|
a(i2);
|
|
}
|
|
|
|
private static boolean a(NetworkInfo networkInfo) {
|
|
return networkInfo != null && networkInfo.isConnected();
|
|
}
|
|
}
|