summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-04 07:52:01 +0100
committerTao Bao <tbao@google.com>2016-11-18 06:30:32 +0100
commit1bf1772625392efe721e432681418548b9343bdd (patch)
treef1641627b56893148de037fe93782e339db3e892
parentDO NOT MERGE ANYWHERE init: move healthd to late-init am: 195ff7f79e -s ours am: 7ceb371048 -s ours am: b8c1788e7b -s ours am: 8837b0d25d -s ours am: 3fdf1fd515 -s ours (diff)
downloadandroid_bootable_recovery-1bf1772625392efe721e432681418548b9343bdd.tar
android_bootable_recovery-1bf1772625392efe721e432681418548b9343bdd.tar.gz
android_bootable_recovery-1bf1772625392efe721e432681418548b9343bdd.tar.bz2
android_bootable_recovery-1bf1772625392efe721e432681418548b9343bdd.tar.lz
android_bootable_recovery-1bf1772625392efe721e432681418548b9343bdd.tar.xz
android_bootable_recovery-1bf1772625392efe721e432681418548b9343bdd.tar.zst
android_bootable_recovery-1bf1772625392efe721e432681418548b9343bdd.zip
-rw-r--r--updater/install.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/updater/install.cpp b/updater/install.cpp
index 005f9f97d..74feb56be 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -35,8 +35,10 @@
#include <inttypes.h>
#include <memory>
+#include <string>
#include <vector>
+#include <android-base/file.h>
#include <android-base/parseint.h>
#include <android-base/strings.h>
#include <android-base/stringprintf.h>
@@ -966,7 +968,6 @@ Value* GetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
return StringValue(strdup(value));
}
-
// file_getprop(file, key)
//
// interprets 'file' as a getprop-style file (key=value pairs, one
@@ -1428,6 +1429,31 @@ Value* ReadFileFn(const char* name, State* state, int argc, Expr* argv[]) {
return v;
}
+// write_value(value, filename)
+// Writes 'value' to 'filename'.
+// Example: write_value("960000", "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq")
+Value* WriteValueFn(const char* name, State* state, int argc, Expr* argv[]) {
+ if (argc != 2) {
+ return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc);
+ }
+
+ char* value;
+ char* filename;
+ if (ReadArgs(state, argv, 2, &value, &filename) < 0) {
+ return ErrorAbort(state, kArgsParsingFailure, "%s(): Failed to parse the argument(s)",
+ name);
+ }
+
+ bool ret = android::base::WriteStringToFile(value, filename);
+ if (!ret) {
+ printf("%s: Failed to write to \"%s\": %s\n", name, filename, strerror(errno));
+ }
+
+ free(value);
+ free(filename);
+ return StringValue(strdup(ret ? "t" : ""));
+}
+
// Immediately reboot the device. Recovery is not finished normally,
// so if you reboot into recovery it will re-start applying the
// current package (because nothing has cleared the copy of the
@@ -1627,6 +1653,7 @@ void RegisterInstallFunctions() {
RegisterFunction("read_file", ReadFileFn);
RegisterFunction("sha1_check", Sha1CheckFn);
RegisterFunction("rename", RenameFn);
+ RegisterFunction("write_value", WriteValueFn);
RegisterFunction("wipe_cache", WipeCacheFn);