oppo: Reset missing battery states to UNKNOWN for UI

This commit is contained in:
NTeditor
2026-06-20 03:21:55 +03:00
parent a603677629
commit c8fd2f0c15
@@ -240,6 +240,10 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
}
final int batteryLevel = payload[i + 1] & 0x7f;
if (batteryIndex == 2 && batteryLevel == 0) {
continue;
}
final BatteryState batteryState = (payload[i + 1] & 0x80) != 0 ? BatteryState.BATTERY_CHARGING : BatteryState.BATTERY_NORMAL;
LOG.debug("Got battery {}: {}%, {}", batteryIndex, batteryLevel, batteryState);
@@ -251,6 +255,22 @@ public class OppoHeadphonesProtocol extends GBDeviceProtocol {
events.add(eventBatteryInfo);
}
List<Integer> processedBatteries = events.stream()
.map(event -> ((GBDeviceEventBatteryInfo) event).batteryIndex)
.toList();
for (int i = 0; i < 2; i++) {
if (processedBatteries.contains(i)) {
continue;
}
final GBDeviceEventBatteryInfo eventBatteryInfo = new GBDeviceEventBatteryInfo();
eventBatteryInfo.batteryIndex = i;
eventBatteryInfo.level = -1;
eventBatteryInfo.state = BatteryState.UNKNOWN;
events.add(eventBatteryInfo);
}
return events;
}