Add add_slot_suffix function.
This function appends androidboot.slot_suffix to the value of the argument. Test: apply update Bug: 153581609 Change-Id: I28a4047b5f2051acc039084f65a71deb492d9dcb
This commit is contained in:
parent
bc7e1db211
commit
dff8004275
7 changed files with 32 additions and 0 deletions
|
@ -36,6 +36,7 @@ AllowShortIfStatementsOnASingleLine: true
|
||||||
ColumnLimit: 100
|
ColumnLimit: 100
|
||||||
CommentPragmas: NOLINT:.*
|
CommentPragmas: NOLINT:.*
|
||||||
DerivePointerAlignment: false
|
DerivePointerAlignment: false
|
||||||
|
IncludeBlocks: Preserve
|
||||||
IndentWidth: 2
|
IndentWidth: 2
|
||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
TabWidth: 2
|
TabWidth: 2
|
||||||
|
|
|
@ -71,4 +71,7 @@ class UpdaterRuntimeInterface {
|
||||||
virtual bool MapPartitionOnDeviceMapper(const std::string& partition_name, std::string* path) = 0;
|
virtual bool MapPartitionOnDeviceMapper(const std::string& partition_name, std::string* path) = 0;
|
||||||
virtual bool UnmapPartitionOnDeviceMapper(const std::string& partition_name) = 0;
|
virtual bool UnmapPartitionOnDeviceMapper(const std::string& partition_name) = 0;
|
||||||
virtual bool UpdateDynamicPartitions(const std::string_view op_list_value) = 0;
|
virtual bool UpdateDynamicPartitions(const std::string_view op_list_value) = 0;
|
||||||
|
|
||||||
|
// On devices supports A/B, add current slot suffix to arg. Otherwise, return |arg| as is.
|
||||||
|
virtual std::string AddSlotSuffix(const std::string_view arg) const = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,6 +53,7 @@ class SimulatorRuntime : public UpdaterRuntimeInterface {
|
||||||
bool MapPartitionOnDeviceMapper(const std::string& partition_name, std::string* path) override;
|
bool MapPartitionOnDeviceMapper(const std::string& partition_name, std::string* path) override;
|
||||||
bool UnmapPartitionOnDeviceMapper(const std::string& partition_name) override;
|
bool UnmapPartitionOnDeviceMapper(const std::string& partition_name) override;
|
||||||
bool UpdateDynamicPartitions(const std::string_view op_list_value) override;
|
bool UpdateDynamicPartitions(const std::string_view op_list_value) override;
|
||||||
|
std::string AddSlotSuffix(const std::string_view arg) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string FindBlockDeviceName(const std::string_view name) const override;
|
std::string FindBlockDeviceName(const std::string_view name) const override;
|
||||||
|
|
|
@ -56,6 +56,7 @@ class UpdaterRuntime : public UpdaterRuntimeInterface {
|
||||||
bool MapPartitionOnDeviceMapper(const std::string& partition_name, std::string* path) override;
|
bool MapPartitionOnDeviceMapper(const std::string& partition_name, std::string* path) override;
|
||||||
bool UnmapPartitionOnDeviceMapper(const std::string& partition_name) override;
|
bool UnmapPartitionOnDeviceMapper(const std::string& partition_name) override;
|
||||||
bool UpdateDynamicPartitions(const std::string_view op_list_value) override;
|
bool UpdateDynamicPartitions(const std::string_view op_list_value) override;
|
||||||
|
std::string AddSlotSuffix(const std::string_view arg) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct selabel_handle* sehandle_{ nullptr };
|
struct selabel_handle* sehandle_{ nullptr };
|
||||||
|
|
|
@ -852,6 +852,20 @@ Value* Tune2FsFn(const char* name, State* state, const std::vector<std::unique_p
|
||||||
return StringValue("t");
|
return StringValue("t");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value* AddSlotSuffixFn(const char* name, State* state,
|
||||||
|
const std::vector<std::unique_ptr<Expr>>& argv) {
|
||||||
|
if (argv.size() != 1) {
|
||||||
|
return ErrorAbort(state, kArgsParsingFailure, "%s() expects 1 arg, got %zu", name, argv.size());
|
||||||
|
}
|
||||||
|
std::vector<std::string> args;
|
||||||
|
if (!ReadArgs(state, argv, &args)) {
|
||||||
|
return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name);
|
||||||
|
}
|
||||||
|
const std::string& arg = args[0];
|
||||||
|
auto updater_runtime = state->updater->GetRuntime();
|
||||||
|
return StringValue(updater_runtime->AddSlotSuffix(arg));
|
||||||
|
}
|
||||||
|
|
||||||
void RegisterInstallFunctions() {
|
void RegisterInstallFunctions() {
|
||||||
RegisterFunction("mount", MountFn);
|
RegisterFunction("mount", MountFn);
|
||||||
RegisterFunction("is_mounted", IsMountedFn);
|
RegisterFunction("is_mounted", IsMountedFn);
|
||||||
|
@ -885,4 +899,6 @@ void RegisterInstallFunctions() {
|
||||||
|
|
||||||
RegisterFunction("enable_reboot", EnableRebootFn);
|
RegisterFunction("enable_reboot", EnableRebootFn);
|
||||||
RegisterFunction("tune2fs", Tune2FsFn);
|
RegisterFunction("tune2fs", Tune2FsFn);
|
||||||
|
|
||||||
|
RegisterFunction("add_slot_suffix", AddSlotSuffixFn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,3 +130,8 @@ bool SimulatorRuntime::UpdateDynamicPartitions(const std::string_view op_list_va
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string SimulatorRuntime::AddSlotSuffix(const std::string_view arg) const {
|
||||||
|
LOG(INFO) << "Skip adding slot suffix to " << arg;
|
||||||
|
return std::string(arg);
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
#include <ext4_utils/wipe.h>
|
#include <ext4_utils/wipe.h>
|
||||||
|
#include <fs_mgr.h>
|
||||||
#include <selinux/label.h>
|
#include <selinux/label.h>
|
||||||
#include <tune2fs.h>
|
#include <tune2fs.h>
|
||||||
|
|
||||||
|
@ -186,3 +187,7 @@ int UpdaterRuntime::Tune2Fs(const std::vector<std::string>& args) const {
|
||||||
// tune2fs changes the filesystem parameters on an ext2 filesystem; it returns 0 on success.
|
// tune2fs changes the filesystem parameters on an ext2 filesystem; it returns 0 on success.
|
||||||
return tune2fs_main(tune2fs_args.size() - 1, tune2fs_args.data());
|
return tune2fs_main(tune2fs_args.size() - 1, tune2fs_args.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string UpdaterRuntime::AddSlotSuffix(const std::string_view arg) const {
|
||||||
|
return std::string(arg) + fs_mgr_get_slot_suffix();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue