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

Commit e09cc549 authored by Stefano Angeleri's avatar Stefano Angeleri
Browse files

Use the actual charging status instead of the plugged status to determine if...

Use the actual charging status instead of the plugged status to determine if the battery is charging.

While usually when a device is plugged in (usb for example) it's actually charging, there are cases when this isn't true.
For example, since recently the zte blade has an option to disable usb charging even if plugged in.
The function works correctly but the battery icon will show the battery charging even if it's effectively not charging or even discharging.

This patch uses the Status information instead of the Plugged information from the received message to show the real status of the battery.

Change-Id: Ib68401040294681824ea0c3fe68391b6a8375a65
parent 17fc45c2
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Handler;
import android.os.SystemClock;
import android.os.BatteryManager;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;
@@ -54,8 +55,8 @@ public class CmBatteryMiniIcon extends ImageView {
    // contains the current bat level, values: 0-100
    private int mBatteryLevel = 0;

    // contains current charger plugged state
    private boolean mBatteryPlugged = false;
    // contains current charging state of the battery.
    private boolean mBatteryCharging = false;

    // recalculation of BATTERY_MINI_ICON_WIDTH_DIP to pixels
    private int mWidthPx;
@@ -190,11 +191,11 @@ public class CmBatteryMiniIcon extends ImageView {
            if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
                // mIconId = intent.getIntExtra("icon-small", 0);
                mBatteryLevel = intent.getIntExtra("level", 0);
                boolean oldPluggedState = mBatteryPlugged;
                mBatteryPlugged = intent.getIntExtra("plugged", 0) != 0;
                boolean oldChargingState = mBatteryCharging;
                mBatteryCharging = intent.getIntExtra("status", 0) == BatteryManager.BATTERY_STATUS_CHARGING;

                if (mBatteryPlugged && mBatteryLevel < 100) {
                    if (!oldPluggedState)
                if (mBatteryCharging && mBatteryLevel < 100) {
                    if (!oldChargingState)
                        startTimer();
                    if(mBatteryLevel % 10 == 0)
                        updateAnimDuration();