67 lines
1.9 KiB
Java
67 lines
1.9 KiB
Java
|
package com.google.firebase.crashlytics.internal.common;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.content.IntentFilter;
|
||
|
import com.huawei.hms.support.feature.result.CommonConstant;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
class BatteryState {
|
||
|
static final int VELOCITY_CHARGING = 2;
|
||
|
static final int VELOCITY_FULL = 3;
|
||
|
static final int VELOCITY_UNPLUGGED = 1;
|
||
|
private final Float level;
|
||
|
private final boolean powerConnected;
|
||
|
|
||
|
private BatteryState(Float f, boolean z) {
|
||
|
this.powerConnected = z;
|
||
|
this.level = f;
|
||
|
}
|
||
|
|
||
|
public int getBatteryVelocity() {
|
||
|
Float f;
|
||
|
if (!this.powerConnected || (f = this.level) == null) {
|
||
|
return 1;
|
||
|
}
|
||
|
return ((double) f.floatValue()) < 0.99d ? 2 : 3;
|
||
|
}
|
||
|
|
||
|
public static BatteryState get(Context context) {
|
||
|
boolean z;
|
||
|
Float f = null;
|
||
|
Intent registerReceiver = context.registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
|
||
|
if (registerReceiver != null) {
|
||
|
z = isPowerConnected(registerReceiver);
|
||
|
f = getLevel(registerReceiver);
|
||
|
} else {
|
||
|
z = false;
|
||
|
}
|
||
|
return new BatteryState(f, z);
|
||
|
}
|
||
|
|
||
|
private static boolean isPowerConnected(Intent intent) {
|
||
|
int intExtra = intent.getIntExtra(CommonConstant.KEY_STATUS, -1);
|
||
|
if (intExtra == -1) {
|
||
|
return false;
|
||
|
}
|
||
|
return intExtra == 2 || intExtra == 5;
|
||
|
}
|
||
|
|
||
|
private static Float getLevel(Intent intent) {
|
||
|
int intExtra = intent.getIntExtra("level", -1);
|
||
|
int intExtra2 = intent.getIntExtra("scale", -1);
|
||
|
if (intExtra == -1 || intExtra2 == -1) {
|
||
|
return null;
|
||
|
}
|
||
|
return Float.valueOf(intExtra / intExtra2);
|
||
|
}
|
||
|
|
||
|
boolean isPowerConnected() {
|
||
|
return this.powerConnected;
|
||
|
}
|
||
|
|
||
|
public Float getBatteryLevel() {
|
||
|
return this.level;
|
||
|
}
|
||
|
}
|