Loading src/com/android/settings/fuelgauge/BatteryInfo.java +12 −6 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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); Loading @@ -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); } } Loading @@ -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); Loading Loading @@ -232,6 +237,7 @@ public class BatteryInfo { chargeStatusLabel); } } BatteryUtils.logRuntime(LOG_TAG, "time for getBatteryInfo", startTime); return info; } Loading src/com/android/settings/fuelgauge/BatteryInfoLoader.java +8 −4 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading @@ -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; } } src/com/android/settings/fuelgauge/BatteryUtils.java +4 −0 Original line number Diff line number Diff line Loading @@ -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 * Loading Loading
src/com/android/settings/fuelgauge/BatteryInfo.java +12 −6 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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); Loading @@ -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); } } Loading @@ -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); Loading Loading @@ -232,6 +237,7 @@ public class BatteryInfo { chargeStatusLabel); } } BatteryUtils.logRuntime(LOG_TAG, "time for getBatteryInfo", startTime); return info; } Loading
src/com/android/settings/fuelgauge/BatteryInfoLoader.java +8 −4 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading @@ -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; } }
src/com/android/settings/fuelgauge/BatteryUtils.java +4 −0 Original line number Diff line number Diff line Loading @@ -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 * Loading