use of android.os.UserBatteryConsumer 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.UserBatteryConsumer in project android_packages_apps_Settings by omnirom.
the class BatteryEntryTest method createUserBatteryConsumer.
private BatteryEntry createUserBatteryConsumer(int userId) {
UserBatteryConsumer consumer = mock(UserBatteryConsumer.class);
when(consumer.getUserId()).thenReturn(userId);
return new BatteryEntry(mMockContext, mockHandler, mockUserManager, consumer, false, 0, null, null);
}
Aggregations