Update BatteryInfo to include averageTimeToDischarge
am: db1efa3e03
Change-Id: Ibad0041006908e4ab4a229bf8dc7bde5f14bb18a
This commit is contained in:
@@ -35,18 +35,15 @@ import com.android.settings.overlay.FeatureFactory;
|
|||||||
import com.android.settingslib.R;
|
import com.android.settingslib.R;
|
||||||
import com.android.settingslib.utils.PowerUtil;
|
import com.android.settingslib.utils.PowerUtil;
|
||||||
import com.android.settingslib.utils.StringUtil;
|
import com.android.settingslib.utils.StringUtil;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class BatteryInfo {
|
public class BatteryInfo {
|
||||||
private static final long SEVEN_MINUTES_MICROS = TimeUnit.MINUTES.toMicros(7);
|
|
||||||
private static final long FIFTEEN_MINUTES_MICROS = TimeUnit.MINUTES.toMicros(15);
|
|
||||||
private static final long ONE_DAY_MICROS = TimeUnit.DAYS.toMicros(1);
|
|
||||||
|
|
||||||
public CharSequence chargeLabel;
|
public CharSequence chargeLabel;
|
||||||
public CharSequence remainingLabel;
|
public CharSequence remainingLabel;
|
||||||
public int batteryLevel;
|
public int batteryLevel;
|
||||||
public boolean discharging = true;
|
public boolean discharging = true;
|
||||||
public long remainingTimeUs = 0;
|
public long remainingTimeUs = 0;
|
||||||
|
public long averageTimeToDischarge = Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
|
||||||
public String batteryPercentString;
|
public String batteryPercentString;
|
||||||
public String statusLabel;
|
public String statusLabel;
|
||||||
private boolean mCharging;
|
private boolean mCharging;
|
||||||
@@ -180,16 +177,18 @@ public class BatteryInfo {
|
|||||||
BatteryUtils
|
BatteryUtils
|
||||||
.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
||||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, shortString,
|
estimate, elapsedRealtimeUs, shortString);
|
||||||
PowerUtil.convertMsToUs(estimate.estimateMillis),
|
|
||||||
estimate.isBasedOnUsage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long prediction = discharging
|
long prediction = discharging
|
||||||
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
||||||
|
Estimate estimate = new Estimate(
|
||||||
|
PowerUtil.convertUsToMs(prediction),
|
||||||
|
false, /* isBasedOnUsage */
|
||||||
|
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
|
||||||
BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
|
BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
|
||||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, shortString, prediction, false);
|
estimate, elapsedRealtimeUs, shortString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -204,25 +203,29 @@ public class BatteryInfo {
|
|||||||
@WorkerThread
|
@WorkerThread
|
||||||
public static BatteryInfo getBatteryInfoOld(Context context, Intent batteryBroadcast,
|
public static BatteryInfo getBatteryInfoOld(Context context, Intent batteryBroadcast,
|
||||||
BatteryStats stats, long elapsedRealtimeUs, boolean shortString) {
|
BatteryStats stats, long elapsedRealtimeUs, boolean shortString) {
|
||||||
return getBatteryInfo(context, batteryBroadcast, stats, elapsedRealtimeUs, shortString,
|
Estimate estimate = new Estimate(
|
||||||
stats.computeBatteryTimeRemaining(elapsedRealtimeUs), false);
|
PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)),
|
||||||
|
false,
|
||||||
|
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
|
||||||
|
return getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs,
|
||||||
|
shortString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public static BatteryInfo getBatteryInfo(Context context, Intent batteryBroadcast,
|
public static BatteryInfo getBatteryInfo(Context context, Intent batteryBroadcast,
|
||||||
BatteryStats stats, long elapsedRealtimeUs, boolean shortString, long drainTimeUs,
|
BatteryStats stats, Estimate estimate, long elapsedRealtimeUs, boolean shortString) {
|
||||||
boolean basedOnUsage) {
|
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
BatteryInfo info = new BatteryInfo();
|
BatteryInfo info = new BatteryInfo();
|
||||||
info.mStats = stats;
|
info.mStats = stats;
|
||||||
info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
|
info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
|
||||||
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
|
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
|
||||||
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
||||||
|
info.averageTimeToDischarge = estimate.averageDischargeTime;
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
|
|
||||||
info.statusLabel = Utils.getBatteryStatus(resources, batteryBroadcast);
|
info.statusLabel = Utils.getBatteryStatus(resources, batteryBroadcast);
|
||||||
if (!info.mCharging) {
|
if (!info.mCharging) {
|
||||||
updateBatteryInfoDischarging(context, shortString, drainTimeUs, basedOnUsage, info);
|
updateBatteryInfoDischarging(context, shortString, estimate, info);
|
||||||
} else {
|
} else {
|
||||||
updateBatteryInfoCharging(context, batteryBroadcast, stats, elapsedRealtimeUs, info);
|
updateBatteryInfoCharging(context, batteryBroadcast, stats, elapsedRealtimeUs, info);
|
||||||
}
|
}
|
||||||
@@ -256,20 +259,21 @@ public class BatteryInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void updateBatteryInfoDischarging(Context context, boolean shortString,
|
private static void updateBatteryInfoDischarging(Context context, boolean shortString,
|
||||||
long drainTimeUs, boolean basedOnUsage, BatteryInfo info) {
|
Estimate estimate, BatteryInfo info) {
|
||||||
|
final long drainTimeUs = PowerUtil.convertMsToUs(estimate.estimateMillis);
|
||||||
if (drainTimeUs > 0) {
|
if (drainTimeUs > 0) {
|
||||||
info.remainingTimeUs = drainTimeUs;
|
info.remainingTimeUs = drainTimeUs;
|
||||||
info.remainingLabel = PowerUtil.getBatteryRemainingStringFormatted(
|
info.remainingLabel = PowerUtil.getBatteryRemainingStringFormatted(
|
||||||
context,
|
context,
|
||||||
PowerUtil.convertUsToMs(drainTimeUs),
|
PowerUtil.convertUsToMs(drainTimeUs),
|
||||||
null /* percentageString */,
|
null /* percentageString */,
|
||||||
basedOnUsage && !shortString
|
estimate.isBasedOnUsage && !shortString
|
||||||
);
|
);
|
||||||
info.chargeLabel = PowerUtil.getBatteryRemainingStringFormatted(
|
info.chargeLabel = PowerUtil.getBatteryRemainingStringFormatted(
|
||||||
context,
|
context,
|
||||||
PowerUtil.convertUsToMs(drainTimeUs),
|
PowerUtil.convertUsToMs(drainTimeUs),
|
||||||
info.batteryPercentString,
|
info.batteryPercentString,
|
||||||
basedOnUsage && !shortString
|
estimate.isBasedOnUsage && !shortString
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
info.remainingLabel = null;
|
info.remainingLabel = null;
|
||||||
|
@@ -438,14 +438,15 @@ public class BatteryUtils {
|
|||||||
|
|
||||||
if (estimate != null) {
|
if (estimate != null) {
|
||||||
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false /* shortString */,
|
estimate, elapsedRealtimeUs, false /* shortString */);
|
||||||
PowerUtil.convertMsToUs(estimate.estimateMillis),
|
|
||||||
estimate.isBasedOnUsage);
|
|
||||||
} else {
|
} else {
|
||||||
|
estimate = new Estimate(
|
||||||
|
PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)),
|
||||||
|
false,
|
||||||
|
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN
|
||||||
|
);
|
||||||
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false /* shortString */,
|
estimate, elapsedRealtimeUs, false /* shortString */);
|
||||||
discharging ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0,
|
|
||||||
false /* basedOnUsage */);
|
|
||||||
}
|
}
|
||||||
BatteryUtils.logRuntime(tag, "BatteryInfoLoader.loadInBackground", startTime);
|
BatteryUtils.logRuntime(tag, "BatteryInfoLoader.loadInBackground", startTime);
|
||||||
|
|
||||||
|
@@ -58,12 +58,10 @@ public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
|
|||||||
|
|
||||||
Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
|
Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
|
||||||
if (estimate == null) {
|
if (estimate == null) {
|
||||||
estimate = new Estimate(0, false);
|
estimate = new Estimate(0, false, Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
|
||||||
}
|
}
|
||||||
BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false,
|
estimate, elapsedRealtimeUs, false);
|
||||||
PowerUtil.convertMsToUs(estimate.estimateMillis),
|
|
||||||
estimate.isBasedOnUsage);
|
|
||||||
|
|
||||||
List<BatteryInfo> infos = new ArrayList<>();
|
List<BatteryInfo> infos = new ArrayList<>();
|
||||||
infos.add(oldinfo);
|
infos.add(oldinfo);
|
||||||
|
@@ -2,11 +2,17 @@ package com.android.settings.fuelgauge;
|
|||||||
|
|
||||||
public class Estimate {
|
public class Estimate {
|
||||||
|
|
||||||
public final long estimateMillis;
|
// Value to indicate averageTimeToDischarge could not be obtained
|
||||||
public final boolean isBasedOnUsage;
|
public static final int AVERAGE_TIME_TO_DISCHARGE_UNKNOWN = -1;
|
||||||
|
|
||||||
public Estimate(long estimateMillis, boolean isBasedOnUsage) {
|
public final long estimateMillis;
|
||||||
this.estimateMillis = estimateMillis;
|
public final boolean isBasedOnUsage;
|
||||||
this.isBasedOnUsage = isBasedOnUsage;
|
public final long averageDischargeTime;
|
||||||
}
|
|
||||||
|
public Estimate(long estimateMillis, boolean isBasedOnUsage,
|
||||||
|
long averageDischargeTime) {
|
||||||
|
this.estimateMillis = estimateMillis;
|
||||||
|
this.isBasedOnUsage = isBasedOnUsage;
|
||||||
|
this.averageDischargeTime = averageDischargeTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -63,7 +63,6 @@ public class BatteryInfoTest {
|
|||||||
private static final String STATUS_CHARGING_NO_TIME = "50% - charging";
|
private static final String STATUS_CHARGING_NO_TIME = "50% - charging";
|
||||||
private static final String STATUS_CHARGING_TIME = "50% - 0m until fully charged";
|
private static final String STATUS_CHARGING_TIME = "50% - 0m until fully charged";
|
||||||
private static final String STATUS_NOT_CHARGING = "Not charging";
|
private static final String STATUS_NOT_CHARGING = "Not charging";
|
||||||
private static final int PLUGGED_IN = 1;
|
|
||||||
private static final long REMAINING_TIME_NULL = -1;
|
private static final long REMAINING_TIME_NULL = -1;
|
||||||
private static final long REMAINING_TIME = 2;
|
private static final long REMAINING_TIME = 2;
|
||||||
private static final String ENHANCED_STRING_SUFFIX = "based on your usage";
|
private static final String ENHANCED_STRING_SUFFIX = "based on your usage";
|
||||||
@@ -72,6 +71,11 @@ public class BatteryInfoTest {
|
|||||||
"1m left until fully charged";
|
"1m left until fully charged";
|
||||||
private static final String TEST_BATTERY_LEVEL_10 = "10%";
|
private static final String TEST_BATTERY_LEVEL_10 = "10%";
|
||||||
private static final String FIFTEEN_MIN_FORMATTED = "15m";
|
private static final String FIFTEEN_MIN_FORMATTED = "15m";
|
||||||
|
public static final Estimate DUMMY_ESTIMATE = new Estimate(
|
||||||
|
1000, /* estimateMillis */
|
||||||
|
false, /* isBasedOnUsage */
|
||||||
|
1000 /* averageDischargeTime */);
|
||||||
|
|
||||||
private Intent mDisChargingBatteryBroadcast;
|
private Intent mDisChargingBatteryBroadcast;
|
||||||
private Intent mChargingBatteryBroadcast;
|
private Intent mChargingBatteryBroadcast;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -132,14 +136,15 @@ public class BatteryInfoTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBatteryInfo_basedOnUsageTrueMoreThanFifteenMinutes_usesCorrectString() {
|
public void testGetBatteryInfo_basedOnUsageTrueMoreThanFifteenMinutes_usesCorrectString() {
|
||||||
|
Estimate estimate = new Estimate(Duration.ofHours(4).toMillis(),
|
||||||
|
true /* isBasedOnUsage */,
|
||||||
|
1000 /* averageDischargeTime */);
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */,
|
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||||
PowerUtil.convertMsToUs(Duration.ofHours(4).toMillis()),
|
false /* shortString */);
|
||||||
true /* basedOnUsage */);
|
|
||||||
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */,
|
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||||
PowerUtil.convertMsToUs(Duration.ofHours(4).toMillis()),
|
true /* shortString */);
|
||||||
true /* basedOnUsage */);
|
|
||||||
|
|
||||||
// We only add special mention for the long string
|
// We only add special mention for the long string
|
||||||
assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
|
assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
|
||||||
@@ -149,14 +154,15 @@ public class BatteryInfoTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBatteryInfo_basedOnUsageTrueLessThanSevenMinutes_usesCorrectString() {
|
public void testGetBatteryInfo_basedOnUsageTrueLessThanSevenMinutes_usesCorrectString() {
|
||||||
|
Estimate estimate = new Estimate(Duration.ofMinutes(7).toMillis(),
|
||||||
|
true /* isBasedOnUsage */,
|
||||||
|
1000 /* averageDischargeTime */);
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */,
|
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||||
PowerUtil.convertMsToUs(Duration.ofMinutes(7).toMillis()),
|
false /* shortString */);
|
||||||
true /* basedOnUsage */);
|
|
||||||
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */,
|
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||||
PowerUtil.convertMsToUs(Duration.ofMinutes(7).toMillis()),
|
true /* shortString */);
|
||||||
true /* basedOnUsage */);
|
|
||||||
|
|
||||||
// These should be identical in either case
|
// These should be identical in either case
|
||||||
assertThat(info.remainingLabel.toString()).isEqualTo(
|
assertThat(info.remainingLabel.toString()).isEqualTo(
|
||||||
@@ -167,10 +173,12 @@ public class BatteryInfoTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBatteryInfo_basedOnUsageTrueBetweenSevenAndFifteenMinutes_usesCorrectString() {
|
public void testGetBatteryInfo_basedOnUsageTrueBetweenSevenAndFifteenMinutes_usesCorrectString() {
|
||||||
|
Estimate estimate = new Estimate(Duration.ofMinutes(10).toMillis(),
|
||||||
|
true /* isBasedOnUsage */,
|
||||||
|
1000 /* averageDischargeTime */);
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */,
|
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||||
PowerUtil.convertMsToUs(Duration.ofMinutes(10).toMillis()),
|
false /* shortString */);
|
||||||
true /* basedOnUsage */);
|
|
||||||
|
|
||||||
// Check that strings are showing less than 15 minutes remaining regardless of exact time.
|
// Check that strings are showing less than 15 minutes remaining regardless of exact time.
|
||||||
assertThat(info.chargeLabel.toString()).isEqualTo(
|
assertThat(info.chargeLabel.toString()).isEqualTo(
|
||||||
@@ -184,11 +192,11 @@ public class BatteryInfoTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetBatteryInfo_basedOnUsageFalse_usesDefaultString() {
|
public void testGetBatteryInfo_basedOnUsageFalse_usesDefaultString() {
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */,
|
mBatteryStats, DUMMY_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||||
1000, false /* basedOnUsage */);
|
false /* shortString */);
|
||||||
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, true /* shortString */,
|
mBatteryStats, DUMMY_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||||
1000, false /* basedOnUsage */);
|
true /* shortString */);
|
||||||
|
|
||||||
assertThat(info.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
assertThat(info.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
||||||
assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
||||||
@@ -199,8 +207,10 @@ public class BatteryInfoTest {
|
|||||||
doReturn(TEST_CHARGE_TIME_REMAINING)
|
doReturn(TEST_CHARGE_TIME_REMAINING)
|
||||||
.when(mBatteryStats)
|
.when(mBatteryStats)
|
||||||
.computeChargeTimeRemaining(anyLong());
|
.computeChargeTimeRemaining(anyLong());
|
||||||
|
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false, 1000, false);
|
mBatteryStats, DUMMY_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||||
|
false /* shortString */);
|
||||||
assertThat(info.remainingTimeUs).isEqualTo(TEST_CHARGE_TIME_REMAINING);
|
assertThat(info.remainingTimeUs).isEqualTo(TEST_CHARGE_TIME_REMAINING);
|
||||||
assertThat(info.remainingLabel.toString())
|
assertThat(info.remainingLabel.toString())
|
||||||
.isEqualTo(TEST_CHARGE_TIME_REMAINING_STRINGIFIED);
|
.isEqualTo(TEST_CHARGE_TIME_REMAINING_STRINGIFIED);
|
||||||
@@ -211,8 +221,8 @@ public class BatteryInfoTest {
|
|||||||
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 100);
|
mChargingBatteryBroadcast.putExtra(BatteryManager.EXTRA_LEVEL, 100);
|
||||||
|
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false /* shortString */,
|
mBatteryStats, DUMMY_ESTIMATE, SystemClock.elapsedRealtime() * 1000,
|
||||||
1000, false /* basedOnUsage */);
|
false /* shortString */);
|
||||||
|
|
||||||
assertThat(info.chargeLabel).isEqualTo("100%");
|
assertThat(info.chargeLabel).isEqualTo("100%");
|
||||||
}
|
}
|
||||||
@@ -296,10 +306,13 @@ public class BatteryInfoTest {
|
|||||||
} else {
|
} else {
|
||||||
doReturn(0L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
|
doReturn(0L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
|
||||||
}
|
}
|
||||||
|
Estimate batteryEstimate = new Estimate(
|
||||||
|
estimate ? 1000 : 0,
|
||||||
|
false /* isBasedOnUsage */,
|
||||||
|
1000 /* averageDischargeTime */);
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext,
|
||||||
charging ? mChargingBatteryBroadcast : mDisChargingBatteryBroadcast,
|
charging ? mChargingBatteryBroadcast : mDisChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false,
|
mBatteryStats, batteryEstimate, SystemClock.elapsedRealtime() * 1000, false);
|
||||||
estimate ? 1000 : 0 /* drainTimeUs */, false);
|
|
||||||
doReturn(enhanced).when(mFeatureFactory.powerUsageFeatureProvider)
|
doReturn(enhanced).when(mFeatureFactory.powerUsageFeatureProvider)
|
||||||
.isEnhancedBatteryPredictionEnabled(mContext);
|
.isEnhancedBatteryPredictionEnabled(mContext);
|
||||||
return info;
|
return info;
|
||||||
|
Reference in New Issue
Block a user