Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43d4fefb authored by Alex Kulesza's avatar Alex Kulesza
Browse files

Make utility methods static.

BatteryUtils.convertUsToMs and .convertMsToUs should be static, and now
they are.

Bug: 63347148
Test: make RunSettingsRoboTests
Change-Id: If652e2d3e1260df9a933805d7da670fbb26b2c25
parent 6d505764
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -136,13 +136,11 @@ public class BatteryInfo {
                final long startTime = System.currentTimeMillis();
                PowerUsageFeatureProvider provider =
                        FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
                final BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
                final long elapsedRealtimeUs =
                        batteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
                        BatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());

                Intent batteryBroadcast = context.registerReceiver(null,
                        new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
                BatteryUtils utils = BatteryUtils.getInstance(context);
                // 0 means we are discharging, anything else means charging
                boolean discharging =
                        batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
@@ -152,7 +150,8 @@ public class BatteryInfo {
                    final long prediction = provider.getEnhancedBatteryPrediction(context);
                    BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
                    return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
                            elapsedRealtimeUs, shortString, utils.convertMsToUs(prediction), true);
                            elapsedRealtimeUs, shortString, BatteryUtils.convertMsToUs(prediction),
                            true);
                } else {
                    long prediction = discharging
                            ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
@@ -187,14 +186,13 @@ public class BatteryInfo {
        info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
        info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
        final Resources resources = context.getResources();
        final BatteryUtils batteryUtils = BatteryUtils.getInstance(context);

        info.statusLabel = Utils.getBatteryStatus(resources, batteryBroadcast);
        if (!info.mCharging) {
            if (drainTimeUs > 0) {
                info.remainingTimeUs = drainTimeUs;
                CharSequence timeString = Utils.formatElapsedTime(context,
                        batteryUtils.convertUsToMs(drainTimeUs), false /* withSeconds */);
                        BatteryUtils.convertUsToMs(drainTimeUs), false /* withSeconds */);
                info.remainingLabel = TextUtils.expandTemplate(context.getText(shortString ?
                        (basedOnUsage ?
                                R.string.power_remaining_duration_only_short_enhanced :
@@ -221,7 +219,7 @@ public class BatteryInfo {
            if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
                info.remainingTimeUs = chargeTime;
                CharSequence timeString = Utils.formatElapsedTime(context,
                        batteryUtils.convertUsToMs(chargeTime), false /* withSeconds */);
                        BatteryUtils.convertUsToMs(chargeTime), false /* withSeconds */);
                int resId = shortString ? R.string.power_charging_duration_short
                        : R.string.power_charging_duration;
                info.remainingLabel = TextUtils.expandTemplate(context.getText(
+4 −5
Original line number Diff line number Diff line
@@ -55,10 +55,9 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
                FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);

        // Stuff we always need to get BatteryInfo
        BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
        Intent batteryBroadcast = getContext().registerReceiver(null,
                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        final long elapsedRealtimeUs = batteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
        final long elapsedRealtimeUs = BatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
        BatteryInfo batteryInfo;

        // 0 means we are discharging, anything else means charging
@@ -71,19 +70,19 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
            cursor = context.getContentResolver().query(queryUri, null, null, null, null);
        }
        BatteryStats stats = mStatsHelper.getStats();
        batteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader post query", startTime);
        BatteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader post query", startTime);
        if (cursor != null && cursor.moveToFirst()) {
            long enhancedEstimate = powerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
            batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
                    elapsedRealtimeUs, false /* shortString */,
                    batteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
                    BatteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
        } else {
            batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
                    elapsedRealtimeUs, false /* shortString */,
                    discharging ? 0 : stats.computeBatteryTimeRemaining(elapsedRealtimeUs),
                    false /* basedOnUsage */);
        }
        batteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader.loadInBackground", startTime);
        BatteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader.loadInBackground", startTime);
        return batteryInfo;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -320,11 +320,11 @@ public class BatteryUtils {
        }
    }

    public long convertUsToMs(long timeUs) {
    public static long convertUsToMs(long timeUs) {
        return timeUs / 1000;
    }

    public long convertMsToUs(long timeMs) {
    public static long convertMsToUs(long timeMs) {
        return timeMs * 1000;
    }

+2 −3
Original line number Diff line number Diff line
@@ -46,8 +46,7 @@ public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
                FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);

        // get stuff we'll need for both BatteryInfo
        BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
        final long elapsedRealtimeUs = batteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
        final long elapsedRealtimeUs = BatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
        Intent batteryBroadcast = getContext().registerReceiver(null,
                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
        BatteryStats stats = mStatsHelper.getStats();
@@ -55,7 +54,7 @@ public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
        BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
                stats, elapsedRealtimeUs, false);

        final long timeRemainingEnhanced = batteryUtils.convertMsToUs(
        final long timeRemainingEnhanced = BatteryUtils.convertMsToUs(
                powerUsageFeatureProvider.getEnhancedBatteryPrediction(getContext()));
        BatteryInfo newinfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
                elapsedRealtimeUs, false, timeRemainingEnhanced, true);
+2 −3
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.Loader;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.BatteryStats;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -206,12 +205,12 @@ public class PowerUsageSummary extends PowerUsageBase implements
                    // be unplugged for a period of time before being willing ot make an estimate.
                    summary1.setText(mPowerFeatureProvider.getOldEstimateDebugString(
                            Formatter.formatShortElapsedTime(getContext(),
                                    mBatteryUtils.convertUsToMs(oldInfo.remainingTimeUs))));
                                    BatteryUtils.convertUsToMs(oldInfo.remainingTimeUs))));

                    // for this one we can just set the string directly
                    summary2.setText(mPowerFeatureProvider.getEnhancedEstimateDebugString(
                            Formatter.formatShortElapsedTime(getContext(),
                                    mBatteryUtils.convertUsToMs(newInfo.remainingTimeUs))));
                                    BatteryUtils.convertUsToMs(newInfo.remainingTimeUs))));

                    batteryView.setBatteryLevel(oldInfo.batteryLevel);
                    batteryView.setCharging(!oldInfo.discharging);
Loading