summaryrefslogtreecommitdiffstats
path: root/updater/include
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2019-05-14 19:54:43 +0200
committerTianjie Xu <xunchang@google.com>2019-05-21 03:03:27 +0200
commit1536db887f496b6c50522d62be22d9f6584eaf87 (patch)
tree0d749c706dcc35bcfd500cec17d31d17890a3792 /updater/include
parentDO NOT MERGE - Skip pi-platform-release (PPRL.190505.001) in stage-aosp-master (diff)
downloadandroid_bootable_recovery-1536db887f496b6c50522d62be22d9f6584eaf87.tar
android_bootable_recovery-1536db887f496b6c50522d62be22d9f6584eaf87.tar.gz
android_bootable_recovery-1536db887f496b6c50522d62be22d9f6584eaf87.tar.bz2
android_bootable_recovery-1536db887f496b6c50522d62be22d9f6584eaf87.tar.lz
android_bootable_recovery-1536db887f496b6c50522d62be22d9f6584eaf87.tar.xz
android_bootable_recovery-1536db887f496b6c50522d62be22d9f6584eaf87.tar.zst
android_bootable_recovery-1536db887f496b6c50522d62be22d9f6584eaf87.zip
Diffstat (limited to 'updater/include')
-rw-r--r--updater/include/updater/updater.h40
-rw-r--r--updater/include/updater/updater_runtime.h58
2 files changed, 83 insertions, 15 deletions
diff --git a/updater/include/updater/updater.h b/updater/include/updater/updater.h
index d5468292b..7bbecbc57 100644
--- a/updater/include/updater/updater.h
+++ b/updater/include/updater/updater.h
@@ -21,45 +21,53 @@
#include <memory>
#include <string>
+#include <string_view>
#include <ziparchive/zip_archive.h>
#include "edify/expr.h"
+#include "edify/updater_interface.h"
#include "otautil/error_code.h"
#include "otautil/sysutil.h"
-struct selabel_handle;
+class UpdaterRuntime;
-class Updater {
+class Updater : public UpdaterInterface {
public:
- ~Updater();
+ explicit Updater(std::unique_ptr<UpdaterRuntimeInterface> run_time)
+ : runtime_(std::move(run_time)) {}
+
+ Updater();
+
+ ~Updater() override;
// Memory-maps the OTA package and opens it as a zip file. Also sets up the command pipe and
- // selabel handle. TODO(xunchang) implement a run time environment class and move sehandle there.
- bool Init(int fd, const std::string& package_filename, bool is_retry,
- struct selabel_handle* sehandle);
+ // UpdaterRuntime.
+ bool Init(int fd, const std::string_view package_filename, bool is_retry);
// Parses and evaluates the updater-script in the OTA package. Reports the error code if the
// evaluation fails.
bool RunUpdate();
// Writes the message to command pipe, adds a new line in the end.
- void WriteToCommandPipe(const std::string& message, bool flush = false) const;
+ void WriteToCommandPipe(const std::string_view message, bool flush = false) const override;
// Sends over the message to recovery to print it on the screen.
- void UiPrint(const std::string& message) const;
+ void UiPrint(const std::string_view message) const override;
- ZipArchiveHandle package_handle() const {
- return package_handle_;
+ std::string FindBlockDeviceName(const std::string_view name) const override;
+
+ UpdaterRuntimeInterface* GetRuntime() const override {
+ return runtime_.get();
}
- struct selabel_handle* sehandle() const {
- return sehandle_;
+ ZipArchiveHandle GetPackageHandle() const override {
+ return package_handle_;
}
- std::string result() const {
+ std::string GetResult() const override {
return result_;
}
- uint8_t* GetMappedPackageAddress() const {
+ uint8_t* GetMappedPackageAddress() const override {
return mapped_package_.addr;
}
@@ -76,13 +84,15 @@ class Updater {
// Parses the error code embedded in state->errmsg; and reports the error code and cause code.
void ParseAndReportErrorCode(State* state);
+ std::unique_ptr<UpdaterRuntimeInterface> runtime_;
+
MemMapping mapped_package_;
ZipArchiveHandle package_handle_{ nullptr };
std::string updater_script_;
bool is_retry_{ false };
std::unique_ptr<FILE, decltype(&fclose)> cmd_pipe_{ nullptr, fclose };
- struct selabel_handle* sehandle_{ nullptr };
std::string result_;
+ std::vector<std::string> skipped_functions_;
};
diff --git a/updater/include/updater/updater_runtime.h b/updater/include/updater/updater_runtime.h
new file mode 100644
index 000000000..6cd0ffb48
--- /dev/null
+++ b/updater/include/updater/updater_runtime.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2019 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 <memory>
+#include <string>
+#include <string_view>
+#include <utility>
+#include <vector>
+
+#include "edify/updater_runtime_interface.h"
+
+struct selabel_handle;
+struct Partition;
+
+class UpdaterRuntime : public UpdaterRuntimeInterface {
+ public:
+ explicit UpdaterRuntime(struct selabel_handle* sehandle) : sehandle_(sehandle) {}
+ ~UpdaterRuntime() override = default;
+
+ bool IsSimulator() const override {
+ return false;
+ }
+
+ std::string GetProperty(const std::string_view key,
+ const std::string_view default_value) const override;
+
+ std::string FindBlockDeviceName(const std::string_view name) const override;
+
+ int Mount(const std::string_view location, const std::string_view mount_point,
+ const std::string_view fs_type, const std::string_view mount_options) override;
+ bool IsMounted(const std::string_view mount_point) const override;
+ std::pair<bool, int> Unmount(const std::string_view mount_point) override;
+
+ bool ReadFileToString(const std::string_view filename, std::string* content) const override;
+ bool WriteStringToFile(const std::string_view content,
+ const std::string_view filename) const override;
+
+ int WipeBlockDevice(const std::string_view filename, size_t len) const override;
+ int RunProgram(const std::vector<std::string>& args, bool is_vfork) const override;
+ int Tune2Fs(const std::vector<std::string>& args) const override;
+
+ struct selabel_handle* sehandle_{ nullptr };
+};