use of android.os.UidBatteryConsumer in project android_packages_apps_Settings by omnirom.
the class BatteryEntry method add.
/**
* Adds the consumed power of the supplied BatteryConsumer to this entry. Also
* uses its package with highest drain, if necessary.
*/
public void add(BatteryConsumer batteryConsumer) {
mConsumedPower += batteryConsumer.getConsumedPower();
if (batteryConsumer instanceof UidBatteryConsumer) {
UidBatteryConsumer uidBatteryConsumer = (UidBatteryConsumer) batteryConsumer;
mTimeInForegroundMs += uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_FOREGROUND);
mTimeInBackgroundMs += uidBatteryConsumer.getTimeInStateMs(UidBatteryConsumer.STATE_BACKGROUND);
if (mDefaultPackageName == null) {
mDefaultPackageName = uidBatteryConsumer.getPackageWithHighestDrain();
}
}
}
use of android.os.UidBatteryConsumer in project android_packages_apps_Settings by omnirom.
the class BatteryAppListPreferenceController method getCoalescedUsageList.
/**
* We want to coalesce some UIDs. For example, dex2oat runs under a shared gid that
* exists for all users of the same app. We detect this case and merge the power use
* for dex2oat to the device OWNER's use of the app.
*
* @return A sorted list of apps using power.
*/
private List<BatteryEntry> getCoalescedUsageList(boolean showAllApps, boolean loadDataInBackground) {
final SparseArray<BatteryEntry> batteryEntryList = new SparseArray<>();
final ArrayList<BatteryEntry> results = new ArrayList<>();
final List<UidBatteryConsumer> uidBatteryConsumers = mBatteryUsageStats.getUidBatteryConsumers();
// Sort to have all apps with "real" UIDs first, followed by apps that are supposed
// to be combined with the real ones.
uidBatteryConsumers.sort(Comparator.comparingInt(consumer -> consumer.getUid() == getRealUid(consumer) ? 0 : 1));
for (int i = 0, size = uidBatteryConsumers.size(); i < size; i++) {
final UidBatteryConsumer consumer = uidBatteryConsumers.get(i);
final int uid = getRealUid(consumer);
final String[] packages = mPackageManager.getPackagesForUid(uid);
if (mBatteryUtils.shouldHideUidBatteryConsumerUnconditionally(consumer, packages)) {
continue;
}
final boolean isHidden = mBatteryUtils.shouldHideUidBatteryConsumer(consumer, packages);
if (isHidden && !showAllApps) {
continue;
}
final int index = batteryEntryList.indexOfKey(uid);
if (index < 0) {
// New entry.
batteryEntryList.put(uid, new BatteryEntry(mContext, mHandler, mUserManager, consumer, isHidden, uid, packages, null, loadDataInBackground));
} else {
// Combine BatterySippers if we already have one with this UID.
final BatteryEntry existingSipper = batteryEntryList.valueAt(index);
existingSipper.add(consumer);
}
}
final BatteryConsumer deviceConsumer = mBatteryUsageStats.getAggregateBatteryConsumer(BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_DEVICE);
final BatteryConsumer appsConsumer = mBatteryUsageStats.getAggregateBatteryConsumer(BatteryUsageStats.AGGREGATE_BATTERY_CONSUMER_SCOPE_ALL_APPS);
for (int componentId = 0; componentId < BatteryConsumer.POWER_COMPONENT_COUNT; componentId++) {
if (!showAllApps && mBatteryUtils.shouldHideDevicePowerComponent(deviceConsumer, componentId)) {
continue;
}
results.add(new BatteryEntry(mContext, componentId, deviceConsumer.getConsumedPower(componentId), appsConsumer.getConsumedPower(componentId), deviceConsumer.getUsageDurationMillis(componentId)));
}
for (int componentId = BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID; componentId < BatteryConsumer.FIRST_CUSTOM_POWER_COMPONENT_ID + deviceConsumer.getCustomPowerComponentCount(); componentId++) {
if (!showAllApps) {
continue;
}
results.add(new BatteryEntry(mContext, componentId, deviceConsumer.getCustomPowerComponentName(componentId), deviceConsumer.getConsumedPowerForCustomComponent(componentId), appsConsumer.getConsumedPowerForCustomComponent(componentId)));
}
if (showAllApps) {
final List<UserBatteryConsumer> userBatteryConsumers = mBatteryUsageStats.getUserBatteryConsumers();
for (int i = 0, size = userBatteryConsumers.size(); i < size; i++) {
final UserBatteryConsumer consumer = userBatteryConsumers.get(i);
results.add(new BatteryEntry(mContext, mHandler, mUserManager, consumer, /* isHidden */
true, Process.INVALID_UID, null, null, loadDataInBackground));
}
}
final int numUidSippers = batteryEntryList.size();
for (int i = 0; i < numUidSippers; i++) {
results.add(batteryEntryList.valueAt(i));
}
// The sort order must have changed, so re-sort based on total power use.
results.sort(BatteryEntry.COMPARATOR);
return results;
}
use of android.os.UidBatteryConsumer in project android_packages_apps_Settings by omnirom.
the class HighUsageDetector method detect.
@Override
public BatteryTip detect() {
final long lastFullChargeTimeMs = mBatteryUtils.calculateLastFullChargeTime(mBatteryUsageStats, System.currentTimeMillis());
if (mPolicy.highUsageEnabled && mDischarging) {
parseBatteryData();
if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
final double totalPower = mBatteryUsageStats.getConsumedPower();
final int dischargeAmount = mBatteryUsageStats.getDischargePercentage();
final List<UidBatteryConsumer> uidBatteryConsumers = mBatteryUsageStats.getUidBatteryConsumers();
// Sort by descending power
uidBatteryConsumers.sort((consumer1, consumer2) -> Double.compare(consumer2.getConsumedPower(), consumer1.getConsumedPower()));
for (UidBatteryConsumer consumer : uidBatteryConsumers) {
final double percent = mBatteryUtils.calculateBatteryPercent(consumer.getConsumedPower(), totalPower, dischargeAmount);
if ((percent + 0.5f < 1f) || mBatteryUtils.shouldHideUidBatteryConsumer(consumer)) {
// Don't show it if we should hide or usage percentage is lower than 1%
continue;
}
mHighUsageAppList.add(new AppInfo.Builder().setUid(consumer.getUid()).setPackageName(mBatteryUtils.getPackageName(consumer.getUid())).build());
if (mHighUsageAppList.size() >= mPolicy.highUsageAppCount) {
break;
}
}
// When in test mode, add an app if necessary
if (mPolicy.testHighUsageTip && mHighUsageAppList.isEmpty()) {
mHighUsageAppList.add(new AppInfo.Builder().setPackageName(SETTINGS_PACKAGE_NAME).setScreenOnTimeMs(TimeUnit.HOURS.toMillis(3)).build());
}
}
}
return new HighUsageTip(lastFullChargeTimeMs, mHighUsageAppList);
}
use of android.os.UidBatteryConsumer in project android_packages_apps_Settings by omnirom.
the class BatteryEntryTest method createBatteryEntryForApp.
private BatteryEntry createBatteryEntryForApp(String[] packages, String packageName, String highDrainPackage) {
UidBatteryConsumer consumer = mock(UidBatteryConsumer.class);
when(consumer.getUid()).thenReturn(APP_UID);
when(consumer.getPackageWithHighestDrain()).thenReturn(highDrainPackage);
return new BatteryEntry(mMockContext, mockHandler, mockUserManager, consumer, false, APP_UID, packages, packageName);
}
Aggregations