summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-07-26 09:26:20 +0200
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-07-26 09:26:20 +0200
commit70ec0b3cc12ae49e1c85d39152a99fb462ef469f (patch)
tree59f5e160f5b53207f6e15671b7d50c49b4ee2384
parentrelease-request-2b6c1b3d-5e73-4d4a-9a8d-92acb8a1483b-for-git_oc-mr1-release-4212424 snap-temp-L13800000085536241 (diff)
parentrecovery: handle security footer before passing size to mke2fs (diff)
downloadandroid_bootable_recovery-70ec0b3cc12ae49e1c85d39152a99fb462ef469f.tar
android_bootable_recovery-70ec0b3cc12ae49e1c85d39152a99fb462ef469f.tar.gz
android_bootable_recovery-70ec0b3cc12ae49e1c85d39152a99fb462ef469f.tar.bz2
android_bootable_recovery-70ec0b3cc12ae49e1c85d39152a99fb462ef469f.tar.lz
android_bootable_recovery-70ec0b3cc12ae49e1c85d39152a99fb462ef469f.tar.xz
android_bootable_recovery-70ec0b3cc12ae49e1c85d39152a99fb462ef469f.tar.zst
android_bootable_recovery-70ec0b3cc12ae49e1c85d39152a99fb462ef469f.zip
-rw-r--r--recovery.cpp17
-rw-r--r--roots.cpp39
2 files changed, 36 insertions, 20 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 11c12f6f1..8f08c53f4 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -1591,15 +1591,14 @@ int main(int argc, char **argv) {
ui->Print("Rebooting automatically.\n");
}
} else if (!just_exit) {
- status = INSTALL_NONE; // No command specified
- ui->SetBackground(RecoveryUI::NO_COMMAND);
-
- // http://b/17489952
- // If this is an eng or userdebug build, automatically turn on the
- // text display if no command is specified.
- if (is_ro_debuggable()) {
- ui->ShowText(true);
- }
+ // If this is an eng or userdebug build, automatically turn on the text display if no command
+ // is specified. Note that this should be called before setting the background to avoid
+ // flickering the background image.
+ if (is_ro_debuggable()) {
+ ui->ShowText(true);
+ }
+ status = INSTALL_NONE; // No command specified
+ ui->SetBackground(RecoveryUI::NO_COMMAND);
}
if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) {
diff --git a/roots.cpp b/roots.cpp
index c4afd5de3..29f55b96f 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -29,6 +29,7 @@
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
+#include <android-base/unique_fd.h>
#include <ext4_utils/wipe.h>
#include <fs_mgr.h>
@@ -173,6 +174,23 @@ static int exec_cmd(const char* path, char* const argv[]) {
return WEXITSTATUS(status);
}
+static ssize_t get_file_size(int fd, uint64_t reserve_len) {
+ struct stat buf;
+ int ret = fstat(fd, &buf);
+ if (ret) return 0;
+
+ ssize_t computed_size;
+ if (S_ISREG(buf.st_mode)) {
+ computed_size = buf.st_size - reserve_len;
+ } else if (S_ISBLK(buf.st_mode)) {
+ computed_size = get_block_device_size(fd) - reserve_len;
+ } else {
+ computed_size = 0;
+ }
+
+ return computed_size;
+}
+
int format_volume(const char* volume, const char* directory) {
Volume* v = volume_for_path(volume);
if (v == NULL) {
@@ -212,7 +230,16 @@ int format_volume(const char* volume, const char* directory) {
if (v->length != 0) {
length = v->length;
} else if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0) {
- length = -CRYPT_FOOTER_OFFSET;
+ android::base::unique_fd fd(open(v->blk_device, O_RDONLY));
+ if (fd < 0) {
+ PLOG(ERROR) << "get_file_size: failed to open " << v->blk_device;
+ return -1;
+ }
+ length = get_file_size(fd.get(), CRYPT_FOOTER_OFFSET);
+ if (length <= 0) {
+ LOG(ERROR) << "get_file_size: invalid size " << length << " for " << v->blk_device;
+ return -1;
+ }
}
int result;
if (strcmp(v->fs_type, "ext4") == 0) {
@@ -270,16 +297,6 @@ int format_volume(const char* volume, const char* directory) {
result = exec_cmd(e2fsdroid_argv[0], const_cast<char**>(e2fsdroid_argv));
}
} else { /* Has to be f2fs because we checked earlier. */
- if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0 && length < 0) {
- LOG(ERROR) << "format_volume: crypt footer + negative length (" << length
- << ") not supported on " << v->fs_type;
- return -1;
- }
- if (length < 0) {
- LOG(ERROR) << "format_volume: negative length (" << length
- << ") not supported on " << v->fs_type;
- return -1;
- }
char *num_sectors = nullptr;
if (length >= 512 && asprintf(&num_sectors, "%zd", length / 512) <= 0) {
LOG(ERROR) << "format_volume: failed to create " << v->fs_type