Search in sources :

Example 26 with SparseLongArray

use of android.util.SparseLongArray in project android_packages_apps_Settings by crdroidandroid.

the class BatteryUtils method smearScreenBatterySipper.

/**
 * Smear the screen on power usage among {@code sippers}, based on ratio of foreground activity
 * time.
 */
@VisibleForTesting
void smearScreenBatterySipper(List<BatterySipper> sippers, BatterySipper screenSipper) {
    long totalActivityTimeMs = 0;
    final SparseLongArray activityTimeArray = new SparseLongArray();
    for (int i = 0, size = sippers.size(); i < size; i++) {
        final BatteryStats.Uid uid = sippers.get(i).uidObj;
        if (uid != null) {
            final long timeMs = getProcessTimeMs(StatusType.SCREEN_USAGE, uid, BatteryStats.STATS_SINCE_CHARGED);
            activityTimeArray.put(uid.getUid(), timeMs);
            totalActivityTimeMs += timeMs;
        }
    }
    if (totalActivityTimeMs >= 10 * DateUtils.MINUTE_IN_MILLIS) {
        final double screenPowerMah = screenSipper.totalPowerMah;
        for (int i = 0, size = sippers.size(); i < size; i++) {
            final BatterySipper sipper = sippers.get(i);
            sipper.totalPowerMah += screenPowerMah * activityTimeArray.get(sipper.getUid(), 0) / totalActivityTimeMs;
        }
    }
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) SparseLongArray(android.util.SparseLongArray) BatteryStats(android.os.BatteryStats) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 27 with SparseLongArray

use of android.util.SparseLongArray in project android_packages_apps_Settings by SudaMod.

the class BatteryUtils method smearScreenBatterySipper.

/**
 * Smear the screen on power usage among {@code sippers}, based on ratio of foreground activity
 * time.
 */
@VisibleForTesting
void smearScreenBatterySipper(List<BatterySipper> sippers, BatterySipper screenSipper) {
    long totalActivityTimeMs = 0;
    final SparseLongArray activityTimeArray = new SparseLongArray();
    for (int i = 0, size = sippers.size(); i < size; i++) {
        final BatteryStats.Uid uid = sippers.get(i).uidObj;
        if (uid != null) {
            final long timeMs = getProcessTimeMs(StatusType.SCREEN_USAGE, uid, BatteryStats.STATS_SINCE_CHARGED);
            activityTimeArray.put(uid.getUid(), timeMs);
            totalActivityTimeMs += timeMs;
        }
    }
    if (totalActivityTimeMs >= 10 * DateUtils.MINUTE_IN_MILLIS) {
        final double screenPowerMah = screenSipper.totalPowerMah;
        for (int i = 0, size = sippers.size(); i < size; i++) {
            final BatterySipper sipper = sippers.get(i);
            sipper.totalPowerMah += screenPowerMah * activityTimeArray.get(sipper.getUid(), 0) / totalActivityTimeMs;
        }
    }
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) SparseLongArray(android.util.SparseLongArray) BatteryStats(android.os.BatteryStats) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 28 with SparseLongArray

use of android.util.SparseLongArray in project platform_packages_apps_Settings by BlissRoms.

the class BatteryUtils method smearScreenBatterySipper.

/**
 * Smear the screen on power usage among {@code sippers}, based on ratio of foreground activity
 * time.
 */
@VisibleForTesting
void smearScreenBatterySipper(List<BatterySipper> sippers, BatterySipper screenSipper) {
    long totalActivityTimeMs = 0;
    final SparseLongArray activityTimeArray = new SparseLongArray();
    for (int i = 0, size = sippers.size(); i < size; i++) {
        final BatteryStats.Uid uid = sippers.get(i).uidObj;
        if (uid != null) {
            final long timeMs = getProcessTimeMs(StatusType.SCREEN_USAGE, uid, BatteryStats.STATS_SINCE_CHARGED);
            activityTimeArray.put(uid.getUid(), timeMs);
            totalActivityTimeMs += timeMs;
        }
    }
    if (totalActivityTimeMs >= 10 * DateUtils.MINUTE_IN_MILLIS) {
        final double screenPowerMah = screenSipper.totalPowerMah;
        for (int i = 0, size = sippers.size(); i < size; i++) {
            final BatterySipper sipper = sippers.get(i);
            sipper.totalPowerMah += screenPowerMah * activityTimeArray.get(sipper.getUid(), 0) / totalActivityTimeMs;
        }
    }
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) SparseLongArray(android.util.SparseLongArray) BatteryStats(android.os.BatteryStats) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 29 with SparseLongArray

use of android.util.SparseLongArray in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RestrictedAppDetailsTest method refreshUi_displayPreference.

@Test
public void refreshUi_displayPreference() throws Exception {
    doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfoAsUser(PACKAGE_NAME, 0, USER_ID);
    doReturn(APP_NAME).when(mPackageManager).getApplicationLabel(mApplicationInfo);
    doReturn(true).when(mRestrictedAppDetails.mBatteryUtils).isForceAppStandbyEnabled(UID, PACKAGE_NAME);
    final SparseLongArray timestampArray = new SparseLongArray();
    timestampArray.put(UID, System.currentTimeMillis() - TimeUnit.HOURS.toMillis(5));
    doReturn(timestampArray).when(mBatteryDatabaseManager).queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
    mRestrictedAppDetails.refreshUi();
    assertThat(mRestrictedAppDetails.mRestrictedAppListGroup.getPreferenceCount()).isEqualTo(1);
    final CheckBoxPreference preference = (CheckBoxPreference) mRestrictedAppDetails.mRestrictedAppListGroup.getPreference(0);
    assertThat(preference.getTitle()).isEqualTo(APP_NAME);
    assertThat(preference.isChecked()).isTrue();
    assertThat(preference.getSummary()).isEqualTo("Restricted 5 hours ago");
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) SparseLongArray(android.util.SparseLongArray) Test(org.junit.Test)

Example 30 with SparseLongArray

use of android.util.SparseLongArray in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RestrictedAppDetails method refreshUi.

@VisibleForTesting
void refreshUi() {
    mRestrictedAppListGroup.removeAll();
    final Context context = getPrefContext();
    final SparseLongArray timestampArray = mBatteryDatabaseManager.queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
    final long now = System.currentTimeMillis();
    for (int i = 0, size = mAppInfos.size(); i < size; i++) {
        final CheckBoxPreference checkBoxPreference = new AppCheckBoxPreference(context);
        final AppInfo appInfo = mAppInfos.get(i);
        try {
            final ApplicationInfo applicationInfo = mPackageManager.getApplicationInfoAsUser(appInfo.packageName, 0, /* flags */
            UserHandle.getUserId(appInfo.uid));
            checkBoxPreference.setChecked(mBatteryUtils.isForceAppStandbyEnabled(appInfo.uid, appInfo.packageName));
            checkBoxPreference.setTitle(mPackageManager.getApplicationLabel(applicationInfo));
            checkBoxPreference.setIcon(Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, appInfo.packageName, UserHandle.getUserId(appInfo.uid)));
            checkBoxPreference.setKey(getKeyFromAppInfo(appInfo));
            checkBoxPreference.setOnPreferenceChangeListener((pref, value) -> {
                final BatteryTipDialogFragment fragment = createDialogFragment(appInfo, (Boolean) value);
                fragment.setTargetFragment(this, 0);
                fragment.show(getFragmentManager(), TAG);
                return false;
            });
            final long timestamp = timestampArray.get(appInfo.uid, TIME_NULL);
            if (timestamp != TIME_NULL) {
                checkBoxPreference.setSummary(getString(R.string.restricted_app_time_summary, StringUtil.formatRelativeTime(context, now - timestamp, false)));
            }
            final CharSequence test = checkBoxPreference.getSummaryOn();
            mRestrictedAppListGroup.addPreference(checkBoxPreference);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Can't find package: " + appInfo.packageName);
        }
    }
}
Also used : Context(android.content.Context) BatteryTipDialogFragment(com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment) PackageManager(android.content.pm.PackageManager) CheckBoxPreference(androidx.preference.CheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) ApplicationInfo(android.content.pm.ApplicationInfo) SparseLongArray(android.util.SparseLongArray) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

SparseLongArray (android.util.SparseLongArray)32 BatteryStats (android.os.BatteryStats)7 BatterySipper (com.android.internal.os.BatterySipper)7 Test (org.junit.Test)7 VisibleForTesting (android.support.annotation.VisibleForTesting)6 Animator (android.animation.Animator)5 SurfaceView (android.view.SurfaceView)5 TextureView (android.view.TextureView)5 View (android.view.View)5 ListView (android.widget.ListView)5 NetworkStats (android.net.NetworkStats)4 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 PackageRollbackInfo (android.content.rollback.PackageRollbackInfo)2 IntArray (android.util.IntArray)2 SparseArray (android.util.SparseArray)2 SparseBooleanArray (android.util.SparseBooleanArray)2 SparseIntArray (android.util.SparseIntArray)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 CheckBoxPreference (androidx.preference.CheckBoxPreference)2