2021-08-11 06:37:47 +00:00
|
|
|
package c.a.q;
|
2021-07-24 02:37:17 +00:00
|
|
|
|
2021-08-12 06:36:45 +00:00
|
|
|
import android.app.Application;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
import android.os.PowerManager;
|
|
|
|
import androidx.annotation.AnyThread;
|
|
|
|
import androidx.annotation.RequiresApi;
|
2021-10-08 22:11:56 +00:00
|
|
|
import c.c.a.a0.d;
|
2021-08-12 06:36:45 +00:00
|
|
|
import com.discord.rtcconnection.enums.ThermalStatus;
|
|
|
|
import com.discord.utilities.debug.DebugPrintBuilder;
|
|
|
|
import com.discord.utilities.debug.DebugPrintable;
|
|
|
|
import com.discord.utilities.lifecycle.ApplicationProvider;
|
|
|
|
import com.discord.utilities.logging.LoggingProvider;
|
2021-11-02 06:38:17 +00:00
|
|
|
import d0.g;
|
|
|
|
import d0.i;
|
|
|
|
import d0.z.d.m;
|
|
|
|
import d0.z.d.o;
|
2021-07-24 02:37:17 +00:00
|
|
|
import java.util.Objects;
|
2021-08-12 06:36:45 +00:00
|
|
|
import kotlin.Lazy;
|
2021-07-24 02:37:17 +00:00
|
|
|
import kotlin.jvm.functions.Function0;
|
2021-08-12 06:36:45 +00:00
|
|
|
/* compiled from: ThermalDetector.kt */
|
|
|
|
@AnyThread
|
|
|
|
@RequiresApi(29)
|
|
|
|
public final class i0 implements PowerManager.OnThermalStatusChangedListener, Runnable, DebugPrintable {
|
|
|
|
public static final Lazy i = g.lazy(i.NONE, a.i);
|
|
|
|
public static boolean j;
|
|
|
|
public static boolean k;
|
|
|
|
public static boolean l;
|
|
|
|
public static final i0 m = new i0();
|
|
|
|
|
|
|
|
/* compiled from: ThermalDetector.kt */
|
|
|
|
public static final class a extends o implements Function0<Handler> {
|
|
|
|
public static final a i = new a();
|
|
|
|
|
|
|
|
public a() {
|
|
|
|
super(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
|
|
@Override // kotlin.jvm.functions.Function0
|
|
|
|
/* renamed from: invoke */
|
2021-11-02 06:38:17 +00:00
|
|
|
public Handler mo1invoke() {
|
2021-08-12 06:36:45 +00:00
|
|
|
return new Handler(Looper.getMainLooper());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final ThermalStatus a() {
|
|
|
|
ThermalStatus.a aVar = ThermalStatus.Companion;
|
|
|
|
Application application = ApplicationProvider.INSTANCE.get();
|
|
|
|
Objects.requireNonNull(aVar);
|
|
|
|
m.checkNotNullParameter(application, "context");
|
|
|
|
Object systemService = application.getSystemService("power");
|
|
|
|
Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.os.PowerManager");
|
|
|
|
return aVar.a(((PowerManager) systemService).getCurrentThermalStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void b(ThermalStatus thermalStatus) {
|
|
|
|
LoggingProvider.INSTANCE.get().recordBreadcrumb("thermalStatus = " + thermalStatus, "thermal");
|
|
|
|
switch (thermalStatus.ordinal()) {
|
|
|
|
case 0:
|
|
|
|
if (k) {
|
2021-11-05 06:48:17 +00:00
|
|
|
d.c1("ThermalDetector", "totally cool: no longer in thermal trouble");
|
2021-08-12 06:36:45 +00:00
|
|
|
k = false;
|
|
|
|
if (l) {
|
|
|
|
((Handler) i.getValue()).removeCallbacks(this);
|
|
|
|
l = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-11-05 06:48:17 +00:00
|
|
|
d.d1("ThermalDetector", "totally cool: thermal status is nominal");
|
2021-08-12 06:36:45 +00:00
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
if (k) {
|
2021-11-05 06:48:17 +00:00
|
|
|
d.c1("ThermalDetector", "cooling down: thermal status = " + thermalStatus);
|
2021-08-12 06:36:45 +00:00
|
|
|
c();
|
|
|
|
return;
|
|
|
|
}
|
2021-11-05 06:48:17 +00:00
|
|
|
d.d1("ThermalDetector", "pretty warm: ignoring low priority thermal status = " + thermalStatus);
|
2021-08-12 06:36:45 +00:00
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
if (!k) {
|
2021-11-05 06:48:17 +00:00
|
|
|
d.e1("ThermalDetector", "we're starting to be in thermal trouble");
|
2021-08-12 06:36:45 +00:00
|
|
|
k = true;
|
|
|
|
}
|
|
|
|
String str = "very toasty: thermal status = " + thermalStatus;
|
|
|
|
if (thermalStatus.compareTo(ThermalStatus.Emergency) < 0) {
|
2021-11-05 06:48:17 +00:00
|
|
|
d.e1("ThermalDetector", str);
|
2021-08-12 06:36:45 +00:00
|
|
|
} else {
|
2021-11-05 06:48:17 +00:00
|
|
|
d.b1("ThermalDetector", str, new RuntimeException(str));
|
2021-08-12 06:36:45 +00:00
|
|
|
}
|
|
|
|
c();
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void c() {
|
|
|
|
if (!l) {
|
|
|
|
((Handler) i.getValue()).postDelayed(this, 1000);
|
|
|
|
l = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // com.discord.utilities.debug.DebugPrintable
|
|
|
|
@AnyThread
|
|
|
|
public void debugPrint(DebugPrintBuilder debugPrintBuilder) {
|
|
|
|
m.checkNotNullParameter(debugPrintBuilder, "dp");
|
|
|
|
debugPrintBuilder.appendKeyValue("registered", Boolean.valueOf(j));
|
|
|
|
debugPrintBuilder.appendKeyValue("inThermalTrouble", Boolean.valueOf(k));
|
|
|
|
debugPrintBuilder.appendKeyValue("updateScheduled", Boolean.valueOf(l));
|
|
|
|
debugPrintBuilder.appendKeyValue("currentThermalStatus", a());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // android.os.PowerManager.OnThermalStatusChangedListener
|
|
|
|
public synchronized void onThermalStatusChanged(int i2) {
|
|
|
|
ThermalStatus a2 = ThermalStatus.Companion.a(i2);
|
2021-11-05 06:48:17 +00:00
|
|
|
d.a1("ThermalDetector", "system update: onThermalStatusChanged( " + a2 + " )");
|
2021-08-12 06:36:45 +00:00
|
|
|
b(a2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.lang.Runnable
|
|
|
|
public synchronized void run() {
|
|
|
|
l = false;
|
|
|
|
ThermalStatus a2 = a();
|
2021-11-05 06:48:17 +00:00
|
|
|
d.a1("ThermalDetector", "scheduled update: current thermal status = " + a2);
|
2021-08-12 06:36:45 +00:00
|
|
|
b(a2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.lang.Object
|
|
|
|
public synchronized String toString() {
|
|
|
|
return "ThermalDetector(registered=" + j + ", inThermalTrouble=" + k + ", updateScheduled=" + l + ')';
|
2021-07-24 02:37:17 +00:00
|
|
|
}
|
|
|
|
}
|