Merge "Merge Android 24Q1 Release (ab/11220357)" into aosp-main-future
diff --git a/Android.bp b/Android.bp
index 83af9f4..ceb6ae1 100644
--- a/Android.bp
+++ b/Android.bp
@@ -74,7 +74,6 @@
"HalManifest.cpp",
"HalInterface.cpp",
"KernelConfigTypedValue.cpp",
- "KernelConfigParser.cpp",
"KernelInfo.cpp",
"RuntimeInfo.cpp",
"ManifestHal.cpp",
@@ -103,6 +102,7 @@
],
whole_static_libs: [
"libkver",
+ "libkernelconfigs",
],
export_include_dirs: [
"include",
@@ -260,3 +260,27 @@
"VintfFmMain.cpp",
],
}
+
+cc_library_static {
+ name: "libkernelconfigs",
+ defaults: ["libvintf-defaults"],
+ host_supported: true,
+ recovery_available: true,
+ srcs: [
+ "KernelConfigs.cpp",
+ "KernelConfigParser.cpp",
+ ],
+ header_libs: [
+ "libutils_headers",
+ ],
+ shared_libs: [
+ "libbase",
+ "libz",
+ ],
+ export_include_dirs: [
+ "include",
+ ],
+ local_include_dirs: [
+ "include/vintf",
+ ],
+}
diff --git a/KernelConfigs.cpp b/KernelConfigs.cpp
new file mode 100644
index 0000000..3de65ea
--- /dev/null
+++ b/KernelConfigs.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+#include "KernelConfigs.h"
+
+#include <android-base/logging.h>
+
+#include <map>
+#include <string>
+
+#include <zlib.h>
+#include "vintf/KernelConfigParser.h"
+
+#define BUFFER_SIZE sysconf(_SC_PAGESIZE)
+
+namespace android {
+namespace kernelconfigs {
+
+status_t LoadKernelConfigs(std::map<std::string, std::string>* configs) {
+ vintf::KernelConfigParser parser;
+ gzFile f = gzopen("/proc/config.gz", "rb");
+ if (f == NULL) {
+ LOG(ERROR) << "Could not open /proc/config.gz: " << errno;
+ return -errno;
+ }
+
+ char buf[BUFFER_SIZE];
+ int len;
+ while ((len = gzread(f, buf, sizeof buf)) > 0) {
+ parser.process(buf, len);
+ }
+ status_t err = OK;
+ if (len < 0) {
+ int errnum;
+ const char* errmsg = gzerror(f, &errnum);
+ LOG(ERROR) << "Could not read /proc/config.gz: " << errmsg;
+ err = (errnum == Z_ERRNO ? -errno : errnum);
+ }
+ parser.finish();
+ gzclose(f);
+ *configs = std::move(parser.configs());
+ return err;
+}
+
+} // namespace kernelconfigs
+} // namespace android
diff --git a/RuntimeInfo-target.cpp b/RuntimeInfo-target.cpp
index d747fc7..453be56 100644
--- a/RuntimeInfo-target.cpp
+++ b/RuntimeInfo-target.cpp
@@ -21,7 +21,6 @@
#include "RuntimeInfo.h"
#include "CompatibilityMatrix.h"
-#include "KernelConfigParser.h"
#include "parse_string.h"
#include <dirent.h>
@@ -35,10 +34,8 @@
#include <android-base/properties.h>
#include <selinux/selinux.h>
-#include <zlib.h>
-#define PROC_CONFIG "/proc/config.gz"
-#define BUFFER_SIZE sysconf(_SC_PAGESIZE)
+#include "KernelConfigs.h"
namespace android {
namespace vintf {
@@ -54,34 +51,12 @@
status_t fetchKernelSepolicyVers(RuntimeInfo::FetchFlags flags);
status_t fetchAvb(RuntimeInfo::FetchFlags flags);
status_t parseKernelVersion();
- RuntimeInfo *mRuntimeInfo;
- KernelConfigParser mConfigParser;
+ RuntimeInfo* mRuntimeInfo;
};
// decompress /proc/config.gz and read its contents.
status_t RuntimeInfoFetcher::fetchKernelConfigs(RuntimeInfo::FetchFlags) {
- gzFile f = gzopen(PROC_CONFIG, "rb");
- if (f == NULL) {
- LOG(ERROR) << "Could not open /proc/config.gz: " << errno;
- return -errno;
- }
-
- char buf[BUFFER_SIZE];
- int len;
- while ((len = gzread(f, buf, sizeof buf)) > 0) {
- mConfigParser.process(buf, len);
- }
- status_t err = OK;
- if (len < 0) {
- int errnum;
- const char *errmsg = gzerror(f, &errnum);
- LOG(ERROR) << "Could not read /proc/config.gz: " << errmsg;
- err = (errnum == Z_ERRNO ? -errno : errnum);
- }
- mConfigParser.finish();
- gzclose(f);
- mRuntimeInfo->mKernel.mConfigs = std::move(mConfigParser.configs());
- return err;
+ return kernelconfigs::LoadKernelConfigs(&mRuntimeInfo->mKernel.mConfigs);
}
status_t RuntimeInfoFetcher::fetchCpuInfo(RuntimeInfo::FetchFlags) {
diff --git a/include/vintf/KernelConfigs.h b/include/vintf/KernelConfigs.h
new file mode 100644
index 0000000..6324d9c
--- /dev/null
+++ b/include/vintf/KernelConfigs.h
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <map>
+#include <string>
+
+#include <utils/Errors.h>
+
+namespace android {
+namespace kernelconfigs {
+
+status_t LoadKernelConfigs(std::map<std::string, std::string>* configs);
+
+} // namespace kernelconfigs
+} // namespace android