[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; BOOLEAN Arrival;
ULONG Caps; ULONG Caps;
NTSTATUS Status; NTSTATUS Status;
POP_POLICY_DEVICE_TYPE DeviceType = (POP_POLICY_DEVICE_TYPE)(ULONG_PTR)Context;
DPRINT("PopAddRemoveSysCapsCallback(%p %p)\n", DPRINT("PopAddRemoveSysCapsCallback(%p %p)\n",
NotificationStructure, Context); NotificationStructure, Context);
@ -175,6 +176,12 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
else else
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
if (Arrival && DeviceType == PolicyDeviceBattery)
{
PopCapabilities.SystemBatteriesPresent = TRUE;
return STATUS_SUCCESS;
}
if (Arrival) if (Arrival)
{ {
DPRINT("Arrival of %wZ\n", Notification->SymbolicLinkName); DPRINT("Arrival of %wZ\n", Notification->SymbolicLinkName);

View file

@ -423,6 +423,18 @@ PoInitSystem(IN ULONG BootPhase)
PopAddRemoveSysCapsCallback, PopAddRemoveSysCapsCallback,
(PVOID)(ULONG_PTR)PolicyDeviceSystemButton, (PVOID)(ULONG_PTR)PolicyDeviceSystemButton,
&NotificationEntry); &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); return NT_SUCCESS(Status);
} }
@ -824,7 +836,10 @@ NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel,
/* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */ /* Just zero the struct (and thus set BatteryState->BatteryPresent = FALSE) */
RtlZeroMemory(BatteryState, sizeof(SYSTEM_BATTERY_STATE)); RtlZeroMemory(BatteryState, sizeof(SYSTEM_BATTERY_STATE));
BatteryState->EstimatedTime = MAXULONG; BatteryState->EstimatedTime = MAXULONG;
BatteryState->BatteryPresent = PopCapabilities.SystemBatteriesPresent;
// BatteryState->AcOnLine = TRUE; // BatteryState->AcOnLine = TRUE;
// BatteryState->MaxCapacity = ;
// BatteryState->RemainingCapacity = ;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }