Hridya Valsaraju | 20c81b3 | 2018-07-27 22:09:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "fastboot.h" |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | |
| 22 | #include <algorithm> |
| 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
| 26 | #include <android-base/logging.h> |
| 27 | #include <android-base/properties.h> |
| 28 | #include <bootloader_message/bootloader_message.h> |
| 29 | |
| 30 | #include "device.h" |
| 31 | #include "ui.h" |
| 32 | |
| 33 | static const std::vector<std::pair<std::string, Device::BuiltinAction>> kFastbootMenuActions{ |
| 34 | { "Reboot system now", Device::REBOOT }, |
| 35 | { "Enter recovery", Device::ENTER_RECOVERY }, |
| 36 | { "Reboot to bootloader", Device::REBOOT_BOOTLOADER }, |
| 37 | { "Power off", Device::SHUTDOWN }, |
| 38 | }; |
| 39 | |
| 40 | Device::BuiltinAction StartFastboot(Device* device, const std::vector<std::string>& /* args */) { |
| 41 | RecoveryUI* ui = device->GetUI(); |
| 42 | |
| 43 | std::vector<std::string> title_lines = { "Android Fastboot" }; |
| 44 | title_lines.push_back("Product name - " + android::base::GetProperty("ro.product.device", "")); |
| 45 | title_lines.push_back("Bootloader version - " + android::base::GetProperty("ro.bootloader", "")); |
| 46 | title_lines.push_back("Baseband version - " + |
| 47 | android::base::GetProperty("ro.build.expect.baseband", "")); |
| 48 | title_lines.push_back("Serial number - " + android::base::GetProperty("ro.serialno", "")); |
| 49 | title_lines.push_back(std::string("Secure boot - ") + |
| 50 | ((android::base::GetProperty("ro.secure", "") == "1") ? "yes" : "no")); |
| 51 | title_lines.push_back("HW version - " + android::base::GetProperty("ro.revision", "")); |
| 52 | |
| 53 | ui->ResetKeyInterruptStatus(); |
| 54 | ui->SetTitle(title_lines); |
| 55 | ui->ShowText(true); |
| 56 | |
| 57 | // Reset to normal system boot so recovery won't cycle indefinitely. |
| 58 | // TODO(b/112277594) Clear only if 'recovery' field of BCB is empty. If not, |
| 59 | // set the 'command' field of BCB to 'boot-recovery' so the next boot is into recovery |
| 60 | // to finish any interrupted tasks. |
| 61 | std::string err; |
| 62 | if (!clear_bootloader_message(&err)) { |
| 63 | LOG(ERROR) << "Failed to clear BCB message: " << err; |
| 64 | } |
| 65 | |
| 66 | std::vector<std::string> fastboot_menu_items; |
| 67 | std::transform(kFastbootMenuActions.cbegin(), kFastbootMenuActions.cend(), |
| 68 | std::back_inserter(fastboot_menu_items), |
| 69 | [](const auto& entry) { return entry.first; }); |
| 70 | |
| 71 | auto chosen_item = ui->ShowMenu( |
| 72 | {}, fastboot_menu_items, 0, false, |
| 73 | std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2)); |
| 74 | |
| 75 | if (chosen_item == static_cast<size_t>(RecoveryUI::KeyError::INTERRUPTED)) { |
| 76 | return Device::KEY_INTERRUPTED; |
| 77 | } |
| 78 | if (chosen_item == static_cast<size_t>(RecoveryUI::KeyError::TIMED_OUT)) { |
| 79 | return Device::BuiltinAction::NO_ACTION; |
| 80 | } |
| 81 | return kFastbootMenuActions[chosen_item].second; |
| 82 | } |