Create graphics composer service for pps socket

The [email protected] inherits
from [email protected]. Use it to
enable pps socket.

Bug: 146774711
Test: Boot to home
Test: Check if the pps socket open successfully by using below command
      $adb shell ls /dev/socket/pps
Test: Check FOSS status and it can enter running state
      $adb shell "ppd 'foss:on'"
      $adb shell "ppd 'foss:status'"

Change-Id: I045c455d94c0862d79546004b8f3b56df6fbf5c2
Merged-In: I045c455d94c0862d79546004b8f3b56df6fbf5c2
diff --git a/composer/Android.bp b/composer/Android.bp
new file mode 100644
index 0000000..66595d3
--- /dev/null
+++ b/composer/Android.bp
@@ -0,0 +1,46 @@
+//
+// Copyright (C) 2020 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.
+//
+
+cc_binary {
+    name: "[email protected]",
+    defaults: ["hidl_defaults"],
+    vendor: true,
+    relative_install_path: "hw",
+    srcs: ["service.cpp"],
+    init_rc: ["[email protected]"],
+    header_libs: [
+        "[email protected]",
+    ],
+    shared_libs: [
+        "[email protected]",
+        "[email protected]",
+        "[email protected]",
+        "[email protected]",
+        "[email protected]",
+        "libbase",
+        "libbinder",
+        "libcutils",
+        "libfmq",
+        "libhardware",
+        "libhidlbase",
+        "libhidltransport",
+        "libhwc2on1adapter",
+        "libhwc2onfbadapter",
+        "liblog",
+        "libsync",
+        "libutils",
+    ],
+}
diff --git a/composer/[email protected] b/composer/[email protected]
new file mode 100644
index 0000000..7fa8b55
--- /dev/null
+++ b/composer/[email protected]
@@ -0,0 +1,8 @@
+service vendor.hwcomposer-2-3 /vendor/bin/hw/[email protected]
+    class hal animation
+    user system
+    group graphics drmrpc
+    capabilities SYS_NICE
+    onrestart restart surfaceflinger
+    writepid /dev/cpuset/system-background/tasks
+    socket pps stream 0660 system system
diff --git a/composer/service.cpp b/composer/service.cpp
new file mode 100644
index 0000000..f773da4
--- /dev/null
+++ b/composer/service.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2020 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 <sched.h>
+
+#include <android/hardware/graphics/composer/2.3/IComposer.h>
+#include <binder/ProcessState.h>
+#include <composer-passthrough/2.3/HwcLoader.h>
+#include <hidl/HidlTransportSupport.h>
+
+using android::hardware::graphics::composer::V2_3::IComposer;
+using android::hardware::graphics::composer::V2_3::passthrough::HwcLoader;
+
+int main() {
+    // the conventional HAL might start binder services
+    android::ProcessState::initWithDriver("/dev/vndbinder");
+    android::ProcessState::self()->setThreadPoolMaxThreadCount(4);
+    android::ProcessState::self()->startThreadPool();
+
+    // same as SF main thread
+    struct sched_param param = {0};
+    param.sched_priority = 2;
+    if (sched_setscheduler(0, SCHED_FIFO | SCHED_RESET_ON_FORK, &param) != 0) {
+        ALOGE("Couldn't set SCHED_FIFO: %d", errno);
+    }
+
+    android::hardware::configureRpcThreadpool(4, true /* will join */);
+
+    android::sp<IComposer> composer = HwcLoader::load();
+    if (composer == nullptr) {
+        return 1;
+    }
+    if (composer->registerAsService() != android::NO_ERROR) {
+        ALOGE("failed to register service");
+        return 1;
+    }
+
+    android::hardware::joinRpcThreadpool();
+
+    ALOGE("service is terminating");
+    return 1;
+}
diff --git a/config/display-product.mk b/config/display-product.mk
index aa22e72..a0fa094 100644
--- a/config/display-product.mk
+++ b/config/display-product.mk
@@ -1,7 +1,7 @@
 # Display product definitions
 PRODUCT_PACKAGES += \
     [email protected] \
-    [email protected] \
+    [email protected] \
     [email protected] \
     vendor.qti.hardware.display.allocator-service \
     [email protected] \