Skip to content

Fix battery_usage_v9 KeyError on absent protobuf fields; convert to artifact_processor#865

Merged
abrignoni merged 1 commit into
mainfrom
fix-battery-usage-v9
Jun 22, 2026
Merged

Fix battery_usage_v9 KeyError on absent protobuf fields; convert to artifact_processor#865
abrignoni merged 1 commit into
mainfrom
fix-battery-usage-v9

Conversation

@abrignoni

Copy link
Copy Markdown
Owner

Bug: while running ALEAPP, get_battery_usage_v9 aborted with KeyError: '20' (Error was '20'). A BatteryState record whose batteryInformation protobuf lacked field '20' (foreground-service usage) crashed the whole artifact — and every battery_info_proto['N'] access was unguarded, so any missing field would do the same.

Fix + conversion

  • All protobuf field reads are now defensive: _ms_field() returns blank when an optional numeric field is absent (instead of proto['20']/1000 raising), _txt() handles absent/bytes fields, and the battery status/health lookups guard the int() conversion. A record missing a field now yields a row with blanks rather than killing the parser.
  • Converted both artifacts (Battery States + App Battery Usage Events) to @artifact_processor; SQLite timestamps → aware UTC datetime; read-only DB access.
  • Fixed the paths values, which were a bare parenthesized string (no trailing comma) rather than a tuple.

Verification

  • Compiles; pylint clean (-d C,R); both header sets pass a live CREATE TABLE; PluginLoader 495 with both functions.
  • Fixture test with a real battery-usage-db-v9: a sparse proto record (missing '20', '3', '7') and a full record both produce rows — the sparse one has blanks for the absent fields (no crash), status/health/total-power resolve correctly, timestamps are aware-UTC, and the app-usage CASE maps to 'Resumed'.

…rtifact_processor

A BatteryState record whose batteryInformation protobuf lacked field '20'
(foreground-service usage) raised KeyError and aborted the entire artifact
('Error was 20'). Every battery_info_proto['N'] access was unguarded, so any
missing field killed the run.

- All protobuf field reads are now defensive (.get with blank defaults via
  _ms_field/_txt helpers), so a record missing an optional field yields a row
  with blanks instead of crashing. Battery status/health lookups guard the
  int() conversion.
- Converted both functions (Battery States + App Battery Usage Events) to
  @artifact_processor; timestamps -> aware UTC; read-only DB access.
- Fixed the paths values (were a bare parenthesized string, not a tuple).
@abrignoni abrignoni merged commit a5eea33 into main Jun 22, 2026
2 checks passed
@abrignoni abrignoni deleted the fix-battery-usage-v9 branch June 22, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant