From e3f09a72f51df5abcf46a63de4a39ca5ed53698b Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 1 Oct 2019 11:55:36 -0700 Subject: otautil: Factor out the utils that're private to recovery. A number of utility functions are intended for serving recovery's own use. Exposing them via libotautil (which is a static lib) would pass the dependencies onto libotautil's users (e.g. recovery image, updater, host simulator, device-specific recovery UI/updater extensions etc). This CL finds a new home for the utils that are private to recovery. Test: mmma bootable/recovery Change-Id: I575e97ad099b85fe1c1c8c7c9458a5a43d4e11e1 --- recovery_utils/include/recovery_utils/logging.h | 65 ++++++++++++++++++++++ .../include/recovery_utils/parse_install_logs.h | 33 +++++++++++ recovery_utils/include/recovery_utils/roots.h | 58 +++++++++++++++++++ .../include/recovery_utils/thermalutil.h | 24 ++++++++ 4 files changed, 180 insertions(+) create mode 100644 recovery_utils/include/recovery_utils/logging.h create mode 100644 recovery_utils/include/recovery_utils/parse_install_logs.h create mode 100644 recovery_utils/include/recovery_utils/roots.h create mode 100644 recovery_utils/include/recovery_utils/thermalutil.h (limited to 'recovery_utils/include') 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 +#include +#include + +#include +#include + +#include + +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 ReadLogFilesToMemory(); + +bool RestoreLogFilesAfterFormat(const std::vector& 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 + +#include +#include +#include + +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 ParseRecoveryUpdateMetrics(const std::vector& 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 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 + +#include + +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 -- cgit v1.2.3