Search in sources :

Example 66 with BatterySipper

use of com.android.internal.os.BatterySipper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryEntryTest method batteryEntryForAOD_containCorrectInfo.

@Test
public void batteryEntryForAOD_containCorrectInfo() {
    final BatterySipper batterySipper = mock(BatterySipper.class);
    batterySipper.drainType = DrainType.AMBIENT_DISPLAY;
    final BatteryEntry entry = new BatteryEntry(RuntimeEnvironment.application, mockHandler, mockUserManager, batterySipper);
    assertThat(entry.iconId).isEqualTo(R.drawable.ic_settings_aod);
    assertThat(entry.name).isEqualTo("Ambient display");
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) Test(org.junit.Test)

Example 67 with BatterySipper

use of com.android.internal.os.BatterySipper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryEntryTest method createSipperForSystem.

private BatterySipper createSipperForSystem() {
    BatterySipper sipper = new BatterySipper(DrainType.APP, new FakeUid(SYSTEM_UID), 0);
    sipper.packageWithHighestDrain = HIGH_DRAIN_PACKAGE;
    sipper.mPackages = SYSTEM_PACKAGES;
    return sipper;
}
Also used : BatterySipper(com.android.internal.os.BatterySipper)

Example 68 with BatterySipper

use of com.android.internal.os.BatterySipper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryAppListPreferenceController 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 69 with BatterySipper

use of com.android.internal.os.BatterySipper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryAppListPreferenceController method refreshAppListGroup.

public void refreshAppListGroup(BatteryStatsHelper statsHelper, boolean showAllApps) {
    if (!isAvailable()) {
        return;
    }
    mBatteryStatsHelper = statsHelper;
    mAppListGroup.setTitle(R.string.power_usage_list_summary);
    final PowerProfile powerProfile = statsHelper.getPowerProfile();
    final BatteryStats stats = statsHelper.getStats();
    final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
    boolean addedSome = false;
    final int dischargeAmount = USE_FAKE_DATA ? 5000 : stats != null ? stats.getDischargeAmount(STATS_TYPE) : 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() : statsHelper.getUsageList());
        double hiddenPowerMah = showAllApps ? 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 : statsHelper.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(mActivity, mHandler, mUserManager, sipper);
            final Drawable badgedIcon = mUserManager.getBadgedIconForUser(entry.getIcon(), userHandle);
            final CharSequence contentDescription = mUserManager.getBadgedLabelForUser(entry.getLabel(), userHandle);
            final String key = extractKeyFromSipper(sipper);
            PowerGaugePreference pref = (PowerGaugePreference) getCachedPreference(key);
            if (pref == null) {
                pref = new PowerGaugePreference(mPrefContext, badgedIcon, contentDescription, entry);
                pref.setKey(key);
            }
            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, STATS_TYPE);
            }
            setUsageSummary(pref, sipper);
            addedSome = true;
            mAppListGroup.addPreference(pref);
            if (mAppListGroup.getPreferenceCount() - getCachedCount() > (MAX_ITEMS_TO_LIST + 1)) {
                break;
            }
        }
    }
    if (!addedSome) {
        addNotAvailableMessage();
    }
    removeCachedPrefs(mAppListGroup);
    BatteryEntry.startRequestQueue();
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) Drawable(android.graphics.drawable.Drawable) BatteryStats(android.os.BatteryStats) UserHandle(android.os.UserHandle) PowerProfile(com.android.internal.os.PowerProfile)

Example 70 with BatterySipper

use of com.android.internal.os.BatterySipper in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AdvancedPowerUsageDetail method startBatteryDetailPage.

@VisibleForTesting
static void startBatteryDetailPage(Activity caller, BatteryUtils batteryUtils, InstrumentedPreferenceFragment fragment, BatteryStatsHelper helper, int which, BatteryEntry entry, String usagePercent) {
    // Initialize mStats if necessary.
    helper.getStats();
    final Bundle args = new Bundle();
    final BatterySipper sipper = entry.sipper;
    final BatteryStats.Uid uid = sipper.uidObj;
    final boolean isTypeApp = sipper.drainType == BatterySipper.DrainType.APP;
    final long foregroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(BatteryUtils.StatusType.FOREGROUND, uid, which) : sipper.usageTimeMs;
    final long backgroundTimeMs = isTypeApp ? batteryUtils.getProcessTimeMs(BatteryUtils.StatusType.BACKGROUND, uid, which) : 0;
    if (ArrayUtils.isEmpty(sipper.mPackages)) {
        // populate data for system app
        args.putString(EXTRA_LABEL, entry.getLabel());
        args.putInt(EXTRA_ICON_ID, entry.iconId);
        args.putString(EXTRA_PACKAGE_NAME, null);
    } else {
        // populate data for normal app
        args.putString(EXTRA_PACKAGE_NAME, entry.defaultPackageName != null ? entry.defaultPackageName : sipper.mPackages[0]);
    }
    args.putInt(EXTRA_UID, sipper.getUid());
    args.putLong(EXTRA_BACKGROUND_TIME, backgroundTimeMs);
    args.putLong(EXTRA_FOREGROUND_TIME, foregroundTimeMs);
    args.putString(EXTRA_POWER_USAGE_PERCENT, usagePercent);
    args.putInt(EXTRA_POWER_USAGE_AMOUNT, (int) sipper.totalPowerMah);
    new SubSettingLauncher(caller).setDestination(AdvancedPowerUsageDetail.class.getName()).setTitleRes(R.string.battery_details_title).setArguments(args).setSourceMetricsCategory(fragment.getMetricsCategory()).setUserHandle(new UserHandle(getUserIdToLaunchAdvancePowerUsageDetail(sipper))).launch();
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle) UserHandle(android.os.UserHandle) BatteryStats(android.os.BatteryStats) VisibleForTesting(androidx.annotation.VisibleForTesting)

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