Merge "Fix null pointer error && add settings side guard"

This commit is contained in:
Salvador Martinez
2017-05-10 18:50:53 +00:00
committed by Android (Google) Code Review
2 changed files with 33 additions and 3 deletions

View File

@@ -166,7 +166,8 @@ public class PowerUsageSummary extends PowerUsageBase implements
}
};
private LoaderManager.LoaderCallbacks<Cursor> mBatteryPredictionLoaderCallbacks =
@VisibleForTesting
LoaderManager.LoaderCallbacks<Cursor> mBatteryPredictionLoaderCallbacks =
new LoaderManager.LoaderCallbacks<Cursor>() {
@Override
@@ -177,8 +178,11 @@ public class PowerUsageSummary extends PowerUsageBase implements
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
if (cursor == null) {
return;
}
try {
if (cursor != null && cursor.moveToFirst()) {
if (cursor.moveToFirst()) {
mEnhancedEstimate =
mPowerFeatureProvider.getTimeRemainingEstimate(cursor);
}
@@ -746,7 +750,8 @@ public class PowerUsageSummary extends PowerUsageBase implements
@VisibleForTesting
void useEnhancedEstimateIfAvailable(Context context, BatteryInfo batteryInfo) {
if (mEnhancedEstimate > 0) {
if (mEnhancedEstimate > 0
&& mPowerFeatureProvider.isEnhancedBatteryPredictionEnabled(context)) {
final Resources resources = context.getResources();
batteryInfo.remainingTimeUs = mEnhancedEstimate;
String timeString = Formatter.formatShortElapsedTime(context, mEnhancedEstimate);