Merge "Add BatteryInfo logging to settings" into oc-dr1-dev
am: 9a3b115cc8
Change-Id: I447d0d7689f77b12a0caf9374155883217ff330a
This commit is contained in:
@@ -46,6 +46,7 @@ public class BatteryInfo {
|
|||||||
public String statusLabel;
|
public String statusLabel;
|
||||||
private boolean mCharging;
|
private boolean mCharging;
|
||||||
private BatteryStats mStats;
|
private BatteryStats mStats;
|
||||||
|
private static final String LOG_TAG = "BatteryInfo";
|
||||||
private long timePeriod;
|
private long timePeriod;
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
@@ -132,6 +133,7 @@ public class BatteryInfo {
|
|||||||
new AsyncTask<Void, Void, BatteryInfo>() {
|
new AsyncTask<Void, Void, BatteryInfo>() {
|
||||||
@Override
|
@Override
|
||||||
protected BatteryInfo doInBackground(Void... params) {
|
protected BatteryInfo doInBackground(Void... params) {
|
||||||
|
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 BatteryUtils batteryUtils = BatteryUtils.getInstance(context);
|
||||||
@@ -144,17 +146,19 @@ public class BatteryInfo {
|
|||||||
// 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;
|
||||||
|
|
||||||
if (discharging && provider != null
|
if (discharging && provider != null
|
||||||
&& provider.isEnhancedBatteryPredictionEnabled(context)) {
|
&& provider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||||
|
final long prediction = provider.getEnhancedBatteryPrediction(context);
|
||||||
|
BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
||||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, shortString,
|
elapsedRealtimeUs, shortString, utils.convertMsToUs(prediction), true);
|
||||||
utils.convertMsToUs(provider.getEnhancedBatteryPrediction(context)),
|
|
||||||
true);
|
|
||||||
} else {
|
} else {
|
||||||
|
long prediction = discharging
|
||||||
|
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
||||||
|
BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
|
||||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, shortString,
|
elapsedRealtimeUs, shortString, prediction, false);
|
||||||
discharging ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0,
|
|
||||||
false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +180,7 @@ public class BatteryInfo {
|
|||||||
public static BatteryInfo getBatteryInfo(Context context, Intent batteryBroadcast,
|
public static BatteryInfo getBatteryInfo(Context context, Intent batteryBroadcast,
|
||||||
BatteryStats stats, long elapsedRealtimeUs, boolean shortString, long drainTimeUs,
|
BatteryStats stats, long elapsedRealtimeUs, boolean shortString, long drainTimeUs,
|
||||||
boolean basedOnUsage) {
|
boolean basedOnUsage) {
|
||||||
|
final long startTime = System.currentTimeMillis();
|
||||||
BatteryInfo info = new BatteryInfo();
|
BatteryInfo info = new BatteryInfo();
|
||||||
info.mStats = stats;
|
info.mStats = stats;
|
||||||
info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
|
info.batteryLevel = Utils.getBatteryLevel(batteryBroadcast);
|
||||||
@@ -232,6 +237,7 @@ public class BatteryInfo {
|
|||||||
chargeStatusLabel);
|
chargeStatusLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BatteryUtils.logRuntime(LOG_TAG, "time for getBatteryInfo", startTime);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,7 +33,9 @@ import com.android.settings.utils.AsyncLoader;
|
|||||||
* when not available.
|
* when not available.
|
||||||
*/
|
*/
|
||||||
public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
||||||
|
|
||||||
BatteryStatsHelper mStatsHelper;
|
BatteryStatsHelper mStatsHelper;
|
||||||
|
private static final String LOG_TAG = "BatteryInfoLoader";
|
||||||
|
|
||||||
public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
|
public BatteryInfoLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -47,6 +49,7 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BatteryInfo loadInBackground() {
|
public BatteryInfo loadInBackground() {
|
||||||
|
final long startTime = System.currentTimeMillis();
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
PowerUsageFeatureProvider powerUsageFeatureProvider =
|
PowerUsageFeatureProvider powerUsageFeatureProvider =
|
||||||
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
|
||||||
@@ -67,19 +70,20 @@ public class BatteryInfoLoader extends AsyncLoader<BatteryInfo>{
|
|||||||
final Uri queryUri = powerUsageFeatureProvider.getEnhancedBatteryPredictionUri();
|
final Uri queryUri = powerUsageFeatureProvider.getEnhancedBatteryPredictionUri();
|
||||||
cursor = context.getContentResolver().query(queryUri, null, null, null, null);
|
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()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
long enhancedEstimate = powerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
|
long enhancedEstimate = powerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
|
||||||
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast,
|
batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
mStatsHelper.getStats(), elapsedRealtimeUs, false /* shortString */,
|
elapsedRealtimeUs, false /* shortString */,
|
||||||
batteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
|
batteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
|
||||||
} else {
|
} else {
|
||||||
BatteryStats stats = mStatsHelper.getStats();
|
|
||||||
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);
|
||||||
return batteryInfo;
|
return batteryInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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
|
* Find package uid from package name
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user