Make utility methods static. am: 43d4fefb36

am: cc56b1aa04

Change-Id: Ia1ebdff4fcd82f829e90f76bf7d49b0adbc8febc
This commit is contained in:
Alex Kulesza
2017-07-06 01:36:33 +00:00
committed by android-build-merger
6 changed files with 16 additions and 21 deletions

View File

@@ -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(

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -160,7 +160,7 @@ public class BatteryInfoTest {
.computeChargeTimeRemaining(anyLong());
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false, 1000, false);
assertThat(info.remainingTimeUs = TEST_CHARGE_TIME_REMAINING);
assertThat(info.remainingTimeUs).isEqualTo(TEST_CHARGE_TIME_REMAINING);
assertThat(info.remainingLabel.toString())
.isEqualTo(TEST_CHARGE_TIME_REMAINING_STRINGIFIED);
}