[NTOS:PO] Set SystemBatteriesPresent when having a battery device in the system

This is (at least) used by powercfg.cpl to know if it needs to display some additional pages.
This commit is contained in:
Hervé Poussineau 2024-02-01 22:40:22 +01:00
parent dff8b93ee2
commit 9e43518da5
2 changed files with 22 additions and 0 deletions

View file

@ -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);

View file

@ -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;
}