Validate FD when reporting brightness support.

If we fail to open the brightness sysfs node, then we shouldn't report
that we support setting the brightness since any attempts fail.

Also, fix capabilities count. This was accidentally left in when moving
brightness support from a global capability to a display-specific one.

Bug: 128496688
Test: manual
Change-Id: Ie623b98232481bca3c0f955b259a3b168c83cf2e
(cherry picked from commit 965961d0fca31d11bdc1fcbcfc3c65cebb3d65d0)
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index 60b719f..3b13681 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -310,7 +310,7 @@
   if (Debug::Get()->GetProperty(DISABLE_SKIP_VALIDATE_PROP, &value) == kErrorNone) {
     disable_skip_validate = (value == 1);
   }
-  uint32_t count = 2 + (disable_skip_validate ? 0 : 1);
+  uint32_t count = 1 + (disable_skip_validate ? 0 : 1);
 
   if (outCapabilities != nullptr && (*outCount >= count)) {
     outCapabilities[0] = HWC2_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM;
@@ -948,9 +948,14 @@
     return INT32(HWC2::Error::None);
   }
 
-  bool brightness_support = display == HWC_DISPLAY_PRIMARY;
+  bool brightness_support = false;
+  auto status = GetDisplayBrightnessSupport(device, display, &brightness_support);
+  if (status != HWC2_ERROR_NONE) {
+    DLOGE("Failed to get display brightness support Error = %d", status);
+    return INT32(status);
+  }
   int doze_support = 0;
-  auto status = GetDozeSupport(device, display, &doze_support);
+  status = GetDozeSupport(device, display, &doze_support);
   if (status != HWC2_ERROR_NONE) {
     DLOGE("Failed to get doze support Error = %d", status);
     return INT32(status);
@@ -974,13 +979,19 @@
 
 int32_t HWCSession::GetDisplayBrightnessSupport(hwc2_device_t *device, hwc2_display_t display,
                                                 bool *out_support) {
-  *out_support = display == HWC_DISPLAY_PRIMARY;
+  HWCSession *hwc_session = static_cast<HWCSession *>(device);
+  *out_support = display == HWC_DISPLAY_PRIMARY && hwc_session->brightness_fd_ != -1;
   return INT32(HWC2::Error::None);
 }
 
 int32_t HWCSession::SetDisplayBrightness(hwc2_device_t *device, hwc2_display_t display,
                                          float brightness) {
-  if (display != HWC_DISPLAY_PRIMARY) {
+  bool brightness_support = false;
+  auto status = GetDisplayBrightnessSupport(device, display, &brightness_support);
+  if (status != HWC2_ERROR_NONE) {
+    return INT32(status);
+  }
+  if (!brightness_support) {
     return INT32(HWC2::Error::BadDisplay);
   }
   int backlight = -1;