package c.a.r; import android.app.Application; import android.os.Handler; import android.os.Looper; import android.os.PowerManager; import androidx.annotation.AnyThread; import androidx.annotation.RequiresApi; import com.airbnb.lottie.parser.AnimatableValueParser; 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; import d0.g; import d0.i; import d0.z.d.m; import d0.z.d.o; import java.util.Objects; import kotlin.Lazy; import kotlin.jvm.functions.Function0; /* 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 { 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 */ public Handler mo1invoke() { 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) { AnimatableValueParser.E1("ThermalDetector", "totally cool: no longer in thermal trouble"); k = false; if (l) { ((Handler) i.getValue()).removeCallbacks(this); l = false; return; } return; } AnimatableValueParser.F1("ThermalDetector", "totally cool: thermal status is nominal"); return; case 1: case 2: if (k) { AnimatableValueParser.E1("ThermalDetector", "cooling down: thermal status = " + thermalStatus); c(); return; } AnimatableValueParser.F1("ThermalDetector", "pretty warm: ignoring low priority thermal status = " + thermalStatus); return; case 3: case 4: case 5: case 6: if (!k) { AnimatableValueParser.G1("ThermalDetector", "we're starting to be in thermal trouble"); k = true; } String str = "very toasty: thermal status = " + thermalStatus; if (thermalStatus.compareTo(ThermalStatus.Emergency) < 0) { AnimatableValueParser.G1("ThermalDetector", str); } else { AnimatableValueParser.D1("ThermalDetector", str, new RuntimeException(str)); } 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); AnimatableValueParser.C1("ThermalDetector", "system update: onThermalStatusChanged( " + a2 + " )"); b(a2); } @Override // java.lang.Runnable public synchronized void run() { l = false; ThermalStatus a2 = a(); AnimatableValueParser.C1("ThermalDetector", "scheduled update: current thermal status = " + a2); b(a2); } @Override // java.lang.Object public synchronized String toString() { return "ThermalDetector(registered=" + j + ", inThermalTrouble=" + k + ", updateScheduled=" + l + ')'; } }