@Test public void test_blank() { collector.getSnapshot(metrics); assertThat(metrics.total.activeTimeMs).isEqualTo(0); assertThat(metrics.total.powerMah).isEqualTo(0); assertThat(metrics.total.wakeUpTimeMs).isEqualTo(0); }
@Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; }
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; } }
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; }  }
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; }  @Override int hashCode(); synchronized void disable(); synchronized void register(SensorEventListener listener, Sensor sensor); synchronized void unregister(SensorEventListener listener, @Nullable Sensor sensor); @Override synchronized boolean getSnapshot(SensorMetrics snapshot); @Override SensorMetrics createMetrics(); }
SensorMetricsCollector extends SystemMetricsCollector<SensorMetrics> { @Override public synchronized boolean getSnapshot(SensorMetrics snapshot) { Utilities.checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mEnabled) { return false; } long currentTimeMs = SystemClock.elapsedRealtime(); snapshot.set(mCumulativeMetrics); for (int i = 0, l = mActiveSensors.size(); i < l; i++) { Sensor sensor = mActiveSensors.keyAt(i); SensorData data = mActiveSensors.valueAt(i); if (data.activeCount <= 0) { continue; } long sensorActiveTimeMs = currentTimeMs - data.startTimeMs; double sensorPowerMah = energyConsumedMah(sensor, sensorActiveTimeMs); snapshot.total.activeTimeMs += sensorActiveTimeMs; snapshot.total.powerMah += sensorPowerMah; boolean isWakeupSensor = Util.isWakeupSensor(sensor); if (isWakeupSensor) { snapshot.total.wakeUpTimeMs += sensorActiveTimeMs; } if (snapshot.isAttributionEnabled) { int type = sensor.getType(); SensorMetrics.Consumption consumption = snapshot.sensorConsumption.get(type); if (consumption == null) { consumption = new SensorMetrics.Consumption(); snapshot.sensorConsumption.put(type, consumption); } consumption.activeTimeMs += sensorActiveTimeMs; consumption.powerMah += sensorPowerMah; if (isWakeupSensor) { consumption.wakeUpTimeMs += sensorActiveTimeMs; } } } return true; }  @Override int hashCode(); synchronized void disable(); synchronized void register(SensorEventListener listener, Sensor sensor); synchronized void unregister(SensorEventListener listener, @Nullable Sensor sensor); @Override synchronized boolean getSnapshot(SensorMetrics snapshot); @Override SensorMetrics createMetrics();  }