use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class PowerUsageSummary 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<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
final SparseArray<BatterySipper> uidList = new SparseArray<>();
final ArrayList<BatterySipper> results = new ArrayList<>();
final int numSippers = sippers.size();
for (int i = 0; i < numSippers; i++) {
BatterySipper sipper = sippers.get(i);
if (sipper.getUid() > 0) {
int realUid = sipper.getUid();
// actual app UID.
if (isSharedGid(sipper.getUid())) {
realUid = UserHandle.getUid(UserHandle.USER_SYSTEM, UserHandle.getAppIdFromSharedAppGid(sipper.getUid()));
}
// Check if this UID is a system UID (mediaserver, logd, nfc, drm, etc).
if (isSystemUid(realUid) && !"mediaserver".equals(sipper.packageWithHighestDrain)) {
// Use the system UID for all UIDs running in their own sandbox that
// are not apps. We exclude mediaserver because we already are expected to
// report that as a separate item.
realUid = Process.SYSTEM_UID;
}
if (realUid != sipper.getUid()) {
// Replace the BatterySipper with a new one with the real UID set.
BatterySipper newSipper = new BatterySipper(sipper.drainType, new FakeUid(realUid), 0.0);
newSipper.add(sipper);
newSipper.packageWithHighestDrain = sipper.packageWithHighestDrain;
newSipper.mPackages = sipper.mPackages;
sipper = newSipper;
}
int index = uidList.indexOfKey(realUid);
if (index < 0) {
// New entry.
uidList.put(realUid, sipper);
} else {
// Combine BatterySippers if we already have one with this UID.
final BatterySipper existingSipper = uidList.valueAt(index);
existingSipper.add(sipper);
if (existingSipper.packageWithHighestDrain == null && sipper.packageWithHighestDrain != null) {
existingSipper.packageWithHighestDrain = sipper.packageWithHighestDrain;
}
final int existingPackageLen = existingSipper.mPackages != null ? existingSipper.mPackages.length : 0;
final int newPackageLen = sipper.mPackages != null ? sipper.mPackages.length : 0;
if (newPackageLen > 0) {
String[] newPackages = new String[existingPackageLen + newPackageLen];
if (existingPackageLen > 0) {
System.arraycopy(existingSipper.mPackages, 0, newPackages, 0, existingPackageLen);
}
System.arraycopy(sipper.mPackages, 0, newPackages, existingPackageLen, newPackageLen);
existingSipper.mPackages = newPackages;
}
}
} else {
results.add(sipper);
}
}
final int numUidSippers = uidList.size();
for (int i = 0; i < numUidSippers; i++) {
results.add(uidList.valueAt(i));
}
// The sort order must have changed, so re-sort based on total power use.
mBatteryUtils.sortUsageList(results);
return results;
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class BluetoothScanAnomalyDetector method detectAnomalies.
@Override
public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, String targetPackageName) {
final List<BatterySipper> batterySippers = batteryStatsHelper.getUsageList();
final List<Anomaly> anomalies = new ArrayList<>();
final int targetUid = mBatteryUtils.getPackageUid(targetPackageName);
final long elapsedRealtimeMs = SystemClock.elapsedRealtime();
for (int i = 0, size = batterySippers.size(); i < size; i++) {
final BatterySipper sipper = batterySippers.get(i);
final BatteryStats.Uid uid = sipper.uidObj;
if (uid == null || mBatteryUtils.shouldHideSipper(sipper) || (targetUid != BatteryUtils.UID_NULL && targetUid != uid.getUid())) {
continue;
}
final long bluetoothTimeMs = getBluetoothUnoptimizedBgTimeMs(uid, elapsedRealtimeMs);
if (bluetoothTimeMs > mBluetoothScanningThreshold) {
final String packageName = mBatteryUtils.getPackageName(uid.getUid());
final CharSequence displayName = Utils.getApplicationLabel(mContext, packageName);
Anomaly anomaly = new Anomaly.Builder().setUid(uid.getUid()).setType(Anomaly.AnomalyType.BLUETOOTH_SCAN).setDisplayName(displayName).setPackageName(packageName).setBluetoothScanningTimeMs(bluetoothTimeMs).build();
if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) {
anomalies.add(anomaly);
}
}
}
return anomalies;
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class WakeLockAnomalyDetector method detectAnomalies.
@Override
public List<Anomaly> detectAnomalies(BatteryStatsHelper batteryStatsHelper, String targetPackageName) {
final List<BatterySipper> batterySippers = batteryStatsHelper.getUsageList();
final List<Anomaly> anomalies = new ArrayList<>();
final long rawRealtime = SystemClock.elapsedRealtime();
final int targetUid = mBatteryUtils.getPackageUid(targetPackageName);
// Check the app one by one
for (int i = 0, size = batterySippers.size(); i < size; i++) {
final BatterySipper sipper = batterySippers.get(i);
final BatteryStats.Uid uid = sipper.uidObj;
if (uid == null || mBatteryUtils.shouldHideSipper(sipper) || (targetUid != BatteryUtils.UID_NULL && targetUid != uid.getUid())) {
continue;
}
final long currentDurationMs = getCurrentDurationMs(uid, rawRealtime);
final long backgroundDurationMs = getBackgroundTotalDurationMs(uid, rawRealtime);
if (backgroundDurationMs > mWakeLockThresholdMs && currentDurationMs != 0) {
final String packageName = mBatteryUtils.getPackageName(uid.getUid());
final CharSequence displayName = Utils.getApplicationLabel(mContext, packageName);
Anomaly anomaly = new Anomaly.Builder().setUid(uid.getUid()).setType(Anomaly.AnomalyType.WAKE_LOCK).setDisplayName(displayName).setPackageName(packageName).setWakeLockTimeMs(backgroundDurationMs).build();
if (mAnomalyUtils.getAnomalyAction(anomaly).isActionActive(anomaly)) {
anomalies.add(anomaly);
}
}
}
return anomalies;
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class BatteryEntryTest method createSipperForApp.
private BatterySipper createSipperForApp() {
BatterySipper sipper = new BatterySipper(DrainType.APP, new FakeUid(APP_UID), 0);
sipper.packageWithHighestDrain = HIGH_DRAIN_PACKAGE;
return sipper;
}
use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by LineageOS.
the class BatteryUtilsTest method createTestSmearBatterySipper.
private BatterySipper createTestSmearBatterySipper(long topTime, double totalPowerMah, int uidCode, boolean isUidNull) {
final BatterySipper sipper = mock(BatterySipper.class);
sipper.drainType = BatterySipper.DrainType.APP;
sipper.totalPowerMah = totalPowerMah;
doReturn(uidCode).when(sipper).getUid();
if (!isUidNull) {
final BatteryStats.Uid uid = mock(BatteryStats.Uid.class, RETURNS_DEEP_STUBS);
doReturn(topTime).when(mBatteryUtils).getProcessTimeMs(eq(BatteryUtils.StatusType.SCREEN_USAGE), eq(uid), anyInt());
doReturn(uidCode).when(uid).getUid();
sipper.uidObj = uid;
}
return sipper;
}
Aggregations