https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9e43518da596d23b78d33f38d23900a5f8ff9dd9

commit 9e43518da596d23b78d33f38d23900a5f8ff9dd9
Author:     Hervé Poussineau <hpous...@reactos.org>
AuthorDate: Thu Feb 1 22:40:22 2024 +0100
Commit:     Hervé Poussineau <hpous...@reactos.org>
CommitDate: Mon Feb 5 18:04:02 2024 +0100

    [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.
---
 ntoskrnl/po/events.c |  7 +++++++
 ntoskrnl/po/power.c  | 15 +++++++++++++++
 2 files changed, 22 insertions(+)

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

Reply via email to