Merge "Add BatteryInfo logging to settings" into oc-dr1-dev

This commit is contained in:
TreeHugger Robot
2017-06-30 21:58:38 +00:00
committed by Android (Google) Code Review
3 changed files with 24 additions and 10 deletions

View File

@@ -46,6 +46,7 @@ public class BatteryInfo {
public String statusLabel;
private boolean mCharging;
private BatteryStats mStats;
private static final String LOG_TAG = "BatteryInfo";
private long timePeriod;
public interface Callback {
@@ -132,6 +133,7 @@ public class BatteryInfo {
new AsyncTask<Void, Void, BatteryInfo>() {
@Override
protected BatteryInfo doInBackground(Void... params) {
final long startTime = System.currentTimeMillis();
PowerUsageFeatureProvider provider =
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
final BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
@@ -144,17 +146,19 @@ public class BatteryInfo {
// 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)) {
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(provider.getEnhancedBatteryPrediction(context)),
true);
elapsedRealtimeUs, shortString, utils.convertMsToUs(prediction), true);
} else {
long prediction = discharging
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
elapsedRealtimeUs, shortString,
discharging ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0,
false);
elapsedRealtimeUs, shortString, prediction, false);
}
}
@@ -176,6 +180,7 @@ public class BatteryInfo {
public static BatteryInfo getBatteryInfo(Context context, Intent batteryBroadcast,
BatteryStats stats, long elapsedRealtimeUs, boolean shortString, long drainTimeUs,
boolean basedOnUsage) {
final long startTime = System.currentTimeMillis();
BatteryInfo info = new BatteryInfo();
info.mStats = stats;
info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
@@ -232,6 +237,7 @@ public class BatteryInfo {
chargeStatusLabel);
}
}
BatteryUtils.logRuntime(LOG_TAG, "time for getBatteryInfo", startTime);
return info;
}

View File

@@ -33,7 +33,9 @@ import com.android.settings.utils.AsyncLoader;
* when not available.
*/
public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
BatteryStatsHelper mStatsHelper;
private static final String LOG_TAG = "BatteryInfoLoader";
public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
super(context);
@@ -47,6 +49,7 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
@Override
public BatteryInfo loadInBackground() {
final long startTime = System.currentTimeMillis();
Context context = getContext();
PowerUsageFeatureProvider powerUsageFeatureProvider =
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
@@ -67,19 +70,20 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
final Uri queryUri = powerUsageFeatureProvider.getEnhancedBatteryPredictionUri();
cursor = context.getContentResolver().query(queryUri, null, null, null, null);
}
BatteryStats stats = mStatsHelper.getStats();
batteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader post query", startTime);
if (cursor != null && cursor.moveToFirst()) {
long enhancedEstimate = powerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast,
mStatsHelper.getStats(), elapsedRealtimeUs, false /* shortString */,
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
elapsedRealtimeUs, false /* shortString */,
batteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
} else {
BatteryStats stats = mStatsHelper.getStats();
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
elapsedRealtimeUs, false /* shortString */,
discharging ? 0 : stats.computeBatteryTimeRemaining(elapsedRealtimeUs),
false /* basedOnUsage */);
}
batteryUtils.logRuntime(LOG_TAG, "BatteryInfoLoader.loadInBackground", startTime);
return batteryInfo;
}
}

View File

@@ -285,6 +285,10 @@ public class BatteryUtils {
}
public static void logRuntime(String tag, String message, long startTime) {
Log.d(tag, message + ": " + (System.currentTimeMillis() - startTime) + "ms");
}
/**
* Find package uid from package name
*