summaryrefslogtreecommitdiffstats
path: root/recovery_utils/include
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2019-10-01 20:55:36 +0200
committerTao Bao <tbao@google.com>2019-10-02 19:56:46 +0200
commite3f09a72f51df5abcf46a63de4a39ca5ed53698b (patch)
tree76c6fa3594480dafbd5b0ef7c032bf7258a017bb /recovery_utils/include
parentMerge "otautil: Drop a few unneeded includes." (diff)
downloadandroid_bootable_recovery-e3f09a72f51df5abcf46a63de4a39ca5ed53698b.tar
android_bootable_recovery-e3f09a72f51df5abcf46a63de4a39ca5ed53698b.tar.gz
android_bootable_recovery-e3f09a72f51df5abcf46a63de4a39ca5ed53698b.tar.bz2
android_bootable_recovery-e3f09a72f51df5abcf46a63de4a39ca5ed53698b.tar.lz
android_bootable_recovery-e3f09a72f51df5abcf46a63de4a39ca5ed53698b.tar.xz
android_bootable_recovery-e3f09a72f51df5abcf46a63de4a39ca5ed53698b.tar.zst
android_bootable_recovery-e3f09a72f51df5abcf46a63de4a39ca5ed53698b.zip
Diffstat (limited to 'recovery_utils/include')
-rw-r--r--recovery_utils/include/recovery_utils/logging.h65
-rw-r--r--recovery_utils/include/recovery_utils/parse_install_logs.h33
-rw-r--r--recovery_utils/include/recovery_utils/roots.h58
-rw-r--r--recovery_utils/include/recovery_utils/thermalutil.h24
4 files changed, 180 insertions, 0 deletions
diff --git a/recovery_utils/include/recovery_utils/logging.h b/recovery_utils/include/recovery_utils/logging.h
new file mode 100644
index 000000000..4462eca6e
--- /dev/null
+++ b/recovery_utils/include/recovery_utils/logging.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef _LOGGING_H
+#define _LOGGING_H
+
+#include <stddef.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <string>
+#include <vector>
+
+#include <log/log_id.h>
+
+static constexpr int KEEP_LOG_COUNT = 10;
+
+struct selabel_handle;
+
+struct saved_log_file {
+ std::string name;
+ struct stat sb;
+ std::string data;
+};
+
+void SetLoggingSehandle(selabel_handle* handle);
+
+ssize_t logbasename(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
+ void* arg);
+
+ssize_t logrotate(log_id_t id, char prio, const char* filename, const char* buf, size_t len,
+ void* arg);
+
+// Rename last_log -> last_log.1 -> last_log.2 -> ... -> last_log.$max.
+// Similarly rename last_kmsg -> last_kmsg.1 -> ... -> last_kmsg.$max.
+// Overwrite any existing last_log.$max and last_kmsg.$max.
+void rotate_logs(const char* last_log_file, const char* last_kmsg_file);
+
+// In turn fflush(3)'s, fsync(3)'s and fclose(3)'s the given stream.
+void check_and_fclose(FILE* fp, const std::string& name);
+
+void copy_log_file_to_pmsg(const std::string& source, const std::string& destination);
+void copy_logs(bool save_current_log);
+void reset_tmplog_offset();
+
+void save_kernel_log(const char* destination);
+
+std::vector<saved_log_file> ReadLogFilesToMemory();
+
+bool RestoreLogFilesAfterFormat(const std::vector<saved_log_file>& log_files);
+
+#endif //_LOGGING_H
diff --git a/recovery_utils/include/recovery_utils/parse_install_logs.h b/recovery_utils/include/recovery_utils/parse_install_logs.h
new file mode 100644
index 000000000..135d29ccf
--- /dev/null
+++ b/recovery_utils/include/recovery_utils/parse_install_logs.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2018 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 <stdint.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+constexpr const char* LAST_INSTALL_FILE = "/data/misc/recovery/last_install";
+constexpr const char* LAST_INSTALL_FILE_IN_CACHE = "/cache/recovery/last_install";
+
+// Parses the metrics of update applied under recovery mode in |lines|, and returns a map with
+// "name: value".
+std::map<std::string, int64_t> ParseRecoveryUpdateMetrics(const std::vector<std::string>& lines);
+// Parses the sideload history and update metrics in the last_install file. Returns a map with
+// entries as "metrics_name: value". If no such file exists, returns an empty map.
+std::map<std::string, int64_t> ParseLastInstall(const std::string& file_name);
diff --git a/recovery_utils/include/recovery_utils/roots.h b/recovery_utils/include/recovery_utils/roots.h
new file mode 100644
index 000000000..92ee756f0
--- /dev/null
+++ b/recovery_utils/include/recovery_utils/roots.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2007 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 <string>
+
+#include <fstab/fstab.h>
+
+using Volume = android::fs_mgr::FstabEntry;
+
+// Load and parse volume data from /etc/recovery.fstab.
+void load_volume_table();
+
+// Return the Volume* record for this mount point (or nullptr).
+Volume* volume_for_mount_point(const std::string& mount_point);
+
+// Make sure that the volume 'path' is on is mounted. Returns 0 on
+// success (volume is mounted).
+int ensure_path_mounted(const std::string& path);
+
+// Similar to ensure_path_mounted, but allows one to specify the mount_point.
+int ensure_path_mounted_at(const std::string& path, const std::string& mount_point);
+
+// Make sure that the volume 'path' is on is unmounted. Returns 0 on
+// success (volume is unmounted);
+int ensure_path_unmounted(const std::string& path);
+
+// Reformat the given volume (must be the mount point only, eg
+// "/cache"), no paths permitted. Attempts to unmount the volume if
+// it is mounted.
+int format_volume(const std::string& volume);
+
+// Reformat the given volume (must be the mount point only, eg
+// "/cache"), no paths permitted. Attempts to unmount the volume if
+// it is mounted.
+// Copies 'directory' to root of the newly formatted volume
+int format_volume(const std::string& volume, const std::string& directory);
+
+// Ensure that all and only the volumes that packages expect to find
+// mounted (/tmp and /cache) are mounted. Returns 0 on success.
+int setup_install_mounts();
+
+// Returns true if there is /cache in the volumes.
+bool HasCache();
diff --git a/recovery_utils/include/recovery_utils/thermalutil.h b/recovery_utils/include/recovery_utils/thermalutil.h
new file mode 100644
index 000000000..43ab55940
--- /dev/null
+++ b/recovery_utils/include/recovery_utils/thermalutil.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#ifndef OTAUTIL_THERMALUTIL_H
+#define OTAUTIL_THERMALUTIL_H
+
+// We can find the temperature reported by all sensors in /sys/class/thermal/thermal_zone*/temp.
+// Their values are in millidegree Celsius; and we will log the maximum one.
+int GetMaxValueFromThermalZone();
+
+#endif // OTAUTIL_THERMALUTIL_H