Merge "Batterystats BLE results counter takes in count" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-12 21:57:13 +00:00
committed by Android (Google) Code Review
4 changed files with 15 additions and 11 deletions

View File

@@ -132,7 +132,7 @@ interface IBatteryStats {
void noteBleScanStarted(in WorkSource ws);
void noteBleScanStopped(in WorkSource ws);
void noteResetBleScan();
void noteBleScanResult(in WorkSource ws);
void noteBleScanResults(in WorkSource ws, int numNewResults);
HealthStatsParceler takeUidSnapshot(int uid);
HealthStatsParceler[] takeUidSnapshots(in int[] uid);

View File

@@ -935,6 +935,10 @@ public class BatteryStatsImpl extends BatteryStats {
mCount.incrementAndGet();
}
void addAtomic(int delta) {
mCount.addAndGet(delta);
}
/**
* Clear state of this counter.
*/
@@ -4835,11 +4839,11 @@ public class BatteryStatsImpl extends BatteryStats {
}
}
public void noteBluetoothScanResultFromSourceLocked(WorkSource ws) {
public void noteBluetoothScanResultsFromSourceLocked(WorkSource ws, int numNewResults) {
final int N = ws.size();
for (int i = 0; i < N; i++) {
int uid = mapUid(ws.get(i));
getUidStatsLocked(uid).noteBluetoothScanResultLocked();
getUidStatsLocked(uid).noteBluetoothScanResultsLocked(numNewResults);
}
}
@@ -6050,8 +6054,8 @@ public class BatteryStatsImpl extends BatteryStats {
return mBluetoothScanResultCounter;
}
public void noteBluetoothScanResultLocked() {
createBluetoothScanResultCounterLocked().stepAtomic();
public void noteBluetoothScanResultsLocked(int numNewResults) {
createBluetoothScanResultCounterLocked().addAtomic(numNewResults);
}
@Override

View File

@@ -29,15 +29,15 @@ public class BatteryStatsNoteTest extends TestCase{
private static final int UID = 10500;
private static final WorkSource WS = new WorkSource(UID);
/** Test that BatteryStatsImpl.Uid.noteBluetoothScanResultLocked. */
/** Test that BatteryStatsImpl.Uid.noteBluetoothScanResultsLocked. */
@SmallTest
public void testNoteBluetoothScanResultLocked() throws Exception {
MockBatteryStatsImpl bi = new MockBatteryStatsImpl(new MockClocks());
bi.updateTimeBasesLocked(true, true, 0, 0);
bi.noteBluetoothScanResultFromSourceLocked(WS);
bi.noteBluetoothScanResultFromSourceLocked(WS);
assertEquals(2,
bi.noteBluetoothScanResultsFromSourceLocked(WS, 1);
bi.noteBluetoothScanResultsFromSourceLocked(WS, 100);
assertEquals(101,
bi.getUidStats().get(UID).getBluetoothScanResultCounter()
.getCountLocked(STATS_SINCE_CHARGED));
}

View File

@@ -966,10 +966,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
}
@Override
public void noteBleScanResult(WorkSource ws) {
public void noteBleScanResults(WorkSource ws, int numNewResults) {
enforceCallingPermission();
synchronized (mStats) {
mStats.noteBluetoothScanResultFromSourceLocked(ws);
mStats.noteBluetoothScanResultsFromSourceLocked(ws, numNewResults);
}
}