use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryUtilsTest method getEnhancedEstimate_doesNotUpdateCache_ifEstimateFresh.
@Test
public void getEnhancedEstimate_doesNotUpdateCache_ifEstimateFresh() {
Estimate estimate = new Estimate(1000, true, 1000);
Estimate.storeCachedEstimate(mContext, estimate);
estimate = mBatteryUtils.getEnhancedEstimate();
// only pass if estimate has not changed
assertThat(estimate).isNotNull();
assertThat(estimate.isBasedOnUsage()).isTrue();
assertThat(estimate.getAverageDischargeTime()).isEqualTo(1000);
}
use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryInfoTest method testGetBatteryInfo_basedOnUsageTrueLessThanSevenMinutes_usesCorrectString.
@Test
public void testGetBatteryInfo_basedOnUsageTrueLessThanSevenMinutes_usesCorrectString() {
Estimate estimate = new Estimate(Duration.ofMinutes(7).toMillis(), true, /* isBasedOnUsage */
1000);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast, mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000, false);
BatteryInfo info2 = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast, mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000, true);
// These should be identical in either case
assertThat(info.remainingLabel.toString()).isEqualTo(mContext.getString(R.string.power_remaining_duration_only_shutdown_imminent));
assertThat(info2.remainingLabel.toString()).isEqualTo(mContext.getString(R.string.power_remaining_duration_only_shutdown_imminent));
assertThat(info2.suggestionLabel).contains(EXTEND_PREFIX);
}
use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryInfoTest method getBatteryInfo_MoreThanOneDay_suggestionLabelIsCorrectString.
@Test
public void getBatteryInfo_MoreThanOneDay_suggestionLabelIsCorrectString() {
Estimate estimate = new Estimate(Duration.ofDays(3).toMillis(), true, /* isBasedOnUsage */
1000);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast, mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000, false);
assertThat(info.suggestionLabel).doesNotContain(EXTEND_PREFIX);
}
use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryInfoTest method getBatteryInfo.
private BatteryInfo getBatteryInfo(boolean charging, boolean enhanced, boolean estimate) {
if (charging && estimate) {
doReturn(1000L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
} else {
doReturn(0L).when(mBatteryStats).computeChargeTimeRemaining(anyLong());
}
Estimate batteryEstimate = new Estimate(estimate ? 1000 : 0, false, /* isBasedOnUsage */
1000);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, charging ? mChargingBatteryBroadcast : mDisChargingBatteryBroadcast, mBatteryStats, batteryEstimate, SystemClock.elapsedRealtime() * 1000, false);
doReturn(enhanced).when(mFeatureFactory.powerUsageFeatureProvider).isEnhancedBatteryPredictionEnabled(mContext);
return info;
}
use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryUtils method getBatteryInfo.
@WorkerThread
public BatteryInfo getBatteryInfo(final BatteryStatsHelper statsHelper, final String tag) {
final long startTime = System.currentTimeMillis();
// Stuff we always need to get BatteryInfo
final Intent batteryBroadcast = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
final BatteryStats stats = statsHelper.getStats();
BatteryInfo batteryInfo;
Estimate estimate = getEnhancedEstimate();
// couldn't get estimate from cache or provider, use fallback
if (estimate == null) {
estimate = new Estimate(PowerUtil.convertUsToMs(stats.computeBatteryTimeRemaining(elapsedRealtimeUs)), false, /* isBasedOnUsage */
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
}
BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats, estimate, elapsedRealtimeUs, false);
BatteryUtils.logRuntime(tag, "BatteryInfoLoader.loadInBackground", startTime);
return batteryInfo;
}
Aggregations