@Test public void testEmptyBatteryIntent() { DeviceBatteryMetrics metrics = new DeviceBatteryMetrics(); DeviceBatteryMetricsCollector collector = new DeviceBatteryMetricsCollector(mContext); collector.getSnapshot(metrics); }
@Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } }
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } }
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); }
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics(); }
DeviceBatteryMetricsCollector extends SystemMetricsCollector<DeviceBatteryMetrics> { @Override @ThreadSafe(enableChecks = false) public boolean getSnapshot(DeviceBatteryMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); snapshot.batteryLevelPct = getBatteryLevel(getBatteryIntent()); long now = SystemClock.elapsedRealtime(); synchronized (this) { if (mIsCurrentlyCharging) { snapshot.chargingRealtimeMs = mChargingRealtimeMs + (now - mLastUpdateMs); snapshot.batteryRealtimeMs = mBatteryRealtimeMs; } else { snapshot.chargingRealtimeMs = mChargingRealtimeMs; snapshot.batteryRealtimeMs = mBatteryRealtimeMs + (now - mLastUpdateMs); } return true; } } DeviceBatteryMetricsCollector(Context context); @Override @ThreadSafe(enableChecks = false) boolean getSnapshot(DeviceBatteryMetrics snapshot); @Override DeviceBatteryMetrics createMetrics();  }