Improve messaging for enhanced notifications
The message displayed in battery settings will now more accurately reflect when an estimate is enhanced based on our updated definition of what that means. Test: robotests Bug: 64833846 Change-Id: Id635d78d8f56d10253e22df2705af93f2693db70
This commit is contained in:
@@ -170,11 +170,12 @@ public class BatteryInfo {
|
|||||||
|
|
||||||
if (discharging && provider != null
|
if (discharging && provider != null
|
||||||
&& provider.isEnhancedBatteryPredictionEnabled(context)) {
|
&& provider.isEnhancedBatteryPredictionEnabled(context)) {
|
||||||
final long prediction = provider.getEnhancedBatteryPrediction(context);
|
Estimate estimate = provider.getEnhancedBatteryPrediction(context);
|
||||||
BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
|
||||||
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, shortString, BatteryUtils.convertMsToUs(prediction),
|
elapsedRealtimeUs, shortString,
|
||||||
true);
|
BatteryUtils.convertMsToUs(estimate.estimateMillis),
|
||||||
|
estimate.isBasedOnUsage);
|
||||||
} else {
|
} else {
|
||||||
long prediction = discharging
|
long prediction = discharging
|
||||||
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
|
||||||
|
@@ -21,8 +21,6 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -410,19 +408,19 @@ public class BatteryUtils {
|
|||||||
final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)
|
final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)
|
||||||
== 0;
|
== 0;
|
||||||
// Get enhanced prediction if available and discharging, otherwise use the old code
|
// Get enhanced prediction if available and discharging, otherwise use the old code
|
||||||
Cursor cursor = null;
|
Estimate estimate = null;
|
||||||
if (discharging && mPowerUsageFeatureProvider != null &&
|
if (discharging && mPowerUsageFeatureProvider != null &&
|
||||||
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
|
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
|
||||||
final Uri queryUri = mPowerUsageFeatureProvider.getEnhancedBatteryPredictionUri();
|
estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext);
|
||||||
cursor = mContext.getContentResolver().query(queryUri, null, null, null, null);
|
|
||||||
}
|
}
|
||||||
final BatteryStats stats = statsHelper.getStats();
|
final BatteryStats stats = statsHelper.getStats();
|
||||||
BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
|
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,
|
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false /* shortString */,
|
elapsedRealtimeUs, false /* shortString */,
|
||||||
BatteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
|
BatteryUtils.convertMsToUs(estimate.estimateMillis),
|
||||||
|
estimate.isBasedOnUsage);
|
||||||
} else {
|
} else {
|
||||||
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
|
||||||
elapsedRealtimeUs, false /* shortString */,
|
elapsedRealtimeUs, false /* shortString */,
|
||||||
|
@@ -54,14 +54,15 @@ public class DebugEstimatesLoader extends AsyncLoader<List<BatteryInfo>> {
|
|||||||
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
|
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
|
||||||
stats, elapsedRealtimeUs, false);
|
stats, elapsedRealtimeUs, false);
|
||||||
|
|
||||||
final long timeRemainingEnhanced = BatteryUtils.convertMsToUs(
|
Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
|
||||||
powerUsageFeatureProvider.getEnhancedBatteryPrediction(getContext()));
|
BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
||||||
BatteryInfo newinfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
|
elapsedRealtimeUs, false,
|
||||||
elapsedRealtimeUs, false, timeRemainingEnhanced, true);
|
BatteryUtils.convertMsToUs(estimate.estimateMillis),
|
||||||
|
estimate.isBasedOnUsage);
|
||||||
|
|
||||||
List<BatteryInfo> infos = new ArrayList<>();
|
List<BatteryInfo> infos = new ArrayList<>();
|
||||||
infos.add(oldinfo);
|
infos.add(oldinfo);
|
||||||
infos.add(newinfo);
|
infos.add(newInfo);
|
||||||
return infos;
|
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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.util.SparseIntArray;
|
import android.util.SparseIntArray;
|
||||||
|
|
||||||
import com.android.internal.os.BatterySipper;
|
import com.android.internal.os.BatterySipper;
|
||||||
@@ -28,6 +26,7 @@ import com.android.internal.os.BatterySipper;
|
|||||||
* Feature Provider used in power usage
|
* Feature Provider used in power usage
|
||||||
*/
|
*/
|
||||||
public interface PowerUsageFeatureProvider {
|
public interface PowerUsageFeatureProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether location setting is enabled
|
* Check whether location setting is enabled
|
||||||
*/
|
*/
|
||||||
@@ -66,7 +65,7 @@ public interface PowerUsageFeatureProvider {
|
|||||||
/**
|
/**
|
||||||
* Returns an improved prediction for battery time remaining.
|
* 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.
|
* Returns an improved projection curve for future battery level.
|
||||||
@@ -79,16 +78,6 @@ public interface PowerUsageFeatureProvider {
|
|||||||
*/
|
*/
|
||||||
boolean isEnhancedBatteryPredictionEnabled(Context context);
|
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.
|
* Checks whether debugging should be enabled for battery estimates.
|
||||||
* @return
|
* @return
|
||||||
|
@@ -21,7 +21,6 @@ import static com.android.settings.core.FeatureFlags.BATTERY_SETTINGS_V2;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.util.FeatureFlagUtils;
|
||||||
@@ -95,8 +94,8 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEnhancedBatteryPrediction(Context context) {
|
public Estimate getEnhancedBatteryPrediction(Context context) {
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -109,16 +108,6 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Uri getEnhancedBatteryPredictionUri() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getTimeRemainingEstimate(Cursor cursor) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEnhancedEstimateDebugString(String timeRemaining) {
|
public String getEnhancedEstimateDebugString(String timeRemaining) {
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user