clang-format derive_sdk am: e4fd55c992

Original change: https://android-review.googlesource.com/c/platform/packages/modules/SdkExtensions/+/1537282

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ibff069d2246c78bf730fe1df25299fe33a14ddc5
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..65c2b62
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,7 @@
+[Builtin Hooks]
+clang_format = true
+commit_msg_changeid_field = true
+commit_msg_test_field = true
+
+[Builtin Hooks Options]
+clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
diff --git a/derive_sdk/.clang-format b/derive_sdk/.clang-format
new file mode 100644
index 0000000..f6cb8ad
--- /dev/null
+++ b/derive_sdk/.clang-format
@@ -0,0 +1 @@
+BasedOnStyle: Google
diff --git a/derive_sdk/derive_sdk.cpp b/derive_sdk/derive_sdk.cpp
index 89c9adf..1b85c90 100644
--- a/derive_sdk/derive_sdk.cpp
+++ b/derive_sdk/derive_sdk.cpp
@@ -16,71 +16,71 @@
 
 #define LOG_TAG "derive_sdk"
 
-#include <algorithm>
-#include <dirent.h>
-#include <iostream>
-#include <sys/stat.h>
-#include <vector>
-
 #include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/properties.h>
 #include <android-modules-utils/sdk_level.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include <algorithm>
+#include <iostream>
+#include <vector>
 
 #include "packages/modules/SdkExtensions/derive_sdk/sdk.pb.h"
 
 using com::android::sdkext::proto::SdkVersion;
 
 int main(int, char**) {
-    std::unique_ptr<DIR, decltype(&closedir)> apex(opendir("/apex"), closedir);
-    if (!apex) {
-        LOG(ERROR) << "Could not read /apex";
-        return EXIT_FAILURE;
+  std::unique_ptr<DIR, decltype(&closedir)> apex(opendir("/apex"), closedir);
+  if (!apex) {
+    LOG(ERROR) << "Could not read /apex";
+    return EXIT_FAILURE;
+  }
+  struct dirent* de;
+  std::vector<std::string> paths;
+  while ((de = readdir(apex.get()))) {
+    std::string name = de->d_name;
+    if (name[0] == '.' || name.find('@') != std::string::npos) {
+      // Skip <name>@<ver> dirs, as they are bind-mounted to <name>
+      continue;
     }
-    struct dirent* de;
-    std::vector<std::string> paths;
-    while ((de = readdir(apex.get()))) {
-        std::string name = de->d_name;
-        if (name[0] == '.' || name.find('@') != std::string::npos) {
-            // Skip <name>@<ver> dirs, as they are bind-mounted to <name>
-            continue;
-        }
-        std::string path = "/apex/" + name + "/etc/sdkinfo.binarypb";
-        struct stat statbuf;
-        if (stat(path.c_str(), &statbuf) == 0) {
-            paths.push_back(path);
-        }
+    std::string path = "/apex/" + name + "/etc/sdkinfo.binarypb";
+    struct stat statbuf;
+    if (stat(path.c_str(), &statbuf) == 0) {
+      paths.push_back(path);
     }
+  }
 
-    std::vector<int> versions;
-    for (const auto& path : paths) {
-        std::string contents;
-        if (!android::base::ReadFileToString(path, &contents, true)) {
-            LOG(ERROR) << "failed to read " << path;
-            continue;
-        }
-        SdkVersion sdk_version;
-        if (!sdk_version.ParseFromString(contents)) {
-            LOG(ERROR) << "failed to parse " << path;
-            continue;
-        }
-        LOG(INFO) << "Read version " << sdk_version.version() << " from " << path;
-        versions.push_back(sdk_version.version());
+  std::vector<int> versions;
+  for (const auto& path : paths) {
+    std::string contents;
+    if (!android::base::ReadFileToString(path, &contents, true)) {
+      LOG(ERROR) << "failed to read " << path;
+      continue;
     }
-    auto itr = std::min_element(versions.begin(), versions.end());
-    std::string prop_value = itr == versions.end() ? "0" : std::to_string(*itr);
+    SdkVersion sdk_version;
+    if (!sdk_version.ParseFromString(contents)) {
+      LOG(ERROR) << "failed to parse " << path;
+      continue;
+    }
+    LOG(INFO) << "Read version " << sdk_version.version() << " from " << path;
+    versions.push_back(sdk_version.version());
+  }
+  auto itr = std::min_element(versions.begin(), versions.end());
+  std::string prop_value = itr == versions.end() ? "0" : std::to_string(*itr);
 
-    if (!android::base::SetProperty("build.version.extensions.r", prop_value)) {
-        LOG(ERROR) << "failed to set r sdk_info prop";
-        return EXIT_FAILURE;
+  if (!android::base::SetProperty("build.version.extensions.r", prop_value)) {
+    LOG(ERROR) << "failed to set r sdk_info prop";
+    return EXIT_FAILURE;
+  }
+  if (android::modules::sdklevel::IsAtLeastS()) {
+    if (!android::base::SetProperty("build.version.extensions.s", prop_value)) {
+      LOG(ERROR) << "failed to set s sdk_info prop";
+      return EXIT_FAILURE;
     }
-    if (android::modules::sdklevel::IsAtLeastS()) {
-        if (!android::base::SetProperty("build.version.extensions.s", prop_value)) {
-            LOG(ERROR) << "failed to set s sdk_info prop";
-            return EXIT_FAILURE;
-        }
-    }
+  }
 
-    LOG(INFO) << "Extension version is " << prop_value;
-    return EXIT_SUCCESS;
+  LOG(INFO) << "Extension version is " << prop_value;
+  return EXIT_SUCCESS;
 }
diff --git a/derive_sdk/sdk_extensions.proto b/derive_sdk/sdk_extensions.proto
new file mode 100644
index 0000000..e2929c2
--- /dev/null
+++ b/derive_sdk/sdk_extensions.proto
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+syntax = "proto3";
+package com.android.sdkext.proto;
+
+option java_outer_classname = "VersionRequirements";
+option optimize_for = LITE_RUNTIME;
+
+// All the modules that can be used for version requirements.
+enum SdkModule {
+  // R modules
+  IPSEC = 1;
+  MEDIA = 2;
+  MEDIA_PROVIDER = 3;
+  PERMISSIONS = 4;
+  SDK_EXTENSIONS = 5;
+  STATSD = 6;
+  TETHERING = 7;
+}
+
+// A single extension version.
+message ExtensionVersion {
+  message ModuleRequirement {
+    SdkModule module = 1;
+    int32 version = 2;
+  }
+  repeated ModuleRequirement requirements = 1
+}
+
+// All the defined extension versions.
+message ExtensionVersions {
+  repeated ExtensionVersion versions = 1;
+}