mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 08:39:22 +01:00
Include battery info debuglog.
This commit is contained in:
@@ -4,6 +4,7 @@ import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.MemoryInfo;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -79,6 +80,25 @@ public final class DeviceProperties {
|
||||
return activityManager.isBackgroundRestricted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current battery level as a percentage (0-100), or -1 if unavailable.
|
||||
*/
|
||||
public static int getBatteryLevel(@NonNull Context context) {
|
||||
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||
if (batteryManager != null) {
|
||||
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the device is currently charging.
|
||||
*/
|
||||
public static boolean isCharging(@NonNull Context context) {
|
||||
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||
return batteryManager != null && batteryManager.isCharging();
|
||||
}
|
||||
|
||||
public static DataSaverState getDataSaverState(@NonNull Context context) {
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
switch (ServiceUtil.getConnectivityManager(context).getRestrictBackgroundStatus()) {
|
||||
|
||||
Reference in New Issue
Block a user