Merge "Fix BatteryInfo using enhanced estimate for charge time" into oc-dr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ed66c5fcdf
@@ -137,11 +137,15 @@ public class BatteryInfo {
|
||||
final BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
|
||||
final long elapsedRealtimeUs =
|
||||
batteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
||||
|
||||
Intent batteryBroadcast = context.registerReceiver(null,
|
||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
BatteryUtils utils = BatteryUtils.getInstance(context);
|
||||
|
||||
if (provider != null && provider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||
// 0 means we are discharging, anything else means charging
|
||||
boolean discharging =
|
||||
batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
|
||||
if (discharging && provider != null
|
||||
&& provider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, shortString,
|
||||
utils.convertMsToUs(provider.getEnhancedBatteryPrediction(context)),
|
||||
@@ -149,7 +153,8 @@ public class BatteryInfo {
|
||||
} else {
|
||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, shortString,
|
||||
stats.computeBatteryTimeRemaining(elapsedRealtimeUs), false);
|
||||
discharging ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +216,7 @@ public class BatteryInfo {
|
||||
if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
|
||||
info.remainingTimeUs = chargeTime;
|
||||
CharSequence timeString = Utils.formatElapsedTime(context,
|
||||
batteryUtils.convertUsToMs(drainTimeUs), 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(
|
||||
|
@@ -20,6 +20,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.SystemClock;
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
@@ -57,9 +58,12 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
||||
final long elapsedRealtimeUs = batteryUtils.convertMsToUs(SystemClock.elapsedRealtime());
|
||||
BatteryInfo batteryInfo;
|
||||
|
||||
// Get enhanced prediction if available, otherwise use the old prediction code
|
||||
// 0 means we are discharging, anything else means charging
|
||||
boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
|
||||
// Get enhanced prediction if available and discharging, otherwise use the old code
|
||||
Cursor cursor = null;
|
||||
if (powerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||
if (discharging && powerUsageFeatureProvider != null &&
|
||||
powerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||
final Uri queryUri = powerUsageFeatureProvider.getEnhancedBatteryPredictionUri();
|
||||
cursor = context.getContentResolver().query(queryUri, null, null, null, null);
|
||||
}
|
||||
@@ -72,7 +76,8 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
||||
BatteryStats stats = mStatsHelper.getStats();
|
||||
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, false /* shortString */,
|
||||
stats.computeBatteryTimeRemaining(elapsedRealtimeUs), false /* basedOnUsage */);
|
||||
discharging ? 0 : stats.computeBatteryTimeRemaining(elapsedRealtimeUs),
|
||||
false /* basedOnUsage */);
|
||||
}
|
||||
|
||||
return batteryInfo;
|
||||
|
@@ -769,11 +769,8 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
||||
|
||||
@VisibleForTesting
|
||||
void restartBatteryInfoLoader() {
|
||||
if (mPowerFeatureProvider != null
|
||||
&& mPowerFeatureProvider.isEnhancedBatteryPredictionEnabled(getContext())) {
|
||||
getLoaderManager().restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
|
||||
mBatteryInfoLoaderCallbacks);
|
||||
}
|
||||
getLoaderManager().restartLoader(BATTERY_INFO_LOADER, Bundle.EMPTY,
|
||||
mBatteryInfoLoaderCallbacks);
|
||||
}
|
||||
|
||||
private static List<BatterySipper> getFakeStats() {
|
||||
|
Reference in New Issue
Block a user