Search in sources :

Example 91 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by omnirom.

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;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper)

Example 92 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by omnirom.

the class PowerUsageSummary method updateScreenPreference.

@VisibleForTesting
void updateScreenPreference() {
    final BatterySipper sipper = findBatterySipperByType(mStatsHelper.getUsageList(), DrainType.SCREEN);
    final long usageTimeMs = sipper != null ? sipper.usageTimeMs : 0;
    mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(getContext(), usageTimeMs, false));
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 93 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by omnirom.

the class PowerUsageSummary method getFakeStats.

private static List<BatterySipper> getFakeStats() {
    ArrayList<BatterySipper> stats = new ArrayList<>();
    float use = 5;
    for (DrainType type : DrainType.values()) {
        if (type == DrainType.APP) {
            continue;
        }
        stats.add(new BatterySipper(type, null, use));
        use += 5;
    }
    for (int i = 0; i < 100; i++) {
        stats.add(new BatterySipper(DrainType.APP, new FakeUid(Process.FIRST_APPLICATION_UID + i), use));
    }
    stats.add(new BatterySipper(DrainType.APP, new FakeUid(0), use));
    // Simulate dex2oat process.
    BatterySipper sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID)), 10.0f);
    sipper.packageWithHighestDrain = "dex2oat";
    stats.add(sipper);
    sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.FIRST_APPLICATION_UID + 1)), 10.0f);
    sipper.packageWithHighestDrain = "dex2oat";
    stats.add(sipper);
    sipper = new BatterySipper(DrainType.APP, new FakeUid(UserHandle.getSharedAppGid(Process.LOG_UID)), 9.0f);
    stats.add(sipper);
    return stats;
}
Also used : DrainType(com.android.internal.os.BatterySipper.DrainType) BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList)

Example 94 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by omnirom.

the class PowerUsageSummary method refreshAppListGroup.

private void refreshAppListGroup() {
    final Context context = getContext();
    final PowerProfile powerProfile = mStatsHelper.getPowerProfile();
    final BatteryStats stats = mStatsHelper.getStats();
    final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
    boolean addedSome = false;
    TypedArray array = context.obtainStyledAttributes(new int[] { android.R.attr.colorControlNormal });
    final int colorControl = array.getColor(0, 0);
    array.recycle();
    final int dischargeAmount = USE_FAKE_DATA ? 5000 : stats != null ? stats.getDischargeAmount(mStatsType) : 0;
    cacheRemoveAllPrefs(mAppListGroup);
    mAppListGroup.setOrderingAsAdded(false);
    if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
        final List<BatterySipper> usageList = getCoalescedUsageList(USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
        double hiddenPowerMah = mShowAllApps ? 0 : mBatteryUtils.removeHiddenBatterySippers(usageList);
        mBatteryUtils.sortUsageList(usageList);
        final int numSippers = usageList.size();
        for (int i = 0; i < numSippers; i++) {
            final BatterySipper sipper = usageList.get(i);
            double totalPower = USE_FAKE_DATA ? 4000 : mStatsHelper.getTotalPower();
            final double percentOfTotal = mBatteryUtils.calculateBatteryPercent(sipper.totalPowerMah, totalPower, hiddenPowerMah, dischargeAmount);
            if (((int) (percentOfTotal + .5)) < 1) {
                continue;
            }
            if (shouldHideSipper(sipper)) {
                continue;
            }
            final UserHandle userHandle = new UserHandle(UserHandle.getUserId(sipper.getUid()));
            final BatteryEntry entry = new BatteryEntry(getActivity(), mHandler, mUm, sipper);
            final Drawable badgedIcon = mUm.getBadgedIconForUser(entry.getIcon(), userHandle);
            final CharSequence contentDescription = mUm.getBadgedLabelForUser(entry.getLabel(), userHandle);
            final String key = extractKeyFromSipper(sipper);
            PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
            if (pref == null) {
                pref = new PowerGaugePreference(getPrefContext(), badgedIcon, contentDescription, entry);
                pref.setKey(key);
            }
            final double percentOfMax = (sipper.totalPowerMah * 100) / mStatsHelper.getMaxPower();
            sipper.percent = percentOfTotal;
            pref.setTitle(entry.getLabel());
            pref.setOrder(i + 1);
            pref.setPercent(percentOfTotal);
            pref.shouldShowAnomalyIcon(false);
            if (sipper.usageTimeMs == 0 && sipper.drainType == DrainType.APP) {
                sipper.usageTimeMs = mBatteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, sipper.uidObj, mStatsType);
            }
            setUsageSummary(pref, sipper);
            if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == Process.ROOT_UID) && sipper.drainType != DrainType.USER) {
                pref.setTint(colorControl);
            }
            addedSome = true;
            mAppListGroup.addPreference(pref);
            if (mAppListGroup.getPreferenceCount() - getCachedCount() > (MAX_ITEMS_TO_LIST + 1)) {
                break;
            }
        }
    }
    if (!addedSome) {
        addNotAvailableMessage();
    }
    removeCachedPrefs(mAppListGroup);
    BatteryEntry.startRequestQueue();
}
Also used : Context(android.content.Context) BatterySipper(com.android.internal.os.BatterySipper) Drawable(android.graphics.drawable.Drawable) BatteryStats(android.os.BatteryStats) TypedArray(android.content.res.TypedArray) UserHandle(android.os.UserHandle) PowerProfile(com.android.internal.os.PowerProfile)

Example 95 with BatterySipper

use of com.android.internal.os.BatterySipper in project android_packages_apps_Settings by omnirom.

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;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) ArrayList(java.util.ArrayList) Anomaly(com.android.settings.fuelgauge.anomaly.Anomaly) BatteryStats(android.os.BatteryStats)

Aggregations

BatterySipper (com.android.internal.os.BatterySipper)148 ArrayList (java.util.ArrayList)60 BatteryStats (android.os.BatteryStats)48 VisibleForTesting (android.support.annotation.VisibleForTesting)30 Test (org.junit.Test)29 Anomaly (com.android.settings.fuelgauge.anomaly.Anomaly)18 HashMap (java.util.HashMap)16 UserHandle (android.os.UserHandle)15 ArrayMap (android.util.ArrayMap)10 BatteryStatsHelper (com.android.internal.os.BatteryStatsHelper)10 Map (java.util.Map)10 Drawable (android.graphics.drawable.Drawable)8 SparseArray (android.util.SparseArray)8 DrainType (com.android.internal.os.BatterySipper.DrainType)8 PowerProfile (com.android.internal.os.PowerProfile)8 Bundle (android.os.Bundle)7 SparseLongArray (android.util.SparseLongArray)7 Context (android.content.Context)6 TypedArray (android.content.res.TypedArray)6 PowerUsageData (com.android.settings.fuelgauge.PowerUsageAdvanced.PowerUsageData)6