Search in sources :

Example 1 with Estimate

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);
}
Also used : Estimate(com.android.settingslib.fuelgauge.Estimate) Test(org.junit.Test)

Example 2 with Estimate

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);
}
Also used : Estimate(com.android.settingslib.fuelgauge.Estimate) Test(org.junit.Test)

Example 3 with Estimate

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);
}
Also used : Estimate(com.android.settingslib.fuelgauge.Estimate) Test(org.junit.Test)

Example 4 with Estimate

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;
}
Also used : Estimate(com.android.settingslib.fuelgauge.Estimate)

Example 5 with Estimate

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;
}
Also used : IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) Intent(android.content.Intent) BatteryStats(android.os.BatteryStats) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

Estimate (com.android.settingslib.fuelgauge.Estimate)9 Test (org.junit.Test)5 Intent (android.content.Intent)3 IntentFilter (android.content.IntentFilter)3 BatteryStats (android.os.BatteryStats)3 Context (android.content.Context)1 WorkerThread (androidx.annotation.WorkerThread)1 BatteryStatsHelper (com.android.internal.os.BatteryStatsHelper)1 ArrayList (java.util.ArrayList)1