Provide foreground_service usage time in BatteryDiffEntry.
- Fetch foreground service info through new api from UidBatteryConsumer. - Record fgs & bg usage time separately, combine them till ui display. Bug: 315255868 Test: make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge.*" Change-Id: Ic19844db7908a6ae6522c7a72972f44f94dcfca4
This commit is contained in:
@@ -148,7 +148,8 @@ public class AdvancedPowerUsageDetail extends DashboardFragment
|
||||
launchArgs.mShowTimeInformation = showTimeInformation;
|
||||
if (launchArgs.mShowTimeInformation) {
|
||||
launchArgs.mForegroundTimeMs = diffEntry.mForegroundUsageTimeInMs;
|
||||
launchArgs.mBackgroundTimeMs = diffEntry.mBackgroundUsageTimeInMs;
|
||||
launchArgs.mBackgroundTimeMs =
|
||||
diffEntry.mBackgroundUsageTimeInMs + diffEntry.mForegroundServiceUsageTimeInMs;
|
||||
launchArgs.mScreenOnTimeMs = diffEntry.mScreenOnTimeInMs;
|
||||
launchArgs.mAnomalyHintPrefKey = anomalyHintPrefKey;
|
||||
launchArgs.mAnomalyHintText = anomalyHintText;
|
||||
|
||||
@@ -92,6 +92,7 @@ public class BatteryDiffEntry {
|
||||
public String mLegacyLabel;
|
||||
public int mConsumerType;
|
||||
public long mForegroundUsageTimeInMs;
|
||||
public long mForegroundServiceUsageTimeInMs;
|
||||
public long mBackgroundUsageTimeInMs;
|
||||
public long mScreenOnTimeInMs;
|
||||
public double mConsumePower;
|
||||
@@ -125,6 +126,7 @@ public class BatteryDiffEntry {
|
||||
String legacyLabel,
|
||||
int consumerType,
|
||||
long foregroundUsageTimeInMs,
|
||||
long foregroundServiceUsageTimeInMs,
|
||||
long backgroundUsageTimeInMs,
|
||||
long screenOnTimeInMs,
|
||||
double consumePower,
|
||||
@@ -142,6 +144,7 @@ public class BatteryDiffEntry {
|
||||
mLegacyLabel = legacyLabel;
|
||||
mConsumerType = consumerType;
|
||||
mForegroundUsageTimeInMs = foregroundUsageTimeInMs;
|
||||
mForegroundServiceUsageTimeInMs = foregroundServiceUsageTimeInMs;
|
||||
mBackgroundUsageTimeInMs = backgroundUsageTimeInMs;
|
||||
mScreenOnTimeInMs = screenOnTimeInMs;
|
||||
mConsumePower = consumePower;
|
||||
@@ -164,6 +167,7 @@ public class BatteryDiffEntry {
|
||||
legacyLabel,
|
||||
consumerType,
|
||||
/* foregroundUsageTimeInMs= */ 0,
|
||||
/* foregroundServiceUsageTimeInMs= */ 0,
|
||||
/* backgroundUsageTimeInMs= */ 0,
|
||||
/* screenOnTimeInMs= */ 0,
|
||||
/* consumePower= */ 0,
|
||||
@@ -232,6 +236,7 @@ public class BatteryDiffEntry {
|
||||
this.mLegacyLabel,
|
||||
this.mConsumerType,
|
||||
this.mForegroundUsageTimeInMs,
|
||||
this.mForegroundServiceUsageTimeInMs,
|
||||
this.mBackgroundUsageTimeInMs,
|
||||
this.mScreenOnTimeInMs,
|
||||
this.mConsumePower,
|
||||
@@ -515,48 +520,50 @@ public class BatteryDiffEntry {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder =
|
||||
new StringBuilder()
|
||||
.append("BatteryDiffEntry{")
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tname=%s restrictable=%b",
|
||||
mAppLabel, mValidForRestriction))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tconsume=%.2f%% %f/%f",
|
||||
mPercentage, mConsumePower, mTotalConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tconsume power= foreground:%f foregroundService:%f",
|
||||
mForegroundUsageConsumePower,
|
||||
mForegroundServiceUsageConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tconsume power= background:%f cached:%f",
|
||||
mBackgroundUsageConsumePower, mCachedUsageConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\ttime= foreground:%s background:%s screen-on:%s",
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mForegroundUsageTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false),
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mBackgroundUsageTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false),
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mScreenOnTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false)))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tpackage:%s|%s uid:%d userId:%d",
|
||||
mLegacyPackageName, getPackageName(), mUid, mUserId));
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("BatteryDiffEntry{");
|
||||
builder.append(
|
||||
String.format("\n\tname=%s restrictable=%b", mAppLabel, mValidForRestriction));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tconsume=%.2f%% %f/%f",
|
||||
mPercentage, mConsumePower, mTotalConsumePower));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tconsume power= foreground:%f foregroundService:%f",
|
||||
mForegroundUsageConsumePower, mForegroundServiceUsageConsumePower));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tconsume power= background:%f cached:%f",
|
||||
mBackgroundUsageConsumePower, mCachedUsageConsumePower));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\ttime= foreground:%s foregroundService:%s "
|
||||
+ "background:%s screen-on:%s",
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mForegroundUsageTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false),
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mForegroundServiceUsageTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false),
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mBackgroundUsageTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false),
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
(double) mScreenOnTimeInMs,
|
||||
/* withSeconds= */ true,
|
||||
/* collapseTimeUnit= */ false)));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tpackage:%s|%s uid:%d userId:%d",
|
||||
mLegacyPackageName, getPackageName(), mUid, mUserId));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ public class BatteryEntry {
|
||||
@BatteryConsumer.PowerComponent private final int mPowerComponentId;
|
||||
private long mUsageDurationMs;
|
||||
private long mTimeInForegroundMs;
|
||||
private long mTimeInForegroundServiceMs;
|
||||
private long mTimeInBackgroundMs;
|
||||
|
||||
public String mName;
|
||||
@@ -188,9 +189,14 @@ public class BatteryEntry {
|
||||
}
|
||||
}
|
||||
mTimeInForegroundMs =
|
||||
uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND);
|
||||
uidBatteryConsumer.getTimeInProcessStateMs(
|
||||
UidBatteryConsumer.PROCESS_STATE_FOREGROUND);
|
||||
mTimeInForegroundServiceMs =
|
||||
uidBatteryConsumer.getTimeInProcessStateMs(
|
||||
UidBatteryConsumer.PROCESS_STATE_FOREGROUND_SERVICE);
|
||||
mTimeInBackgroundMs =
|
||||
uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND);
|
||||
uidBatteryConsumer.getTimeInProcessStateMs(
|
||||
UidBatteryConsumer.PROCESS_STATE_BACKGROUND);
|
||||
mConsumedPowerInForeground =
|
||||
safeGetConsumedPower(
|
||||
uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND]);
|
||||
@@ -433,20 +439,19 @@ public class BatteryEntry {
|
||||
|
||||
/** Returns foreground time/ms that is attributed to this entry. */
|
||||
public long getTimeInForegroundMs() {
|
||||
if (mBatteryConsumer instanceof UidBatteryConsumer) {
|
||||
return mTimeInForegroundMs;
|
||||
} else {
|
||||
return mUsageDurationMs;
|
||||
}
|
||||
return (mBatteryConsumer instanceof UidBatteryConsumer)
|
||||
? mTimeInForegroundMs
|
||||
: mUsageDurationMs;
|
||||
}
|
||||
|
||||
/** Returns foreground service time/ms that is attributed to this entry. */
|
||||
public long getTimeInForegroundServiceMs() {
|
||||
return (mBatteryConsumer instanceof UidBatteryConsumer) ? mTimeInForegroundServiceMs : 0;
|
||||
}
|
||||
|
||||
/** Returns background activity time/ms that is attributed to this entry. */
|
||||
public long getTimeInBackgroundMs() {
|
||||
if (mBatteryConsumer instanceof UidBatteryConsumer) {
|
||||
return mTimeInBackgroundMs;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return (mBatteryConsumer instanceof UidBatteryConsumer) ? mTimeInBackgroundMs : 0;
|
||||
}
|
||||
|
||||
/** Returns total amount of power (in milli-amp-hours) that is attributed to this entry. */
|
||||
@@ -510,9 +515,14 @@ public class BatteryEntry {
|
||||
if (batteryConsumer instanceof UidBatteryConsumer) {
|
||||
UidBatteryConsumer uidBatteryConsumer = (UidBatteryConsumer) batteryConsumer;
|
||||
mTimeInForegroundMs +=
|
||||
uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND);
|
||||
uidBatteryConsumer.getTimeInProcessStateMs(
|
||||
UidBatteryConsumer.PROCESS_STATE_FOREGROUND);
|
||||
mTimeInForegroundServiceMs +=
|
||||
uidBatteryConsumer.getTimeInProcessStateMs(
|
||||
UidBatteryConsumer.PROCESS_STATE_FOREGROUND_SERVICE);
|
||||
mTimeInBackgroundMs +=
|
||||
uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND);
|
||||
uidBatteryConsumer.getTimeInProcessStateMs(
|
||||
UidBatteryConsumer.PROCESS_STATE_BACKGROUND);
|
||||
mConsumedPowerInForeground +=
|
||||
safeGetConsumedPower(
|
||||
uidBatteryConsumer, BATTERY_DIMENSIONS[BATTERY_USAGE_INDEX_FOREGROUND]);
|
||||
|
||||
@@ -20,8 +20,6 @@ import android.database.Cursor;
|
||||
import android.os.BatteryConsumer;
|
||||
import android.util.Log;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
/** A container class to carry data from {@link ContentValues}. */
|
||||
public class BatteryHistEntry {
|
||||
private static final boolean DEBUG = false;
|
||||
@@ -57,6 +55,7 @@ public class BatteryHistEntry {
|
||||
public final double mCachedUsageConsumePower;
|
||||
public final double mPercentOfTotal;
|
||||
public final long mForegroundUsageTimeInMs;
|
||||
public final long mForegroundServiceUsageTimeInMs;
|
||||
public final long mBackgroundUsageTimeInMs;
|
||||
@BatteryConsumer.PowerComponent public final int mDrainType;
|
||||
@ConvertUtils.ConsumerType public final int mConsumerType;
|
||||
@@ -89,6 +88,7 @@ public class BatteryHistEntry {
|
||||
mCachedUsageConsumePower = batteryInformation.getCachedUsageConsumePower();
|
||||
mPercentOfTotal = batteryInformation.getPercentOfTotal();
|
||||
mForegroundUsageTimeInMs = batteryInformation.getForegroundUsageTimeInMs();
|
||||
mForegroundServiceUsageTimeInMs = batteryInformation.getForegroundServiceUsageTimeInMs();
|
||||
mBackgroundUsageTimeInMs = batteryInformation.getBackgroundUsageTimeInMs();
|
||||
mDrainType = batteryInformation.getDrainType();
|
||||
final DeviceBatteryState deviceBatteryState = batteryInformation.getDeviceBatteryState();
|
||||
@@ -118,6 +118,7 @@ public class BatteryHistEntry {
|
||||
mCachedUsageConsumePower = batteryInformation.getCachedUsageConsumePower();
|
||||
mPercentOfTotal = batteryInformation.getPercentOfTotal();
|
||||
mForegroundUsageTimeInMs = batteryInformation.getForegroundUsageTimeInMs();
|
||||
mForegroundServiceUsageTimeInMs = batteryInformation.getForegroundServiceUsageTimeInMs();
|
||||
mBackgroundUsageTimeInMs = batteryInformation.getBackgroundUsageTimeInMs();
|
||||
mDrainType = batteryInformation.getDrainType();
|
||||
final DeviceBatteryState deviceBatteryState = batteryInformation.getDeviceBatteryState();
|
||||
@@ -137,6 +138,7 @@ public class BatteryHistEntry {
|
||||
double backgroundUsageConsumePower,
|
||||
double cachedUsageConsumePower,
|
||||
long foregroundUsageTimeInMs,
|
||||
long foregroundServiceUsageTimeInMs,
|
||||
long backgroundUsageTimeInMs,
|
||||
int batteryLevel) {
|
||||
mUid = fromEntry.mUid;
|
||||
@@ -155,6 +157,7 @@ public class BatteryHistEntry {
|
||||
mCachedUsageConsumePower = cachedUsageConsumePower;
|
||||
mPercentOfTotal = fromEntry.mPercentOfTotal;
|
||||
mForegroundUsageTimeInMs = foregroundUsageTimeInMs;
|
||||
mForegroundServiceUsageTimeInMs = foregroundServiceUsageTimeInMs;
|
||||
mBackgroundUsageTimeInMs = backgroundUsageTimeInMs;
|
||||
mDrainType = fromEntry.mDrainType;
|
||||
mConsumerType = fromEntry.mConsumerType;
|
||||
@@ -189,45 +192,40 @@ public class BatteryHistEntry {
|
||||
@Override
|
||||
public String toString() {
|
||||
final String recordAtDateTime = ConvertUtils.utcToLocalTimeForLogging(mTimestamp);
|
||||
final StringBuilder builder =
|
||||
new StringBuilder()
|
||||
.append("\nBatteryHistEntry{")
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tpackage=%s|label=%s|uid=%d|userId=%d|isHidden=%b",
|
||||
mPackageName, mAppLabel, mUid, mUserId, mIsHidden))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\ttimestamp=%s|zoneId=%s|bootTimestamp=%d",
|
||||
recordAtDateTime,
|
||||
mZoneId,
|
||||
Duration.ofMillis(mBootTimestamp).getSeconds()))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tusage=%f|total=%f|consume=%f",
|
||||
mPercentOfTotal, mTotalPower, mConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tforeground=%f|foregroundService=%f",
|
||||
mForegroundUsageConsumePower,
|
||||
mForegroundServiceUsageConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tbackground=%f|cached=%f",
|
||||
mBackgroundUsageConsumePower, mCachedUsageConsumePower))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\telapsedTime=%d|%d",
|
||||
Duration.ofMillis(mForegroundUsageTimeInMs).getSeconds(),
|
||||
Duration.ofMillis(mBackgroundUsageTimeInMs).getSeconds()))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tdrainType=%d|consumerType=%d",
|
||||
mDrainType, mConsumerType))
|
||||
.append(
|
||||
String.format(
|
||||
"\n\tbattery=%d|status=%d|health=%d\n}",
|
||||
mBatteryLevel, mBatteryStatus, mBatteryHealth));
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("\nBatteryHistEntry{");
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tpackage=%s|label=%s|uid=%d|userId=%d|isHidden=%b",
|
||||
mPackageName, mAppLabel, mUid, mUserId, mIsHidden));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\ttimestamp=%s|zoneId=%s|bootTimestamp=%d",
|
||||
recordAtDateTime, mZoneId, TimestampUtils.getSeconds(mBootTimestamp)));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tusage=%f|total=%f|consume=%f",
|
||||
mPercentOfTotal, mTotalPower, mConsumePower));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tforeground=%f|foregroundService=%f",
|
||||
mForegroundUsageConsumePower, mForegroundServiceUsageConsumePower));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tbackground=%f|cached=%f",
|
||||
mBackgroundUsageConsumePower, mCachedUsageConsumePower));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\telapsedTime,fg=%d|fgs=%d|bg=%d",
|
||||
TimestampUtils.getSeconds(mBackgroundUsageTimeInMs),
|
||||
TimestampUtils.getSeconds(mForegroundServiceUsageTimeInMs),
|
||||
TimestampUtils.getSeconds(mBackgroundUsageTimeInMs)));
|
||||
builder.append(
|
||||
String.format("\n\tdrainType=%d|consumerType=%d", mDrainType, mConsumerType));
|
||||
builder.append(
|
||||
String.format(
|
||||
"\n\tbattery=%d|status=%d|health=%d\n}",
|
||||
mBatteryLevel, mBatteryStatus, mBatteryHealth));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -323,19 +321,20 @@ public class BatteryHistEntry {
|
||||
ratio);
|
||||
final double foregroundUsageTimeInMs =
|
||||
interpolate(
|
||||
(double)
|
||||
(lowerHistEntry == null
|
||||
? 0
|
||||
: lowerHistEntry.mForegroundUsageTimeInMs),
|
||||
(double) upperHistEntry.mForegroundUsageTimeInMs,
|
||||
(lowerHistEntry == null ? 0 : lowerHistEntry.mForegroundUsageTimeInMs),
|
||||
upperHistEntry.mForegroundUsageTimeInMs,
|
||||
ratio);
|
||||
final double foregroundServiceUsageTimeInMs =
|
||||
interpolate(
|
||||
(lowerHistEntry == null
|
||||
? 0
|
||||
: lowerHistEntry.mForegroundServiceUsageTimeInMs),
|
||||
upperHistEntry.mForegroundServiceUsageTimeInMs,
|
||||
ratio);
|
||||
final double backgroundUsageTimeInMs =
|
||||
interpolate(
|
||||
(double)
|
||||
(lowerHistEntry == null
|
||||
? 0
|
||||
: lowerHistEntry.mBackgroundUsageTimeInMs),
|
||||
(double) upperHistEntry.mBackgroundUsageTimeInMs,
|
||||
(lowerHistEntry == null ? 0 : lowerHistEntry.mBackgroundUsageTimeInMs),
|
||||
upperHistEntry.mBackgroundUsageTimeInMs,
|
||||
ratio);
|
||||
// Checks whether there is any abnormal cases!
|
||||
if (upperHistEntry.mConsumePower < consumePower
|
||||
@@ -345,6 +344,7 @@ public class BatteryHistEntry {
|
||||
|| upperHistEntry.mBackgroundUsageConsumePower < backgroundUsageConsumePower
|
||||
|| upperHistEntry.mCachedUsageConsumePower < cachedUsageConsumePower
|
||||
|| upperHistEntry.mForegroundUsageTimeInMs < foregroundUsageTimeInMs
|
||||
|| upperHistEntry.mForegroundServiceUsageTimeInMs < foregroundServiceUsageTimeInMs
|
||||
|| upperHistEntry.mBackgroundUsageTimeInMs < backgroundUsageTimeInMs) {
|
||||
if (DEBUG) {
|
||||
Log.w(
|
||||
@@ -371,6 +371,7 @@ public class BatteryHistEntry {
|
||||
backgroundUsageConsumePower,
|
||||
cachedUsageConsumePower,
|
||||
Math.round(foregroundUsageTimeInMs),
|
||||
Math.round(foregroundServiceUsageTimeInMs),
|
||||
Math.round(backgroundUsageTimeInMs),
|
||||
(int) Math.round(batteryLevel));
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
mPrefContext,
|
||||
entry.isSystemEntry(),
|
||||
entry.mForegroundUsageTimeInMs,
|
||||
entry.mBackgroundUsageTimeInMs,
|
||||
entry.mBackgroundUsageTimeInMs + entry.mForegroundServiceUsageTimeInMs,
|
||||
entry.mScreenOnTimeInMs));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,6 +544,7 @@ public final class ConvertUtils {
|
||||
batteryUsageDiff.getLabel(),
|
||||
batteryUsageDiff.getConsumerType(),
|
||||
batteryUsageDiff.getForegroundUsageTime(),
|
||||
batteryUsageDiff.getForegroundServiceUsageTime(),
|
||||
batteryUsageDiff.getBackgroundUsageTime(),
|
||||
batteryUsageDiff.getScreenOnTime(),
|
||||
batteryUsageDiff.getConsumePower(),
|
||||
@@ -612,6 +613,7 @@ public final class ConvertUtils {
|
||||
.setPercentOfTotal(entry.mPercent)
|
||||
.setDrainType(entry.getPowerComponentId())
|
||||
.setForegroundUsageTimeInMs(entry.getTimeInForegroundMs())
|
||||
.setForegroundServiceUsageTimeInMs(entry.getTimeInForegroundServiceMs())
|
||||
.setBackgroundUsageTimeInMs(entry.getTimeInBackgroundMs());
|
||||
}
|
||||
|
||||
|
||||
@@ -675,6 +675,7 @@ public final class DataProcessor {
|
||||
entry.mAppLabel,
|
||||
entry.mConsumerType,
|
||||
entry.mForegroundUsageTimeInMs,
|
||||
entry.mForegroundServiceUsageTimeInMs,
|
||||
entry.mBackgroundUsageTimeInMs,
|
||||
/* screenOnTimeInMs= */ 0,
|
||||
entry.mConsumePower,
|
||||
@@ -1412,6 +1413,7 @@ public final class DataProcessor {
|
||||
|
||||
// Cumulative values is a specific time slot for a specific app.
|
||||
long foregroundUsageTimeInMs = 0;
|
||||
long foregroundServiceUsageTimeInMs = 0;
|
||||
long backgroundUsageTimeInMs = 0;
|
||||
double consumePower = 0;
|
||||
double foregroundUsageConsumePower = 0;
|
||||
@@ -1425,6 +1427,10 @@ public final class DataProcessor {
|
||||
getDiffValue(
|
||||
currentEntry.mForegroundUsageTimeInMs,
|
||||
nextEntry.mForegroundUsageTimeInMs);
|
||||
foregroundServiceUsageTimeInMs +=
|
||||
getDiffValue(
|
||||
currentEntry.mForegroundServiceUsageTimeInMs,
|
||||
nextEntry.mForegroundServiceUsageTimeInMs);
|
||||
backgroundUsageTimeInMs +=
|
||||
getDiffValue(
|
||||
currentEntry.mBackgroundUsageTimeInMs,
|
||||
@@ -1453,24 +1459,32 @@ public final class DataProcessor {
|
||||
foregroundUsageTimeInMs = slotScreenOnTime;
|
||||
}
|
||||
// Excludes entry since we don't have enough data to calculate.
|
||||
if (foregroundUsageTimeInMs == 0 && backgroundUsageTimeInMs == 0 && consumePower == 0) {
|
||||
if (foregroundUsageTimeInMs == 0
|
||||
&& foregroundServiceUsageTimeInMs == 0
|
||||
&& backgroundUsageTimeInMs == 0
|
||||
&& consumePower == 0) {
|
||||
continue;
|
||||
}
|
||||
// Forces refine the cumulative value since it may introduce deviation error since we
|
||||
// will apply the interpolation arithmetic.
|
||||
final float totalUsageTimeInMs = foregroundUsageTimeInMs + backgroundUsageTimeInMs;
|
||||
final float totalUsageTimeInMs =
|
||||
foregroundUsageTimeInMs
|
||||
+ backgroundUsageTimeInMs
|
||||
+ foregroundServiceUsageTimeInMs;
|
||||
if (totalUsageTimeInMs > slotDuration) {
|
||||
final float ratio = slotDuration / totalUsageTimeInMs;
|
||||
if (sDebug) {
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format(
|
||||
"abnormal usage time %d|%d for:\n%s",
|
||||
"abnormal usage time %d|%d|%d for:\n%s",
|
||||
Duration.ofMillis(foregroundUsageTimeInMs).getSeconds(),
|
||||
Duration.ofMillis(foregroundServiceUsageTimeInMs).getSeconds(),
|
||||
Duration.ofMillis(backgroundUsageTimeInMs).getSeconds(),
|
||||
selectedBatteryEntry));
|
||||
}
|
||||
foregroundUsageTimeInMs = Math.round(foregroundUsageTimeInMs * ratio);
|
||||
foregroundServiceUsageTimeInMs = Math.round(foregroundServiceUsageTimeInMs * ratio);
|
||||
backgroundUsageTimeInMs = Math.round(backgroundUsageTimeInMs * ratio);
|
||||
consumePower = consumePower * ratio;
|
||||
foregroundUsageConsumePower = foregroundUsageConsumePower * ratio;
|
||||
@@ -1487,9 +1501,14 @@ public final class DataProcessor {
|
||||
appUsageMap,
|
||||
selectedBatteryEntry.mUserId,
|
||||
selectedBatteryEntry.mPackageName));
|
||||
// Make sure the background + screen-on time will not exceed the threshold.
|
||||
// Ensure the following value will not exceed the threshold.
|
||||
// value = background + foregroundService + screen-on
|
||||
backgroundUsageTimeInMs =
|
||||
Math.min(backgroundUsageTimeInMs, (long) slotDuration - screenOnTime);
|
||||
foregroundServiceUsageTimeInMs =
|
||||
Math.min(
|
||||
foregroundServiceUsageTimeInMs,
|
||||
(long) slotDuration - screenOnTime - backgroundUsageTimeInMs);
|
||||
final BatteryDiffEntry currentBatteryDiffEntry =
|
||||
new BatteryDiffEntry(
|
||||
context,
|
||||
@@ -1502,6 +1521,7 @@ public final class DataProcessor {
|
||||
selectedBatteryEntry.mAppLabel,
|
||||
selectedBatteryEntry.mConsumerType,
|
||||
foregroundUsageTimeInMs,
|
||||
foregroundServiceUsageTimeInMs,
|
||||
backgroundUsageTimeInMs,
|
||||
screenOnTime,
|
||||
consumePower,
|
||||
@@ -1647,6 +1667,8 @@ public final class DataProcessor {
|
||||
} else {
|
||||
// Sums up some field data into the existing one.
|
||||
oldBatteryDiffEntry.mForegroundUsageTimeInMs += entry.mForegroundUsageTimeInMs;
|
||||
oldBatteryDiffEntry.mForegroundServiceUsageTimeInMs +=
|
||||
entry.mForegroundServiceUsageTimeInMs;
|
||||
oldBatteryDiffEntry.mBackgroundUsageTimeInMs += entry.mBackgroundUsageTimeInMs;
|
||||
oldBatteryDiffEntry.mScreenOnTimeInMs += entry.mScreenOnTimeInMs;
|
||||
oldBatteryDiffEntry.mConsumePower += entry.mConsumePower;
|
||||
|
||||
@@ -660,36 +660,39 @@ public final class DatabaseUtils {
|
||||
// Creates the ContentValues list to insert them into provider.
|
||||
final List<ContentValues> valuesList = new ArrayList<>();
|
||||
if (batteryEntryList != null) {
|
||||
batteryEntryList.stream()
|
||||
.filter(
|
||||
entry -> {
|
||||
final long foregroundMs = entry.getTimeInForegroundMs();
|
||||
final long backgroundMs = entry.getTimeInBackgroundMs();
|
||||
if (entry.getConsumedPower() == 0
|
||||
&& (foregroundMs != 0 || backgroundMs != 0)) {
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format(
|
||||
"no consumed power but has running time for %s"
|
||||
+ " time=%d|%d",
|
||||
entry.getLabel(), foregroundMs, backgroundMs));
|
||||
}
|
||||
return entry.getConsumedPower() != 0
|
||||
|| foregroundMs != 0
|
||||
|| backgroundMs != 0;
|
||||
})
|
||||
.forEach(
|
||||
entry ->
|
||||
valuesList.add(
|
||||
ConvertUtils.convertBatteryEntryToContentValues(
|
||||
entry,
|
||||
batteryUsageStats,
|
||||
batteryLevel,
|
||||
batteryStatus,
|
||||
batteryHealth,
|
||||
snapshotBootTimestamp,
|
||||
snapshotTimestamp,
|
||||
isFullChargeStart)));
|
||||
for (BatteryEntry entry : batteryEntryList) {
|
||||
final long foregroundMs = entry.getTimeInForegroundMs();
|
||||
final long foregroundServiceMs = entry.getTimeInForegroundServiceMs();
|
||||
final long backgroundMs = entry.getTimeInBackgroundMs();
|
||||
if (entry.getConsumedPower() == 0
|
||||
&& (foregroundMs != 0 || foregroundServiceMs != 0 || backgroundMs != 0)) {
|
||||
Log.w(
|
||||
TAG,
|
||||
String.format(
|
||||
"no consumed power but has running time for %s"
|
||||
+ " time=%d|%d|%d",
|
||||
entry.getLabel(),
|
||||
foregroundMs,
|
||||
foregroundServiceMs,
|
||||
backgroundMs));
|
||||
}
|
||||
if (entry.getConsumedPower() == 0
|
||||
&& foregroundMs == 0
|
||||
&& foregroundServiceMs == 0
|
||||
&& backgroundMs == 0) {
|
||||
continue;
|
||||
}
|
||||
valuesList.add(
|
||||
ConvertUtils.convertBatteryEntryToContentValues(
|
||||
entry,
|
||||
batteryUsageStats,
|
||||
batteryLevel,
|
||||
batteryStatus,
|
||||
batteryHealth,
|
||||
snapshotBootTimestamp,
|
||||
snapshotTimestamp,
|
||||
isFullChargeStart));
|
||||
}
|
||||
}
|
||||
|
||||
int size = 1;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batteryusage;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Calendar;
|
||||
|
||||
/** A utility class for timestamp operations. */
|
||||
@@ -48,6 +49,10 @@ final class TimestampUtils {
|
||||
return calendar.getTimeInMillis();
|
||||
}
|
||||
|
||||
static long getSeconds(final long timeInMs) {
|
||||
return Duration.ofMillis(timeInMs).getSeconds();
|
||||
}
|
||||
|
||||
static boolean isMidnight(final long timestamp) {
|
||||
final Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(timestamp);
|
||||
|
||||
@@ -31,4 +31,5 @@ message BatteryUsageDiff {
|
||||
optional int64 foreground_usage_time = 14;
|
||||
optional int64 background_usage_time = 15;
|
||||
optional int64 screen_on_time = 16;
|
||||
optional int64 foreground_service_usage_time = 17;
|
||||
}
|
||||
|
||||
@@ -36,4 +36,5 @@ message BatteryInformation {
|
||||
optional double foreground_service_usage_consume_power = 17;
|
||||
optional double background_usage_consume_power = 18;
|
||||
optional double cached_usage_consume_power = 19;
|
||||
optional int64 foreground_service_usage_time_in_ms = 20;
|
||||
}
|
||||
Reference in New Issue
Block a user