Mark 24Q4 as merged in aosp-main-future

Bug: 373937381
Merged-In: I3fa081c724b4adc9aa913c4158e587b1e376bd7a
Change-Id: Ibaaabd4ccb1db6adeba2cfd75ba4038b5fca26a7
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f58f7a3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.out/
+.vscode/
+.idea/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index da052c3..5863159 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -5,7 +5,7 @@
 
 variables:
   DEBIAN_FRONTEND: noninteractive
-  DOCKER_IMAGE_TAG: $CI_REGISTRY_IMAGE:latest
+  DOCKER_IMAGE_TAG: registry.freedesktop.org/drm-hwcomposer/drm-hwcomposer:latest
 
 stages:
   - build-container
@@ -20,13 +20,26 @@
     - docker:27.0.3-dind
   variables:
     DOCKER_TLS_CERTDIR: ""
+    # Use the fork's docker image when rebuilding the container
+    DOCKER_IMAGE_TAG: $CI_REGISTRY_IMAGE:latest
   before_script:
     - echo "$CI_JOB_TOKEN" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
   script:
     - docker build -t $DOCKER_IMAGE_TAG -f .ci/Dockerfile .
     - docker push $DOCKER_IMAGE_TAG
+    - echo "DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG" >> build.env
   after_script:
     - docker logout
+  artifacts:
+    reports:
+      dotenv: build.env
+  rules:
+    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
+      changes:
+      - .ci/Dockerfile
+    - if: $CI_PIPELINE_SOURCE == 'push'
+      changes:
+      - .ci/Dockerfile
 
 build:
   stage: build
diff --git a/Android.bp b/Android.bp
index 7d014dc..2578188 100644
--- a/Android.bp
+++ b/Android.bp
@@ -194,7 +194,6 @@
     shared_libs: [
         "android.hardware.graphics.composer3-V3-ndk",
         "libbase",
-        "libbinder",
         "libbinder_ndk",
         "liblog",
         "libutils",
@@ -242,3 +241,60 @@
     name: "drm_hwcomposer_platformmediatek",
     srcs: ["bufferinfo/legacy/BufferInfoMaliMediatek.cpp"],
 }
+
+prebuilt_etc {
+    name: "drm_hwcomposer_hwc3_apex_vintf",
+    src: "hwc3/hwc3-drm.xml",
+    sub_dir: "vintf",
+    vendor: true,
+    installable: false,
+}
+
+prebuilt_etc {
+    name: "drm_hwcomposer_hwc3_apex_init_rc",
+    filename_from_src: true,
+    vendor: true,
+    src: ":gen-drm_hwcomposer_hwc3_apex_init_rc",
+}
+
+genrule {
+    name: "gen-drm_hwcomposer_hwc3_apex_init_rc",
+    srcs: ["hwc3/hwc3-drm.rc"],
+    out: ["hwc3-drm.apex.rc"],
+    cmd: "sed " +
+        // Update the binary location to inside the Apex:
+        "-e 's%/vendor/bin/%/apex/com.android.hardware.graphics.composer/bin/%' " +
+        "$(in) > $(out)",
+}
+
+filegroup {
+    name: "drm_hwcomposer_hwc3_apex_file_contexts",
+    srcs: [
+        "hwc3/hwc3-apex-file-contexts",
+    ],
+}
+
+filegroup {
+    name: "drm_hwcomposer_hwc3_apex_manifest",
+    srcs: [
+        "hwc3/hwc3-apex-manifest.json",
+    ],
+}
+
+apex {
+    name: "com.android.hardware.graphics.composer.drm_hwcomposer",
+    key: "com.android.hardware.key",
+    certificate: ":com.android.hardware.certificate",
+    file_contexts: ":drm_hwcomposer_hwc3_apex_file_contexts",
+    manifest: ":drm_hwcomposer_hwc3_apex_manifest",
+    vendor: true,
+    updatable: false,
+    soc_specific: true,
+    binaries: [
+        "android.hardware.composer.hwc3-service.drm",
+    ],
+    prebuilts: [
+        "drm_hwcomposer_hwc3_apex_init_rc",
+        "drm_hwcomposer_hwc3_apex_vintf",
+    ],
+}
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..1f413f7
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,3 @@
+[Hook Scripts]
+
+check hooks installed = hooks/check-hooks-installed
\ No newline at end of file
diff --git a/drm/DrmMode.h b/drm/DrmMode.h
index c5790a5..5450daf 100644
--- a/drm/DrmMode.h
+++ b/drm/DrmMode.h
@@ -48,6 +48,12 @@
            (float)(mode_.vtotal * mode_.htotal) * 1000.0F;
   }
 
+  auto GetVSyncPeriodNs() const {
+    static const int kNanosecondsPerSecond = 1E9;
+    return static_cast<int32_t>(kNanosecondsPerSecond *
+                                double(1 / GetVRefresh()));
+  }
+
   auto GetName() const {
     return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
   }
diff --git a/hooks/check-hooks-installed b/hooks/check-hooks-installed
new file mode 100755
index 0000000..45e5c73
--- /dev/null
+++ b/hooks/check-hooks-installed
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Gerrit hook that runs on repo upload. Checks to ensure that the pre-upload hook
+# has been installed.
+
+cmd=$(git config hookcmd.check-non-public-commits.command)
+if [ -z "$cmd" ]; then
+  echo "Please install hooks by running: hooks/install-hooks.sh"
+  exit 1
+fi
\ No newline at end of file
diff --git a/hooks/check-non-public-commits b/hooks/check-non-public-commits
new file mode 100755
index 0000000..fc20795
--- /dev/null
+++ b/hooks/check-non-public-commits
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# git pre-push hook to detect whether a developer is attempting to push
+# non-public commits to a public repository.
+
+remote="$1"
+url="$2"
+
+# Don't bother checking if this is being pushed to gerrit.
+if [[ "$url" = "sso://googleplex-android/platform/external/drm_hwcomposer" ]] ||
+   [[ "$url" = "sso://android.googlesource.com/platform/external/drm_hwcomposer" ]]
+then
+  exit 0
+fi
+
+while read local_ref local_sha remote_ref remote_sha
+do
+  # Gather a list of all commits that are to be pushed to the remote.
+  # remote_sha will be 000000 if there is no corresponding remote branch.
+  if [[ "$remote_sha" =~ "0000000000" ]]; then
+    commits=$(git rev-list $local_sha --not --remotes=$remote)
+  else
+    commits=$(git rev-list $remote_sha..$local_sha)
+  fi
+
+  # Check each commit message for the prohibited prefix.
+  for commit in $commits; do
+    # Get the commit message.
+    message=$(git log -1 --pretty=%B $commit)
+
+    # Check if the commit message starts with "ANDROID:"
+    if [[ "$message" == "ANDROID"* ]] ||
+       [[ "$message" == "INTERNAL"* ]] ||
+       [[ "$message" == "DO NOT MERGE"* ]]; then
+      echo "Error: Commit message starts with downstream tag:"
+      echo "$message"
+      echo "It looks like you're trying to push internal changes to an externally "
+      echo "visible repository: $url"
+      exit 1
+    fi
+  done
+done
+
+exit 0
diff --git a/hooks/install-hooks.sh b/hooks/install-hooks.sh
new file mode 100755
index 0000000..cc5d967
--- /dev/null
+++ b/hooks/install-hooks.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+# Install hooks.
+git config --add hookcmd.check-non-public-commits.command "[ ! -d hooks ] || hooks/check-non-public-commits"
+git config --add hook.pre-push.command check-non-public-commits
\ No newline at end of file
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index 36333d2..9a9761b 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -320,7 +320,7 @@
       break;
     case HWC2::Attribute::VsyncPeriod:
       // in nanoseconds
-      *value = static_cast<int>(1E9 / hwc_config.mode.GetVRefresh());
+      *value = hwc_config.mode.GetVSyncPeriodNs();
       break;
     case HWC2::Attribute::DpiY:
       // ideally this should be vdisplay/mm_heigth, however mm_height
diff --git a/hwc3/CommandResultWriter.h b/hwc3/CommandResultWriter.h
index fa96f33..aae6817 100644
--- a/hwc3/CommandResultWriter.h
+++ b/hwc3/CommandResultWriter.h
@@ -17,6 +17,8 @@
 #include <unordered_map>
 #include <vector>
 
+#include <android-base/unique_fd.h>
+
 #include "Utils.h"
 #include "aidl/android/hardware/graphics/composer3/CommandError.h"
 #include "aidl/android/hardware/graphics/composer3/CommandResultPayload.h"
diff --git a/hwc3/ComposerClient.cpp b/hwc3/ComposerClient.cpp
index f353abb..2efce8f 100644
--- a/hwc3/ComposerClient.cpp
+++ b/hwc3/ComposerClient.cpp
@@ -202,9 +202,15 @@
     return Hwc2toHwc3Error(hwc2_error);
   }
 
+  hwc3::Error error = Hwc2toHwc3Error(
+      display.GetChangedCompositionTypes(&num_types, nullptr, nullptr));
+  if (error != hwc3::Error::kNone) {
+    return error;
+  }
+
   std::vector<hwc2_layer_t> hwc_changed_layers(num_types);
   std::vector<int32_t> hwc_composition_types(num_types);
-  hwc3::Error error = Hwc2toHwc3Error(
+  error = Hwc2toHwc3Error(
       display.GetChangedCompositionTypes(&num_types, hwc_changed_layers.data(),
                                          hwc_composition_types.data()));
   if (error != hwc3::Error::kNone) {
@@ -966,15 +972,13 @@
 
   const HwcDisplayConfigs& configs = display->GetDisplayConfigs();
   for (const auto& [id, config] : configs.hwc_configs) {
-    static const int kNanosecondsPerSecond = 1E9;
     configurations->emplace_back(
         DisplayConfiguration{.configId = static_cast<int32_t>(config.id),
                              .width = config.mode.GetRawMode().hdisplay,
                              .height = config.mode.GetRawMode().vdisplay,
                              .configGroup = static_cast<int32_t>(
                                  config.group_id),
-                             .vsyncPeriod = static_cast<int>(kNanosecondsPerSecond * double(
-                                 1 / config.mode.GetVRefresh()))});
+                             .vsyncPeriod = config.mode.GetVSyncPeriodNs()});
 
     if (configs.mm_width != 0) {
       // ideally this should be vdisplay/mm_heigth, however mm_height
diff --git a/hwc3/Utils.h b/hwc3/Utils.h
index 23d6bdc..2e21b97 100644
--- a/hwc3/Utils.h
+++ b/hwc3/Utils.h
@@ -18,6 +18,7 @@
 
 #include <aidl/android/hardware/graphics/composer3/IComposerClient.h>
 #include <hardware/hwcomposer2.h>
+#include <log/log.h>
 
 #include <cstdint>
 
diff --git a/hwc3/hwc3-apex-file-contexts b/hwc3/hwc3-apex-file-contexts
new file mode 100644
index 0000000..5c8de15
--- /dev/null
+++ b/hwc3/hwc3-apex-file-contexts
@@ -0,0 +1,3 @@
+(/.*)?                                                   u:object_r:vendor_file:s0
+/etc(/.*)?                                               u:object_r:vendor_configs_file:s0
+/bin/hw/android\.hardware\.composer\.hwc3-service\.drm   u:object_r:hal_graphics_composer_default_exec:s0
\ No newline at end of file
diff --git a/hwc3/hwc3-apex-manifest.json b/hwc3/hwc3-apex-manifest.json
new file mode 100644
index 0000000..fa9e626
--- /dev/null
+++ b/hwc3/hwc3-apex-manifest.json
@@ -0,0 +1,5 @@
+{
+    "name": "com.android.hardware.graphics.composer",
+    "version": 1,
+    "vendorBootstrap": true
+}
\ No newline at end of file
diff --git a/hwc3/service.cpp b/hwc3/service.cpp
index 920260a..d91ce9e 100644
--- a/hwc3/service.cpp
+++ b/hwc3/service.cpp
@@ -19,7 +19,6 @@
 
 #include <android/binder_manager.h>
 #include <android/binder_process.h>
-#include <binder/ProcessState.h>
 #include <sched.h>
 
 #include "Composer.h"