libprocessgroup_setup: use libcgrouprc_format

Use CgroupController definition from libcgrouprc_format, not
libprocessgroup, because the wire format will be removed
from libprocessgroup later.

Bug: 123664216
Test: builds
Change-Id: If5e2301a1b65c3f6a51a1661cfeeed4e299f634e
diff --git a/init/Android.bp b/init/Android.bp
index e834e99..69ee34f 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -61,6 +61,7 @@
     static_libs: [
         "libseccomp_policy",
         "libavb",
+        "libcgrouprc_format",
         "libprotobuf-cpp-lite",
         "libpropertyinfoserializer",
         "libpropertyinfoparser",
diff --git a/libprocessgroup/setup/Android.bp b/libprocessgroup/setup/Android.bp
index a403a23..f6fc066 100644
--- a/libprocessgroup/setup/Android.bp
+++ b/libprocessgroup/setup/Android.bp
@@ -25,9 +25,12 @@
     ],
     shared_libs: [
         "libbase",
-        "libprocessgroup",
+        "libcgrouprc",
         "libjsoncpp",
     ],
+    static_libs: [
+        "libcgrouprc_format",
+    ],
     header_libs: [
         "libprocessgroup_headers",
     ],
diff --git a/libprocessgroup/setup/cgroup_descriptor.h b/libprocessgroup/setup/cgroup_descriptor.h
index 185c5f9..597060e 100644
--- a/libprocessgroup/setup/cgroup_descriptor.h
+++ b/libprocessgroup/setup/cgroup_descriptor.h
@@ -16,8 +16,10 @@
 
 #pragma once
 
-// TODO(b/123664216): Use libcgrouprc_format
-#include "../cgroup_map.h"
+#include <processgroup/format/cgroup_controller.h>
+
+namespace android {
+namespace cgrouprc {
 
 // Complete controller description for mounting cgroups
 class CgroupDescriptor {
@@ -25,14 +27,17 @@
     CgroupDescriptor(uint32_t version, const std::string& name, const std::string& path,
                      mode_t mode, const std::string& uid, const std::string& gid);
 
-    const CgroupController* controller() const { return &controller_; }
+    const format::CgroupController* controller() const { return &controller_; }
     mode_t mode() const { return mode_; }
     std::string uid() const { return uid_; }
     std::string gid() const { return gid_; }
 
   private:
-    CgroupController controller_;
+    format::CgroupController controller_;
     mode_t mode_ = 0;
     std::string uid_;
     std::string gid_;
 };
+
+}  // namespace cgrouprc
+}  // namespace android
diff --git a/libprocessgroup/setup/cgroup_map_write.cpp b/libprocessgroup/setup/cgroup_map_write.cpp
index 8ecc0a4..6aabd56 100644
--- a/libprocessgroup/setup/cgroup_map_write.cpp
+++ b/libprocessgroup/setup/cgroup_map_write.cpp
@@ -37,6 +37,7 @@
 #include <android-base/unique_fd.h>
 #include <json/reader.h>
 #include <json/value.h>
+#include <processgroup/format/cgroup_file.h>
 #include <processgroup/processgroup.h>
 #include <processgroup/setup.h>
 
@@ -46,6 +47,9 @@
 using android::base::StringPrintf;
 using android::base::unique_fd;
 
+namespace android {
+namespace cgrouprc {
+
 static constexpr const char* CGROUPS_DESC_FILE = "/etc/cgroups.json";
 static constexpr const char* CGROUPS_DESC_VENDOR_FILE = "/vendor/etc/cgroups.json";
 
@@ -185,7 +189,7 @@
 #if defined(__ANDROID__)
 
 static bool SetupCgroup(const CgroupDescriptor& descriptor) {
-    const CgroupController* controller = descriptor.controller();
+    const format::CgroupController* controller = descriptor.controller();
 
     // mkdir <path> [mode] [owner] [group]
     if (!Mkdir(controller->path(), descriptor.mode(), descriptor.uid(), descriptor.gid())) {
@@ -244,8 +248,8 @@
         return false;
     }
 
-    CgroupFile fl;
-    fl.version_ = CgroupFile::FILE_CURR_VERSION;
+    format::CgroupFile fl;
+    fl.version_ = format::CgroupFile::FILE_CURR_VERSION;
     fl.controller_count_ = descriptors.size();
     int ret = TEMP_FAILURE_RETRY(write(fd, &fl, sizeof(fl)));
     if (ret < 0) {
@@ -254,7 +258,8 @@
     }
 
     for (const auto& [name, descriptor] : descriptors) {
-        ret = TEMP_FAILURE_RETRY(write(fd, descriptor.controller(), sizeof(CgroupController)));
+        ret = TEMP_FAILURE_RETRY(
+                write(fd, descriptor.controller(), sizeof(format::CgroupController)));
         if (ret < 0) {
             PLOG(ERROR) << "write() failed for " << CGROUPS_RC_PATH;
             return false;
@@ -269,7 +274,12 @@
                                    const std::string& gid)
     : controller_(version, name, path), mode_(mode), uid_(uid), gid_(gid) {}
 
+}  // namespace cgrouprc
+}  // namespace android
+
 bool CgroupSetupCgroups() {
+    using namespace android::cgrouprc;
+
     std::map<std::string, CgroupDescriptor> descriptors;
 
     if (getpid() != 1) {