Replace the getBatteryLevel() method from SettingsLib API
Bug: 260524172 Test: presubmit Change-Id: Icb56abd3dc258dde142a956124dc12bbfd9ae889
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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(
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user