Search in sources :

Example 11 with SparseLongArray

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

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 12 with SparseLongArray

use of android.util.SparseLongArray in project robolectric by robolectric.

the class PackageRollbackInfoBuilderTest method build_onR.

@Test
@Config(sdk = Build.VERSION_CODES.R)
public void build_onR() {
    PackageRollbackInfo packageRollbackInfo = PackageRollbackInfoBuilder.newBuilder().setPackageRolledBackFrom(packageRolledBackFrom).setPackageRolledBackTo(packageRolledBackTo).addPendingBackup(BACKUP_ID).addPendingRestore(RESTORE_INFO_USER_ID, RESTORE_INFO_APP_ID, RESTORE_INFO_SEINFO).setIsApex(true).setIsApkInApex(true).addSnapshottedUser(SNAPSHOTTED_USER_ID).setCeSnapshotInodes(ceSnapshotInodes).build();
    assertThat(packageRollbackInfo).isNotNull();
    assertThat(packageRollbackInfo.getVersionRolledBackFrom()).isEqualTo(packageRolledBackFrom);
    assertThat(packageRollbackInfo.getVersionRolledBackTo()).isEqualTo(packageRolledBackTo);
    int[] pendingBackups = ((IntArray) ReflectionHelpers.callInstanceMethod(packageRollbackInfo, "getPendingBackups")).toArray();
    assertThat(pendingBackups).asList().containsExactly(BACKUP_ID);
    assertThat(packageRollbackInfo.getPendingRestores()).hasSize(1);
    assertThat(packageRollbackInfo.getPendingRestores().get(0).userId).isEqualTo(RESTORE_INFO_USER_ID);
    assertThat(packageRollbackInfo.getPendingRestores().get(0).appId).isEqualTo(RESTORE_INFO_APP_ID);
    assertThat(packageRollbackInfo.getPendingRestores().get(0).seInfo).isEqualTo(RESTORE_INFO_SEINFO);
    assertThat(packageRollbackInfo.isApex()).isTrue();
    assertThat(packageRollbackInfo.isApkInApex()).isTrue();
    int[] snapshottedUsers = ((IntArray) ReflectionHelpers.callInstanceMethod(packageRollbackInfo, "getSnapshottedUsers")).toArray();
    assertThat(snapshottedUsers).asList().containsExactly(SNAPSHOTTED_USER_ID);
    assertThat((SparseLongArray) ReflectionHelpers.callInstanceMethod(packageRollbackInfo, "getCeSnapshotInodes")).isEqualTo(ceSnapshotInodes);
}
Also used : IntArray(android.util.IntArray) PackageRollbackInfo(android.content.rollback.PackageRollbackInfo) SparseLongArray(android.util.SparseLongArray) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 13 with SparseLongArray

use of android.util.SparseLongArray in project ExoPlayer by google.

the class UtilTest method sparseLongArrayMinValue_returnsMinValue.

@Test
public void sparseLongArrayMinValue_returnsMinValue() {
    SparseLongArray sparseLongArray = new SparseLongArray();
    sparseLongArray.put(0, 12);
    sparseLongArray.put(25, 10);
    sparseLongArray.put(42, 11);
    assertThat(minValue(sparseLongArray)).isEqualTo(10);
}
Also used : SparseLongArray(android.util.SparseLongArray) Test(org.junit.Test)

Example 14 with SparseLongArray

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

the class BatteryDatabaseManagerTest method allActionFunctions.

@Test
public void allActionFunctions() {
    final long timestamp = System.currentTimeMillis();
    mBatteryDatabaseManager.insertAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_OLD, PACKAGE_NAME_OLD, 0);
    mBatteryDatabaseManager.insertAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_OLD, PACKAGE_NAME_OLD, 1);
    mBatteryDatabaseManager.insertAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_NEW, PACKAGE_NAME_NEW, timestamp);
    final SparseLongArray timeArray = mBatteryDatabaseManager.queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
    assertThat(timeArray.size()).isEqualTo(2);
    assertThat(timeArray.get(UID_OLD)).isEqualTo(1);
    assertThat(timeArray.get(UID_NEW)).isEqualTo(timestamp);
    mBatteryDatabaseManager.deleteAction(AnomalyDatabaseHelper.ActionType.RESTRICTION, UID_NEW, PACKAGE_NAME_NEW);
    final SparseLongArray recentTimeArray = mBatteryDatabaseManager.queryActionTime(AnomalyDatabaseHelper.ActionType.RESTRICTION);
    assertThat(recentTimeArray.size()).isEqualTo(1);
    assertThat(timeArray.get(UID_OLD)).isEqualTo(1);
}
Also used : SparseLongArray(android.util.SparseLongArray) Test(org.junit.Test)

Example 15 with SparseLongArray

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

the class BatteryDatabaseManager method queryActionTime.

/**
 * Query latest timestamps when an app has been performed action {@code type}
 *
 * @param type of action been performed
 * @return {@link SparseLongArray} where key is uid and value is timestamp
 */
public synchronized SparseLongArray queryActionTime(@AnomalyDatabaseHelper.ActionType int type) {
    final SparseLongArray timeStamps = new SparseLongArray();
    final SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    final String[] projection = { ActionColumns.UID, ActionColumns.TIME_STAMP_MS };
    final String selection = ActionColumns.ACTION_TYPE + " = ? ";
    final String[] selectionArgs = new String[] { String.valueOf(type) };
    try (Cursor cursor = db.query(TABLE_ACTION, projection, selection, selectionArgs, null, /* groupBy */
    null, /* having */
    null)) {
        final int uidIndex = cursor.getColumnIndex(ActionColumns.UID);
        final int timestampIndex = cursor.getColumnIndex(ActionColumns.TIME_STAMP_MS);
        while (cursor.moveToNext()) {
            final int uid = cursor.getInt(uidIndex);
            final long timeStamp = cursor.getLong(timestampIndex);
            timeStamps.append(uid, timeStamp);
        }
    }
    return timeStamps;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SparseLongArray(android.util.SparseLongArray)

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