diff --git a/ntoskrnl/po/events.c b/ntoskrnl/po/events.c index 0db341a6ffa..98be49b06e1 100644 --- a/ntoskrnl/po/events.c +++ b/ntoskrnl/po/events.c @@ -159,6 +159,7 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, BOOLEAN Arrival; ULONG Caps; NTSTATUS Status; + POP_POLICY_DEVICE_TYPE DeviceType = (POP_POLICY_DEVICE_TYPE)(ULONG_PTR)Context; DPRINT("PopAddRemoveSysCapsCallback(%p %p)\n", NotificationStructure, Context); @@ -175,6 +176,12 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure, else return STATUS_INVALID_PARAMETER; + if (Arrival && DeviceType == PolicyDeviceBattery) + { + PopCapabilities.SystemBatteriesPresent = TRUE; + return STATUS_SUCCESS; + } + if (Arrival) { DPRINT("Arrival of %wZ\n", Notification->SymbolicLinkName); diff --git a/ntoskrnl/po/power.c b/ntoskrnl/po/power.c index b7143b441d3..8a6df8a4195 100644 --- a/ntoskrnl/po/power.c +++ b/ntoskrnl/po/power.c @@ -423,6 +423,18 @@ PoInitSystem(IN ULONG BootPhase) PopAddRemoveSysCapsCallback, (PVOID)(ULONG_PTR)PolicyDeviceSystemButton, &NotificationEntry); + if (!NT_SUCCESS(Status)) + return FALSE; + + /* Register battery notification */ + Status = IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange, + PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES, + (PVOID)&GUID_DEVICE_BATTERY, + IopRootDeviceNode->PhysicalDeviceObject->DriverObject, + PopAddRemoveSysCapsCallback, + (PVOID)(ULONG_PTR)PolicyDeviceBattery, + &NotificationEntry); + return NT_SUCCESS(Status); } @@ -824,7 +836,10 @@ NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */ RtlZeroMemory(BatteryState, sizeof(SYSTEM_BATTERY_STATE)); BatteryState->EstimatedTime = MAXULONG; + BatteryState->BatteryPresent = PopCapabilities.SystemBatteriesPresent; // BatteryState->AcOnLine = TRUE; +// BatteryState->MaxCapacity = ; +// BatteryState->RemainingCapacity = ; Status = STATUS_SUCCESS; }