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;
}
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations