/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Common.h"

#include <android-base/properties.h>

namespace aidl::android::hardware::graphics::composer3::impl {

bool IsCuttlefish() {
  return ::android::base::GetProperty("ro.product.board", "") == "cutf";
}

bool IsCuttlefishFoldable() {
  return IsCuttlefish() &&
         ::android::base::GetProperty("ro.product.name", "").find("foldable") !=
             std::string::npos;
}

bool IsInNoOpCompositionMode() {
  const std::string mode = ::android::base::GetProperty("ro.vendor.hwcomposer.mode", "");
  DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.mode is %s", __FUNCTION__, mode.c_str());
  return mode == "noop";
}

bool IsInClientCompositionMode() {
  const std::string mode = ::android::base::GetProperty("ro.vendor.hwcomposer.mode", "");
  DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.mode is %s", __FUNCTION__, mode.c_str());
  return mode == "client";
}

bool IsInNoOpDisplayFinderMode() {
  const std::string mode =
    ::android::base::GetProperty("ro.vendor.hwcomposer.display_finder_mode", "");
  DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.display_finder_mode is %s",
            __FUNCTION__, mode.c_str());
  return mode == "noop";
}

bool IsInDrmDisplayFinderMode() {
  const std::string mode =
    ::android::base::GetProperty("ro.vendor.hwcomposer.display_finder_mode", "");
  DEBUG_LOG("%s: sysprop ro.vendor.hwcomposer.display_finder_mode is %s",
            __FUNCTION__, mode.c_str());
  return mode == "drm";
}

std::string toString(HWC3::Error error) {
  switch (error) {
    case HWC3::Error::None:
      return "None";
    case HWC3::Error::BadConfig:
      return "BadConfig";
    case HWC3::Error::BadDisplay:
      return "BadDisplay";
    case HWC3::Error::BadLayer:
      return "BadLayer";
    case HWC3::Error::BadParameter:
      return "BadParameter";
    case HWC3::Error::NoResources:
      return "NoResources";
    case HWC3::Error::NotValidated:
      return "NotValidated";
    case HWC3::Error::Unsupported:
      return "Unsupported";
    case HWC3::Error::SeamlessNotAllowed:
      return "SeamlessNotAllowed";
  }
}

}  // namespace aidl::android::hardware::graphics::composer3::impl
