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

Commit c95c5b15 authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "Replace the getBatteryLevel() method from SettingsLib API"

parents 60a724fe e77b5bbe
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -602,15 +602,6 @@ public class BatteryUtils {
                /*receiver=*/ null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    }

    /** Gets the battery level from the intent. */
    public static int getBatteryLevel(Intent intent) {
        final int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        final int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
        return scale == 0
                ? -1 /*invalid battery level*/
                : Math.round((level / (float) scale) * 100f);
    }

    /** Gets the current dock defender mode */
    public static int getCurrentDockDefenderMode(Context context, BatteryInfo batteryInfo) {
        if (batteryInfo.pluggedStatus == BatteryManager.BATTERY_PLUGGED_DOCK) {
+2 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import androidx.annotation.VisibleForTesting;

import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batteryusage.db.BatteryStateDatabase;
import com.android.settingslib.fuelgauge.BatteryStatus;

import java.time.Clock;
import java.time.Duration;
@@ -149,7 +150,7 @@ public final class DatabaseUtils {
            clearMemory();
            return null;
        }
        final int batteryLevel = BatteryUtils.getBatteryLevel(intent);
        final int batteryLevel = BatteryStatus.getBatteryLevel(intent);
        final int batteryStatus = intent.getIntExtra(
                BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_UNKNOWN);
        final int batteryHealth = intent.getIntExtra(
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ public final class BatteryUsageBroadcastReceiverTest {
    private static Intent getBatteryIntent(int level, int status) {
        final Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
        intent.putExtra(BatteryManager.EXTRA_LEVEL, level);
        intent.putExtra(BatteryManager.EXTRA_SCALE, 100);
        intent.putExtra(BatteryManager.EXTRA_STATUS, status);
        return intent;
    }