Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Simple Battery Notifier

An Android app that monitors the device battery and raises notifications for low/critical/full
levels, high temperature, and battery health. This glossary pins down the terms the app's UI and
code use so they don't drift.

## Language

**Drain rate**:
How fast the battery level is falling while discharging, expressed in percentage-points per hour
(%/h). The normalized, device-size-independent headline metric for consumption.
_Avoid_: consumption, usage, speed.

**Charge rate**:
How fast the battery level is rising while charging, in %/h. The charging counterpart of the drain
rate.
_Avoid_: charging speed.

**Instantaneous current**:
The live current flowing in or out of the battery right now, in milliamps (mA), read from
`BatteryManager.BATTERY_PROPERTY_CURRENT_NOW`. Shown as raw detail; not normalized, so it is not
colored on its own.
_Avoid_: amperage, draw, consumption.

**Design capacity**:
The battery's rated full capacity when new (mAh), from the manufacturer's spec. User-entered or
best-effort auto-detected from the kernel. Distinct from the measured current full capacity.
_Avoid_: rated capacity (in prose only), max capacity.
</content>
</invoke>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public final class BatteryDO {
private int voltage;
private boolean present;
private int capacity;
// Instantaneous current in µA from BATTERY_PROPERTY_CURRENT_NOW; Integer.MIN_VALUE when the device
// doesn't report it. Sign convention varies by OEM, so callers derive direction from the status.
private int currentMicroAmps = Integer.MIN_VALUE;
private String technology;
private String powerSource;
private String health;
Expand Down Expand Up @@ -124,6 +127,15 @@ public BatteryDO setCapacity(final int capacity) {
return this;
}

public int getCurrentMicroAmps() {
return currentMicroAmps;
}

public BatteryDO setCurrentMicroAmps(final int currentMicroAmps) {
this.currentMicroAmps = currentMicroAmps;
return this;
}

public String getPowerSource() {
return powerSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.almothafar.simplebatterynotifier.R;
import com.almothafar.simplebatterynotifier.model.BatteryDO;
import com.almothafar.simplebatterynotifier.service.BatteryHealthTracker;
import com.almothafar.simplebatterynotifier.service.BatteryRateTracker;
import com.almothafar.simplebatterynotifier.service.NotificationService;
import com.almothafar.simplebatterynotifier.service.SystemService;
import com.almothafar.simplebatterynotifier.util.TemperatureUtils;
Expand Down Expand Up @@ -64,8 +65,13 @@ public void onReceive(final Context context, final Intent intent) {
// Reuse the sticky intent we already read above instead of triggering a second read.
final BatteryDO batteryDO = SystemService.getBatteryInfo(context, batteryStatus);

// Keep the persistent foreground-service status notification live with the latest reading
NotificationService.updateOngoingNotification(context, batteryDO);
// Feed the charge/drain rate window from this broadcast (no polling timer of our own) so both the
// ongoing notification below and the details table reflect the latest reading (issue #108).
final BatteryRateTracker.BatteryRate rate = BatteryRateTracker.record(context, batteryDO);

// Keep the persistent foreground-service status notification live with the latest reading,
// reusing the rate just computed instead of re-parsing the persisted sample window.
NotificationService.updateOngoingNotification(context, batteryDO, rate);

if (batteryDO == null) {
// Without a real reading, don't assume a level. Previously this defaulted to 100%,
Expand Down
Loading