Search in sources :

Example 6 with Estimate

use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryInfoTest method testGetBatteryInfo_basedOnUsageTrueBetweenSevenAndFifteenMinutes_usesCorrectString.

@Test
public void testGetBatteryInfo_basedOnUsageTrueBetweenSevenAndFifteenMinutes_usesCorrectString() {
    Estimate estimate = new Estimate(Duration.ofMinutes(10).toMillis(), true, /* isBasedOnUsage */
    1000);
    BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast, mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000, false);
    // Check that strings are showing less than 15 minutes remaining regardless of exact time.
    assertThat(info.chargeLabel.toString()).isEqualTo(mContext.getString(R.string.power_remaining_less_than_duration, FIFTEEN_MIN_FORMATTED, TEST_BATTERY_LEVEL_10));
    assertThat(info.remainingLabel.toString()).isEqualTo(mContext.getString(R.string.power_remaining_less_than_duration_only, FIFTEEN_MIN_FORMATTED));
}
Also used : Estimate(com.android.settingslib.fuelgauge.Estimate) Test(org.junit.Test)

Example 7 with Estimate

use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryInfoTest method testGetBatteryInfo_basedOnUsageTrueMoreThanFifteenMinutes_usesCorrectString.

@Test
public void testGetBatteryInfo_basedOnUsageTrueMoreThanFifteenMinutes_usesCorrectString() {
    Estimate estimate = new Estimate(Duration.ofHours(4).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);
    // We only add special mention for the long string
    assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
    assertThat(info.suggestionLabel).contains(EXTEND_PREFIX);
    // shortened string should not have extra text
    assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
    assertThat(info2.suggestionLabel).contains(EXTEND_PREFIX);
}
Also used : Estimate(com.android.settingslib.fuelgauge.Estimate) Test(org.junit.Test)

Example 8 with Estimate

use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DebugEstimatesLoader method loadInBackground.

@Override
public List<BatteryInfo> loadInBackground() {
    Context context = getContext();
    PowerUsageFeatureProvider powerUsageFeatureProvider = FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
    // get stuff we'll need for both BatteryInfo
    final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
    Intent batteryBroadcast = getContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    BatteryStats stats = mStatsHelper.getStats();
    BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast, stats, elapsedRealtimeUs, false);
    Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
    if (estimate == null) {
        estimate = new Estimate(0, false, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
    }
    BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats, estimate, elapsedRealtimeUs, false);
    List<BatteryInfo> infos = new ArrayList<>();
    infos.add(oldinfo);
    infos.add(newInfo);
    return infos;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) ArrayList(java.util.ArrayList) Intent(android.content.Intent) BatteryStats(android.os.BatteryStats)

Example 9 with Estimate

use of com.android.settingslib.fuelgauge.Estimate in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryInfo method getBatteryInfo.

public static BatteryInfo getBatteryInfo(final Context context, final BatteryStatsHelper statsHelper, boolean shortString) {
    final BatteryStats stats;
    final long batteryStatsTime = System.currentTimeMillis();
    if (statsHelper == null) {
        final BatteryStatsHelper localStatsHelper = new BatteryStatsHelper(context, true);
        localStatsHelper.create((Bundle) null);
        stats = localStatsHelper.getStats();
    } else {
        stats = statsHelper.getStats();
    }
    BatteryUtils.logRuntime(LOG_TAG, "time for getStats", batteryStatsTime);
    final long startTime = System.currentTimeMillis();
    PowerUsageFeatureProvider provider = FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
    final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
    final Intent batteryBroadcast = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    // 0 means we are discharging, anything else means charging
    final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
    if (discharging && provider != null && provider.isEnhancedBatteryPredictionEnabled(context)) {
        Estimate estimate = provider.getEnhancedBatteryPrediction(context);
        if (estimate != null) {
            Estimate.storeCachedEstimate(context, estimate);
            BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
            return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString);
        }
    }
    final long prediction = discharging ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
    final Estimate estimate = new Estimate(PowerUtil.convertUsToMs(prediction), false, /* isBasedOnUsage */
    EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
    BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
    return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString);
}
Also used : IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) Intent(android.content.Intent) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) BatteryStats(android.os.BatteryStats)

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