Make utility methods static.
BatteryUtils.convertUsToMs and .convertMsToUs should be static, and now they are. Bug: 63347148 Test: make RunSettingsRoboTests Change-Id: If652e2d3e1260df9a933805d7da670fbb26b2c25
This commit is contained in:
@@ -136,13 +136,11 @@ public class BatteryInfo {
|
|||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
PowerUsageFeatureProvider provider =
|
PowerUsageFeatureProvider provider =
|
||||||
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
||||||
final BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
|
|
||||||
final long elapsedRealtimeUs =
|
final long elapsedRealtimeUs =
|
||||||
batteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
BatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
||||||
|
|
||||||
Intent batteryBroadcast = context.registerReceiver(null,
|
Intent batteryBroadcast = context.registerReceiver(null,
|
||||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
BatteryUtils utils = BatteryUtils.getInstance(context);
|
|
||||||
// 0 means we are discharging, anything else means charging
|
// 0 means we are discharging, anything else means charging
|
||||||
boolean discharging =
|
boolean discharging =
|
||||||
batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
|
batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
|
||||||
@@ -152,7 +150,8 @@ public class BatteryInfo {
|
|||||||
final long prediction = provider.getEnhancedBatteryPrediction(context);
|
final long prediction = provider.getEnhancedBatteryPrediction(context);
|
||||||
BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
||||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, shortString, utils.convertMsToUs(prediction), true);
|
elapsedRealtimeUs, shortString, BatteryUtils.convertMsToUs(prediction),
|
||||||
|
true);
|
||||||
} else {
|
} else {
|
||||||
long prediction = discharging
|
long prediction = discharging
|
||||||
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
||||||
@@ -187,14 +186,13 @@ public class BatteryInfo {
|
|||||||
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
|
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
|
||||||
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
final BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
|
|
||||||
|
|
||||||
info.statusLabel = Utils.getBatteryStatus(resources, batteryBroadcast);
|
info.statusLabel = Utils.getBatteryStatus(resources, batteryBroadcast);
|
||||||
if (!info.mCharging) {
|
if (!info.mCharging) {
|
||||||
if (drainTimeUs > 0) {
|
if (drainTimeUs > 0) {
|
||||||
info.remainingTimeUs = drainTimeUs;
|
info.remainingTimeUs = drainTimeUs;
|
||||||
CharSequence timeString = Utils.formatElapsedTime(context,
|
CharSequence timeString = Utils.formatElapsedTime(context,
|
||||||
batteryUtils.convertUsToMs(drainTimeUs), false /* withSeconds */);
|
BatteryUtils.convertUsToMs(drainTimeUs), false /* withSeconds */);
|
||||||
info.remainingLabel = TextUtils.expandTemplate(context.getText(shortString ?
|
info.remainingLabel = TextUtils.expandTemplate(context.getText(shortString ?
|
||||||
(basedOnUsage ?
|
(basedOnUsage ?
|
||||||
R.string.power_remaining_duration_only_short_enhanced :
|
R.string.power_remaining_duration_only_short_enhanced :
|
||||||
@@ -221,7 +219,7 @@ public class BatteryInfo {
|
|||||||
if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
|
if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
|
||||||
info.remainingTimeUs = chargeTime;
|
info.remainingTimeUs = chargeTime;
|
||||||
CharSequence timeString = Utils.formatElapsedTime(context,
|
CharSequence timeString = Utils.formatElapsedTime(context,
|
||||||
batteryUtils.convertUsToMs(chargeTime), false /* withSeconds */);
|
BatteryUtils.convertUsToMs(chargeTime), false /* withSeconds */);
|
||||||
int resId = shortString ? R.string.power_charging_duration_short
|
int resId = shortString ? R.string.power_charging_duration_short
|
||||||
: R.string.power_charging_duration;
|
: R.string.power_charging_duration;
|
||||||
info.remainingLabel = TextUtils.expandTemplate(context.getText(
|
info.remainingLabel = TextUtils.expandTemplate(context.getText(
|
||||||
|
@@ -55,10 +55,9 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
|||||||
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
||||||
|
|
||||||
// Stuff we always need to get BatteryInfo
|
// Stuff we always need to get BatteryInfo
|
||||||
BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
|
|
||||||
Intent batteryBroadcast = getContext().registerReceiver(null,
|
Intent batteryBroadcast = getContext().registerReceiver(null,
|
||||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
final long elapsedRealtimeUs = batteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
final long elapsedRealtimeUs = BatteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
||||||
BatteryInfo batteryInfo;
|
BatteryInfo batteryInfo;
|
||||||
|
|
||||||
// 0 means we are discharging, anything else means charging
|
// 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);
|
cursor = context.getContentResolver().query(queryUri, null, null, null, null);
|
||||||
}
|
}
|
||||||
BatteryStats stats = mStatsHelper.getStats();
|
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()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
long enhancedEstimate = powerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
|
long enhancedEstimate = powerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
|
||||||
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false /* shortString */,
|
elapsedRealtimeUs, false /* shortString */,
|
||||||
batteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
|
BatteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
|
||||||
} else {
|
} else {
|
||||||
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false /* shortString */,
|
elapsedRealtimeUs, false /* shortString */,
|
||||||
discharging ? 0 : stats.computeBatteryTimeRemaining(elapsedRealtimeUs),
|
discharging ? 0 : stats.computeBatteryTimeRemaining(elapsedRealtimeUs),
|
||||||
false /* basedOnUsage */);
|
false /* basedOnUsage */);
|
||||||
}
|
}
|
||||||
batteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader.loadInBackground", startTime);
|
BatteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader.loadInBackground", startTime);
|
||||||
return batteryInfo;
|
return batteryInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -320,11 +320,11 @@ public class BatteryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long convertUsToMs(long timeUs) {
|
public static long convertUsToMs(long timeUs) {
|
||||||
return timeUs / 1000;
|
return timeUs / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long convertMsToUs(long timeMs) {
|
public static long convertMsToUs(long timeMs) {
|
||||||
return timeMs * 1000;
|
return timeMs * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,8 +46,7 @@ public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
|
|||||||
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
||||||
|
|
||||||
// get stuff we'll need for both BatteryInfo
|
// 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,
|
Intent batteryBroadcast = getContext().registerReceiver(null,
|
||||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
BatteryStats stats = mStatsHelper.getStats();
|
BatteryStats stats = mStatsHelper.getStats();
|
||||||
@@ -55,7 +54,7 @@ public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
|
|||||||
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
|
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
|
||||||
stats, elapsedRealtimeUs, false);
|
stats, elapsedRealtimeUs, false);
|
||||||
|
|
||||||
final long timeRemainingEnhanced = batteryUtils.convertMsToUs(
|
final long timeRemainingEnhanced = BatteryUtils.convertMsToUs(
|
||||||
powerUsageFeatureProvider.getEnhancedBatteryPrediction(getContext()));
|
powerUsageFeatureProvider.getEnhancedBatteryPrediction(getContext()));
|
||||||
BatteryInfo newinfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
BatteryInfo newinfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false, timeRemainingEnhanced, true);
|
elapsedRealtimeUs, false, timeRemainingEnhanced, true);
|
||||||
|
@@ -24,7 +24,6 @@ import android.content.Loader;
|
|||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
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.
|
// be unplugged for a period of time before being willing ot make an estimate.
|
||||||
summary1.setText(mPowerFeatureProvider.getOldEstimateDebugString(
|
summary1.setText(mPowerFeatureProvider.getOldEstimateDebugString(
|
||||||
Formatter.formatShortElapsedTime(getContext(),
|
Formatter.formatShortElapsedTime(getContext(),
|
||||||
mBatteryUtils.convertUsToMs(oldInfo.remainingTimeUs))));
|
BatteryUtils.convertUsToMs(oldInfo.remainingTimeUs))));
|
||||||
|
|
||||||
// for this one we can just set the string directly
|
// for this one we can just set the string directly
|
||||||
summary2.setText(mPowerFeatureProvider.getEnhancedEstimateDebugString(
|
summary2.setText(mPowerFeatureProvider.getEnhancedEstimateDebugString(
|
||||||
Formatter.formatShortElapsedTime(getContext(),
|
Formatter.formatShortElapsedTime(getContext(),
|
||||||
mBatteryUtils.convertUsToMs(newInfo.remainingTimeUs))));
|
BatteryUtils.convertUsToMs(newInfo.remainingTimeUs))));
|
||||||
|
|
||||||
batteryView.setBatteryLevel(oldInfo.batteryLevel);
|
batteryView.setBatteryLevel(oldInfo.batteryLevel);
|
||||||
batteryView.setCharging(!oldInfo.discharging);
|
batteryView.setCharging(!oldInfo.discharging);
|
||||||
|
@@ -160,7 +160,7 @@ public class BatteryInfoTest {
|
|||||||
.computeChargeTimeRemaining(anyLong());
|
.computeChargeTimeRemaining(anyLong());
|
||||||
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mChargingBatteryBroadcast,
|
||||||
mBatteryStats, SystemClock.elapsedRealtime() * 1000, false, 1000, false);
|
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())
|
assertThat(info.remainingLabel.toString())
|
||||||
.isEqualTo(TEST_CHARGE_TIME_REMAINING_STRINGIFIED);
|
.isEqualTo(TEST_CHARGE_TIME_REMAINING_STRINGIFIED);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user