Merge "Improve messaging for enhanced notifications"
This commit is contained in:
committed by
Android (Google) Code Review
commit
0360957957
@@ -170,11 +170,12 @@ public class BatteryInfo {
|
||||
|
||||
if (discharging && provider != null
|
||||
&& provider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||
final long prediction = provider.getEnhancedBatteryPrediction(context);
|
||||
Estimate estimate = provider.getEnhancedBatteryPrediction(context);
|
||||
BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, shortString, BatteryUtils.convertMsToUs(prediction),
|
||||
true);
|
||||
elapsedRealtimeUs, shortString,
|
||||
BatteryUtils.convertMsToUs(estimate.estimateMillis),
|
||||
estimate.isBasedOnUsage);
|
||||
} else {
|
||||
long prediction = discharging
|
||||
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
||||
|
@@ -21,8 +21,6 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.Bundle;
|
||||
@@ -410,19 +408,19 @@ public class BatteryUtils {
|
||||
final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)
|
||||
== 0;
|
||||
// Get enhanced prediction if available and discharging, otherwise use the old code
|
||||
Cursor cursor = null;
|
||||
Estimate estimate = null;
|
||||
if (discharging && mPowerUsageFeatureProvider != null &&
|
||||
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
|
||||
final Uri queryUri = mPowerUsageFeatureProvider.getEnhancedBatteryPredictionUri();
|
||||
cursor = mContext.getContentResolver().query(queryUri, null, null, null, null);
|
||||
estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext);
|
||||
}
|
||||
final BatteryStats stats = statsHelper.getStats();
|
||||
BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
long enhancedEstimate = mPowerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
|
||||
|
||||
if (estimate != null) {
|
||||
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, false /* shortString */,
|
||||
BatteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
|
||||
BatteryUtils.convertMsToUs(estimate.estimateMillis),
|
||||
estimate.isBasedOnUsage);
|
||||
} else {
|
||||
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, false /* shortString */,
|
||||
|
@@ -54,14 +54,15 @@ public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
|
||||
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
|
||||
stats, elapsedRealtimeUs, false);
|
||||
|
||||
final long timeRemainingEnhanced = BatteryUtils.convertMsToUs(
|
||||
powerUsageFeatureProvider.getEnhancedBatteryPrediction(getContext()));
|
||||
BatteryInfo newinfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, false, timeRemainingEnhanced, true);
|
||||
Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
|
||||
BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
||||
elapsedRealtimeUs, false,
|
||||
BatteryUtils.convertMsToUs(estimate.estimateMillis),
|
||||
estimate.isBasedOnUsage);
|
||||
|
||||
List<BatteryInfo> infos = new ArrayList<>();
|
||||
infos.add(oldinfo);
|
||||
infos.add(newinfo);
|
||||
infos.add(newInfo);
|
||||
return infos;
|
||||
}
|
||||
}
|
||||
|
12
src/com/android/settings/fuelgauge/Estimate.java
Normal file
12
src/com/android/settings/fuelgauge/Estimate.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
public class Estimate {
|
||||
|
||||
public final long estimateMillis;
|
||||
public final boolean isBasedOnUsage;
|
||||
|
||||
public Estimate(long estimateMillis, boolean isBasedOnUsage) {
|
||||
this.estimateMillis = estimateMillis;
|
||||
this.isBasedOnUsage = isBasedOnUsage;
|
||||
}
|
||||
}
|
@@ -18,8 +18,6 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
@@ -28,6 +26,7 @@ import com.android.internal.os.BatterySipper;
|
||||
* Feature Provider used in power usage
|
||||
*/
|
||||
public interface PowerUsageFeatureProvider {
|
||||
|
||||
/**
|
||||
* Check whether location setting is enabled
|
||||
*/
|
||||
@@ -66,7 +65,7 @@ public interface PowerUsageFeatureProvider {
|
||||
/**
|
||||
* Returns an improved prediction for battery time remaining.
|
||||
*/
|
||||
long getEnhancedBatteryPrediction(Context context);
|
||||
Estimate getEnhancedBatteryPrediction(Context context);
|
||||
|
||||
/**
|
||||
* Returns an improved projection curve for future battery level.
|
||||
@@ -79,16 +78,6 @@ public interface PowerUsageFeatureProvider {
|
||||
*/
|
||||
boolean isEnhancedBatteryPredictionEnabled(Context context);
|
||||
|
||||
/**
|
||||
* Returns the Uri used to query for an enhanced battery prediction from a cursor loader.
|
||||
*/
|
||||
Uri getEnhancedBatteryPredictionUri();
|
||||
|
||||
/**
|
||||
* Returns the the estimate in the cursor as a long or -1 if the cursor is null
|
||||
*/
|
||||
long getTimeRemainingEstimate(Cursor cursor);
|
||||
|
||||
/**
|
||||
* Checks whether debugging should be enabled for battery estimates.
|
||||
* @return
|
||||
|
@@ -21,7 +21,6 @@ import static com.android.settings.core.FeatureFlags.BATTERY_SETTINGS_V2;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Process;
|
||||
import android.util.FeatureFlagUtils;
|
||||
@@ -95,8 +94,8 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnhancedBatteryPrediction(Context context) {
|
||||
return -1;
|
||||
public Estimate getEnhancedBatteryPrediction(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,16 +108,6 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getEnhancedBatteryPredictionUri() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimeRemainingEstimate(Cursor cursor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEnhancedEstimateDebugString(String timeRemaining) {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user