Merge changes I573e4fb9,I8e7baadc into oc-dev
am: 67e38774ce
Change-Id: Id3a830eb46004a3febdb9c4bf96a39b8c4afaedd
This commit is contained in:
@@ -22,7 +22,9 @@ import android.os.SystemClock;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseLongArray;
|
||||
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
@@ -115,25 +117,64 @@ public class BatteryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the {@link BatterySipper} that we should hide.
|
||||
* Remove the {@link BatterySipper} that we should hide and smear the screen usage based on
|
||||
* foreground activity time.
|
||||
*
|
||||
* @param sippers sipper list that need to check and remove
|
||||
* @return the total power of the hidden items of {@link BatterySipper}
|
||||
* for proportional smearing
|
||||
*/
|
||||
public double removeHiddenBatterySippers(List<BatterySipper> sippers) {
|
||||
double totalPowerMah = 0;
|
||||
double proportionalSmearPowerMah = 0;
|
||||
BatterySipper screenSipper = null;
|
||||
for (int i = sippers.size() - 1; i >= 0; i--) {
|
||||
final BatterySipper sipper = sippers.get(i);
|
||||
if (shouldHideSipper(sipper)) {
|
||||
sippers.remove(i);
|
||||
if (sipper.drainType != BatterySipper.DrainType.OVERCOUNTED) {
|
||||
// Don't add it if it is overcounted
|
||||
totalPowerMah += sipper.totalPowerMah;
|
||||
if (sipper.drainType != BatterySipper.DrainType.OVERCOUNTED
|
||||
&& sipper.drainType != BatterySipper.DrainType.SCREEN
|
||||
&& sipper.drainType != BatterySipper.DrainType.UNACCOUNTED) {
|
||||
// Don't add it if it is overcounted, unaccounted or screen
|
||||
proportionalSmearPowerMah += sipper.totalPowerMah;
|
||||
}
|
||||
}
|
||||
|
||||
if (sipper.drainType == BatterySipper.DrainType.SCREEN) {
|
||||
screenSipper = sipper;
|
||||
}
|
||||
}
|
||||
|
||||
return totalPowerMah;
|
||||
smearScreenBatterySipper(sippers, screenSipper);
|
||||
|
||||
return proportionalSmearPowerMah;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smear the screen on power usage among {@code sippers}, based on ratio of foreground activity
|
||||
* time.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
void smearScreenBatterySipper(List<BatterySipper> sippers, BatterySipper screenSipper) {
|
||||
final long rawRealtimeMs = SystemClock.elapsedRealtime();
|
||||
long totalActivityTimeMs = 0;
|
||||
final SparseLongArray activityTimeArray = new SparseLongArray();
|
||||
for (int i = 0, size = sippers.size(); i < size; i++) {
|
||||
final BatteryStats.Uid uid = sippers.get(i).uidObj;
|
||||
if (uid != null) {
|
||||
final long timeMs = getForegroundActivityTotalTimeMs(uid, rawRealtimeMs);
|
||||
activityTimeArray.put(uid.getUid(), timeMs);
|
||||
totalActivityTimeMs += timeMs;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalActivityTimeMs >= 10 * DateUtils.MINUTE_IN_MILLIS) {
|
||||
final double screenPowerMah = screenSipper.totalPowerMah;
|
||||
for (int i = 0, size = sippers.size(); i < size; i++) {
|
||||
final BatterySipper sipper = sippers.get(i);
|
||||
sipper.totalPowerMah += screenPowerMah * activityTimeArray.get(sipper.getUid(), 0)
|
||||
/ totalActivityTimeMs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,5 +227,15 @@ public class BatteryUtils {
|
||||
return mPackageManager == null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
long getForegroundActivityTotalTimeMs(BatteryStats.Uid uid, long rawRealtimeMs) {
|
||||
final BatteryStats.Timer timer = uid.getForegroundActivityTimer();
|
||||
if (timer != null) {
|
||||
return timer.getTotalTimeLocked(rawRealtimeMs, BatteryStats.STATS_SINCE_CHARGED);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -57,7 +57,7 @@ public abstract class PowerUsageBase extends DashboardFragment
|
||||
|
||||
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(getContext());
|
||||
mBatteryBroadcastReceiver.setBatteryChangedListener(() -> {
|
||||
getLoaderManager().restartLoader(0, null, this);
|
||||
restartBatteryStatsLoader();
|
||||
});
|
||||
|
||||
getLoaderManager().initLoader(0, icicle, this);
|
||||
@@ -95,6 +95,10 @@ public abstract class PowerUsageBase extends DashboardFragment
|
||||
}
|
||||
}
|
||||
|
||||
protected void restartBatteryStatsLoader() {
|
||||
getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
|
||||
}
|
||||
|
||||
protected abstract void refreshUi();
|
||||
|
||||
protected void updatePreference(BatteryHistoryPreference historyPref) {
|
||||
|
@@ -287,7 +287,7 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
item.setTitle(mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps);
|
||||
metricsFeatureProvider.action(context,
|
||||
MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE, mShowAllApps);
|
||||
refreshUi();
|
||||
restartBatteryStatsLoader();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
Reference in New Issue
Block a user