Fix battery_usage_v9 KeyError on absent protobuf fields; convert to artifact_processor#865
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: while running ALEAPP,
get_battery_usage_v9aborted withKeyError: '20'(Error was '20'). ABatteryStaterecord whosebatteryInformationprotobuf lacked field'20'(foreground-service usage) crashed the whole artifact — and everybattery_info_proto['N']access was unguarded, so any missing field would do the same.Fix + conversion
_ms_field()returns blank when an optional numeric field is absent (instead ofproto['20']/1000raising),_txt()handles absent/bytes fields, and the battery status/health lookups guard theint()conversion. A record missing a field now yields a row with blanks rather than killing the parser.@artifact_processor; SQLite timestamps → aware UTCdatetime; read-only DB access.pathsvalues, which were a bare parenthesized string (no trailing comma) rather than a tuple.Verification
-d C,R); both header sets pass a liveCREATE TABLE; PluginLoader 495 with both functions.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'.