Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf3e26e1 authored by Kuan Wang's avatar Kuan Wang Committed by Automerger Merge Worker
Browse files

Add static funciton isCharged in BatteryStatus to check charge status am: c0acc179

parents 9ff68d2d c0acc179
Loading
Loading
Loading
Loading
+28 −1
Original line number Original line Diff line number Diff line
@@ -135,7 +135,7 @@ public class BatteryStatus {
     * @return true if the device is charged
     * @return true if the device is charged
     */
     */
    public boolean isCharged() {
    public boolean isCharged() {
        return status == BATTERY_STATUS_FULL || level >= 100;
        return isCharged(status, level);
    }
    }


    /**
    /**
@@ -177,4 +177,31 @@ public class BatteryStatus {
        return "BatteryStatus{status=" + status + ",level=" + level + ",plugged=" + plugged
        return "BatteryStatus{status=" + status + ",level=" + level + ",plugged=" + plugged
                + ",health=" + health + ",maxChargingWattage=" + maxChargingWattage + "}";
                + ",health=" + health + ",maxChargingWattage=" + maxChargingWattage + "}";
    }
    }

    /**
     * Whether or not the device is charged. Note that some devices never return 100% for
     * battery level, so this allows either battery level or status to determine if the
     * battery is charged.
     *
     * @param batteryChangedIntent ACTION_BATTERY_CHANGED intent
     * @return true if the device is charged
     */
    public static boolean isCharged(Intent batteryChangedIntent) {
        int status = batteryChangedIntent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN);
        int level = batteryChangedIntent.getIntExtra(EXTRA_LEVEL, 0);
        return isCharged(status, level);
    }

    /**
     * Whether or not the device is charged. Note that some devices never return 100% for
     * battery level, so this allows either battery level or status to determine if the
     * battery is charged.
     *
     * @param status values for "status" field in the ACTION_BATTERY_CHANGED Intent
     * @param level values from 0 to 100
     * @return true if the device is charged
     */
    public static boolean isCharged(int status, int level) {
        return status == BATTERY_STATUS_FULL || level >= 100;
    }
}
}