drm_hwcomposer: Tidy-up DrmDevice class

1. Move drm/DrmConnector.h to Normal clang-tidy checks list by fixing
   clang-tidy findings.

2. Remove DrmDevice self-reference.

3. Replace shared_ptr reference to DrmDevice in DrmFbImporter with a
   pointer, making ResourceManager only owner of DrmDevice and its
   chilren.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index a6d2289..29dd95f 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -37,54 +37,53 @@
 namespace android {
 
 DrmDevice::DrmDevice() {
-  self.reset(this);
-  mDrmFbImporter = std::make_unique<DrmFbImporter>(self);
+  drm_fb_importer_ = std::make_unique<DrmFbImporter>(*this);
 }
 
 // NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme
 std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) {
   /* TODO: Use drmOpenControl here instead */
   fd_ = UniqueFd(open(path, O_RDWR | O_CLOEXEC));
-  if (fd() < 0) {
+  if (!fd_) {
     // NOLINTNEXTLINE(concurrency-mt-unsafe): Fixme
     ALOGE("Failed to open dri %s: %s", path, strerror(errno));
     return std::make_tuple(-ENODEV, 0);
   }
 
-  int ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
-  if (ret) {
+  int ret = drmSetClientCap(GetFd(), DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
+  if (ret != 0) {
     ALOGE("Failed to set universal plane cap %d", ret);
     return std::make_tuple(ret, 0);
   }
 
-  ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_ATOMIC, 1);
-  if (ret) {
+  ret = drmSetClientCap(GetFd(), DRM_CLIENT_CAP_ATOMIC, 1);
+  if (ret != 0) {
     ALOGE("Failed to set atomic cap %d", ret);
     return std::make_tuple(ret, 0);
   }
 
 #ifdef DRM_CLIENT_CAP_WRITEBACK_CONNECTORS
-  ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1);
-  if (ret) {
+  ret = drmSetClientCap(GetFd(), DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1);
+  if (ret != 0) {
     ALOGI("Failed to set writeback cap %d", ret);
     ret = 0;
   }
 #endif
 
   uint64_t cap_value = 0;
-  if (drmGetCap(fd(), DRM_CAP_ADDFB2_MODIFIERS, &cap_value)) {
+  if (drmGetCap(GetFd(), DRM_CAP_ADDFB2_MODIFIERS, &cap_value) != 0) {
     ALOGW("drmGetCap failed. Fallback to no modifier support.");
     cap_value = 0;
   }
   HasAddFb2ModifiersSupport_ = cap_value != 0;
 
-  drmSetMaster(fd());
-  if (!drmIsMaster(fd())) {
+  drmSetMaster(GetFd());
+  if (drmIsMaster(GetFd()) == 0) {
     ALOGE("DRM/KMS master access required");
     return std::make_tuple(-EACCES, 0);
   }
 
-  auto res = MakeDrmModeResUnique(fd());
+  auto res = MakeDrmModeResUnique(GetFd());
   if (!res) {
     ALOGE("Failed to get DrmDevice resources");
     return std::make_tuple(-ENODEV, 0);
@@ -147,10 +146,10 @@
   add_displays(/*internal = */ false, /*connected = */ false);
 
   // Catch-all for the above loops
-  if (ret)
+  if (ret != 0)
     return std::make_tuple(ret, 0);
 
-  auto plane_res = MakeDrmModePlaneResUnique(fd());
+  auto plane_res = MakeDrmModePlaneResUnique(GetFd());
   if (!plane_res) {
     ALOGE("Failed to get plane resources");
     return std::make_tuple(-ENOENT, 0);
@@ -167,7 +166,7 @@
 
   for (auto &conn : connectors_) {
     ret = CreateDisplayPipe(conn.get());
-    if (ret) {
+    if (ret != 0) {
       ALOGE("Failed CreateDisplayPipe %d with %d", conn->GetId(), ret);
       return std::make_tuple(ret, 0);
     }
@@ -187,18 +186,10 @@
   return bound_crtcs_.at(display);
 }
 
-const std::vector<std::unique_ptr<DrmCrtc>> &DrmDevice::crtcs() const {
-  return crtcs_;
-}
-
-uint32_t DrmDevice::next_mode_id() {
-  return ++mode_id_;
-}
-
 int DrmDevice::TryEncoderForDisplay(int display, DrmEncoder *enc) {
   /* First try to use the currently-bound crtc */
   auto *crtc = FindCrtcById(enc->GetCurrentCrtcId());
-  if (crtc && bound_crtcs_.count(display) == 0) {
+  if (crtc != nullptr && bound_crtcs_.count(display) == 0) {
     bound_crtcs_[display] = crtc;
     bound_encoders_[crtc] = enc;
     return 0;
@@ -228,7 +219,7 @@
   auto *enc0 = FindEncoderById(connector->GetCurrentEncoderId());
   if (enc0 != nullptr && encoders_to_display_id_.count(enc0) == 0) {
     int ret = TryEncoderForDisplay(display, enc0);
-    if (!ret) {
+    if (ret == 0) {
       encoders_to_display_id_[enc0] = display;
       return 0;
     }
@@ -246,7 +237,7 @@
     }
 
     int ret = TryEncoderForDisplay(display, enc.get());
-    if (!ret) {
+    if (ret == 0) {
       encoders_to_display_id_[enc.get()] = display;
       return 0;
     }
@@ -264,10 +255,11 @@
     -> DrmModeUserPropertyBlobUnique {
   struct drm_mode_create_blob create_blob {};
   create_blob.length = length;
+  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
   create_blob.data = (__u64)data;
 
-  int ret = drmIoctl(fd(), DRM_IOCTL_MODE_CREATEPROPBLOB, &create_blob);
-  if (ret) {
+  int ret = drmIoctl(GetFd(), DRM_IOCTL_MODE_CREATEPROPBLOB, &create_blob);
+  if (ret != 0) {
     ALOGE("Failed to create mode property blob %d", ret);
     return {};
   }
@@ -276,7 +268,8 @@
       new uint32_t(create_blob.blob_id), [this](const uint32_t *it) {
         struct drm_mode_destroy_blob destroy_blob {};
         destroy_blob.blob_id = (__u32)*it;
-        int err = drmIoctl(fd(), DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy_blob);
+        int err = drmIoctl(GetFd(), DRM_IOCTL_MODE_DESTROYPROPBLOB,
+                           &destroy_blob);
         if (err != 0) {
           ALOGE("Failed to destroy mode property blob %" PRIu32 "/%d", *it,
                 err);
@@ -290,16 +283,18 @@
                            const char *prop_name, DrmProperty *property) const {
   drmModeObjectPropertiesPtr props = nullptr;
 
-  props = drmModeObjectGetProperties(fd(), obj_id, obj_type);
-  if (!props) {
+  props = drmModeObjectGetProperties(GetFd(), obj_id, obj_type);
+  if (props == nullptr) {
     ALOGE("Failed to get properties for %d/%x", obj_id, obj_type);
     return -ENODEV;
   }
 
   bool found = false;
   for (int i = 0; !found && (size_t)i < props->count_props; ++i) {
-    drmModePropertyPtr p = drmModeGetProperty(fd(), props->props[i]);
-    if (!strcmp(p->name, prop_name)) {
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
+    drmModePropertyPtr p = drmModeGetProperty(GetFd(), props->props[i]);
+    if (strcmp(p->name, prop_name) == 0) {
+      // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
       property->Init(obj_id, p, props->prop_values[i]);
       found = true;
     }
@@ -311,9 +306,9 @@
 }
 
 std::string DrmDevice::GetName() const {
-  auto *ver = drmGetVersion(fd());
-  if (!ver) {
-    ALOGW("Failed to get drm version for fd=%d", fd());
+  auto *ver = drmGetVersion(GetFd());
+  if (ver == nullptr) {
+    ALOGW("Failed to get drm version for fd=%d", GetFd());
     return "generic";
   }
 
@@ -339,4 +334,22 @@
   return is_kms;
 }
 
+auto DrmDevice::GetConnectors()
+    -> const std::vector<std::unique_ptr<DrmConnector>> & {
+  return connectors_;
+}
+
+auto DrmDevice::GetPlanes() -> const std::vector<std::unique_ptr<DrmPlane>> & {
+  return planes_;
+}
+
+auto DrmDevice::GetCrtcs() -> const std::vector<std::unique_ptr<DrmCrtc>> & {
+  return crtcs_;
+}
+
+auto DrmDevice::GetEncoders()
+    -> const std::vector<std::unique_ptr<DrmEncoder>> & {
+  return encoders_;
+}
+
 }  // namespace android