Fix C2 seccomp policy filename am: 2ad02e5893

Original change: https://android-review.googlesource.com/c/device/generic/goldfish-opengl/+/2754848

Change-Id: I93f787faf964ed058f18c0a39d0e46a8c8fc49dd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/system/codecs/c2/decoders/avcdec/Android.bp b/system/codecs/c2/decoders/avcdec/Android.bp
index 5d840b0..672a80f 100644
--- a/system/codecs/c2/decoders/avcdec/Android.bp
+++ b/system/codecs/c2/decoders/avcdec/Android.bp
@@ -27,6 +27,7 @@
 
    header_libs: [
     "libgralloc_cb.ranchu",
+    "libgralloc_cb3.ranchu",
     ],
 
    static_libs: ["libavcdec",
diff --git a/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp b/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp
index 74d971f..4a89613a 100644
--- a/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp
+++ b/system/codecs/c2/decoders/avcdec/C2GoldfishAvcDec.cpp
@@ -748,8 +748,15 @@
     const bool isGraphic = (pool->getAllocatorId() & C2Allocator::GRAPHIC);
     DDD("buffer pool allocator id %x",  (int)(pool->getAllocatorId()));
     if (isGraphic) {
-        DDD("decoding to host color buffer");
-        mEnableAndroidNativeBuffers = true;
+        uint64_t client_usage = getClientUsage(pool);
+        DDD("client has usage as 0x%llx", client_usage);
+        if (client_usage & BufferUsage::CPU_READ_MASK) {
+            DDD("decoding to guest byte buffer as client has read usage");
+            mEnableAndroidNativeBuffers = false;
+        } else {
+            DDD("decoding to host color buffer");
+            mEnableAndroidNativeBuffers = true;
+        }
     } else {
         DDD("decoding to guest byte buffer");
         mEnableAndroidNativeBuffers = false;
diff --git a/system/codecs/c2/decoders/base/Android.bp b/system/codecs/c2/decoders/base/Android.bp
index 348334b..8dc1596 100644
--- a/system/codecs/c2/decoders/base/Android.bp
+++ b/system/codecs/c2/decoders/base/Android.bp
@@ -47,6 +47,7 @@
 
     header_libs: [
         "libgralloc_cb.ranchu",
+        "libgralloc_cb3.ranchu",
     ],
 
     sanitize: {
diff --git a/system/codecs/c2/decoders/base/color_buffer_utils.cpp b/system/codecs/c2/decoders/base/color_buffer_utils.cpp
index a36ba32..99563f4 100644
--- a/system/codecs/c2/decoders/base/color_buffer_utils.cpp
+++ b/system/codecs/c2/decoders/base/color_buffer_utils.cpp
@@ -19,8 +19,11 @@
 #include <android-base/strings.h>
 #include <log/log.h>
 #include <gralloc_cb_bp.h>
+#include <cb_handle_30.h>
 #include <xf86drm.h>
 
+#include <C2AllocatorGralloc.h>
+
 #include "cros_gralloc_handle.h"
 #include "virtgpu_drm.h"
 
@@ -114,3 +117,17 @@
 uint32_t getColorBufferHandle(native_handle_t const* handle) {
     return getGlobals()->getColorBufferHandle(handle);
 }
+
+uint64_t getClientUsage(const std::shared_ptr<C2BlockPool> &pool) {
+      std::shared_ptr<C2GraphicBlock> myOutBlock;
+      const C2MemoryUsage usage = {0, 0};
+      const uint32_t format = HAL_PIXEL_FORMAT_YCBCR_420_888;
+      pool->fetchGraphicBlock(2, 2, format, usage, &myOutBlock);
+      auto myc2Handle = myOutBlock->handle();
+      native_handle_t *mygrallocHandle =
+      android::UnwrapNativeCodec2GrallocHandle(myc2Handle);
+      cb_handle_30_t* mycb = (cb_handle_30_t*)(mygrallocHandle);
+      ALOGV("%s %s %d: client usage 0x%x", __FILE__, __func__, __LINE__, mycb->usage);
+      return mycb->usage;
+}
+
diff --git a/system/codecs/c2/decoders/base/include/color_buffer_utils.h b/system/codecs/c2/decoders/base/include/color_buffer_utils.h
index d0a7876..ebb8527 100644
--- a/system/codecs/c2/decoders/base/include/color_buffer_utils.h
+++ b/system/codecs/c2/decoders/base/include/color_buffer_utils.h
@@ -14,5 +14,7 @@
  * limitations under the License.
  */
 #include <cutils/native_handle.h>
+#include <SimpleC2Interface.h>
 
 uint32_t getColorBufferHandle(native_handle_t const* handle);
+uint64_t getClientUsage(const std::shared_ptr<C2BlockPool> &pool);
diff --git a/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp b/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp
index c60138b..14eed1f 100644
--- a/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp
+++ b/system/codecs/c2/decoders/hevcdec/C2GoldfishHevcDec.cpp
@@ -696,8 +696,15 @@
     const bool isGraphic = (pool->getAllocatorId() & C2Allocator::GRAPHIC);
     DDD("buffer pool allocator id %x",  (int)(pool->getAllocatorId()));
     if (isGraphic) {
-        DDD("decoding to host color buffer");
-        mEnableAndroidNativeBuffers = true;
+        uint64_t client_usage = getClientUsage(pool);
+        DDD("client has usage as 0x%llx", client_usage);
+        if (client_usage & BufferUsage::CPU_READ_MASK) {
+            DDD("decoding to guest byte buffer as client has read usage");
+            mEnableAndroidNativeBuffers = false;
+        } else {
+            DDD("decoding to host color buffer");
+            mEnableAndroidNativeBuffers = true;
+        }
     } else {
         DDD("decoding to guest byte buffer");
         mEnableAndroidNativeBuffers = false;
diff --git a/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp b/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp
index 59030d4..1655138 100644
--- a/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp
+++ b/system/codecs/c2/decoders/vpxdec/C2GoldfishVpxDec.cpp
@@ -499,8 +499,15 @@
     const bool isGraphic = (pool->getAllocatorId() & C2Allocator::GRAPHIC);
     DDD("buffer pool allocator id %x",  (int)(pool->getAllocatorId()));
     if (isGraphic) {
-        DDD("decoding to host color buffer");
-        mEnableAndroidNativeBuffers = true;
+        uint64_t client_usage = getClientUsage(pool);
+        DDD("client has usage as 0x%llx", client_usage);
+        if (client_usage & BufferUsage::CPU_READ_MASK) {
+            DDD("decoding to guest byte buffer as client has read usage");
+            mEnableAndroidNativeBuffers = false;
+        } else {
+            DDD("decoding to host color buffer");
+            mEnableAndroidNativeBuffers = true;
+        }
     } else {
         DDD("decoding to guest byte buffer");
         mEnableAndroidNativeBuffers = false;
diff --git a/system/hals/Android.bp b/system/hals/Android.bp
new file mode 100644
index 0000000..cec9efb
--- /dev/null
+++ b/system/hals/Android.bp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "device_generic_goldfish-opengl_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["device_generic_goldfish-opengl_license"],
+}
+
+cc_library_headers {
+    name: "libgralloc_cb3.ranchu",
+    vendor_available: true,
+    export_include_dirs: ["."],
+    header_libs: [
+        "libcutils_headers",
+        "libqemupipe-types.ranchu",
+    ],
+    export_header_lib_headers: [
+        "libcutils_headers",
+        "libqemupipe-types.ranchu"
+    ],
+}
diff --git a/system/hals/allocator3.cpp b/system/hals/allocator3.cpp
index 3ff8c84..8a05abd 100644
--- a/system/hals/allocator3.cpp
+++ b/system/hals/allocator3.cpp
@@ -27,7 +27,6 @@
 #include "debug.h"
 
 const int kOMX_COLOR_FormatYUV420Planar = 19;
-const int kC2_COLOR_FormatYCBCR_420_888 = 0x23;
 
 using ::android::hardware::hidl_handle;
 using ::android::hardware::hidl_vec;
@@ -102,7 +101,7 @@
         if (!descriptor.height) { RETURN_ERROR(Error3::UNSUPPORTED); }
         if (descriptor.layerCount != 1) { RETURN_ERROR(Error3::UNSUPPORTED); }
 
-        uint32_t usage = descriptor.usage;
+        const uint32_t usage = descriptor.usage;
 
         int bpp = 1;
         int glFormat = 0;
@@ -113,7 +112,7 @@
             EmulatorFrameworkFormat::GL_COMPATIBLE;
 
         PixelFormat format;
-        Error3 e = getBufferFormat(descriptor.format, &usage, &format);
+        Error3 e = getBufferFormat(descriptor.format, usage, &format);
         if (e != Error3::NONE) {
             ALOGE("%s:%d Unsupported format: frameworkFormat=%d, usage=%x",
                   __func__, __LINE__, descriptor.format, usage);
@@ -291,22 +290,19 @@
         }
     }
 
-    static Error3 getBufferFormat(const PixelFormat frameworkFormat, uint32_t* pusage,
+    static Error3 getBufferFormat(const PixelFormat frameworkFormat,
+                                  const uint32_t usage,
                                   PixelFormat* format) {
-        uint32_t& usage = *pusage;
         if (frameworkFormat == PixelFormat::IMPLEMENTATION_DEFINED) {
             RETURN_ERROR(Error3::UNSUPPORTED);
-        } else if ((static_cast<int>(frameworkFormat) == kOMX_COLOR_FormatYUV420Planar ||
-                    static_cast<int>(frameworkFormat) == kC2_COLOR_FormatYCBCR_420_888) &&
-                   (usage & BufferUsage::VIDEO_DECODER)) {
+        } else if (static_cast<int>(frameworkFormat) == kOMX_COLOR_FormatYUV420Planar &&
+               (usage & BufferUsage::VIDEO_DECODER)) {
             ALOGW("gralloc_alloc: Requested OMX_COLOR_FormatYUV420Planar, given "
               "YCbCr_420_888, taking experimental path. "
               "usage=%x", usage);
             *format = PixelFormat::YCBCR_420_888;
-            usage = static_cast<typeof(usage)>(usage | BufferUsage::CPU_READ_OFTEN);
-            usage = static_cast<typeof(usage)>(usage | BufferUsage::CPU_WRITE_OFTEN);
             RETURN(Error3::NONE);
-        } else {
+        } else  {
             *format = frameworkFormat;
             RETURN(Error3::NONE);
         }
diff --git a/system/hwc3/Android.mk b/system/hwc3/Android.mk
index 1ed4cb7..fff897e 100644
--- a/system/hwc3/Android.mk
+++ b/system/hwc3/Android.mk
@@ -30,11 +30,10 @@
 LOCAL_SHARED_LIBRARIES := \
     android.hardware.graphics.composer@2.1-resources \
     android.hardware.graphics.composer@2.2-resources \
-    android.hardware.graphics.composer3-V1-ndk \
+    android.hardware.graphics.composer3-V2-ndk \
     android.hardware.graphics.mapper@2.0 \
     android.hardware.graphics.mapper@4.0 \
     libbase \
-    libbinder \
     libbinder_ndk \
     libEGL \
     libcutils \
diff --git a/system/hwc3/ComposerClient.cpp b/system/hwc3/ComposerClient.cpp
index 6bd8f0c..ad23406 100644
--- a/system/hwc3/ComposerClient.cpp
+++ b/system/hwc3/ComposerClient.cpp
@@ -421,6 +421,16 @@
   return ToBinderStatus(display->getHdrCapabilities(outCapabilities));
 }
 
+ndk::ScopedAStatus ComposerClient::getOverlaySupport(
+    OverlayProperties* properties) {
+  DEBUG_LOG("%s", __FUNCTION__);
+
+  // no supported combinations
+  properties->combinations.clear();
+
+  return ToBinderStatus(HWC3::Error::None);
+}
+
 ndk::ScopedAStatus ComposerClient::getMaxVirtualDisplayCount(
     int32_t* outCount) {
   DEBUG_LOG("%s", __FUNCTION__);
@@ -582,6 +592,28 @@
   return ToBinderStatus(display->getPreferredBootConfig(outConfigId));
 }
 
+ndk::ScopedAStatus ComposerClient::getHdrConversionCapabilities(
+    std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability>* capabilities) {
+  DEBUG_LOG("%s", __FUNCTION__);
+  capabilities->clear();
+  return ToBinderStatus(HWC3::Error::None);
+}
+
+ndk::ScopedAStatus ComposerClient::setHdrConversionStrategy(
+    const aidl::android::hardware::graphics::common::HdrConversionStrategy& conversionStrategy,
+    aidl::android::hardware::graphics::common::Hdr* preferredHdrOutputType) {
+  DEBUG_LOG("%s", __FUNCTION__);
+  using HdrConversionStrategyTag = aidl::android::hardware::graphics::common::HdrConversionStrategy::Tag;
+  switch (conversionStrategy.getTag() == HdrConversionStrategyTag::autoAllowedHdrTypes) {
+      auto autoHdrTypes = conversionStrategy.get<HdrConversionStrategyTag::autoAllowedHdrTypes>();
+      if (autoHdrTypes.size() != 0) {
+          return ToBinderStatus(HWC3::Error::Unsupported);
+      }
+  }
+  *preferredHdrOutputType = aidl::android::hardware::graphics::common::Hdr::INVALID;
+  return ToBinderStatus(HWC3::Error::None);
+}
+
 ndk::ScopedAStatus ComposerClient::setAutoLowLatencyMode(int64_t displayId,
                                                          bool on) {
   DEBUG_LOG("%s", __FUNCTION__);
@@ -704,6 +736,15 @@
   return ToBinderStatus(display->setIdleTimerEnabled(timeoutMs));
 }
 
+ndk::ScopedAStatus ComposerClient::setRefreshRateChangedCallbackDebugEnabled(
+        int64_t displayId, bool) {
+    DEBUG_LOG("%s", __FUNCTION__);
+
+    GET_DISPLAY_OR_RETURN_ERROR();
+
+    return ToBinderStatus(HWC3::Error::Unsupported);
+}
+
 ndk::SpAIBinder ComposerClient::createBinder() {
   auto binder = BnComposerClient::createBinder();
   AIBinder_setInheritRt(binder.get(), true);
diff --git a/system/hwc3/ComposerClient.h b/system/hwc3/ComposerClient.h
index 7e19d2c..41ca7ba 100644
--- a/system/hwc3/ComposerClient.h
+++ b/system/hwc3/ComposerClient.h
@@ -81,6 +81,7 @@
       int64_t displayId, common::Transform* orientation) override;
   ndk::ScopedAStatus getHdrCapabilities(int64_t displayId,
                                         HdrCapabilities* caps) override;
+  ndk::ScopedAStatus getOverlaySupport(OverlayProperties* properties) override;
   ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override;
   ndk::ScopedAStatus getPerFrameMetadataKeys(
       int64_t displayId, std::vector<PerFrameMetadataKey>* keys) override;
@@ -109,6 +110,11 @@
   ndk::ScopedAStatus clearBootDisplayConfig(int64_t displayId) override;
   ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t displayId,
                                                    int32_t* config) override;
+  ndk::ScopedAStatus getHdrConversionCapabilities(
+      std::vector<aidl::android::hardware::graphics::common::HdrConversionCapability>*) override;
+  ndk::ScopedAStatus setHdrConversionStrategy(
+      const aidl::android::hardware::graphics::common::HdrConversionStrategy& conversionStrategy,
+      aidl::android::hardware::graphics::common::Hdr* preferredHdrOutputType) override;
   ndk::ScopedAStatus setAutoLowLatencyMode(int64_t displayId, bool on) override;
   ndk::ScopedAStatus setClientTargetSlotCount(int64_t displayId,
                                               int32_t count) override;
@@ -127,6 +133,8 @@
   ndk::ScopedAStatus setVsyncEnabled(int64_t displayId, bool enabled) override;
   ndk::ScopedAStatus setIdleTimerEnabled(int64_t displayId,
                                          int32_t timeoutMs) override;
+  ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(int64_t displayId,
+                                                               bool enabled) override;
 
  protected:
   ndk::SpAIBinder createBinder() override;
diff --git a/system/hwc3/Layer.cpp b/system/hwc3/Layer.cpp
index f58d5a5..6b2480f 100644
--- a/system/hwc3/Layer.cpp
+++ b/system/hwc3/Layer.cpp
@@ -110,7 +110,7 @@
 
 HWC3::Error Layer::setColor(Color color) {
   DEBUG_LOG("%s: layer:%" PRId64
-            " color-r:%d color-g:%d color-b:%d color-a:%d)",
+            " color-r:%f color-g:%f color-b:%f color-a:%f)",
             __FUNCTION__, mId, color.r, color.g, color.b, color.a);
 
   mColor = color;
@@ -120,7 +120,7 @@
 Color Layer::getColor() const {
   auto color = mColor;
   DEBUG_LOG("%s: layer:%" PRId64
-            " color-r:%d color-g:%d color-b:%d color-a:%d)",
+            " color-r:%f color-g:%f color-b:%f color-a:%f)",
             __FUNCTION__, mId, color.r, color.g, color.b, color.a);
 
   return color;
diff --git a/system/hwc3/Main.cpp b/system/hwc3/Main.cpp
index 440a1c2..fbb1206 100644
--- a/system/hwc3/Main.cpp
+++ b/system/hwc3/Main.cpp
@@ -17,7 +17,6 @@
 #include <android-base/logging.h>
 #include <android/binder_manager.h>
 #include <android/binder_process.h>
-#include <binder/ProcessState.h>
 #include <sched.h>
 
 #include "Composer.h"
@@ -43,10 +42,6 @@
       AServiceManager_addService(composer->asBinder().get(), instance.c_str());
   CHECK(status == STATUS_OK);
 
-  // Thread pool for vendor libbinder for internal vendor services
-  android::ProcessState::self()->setThreadPoolMaxThreadCount(2);
-  android::ProcessState::self()->startThreadPool();
-
   // Thread pool for system libbinder (via libbinder_ndk) for aidl services
   // IComposer and IDisplay
   ABinderProcess_setThreadPoolMaxThreadCount(5);
@@ -54,4 +49,4 @@
   ABinderProcess_joinThreadPool();
 
   return EXIT_FAILURE;
-}
\ No newline at end of file
+}
diff --git a/system/hwc3/hwc3.xml b/system/hwc3/hwc3.xml
index 79d6a8d..861b4b7 100644
--- a/system/hwc3/hwc3.xml
+++ b/system/hwc3/hwc3.xml
@@ -1,7 +1,7 @@
 <manifest version="1.0" type="device">
     <hal format="aidl">
         <name>android.hardware.graphics.composer3</name>
-        <version>1</version>
+        <version>2</version>
         <interface>
             <name>IComposer</name>
             <instance>default</instance>